Lines Matching +full:in +full:- +full:line

1 # SPDX-License-Identifier: GPL-2.0
4 # results with reader-friendly format. Stores and returns test results in a
25 results within a test log are stored in a main Test object as
29 status : TestStatus - status of the test
30 name : str - name of the test
31 expected_count : int - expected number of subtests (0 if single
33 subtests : List[Test] - list of subtests
34 log : List[str] - log of KTAP lines that correspond to the test
35 counts : TestCounts - counts of the test statuses and errors of
39 def __init__(self) -> None:
48 def __str__(self) -> str:
53 def __repr__(self) -> str:
57 def add_error(self, printer: Printer, error_message: str) -> None:
62 def ok_status(self) -> bool:
64 return self.status in (TestStatus.SUCCESS, TestStatus.SKIPPED)
87 def __str__(self) -> str:
93 ', '.join(f'{s}: {n}' for s, n in statuses if n > 0)
95 def total(self) -> int:
102 def add_subtest_counts(self, counts: TestCounts) -> None:
109 counts - a different TestCounts object whose counts
118 def get_status(self) -> TestStatus:
135 def add_status(self, status: TestStatus) -> None:
150 (line#, text).
164 def _get_next(self) -> None:
165 """Advances the LineSteam to the next line, if necessary."""
175 def peek(self) -> str:
176 """Returns the current line, without advancing the LineStream.
181 def pop(self) -> str:
182 """Returns the current line and advances the LineStream to
183 the next line.
187 raise ValueError(f'LineStream: going past EOF, last line was {s}')
191 def __bool__(self) -> bool:
197 def __iter__(self) -> Iterator[str]:
198 """Empties all lines stored in LineStream object into
204 def line_number(self) -> int:
205 """Returns the line number of the current line."""
211 KTAP_START = re.compile(r'\s*KTAP version ([0-9]+)$')
212 TAP_START = re.compile(r'\s*TAP version ([0-9]+)$')
214 'Kernel panic - not syncing: VFS:|reboot: System halted)')
217 def extract_tap_lines(kernel_output: Iterable[str]) -> LineStream:
220 -> Iterator[Tuple[int, str]]:
223 for line in kernel_output:
225 line = line.rstrip() # remove trailing \n
226 if not started and KTAP_START.search(line):
228 # to number of characters before version line
230 line.split('KTAP version')[0])
232 yield line_num, line[prefix_len:]
233 elif not started and TAP_START.search(line):
235 # to number of characters before version line
236 prefix_len = len(line.split('TAP version')[0])
238 yield line_num, line[prefix_len:]
239 elif started and KTAP_END.search(line):
244 line = line[prefix_len:]
245 yield line_num, line
246 elif EXECUTOR_ERROR.search(line):
247 yield line_num, line
254 version_type: str, test: Test, printer: Printer) -> None:
260 version_num - The inputted version number from the parsed KTAP or TAP
261 header line
262 accepted_version - List of accepted KTAP or TAP versions
263 version_type - 'KTAP' or 'TAP' depending on the type of
264 version line.
265 test - Test object for current test being parsed
266 printer - Printer object to output error
273 def parse_ktap_header(lines: LineStream, test: Test, printer: Printer) -> bool:
275 Parses KTAP/TAP header line and checks version number.
276 Returns False if fails to parse KTAP/TAP header line.
279 - 'KTAP version [version number]'
280 - 'TAP version [version number]'
283 lines - LineStream of KTAP output to parse
284 test - Test object for current test being parsed
285 printer - Printer object to output results
288 True if successfully parsed KTAP/TAP header line
305 def parse_test_header(lines: LineStream, test: Test) -> bool:
307 Parses test header and stores test name in test object.
308 Returns False if fails to parse test header line.
311 - '# Subtest: [test name]'
314 lines - LineStream of KTAP output to parse
315 test - Test object for current test being parsed
318 True if successfully parsed test header line
327 TEST_PLAN = re.compile(r'^\s*1\.\.([0-9]+)')
329 def parse_test_plan(lines: LineStream, test: Test) -> bool:
331 Parses test plan line and stores the expected number of subtests in
337 - '1..[number of subtests]'
340 lines - LineStream of KTAP output to parse
341 test - Test object for current test being parsed
344 True if successfully parsed test plan line
355 TEST_RESULT = re.compile(r'^\s*(ok|not ok) ([0-9]+) ?(- )?([^#]*)( # .*)?$')
357 TEST_RESULT_SKIP = re.compile(r'^\s*(ok|not ok) ([0-9]+) ?(- )?(.*) # SKIP ?(.*)$')
359 def peek_test_name_match(lines: LineStream, test: Test) -> bool:
361 Matches current line with the format of a test result line and checks
366 - '[ok|not ok] [test number] [-] [test name] [optional skip
370 lines - LineStream of KTAP output to parse
371 test - Test object for current test being parsed
374 True if matched a test result line and the name matching the
377 line = lines.peek()
378 match = TEST_RESULT.match(line)
387 expected_num: int, printer: Printer) -> bool:
389 Parses test result line and stores the status and name in the test
392 Returns False if fails to parse test result line.
395 change in status.
398 - '[ok|not ok] [test number] [-] [test name] [optional skip
402 lines - LineStream of KTAP output to parse
403 test - Test object for current test being parsed
404 expected_num - expected test number for current test
405 printer - Printer object to output results
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
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
449 - 'KTAP version [version number]'
452 lines - LineStream of KTAP output to parse
460 for re in non_diagnostic_lines):
469 def format_test_divider(message: str, len_message: int) -> str:
471 Returns string with message centered in fixed width divider.
477 message - message to be centered in divider line
478 len_message - length of the message to be printed such that
482 String containing message centered in fixed width divider
487 difference = len(DIVIDER) - len_message - 2 # 2 spaces added
491 len_2 = difference - len_1
494 def print_test_header(test: Test, printer: Printer) -> None:
503 test - Test object representing current test being printed
504 printer - Printer object to output results
509 # is provided using a "# Subtest" header line.
518 def print_log(log: Iterable[str], printer: Printer) -> None:
519 """Prints all strings in saved log for test in yellow."""
521 for line in formatted.splitlines():
522 printer.print_with_timestamp(printer.yellow(line))
524 def format_test_result(test: Test, printer: Printer) -> str:
533 test - Test object representing current test being printed
534 printer - Printer object to output results
551 def print_test_result(test: Test, printer: Printer) -> None:
553 Prints result line with status of test.
559 test - Test object representing current test being printed
560 printer - Printer object
564 def print_test_footer(test: Test, printer: Printer) -> None:
572 test - Test object representing current test being printed
573 printer - Printer object to output results
577 len(message) - printer.color_len()))
579 def print_test(test: Test, failed_only: bool, printer: Printer) -> None:
581 Prints Test object to given printer. For a child test, the result line is
587 test - Test object to print
588 failed_only - True if only failed/crashed tests should be printed.
589 printer - Printer object to output results
593 for subtest in test.subtests:
599 for subtest in test.subtests:
606 def _summarize_failed_tests(test: Test) -> str:
607 """Tries to summarize all the failing subtests in `test`."""
609 def failed_names(test: Test, parent_name: str) -> List[str]:
610 # Note: we use 'main' internally for the top-level test.
620 # Don't summarize it down "the top-level test failed", though.
621 failed_subtests = [sub for sub in test.subtests if not sub.ok_status()]
626 for t in failed_subtests:
638 def print_summary_line(test: Test, printer: Printer) -> None:
640 Prints summary line of test object. Color of line is dependent on
642 skipped, and red if the test fails or crashes. Summary line contains
650 test - Test object representing current test being printed
651 printer - Printer object to output results
655 elif test.status in (TestStatus.SKIPPED, TestStatus.NO_TESTS):
661 # Summarize failures that might have gone off-screen since we had a lot
672 def bubble_up_test_results(test: Test) -> None:
680 test - Test object for current test being parsed
685 for t in subtests:
692 def parse_test(lines: LineStream, expected_num: int, log: List[str], is_subtest: bool, printer: Printer) -> Test:
694 Finds next test to parse in LineStream, creates new Test object,
702 - Main KTAP/TAP header
710 - Subtest header (must include either the KTAP version line or
711 "# Subtest" header line)
713 Example (preferred format with both KTAP version line and
714 "# Subtest" line):
722 Example (only "# Subtest" line):
729 Example (only KTAP version line, compliant with KTAP v1 spec):
736 - Test result line
740 ok 1 - test
743 lines - LineStream of KTAP output to parse
744 expected_num - expected test number for test to be parsed
745 log - list of strings containing any preceding diagnostic lines
747 is_subtest - boolean indicating whether test is a subtest
748 printer - Printer object to output results
761 # If parsing the main/top-level test, parse KTAP version line and
770 # the KTAP version line and/or subtest header line
786 # result line with matching name to subtest header is found
787 # or no more lines in stream.
810 # If not main test, look for test result line
813 test.add_error(printer, 'missing subtest result line!')
825 if test.status in (TestStatus.TEST_CRASHED, TestStatus.SUCCESS):
830 # Add statuses to TestCounts attribute in Test object
840 def parse_run_tests(kernel_output: Iterable[str], printer: Printer) -> Test:
843 results and print condensed test results and summary line.
846 kernel_output - Iterable object contains lines of kernel output
847 printer - Printer object to output results
850 Test - the main test object with all subtests.