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
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:
42 self.name = ''
48 def __str__(self) -> str:
50 return (f'Test({self.status}, {self.name}, {self.expected_count}, '
53 def __repr__(self) -> str:
57 def add_error(self, printer: Printer, error_message: str) -> None:
60 printer.print_with_timestamp(stdout.red('[ERROR]') + f' Test: {self.name}: {error_message}')
62 def ok_status(self) -> bool:
87 def __str__(self) -> str:
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]:
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
323 test.name = match.group(1)
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
362 if the name matches the name of the current test.
363 Returns False if fails to match format or name.
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
375 expected test name
377 line = lines.peek()
378 match = TEST_RESULT.match(line)
381 name = match.group(4)
382 return name == test.name
385 expected_num: int, printer: Printer) -> bool:
387 Parses test result line and stores the status and name in the test
390 Returns False if fails to parse test result line.
396 - '[ok|not ok] [test number] [-] [test name] [optional skip
400 lines - LineStream of KTAP output to parse
401 test - Test object for current test being parsed
402 expected_num - expected test number for current test
403 printer - Printer object to output results
406 True if successfully parsed a test result line.
408 line = lines.peek()
409 match = TEST_RESULT.match(line)
410 skip_match = TEST_RESULT_SKIP.match(line)
412 # Check if line matches test result line format
417 # Set name of test object
419 test.name = skip_match.group(4)
421 test.name = match.group(4)
438 def parse_diagnostic(lines: LineStream) -> List[str]:
440 Parse lines that do not match the format of a test result line or
441 test header line and returns them in list.
443 Line formats that are not parsed:
444 - '# Subtest: [test name]'
445 - '[ok|not ok] [test number] [-] [test name] [optional skip
447 - 'KTAP version [version number]'
450 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, printer: Printer) -> None:
494 Prints test header with test name and optionally the expected number
501 test - Test object representing current test being printed
502 printer - Printer object to output results
504 message = test.name
506 # Add a leading space before the subtest counts only if a test name
507 # is provided using a "# Subtest" header line.
516 def print_log(log: Iterable[str], printer: Printer) -> None:
519 for line in formatted.splitlines():
520 printer.print_with_timestamp(printer.yellow(line))
522 def format_test_result(test: Test, printer: Printer) -> str:
525 name.
531 test - Test object representing current test being printed
532 printer - Printer object to output results
538 return printer.green('[PASSED] ') + test.name
540 return printer.yellow('[SKIPPED] ') + test.name
542 return printer.yellow('[NO TESTS RUN] ') + test.name
545 return stdout.red('[CRASHED] ') + test.name
547 return printer.red('[FAILED] ') + test.name
549 def print_test_result(test: Test, printer: Printer) -> None:
551 Prints result line with status of test.
557 test - Test object representing current test being printed
558 printer - Printer object
562 def print_test_footer(test: Test, printer: Printer) -> None:
570 test - Test object representing current test being printed
571 printer - Printer object to output results
575 len(message) - printer.color_len()))
577 def print_test(test: Test, failed_only: bool, printer: Printer) -> None:
579 Prints Test object to given printer. For a child test, the result line is
585 test - Test object to print
586 failed_only - True if only failed/crashed tests should be printed.
587 printer - Printer object to output results
589 if test.name == "main":
604 def _summarize_failed_tests(test: Test) -> str:
607 def failed_names(test: Test, parent_name: str) -> List[str]:
608 # Note: we use 'main' internally for the top-level test.
610 full_name = test.name
612 full_name = parent_name + '.' + test.name
618 # Don't summarize it down "the top-level test failed", though.
636 def print_summary_line(test: Test, printer: Printer) -> None:
638 Prints summary line of test object. Color of line is dependent on
640 skipped, and red if the test fails or crashes. Summary line contains
648 test - Test object representing current test being printed
649 printer - Printer object to output results
659 # Summarize failures that might have gone off-screen since we had a lot
670 def bubble_up_test_results(test: Test) -> None:
678 test - Test object for current test being parsed
690 …(lines: LineStream, expected_num: int, log: List[str], is_subtest: bool, printer: Printer) -> Test:
694 information (status, name) about the test and the Test objects for
700 - Main KTAP/TAP header
708 - Subtest header (must include either the KTAP version line or
709 "# Subtest" header line)
711 Example (preferred format with both KTAP version line and
712 "# Subtest" line):
715 # Subtest: name
718 ok 1 name
720 Example (only "# Subtest" line):
722 # Subtest: name
725 ok 1 name
727 Example (only KTAP version line, compliant with KTAP v1 spec):
732 ok 1 name
734 - Test result line
738 ok 1 - test
741 lines - LineStream of KTAP output to parse
742 expected_num - expected test number for test to be parsed
743 log - list of strings containing any preceding diagnostic lines
745 is_subtest - boolean indicating whether test is a subtest
746 printer - Printer object to output results
759 # If parsing the main/top-level test, parse KTAP version line and
761 test.name = "main"
768 # the KTAP version line and/or subtest header line
773 # If KTAP version line and/or subtest header is found, attempt
785 # result line with matching name to subtest header is found
809 # If not main test, look for test result line
811 if test.name != "" and not peek_test_name_match(lines, test):
812 test.add_error(printer, 'missing subtest result line!')
835 def parse_run_tests(kernel_output: Iterable[str], printer: Printer) -> Test:
838 results and print condensed test results and summary line.
841 kernel_output - Iterable object contains lines of kernel output
842 printer - Printer object to output results
845 Test - the main test object with all subtests.
851 test.name = '<missing>'