Lines Matching +full:line +full:- +full:name

1 # SPDX-License-Identifier: GPL-2.0
4 # results with reader-friendly format. Stores and returns test results in a
28 status : TestStatus - status of the test
29 name : str - name of the test
30 expected_count : int - expected number of subtests (0 if single
32 subtests : List[Test] - list of subtests
33 log : List[str] - log of KTAP lines that correspond to the test
34 counts : TestCounts - counts of the test statuses and errors of
38 def __init__(self) -> None:
41 self.name = ''
47 def __str__(self) -> str:
49 return (f'Test({self.status}, {self.name}, {self.expected_count}, '
52 def __repr__(self) -> str:
56 def add_error(self, error_message: str) -> None:
59 stdout.print_with_timestamp(stdout.red('[ERROR]') + f' Test: {self.name}: {error_message}')
76 passed : int - the number of tests that have passed
77 failed : int - the number of tests that have failed
78 crashed : int - the number of tests that have crashed
79 skipped : int - the number of tests that have skipped
80 errors : int - the number of errors in the test and subtests
92 def __str__(self) -> str:
100 def total(self) -> int:
107 def add_subtest_counts(self, counts: TestCounts) -> None:
114 counts - a different TestCounts object whose counts
123 def get_status(self) -> TestStatus:
140 def add_status(self, status: TestStatus) -> None:
155 (line#, text).
169 def _get_next(self) -> None:
170 """Advances the LineSteam to the next line, if necessary."""
180 def peek(self) -> str:
181 """Returns the current line, without advancing the LineStream.
186 def pop(self) -> str:
187 """Returns the current line and advances the LineStream to
188 the next line.
192 raise ValueError(f'LineStream: going past EOF, last line was {s}')
196 def __bool__(self) -> bool:
202 def __iter__(self) -> Iterator[str]:
209 def line_number(self) -> int:
210 """Returns the line number of the current line."""
216 KTAP_START = re.compile(r'KTAP version ([0-9]+)$')
217 TAP_START = re.compile(r'TAP version ([0-9]+)$')
219 'Kernel panic - not syncing: VFS:|reboot: System halted)')
221 def extract_tap_lines(kernel_output: Iterable[str], lstrip=True) -> LineStream:
224 -> Iterator[Tuple[int, str]]:
227 for line in kernel_output:
229 line = line.rstrip() # remove trailing \n
230 if not started and KTAP_START.search(line):
232 # to number of characters before version line
234 line.split('KTAP version')[0])
236 yield line_num, line[prefix_len:]
237 elif not started and TAP_START.search(line):
239 # to number of characters before version line
240 prefix_len = len(line.split('TAP version')[0])
242 yield line_num, line[prefix_len:]
243 elif started and KTAP_END.search(line):
249 line = line[prefix_len:]
251 line = line.lstrip()
252 yield line_num, line
259 version_type: str, test: Test) -> None:
265 version_num - The inputted version number from the parsed KTAP or TAP
266 header line
267 accepted_version - List of accepted KTAP or TAP versions
268 version_type - 'KTAP' or 'TAP' depending on the type of
269 version line.
270 test - Test object for current test being parsed
277 def parse_ktap_header(lines: LineStream, test: Test) -> bool:
279 Parses KTAP/TAP header line and checks version number.
280 Returns False if fails to parse KTAP/TAP header line.
283 - 'KTAP version [version number]'
284 - 'TAP version [version number]'
287 lines - LineStream of KTAP output to parse
288 test - Test object for current test being parsed
291 True if successfully parsed KTAP/TAP header line
308 def parse_test_header(lines: LineStream, test: Test) -> bool:
310 Parses test header and stores test name in test object.
311 Returns False if fails to parse test header line.
314 - '# Subtest: [test name]'
317 lines - LineStream of KTAP output to parse
318 test - Test object for current test being parsed
321 True if successfully parsed test header line
327 test.name = match.group(1)
330 TEST_PLAN = re.compile(r'1\.\.([0-9]+)')
332 def parse_test_plan(lines: LineStream, test: Test) -> bool:
334 Parses test plan line and stores the expected number of subtests in
340 - '1..[number of subtests]'
343 lines - LineStream of KTAP output to parse
344 test - Test object for current test being parsed
347 True if successfully parsed test plan line
358 TEST_RESULT = re.compile(r'^(ok|not ok) ([0-9]+) (- )?([^#]*)( # .*)?$')
360 TEST_RESULT_SKIP = re.compile(r'^(ok|not ok) ([0-9]+) (- )?(.*) # SKIP(.*)$')
362 def peek_test_name_match(lines: LineStream, test: Test) -> bool:
364 Matches current line with the format of a test result line and checks
365 if the name matches the name of the current test.
366 Returns False if fails to match format or name.
369 - '[ok|not ok] [test number] [-] [test name] [optional skip
373 lines - LineStream of KTAP output to parse
374 test - Test object for current test being parsed
377 True if matched a test result line and the name matching the
378 expected test name
380 line = lines.peek()
381 match = TEST_RESULT.match(line)
384 name = match.group(4)
385 return name == test.name
388 expected_num: int) -> bool:
390 Parses test result line and stores the status and name in the test
393 Returns False if fails to parse test result line.
399 - '[ok|not ok] [test number] [-] [test name] [optional skip
403 lines - LineStream of KTAP output to parse
404 test - Test object for current test being parsed
405 expected_num - expected test number for current test
408 True if successfully parsed a test result line.
410 line = lines.peek()
411 match = TEST_RESULT.match(line)
412 skip_match = TEST_RESULT_SKIP.match(line)
414 # Check if line matches test result line format
419 # Set name of test object
421 test.name = skip_match.group(4)
423 test.name = match.group(4)
440 def parse_diagnostic(lines: LineStream) -> List[str]:
442 Parse lines that do not match the format of a test result line or
443 test header line and returns them in list.
445 Line formats that are not parsed:
446 - '# Subtest: [test name]'
447 - '[ok|not ok] [test number] [-] [test name] [optional skip
451 lines - LineStream of KTAP output to parse
467 def format_test_divider(message: str, len_message: int) -> str:
475 message - message to be centered in divider line
476 len_message - length of the message to be printed such that
485 difference = len(DIVIDER) - len_message - 2 # 2 spaces added
489 len_2 = difference - len_1
492 def print_test_header(test: Test) -> None:
494 Prints test header with test name and optionally the expected number
501 test - Test object representing current test being printed
503 message = test.name
511 def print_log(log: Iterable[str]) -> None:
516 def format_test_result(test: Test) -> str:
519 name.
525 test - Test object representing current test being printed
531 return stdout.green('[PASSED] ') + test.name
533 return stdout.yellow('[SKIPPED] ') + test.name
535 return stdout.yellow('[NO TESTS RUN] ') + test.name
538 return stdout.red('[CRASHED] ') + test.name
540 return stdout.red('[FAILED] ') + test.name
542 def print_test_result(test: Test) -> None:
544 Prints result line with status of test.
550 test - Test object representing current test being printed
554 def print_test_footer(test: Test) -> None:
562 test - Test object representing current test being printed
566 len(message) - stdout.color_len()))
568 def print_summary_line(test: Test) -> None:
570 Prints summary line of test object. Color of line is dependent on
572 skipped, and red if the test fails or crashes. Summary line contains
580 test - Test object representing current test being printed
592 def bubble_up_test_results(test: Test) -> None:
600 test - Test object for current test being parsed
612 def parse_test(lines: LineStream, expected_num: int, log: List[str]) -> Test:
616 information (status, name) about the test and the Test objects for
622 - Main KTAP/TAP header
630 - Subtest header line
634 # Subtest: name
637 ok 1 name
639 - Test result line
643 ok 1 - test
646 lines - LineStream of KTAP output to parse
647 expected_num - expected test number for test to be parsed
648 log - list of strings containing any preceding diagnostic lines
661 test.name = "main"
666 # header or test result line so parse attempt to parser
681 # result line with matching name to subtest header is found
705 # If not main test, look for test result line
711 test.add_error('missing subtest result line!')
731 def parse_run_tests(kernel_output: Iterable[str]) -> Test:
734 results and print condensed test results and summary line.
737 kernel_output - Iterable object contains lines of kernel output
740 Test - the main test object with all subtests.
746 test.name = '<missing>'