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