Run the functional tests and collect the coverage in Woodpecker-CI
[kconfig-hardened-check.git] / .github / workflows / functional_test.sh
1 #!/bin/sh
2
3 set -x
4 set -e
5
6 echo "Beginning of the functional tests"
7
8 echo ">>>>> get help <<<<<"
9 coverage run -a --branch bin/kconfig-hardened-check
10 coverage run -a --branch bin/kconfig-hardened-check -h
11
12 echo ">>>>> get version <<<<<"
13 coverage run -a --branch bin/kconfig-hardened-check --version
14
15 echo ">>>>> print the security hardening preferences <<<<<"
16 coverage run -a --branch bin/kconfig-hardened-check -p X86_64
17 coverage run -a --branch bin/kconfig-hardened-check -p X86_64 -m verbose
18 coverage run -a --branch bin/kconfig-hardened-check -p X86_64 -m json
19
20 coverage run -a --branch bin/kconfig-hardened-check -p X86_32
21 coverage run -a --branch bin/kconfig-hardened-check -p X86_32 -m verbose
22 coverage run -a --branch bin/kconfig-hardened-check -p X86_32 -m json
23
24 coverage run -a --branch bin/kconfig-hardened-check -p ARM64
25 coverage run -a --branch bin/kconfig-hardened-check -p ARM64 -m verbose
26 coverage run -a --branch bin/kconfig-hardened-check -p ARM64 -m json
27
28 coverage run -a --branch bin/kconfig-hardened-check -p ARM
29 coverage run -a --branch bin/kconfig-hardened-check -p ARM -m verbose
30 coverage run -a --branch bin/kconfig-hardened-check -p ARM -m json
31
32 echo ">>>>> check the example kconfig files and cmdline <<<<<"
33 cat /proc/cmdline
34 echo "l1tf=off mds=full randomize_kstack_offset=on iommu.passthrough=0" > ./cmdline_example
35 cat ./cmdline_example
36 CONFIG_DIR=`find . -name config_files`
37 KCONFIGS=`find $CONFIG_DIR -type f | grep -e "\.config" -e "\.gz"`
38 COUNT=0
39 for C in $KCONFIGS
40 do
41         COUNT=$(expr $COUNT + 1)
42         echo "\n>>>>> checking kconfig number $COUNT <<<<<"
43         coverage run -a --branch bin/kconfig-hardened-check -c $C > /dev/null
44         coverage run -a --branch bin/kconfig-hardened-check -c $C -m verbose > /dev/null
45         coverage run -a --branch bin/kconfig-hardened-check -c $C -l /proc/cmdline > /dev/null
46         coverage run -a --branch bin/kconfig-hardened-check -c $C -l ./cmdline_example > /dev/null
47         coverage run -a --branch bin/kconfig-hardened-check -c $C -l ./cmdline_example -m verbose > /dev/null
48         coverage run -a --branch bin/kconfig-hardened-check -c $C -l ./cmdline_example -m json > /dev/null
49         coverage run -a --branch bin/kconfig-hardened-check -c $C -l ./cmdline_example -m show_ok > /dev/null
50         coverage run -a --branch bin/kconfig-hardened-check -c $C -l ./cmdline_example -m show_fail > /dev/null
51 done
52 echo "\n>>>>> have checked $COUNT kconfigs <<<<<"
53
54 echo "Collect coverage for error handling"
55 echo ">>>>> lonely -l <<<<<"
56 ! coverage run -a --branch bin/kconfig-hardened-check -l /proc/cmdline
57
58 echo ">>>>> wrong modes for -p <<<<<"
59 ! coverage run -a --branch bin/kconfig-hardened-check -p X86_64 -m show_ok
60 ! coverage run -a --branch bin/kconfig-hardened-check -p X86_64 -m show_fail
61
62 echo ">>>>> -p and -c together <<<<<"
63 ! coverage run -a --branch bin/kconfig-hardened-check -p X86_64 -c kconfig_hardened_check/config_files/distros/fedora_34.config
64
65 cp kconfig_hardened_check/config_files/distros/fedora_34.config ./test.config
66
67 echo ">>>>> no kernel version <<<<<"
68 sed '3d' test.config > error.config
69 ! coverage run -a --branch bin/kconfig-hardened-check -c error.config
70
71 echo ">>>>> strange kernel version string <<<<<"
72 sed '3 s/5./version 5./' test.config > error.config
73 ! coverage run -a --branch bin/kconfig-hardened-check -c error.config
74
75 echo ">>>>> no arch <<<<<"
76 sed '305d' test.config > error.config
77 ! coverage run -a --branch bin/kconfig-hardened-check -c error.config
78
79 echo ">>>>> more than one arch <<<<<"
80 cp test.config error.config
81 echo 'CONFIG_ARM64=y' >> error.config
82 ! coverage run -a --branch bin/kconfig-hardened-check -c error.config
83
84 echo ">>>>> invalid disabled kconfig option <<<<<"
85 sed '28 s/is not set/is not set yet/' test.config > error.config
86 ! coverage run -a --branch bin/kconfig-hardened-check -c error.config
87
88 echo ">>>>> invalid enabled kconfig option <<<<<"
89 cp test.config error.config
90 echo 'CONFIG_FOO=is not set' >> error.config
91 ! coverage run -a --branch bin/kconfig-hardened-check -c error.config
92
93 echo ">>>>> one config option multiple times <<<<<"
94 cp test.config error.config
95 echo 'CONFIG_BUG=y' >> error.config
96 ! coverage run -a --branch bin/kconfig-hardened-check -c error.config
97
98 echo ">>>>> invalid compiler versions <<<<<"
99 cp test.config error.config
100 sed '8 s/CONFIG_CLANG_VERSION=0/CONFIG_CLANG_VERSION=120000/' test.config > error.config
101 ! coverage run -a --branch bin/kconfig-hardened-check -c error.config
102
103 echo ">>>>> multi-line cmdline file <<<<<"
104 echo 'hey man 1' > cmdline
105 echo 'hey man 2' >> cmdline
106 ! coverage run -a --branch bin/kconfig-hardened-check -c test.config -l cmdline
107
108 echo "The end of the functional tests"