4 This tool helps me to check Linux kernel options against
5 my security hardening preferences for X86_64, ARM64, X86_32, and ARM.
6 Let the computers do their job!
8 Author: Alexander Popov <alex.popov@linux.com>
10 This module performs unit-testing of the kconfig-hardened-check engine.
14 from collections import OrderedDict
16 from .engine import KconfigCheck, CmdlineCheck, populate_with_data, perform_checks
18 class TestEngine(unittest.TestCase):
19 def run_engine(self, checklist, parsed_kconfig_options, parsed_cmdline_options, kernel_version):
20 # populate the checklist with data
21 populate_with_data(checklist, parsed_kconfig_options, 'kconfig')
22 populate_with_data(checklist, parsed_cmdline_options, 'cmdline')
23 populate_with_data(checklist, kernel_version, 'version')
25 # now everything is ready, perform the checks
26 perform_checks(checklist)
28 # print the results in JSON
32 output.append(opt.json_dump(True)) # with_results
33 print(json.dumps(output))
35 # print the table with the results
38 opt.table_print(None, True) # default mode, with_results
43 # 1. prepare the checklist
45 config_checklist += [KconfigCheck('reason_1', 'decision_1', 'KCONFIG_NAME', 'expected_1')]
46 config_checklist += [CmdlineCheck('reason_2', 'decision_2', 'cmdline_name', 'expected_2')]
48 # 2. prepare the parsed kconfig options
49 parsed_kconfig_options = OrderedDict()
50 parsed_kconfig_options['CONFIG_KCONFIG_NAME'] = 'UNexpected_1'
52 # 3. prepare the parsed cmdline options
53 parsed_cmdline_options = OrderedDict()
54 parsed_cmdline_options['cmdline_name'] = 'expected_2'
56 # 4. prepare the kernel version
57 kernel_version = (42, 43)
60 self.run_engine(config_checklist, parsed_kconfig_options, parsed_cmdline_options, kernel_version)
62 # 6. check that the results are correct
63 self.assertEqual('foo'.upper(), 'FOO')
66 self.assertTrue('FOO'.isupper())