Set the names for the codecov uploads
[kconfig-hardened-check.git] / .github / workflows / functional_test.yml
1 name: functional test
2
3 on:
4   push:
5     branches: [ master ]
6   pull_request:
7     branches: [ master ]
8
9 jobs:
10   functional_test:
11
12     runs-on: ubuntu-latest
13
14     strategy:
15       max-parallel: 3
16       fail-fast: false
17       matrix:
18         # Current ubuntu-latest (Ubuntu 22.04) provides the following versions of Python:
19         python-version: ['3.7', '3.8', '3.9', '3.10', '3.11']
20
21     steps:
22
23     - name: Set up Python ${{ matrix.python-version }}
24       uses: actions/setup-python@v4
25       with:
26         python-version: ${{ matrix.python-version }}
27
28     - name: Install package
29       run: |
30         python -m pip install --upgrade pip
31         pip install coverage
32         pip --verbose install git+https://github.com/a13xp0p0v/kconfig-hardened-check
33         echo ">>>>> first start <<<<<"
34         kconfig-hardened-check
35
36     - name: Check all configs with the installed tool
37       run: |
38         echo ">>>>> check all configs <<<<<"
39         CONFIG_DIR=`find /opt/hostedtoolcache/Python/ -name config_files`
40         KCONFIGS=`find $CONFIG_DIR -type f | grep "\.config"`
41         COUNT=0
42         for C in $KCONFIGS
43         do
44                 COUNT=$(expr $COUNT + 1)
45                 echo -e "\n>>>>> checking config number $COUNT <<<<<"
46                 kconfig-hardened-check -c $C -l /proc/cmdline
47         done
48         echo -e "\n>>>>> checking $COUNT configs is done <<<<<"
49
50     - name: Get source code for collecting coverage
51       uses: actions/checkout@v3
52
53     - name: Collect coverage for the basic functionality
54       run: |
55         echo ">>>>> get help <<<<<"
56         coverage run -a --branch bin/kconfig-hardened-check
57         coverage run -a --branch bin/kconfig-hardened-check -h
58
59         echo ">>>>> get version <<<<<"
60         coverage run -a --branch bin/kconfig-hardened-check --version
61
62         echo ">>>>> print the security hardening preferences <<<<<"
63         coverage run -a --branch bin/kconfig-hardened-check -p X86_64
64         coverage run -a --branch bin/kconfig-hardened-check -p X86_64 -m verbose
65         coverage run -a --branch bin/kconfig-hardened-check -p X86_64 -m json
66
67         coverage run -a --branch bin/kconfig-hardened-check -p X86_32
68         coverage run -a --branch bin/kconfig-hardened-check -p X86_32 -m verbose
69         coverage run -a --branch bin/kconfig-hardened-check -p X86_32 -m json
70
71         coverage run -a --branch bin/kconfig-hardened-check -p ARM64
72         coverage run -a --branch bin/kconfig-hardened-check -p ARM64 -m verbose
73         coverage run -a --branch bin/kconfig-hardened-check -p ARM64 -m json
74
75         coverage run -a --branch bin/kconfig-hardened-check -p ARM
76         coverage run -a --branch bin/kconfig-hardened-check -p ARM -m verbose
77         coverage run -a --branch bin/kconfig-hardened-check -p ARM -m json
78
79         echo ">>>>> check the example kconfig files and cmdline <<<<<"
80         cat /proc/cmdline
81         echo "l1tf=off mds=full randomize_kstack_offset=on iommu.passthrough=0" > ./cmdline_example
82         cat ./cmdline_example
83         CONFIG_DIR=`find . -name config_files`
84         KCONFIGS=`find $CONFIG_DIR -type f | grep "\.config"`
85         COUNT=0
86         for C in $KCONFIGS
87         do
88                 COUNT=$(expr $COUNT + 1)
89                 echo -e "\n>>>>> checking config number $COUNT <<<<<"
90                 coverage run -a --branch bin/kconfig-hardened-check -c $C
91                 coverage run -a --branch bin/kconfig-hardened-check -c $C -m verbose > /dev/null
92                 coverage run -a --branch bin/kconfig-hardened-check -c $C -l /proc/cmdline
93                 coverage run -a --branch bin/kconfig-hardened-check -c $C -l ./cmdline_example
94                 coverage run -a --branch bin/kconfig-hardened-check -c $C -l ./cmdline_example -m verbose > /dev/null
95                 coverage run -a --branch bin/kconfig-hardened-check -c $C -l ./cmdline_example -m json
96                 coverage run -a --branch bin/kconfig-hardened-check -c $C -l ./cmdline_example -m show_ok
97                 coverage run -a --branch bin/kconfig-hardened-check -c $C -l ./cmdline_example -m show_fail
98         done
99         echo -e "\n>>>>> checking $COUNT configs is done <<<<<"
100
101     - name: Collect coverage for error handling
102       run: |
103         echo ">>>>> lonely -l <<<<<"
104         ! coverage run -a --branch bin/kconfig-hardened-check -l /proc/cmdline
105
106         echo ">>>>> wrong modes for -p <<<<<"
107         ! coverage run -a --branch bin/kconfig-hardened-check -p X86_64 -m show_ok
108         ! coverage run -a --branch bin/kconfig-hardened-check -p X86_64 -m show_fail
109
110         echo ">>>>> -p and -c together <<<<<"
111         ! coverage run -a --branch bin/kconfig-hardened-check -p X86_64 -c kconfig_hardened_check/config_files/distros/fedora_34.config
112
113         cp kconfig_hardened_check/config_files/distros/fedora_34.config ./test.config
114
115         echo ">>>>> no kernel version <<<<<"
116         sed '3d' test.config > error.config
117         ! coverage run -a --branch bin/kconfig-hardened-check -c error.config
118
119         echo ">>>>> strange kernel version string <<<<<"
120         sed '3 s/5./version 5./' test.config > error.config
121         ! coverage run -a --branch bin/kconfig-hardened-check -c error.config
122
123         echo ">>>>> no arch <<<<<"
124         sed '305d' test.config > error.config
125         ! coverage run -a --branch bin/kconfig-hardened-check -c error.config
126
127         echo ">>>>> more than one arch <<<<<"
128         cp test.config error.config
129         echo 'CONFIG_ARM64=y' >> error.config
130         ! coverage run -a --branch bin/kconfig-hardened-check -c error.config
131
132         echo ">>>>> invalid disabled kconfig option <<<<<"
133         sed '28 s/is not set/is not set yet/' test.config > error.config
134         ! coverage run -a --branch bin/kconfig-hardened-check -c error.config
135
136         echo ">>>>> invalid enabled kconfig option <<<<<"
137         cp test.config error.config
138         echo 'CONFIG_FOO=is not set' >> error.config
139         ! coverage run -a --branch bin/kconfig-hardened-check -c error.config
140
141         echo ">>>>> one config option multiple times <<<<<"
142         cp test.config error.config
143         echo 'CONFIG_BUG=y' >> error.config
144         ! coverage run -a --branch bin/kconfig-hardened-check -c error.config
145
146         echo ">>>>> invalid compiler versions <<<<<"
147         cp test.config error.config
148         sed '8 s/CONFIG_CLANG_VERSION=0/CONFIG_CLANG_VERSION=120000/' test.config > error.config
149         ! coverage run -a --branch bin/kconfig-hardened-check -c error.config
150
151         echo ">>>>> multi-line cmdline file <<<<<"
152         echo 'hey man 1' > cmdline
153         echo 'hey man 2' >> cmdline
154         ! coverage run -a --branch bin/kconfig-hardened-check -c test.config -l cmdline
155
156     - name: Prepare final coverage report
157       run: |
158         coverage xml -i -o coverage.xml
159
160     - name: Handle coverage
161       uses: codecov/codecov-action@v3
162       with:
163         files: ./coverage.xml
164         flags: functional_test
165         name: functional_test_upload
166         fail_ci_if_error: true
167         verbose: true