1 # SPDX-License-Identifier: GPL-2.0
2 # Copyright 2024 Google LLC
7 # List of test suites we expect to find with 'ut info' and 'ut all'
9 'addrmap', 'bdinfo', 'bloblist', 'bootm', 'bootstd',
10 'cmd', 'common', 'dm', 'env', 'exit',
11 'fdt', 'font', 'hush', 'lib',
12 'loadm', 'log', 'mbr', 'measurement', 'mem',
13 'overlay', 'pci_mps', 'setexpr', 'upl',
17 # Set this to True to aid debugging of tests
21 def collect_info(cons, output):
22 """Process the output from 'ut all'
25 cons: U-Boot console object
26 output: Output from running 'ut all'
30 set: suite names that were found in output
31 set: test names that were found in output
32 dict: test count for each suite:
34 value: number of tests for the suite found in output
35 set: missing suites (compared to EXPECTED_SUITES)
36 set: extra suites (compared to EXPECTED_SUITES)
45 for line in output.splitlines():
48 cons.log.info(f'line: {line}')
49 m = re.search('----Running ([^ ]*) tests----', line)
51 if DEBUG_ME and cur_suite and cur_suite != 'info':
52 cons.log.info(f'suite: {cur_suite} expected {exp_test_count[cur_suite]} found {test_count}')
54 cur_suite = m.group(1)
56 cons.log.info(f'cur_suite: {cur_suite}')
60 m = re.match(rf'Running (\d+) {cur_suite} tests', line)
62 exp_test_count[cur_suite] = int(m.group(1))
63 m = re.search(r'Test: (\w*): ([-a-z0-9_]*\.c)?( .*)?', line)
65 test_name = m.group(1)
68 cons.log.info(f"test_name {test_name} msg '{msg}'")
69 if msg == ' (flat tree)' and test_name not in tests:
72 if not msg or 'skipped as it is manual' in msg:
76 cons.log.info(f'test_count {test_count}')
78 cons.log.info(f'suite: {cur_suite} expected {exp_test_count[cur_suite]} found {test_count}')
79 cons.log.info(f"Tests: {' '.join(sorted(list(tests)))}")
81 # Figure out what is missing, or extra
84 for suite in EXPECTED_SUITES:
90 return suites, tests, exp_test_count, missing, extra
93 def process_ut_info(cons, output):
94 """Process the output of the 'ut info' command
97 cons: U-Boot console object
98 output: Output from running 'ut all'
102 int: Number of suites reported
103 int: Number of tests reported
104 dict: test count for each suite:
106 value: number of tests reported for the suite
110 total_test_count = None
112 for line in output.splitlines():
115 cons.log.info(f'line: {line}')
116 m = re.match(r'Test suites: (.*)', line)
118 suite_count = int(m.group(1))
119 m = re.match(r'Total tests: (.*)', line)
121 total_test_count = int(m.group(1))
122 m = re.match(r' *([0-9?]*) (\w*)', line)
124 test_count[m.group(2)] = m.group(1)
125 return suite_count, total_test_count, test_count
128 @pytest.mark.buildconfigspec('sandbox')
129 @pytest.mark.notbuildconfigspec('sandbox_spl')
130 @pytest.mark.notbuildconfigspec('sandbox64')
131 # This test is disabled since it fails; remove the leading 'x' to try it
132 def xtest_suite(u_boot_console, u_boot_config):
133 """Perform various checks on the unit tests, including:
135 - The number of suites matches that reported by the 'ut info'
136 - Where available, the number of tests is each suite matches that
137 reported by 'ut info -s'
138 - The total number of tests adds up to the total that are actually run
140 - All suites are run with 'ut all'
141 - The expected set of suites is run (the list is hard-coded in this test)
144 cons = u_boot_console
145 buildconfig = u_boot_config.buildconfig
146 with cons.log.section('Run all unit tests'):
147 # ut hush hush_test_simple_dollar prints "Unknown command" on purpose.
148 with u_boot_console.disable_check('unknown_command'):
149 output = cons.run_command('ut all')
151 # Process the output from the run
152 with cons.log.section('Check output'):
153 suites, all_tests, exp_test_count, missing, extra = collect_info(cons,
155 cons.log.info(f'missing {missing}')
156 cons.log.info(f'extra {extra}')
158 # Make sure we got a test count for each suite
159 assert not (suites - exp_test_count.keys())
161 # Deal with missing suites
162 with cons.log.section('Check missing suites'):
163 if 'config_cmd_seama' not in buildconfig:
164 cons.log.info("CMD_SEAMA not enabled: Ignoring suite 'seama'")
165 missing.discard('seama')
167 # Run 'ut info' and compare with the log results
168 with cons.log.section('Check suite test-counts'):
169 output = cons.run_command('ut info -s')
171 suite_count, total_test_count, test_count = process_ut_info(cons,
175 cons.log.info(f"suites: {' '.join(sorted(list(suites)))}")
176 cons.log.error(f'missing: {sorted(list(missing))}')
177 cons.log.error(f'extra: {sorted(list(extra))}')
179 assert not missing, f'Missing suites {missing}'
180 assert not extra, f'Extra suites {extra}'
182 cons.log.info(str(exp_test_count))
183 for suite in EXPECTED_SUITES:
184 assert test_count[suite] in ['?', str(exp_test_count[suite])], \
185 f'suite {suite} expected {exp_test_count[suite]}'
187 assert suite_count == len(EXPECTED_SUITES)
188 assert total_test_count == len(all_tests)