Skip to content
/ linux Public
forked from torvalds/linux

Commit

Permalink
Merge tag 'linux-kselftest-kunit-fixes-5.14-rc2' of git://git.kernel.…
Browse files Browse the repository at this point in the history
…org/pub/scm/linux/kernel/git/shuah/linux-kselftest

Pull kunit fixes from Shuah Khan:
 "Fixes to kunit tool and documentation:

   - fix asserts on older python versions

   - fixes to misleading error messages when TAP header format is
     incorrect or when file is missing

   - documentation fix: drop obsolete information about uml_abort
     coverage

   - remove unnecessary annotations"

* tag 'linux-kselftest-kunit-fixes-5.14-rc2' of git://git.kernel.org/pub/scm/linux/kernel/git/shuah/linux-kselftest:
  kunit: tool: Assert the version requirement
  kunit: tool: remove unnecessary "annotations" import
  Documentation: kunit: drop obsolete note about uml_abort for coverage
  kunit: tool: Fix error messages for cases of no tests and wrong TAP header
  • Loading branch information
torvalds committed Jul 17, 2021
2 parents 00397e7 + df4b080 commit ccbb22b
Show file tree
Hide file tree
Showing 7 changed files with 24 additions and 22 deletions.
14 changes: 1 addition & 13 deletions Documentation/dev-tools/kunit/running_tips.rst
Original file line number Diff line number Diff line change
Expand Up @@ -86,19 +86,7 @@ Generating code coverage reports under UML
.. note::
TODO([email protected]): There are various issues with UML and
versions of gcc 7 and up. You're likely to run into missing ``.gcda``
files or compile errors. We know one `faulty GCC commit
<https://github.com/gcc-mirror/gcc/commit/8c9434c2f9358b8b8bad2c1990edf10a21645f9d>`_
but not how we'd go about getting this fixed. The compile errors still
need some investigation.

.. note::
TODO([email protected]): for recent versions of Linux
(5.10-5.12, maybe earlier), there's a bug with gcov counters not being
flushed in UML. This translates to very low (<1%) reported coverage. This is
related to the above issue and can be worked around by replacing the
one call to ``uml_abort()`` (it's in ``os_dump_core()``) with a plain
``exit()``.

files or compile errors.

This is different from the "normal" way of getting coverage information that is
documented in Documentation/dev-tools/gcov.rst.
Expand Down
2 changes: 2 additions & 0 deletions tools/testing/kunit/kunit.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,8 @@
import os
import time

assert sys.version_info >= (3, 7), "Python version is too old"

from collections import namedtuple
from enum import Enum, auto

Expand Down
6 changes: 2 additions & 4 deletions tools/testing/kunit/kunit_kernel.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,15 +6,13 @@
# Author: Felix Guo <[email protected]>
# Author: Brendan Higgins <[email protected]>

from __future__ import annotations
import importlib.util
import logging
import subprocess
import os
import shutil
import signal
from typing import Iterator
from typing import Optional
from typing import Iterator, Optional, Tuple

from contextlib import ExitStack

Expand Down Expand Up @@ -208,7 +206,7 @@ def get_source_tree_ops(arch: str, cross_compile: Optional[str]) -> LinuxSourceT
raise ConfigError(arch + ' is not a valid arch')

def get_source_tree_ops_from_qemu_config(config_path: str,
cross_compile: Optional[str]) -> tuple[
cross_compile: Optional[str]) -> Tuple[
str, LinuxSourceTreeOperations]:
# The module name/path has very little to do with where the actual file
# exists (I learned this through experimentation and could not find it
Expand Down
6 changes: 4 additions & 2 deletions tools/testing/kunit/kunit_parser.py
Original file line number Diff line number Diff line change
Expand Up @@ -338,9 +338,11 @@ def bubble_up_suite_errors(test_suites: Iterable[TestSuite]) -> TestStatus:
def parse_test_result(lines: LineStream) -> TestResult:
consume_non_diagnostic(lines)
if not lines or not parse_tap_header(lines):
return TestResult(TestStatus.NO_TESTS, [], lines)
return TestResult(TestStatus.FAILURE_TO_PARSE_TESTS, [], lines)
expected_test_suite_num = parse_test_plan(lines)
if not expected_test_suite_num:
if expected_test_suite_num == 0:
return TestResult(TestStatus.NO_TESTS, [], lines)
elif expected_test_suite_num is None:
return TestResult(TestStatus.FAILURE_TO_PARSE_TESTS, [], lines)
test_suites = []
for i in range(1, expected_test_suite_num + 1):
Expand Down
16 changes: 13 additions & 3 deletions tools/testing/kunit/kunit_tool_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -157,8 +157,18 @@ def test_parse_failed_test_log(self):
kunit_parser.TestStatus.FAILURE,
result.status)

def test_no_header(self):
empty_log = test_data_path('test_is_test_passed-no_tests_run_no_header.log')
with open(empty_log) as file:
result = kunit_parser.parse_run_tests(
kunit_parser.extract_tap_lines(file.readlines()))
self.assertEqual(0, len(result.suites))
self.assertEqual(
kunit_parser.TestStatus.FAILURE_TO_PARSE_TESTS,
result.status)

def test_no_tests(self):
empty_log = test_data_path('test_is_test_passed-no_tests_run.log')
empty_log = test_data_path('test_is_test_passed-no_tests_run_with_header.log')
with open(empty_log) as file:
result = kunit_parser.parse_run_tests(
kunit_parser.extract_tap_lines(file.readlines()))
Expand All @@ -173,7 +183,7 @@ def test_no_kunit_output(self):
with open(crash_log) as file:
result = kunit_parser.parse_run_tests(
kunit_parser.extract_tap_lines(file.readlines()))
print_mock.assert_any_call(StrContains('no tests run!'))
print_mock.assert_any_call(StrContains('could not parse test results!'))
print_mock.stop()
file.close()

Expand Down Expand Up @@ -309,7 +319,7 @@ def test_crashed_test_json(self):
result["sub_groups"][1]["test_cases"][0])

def test_no_tests_json(self):
result = self._json_for('test_is_test_passed-no_tests_run.log')
result = self._json_for('test_is_test_passed-no_tests_run_with_header.log')
self.assertEqual(0, len(result['sub_groups']))

class StrContains(str):
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
TAP version 14
1..0

0 comments on commit ccbb22b

Please sign in to comment.