Add --sysctl to functional testing
[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 recommendations <<<<<"
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 ">>>>> generate the Kconfig fragment <<<<<"
33 coverage run -a --branch bin/kconfig-hardened-check -g X86_64
34 coverage run -a --branch bin/kconfig-hardened-check -g X86_32
35 coverage run -a --branch bin/kconfig-hardened-check -g ARM64
36 coverage run -a --branch bin/kconfig-hardened-check -g ARM
37
38 echo ">>>>> check the example kconfig files, cmdline, and sysctl <<<<<"
39 cat /proc/cmdline
40 echo "l1tf=off mds=full randomize_kstack_offset=on iommu.passthrough=0" > ./cmdline_example
41 cat ./cmdline_example
42 sysctl -a > /tmp/sysctls
43 CONFIG_DIR=`find . -name config_files`
44 KCONFIGS=`find $CONFIG_DIR -type f | grep -e "\.config" -e "\.gz"`
45 COUNT=0
46 for C in $KCONFIGS
47 do
48         COUNT=$(expr $COUNT + 1)
49         echo "\n>>>>> checking kconfig number $COUNT <<<<<"
50         coverage run -a --branch bin/kconfig-hardened-check -c $C > /dev/null
51         coverage run -a --branch bin/kconfig-hardened-check -c $C -m verbose > /dev/null
52         coverage run -a --branch bin/kconfig-hardened-check -c $C -l /proc/cmdline > /dev/null
53         coverage run -a --branch bin/kconfig-hardened-check -c $C -s /tmp/sysctls > /dev/null
54         coverage run -a --branch bin/kconfig-hardened-check -c $C -l ./cmdline_example -s /tmp/sysctls > /dev/null
55         coverage run -a --branch bin/kconfig-hardened-check -c $C -l ./cmdline_example -s /tmp/sysctls -m verbose > /dev/null
56         coverage run -a --branch bin/kconfig-hardened-check -c $C -l ./cmdline_example -s /tmp/sysctls -m json > /dev/null
57         coverage run -a --branch bin/kconfig-hardened-check -c $C -l ./cmdline_example -s /tmp/sysctls -m show_ok > /dev/null
58         coverage run -a --branch bin/kconfig-hardened-check -c $C -l ./cmdline_example -s /tmp/sysctls -m show_fail > /dev/null
59 done
60 echo "\n>>>>> have checked $COUNT kconfigs <<<<<"
61
62 echo "Collect coverage for error handling"
63
64 echo ">>>>> -c and -p together <<<<<"
65 coverage run -a --branch bin/kconfig-hardened-check -p X86_64 -c kconfig_hardened_check/config_files/distros/fedora_34.config && exit 1
66
67 echo ">>>>> -c and -g together <<<<<"
68 coverage run -a --branch bin/kconfig-hardened-check -g X86_64 -c kconfig_hardened_check/config_files/distros/fedora_34.config && exit 1
69
70 echo ">>>>> -p and -g together <<<<<"
71 coverage run -a --branch bin/kconfig-hardened-check -p X86_64 -g X86_64 && exit 1
72
73 echo ">>>>> -l without -c <<<<<"
74 coverage run -a --branch bin/kconfig-hardened-check -l /proc/cmdline && exit 1
75
76 echo ">>>>> wrong modes for -p <<<<<"
77 coverage run -a --branch bin/kconfig-hardened-check -p X86_64 -m show_ok && exit 1
78 coverage run -a --branch bin/kconfig-hardened-check -p X86_64 -m show_fail && exit 1
79
80 echo ">>>>> wrong mode for -g <<<<<"
81 coverage run -a --branch bin/kconfig-hardened-check -g X86_64 -m show_ok && exit 1
82
83 cp kconfig_hardened_check/config_files/distros/fedora_34.config ./test.config
84
85 echo ">>>>> no kernel version <<<<<"
86 sed '3d' test.config > error.config
87 coverage run -a --branch bin/kconfig-hardened-check -c error.config && exit 1
88
89 echo ">>>>> strange kernel version string <<<<<"
90 sed '3 s/5./version 5./' test.config > error.config
91 coverage run -a --branch bin/kconfig-hardened-check -c error.config && exit 1
92
93 echo ">>>>> no arch <<<<<"
94 sed '305d' test.config > error.config
95 coverage run -a --branch bin/kconfig-hardened-check -c error.config && exit 1
96
97 echo ">>>>> more than one arch <<<<<"
98 cp test.config error.config
99 echo 'CONFIG_ARM64=y' >> error.config
100 coverage run -a --branch bin/kconfig-hardened-check -c error.config && exit 1
101
102 echo ">>>>> invalid enabled kconfig option <<<<<"
103 cp test.config error.config
104 echo 'CONFIG_FOO=is not set' >> error.config
105 coverage run -a --branch bin/kconfig-hardened-check -c error.config && exit 1
106
107 echo ">>>>> one config option multiple times <<<<<"
108 cp test.config error.config
109 echo 'CONFIG_BUG=y' >> error.config
110 coverage run -a --branch bin/kconfig-hardened-check -c error.config && exit 1
111
112 echo ">>>>> invalid compiler versions <<<<<"
113 cp test.config error.config
114 sed '8 s/CONFIG_CLANG_VERSION=0/CONFIG_CLANG_VERSION=120000/' test.config > error.config
115 coverage run -a --branch bin/kconfig-hardened-check -c error.config && exit 1
116
117 echo ">>>>> multi-line cmdline file <<<<<"
118 echo 'hey man 1' > cmdline
119 echo 'hey man 2' >> cmdline
120 coverage run -a --branch bin/kconfig-hardened-check -c test.config -l cmdline && exit 1
121
122 echo "The end of the functional tests"