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
19 class TestEngine(unittest.TestCase):
21 Example test scenario:
23 # 1. prepare the checklist
25 config_checklist += [KconfigCheck('reason_1', 'decision_1', 'KCONFIG_NAME', 'expected_1')]
26 config_checklist += [CmdlineCheck('reason_2', 'decision_2', 'cmdline_name', 'expected_2')]
28 # 2. prepare the parsed kconfig options
29 parsed_kconfig_options = OrderedDict()
30 parsed_kconfig_options['CONFIG_KCONFIG_NAME'] = 'UNexpected_1'
32 # 3. prepare the parsed cmdline options
33 parsed_cmdline_options = OrderedDict()
34 parsed_cmdline_options['cmdline_name'] = 'expected_2'
36 # 4. prepare the kernel version
37 kernel_version = (42, 43)
41 self.run_engine(config_checklist,
42 parsed_kconfig_options, parsed_cmdline_options, kernel_version,
45 # 6. check that the results are correct
46 # self.assertEqual(...
50 def run_engine(checklist, parsed_kconfig_options, parsed_cmdline_options, kernel_version):
51 # populate the checklist with data
52 populate_with_data(checklist, parsed_kconfig_options, 'kconfig')
53 populate_with_data(checklist, parsed_cmdline_options, 'cmdline')
54 populate_with_data(checklist, kernel_version, 'version')
56 # now everything is ready, perform the checks
57 perform_checks(checklist)
59 # print the results in JSON
63 output.append(opt.json_dump(True)) # with_results
64 print(json.dumps(output))
66 # print the table with the results
69 opt.table_print(None, True) # default mode, with_results
74 # 1. prepare the checklist
76 config_checklist += [KconfigCheck('reason_1', 'decision_1', 'KCONFIG_NAME', 'expected_1')]
77 config_checklist += [CmdlineCheck('reason_2', 'decision_2', 'cmdline_name', 'expected_2')]
79 # 2. prepare the parsed kconfig options
80 parsed_kconfig_options = OrderedDict()
81 parsed_kconfig_options['CONFIG_KCONFIG_NAME'] = 'UNexpected_1'
83 # 3. prepare the parsed cmdline options
84 parsed_cmdline_options = OrderedDict()
85 parsed_cmdline_options['cmdline_name'] = 'expected_2'
87 # 4. prepare the kernel version
88 kernel_version = (42, 43)
91 self.run_engine(config_checklist, parsed_kconfig_options, parsed_cmdline_options, kernel_version)
93 # 6. check that the results are correct
94 self.assertEqual('foo'.upper(), 'FOO')
97 self.assertTrue('FOO'.isupper())