Resguardo inicial

This commit is contained in:
lastdragon
2026-09-06 12:53:21 -06:00
parent 662efe3c2a
commit ad2088d178
94853 changed files with 43200404 additions and 0 deletions
@@ -0,0 +1,4 @@
# SPDX-License-Identifier: GPL-2.0-only
# Byte-compiled / optimized / DLL files
__pycache__/
*.py[cod]
@@ -0,0 +1,61 @@
# This config enables as many tests as possible under UML.
# It is intended for use in continuous integration systems and similar for
# automated testing of as much as possible.
# The config is manually maintained, though it uses KUNIT_ALL_TESTS=y to enable
# any tests whose dependencies are already satisfied. Please feel free to add
# more options if they any new tests.
CONFIG_KUNIT=y
CONFIG_KUNIT_EXAMPLE_TEST=y
CONFIG_KUNIT_ALL_TESTS=y
CONFIG_FORTIFY_SOURCE=y
CONFIG_IIO=y
CONFIG_EXT4_FS=y
CONFIG_MSDOS_FS=y
CONFIG_VFAT_FS=y
CONFIG_PCI=y
CONFIG_USB4=y
CONFIG_I2C=y
CONFIG_NET=y
CONFIG_MCTP=y
CONFIG_MCTP_FLOWS=y
CONFIG_INET=y
CONFIG_MPTCP=y
CONFIG_NETDEVICES=y
CONFIG_WLAN=y
CONFIG_CFG80211=y
CONFIG_MAC80211=y
CONFIG_WLAN_VENDOR_INTEL=y
CONFIG_IWLWIFI=y
CONFIG_DAMON=y
CONFIG_DAMON_VADDR=y
CONFIG_DAMON_PADDR=y
CONFIG_REGMAP_BUILD=y
CONFIG_AUDIT=y
CONFIG_CRYPTO_LIB_ENABLE_ALL_FOR_KUNIT=y
CONFIG_PRIME_NUMBERS=y
CONFIG_CRC_ENABLE_ALL_FOR_KUNIT=y
CONFIG_SECURITY=y
CONFIG_SECURITY_APPARMOR=y
CONFIG_SECURITY_LANDLOCK=y
CONFIG_SOUND=y
CONFIG_SND=y
CONFIG_SND_SOC=y
CONFIG_SND_SOC_TOPOLOGY_BUILD=y
CONFIG_SND_SOC_CS35L56_I2C=y
@@ -0,0 +1,7 @@
# Config options which are added to UML builds by default
# Enable pci, as a lot of tests require it.
CONFIG_KUNIT_UML_PCI=y
# Enable FORTIFY_SOURCE for wider checking.
CONFIG_FORTIFY_SOURCE=y
@@ -0,0 +1,11 @@
# This config fragment enables coverage on UML, which is different from the
# normal gcov used in other arches (no debugfs).
# Example usage:
# ./tools/testing/kunit/kunit.py run \
# --kunitconfig=tools/testing/kunit/configs/all_tests_uml.config \
# --kunitconfig=tools/testing/kunit/configs/coverage_uml.config
CONFIG_DEBUG_KERNEL=y
CONFIG_DEBUG_INFO=y
CONFIG_DEBUG_INFO_DWARF_TOOLCHAIN_DEFAULT=y
CONFIG_GCOV=y
@@ -0,0 +1,3 @@
CONFIG_KUNIT=y
CONFIG_KUNIT_EXAMPLE_TEST=y
CONFIG_KUNIT_ALL_TESTS=y
@@ -0,0 +1,34 @@
# SPDX-License-Identifier: GPL-2.0
# bash completion support for KUnit
_kunit_dir=$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)
_kunit()
{
local cur prev words cword
_init_completion || return
local script="${_kunit_dir}/kunit.py"
if [[ $cword -eq 1 && "$cur" != -* ]]; then
local cmds=$(${script} --list-cmds 2>/dev/null)
COMPREPLY=($(compgen -W "${cmds}" -- "$cur"))
return 0
fi
if [[ "$cur" == -* ]]; then
if [[ -n "${words[1]}" && "${words[1]}" != -* ]]; then
local opts=$(${script} ${words[1]} --list-opts 2>/dev/null)
COMPREPLY=($(compgen -W "${opts}" -- "$cur"))
return 0
else
local opts=$(${script} --list-opts 2>/dev/null)
COMPREPLY=($(compgen -W "${opts}" -- "$cur"))
return 0
fi
fi
}
complete -o default -F _kunit kunit.py
complete -o default -F _kunit kunit
complete -o default -F _kunit ./tools/testing/kunit/kunit.py
+688
View File
@@ -0,0 +1,688 @@
#!/usr/bin/env python3
# SPDX-License-Identifier: GPL-2.0
#
# A thin wrapper on top of the KUnit Kernel
#
# Copyright (C) 2019, Google LLC.
# Author: Felix Guo <felixguoxiuping@gmail.com>
# Author: Brendan Higgins <brendanhiggins@google.com>
import argparse
import os
import re
import shlex
import sys
import time
assert sys.version_info >= (3, 7), "Python version is too old"
from dataclasses import dataclass
from enum import Enum, auto
from typing import Iterable, List, Optional, Sequence, Tuple
import kunit_json
import kunit_junit
import kunit_kernel
import kunit_parser
from kunit_printer import stdout, null_printer
class KunitStatus(Enum):
SUCCESS = auto()
CONFIG_FAILURE = auto()
BUILD_FAILURE = auto()
TEST_FAILURE = auto()
@dataclass
class KunitResult:
status: KunitStatus
elapsed_time: float
@dataclass
class KunitConfigRequest:
build_dir: str
make_options: Optional[List[str]]
@dataclass
class KunitBuildRequest(KunitConfigRequest):
jobs: int
@dataclass
class KunitParseRequest:
raw_output: Optional[str]
json: Optional[str]
junit: Optional[str]
summary: bool
failed: bool
@dataclass
class KunitExecRequest(KunitParseRequest):
build_dir: str
timeout: int
filter_glob: str
filter: str
filter_action: Optional[str]
kernel_args: Optional[List[str]]
run_isolated: Optional[str]
list_tests: bool
list_tests_attr: bool
list_suites: bool
@dataclass
class KunitRequest(KunitExecRequest, KunitBuildRequest):
pass
def get_kernel_root_path() -> str:
path = sys.argv[0] if not __file__ else __file__
parts = os.path.realpath(path).split('tools/testing/kunit')
if len(parts) != 2:
sys.exit(1)
return parts[0]
def config_tests(linux: kunit_kernel.LinuxSourceTree,
request: KunitConfigRequest) -> KunitResult:
stdout.print_with_timestamp('Configuring KUnit Kernel ...')
config_start = time.time()
success = linux.build_reconfig(request.build_dir, request.make_options)
config_end = time.time()
status = KunitStatus.SUCCESS if success else KunitStatus.CONFIG_FAILURE
return KunitResult(status, config_end - config_start)
def build_tests(linux: kunit_kernel.LinuxSourceTree,
request: KunitBuildRequest) -> KunitResult:
stdout.print_with_timestamp('Building KUnit Kernel ...')
build_start = time.time()
success = linux.build_kernel(request.jobs,
request.build_dir,
request.make_options)
build_end = time.time()
status = KunitStatus.SUCCESS if success else KunitStatus.BUILD_FAILURE
return KunitResult(status, build_end - build_start)
def config_and_build_tests(linux: kunit_kernel.LinuxSourceTree,
request: KunitBuildRequest) -> KunitResult:
config_result = config_tests(linux, request)
if config_result.status != KunitStatus.SUCCESS:
return config_result
return build_tests(linux, request)
def _list_tests(linux: kunit_kernel.LinuxSourceTree, request: KunitExecRequest) -> List[str]:
args = ['kunit.action=list']
if request.kernel_args:
args.extend(request.kernel_args)
output = linux.run_kernel(args=args,
timeout=request.timeout,
filter_glob=request.filter_glob,
filter=request.filter,
filter_action=request.filter_action,
build_dir=request.build_dir)
lines = kunit_parser.extract_tap_lines(output)
# Hack! Drop the dummy TAP version header that the executor prints out.
lines.pop()
# Filter out any extraneous non-test output that might have gotten mixed in.
return [l for l in output if re.match(r'^[^\s.]+\.[^\s.]+$', l)]
def _list_tests_attr(linux: kunit_kernel.LinuxSourceTree, request: KunitExecRequest) -> Iterable[str]:
args = ['kunit.action=list_attr']
if request.kernel_args:
args.extend(request.kernel_args)
output = linux.run_kernel(args=args,
timeout=request.timeout,
filter_glob=request.filter_glob,
filter=request.filter,
filter_action=request.filter_action,
build_dir=request.build_dir)
lines = kunit_parser.extract_tap_lines(output)
# Hack! Drop the dummy TAP version header that the executor prints out.
lines.pop()
# Filter out any extraneous non-test output that might have gotten mixed in.
return lines
def _suites_from_test_list(tests: List[str]) -> List[str]:
"""Extracts all the suites from an ordered list of tests."""
suites = [] # type: List[str]
for t in tests:
parts = t.split('.', maxsplit=2)
if len(parts) != 2:
raise ValueError(f'internal KUnit error, test name should be of the form "<suite>.<test>", got "{t}"')
suite, _ = parts
if not suites or suites[-1] != suite:
suites.append(suite)
return suites
def exec_tests(linux: kunit_kernel.LinuxSourceTree, request: KunitExecRequest) -> KunitResult:
filter_globs = [request.filter_glob]
if request.list_tests:
output = _list_tests(linux, request)
for line in output:
print(line.rstrip())
return KunitResult(status=KunitStatus.SUCCESS, elapsed_time=0.0)
if request.list_tests_attr:
attr_output = _list_tests_attr(linux, request)
for line in attr_output:
print(line.rstrip())
return KunitResult(status=KunitStatus.SUCCESS, elapsed_time=0.0)
if request.list_suites:
tests = _list_tests(linux, request)
output = _suites_from_test_list(tests)
for line in output:
print(line.rstrip())
return KunitResult(status=KunitStatus.SUCCESS, elapsed_time=0.0)
if request.run_isolated:
tests = _list_tests(linux, request)
if request.run_isolated == 'test':
filter_globs = tests
elif request.run_isolated == 'suite':
filter_globs = _suites_from_test_list(tests)
# Apply the test-part of the user's glob, if present.
if '.' in request.filter_glob:
test_glob = request.filter_glob.split('.', maxsplit=2)[1]
filter_globs = [g + '.'+ test_glob for g in filter_globs]
metadata = kunit_json.Metadata(arch=linux.arch(), build_dir=request.build_dir, def_config='kunit_defconfig')
test_counts = kunit_parser.TestCounts()
exec_time = 0.0
for i, filter_glob in enumerate(filter_globs):
stdout.print_with_timestamp('Starting KUnit Kernel ({}/{})...'.format(i+1, len(filter_globs)))
test_start = time.time()
run_result = linux.run_kernel(
args=request.kernel_args,
timeout=request.timeout,
filter_glob=filter_glob,
filter=request.filter,
filter_action=request.filter_action,
build_dir=request.build_dir)
_, test_result = parse_tests(request, metadata, run_result)
# run_kernel() doesn't block on the kernel exiting.
# That only happens after we get the last line of output from `run_result`.
# So exec_time here actually contains parsing + execution time, which is fine.
test_end = time.time()
exec_time += test_end - test_start
test_counts.add_subtest_counts(test_result.counts)
if len(filter_globs) == 1 and test_counts.crashed > 0:
bd = request.build_dir
print('The kernel seems to have crashed; you can decode the stack traces with:')
print('$ scripts/decode_stacktrace.sh {}/vmlinux {} < {} | tee {}/decoded.log | {} parse'.format(
bd, bd, kunit_kernel.get_outfile_path(bd), bd, sys.argv[0]))
kunit_status = _map_to_overall_status(test_counts.get_status())
return KunitResult(status=kunit_status, elapsed_time=exec_time)
def _map_to_overall_status(test_status: kunit_parser.TestStatus) -> KunitStatus:
if test_status in (kunit_parser.TestStatus.SUCCESS, kunit_parser.TestStatus.SKIPPED):
return KunitStatus.SUCCESS
return KunitStatus.TEST_FAILURE
def parse_tests(request: KunitParseRequest, metadata: kunit_json.Metadata, input_data: Iterable[str]) -> Tuple[KunitResult, kunit_parser.Test]:
parse_start = time.time()
if request.raw_output:
# Treat unparsed results as one passing test.
fake_test = kunit_parser.Test()
fake_test.status = kunit_parser.TestStatus.SUCCESS
fake_test.counts.passed = 1
output: Iterable[str] = input_data
if request.raw_output == 'all' or request.raw_output == 'full':
pass
elif request.raw_output == 'kunit':
output = kunit_parser.extract_tap_lines(output)
for line in output:
print(line.rstrip())
parse_time = time.time() - parse_start
return KunitResult(KunitStatus.SUCCESS, parse_time), fake_test
default_printer = stdout
if request.summary or request.failed:
default_printer = null_printer
# Actually parse the test results.
test = kunit_parser.parse_run_tests(input_data, default_printer)
parse_time = time.time() - parse_start
if request.failed:
kunit_parser.print_test(test, request.failed, stdout)
kunit_parser.print_summary_line(test, stdout)
if request.json:
json_str = kunit_json.get_json_result(
test=test,
metadata=metadata)
if request.json == 'stdout':
print(json_str)
else:
with open(request.json, 'w') as f:
f.write(json_str)
stdout.print_with_timestamp("Test results stored in %s" %
os.path.abspath(request.json))
if request.junit:
if request.junit == 'stdout':
kunit_junit.print_junit_result(test=test)
else:
kunit_junit.write_junit_result(test=test,filename=request.junit)
stdout.print_with_timestamp(f"Test results stored in {os.path.abspath(request.junit)}")
if test.status != kunit_parser.TestStatus.SUCCESS:
return KunitResult(KunitStatus.TEST_FAILURE, parse_time), test
return KunitResult(KunitStatus.SUCCESS, parse_time), test
def run_tests(linux: kunit_kernel.LinuxSourceTree,
request: KunitRequest) -> KunitResult:
run_start = time.time()
config_result = config_tests(linux, request)
if config_result.status != KunitStatus.SUCCESS:
return config_result
build_result = build_tests(linux, request)
if build_result.status != KunitStatus.SUCCESS:
return build_result
exec_result = exec_tests(linux, request)
run_end = time.time()
stdout.print_with_timestamp((
'Elapsed time: %.3fs total, %.3fs configuring, %.3fs ' +
'building, %.3fs running\n') % (
run_end - run_start,
config_result.elapsed_time,
build_result.elapsed_time,
exec_result.elapsed_time))
return exec_result
# Problem:
# $ kunit.py run --json
# works as one would expect and prints the parsed test results as JSON.
# $ kunit.py run --json suite_name
# would *not* pass suite_name as the filter_glob and print as json.
# argparse will consider it to be another way of writing
# $ kunit.py run --json=suite_name
# i.e. it would run all tests, and dump the json to a `suite_name` file.
# So we hackily automatically rewrite --json => --json=stdout
pseudo_bool_flag_defaults = {
'--json': 'stdout',
'--junit': 'stdout',
'--raw_output': 'kunit',
}
def massage_argv(argv: Sequence[str]) -> Sequence[str]:
def massage_arg(arg: str) -> str:
if arg not in pseudo_bool_flag_defaults:
return arg
return f'{arg}={pseudo_bool_flag_defaults[arg]}'
return list(map(massage_arg, argv))
def get_default_jobs() -> int:
if sys.version_info >= (3, 13):
if (ncpu := os.process_cpu_count()) is not None:
return ncpu
raise RuntimeError("os.process_cpu_count() returned None")
# See https://github.com/python/cpython/blob/b61fece/Lib/os.py#L1175-L1186.
if sys.platform != "darwin":
return len(os.sched_getaffinity(0))
if (ncpu := os.cpu_count()) is not None:
return ncpu
raise RuntimeError("os.cpu_count() returned None")
def get_default_build_dir() -> str:
if 'KBUILD_OUTPUT' in os.environ:
return os.path.join(os.environ['KBUILD_OUTPUT'], '.kunit')
return '.kunit'
def add_completion_opts(parser: argparse.ArgumentParser) -> None:
parser.add_argument('--list-opts',
help=argparse.SUPPRESS,
action='store_true')
def add_root_opts(parser: argparse.ArgumentParser) -> None:
parser.add_argument('--list-cmds',
help=argparse.SUPPRESS,
action='store_true')
add_completion_opts(parser)
def add_common_opts(parser: argparse.ArgumentParser) -> None:
parser.add_argument('--build_dir',
help='As in the make command, it specifies the build '
'directory.',
type=str, default=get_default_build_dir(), metavar='DIR')
parser.add_argument('--make_options',
help='X=Y make option, can be repeated.',
action='append', metavar='X=Y')
parser.add_argument('--alltests',
help='Run all KUnit tests via tools/testing/kunit/configs/all_tests.config',
action='store_true')
parser.add_argument('--kunitconfig',
help='Path to Kconfig fragment that enables KUnit tests.'
' If given a directory, (e.g. lib/kunit), "/.kunitconfig" '
'will get automatically appended. If repeated, the files '
'blindly concatenated, which might not work in all cases.',
action='append', metavar='PATHS')
parser.add_argument('--kconfig_add',
help='Additional Kconfig options to append to the '
'.kunitconfig, e.g. CONFIG_KASAN=y. Can be repeated.',
action='append', metavar='CONFIG_X=Y')
parser.add_argument('--arch',
help=('Specifies the architecture to run tests under. '
'The architecture specified here must match the '
'string passed to the ARCH make param, '
'e.g. i386, x86_64, arm, um, etc. Non-UML '
'architectures run on QEMU.'),
type=str, default='um', metavar='ARCH')
parser.add_argument('--cross_compile',
help=('Sets make\'s CROSS_COMPILE variable; it should '
'be set to a toolchain path prefix (the prefix '
'of gcc and other tools in your toolchain, for '
'example `sparc64-linux-gnu-` if you have the '
'sparc toolchain installed on your system, or '
'`$HOME/toolchains/microblaze/gcc-9.2.0-nolibc/microblaze-linux/bin/microblaze-linux-` '
'if you have downloaded the microblaze toolchain '
'from the 0-day website to a directory in your '
'home directory called `toolchains`).'),
metavar='PREFIX')
parser.add_argument('--qemu_config',
help=('Takes a path to a path to a file containing '
'a QemuArchParams object.'),
type=str, metavar='FILE')
parser.add_argument('--qemu_args',
help='Additional QEMU arguments, e.g. "-smp 8"',
action='append', metavar='')
add_completion_opts(parser)
def add_build_opts(parser: argparse.ArgumentParser) -> None:
parser.add_argument('--jobs',
help='As in the make command, "Specifies the number of '
'jobs (commands) to run simultaneously."',
type=int, default=get_default_jobs(), metavar='N')
def add_exec_opts(parser: argparse.ArgumentParser) -> None:
parser.add_argument('--timeout',
help='maximum number of seconds to allow for all tests '
'to run. This does not include time taken to build the '
'tests.',
type=int,
default=300,
metavar='SECONDS')
parser.add_argument('filter_glob',
help='Filter which KUnit test suites/tests run at '
'boot-time, e.g. list* or list*.*del_test',
type=str,
nargs='?',
default='',
metavar='filter_glob')
parser.add_argument('--filter',
help='Filter KUnit tests with attributes, '
'e.g. module=example or speed>slow',
type=str,
default='')
parser.add_argument('--filter_action',
help='If set to skip, filtered tests will be skipped, '
'e.g. --filter_action=skip. Otherwise they will not run.',
type=str,
choices=['skip'])
parser.add_argument('--kernel_args',
help='Kernel command-line parameters. Maybe be repeated',
action='append', metavar='')
parser.add_argument('--run_isolated', help='If set, boot the kernel for each '
'individual suite/test. This is can be useful for debugging '
'a non-hermetic test, one that might pass/fail based on '
'what ran before it.',
type=str,
choices=['suite', 'test'])
parser.add_argument('--list_tests', help='If set, list all tests that will be '
'run.',
action='store_true')
parser.add_argument('--list_tests_attr', help='If set, list all tests and test '
'attributes.',
action='store_true')
parser.add_argument('--list_suites', help='If set, list all suites that will be '
'run.',
action='store_true')
def add_parse_opts(parser: argparse.ArgumentParser) -> None:
parser.add_argument('--raw_output', help='If set don\'t parse output from kernel. '
'By default, filters to just KUnit output. Use '
'--raw_output=all to show everything',
type=str, nargs='?', const='all', default=None, choices=['all', 'full', 'kunit'])
parser.add_argument('--json',
nargs='?',
help='Prints parsed test results as JSON to stdout or a file if '
'a filename is specified. Does nothing if --raw_output is set.',
type=str, const='stdout', default=None, metavar='FILE')
parser.add_argument('--junit',
nargs='?',
help='Prints parsed test results as JUnit XML to stdout or a file if '
'a filename is specified. Does nothing if --raw_output is set.',
type=str, const='stdout', default=None, metavar='FILE')
parser.add_argument('--summary',
help='Prints only the summary line for parsed test results.'
'Does nothing if --raw_output is set.',
action='store_true')
parser.add_argument('--failed',
help='Prints only the failed parsed test results and summary line.'
'Does nothing if --raw_output is set.',
action='store_true')
def tree_from_args(cli_args: argparse.Namespace) -> kunit_kernel.LinuxSourceTree:
"""Returns a LinuxSourceTree based on the user's arguments."""
# Allow users to specify multiple arguments in one string, e.g. '-smp 8'
qemu_args: List[str] = []
if cli_args.qemu_args:
for arg in cli_args.qemu_args:
qemu_args.extend(shlex.split(arg))
kunitconfigs = cli_args.kunitconfig if cli_args.kunitconfig else []
if cli_args.alltests:
# Prepend so user-specified options take prio if we ever allow
# --kunitconfig options to have differing options.
kunitconfigs = [kunit_kernel.ALL_TESTS_CONFIG_PATH] + kunitconfigs
return kunit_kernel.LinuxSourceTree(cli_args.build_dir,
kunitconfig_paths=kunitconfigs,
kconfig_add=cli_args.kconfig_add,
arch=cli_args.arch,
cross_compile=cli_args.cross_compile,
qemu_config_path=cli_args.qemu_config,
extra_qemu_args=qemu_args)
def run_handler(cli_args: argparse.Namespace) -> None:
if not os.path.exists(cli_args.build_dir):
os.mkdir(cli_args.build_dir)
linux = tree_from_args(cli_args)
request = KunitRequest(build_dir=cli_args.build_dir,
make_options=cli_args.make_options,
jobs=cli_args.jobs,
raw_output=cli_args.raw_output,
json=cli_args.json,
junit=cli_args.junit,
summary=cli_args.summary,
failed=cli_args.failed,
timeout=cli_args.timeout,
filter_glob=cli_args.filter_glob,
filter=cli_args.filter,
filter_action=cli_args.filter_action,
kernel_args=cli_args.kernel_args,
run_isolated=cli_args.run_isolated,
list_tests=cli_args.list_tests,
list_tests_attr=cli_args.list_tests_attr,
list_suites=cli_args.list_suites)
result = run_tests(linux, request)
if result.status != KunitStatus.SUCCESS:
sys.exit(1)
def config_handler(cli_args: argparse.Namespace) -> None:
if cli_args.build_dir and (
not os.path.exists(cli_args.build_dir)):
os.mkdir(cli_args.build_dir)
linux = tree_from_args(cli_args)
request = KunitConfigRequest(build_dir=cli_args.build_dir,
make_options=cli_args.make_options)
result = config_tests(linux, request)
stdout.print_with_timestamp((
'Elapsed time: %.3fs\n') % (
result.elapsed_time))
if result.status != KunitStatus.SUCCESS:
sys.exit(1)
def build_handler(cli_args: argparse.Namespace) -> None:
linux = tree_from_args(cli_args)
request = KunitBuildRequest(build_dir=cli_args.build_dir,
make_options=cli_args.make_options,
jobs=cli_args.jobs)
result = config_and_build_tests(linux, request)
stdout.print_with_timestamp((
'Elapsed time: %.3fs\n') % (
result.elapsed_time))
if result.status != KunitStatus.SUCCESS:
sys.exit(1)
def exec_handler(cli_args: argparse.Namespace) -> None:
linux = tree_from_args(cli_args)
exec_request = KunitExecRequest(raw_output=cli_args.raw_output,
build_dir=cli_args.build_dir,
json=cli_args.json,
junit=cli_args.junit,
summary=cli_args.summary,
failed=cli_args.failed,
timeout=cli_args.timeout,
filter_glob=cli_args.filter_glob,
filter=cli_args.filter,
filter_action=cli_args.filter_action,
kernel_args=cli_args.kernel_args,
run_isolated=cli_args.run_isolated,
list_tests=cli_args.list_tests,
list_tests_attr=cli_args.list_tests_attr,
list_suites=cli_args.list_suites)
result = exec_tests(linux, exec_request)
stdout.print_with_timestamp((
'Elapsed time: %.3fs\n') % (result.elapsed_time))
if result.status != KunitStatus.SUCCESS:
sys.exit(1)
def parse_handler(cli_args: argparse.Namespace) -> None:
if cli_args.file is None:
sys.stdin.reconfigure(errors='backslashreplace') # type: ignore
kunit_output = sys.stdin # type: Iterable[str]
else:
with open(cli_args.file, 'r', errors='backslashreplace') as f:
kunit_output = f.read().splitlines()
# We know nothing about how the result was created!
metadata = kunit_json.Metadata()
request = KunitParseRequest(raw_output=cli_args.raw_output,
json=cli_args.json,
junit=cli_args.junit,
summary=cli_args.summary,
failed=cli_args.failed)
result, _ = parse_tests(request, metadata, kunit_output)
if result.status != KunitStatus.SUCCESS:
sys.exit(1)
subcommand_handlers_map = {
'run': run_handler,
'config': config_handler,
'build': build_handler,
'exec': exec_handler,
'parse': parse_handler
}
def main(argv: Sequence[str]) -> None:
parser = argparse.ArgumentParser(
description='Helps writing and running KUnit tests.')
add_root_opts(parser)
subparser = parser.add_subparsers(dest='subcommand')
# The 'run' command will config, build, exec, and parse in one go.
run_parser = subparser.add_parser('run', help='Runs KUnit tests.')
add_common_opts(run_parser)
add_build_opts(run_parser)
add_exec_opts(run_parser)
add_parse_opts(run_parser)
config_parser = subparser.add_parser('config',
help='Ensures that .config contains all of '
'the options in .kunitconfig')
add_common_opts(config_parser)
build_parser = subparser.add_parser('build', help='Builds a kernel with KUnit tests')
add_common_opts(build_parser)
add_build_opts(build_parser)
exec_parser = subparser.add_parser('exec', help='Run a kernel with KUnit tests')
add_common_opts(exec_parser)
add_exec_opts(exec_parser)
add_parse_opts(exec_parser)
# The 'parse' option is special, as it doesn't need the kernel source
# (therefore there is no need for a build_dir, hence no add_common_opts)
# and the '--file' argument is not relevant to 'run', so isn't in
# add_parse_opts()
parse_parser = subparser.add_parser('parse',
help='Parses KUnit results from a file, '
'and parses formatted results.')
add_parse_opts(parse_parser)
parse_parser.add_argument('file',
help='Specifies the file to read results from.',
type=str, nargs='?', metavar='input_file')
add_completion_opts(parse_parser)
cli_args = parser.parse_args(massage_argv(argv))
if get_kernel_root_path():
os.chdir(get_kernel_root_path())
if cli_args.list_cmds:
print(" ".join(subparser.choices.keys()))
return
if cli_args.list_opts:
target_parser = subparser.choices.get(cli_args.subcommand)
if not target_parser:
target_parser = parser
# Accessing private attribute _option_string_actions to get
# the list of options. This is not a public API, but argparse
# does not provide a way to inspect options programmatically.
print(' '.join(target_parser._option_string_actions.keys()))
return
subcomand_handler = subcommand_handlers_map.get(cli_args.subcommand, None)
if subcomand_handler is None:
parser.print_help()
return
subcomand_handler(cli_args)
if __name__ == '__main__':
main(sys.argv[1:])
@@ -0,0 +1,108 @@
# SPDX-License-Identifier: GPL-2.0
#
# Builds a .config from a kunitconfig.
#
# Copyright (C) 2019, Google LLC.
# Author: Felix Guo <felixguoxiuping@gmail.com>
# Author: Brendan Higgins <brendanhiggins@google.com>
from dataclasses import dataclass
import re
from typing import Any, Dict, Iterable, List, Tuple
CONFIG_IS_NOT_SET_PATTERN = r'^# CONFIG_(\w+) is not set$'
CONFIG_PATTERN = r'^CONFIG_(\w+)=(\S+|".*")$'
@dataclass(frozen=True)
class KconfigEntry:
name: str
value: str
def __str__(self) -> str:
if self.value == 'n':
return f'# CONFIG_{self.name} is not set'
return f'CONFIG_{self.name}={self.value}'
class KconfigParseError(Exception):
"""Error parsing Kconfig defconfig or .config."""
class Kconfig:
"""Represents defconfig or .config specified using the Kconfig language."""
def __init__(self) -> None:
self._entries = {} # type: Dict[str, str]
def __eq__(self, other: Any) -> bool:
if not isinstance(other, self.__class__):
return False
return self._entries == other._entries
def __repr__(self) -> str:
return ','.join(str(e) for e in self.as_entries())
def as_entries(self) -> Iterable[KconfigEntry]:
for name, value in self._entries.items():
yield KconfigEntry(name, value)
def add_entry(self, name: str, value: str) -> None:
self._entries[name] = value
def is_subset_of(self, other: 'Kconfig') -> bool:
for name, value in self._entries.items():
b = other._entries.get(name)
if b is None:
if value == 'n':
continue
return False
if value != b:
return False
return True
def conflicting_options(self, other: 'Kconfig') -> List[Tuple[KconfigEntry, KconfigEntry]]:
diff = [] # type: List[Tuple[KconfigEntry, KconfigEntry]]
for name, value in self._entries.items():
b = other._entries.get(name)
if b and value != b:
pair = (KconfigEntry(name, value), KconfigEntry(name, b))
diff.append(pair)
return diff
def merge_in_entries(self, other: 'Kconfig') -> None:
for name, value in other._entries.items():
self._entries[name] = value
def write_to_file(self, path: str) -> None:
with open(path, 'a+') as f:
for e in self.as_entries():
f.write(str(e) + '\n')
def parse_file(path: str) -> Kconfig:
with open(path, 'r') as f:
return parse_from_string(f.read())
def parse_from_string(blob: str) -> Kconfig:
"""Parses a string containing Kconfig entries."""
kconfig = Kconfig()
is_not_set_matcher = re.compile(CONFIG_IS_NOT_SET_PATTERN)
config_matcher = re.compile(CONFIG_PATTERN)
for line in blob.split('\n'):
line = line.strip()
if not line:
continue
match = config_matcher.match(line)
if match:
kconfig.add_entry(match.group(1), match.group(2))
continue
empty_match = is_not_set_matcher.match(line)
if empty_match:
kconfig.add_entry(empty_match.group(1), 'n')
continue
if line[0] == '#':
continue
raise KconfigParseError('Failed to parse: ' + line)
return kconfig
@@ -0,0 +1,73 @@
# SPDX-License-Identifier: GPL-2.0
#
# Generates JSON from KUnit results according to
# KernelCI spec: https://github.com/kernelci/kernelci-doc/wiki/Test-API
#
# Copyright (C) 2020, Google LLC.
# Author: Heidi Fahim <heidifahim@google.com>
from dataclasses import dataclass
import json
from typing import Any, Dict
from kunit_parser import Test, TestStatus
@dataclass
class Metadata:
"""Stores metadata about this run to include in get_json_result()."""
arch: str = ''
def_config: str = ''
build_dir: str = ''
JsonObj = Dict[str, Any]
_status_map: Dict[TestStatus, str] = {
TestStatus.SUCCESS: "PASS",
TestStatus.SKIPPED: "SKIP",
TestStatus.TEST_CRASHED: "ERROR",
}
def _get_group_json(test: Test, common_fields: JsonObj) -> JsonObj:
sub_groups = [] # List[JsonObj]
test_cases = [] # List[JsonObj]
for subtest in test.subtests:
if subtest.subtests:
sub_group = _get_group_json(subtest, common_fields)
sub_groups.append(sub_group)
continue
status = _status_map.get(subtest.status, "FAIL")
test_cases.append({"name": subtest.name, "status": status})
test_counts = test.counts
counts_json = {
"tests": test_counts.total(),
"passed": test_counts.passed,
"failed": test_counts.failed,
"crashed": test_counts.crashed,
"skipped": test_counts.skipped,
"errors": test_counts.errors,
}
test_group = {
"name": test.name,
"sub_groups": sub_groups,
"test_cases": test_cases,
"misc": counts_json
}
test_group.update(common_fields)
return test_group
def get_json_result(test: Test, metadata: Metadata) -> str:
common_fields = {
"arch": metadata.arch,
"defconfig": metadata.def_config,
"build_environment": metadata.build_dir,
"lab_name": None,
"kernel": None,
"job": None,
"git_branch": "kselftest",
}
test_group = _get_group_json(test, common_fields)
test_group["name"] = "KUnit Test Group"
return json.dumps(test_group, indent=4)
@@ -0,0 +1,61 @@
# SPDX-License-Identifier: GPL-2.0
#
# Generates JUnit XML files from KUnit test results
#
# Copyright (C) 2026, Google LLC and David Gow.
from xml.sax.saxutils import quoteattr, XMLGenerator
import xml.etree.ElementTree as ET
from kunit_parser import Test, TestStatus
from typing import Optional
# Get a string representing a tes suite (including subtests) in JUnit XML
def get_test_suite(test: Test, parent: Optional[ET.Element]) -> ET.Element:
suite_attrs = {
'name': test.name,
'tests': str(test.counts.total()),
'failures': str(test.counts.failed),
'skipped': str(test.counts.skipped),
'errors': str(test.counts.crashed + test.counts.errors),
}
if parent is not None:
test_suite_element = ET.SubElement(parent, 'testsuite', suite_attrs)
else:
test_suite_element = ET.Element('testsuite', suite_attrs)
for subtest in test.subtests:
if subtest.subtests:
get_test_suite(subtest, test_suite_element)
continue
test_case_element = ET.SubElement(test_suite_element, 'testcase', {'name': subtest.name})
if subtest.status == TestStatus.FAILURE:
ET.SubElement(test_case_element, 'failure', {}).text = 'Test Failed'
elif subtest.status == TestStatus.SKIPPED:
ET.SubElement(test_case_element, 'skipped', {}).text = subtest.skip_reason
elif subtest.status == TestStatus.TEST_CRASHED:
ET.SubElement(test_case_element, 'error', {}).text = 'Test Crashed'
if subtest.log:
ET.SubElement(test_case_element, 'system-out', {}).text = "\n".join(subtest.log)
return test_suite_element
# Get a string for an entire XML file for the test structure starting at test
def get_junit_result(test: Test) -> str:
root_element = get_test_suite(test, None)
ET.indent(root_element)
return ET.tostring(root_element, encoding="unicode", xml_declaration=True)
# Print a JUnit result to stdout.
def print_junit_result(test: Test) -> None:
root_element = get_test_suite(test, None)
ET.indent(root_element)
ET.dump(root_element)
# Write an entire XML file for the test structure starting at test
def write_junit_result(test: Test, filename: str) -> None:
root_element = get_test_suite(test, None)
ET.indent(root_element)
root_et = ET.ElementTree(root_element)
root_et.write(filename, encoding='utf-8', xml_declaration=True)
@@ -0,0 +1,409 @@
# SPDX-License-Identifier: GPL-2.0
#
# Runs UML kernel, collects output, and handles errors.
#
# Copyright (C) 2019, Google LLC.
# Author: Felix Guo <felixguoxiuping@gmail.com>
# Author: Brendan Higgins <brendanhiggins@google.com>
import importlib.abc
import importlib.util
import logging
import subprocess
import os
import shlex
import shutil
import signal
import sys
import threading
from typing import Iterator, List, Optional, Tuple, Any
from types import FrameType
import kunit_config
import qemu_config
KCONFIG_PATH = '.config'
KUNITCONFIG_PATH = '.kunitconfig'
OLD_KUNITCONFIG_PATH = 'last_used_kunitconfig'
DEFAULT_KUNITCONFIG_PATH = 'tools/testing/kunit/configs/default.config'
ALL_TESTS_CONFIG_PATH = 'tools/testing/kunit/configs/all_tests.config'
UML_KCONFIG_PATH = 'tools/testing/kunit/configs/arch_uml.config'
OUTFILE_PATH = 'test.log'
ABS_TOOL_PATH = os.path.abspath(os.path.dirname(__file__))
QEMU_CONFIGS_DIR = os.path.join(ABS_TOOL_PATH, 'qemu_configs')
class ConfigError(Exception):
"""Represents an error trying to configure the Linux kernel."""
class BuildError(Exception):
"""Represents an error trying to build the Linux kernel."""
class LinuxSourceTreeOperations:
"""An abstraction over command line operations performed on a source tree."""
def __init__(self, linux_arch: str, cross_compile: Optional[str]):
self._linux_arch = linux_arch
self._cross_compile = cross_compile
def make_mrproper(self) -> None:
try:
subprocess.check_output(['make', 'mrproper'], stderr=subprocess.STDOUT)
except OSError as e:
raise ConfigError('Could not call make command: ' + str(e))
except subprocess.CalledProcessError as e:
raise ConfigError(e.output.decode())
def make_arch_config(self, base_kunitconfig: kunit_config.Kconfig) -> kunit_config.Kconfig:
return base_kunitconfig
def make_olddefconfig(self, build_dir: str, make_options: Optional[List[str]]) -> None:
command = ['make', 'ARCH=' + self._linux_arch, 'O=' + build_dir, 'olddefconfig']
if self._cross_compile:
command += ['CROSS_COMPILE=' + self._cross_compile]
if make_options:
command.extend(make_options)
print('Populating config with:\n$', ' '.join(command))
try:
subprocess.check_output(command, stderr=subprocess.STDOUT)
except OSError as e:
raise ConfigError('Could not call make command: ' + str(e))
except subprocess.CalledProcessError as e:
raise ConfigError(e.output.decode())
def make(self, jobs: int, build_dir: str, make_options: Optional[List[str]]) -> None:
command = ['make', 'all', 'compile_commands.json', 'scripts_gdb',
'ARCH=' + self._linux_arch, 'O=' + build_dir, '--jobs=' + str(jobs)]
if make_options:
command.extend(make_options)
if self._cross_compile:
command += ['CROSS_COMPILE=' + self._cross_compile]
print('Building with:\n$', ' '.join(command))
try:
proc = subprocess.Popen(command,
stderr=subprocess.PIPE,
stdout=subprocess.DEVNULL)
except OSError as e:
raise BuildError('Could not call execute make: ' + str(e))
except subprocess.CalledProcessError as e:
raise BuildError(e.output)
_, stderr = proc.communicate()
if proc.returncode != 0:
raise BuildError(stderr.decode())
if stderr: # likely only due to build warnings
print(stderr.decode())
def start(self, params: List[str], build_dir: str) -> subprocess.Popen:
raise RuntimeError('not implemented!')
class LinuxSourceTreeOperationsQemu(LinuxSourceTreeOperations):
def __init__(self, qemu_arch_params: qemu_config.QemuArchParams, cross_compile: Optional[str]):
super().__init__(linux_arch=qemu_arch_params.linux_arch,
cross_compile=cross_compile)
self._kconfig = qemu_arch_params.kconfig
self._qemu_arch = qemu_arch_params.qemu_arch
self._kernel_path = qemu_arch_params.kernel_path
self._kernel_command_line = qemu_arch_params.kernel_command_line
if 'kunit_shutdown=' not in self._kernel_command_line:
self._kernel_command_line += ' kunit_shutdown=reboot'
self._extra_qemu_params = qemu_arch_params.extra_qemu_params
self._serial = qemu_arch_params.serial
def make_arch_config(self, base_kunitconfig: kunit_config.Kconfig) -> kunit_config.Kconfig:
kconfig = kunit_config.parse_from_string(self._kconfig)
kconfig.merge_in_entries(base_kunitconfig)
return kconfig
def start(self, params: List[str], build_dir: str) -> subprocess.Popen:
kernel_path = os.path.join(build_dir, self._kernel_path)
qemu_command = ['qemu-system-' + self._qemu_arch,
'-nodefaults',
'-m', '1024',
'-kernel', kernel_path,
'-append', ' '.join(params + [self._kernel_command_line]),
'-no-reboot',
'-nographic',
'-accel', 'kvm',
'-accel', 'hvf',
'-accel', 'tcg',
'-serial', self._serial] + self._extra_qemu_params
# Note: shlex.join() does what we want, but requires python 3.8+.
print('Running tests with:\n$', ' '.join(shlex.quote(arg) for arg in qemu_command))
return subprocess.Popen(qemu_command,
stdin=subprocess.PIPE,
stdout=subprocess.PIPE,
stderr=subprocess.STDOUT,
text=True, errors='backslashreplace')
class LinuxSourceTreeOperationsUml(LinuxSourceTreeOperations):
"""An abstraction over command line operations performed on a source tree."""
def __init__(self, cross_compile: Optional[str]=None):
super().__init__(linux_arch='um', cross_compile=cross_compile)
def make_arch_config(self, base_kunitconfig: kunit_config.Kconfig) -> kunit_config.Kconfig:
kconfig = kunit_config.parse_file(UML_KCONFIG_PATH)
kconfig.merge_in_entries(base_kunitconfig)
return kconfig
def start(self, params: List[str], build_dir: str) -> subprocess.Popen:
"""Runs the Linux UML binary. Must be named 'linux'."""
linux_bin = os.path.join(build_dir, 'linux')
params.extend(['mem=1G', 'console=tty', 'kunit_shutdown=halt'])
print('Running tests with:\n$', linux_bin, ' '.join(shlex.quote(arg) for arg in params))
return subprocess.Popen([linux_bin] + params,
stdin=subprocess.PIPE,
stdout=subprocess.PIPE,
stderr=subprocess.STDOUT,
text=True, errors='backslashreplace')
def get_kconfig_path(build_dir: str) -> str:
return os.path.join(build_dir, KCONFIG_PATH)
def get_kunitconfig_path(build_dir: str) -> str:
return os.path.join(build_dir, KUNITCONFIG_PATH)
def get_old_kunitconfig_path(build_dir: str) -> str:
return os.path.join(build_dir, OLD_KUNITCONFIG_PATH)
def get_parsed_kunitconfig(build_dir: str,
kunitconfig_paths: Optional[List[str]]=None) -> kunit_config.Kconfig:
if not kunitconfig_paths:
path = get_kunitconfig_path(build_dir)
if not os.path.exists(path):
shutil.copyfile(DEFAULT_KUNITCONFIG_PATH, path)
return kunit_config.parse_file(path)
merged = kunit_config.Kconfig()
for path in kunitconfig_paths:
if os.path.isdir(path):
path = os.path.join(path, KUNITCONFIG_PATH)
if not os.path.exists(path):
raise ConfigError(f'Specified kunitconfig ({path}) does not exist')
partial = kunit_config.parse_file(path)
diff = merged.conflicting_options(partial)
if diff:
diff_str = '\n\n'.join(f'{a}\n vs from {path}\n{b}' for a, b in diff)
raise ConfigError(f'Multiple values specified for {len(diff)} options in kunitconfig:\n{diff_str}')
merged.merge_in_entries(partial)
return merged
def get_outfile_path(build_dir: str) -> str:
return os.path.join(build_dir, OUTFILE_PATH)
def _default_qemu_config_path(arch: str) -> str:
config_path = os.path.join(QEMU_CONFIGS_DIR, arch + '.py')
if os.path.isfile(config_path):
return config_path
options = [f[:-3] for f in os.listdir(QEMU_CONFIGS_DIR) if f.endswith('.py')]
if arch == 'help':
print('um')
for option in options:
print(option)
sys.exit()
raise ConfigError(arch + ' is not a valid arch, options are ' + str(sorted(options)))
def _get_qemu_ops(config_path: str,
extra_qemu_args: Optional[List[str]],
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
# anywhere in the Python documentation).
#
# Basically, we completely ignore the actual file location of the config
# we are loading and just tell Python that the module lives in the
# QEMU_CONFIGS_DIR for import purposes regardless of where it actually
# exists as a file.
module_path = '.' + os.path.join(os.path.basename(QEMU_CONFIGS_DIR), os.path.basename(config_path))
spec = importlib.util.spec_from_file_location(module_path, config_path)
assert spec is not None
config = importlib.util.module_from_spec(spec)
# See https://github.com/python/typeshed/pull/2626 for context.
assert isinstance(spec.loader, importlib.abc.Loader)
spec.loader.exec_module(config)
if not hasattr(config, 'QEMU_ARCH'):
raise ValueError('qemu_config module missing "QEMU_ARCH": ' + config_path)
params: qemu_config.QemuArchParams = config.QEMU_ARCH
if extra_qemu_args:
params.extra_qemu_params.extend(extra_qemu_args)
return params.linux_arch, LinuxSourceTreeOperationsQemu(
params, cross_compile=cross_compile)
class LinuxSourceTree:
"""Represents a Linux kernel source tree with KUnit tests."""
def __init__(
self,
build_dir: str,
kunitconfig_paths: Optional[List[str]]=None,
kconfig_add: Optional[List[str]]=None,
arch: Optional[str]=None,
cross_compile: Optional[str]=None,
qemu_config_path: Optional[str]=None,
extra_qemu_args: Optional[List[str]]=None) -> None:
signal.signal(signal.SIGINT, self.signal_handler)
if qemu_config_path:
self._arch, self._ops = _get_qemu_ops(qemu_config_path, extra_qemu_args, cross_compile)
else:
self._arch = 'um' if arch is None else arch
if self._arch == 'um':
self._ops = LinuxSourceTreeOperationsUml(cross_compile=cross_compile)
else:
qemu_config_path = _default_qemu_config_path(self._arch)
_, self._ops = _get_qemu_ops(qemu_config_path, extra_qemu_args, cross_compile)
self._kconfig = get_parsed_kunitconfig(build_dir, kunitconfig_paths)
if kconfig_add:
kconfig = kunit_config.parse_from_string('\n'.join(kconfig_add))
self._kconfig.merge_in_entries(kconfig)
self._process : Optional[subprocess.Popen[Any]] = None
def arch(self) -> str:
return self._arch
def clean(self) -> bool:
try:
self._ops.make_mrproper()
except ConfigError as e:
logging.error(e)
return False
return True
def validate_config(self, build_dir: str) -> bool:
kconfig_path = get_kconfig_path(build_dir)
validated_kconfig = kunit_config.parse_file(kconfig_path)
if self._kconfig.is_subset_of(validated_kconfig):
return True
missing = set(self._kconfig.as_entries()) - set(validated_kconfig.as_entries())
message = 'Not all Kconfig options selected in kunitconfig were in the generated .config.\n' \
'This is probably due to unsatisfied dependencies.\n' \
'Missing: ' + ', '.join(str(e) for e in missing)
if self._arch == 'um':
message += '\nNote: many Kconfig options aren\'t available on UML. You can try running ' \
'on a different architecture with something like "--arch=x86_64".'
logging.error(message)
return False
def build_config(self, build_dir: str, make_options: Optional[List[str]]) -> bool:
kconfig_path = get_kconfig_path(build_dir)
if build_dir and not os.path.exists(build_dir):
os.mkdir(build_dir)
try:
self._kconfig = self._ops.make_arch_config(self._kconfig)
self._kconfig.write_to_file(kconfig_path)
self._ops.make_olddefconfig(build_dir, make_options)
except ConfigError as e:
logging.error(e)
return False
if not self.validate_config(build_dir):
return False
old_path = get_old_kunitconfig_path(build_dir)
if os.path.exists(old_path):
os.remove(old_path) # write_to_file appends to the file
self._kconfig.write_to_file(old_path)
return True
def _kunitconfig_changed(self, build_dir: str) -> bool:
old_path = get_old_kunitconfig_path(build_dir)
if not os.path.exists(old_path):
return True
old_kconfig = kunit_config.parse_file(old_path)
return old_kconfig != self._kconfig
def build_reconfig(self, build_dir: str, make_options: Optional[List[str]]) -> bool:
"""Creates a new .config if it is not a subset of the .kunitconfig."""
kconfig_path = get_kconfig_path(build_dir)
if not os.path.exists(kconfig_path):
print('Generating .config ...')
return self.build_config(build_dir, make_options)
existing_kconfig = kunit_config.parse_file(kconfig_path)
self._kconfig = self._ops.make_arch_config(self._kconfig)
if self._kconfig.is_subset_of(existing_kconfig) and not self._kunitconfig_changed(build_dir):
return True
print('Regenerating .config ...')
os.remove(kconfig_path)
return self.build_config(build_dir, make_options)
def build_kernel(self, jobs: int, build_dir: str, make_options: Optional[List[str]]) -> bool:
try:
self._ops.make_olddefconfig(build_dir, make_options)
self._ops.make(jobs, build_dir, make_options)
except (ConfigError, BuildError) as e:
logging.error(e)
return False
return self.validate_config(build_dir)
def _restore_terminal_if_tty(self) -> None:
# stty requires a controlling terminal; skip headless runs.
if sys.stdin is None or not sys.stdin.isatty():
return
subprocess.call(['stty', 'sane'])
def run_kernel(self, args: Optional[List[str]]=None, build_dir: str='', filter_glob: str='', filter: str='', filter_action: Optional[str]=None, timeout: Optional[int]=None) -> Iterator[str]:
# Copy to avoid mutating the caller-supplied list. exec_tests() reuses
# the same args across repeated run_kernel() calls (e.g. --run_isolated),
# so appending to the original would accumulate stale flags on each call.
args = list(args) if args else []
if filter_glob:
args.append('kunit.filter_glob=' + filter_glob)
if filter:
args.append('kunit.filter="' + filter + '"')
if filter_action:
args.append('kunit.filter_action=' + filter_action)
args.append('kunit.enable=1')
self._process = self._ops.start(args, build_dir)
assert self._process is not None # tell mypy it's set
assert self._process.stdout is not None # tell mypy it's set
# Enforce the timeout in a background thread.
def _wait_proc() -> None:
try:
if self._process:
self._process.wait(timeout=timeout)
except Exception as e:
print(e)
if self._process:
self._process.terminate()
self._process.wait()
waiter = threading.Thread(target=_wait_proc)
waiter.start()
output = open(get_outfile_path(build_dir), 'w')
try:
# Tee the output to the file and to our caller in real time.
for line in self._process.stdout:
output.write(line)
yield line
# This runs even if our caller doesn't consume every line.
finally:
# Flush any leftover output to the file
if self._process:
if self._process.stdout:
output.write(self._process.stdout.read())
self._process.stdout.close()
self._process = None
output.close()
waiter.join()
self._restore_terminal_if_tty()
def signal_handler(self, unused_sig: int, unused_frame: Optional[FrameType]) -> None:
logging.error('Build interruption occurred. Cleaning console.')
if self._process:
self._process.terminate()
self._process.wait()
self._restore_terminal_if_tty()
@@ -0,0 +1,873 @@
# SPDX-License-Identifier: GPL-2.0
#
# Parses KTAP test results from a kernel dmesg log and incrementally prints
# results with reader-friendly format. Stores and returns test results in a
# Test object.
#
# Copyright (C) 2019, Google LLC.
# Author: Felix Guo <felixguoxiuping@gmail.com>
# Author: Brendan Higgins <brendanhiggins@google.com>
# Author: Rae Moar <rmoar@google.com>
from __future__ import annotations
from dataclasses import dataclass
import re
import textwrap
from enum import Enum, auto
from typing import Iterable, Iterator, List, Optional, Tuple
from kunit_printer import Printer
class Test:
"""
A class to represent a test parsed from KTAP results. All KTAP
results within a test log are stored in a main Test object as
subtests.
Attributes:
status : TestStatus - status of the test
name : str - name of the test
expected_count : int - expected number of subtests (0 if single
test case and None if unknown expected number of subtests)
subtests : List[Test] - list of subtests
log : List[str] - log of KTAP lines that correspond to the test
counts : TestCounts - counts of the test statuses and errors of
subtests or of the test itself if the test is a single
test case.
"""
def __init__(self) -> None:
"""Creates Test object with default attributes."""
self.status = TestStatus.TEST_CRASHED
self.name = ''
self.expected_count = 0 # type: Optional[int]
self.subtests = [] # type: List[Test]
self.log = [] # type: List[str]
self.counts = TestCounts()
self.skip_reason = ''
def __str__(self) -> str:
"""Returns string representation of a Test class object."""
return (f'Test({self.status}, {self.name}, {self.expected_count}, '
f'{self.subtests}, {self.log}, {self.counts}, {self.skip_reason})')
def __repr__(self) -> str:
"""Returns string representation of a Test class object."""
return str(self)
def add_error(self, printer: Printer, error_message: str) -> None:
"""Records an error that occurred while parsing this test."""
self.counts.errors += 1
printer.print_with_timestamp(printer.red('[ERROR]') + f' Test: {self.name}: {error_message}')
def ok_status(self) -> bool:
"""Returns true if the status was ok, i.e. passed or skipped."""
return self.status in (TestStatus.SUCCESS, TestStatus.SKIPPED)
class TestStatus(Enum):
"""An enumeration class to represent the status of a test."""
SUCCESS = auto()
FAILURE = auto()
SKIPPED = auto()
TEST_CRASHED = auto()
NO_TESTS = auto()
FAILURE_TO_PARSE_TESTS = auto()
@dataclass
class TestCounts:
"""
Tracks the counts of statuses of all test cases and any errors within
a Test.
"""
passed: int = 0
failed: int = 0
crashed: int = 0
skipped: int = 0
errors: int = 0
def __str__(self) -> str:
"""Returns the string representation of a TestCounts object."""
statuses = [('passed', self.passed), ('failed', self.failed),
('crashed', self.crashed), ('skipped', self.skipped),
('errors', self.errors)]
return f'Ran {self.total()} tests: ' + \
', '.join(f'{s}: {n}' for s, n in statuses if n > 0)
def total(self) -> int:
"""Returns the total number of test cases within a test
object, where a test case is a test with no subtests.
"""
return (self.passed + self.failed + self.crashed +
self.skipped)
def add_subtest_counts(self, counts: TestCounts) -> None:
"""
Adds the counts of another TestCounts object to the current
TestCounts object. Used to add the counts of a subtest to the
parent test.
Parameters:
counts - a different TestCounts object whose counts
will be added to the counts of the TestCounts object
"""
self.passed += counts.passed
self.failed += counts.failed
self.crashed += counts.crashed
self.skipped += counts.skipped
self.errors += counts.errors
def get_status(self) -> TestStatus:
"""Returns the aggregated status of a Test using test
counts.
"""
if self.total() == 0:
return TestStatus.NO_TESTS
if self.crashed:
# Crashes should take priority.
return TestStatus.TEST_CRASHED
if self.failed:
return TestStatus.FAILURE
if self.passed:
# No failures or crashes, looks good!
return TestStatus.SUCCESS
# We have only skipped tests.
return TestStatus.SKIPPED
def add_status(self, status: TestStatus) -> None:
"""Increments the count for `status`."""
if status == TestStatus.SUCCESS:
self.passed += 1
elif status == TestStatus.FAILURE:
self.failed += 1
elif status == TestStatus.SKIPPED:
self.skipped += 1
elif status != TestStatus.NO_TESTS:
self.crashed += 1
class LineStream:
"""
A class to represent the lines of kernel output.
Provides a lazy peek()/pop() interface over an iterator of
(line#, text).
"""
_lines: Iterator[Tuple[int, str]]
_next: Tuple[int, str]
_need_next: bool
_done: bool
def __init__(self, lines: Iterator[Tuple[int, str]]):
"""Creates a new LineStream that wraps the given iterator."""
self._lines = lines
self._done = False
self._need_next = True
self._next = (0, '')
def _get_next(self) -> None:
"""Advances the LineSteam to the next line, if necessary."""
if not self._need_next:
return
try:
self._next = next(self._lines)
except StopIteration:
self._done = True
finally:
self._need_next = False
def peek(self) -> str:
"""Returns the current line, without advancing the LineStream.
"""
self._get_next()
return self._next[1]
def pop(self) -> str:
"""Returns the current line and advances the LineStream to
the next line.
"""
s = self.peek()
if self._done:
raise ValueError(f'LineStream: going past EOF, last line was {s}')
self._need_next = True
return s
def __bool__(self) -> bool:
"""Returns True if stream has more lines."""
self._get_next()
return not self._done
# Only used by kunit_tool_test.py.
def __iter__(self) -> Iterator[str]:
"""Empties all lines stored in LineStream object into
Iterator object and returns the Iterator object.
"""
while bool(self):
yield self.pop()
def line_number(self) -> int:
"""Returns the line number of the current line."""
self._get_next()
return self._next[0]
# Parsing helper methods:
KTAP_START = re.compile(r'\s*KTAP version ([0-9]+)$')
TAP_START = re.compile(r'\s*TAP version ([0-9]+)$')
KTAP_END = re.compile(r'\s*(List of all partitions:|'
'Kernel panic - not syncing: VFS:|reboot: System halted)')
EXECUTOR_ERROR = re.compile(r'\s*kunit executor: (.*)$')
def extract_tap_lines(kernel_output: Iterable[str]) -> LineStream:
"""Extracts KTAP lines from the kernel output."""
def isolate_ktap_output(kernel_output: Iterable[str]) \
-> Iterator[Tuple[int, str]]:
line_num = 0
started = False
for line in kernel_output:
line_num += 1
line = line.rstrip() # remove trailing \n
if not started and KTAP_START.search(line):
# start extracting KTAP lines and set prefix
# to number of characters before version line
prefix_len = len(
line.split('KTAP version')[0])
started = True
yield line_num, line[prefix_len:]
elif not started and TAP_START.search(line):
# start extracting KTAP lines and set prefix
# to number of characters before version line
prefix_len = len(line.split('TAP version')[0])
started = True
yield line_num, line[prefix_len:]
elif started and KTAP_END.search(line):
# stop extracting KTAP lines
break
elif started:
# remove the prefix, if any.
line = line[prefix_len:]
yield line_num, line
elif EXECUTOR_ERROR.search(line):
yield line_num, line
return LineStream(lines=isolate_ktap_output(kernel_output))
KTAP_VERSIONS = [1]
TAP_VERSIONS = [13, 14]
def check_version(version_num: int, accepted_versions: List[int],
version_type: str, test: Test, printer: Printer) -> None:
"""
Adds error to test object if version number is too high or too
low.
Parameters:
version_num - The inputted version number from the parsed KTAP or TAP
header line
accepted_version - List of accepted KTAP or TAP versions
version_type - 'KTAP' or 'TAP' depending on the type of
version line.
test - Test object for current test being parsed
printer - Printer object to output error
"""
if version_num < min(accepted_versions):
test.add_error(printer, f'{version_type} version lower than expected!')
elif version_num > max(accepted_versions):
test.add_error(printer, f'{version_type} version higher than expected!')
def parse_ktap_header(lines: LineStream, test: Test, printer: Printer) -> bool:
"""
Parses KTAP/TAP header line and checks version number.
Returns False if fails to parse KTAP/TAP header line.
Accepted formats:
- 'KTAP version [version number]'
- 'TAP version [version number]'
Parameters:
lines - LineStream of KTAP output to parse
test - Test object for current test being parsed
printer - Printer object to output results
Return:
True if successfully parsed KTAP/TAP header line
"""
ktap_match = KTAP_START.match(lines.peek())
tap_match = TAP_START.match(lines.peek())
if ktap_match:
version_num = int(ktap_match.group(1))
check_version(version_num, KTAP_VERSIONS, 'KTAP', test, printer)
elif tap_match:
version_num = int(tap_match.group(1))
check_version(version_num, TAP_VERSIONS, 'TAP', test, printer)
else:
return False
lines.pop()
return True
TEST_HEADER = re.compile(r'^\s*# Subtest: (.*)$')
def parse_test_header(lines: LineStream, test: Test) -> bool:
"""
Parses test header and stores test name in test object.
Returns False if fails to parse test header line.
Accepted format:
- '# Subtest: [test name]'
Parameters:
lines - LineStream of KTAP output to parse
test - Test object for current test being parsed
Return:
True if successfully parsed test header line
"""
match = TEST_HEADER.match(lines.peek())
if not match:
return False
test.name = match.group(1)
lines.pop()
return True
TEST_PLAN = re.compile(r'^\s*1\.\.([0-9]+)')
def parse_test_plan(lines: LineStream, test: Test) -> bool:
"""
Parses test plan line and stores the expected number of subtests in
test object. Reports an error if expected count is 0.
Returns False and sets expected_count to None if there is no valid test
plan.
Accepted format:
- '1..[number of subtests]'
Parameters:
lines - LineStream of KTAP output to parse
test - Test object for current test being parsed
Return:
True if successfully parsed test plan line
"""
match = TEST_PLAN.match(lines.peek())
if not match:
test.expected_count = None
return False
expected_count = int(match.group(1))
test.expected_count = expected_count
lines.pop()
return True
TEST_RESULT = re.compile(r'^\s*(ok|not ok) ([0-9]+) ?(:?- )?([^#]*)( # .*)?$')
TEST_RESULT_SKIP = re.compile(r'^\s*(ok|not ok) ([0-9]+) ?(:?- )?(.*) # SKIP ?(.*)$')
def peek_test_name_match(lines: LineStream, test: Test) -> bool:
"""
Matches current line with the format of a test result line and checks
if the name matches the name of the current test.
Returns False if fails to match format or name.
Accepted format:
- '[ok|not ok] [test number] [-] [test name] [optional skip
directive]'
Parameters:
lines - LineStream of KTAP output to parse
test - Test object for current test being parsed
Return:
True if matched a test result line and the name matching the
expected test name
"""
line = lines.peek()
match = TEST_RESULT.match(line)
if not match:
return False
name = match.group(4)
if not name:
return False
return name == test.name
def parse_test_result(lines: LineStream, test: Test,
expected_num: int, printer: Printer) -> bool:
"""
Parses test result line and stores the status and name in the test
object. Reports an error if the test number does not match expected
test number.
Returns False if fails to parse test result line.
Note that the SKIP directive is the only direction that causes a
change in status.
Accepted format:
- '[ok|not ok] [test number] [-] [test name] [optional skip
directive]'
Parameters:
lines - LineStream of KTAP output to parse
test - Test object for current test being parsed
expected_num - expected test number for current test
printer - Printer object to output results
Return:
True if successfully parsed a test result line.
"""
line = lines.peek()
match = TEST_RESULT.match(line)
skip_match = TEST_RESULT_SKIP.match(line)
# Check if line matches test result line format
if not match:
return False
lines.pop()
# Set name of test object
if skip_match:
test.name = skip_match.group(4)
else:
test.name = match.group(4)
# Check test num
num = int(match.group(2))
if num != expected_num:
test.add_error(printer, f'Expected test number {expected_num} but found {num}')
# Set status of test object
status = match.group(1)
if skip_match:
test.status = TestStatus.SKIPPED
test.skip_reason = skip_match.group(5) or ''
elif status == 'ok':
test.status = TestStatus.SUCCESS
else:
test.status = TestStatus.FAILURE
return True
def parse_diagnostic(lines: LineStream) -> List[str]:
"""
Parse lines that do not match the format of a test result line or
test header line and returns them in list.
Line formats that are not parsed:
- '# Subtest: [test name]'
- '[ok|not ok] [test number] [-] [test name] [optional skip
directive]'
- 'KTAP version [version number]'
Parameters:
lines - LineStream of KTAP output to parse
Return:
Log of diagnostic lines
"""
log = [] # type: List[str]
non_diagnostic_lines = [TEST_RESULT, TEST_HEADER, KTAP_START, TAP_START, TEST_PLAN]
while lines and not any(re.match(lines.peek())
for re in non_diagnostic_lines):
log.append(lines.pop())
return log
# Printing helper methods:
DIVIDER = '=' * 60
def format_test_divider(message: str, len_message: int) -> str:
"""
Returns string with message centered in fixed width divider.
Example:
'===================== message example ====================='
Parameters:
message - message to be centered in divider line
len_message - length of the message to be printed such that
any characters of the color codes are not counted
Return:
String containing message centered in fixed width divider
"""
default_count = 3 # default number of dashes
len_1 = default_count
len_2 = default_count
difference = len(DIVIDER) - len_message - 2 # 2 spaces added
if difference > 0:
# calculate number of dashes for each side of the divider
len_1 = int(difference / 2)
len_2 = difference - len_1
return ('=' * len_1) + f' {message} ' + ('=' * len_2)
def print_test_header(test: Test, printer: Printer) -> None:
"""
Prints test header with test name and optionally the expected number
of subtests.
Example:
'=================== example (2 subtests) ==================='
Parameters:
test - Test object representing current test being printed
printer - Printer object to output results
"""
message = test.name
if message != "":
# Add a leading space before the subtest counts only if a test name
# is provided using a "# Subtest" header line.
message += " "
if test.expected_count:
if test.expected_count == 1:
message += '(1 subtest)'
else:
message += f'({test.expected_count} subtests)'
printer.print_with_timestamp(format_test_divider(message, len(message)))
def print_log(log: Iterable[str], printer: Printer) -> None:
"""Prints all strings in saved log for test in yellow."""
formatted = textwrap.dedent('\n'.join(log))
for line in formatted.splitlines():
printer.print_with_timestamp(printer.yellow(line))
def format_test_result(test: Test, printer: Printer) -> str:
"""
Returns string with formatted test result with colored status and test
name.
Example:
'[PASSED] example'
Parameters:
test - Test object representing current test being printed
printer - Printer object to output results
Return:
String containing formatted test result
"""
if test.status == TestStatus.SUCCESS:
return printer.green('[PASSED] ') + test.name
if test.status == TestStatus.SKIPPED:
skip_message = printer.yellow('[SKIPPED] ') + test.name
if test.skip_reason != '':
skip_message += printer.yellow(' (' + test.skip_reason + ')')
return skip_message
if test.status == TestStatus.NO_TESTS:
return printer.yellow('[NO TESTS RUN] ') + test.name
if test.status == TestStatus.TEST_CRASHED:
print_log(test.log, printer)
return printer.red('[CRASHED] ') + test.name
print_log(test.log, printer)
return printer.red('[FAILED] ') + test.name
def print_test_result(test: Test, printer: Printer) -> None:
"""
Prints result line with status of test.
Example:
'[PASSED] example'
Parameters:
test - Test object representing current test being printed
printer - Printer object
"""
printer.print_with_timestamp(format_test_result(test, printer))
def print_test_footer(test: Test, printer: Printer) -> None:
"""
Prints test footer with status of test.
Example:
'===================== [PASSED] example ====================='
Parameters:
test - Test object representing current test being printed
printer - Printer object to output results
"""
message = format_test_result(test, printer)
printer.print_with_timestamp(format_test_divider(message,
len(message) - printer.color_len()))
def print_test(test: Test, failed_only: bool, printer: Printer) -> None:
"""
Prints Test object to given printer. For a child test, the result line is
printed. For a parent test, the test header, all child test results, and
the test footer are all printed. If failed_only is true, only failed/crashed
tests will be printed.
Parameters:
test - Test object to print
failed_only - True if only failed/crashed tests should be printed.
printer - Printer object to output results
"""
if test.name == "main":
printer.print_with_timestamp(DIVIDER)
for subtest in test.subtests:
print_test(subtest, failed_only, printer)
printer.print_with_timestamp(DIVIDER)
elif test.subtests != []:
if not failed_only or not test.ok_status():
print_test_header(test, printer)
for subtest in test.subtests:
print_test(subtest, failed_only, printer)
print_test_footer(test, printer)
else:
if not failed_only or not test.ok_status():
print_test_result(test, printer)
def _summarize_failed_tests(test: Test) -> str:
"""Tries to summarize all the failing subtests in `test`."""
def failed_names(test: Test, parent_name: str) -> List[str]:
# Note: we use 'main' internally for the top-level test.
if not parent_name or parent_name == 'main':
full_name = test.name
else:
full_name = parent_name + '.' + test.name
if not test.subtests: # this is a leaf node
return [full_name]
# If all the children failed, just say this subtest failed.
# Don't summarize it down "the top-level test failed", though.
failed_subtests = [sub for sub in test.subtests if not sub.ok_status()]
if parent_name and len(failed_subtests) == len(test.subtests):
return [full_name]
all_failures = [] # type: List[str]
for t in failed_subtests:
all_failures.extend(failed_names(t, full_name))
return all_failures
failures = failed_names(test, '')
# If there are too many failures, printing them out will just be noisy.
if len(failures) > 10: # this is an arbitrary limit
return ''
return 'Failures: ' + ', '.join(failures)
def print_summary_line(test: Test, printer: Printer) -> None:
"""
Prints summary line of test object. Color of line is dependent on
status of test. Color is green if test passes, yellow if test is
skipped, and red if the test fails or crashes. Summary line contains
counts of the statuses of the tests subtests or the test itself if it
has no subtests.
Example:
"Testing complete. Passed: 2, Failed: 0, Crashed: 0, Skipped: 0,
Errors: 0"
test - Test object representing current test being printed
printer - Printer object to output results
"""
if test.status == TestStatus.SUCCESS:
color = printer.green
elif test.status in (TestStatus.SKIPPED, TestStatus.NO_TESTS):
color = printer.yellow
else:
color = printer.red
printer.print_with_timestamp(color(f'Testing complete. {test.counts}'))
# Summarize failures that might have gone off-screen since we had a lot
# of tests (arbitrarily defined as >=100 for now).
if test.ok_status() or test.counts.total() < 100:
return
summarized = _summarize_failed_tests(test)
if not summarized:
return
printer.print_with_timestamp(color(summarized))
# Other methods:
def bubble_up_test_results(test: Test) -> None:
"""
If the test has subtests, add the test counts of the subtests to the
test and check if any of the tests crashed and if so set the test
status to crashed. Otherwise if the test has no subtests add the
status of the test to the test counts.
Parameters:
test - Test object for current test being parsed
"""
subtests = test.subtests
counts = test.counts
status = test.status
for t in subtests:
counts.add_subtest_counts(t.counts)
if counts.total() == 0:
counts.add_status(status)
elif test.counts.get_status() == TestStatus.TEST_CRASHED:
test.status = TestStatus.TEST_CRASHED
if status == TestStatus.FAILURE and test.counts.get_status() == TestStatus.SUCCESS:
counts.add_status(status)
def parse_test(lines: LineStream, expected_num: int, log: List[str], is_subtest: bool, printer: Printer) -> Test:
"""
Finds next test to parse in LineStream, creates new Test object,
parses any subtests of the test, populates Test object with all
information (status, name) about the test and the Test objects for
any subtests, and then returns the Test object. The method accepts
three formats of tests:
Accepted test formats:
- Main KTAP/TAP header
Example:
KTAP version 1
1..4
[subtests]
- Subtest header (must include either the KTAP version line or
"# Subtest" header line)
Example (preferred format with both KTAP version line and
"# Subtest" line):
KTAP version 1
# Subtest: name
1..3
[subtests]
ok 1 name
Example (only "# Subtest" line):
# Subtest: name
1..3
[subtests]
ok 1 name
Example (only KTAP version line, compliant with KTAP v1 spec):
KTAP version 1
1..3
[subtests]
ok 1 name
- Test result line
Example:
ok 1 - test
Parameters:
lines - LineStream of KTAP output to parse
expected_num - expected test number for test to be parsed
log - list of strings containing any preceding diagnostic lines
corresponding to the current test
is_subtest - boolean indicating whether test is a subtest
printer - Printer object to output results
Return:
Test object populated with characteristics and any subtests
"""
test = Test()
test.log.extend(log)
# Parse any errors prior to parsing tests
err_log = parse_diagnostic(lines)
test.log.extend(err_log)
if not is_subtest:
# If parsing the main/top-level test, parse KTAP version line and
# test plan
test.name = "main"
parse_ktap_header(lines, test, printer)
test.log.extend(parse_diagnostic(lines))
parse_test_plan(lines, test)
parent_test = True
else:
# If not the main test, attempt to parse a test header containing
# the KTAP version line and/or subtest header line
ktap_line = parse_ktap_header(lines, test, printer)
subtest_line = parse_test_header(lines, test)
test.log.extend(parse_diagnostic(lines))
parse_test_plan(lines, test)
parent_test = (ktap_line or subtest_line)
if parent_test:
print_test_header(test, printer)
expected_count = test.expected_count
subtests = []
test_num = 1
while parent_test and (expected_count is None or test_num <= expected_count):
# Loop to parse any subtests.
# Break after parsing expected number of tests or
# if expected number of tests is unknown break when test
# result line with matching name to subtest header is found
# or no more lines in stream.
sub_log = parse_diagnostic(lines)
sub_test = Test()
if not lines or (peek_test_name_match(lines, test) and
is_subtest):
if expected_count and test_num <= expected_count:
# If parser reaches end of test before
# parsing expected number of subtests, print
# crashed subtest and record error
test.add_error(printer, 'missing expected subtest!')
sub_test.log.extend(sub_log)
test.counts.add_status(
TestStatus.TEST_CRASHED)
print_test_result(sub_test, printer)
else:
test.log.extend(sub_log)
break
else:
sub_test = parse_test(lines, test_num, sub_log, True, printer)
subtests.append(sub_test)
test_num += 1
test.subtests = subtests
if is_subtest:
# If not main test, look for test result line
test.log.extend(parse_diagnostic(lines))
if test.name != "" and not peek_test_name_match(lines, test):
test.add_error(printer, 'missing subtest result line!')
elif not lines:
print_log(test.log, printer)
test.status = TestStatus.NO_TESTS
test.add_error(printer, 'No more test results!')
else:
parse_test_result(lines, test, expected_num, printer)
# Check for there being no subtests within parent test
if parent_test and len(subtests) == 0:
# Don't override a bad status if this test had one reported.
# Assumption: no subtests means CRASHED is from Test.__init__()
if test.status in (TestStatus.TEST_CRASHED, TestStatus.SUCCESS):
print_log(test.log, printer)
test.status = TestStatus.NO_TESTS
test.add_error(printer, '0 tests run!')
# Add statuses to TestCounts attribute in Test object
bubble_up_test_results(test)
if parent_test and is_subtest:
# If test has subtests and is not the main test object, print
# footer.
print_test_footer(test, printer)
elif is_subtest:
print_test_result(test, printer)
return test
def parse_run_tests(kernel_output: Iterable[str], printer: Printer) -> Test:
"""
Using kernel output, extract KTAP lines, parse the lines for test
results and print condensed test results and summary line.
Parameters:
kernel_output - Iterable object contains lines of kernel output
printer - Printer object to output results
Return:
Test - the main test object with all subtests.
"""
printer.print_with_timestamp(DIVIDER)
lines = extract_tap_lines(kernel_output)
test = Test()
if not lines:
test.name = '<missing>'
test.add_error(printer, 'Could not find any KTAP output. Did any KUnit tests run?\n' +
'Try running with the --raw_output=all option to see any log messages.')
test.status = TestStatus.FAILURE_TO_PARSE_TESTS
else:
test = parse_test(lines, 0, [], False, printer)
if test.status != TestStatus.NO_TESTS:
test.status = test.counts.get_status()
printer.print_with_timestamp(DIVIDER)
return test
@@ -0,0 +1,54 @@
#!/usr/bin/env python3
# SPDX-License-Identifier: GPL-2.0
#
# Utilities for printing and coloring output.
#
# Copyright (C) 2022, Google LLC.
# Author: Daniel Latypov <dlatypov@google.com>
import datetime
import sys
import typing
_RESET = '\033[0;0m'
class Printer:
"""Wraps a file object, providing utilities for coloring output, etc."""
def __init__(self, print: bool=True, output: typing.IO[str]=sys.stdout):
self._output = output
self._print = print
if print:
self._use_color = output.isatty()
else:
self._use_color = False
def print(self, message: str) -> None:
if self._print:
print(message, file=self._output)
def print_with_timestamp(self, message: str) -> None:
ts = datetime.datetime.now().strftime('%H:%M:%S')
self.print(f'[{ts}] {message}')
def _color(self, code: str, text: str) -> str:
if not self._use_color:
return text
return code + text + _RESET
def red(self, text: str) -> str:
return self._color('\033[1;31m', text)
def yellow(self, text: str) -> str:
return self._color('\033[1;33m', text)
def green(self, text: str) -> str:
return self._color('\033[1;32m', text)
def color_len(self) -> int:
"""Returns the length of the color escape codes."""
return len(self.red(''))
# Provides a default instance that prints to stdout
stdout = Printer()
null_printer = Printer(print=False)
File diff suppressed because it is too large Load Diff
+6
View File
@@ -0,0 +1,6 @@
[mypy]
strict = True
# E.g. we can't write subprocess.Popen[str] until Python 3.9+.
# But kunit.py tries to support Python 3.7+, so let's disable it.
disable_error_code = type-arg
@@ -0,0 +1,20 @@
# SPDX-License-Identifier: GPL-2.0
#
# Collection of configs for building non-UML kernels and running them on QEMU.
#
# Copyright (C) 2021, Google LLC.
# Author: Brendan Higgins <brendanhiggins@google.com>
from dataclasses import dataclass
from typing import List
@dataclass(frozen=True)
class QemuArchParams:
linux_arch: str
kconfig: str
qemu_arch: str
kernel_path: str
kernel_command_line: str
extra_qemu_params: List[str]
serial: str = 'stdio'
@@ -0,0 +1,10 @@
from ..qemu_config import QemuArchParams
QEMU_ARCH = QemuArchParams(linux_arch='alpha',
kconfig='''
CONFIG_SERIAL_8250=y
CONFIG_SERIAL_8250_CONSOLE=y''',
qemu_arch='alpha',
kernel_path='arch/alpha/boot/vmlinux',
kernel_command_line='console=ttyS0',
extra_qemu_params=[])
@@ -0,0 +1,13 @@
from ..qemu_config import QemuArchParams
QEMU_ARCH = QemuArchParams(linux_arch='arm',
kconfig='''
CONFIG_ARCH_VIRT=y
CONFIG_SERIAL_AMBA_PL010=y
CONFIG_SERIAL_AMBA_PL010_CONSOLE=y
CONFIG_SERIAL_AMBA_PL011=y
CONFIG_SERIAL_AMBA_PL011_CONSOLE=y''',
qemu_arch='arm',
kernel_path='arch/arm/boot/zImage',
kernel_command_line='console=ttyAMA0',
extra_qemu_params=['-machine', 'virt'])
@@ -0,0 +1,12 @@
from ..qemu_config import QemuArchParams
QEMU_ARCH = QemuArchParams(linux_arch='arm64',
kconfig='''
CONFIG_SERIAL_AMBA_PL010=y
CONFIG_SERIAL_AMBA_PL010_CONSOLE=y
CONFIG_SERIAL_AMBA_PL011=y
CONFIG_SERIAL_AMBA_PL011_CONSOLE=y''',
qemu_arch='aarch64',
kernel_path='arch/arm64/boot/Image.gz',
kernel_command_line='console=ttyAMA0',
extra_qemu_params=['-machine', 'virt', '-cpu', 'max'])
@@ -0,0 +1,16 @@
# SPDX-License-Identifier: GPL-2.0
from ..qemu_config import QemuArchParams
QEMU_ARCH = QemuArchParams(linux_arch='arm',
kconfig='''
CONFIG_CPU_BIG_ENDIAN=y
CONFIG_ARCH_VIRT=y
CONFIG_SERIAL_AMBA_PL010=y
CONFIG_SERIAL_AMBA_PL010_CONSOLE=y
CONFIG_SERIAL_AMBA_PL011=y
CONFIG_SERIAL_AMBA_PL011_CONSOLE=y''',
qemu_arch='arm',
kernel_path='arch/arm/boot/zImage',
kernel_command_line='console=ttyAMA0',
extra_qemu_params=['-machine', 'virt'])
@@ -0,0 +1,10 @@
from ..qemu_config import QemuArchParams
QEMU_ARCH = QemuArchParams(linux_arch='i386',
kconfig='''
CONFIG_SERIAL_8250=y
CONFIG_SERIAL_8250_CONSOLE=y''',
qemu_arch='i386',
kernel_path='arch/x86/boot/bzImage',
kernel_command_line='console=ttyS0',
extra_qemu_params=[])
@@ -0,0 +1,21 @@
# SPDX-License-Identifier: GPL-2.0
from ..qemu_config import QemuArchParams
QEMU_ARCH = QemuArchParams(linux_arch='loongarch',
kconfig='''
CONFIG_EFI_STUB=n
CONFIG_PCI_HOST_GENERIC=y
CONFIG_PVPANIC=y
CONFIG_PVPANIC_PCI=y
CONFIG_SERIAL_8250=y
CONFIG_SERIAL_8250_CONSOLE=y
CONFIG_SERIAL_OF_PLATFORM=y
''',
qemu_arch='loongarch64',
kernel_path='arch/loongarch/boot/vmlinux.elf',
kernel_command_line='console=ttyS0 kunit_shutdown=poweroff',
extra_qemu_params=[
'-machine', 'virt',
'-device', 'pvpanic-pci',
'-cpu', 'max',])
@@ -0,0 +1,10 @@
# SPDX-License-Identifier: GPL-2.0-only
from ..qemu_config import QemuArchParams
QEMU_ARCH = QemuArchParams(linux_arch='m68k',
kconfig='''
CONFIG_VIRT=y''',
qemu_arch='m68k',
kernel_path='vmlinux',
kernel_command_line='console=hvc0',
extra_qemu_params=['-machine', 'virt'])
@@ -0,0 +1,18 @@
# SPDX-License-Identifier: GPL-2.0
from ..qemu_config import QemuArchParams
QEMU_ARCH = QemuArchParams(linux_arch='mips',
kconfig='''
CONFIG_32BIT=y
CONFIG_CPU_BIG_ENDIAN=y
CONFIG_MIPS_MALTA=y
CONFIG_SERIAL_8250=y
CONFIG_SERIAL_8250_CONSOLE=y
CONFIG_POWER_RESET=y
CONFIG_POWER_RESET_SYSCON=y
''',
qemu_arch='mips',
kernel_path='vmlinuz',
kernel_command_line='console=ttyS0',
extra_qemu_params=['-M', 'malta'])
@@ -0,0 +1,19 @@
# SPDX-License-Identifier: GPL-2.0
from ..qemu_config import QemuArchParams
QEMU_ARCH = QemuArchParams(linux_arch='mips',
kconfig='''
CONFIG_CPU_MIPS64_R2=y
CONFIG_64BIT=y
CONFIG_CPU_BIG_ENDIAN=y
CONFIG_MIPS_MALTA=y
CONFIG_SERIAL_8250=y
CONFIG_SERIAL_8250_CONSOLE=y
CONFIG_POWER_RESET=y
CONFIG_POWER_RESET_SYSCON=y
''',
qemu_arch='mips64',
kernel_path='vmlinuz',
kernel_command_line='console=ttyS0',
extra_qemu_params=['-M', 'malta', '-cpu', '5KEc'])
@@ -0,0 +1,19 @@
# SPDX-License-Identifier: GPL-2.0
from ..qemu_config import QemuArchParams
QEMU_ARCH = QemuArchParams(linux_arch='mips',
kconfig='''
CONFIG_CPU_MIPS64_R2=y
CONFIG_64BIT=y
CONFIG_CPU_LITTLE_ENDIAN=y
CONFIG_MIPS_MALTA=y
CONFIG_SERIAL_8250=y
CONFIG_SERIAL_8250_CONSOLE=y
CONFIG_POWER_RESET=y
CONFIG_POWER_RESET_SYSCON=y
''',
qemu_arch='mips64el',
kernel_path='vmlinuz',
kernel_command_line='console=ttyS0',
extra_qemu_params=['-M', 'malta', '-cpu', '5KEc'])
@@ -0,0 +1,18 @@
# SPDX-License-Identifier: GPL-2.0
from ..qemu_config import QemuArchParams
QEMU_ARCH = QemuArchParams(linux_arch='mips',
kconfig='''
CONFIG_32BIT=y
CONFIG_CPU_LITTLE_ENDIAN=y
CONFIG_MIPS_MALTA=y
CONFIG_SERIAL_8250=y
CONFIG_SERIAL_8250_CONSOLE=y
CONFIG_POWER_RESET=y
CONFIG_POWER_RESET_SYSCON=y
''',
qemu_arch='mipsel',
kernel_path='vmlinuz',
kernel_command_line='console=ttyS0',
extra_qemu_params=['-M', 'malta'])
@@ -0,0 +1,18 @@
# SPDX-License-Identifier: GPL-2.0-only
from ..qemu_config import QemuArchParams
QEMU_ARCH = QemuArchParams(linux_arch='openrisc',
kconfig='''
CONFIG_SERIAL_8250=y
CONFIG_SERIAL_8250_CONSOLE=y
CONFIG_SERIAL_OF_PLATFORM=y
CONFIG_POWER_RESET=y
CONFIG_POWER_RESET_SYSCON=y
''',
qemu_arch='or1k',
kernel_path='vmlinux',
kernel_command_line='console=ttyS0',
extra_qemu_params=[
'-machine', 'virt',
'-m', '512',
])
@@ -0,0 +1,13 @@
from ..qemu_config import QemuArchParams
QEMU_ARCH = QemuArchParams(linux_arch='powerpc',
kconfig='''
CONFIG_PPC64=y
CONFIG_CPU_BIG_ENDIAN=y
CONFIG_SERIAL_8250=y
CONFIG_SERIAL_8250_CONSOLE=y
CONFIG_HVC_CONSOLE=y''',
qemu_arch='ppc64',
kernel_path='vmlinux',
kernel_command_line='console=ttyS0',
extra_qemu_params=['-M', 'pseries', '-cpu', 'power8'])
@@ -0,0 +1,17 @@
# SPDX-License-Identifier: GPL-2.0
from ..qemu_config import QemuArchParams
QEMU_ARCH = QemuArchParams(linux_arch='powerpc',
kconfig='''
CONFIG_PPC32=y
CONFIG_CPU_BIG_ENDIAN=y
CONFIG_ADB_CUDA=y
CONFIG_SERIAL_PMACZILOG=y
CONFIG_SERIAL_PMACZILOG_TTYS=y
CONFIG_SERIAL_PMACZILOG_CONSOLE=y
''',
qemu_arch='ppc',
kernel_path='vmlinux',
kernel_command_line='console=ttyS0',
extra_qemu_params=['-M', 'g3beige', '-cpu', 'max'])
@@ -0,0 +1,14 @@
# SPDX-License-Identifier: GPL-2.0
from ..qemu_config import QemuArchParams
QEMU_ARCH = QemuArchParams(linux_arch='powerpc',
kconfig='''
CONFIG_PPC64=y
CONFIG_CPU_LITTLE_ENDIAN=y
CONFIG_HVC_CONSOLE=y
''',
qemu_arch='ppc64',
kernel_path='vmlinux',
kernel_command_line='console=ttyS0',
extra_qemu_params=['-M', 'pseries', '-cpu', 'power8'])
@@ -0,0 +1,28 @@
from ..qemu_config import QemuArchParams
import os
import os.path
import sys
OPENSBI_FILE = 'opensbi-riscv64-generic-fw_dynamic.bin'
OPENSBI_PATH = '/usr/share/qemu/' + OPENSBI_FILE
if not os.path.isfile(OPENSBI_PATH):
print('\n\nOpenSBI bios was not found in "' + OPENSBI_PATH + '".\n'
'Please ensure that qemu-system-riscv is installed, or edit the path in "qemu_configs/riscv.py"\n')
sys.exit()
QEMU_ARCH = QemuArchParams(linux_arch='riscv',
kconfig='''
CONFIG_ARCH_VIRT=y
CONFIG_SERIAL_8250=y
CONFIG_SERIAL_8250_CONSOLE=y
CONFIG_SERIAL_OF_PLATFORM=y
CONFIG_RISCV_SBI_V01=y
CONFIG_SERIAL_EARLYCON_RISCV_SBI=y''',
qemu_arch='riscv64',
kernel_path='arch/riscv/boot/Image',
kernel_command_line='console=ttyS0',
extra_qemu_params=[
'-machine', 'virt',
'-cpu', 'rv64',
'-bios', OPENSBI_PATH])
@@ -0,0 +1,17 @@
# SPDX-License-Identifier: GPL-2.0
from ..qemu_config import QemuArchParams
QEMU_ARCH = QemuArchParams(linux_arch='riscv',
kconfig='''
CONFIG_NONPORTABLE=y
CONFIG_ARCH_RV32I=y
CONFIG_ARCH_VIRT=y
CONFIG_SERIAL_8250=y
CONFIG_SERIAL_8250_CONSOLE=y
CONFIG_SERIAL_OF_PLATFORM=y
''',
qemu_arch='riscv32',
kernel_path='arch/riscv/boot/Image',
kernel_command_line='console=ttyS0',
extra_qemu_params=['-machine', 'virt'])
@@ -0,0 +1,14 @@
from ..qemu_config import QemuArchParams
QEMU_ARCH = QemuArchParams(linux_arch='s390',
kconfig='''
CONFIG_EXPERT=y
CONFIG_TUNE_ZEC12=y
CONFIG_NUMA=y
CONFIG_MODULES=y''',
qemu_arch='s390x',
kernel_path='arch/s390/boot/bzImage',
kernel_command_line='console=ttyS0',
extra_qemu_params=[
'-machine', 's390-ccw-virtio',
'-cpu', 'qemu',])
@@ -0,0 +1,19 @@
# SPDX-License-Identifier: GPL-2.0-only
from ..qemu_config import QemuArchParams
QEMU_ARCH = QemuArchParams(linux_arch='sh',
kconfig='''
CONFIG_CPU_SUBTYPE_SH7751R=y
CONFIG_MEMORY_START=0x0c000000
CONFIG_SH_RTS7751R2D=y
CONFIG_RTS7751R2D_PLUS=y
CONFIG_SERIAL_SH_SCI=y
CONFIG_CMDLINE_EXTEND=y
''',
qemu_arch='sh4',
kernel_path='arch/sh/boot/zImage',
kernel_command_line='console=ttySC1',
serial='null',
extra_qemu_params=[
'-machine', 'r2d',
'-serial', 'mon:stdio'])
@@ -0,0 +1,13 @@
from ..qemu_config import QemuArchParams
QEMU_ARCH = QemuArchParams(linux_arch='sparc',
kconfig='''
CONFIG_KUNIT_FAULT_TEST=n
CONFIG_SPARC32=y
CONFIG_SERIAL_SUNZILOG=y
CONFIG_SERIAL_SUNZILOG_CONSOLE=y
''',
qemu_arch='sparc',
kernel_path='arch/sparc/boot/zImage',
kernel_command_line='console=ttyS0 mem=256M',
extra_qemu_params=['-m', '256'])
@@ -0,0 +1,16 @@
# SPDX-License-Identifier: GPL-2.0
from ..qemu_config import QemuArchParams
QEMU_ARCH = QemuArchParams(linux_arch='sparc',
kconfig='''
CONFIG_64BIT=y
CONFIG_SPARC64=y
CONFIG_PCI=y
CONFIG_SERIAL_SUNSU=y
CONFIG_SERIAL_SUNSU_CONSOLE=y
''',
qemu_arch='sparc64',
kernel_path='arch/sparc/boot/image',
kernel_command_line='console=ttyS0 kunit_shutdown=poweroff',
extra_qemu_params=[])
@@ -0,0 +1,12 @@
from ..qemu_config import QemuArchParams
QEMU_ARCH = QemuArchParams(linux_arch='x86_64',
kconfig='''
CONFIG_SERIAL_8250=y
CONFIG_SERIAL_8250_CONSOLE=y''',
qemu_arch='x86_64',
kernel_path='arch/x86/boot/bzImage',
kernel_command_line='console=ttyS0',
# qboot is faster than SeaBIOS and doesn't mess up
# the terminal.
extra_qemu_params=['-bios', 'qboot.rom'])
+81
View File
@@ -0,0 +1,81 @@
#!/usr/bin/env python3
# SPDX-License-Identifier: GPL-2.0
#
# This file runs some basic checks to verify kunit works.
# It is only of interest if you're making changes to KUnit itself.
#
# Copyright (C) 2021, Google LLC.
# Author: Daniel Latypov <dlatypov@google.com.com>
from concurrent import futures
import datetime
import os
import shutil
import subprocess
import sys
import textwrap
from typing import Dict, List, Sequence
ABS_TOOL_PATH = os.path.abspath(os.path.dirname(__file__))
TIMEOUT = datetime.timedelta(minutes=5).total_seconds()
commands: Dict[str, Sequence[str]] = {
'kunit_tool_test.py': ['./kunit_tool_test.py'],
'kunit smoke test': ['./kunit.py', 'run', '--kunitconfig=lib/kunit', '--build_dir=kunit_run_checks'],
'pytype': ['/bin/sh', '-c', 'pytype *.py'],
'mypy': ['mypy', '--config-file', 'mypy.ini', '--exclude', '_test.py$', '--exclude', 'qemu_configs/', '.'],
}
# The user might not have mypy or pytype installed, skip them if so.
# Note: you can install both via `$ pip install mypy pytype`
necessary_deps : Dict[str, str] = {
'pytype': 'pytype',
'mypy': 'mypy',
}
def main(argv: Sequence[str]) -> None:
if argv:
raise RuntimeError('This script takes no arguments')
future_to_name: Dict[futures.Future[None], str] = {}
executor = futures.ThreadPoolExecutor(max_workers=len(commands))
for name, argv in commands.items():
if name in necessary_deps and shutil.which(necessary_deps[name]) is None:
print(f'{name}: SKIPPED, {necessary_deps[name]} not in $PATH')
continue
f = executor.submit(run_cmd, argv)
future_to_name[f] = name
has_failures = False
print(f'Waiting on {len(future_to_name)} checks ({", ".join(future_to_name.values())})...')
for f in futures.as_completed(future_to_name.keys()):
name = future_to_name[f]
ex = f.exception()
if not ex:
print(f'{name}: PASSED')
continue
has_failures = True
if isinstance(ex, subprocess.TimeoutExpired):
print(f'{name}: TIMED OUT')
elif isinstance(ex, subprocess.CalledProcessError):
print(f'{name}: FAILED')
else:
print(f'{name}: unexpected exception: {ex}')
continue
output = ex.output
if output:
print(textwrap.indent(output.decode(), '> '))
executor.shutdown()
if has_failures:
sys.exit(1)
def run_cmd(argv: Sequence[str]) -> None:
subprocess.check_output(argv, stderr=subprocess.STDOUT, cwd=ABS_TOOL_PATH, timeout=TIMEOUT)
if __name__ == '__main__':
main(sys.argv[1:])
@@ -0,0 +1,32 @@
[ 0.060000] printk: console [mc-1] enabled
[ 0.060000] random: get_random_bytes called from init_oops_id+0x35/0x40 with crng_init=0
[ 0.060000] TAP version 14
[ 0.060000] 1..3
[ 0.060000] # Subtest: kunit-resource-test
[ 0.060000] 1..5
[ 0.060000] ok 1 - kunit_resource_test_init_resources
[ 0.060000] ok 2 - kunit_resource_test_alloc_resource
[ 0.060000] ok 3 - kunit_resource_test_destroy_resource
[ 0.060000] ok 4 - kunit_resource_test_cleanup_resources
[ 0.060000] ok 5 - kunit_resource_test_proper_free_ordering
[ 0.060000] ok 1 - kunit-resource-test
[ 0.060000] # Subtest: kunit-try-catch-test
[ 0.060000] 1..2
[ 0.060000] ok 1 - kunit_test_try_catch_successful_try_no_catch
[ 0.060000] ok 2 - kunit_test_try_catch_unsuccessful_try_does_catch
[ 0.060000] ok 2 - kunit-try-catch-test
[ 0.060000] # Subtest: string-stream-test
[ 0.060000] 1..3
[ 0.060000] ok 1 - string_stream_test_empty_on_creation
[ 0.060000] ok 2 - string_stream_test_not_empty_after_add
[ 0.060000] ok 3 - string_stream_test_get_string
[ 0.060000] ok 3 - string-stream-test
[ 0.060000] List of all partitions:
[ 0.060000] No filesystem could mount root, tried:
[ 0.060000]
[ 0.060000] Kernel panic - not syncing: VFS: Unable to mount root fs on unknown-block(98,0)
[ 0.060000] CPU: 0 PID: 1 Comm: swapper Not tainted 5.4.0-rc1-gea2dd7c0875e-dirty #2
[ 0.060000] Stack:
[ 0.060000] 602086f8 601bc260 705c0000 705c0000
[ 0.060000] 602086f8 6005fcec 705c0000 6002c6ab
[ 0.060000] 6005fcec 601bc260 705c0000 3000000010
@@ -0,0 +1,38 @@
[ 0.060000] printk: console [mc-1] enabled
[ 0.060000] random: get_random_bytes called from init_oops_id+0x35/0x40 with crng_init=0
[ 0.060000] TAP version 14
[ 0.060000] 1..3
[ 0.060000] # Subtest: kunit-resource-test
[ 0.060000] 1..5
[ 0.060000] ok 1 - kunit_resource_test_init_resources
[ 0.060000] ok 2 - kunit_resource_test_alloc_resource
[ 0.060000] ok 3 - kunit_resource_test_destroy_resource
[ 0.060000] kAFS: Red Hat AFS client v0.1 registering.
[ 0.060000] FS-Cache: Netfs 'afs' registered for caching
[ 0.060000] *** VALIDATE kAFS ***
[ 0.060000] Btrfs loaded, crc32c=crc32c-generic, debug=on, assert=on, integrity-checker=on, ref-verify=on
[ 0.060000] BTRFS: selftest: sectorsize: 4096 nodesize: 4096
[ 0.060000] BTRFS: selftest: running btrfs free space cache tests
[ 0.060000] ok 4 - kunit_resource_test_cleanup_resources
[ 0.060000] ok 5 - kunit_resource_test_proper_free_ordering
[ 0.060000] ok 1 - kunit-resource-test
[ 0.060000] # Subtest: kunit-try-catch-test
[ 0.060000] 1..2
[ 0.060000] ok 1 - kunit_test_try_catch_successful_try_no_catch
[ 0.060000] ok 2 - kunit_test_try_catch_unsuccessful_try_does_catch
[ 0.060000] ok 2 - kunit-try-catch-test
[ 0.060000] # Subtest: string-stream-test
[ 0.060000] 1..3
[ 0.060000] ok 1 - string_stream_test_empty_on_creation
[ 0.060000] ok 2 - string_stream_test_not_empty_after_add
[ 0.060000] ok 3 - string_stream_test_get_string
[ 0.060000] ok 3 - string-stream-test
[ 0.060000] List of all partitions:
[ 0.060000] No filesystem could mount root, tried:
[ 0.060000]
[ 0.060000] Kernel panic - not syncing: VFS: Unable to mount root fs on unknown-block(98,0)
[ 0.060000] CPU: 0 PID: 1 Comm: swapper Not tainted 5.4.0-rc1-gea2dd7c0875e-dirty #2
[ 0.060000] Stack:
[ 0.060000] 602086f8 601bc260 705c0000 705c0000
[ 0.060000] 602086f8 6005fcec 705c0000 6002c6ab
[ 0.060000] 6005fcec 601bc260 705c0000 3000000010
@@ -0,0 +1,33 @@
TAP version 14
1..2
# Subtest: sysctl_test
1..8
# sysctl_test_dointvec_null_tbl_data: sysctl_test_dointvec_null_tbl_data passed
ok 1 - sysctl_test_dointvec_null_tbl_data
# sysctl_test_dointvec_table_maxlen_unset: sysctl_test_dointvec_table_maxlen_unset passed
ok 2 - sysctl_test_dointvec_table_maxlen_unset
# sysctl_test_dointvec_table_len_is_zero: sysctl_test_dointvec_table_len_is_zero passed
ok 3 - sysctl_test_dointvec_table_len_is_zero
# sysctl_test_dointvec_table_read_but_position_set: sysctl_test_dointvec_table_read_but_position_set passed
ok 4 - sysctl_test_dointvec_table_read_but_position_set
# sysctl_test_dointvec_happy_single_positive: sysctl_test_dointvec_happy_single_positive passed
ok 5 - sysctl_test_dointvec_happy_single_positive
# sysctl_test_dointvec_happy_single_negative: sysctl_test_dointvec_happy_single_negative passed
ok 6 - sysctl_test_dointvec_happy_single_negative
# sysctl_test_dointvec_single_less_int_min: sysctl_test_dointvec_single_less_int_min passed
ok 7 - sysctl_test_dointvec_single_less_int_min
# sysctl_test_dointvec_single_greater_int_max: sysctl_test_dointvec_single_greater_int_max passed
ok 8 - sysctl_test_dointvec_single_greater_int_max
kunit sysctl_test: all tests passed
ok 1 - sysctl_test
# Subtest: example
1..2
init_suite
# example_simple_test: initializing
# example_simple_test: example_simple_test passed
ok 1 - example_simple_test
# example_mock_test: initializing
# example_mock_test: example_mock_test passed
ok 2 - example_mock_test
kunit example: all tests passed
ok 2 - example
@@ -0,0 +1,34 @@
TAP version 14
1..2
# Subtest: sysctl_test
1..4
# sysctl_test_dointvec_null_tbl_data: sysctl_test_dointvec_null_tbl_data passed
ok 1 - sysctl_test_dointvec_null_tbl_data
# Subtest: example
1..2
init_suite
# example_simple_test: initializing
# example_simple_test: example_simple_test passed
ok 1 - example_simple_test
# example_mock_test: initializing
# example_mock_test: example_mock_test passed
ok 2 - example_mock_test
kunit example: all tests passed
ok 2 - example
# sysctl_test_dointvec_table_len_is_zero: sysctl_test_dointvec_table_len_is_zero passed
ok 3 - sysctl_test_dointvec_table_len_is_zero
# sysctl_test_dointvec_table_read_but_position_set: sysctl_test_dointvec_table_read_but_position_set passed
ok 4 - sysctl_test_dointvec_table_read_but_position_set
kunit sysctl_test: all tests passed
ok 1 - sysctl_test
# Subtest: example
1..2
init_suite
# example_simple_test: initializing
# example_simple_test: example_simple_test passed
ok 1 - example_simple_test
# example_mock_test: initializing
# example_mock_test: example_mock_test passed
ok 2 - example_mock_test
kunit example: all tests passed
ok 2 - example
@@ -0,0 +1,10 @@
KTAP version 1
1..2
KTAP version 1
1..1
ok 1 test 1
not ok 1 subtest 1
KTAP version 1
1..1
not ok 1 subsubtest 1
not ok 2 subtest 2
@@ -0,0 +1,37 @@
TAP version 14
1..2
# Subtest: sysctl_test
1..8
# sysctl_test_dointvec_null_tbl_data: sysctl_test_dointvec_null_tbl_data passed
ok 1 - sysctl_test_dointvec_null_tbl_data
# sysctl_test_dointvec_table_maxlen_unset: sysctl_test_dointvec_table_maxlen_unset passed
ok 2 - sysctl_test_dointvec_table_maxlen_unset
# sysctl_test_dointvec_table_len_is_zero: sysctl_test_dointvec_table_len_is_zero passed
ok 3 - sysctl_test_dointvec_table_len_is_zero
# sysctl_test_dointvec_table_read_but_position_set: sysctl_test_dointvec_table_read_but_position_set passed
ok 4 - sysctl_test_dointvec_table_read_but_position_set
# sysctl_test_dointvec_happy_single_positive: sysctl_test_dointvec_happy_single_positive passed
ok 5 - sysctl_test_dointvec_happy_single_positive
# sysctl_test_dointvec_happy_single_negative: sysctl_test_dointvec_happy_single_negative passed
ok 6 - sysctl_test_dointvec_happy_single_negative
# sysctl_test_dointvec_single_less_int_min: sysctl_test_dointvec_single_less_int_min passed
ok 7 - sysctl_test_dointvec_single_less_int_min
# sysctl_test_dointvec_single_greater_int_max: sysctl_test_dointvec_single_greater_int_max passed
ok 8 - sysctl_test_dointvec_single_greater_int_max
kunit sysctl_test: all tests passed
ok 1 - sysctl_test
# Subtest: example
1..2
init_suite
# example_simple_test: initializing
# example_simple_test: EXPECTATION FAILED at lib/kunit/example-test.c:30
Expected 1 + 1 == 3, but
1 + 1 == 2
3 == 3
# example_simple_test: example_simple_test failed
not ok 1 - example_simple_test
# example_mock_test: initializing
# example_mock_test: example_mock_test passed
ok 2 - example_mock_test
kunit example: one or more tests failed
not ok 2 - example
@@ -0,0 +1,15 @@
TAP version 13
1..3
# selftests: membarrier: membarrier_test_single_thread
# TAP version 13
# 1..2
# ok 1 sys_membarrier available
# ok 2 sys membarrier invalid command test: command = -1, flags = 0, errno = 22. Failed as expected
ok 1 selftests: membarrier: membarrier_test_single_thread
# selftests: membarrier: membarrier_test_multi_thread
# TAP version 13
# 1..2
# ok 1 sys_membarrier available
# ok 2 sys membarrier invalid command test: command = -1, flags = 0, errno = 22. Failed as expected
ok 2 selftests: membarrier: membarrier_test_multi_thread
ok 3 # SKIP selftests: membarrier: membarrier_test_multi_thread
@@ -0,0 +1,31 @@
KTAP version 1
# Subtest: sysctl_test
# sysctl_test_dointvec_null_tbl_data: sysctl_test_dointvec_null_tbl_data passed
ok 1 - sysctl_test_dointvec_null_tbl_data
# sysctl_test_dointvec_table_maxlen_unset: sysctl_test_dointvec_table_maxlen_unset passed
ok 2 - sysctl_test_dointvec_table_maxlen_unset
# sysctl_test_dointvec_table_len_is_zero: sysctl_test_dointvec_table_len_is_zero passed
ok 3 - sysctl_test_dointvec_table_len_is_zero
# sysctl_test_dointvec_table_read_but_position_set: sysctl_test_dointvec_table_read_but_position_set passed
ok 4 - sysctl_test_dointvec_table_read_but_position_set
# sysctl_test_dointvec_happy_single_positive: sysctl_test_dointvec_happy_single_positive passed
ok 5 - sysctl_test_dointvec_happy_single_positive
# sysctl_test_dointvec_happy_single_negative: sysctl_test_dointvec_happy_single_negative passed
ok 6 - sysctl_test_dointvec_happy_single_negative
# sysctl_test_dointvec_single_less_int_min: sysctl_test_dointvec_single_less_int_min passed
ok 7 - sysctl_test_dointvec_single_less_int_min
# sysctl_test_dointvec_single_greater_int_max: sysctl_test_dointvec_single_greater_int_max passed
ok 8 - sysctl_test_dointvec_single_greater_int_max
kunit sysctl_test: all tests passed
ok 1 - sysctl_test
# Subtest: example
1..2
init_suite
# example_simple_test: initializing
# example_simple_test: example_simple_test passed
ok 1 - example_simple_test
# example_mock_test: initializing
# example_mock_test: example_mock_test passed
ok 2 - example_mock_test
kunit example: all tests passed
ok 2 - example
@@ -0,0 +1,7 @@
TAP version 14
1..1
# Subtest: suite
1..1
# Subtest: case
ok 1 - case
ok 1 - suite
@@ -0,0 +1,75 @@
Core dump limits :
soft - 0
hard - NONE
Checking environment variables for a tempdir...none found
Checking if /dev/shm is on tmpfs...OK
Checking PROT_EXEC mmap in /dev/shm...OK
Adding 24743936 bytes to physical memory to account for exec-shield gap
Linux version 4.12.0-rc3-00010-g7319eb35f493-dirty (brendanhiggins@mactruck.svl.corp.google.com) (gcc version 7.3.0 (Debian 7.3.0-5) ) #29 Thu Mar 15 14:57:19 PDT 2018
Built 1 zonelists in Zone order, mobility grouping on. Total pages: 14038
Kernel command line: root=98:0
PID hash table entries: 256 (order: -1, 2048 bytes)
Dentry cache hash table entries: 8192 (order: 4, 65536 bytes)
Inode-cache hash table entries: 4096 (order: 3, 32768 bytes)
Memory: 27868K/56932K available (1681K kernel code, 480K rwdata, 400K rodata, 89K init, 205K bss, 29064K reserved, 0K cma-reserved)
SLUB: HWalign=64, Order=0-3, MinObjects=0, CPUs=1, Nodes=1
NR_IRQS:15
clocksource: timer: mask: 0xffffffffffffffff max_cycles: 0x1cd42e205, max_idle_ns: 881590404426 ns
Calibrating delay loop... 7384.26 BogoMIPS (lpj=36921344)
pid_max: default: 32768 minimum: 301
Mount-cache hash table entries: 512 (order: 0, 4096 bytes)
Mountpoint-cache hash table entries: 512 (order: 0, 4096 bytes)
Checking that host ptys support output SIGIO...Yes
Checking that host ptys support SIGIO on close...No, enabling workaround
Using 2.6 host AIO
clocksource: jiffies: mask: 0xffffffff max_cycles: 0xffffffff, max_idle_ns: 19112604462750000 ns
futex hash table entries: 256 (order: 0, 6144 bytes)
clocksource: Switched to clocksource timer
console [stderr0] disabled
mconsole (version 2) initialized on /usr/local/google/home/brendanhiggins/.uml/6Ijecl/mconsole
Checking host MADV_REMOVE support...OK
workingset: timestamp_bits=62 max_order=13 bucket_order=0
Block layer SCSI generic (bsg) driver version 0.4 loaded (major 254)
io scheduler noop registered
io scheduler deadline registered
io scheduler cfq registered (default)
io scheduler mq-deadline registered
io scheduler kyber registered
Initialized stdio console driver
Using a channel type which is configured out of UML
setup_one_line failed for device 1 : Configuration failed
Using a channel type which is configured out of UML
setup_one_line failed for device 2 : Configuration failed
Using a channel type which is configured out of UML
setup_one_line failed for device 3 : Configuration failed
Using a channel type which is configured out of UML
setup_one_line failed for device 4 : Configuration failed
Using a channel type which is configured out of UML
setup_one_line failed for device 5 : Configuration failed
Using a channel type which is configured out of UML
setup_one_line failed for device 6 : Configuration failed
Using a channel type which is configured out of UML
setup_one_line failed for device 7 : Configuration failed
Using a channel type which is configured out of UML
setup_one_line failed for device 8 : Configuration failed
Using a channel type which is configured out of UML
setup_one_line failed for device 9 : Configuration failed
Using a channel type which is configured out of UML
setup_one_line failed for device 10 : Configuration failed
Using a channel type which is configured out of UML
setup_one_line failed for device 11 : Configuration failed
Using a channel type which is configured out of UML
setup_one_line failed for device 12 : Configuration failed
Using a channel type which is configured out of UML
setup_one_line failed for device 13 : Configuration failed
Using a channel type which is configured out of UML
setup_one_line failed for device 14 : Configuration failed
Using a channel type which is configured out of UML
setup_one_line failed for device 15 : Configuration failed
Console initialized on /dev/tty0
console [tty0] enabled
console [mc-1] enabled
List of all partitions:
No filesystem could mount root, tried:
Kernel panic - not syncing: VFS: Unable to mount root fs on unknown-block(98,0)
@@ -0,0 +1,2 @@
TAP version 14
1..0
@@ -0,0 +1,26 @@
[ 0.060000] printk: console [mc-1] enabled
[ 0.060000] random: get_random_bytes called from init_oops_id+0x35/0x40 with crng_init=0
[ 0.060000] TAP version 14
[ 0.060000] 1..3
[ 0.060000] # Subtest: kunit-resource-test
[ 0.060000] 1..5
[ 0.060000] ok 1 - kunit_resource_test_init_resources
[ 0.060000] ok 2 - kunit_resource_test_alloc_resource
[ 0.060000] ok 3 - kunit_resource_test_destroy_resource
[ 0.060000] ok 4 - kunit_resource_test_cleanup_resources
[ 0.060000] ok 5 - kunit_resource_test_proper_free_ordering
[ 0.060000] ok 1 - kunit-resource-test
[ 0.060000] # Subtest: kunit-try-catch-test
[ 0.060000] 1..2
[ 0.060000] ok 1 - kunit_test_try_catch_successful_try_no_catch
[ 0.060000] ok 2 - kunit_test_try_catch_unsuccessful_try_does_catch
[ 0.060000] ok 2 - kunit-try-catch-test
[ 0.060000] # Subtest: string-stream-test
[ 0.060000] 1..3
[ 0.060000] ok 1 - string_stream_test_empty_on_creation
[ 0.060000] Kernel panic - not syncing: VFS: Unable to mount root fs on unknown-block(98,0)
[ 0.060000] CPU: 0 PID: 1 Comm: swapper Not tainted 5.4.0-rc1-gea2dd7c0875e-dirty #2
[ 0.060000] Stack:
[ 0.060000] 602086f8 601bc260 705c0000 705c0000
[ 0.060000] 602086f8 6005fcec 705c0000 6002c6ab
[ 0.060000] 6005fcec 601bc260 705c0000 3000000010
@@ -0,0 +1,32 @@
[ 0.060000][ T1] printk: console [mc-1] enabled
[ 0.060000][ T1] random: get_random_bytes called from init_oops_id+0x35/0x40 with crng_init=0
[ 0.060000][ T1] TAP version 14
[ 0.060000][ T1] 1..3
[ 0.060000][ T1] # Subtest: kunit-resource-test
[ 0.060000][ T1] 1..5
[ 0.060000][ T1] ok 1 - kunit_resource_test_init_resources
[ 0.060000][ T1] ok 2 - kunit_resource_test_alloc_resource
[ 0.060000][ T1] ok 3 - kunit_resource_test_destroy_resource
[ 0.060000][ T1] ok 4 - kunit_resource_test_cleanup_resources
[ 0.060000][ T1] ok 5 - kunit_resource_test_proper_free_ordering
[ 0.060000][ T1] ok 1 - kunit-resource-test
[ 0.060000][ T1] # Subtest: kunit-try-catch-test
[ 0.060000][ T1] 1..2
[ 0.060000][ T1] ok 1 - kunit_test_try_catch_successful_try_no_catch
[ 0.060000][ T1] ok 2 - kunit_test_try_catch_unsuccessful_try_does_catch
[ 0.060000][ T1] ok 2 - kunit-try-catch-test
[ 0.060000][ T1] # Subtest: string-stream-test
[ 0.060000][ T1] 1..3
[ 0.060000][ T1] ok 1 - string_stream_test_empty_on_creation
[ 0.060000][ T1] ok 2 - string_stream_test_not_empty_after_add
[ 0.060000][ T1] ok 3 - string_stream_test_get_string
[ 0.060000][ T1] ok 3 - string-stream-test
[ 0.060000][ T1] List of all partitions:
[ 0.060000][ T1] No filesystem could mount root, tried:
[ 0.060000][ T1]
[ 0.060000][ T1] Kernel panic - not syncing: VFS: Unable to mount root fs on unknown-block(98,0)
[ 0.060000][ T1] CPU: 0 PID: 1 Comm: swapper Not tainted 5.4.0-rc1-gea2dd7c0875e-dirty #2
[ 0.060000][ T1] Stack:
[ 0.060000][ T1] 602086f8 601bc260 705c0000 705c0000
[ 0.060000][ T1] 602086f8 6005fcec 705c0000 6002c6ab
[ 0.060000][ T1] 6005fcec 601bc260 705c0000 3000000010
@@ -0,0 +1,106 @@
Linux version 5.1.0-rc7-00061-g04652f1cb4aa0 (brendanhiggins@mactruck.svl.corp.google.com) (gcc version 7.3.0 (Debian 7.3.0-18)) #163 Wed May 8 16:18:20 PDT 2019
Built 1 zonelists, mobility grouping on. Total pages: 69906
Kernel command line: mem=256M root=98:0
Dentry cache hash table entries: 65536 (order: 7, 524288 bytes)
Inode-cache hash table entries: 32768 (order: 6, 262144 bytes)
Memory: 254468K/283500K available (1734K kernel code, 489K rwdata, 396K rodata, 85K init, 216K bss, 29032K reserved, 0K cma-reserved)
SLUB: HWalign=64, Order=0-3, MinObjects=0, CPUs=1, Nodes=1
NR_IRQS: 15
clocksource: timer: mask: 0xffffffffffffffff max_cycles: 0x1cd42e205, max_idle_ns: 881590404426 ns
------------[ cut here ]------------
WARNING: CPU: 0 PID: 0 at kernel/time/clockevents.c:458 clockevents_register_device+0x143/0x160
posix-timer cpumask == cpu_all_mask, using cpu_possible_mask instead
CPU: 0 PID: 0 Comm: swapper Not tainted 5.1.0-rc7-00061-g04652f1cb4aa0 #163
Stack:
6005cc00 60233e18 60233e60 60233e18
60233e60 00000009 00000000 6002a1b4
1ca00000000 60071c23 60233e78 100000000000062
Call Trace:
[<600214c5>] ? os_is_signal_stack+0x15/0x30
[<6005c5ec>] ? printk+0x0/0x9b
[<6001597e>] ? show_stack+0xbe/0x1c0
[<6005cc00>] ? __printk_safe_exit+0x0/0x40
[<6002a1b4>] ? __warn+0x144/0x170
[<60071c23>] ? clockevents_register_device+0x143/0x160
[<60021440>] ? get_signals+0x0/0x10
[<6005c5ec>] ? printk+0x0/0x9b
[<6002a27b>] ? warn_slowpath_fmt+0x9b/0xb0
[<6005c5ec>] ? printk+0x0/0x9b
[<6002a1e0>] ? warn_slowpath_fmt+0x0/0xb0
[<6005c5ec>] ? printk+0x0/0x9b
[<60021440>] ? get_signals+0x0/0x10
[<600213f0>] ? block_signals+0x0/0x20
[<60071c23>] ? clockevents_register_device+0x143/0x160
[<60021440>] ? get_signals+0x0/0x10
[<600213f0>] ? block_signals+0x0/0x20
[<6005c5ec>] ? printk+0x0/0x9b
[<60001bc8>] ? start_kernel+0x477/0x56a
[<600036f1>] ? start_kernel_proc+0x46/0x4d
[<60014442>] ? new_thread_handler+0x82/0xc0
random: get_random_bytes called from print_oops_end_marker+0x4c/0x60 with crng_init=0
---[ end trace c83434852b3702d3 ]---
Calibrating delay loop... 6958.28 BogoMIPS (lpj=34791424)
pid_max: default: 32768 minimum: 301
Mount-cache hash table entries: 1024 (order: 1, 8192 bytes)
Mountpoint-cache hash table entries: 1024 (order: 1, 8192 bytes)
*** VALIDATE proc ***
Checking that host ptys support output SIGIO...Yes
Checking that host ptys support SIGIO on close...No, enabling workaround
clocksource: jiffies: mask: 0xffffffff max_cycles: 0xffffffff, max_idle_ns: 19112604462750000 ns
futex hash table entries: 256 (order: 0, 6144 bytes)
clocksource: Switched to clocksource timer
printk: console [stderr0] disabled
mconsole (version 2) initialized on /usr/local/google/home/brendanhiggins/.uml/VZ2qMm/mconsole
Checking host MADV_REMOVE support...OK
workingset: timestamp_bits=62 max_order=16 bucket_order=0
Block layer SCSI generic (bsg) driver version 0.4 loaded (major 254)
io scheduler mq-deadline registered
io scheduler kyber registered
Initialized stdio console driver
Using a channel type which is configured out of UML
setup_one_line failed for device 1 : Configuration failed
Using a channel type which is configured out of UML
setup_one_line failed for device 2 : Configuration failed
Using a channel type which is configured out of UML
setup_one_line failed for device 3 : Configuration failed
Using a channel type which is configured out of UML
setup_one_line failed for device 4 : Configuration failed
Using a channel type which is configured out of UML
setup_one_line failed for device 5 : Configuration failed
Using a channel type which is configured out of UML
setup_one_line failed for device 6 : Configuration failed
Using a channel type which is configured out of UML
setup_one_line failed for device 7 : Configuration failed
Using a channel type which is configured out of UML
setup_one_line failed for device 8 : Configuration failed
Using a channel type which is configured out of UML
setup_one_line failed for device 9 : Configuration failed
Using a channel type which is configured out of UML
setup_one_line failed for device 10 : Configuration failed
Using a channel type which is configured out of UML
setup_one_line failed for device 11 : Configuration failed
Using a channel type which is configured out of UML
setup_one_line failed for device 12 : Configuration failed
Using a channel type which is configured out of UML
setup_one_line failed for device 13 : Configuration failed
Using a channel type which is configured out of UML
setup_one_line failed for device 14 : Configuration failed
Using a channel type which is configured out of UML
setup_one_line failed for device 15 : Configuration failed
Console initialized on /dev/tty0
printk: console [tty0] enabled
printk: console [mc-1] enabled
TAP version 14
# Subtest: example
1..2
init_suite
# example_simple_test: initializing
# example_simple_test: example_simple_test passed
ok 1 - example_simple_test
# example_mock_test: initializing
# example_mock_test: example_mock_test passed
ok 2 - example_mock_test
kunit example: all tests passed
ok 1 - example
List of all partitions:
@@ -0,0 +1,33 @@
[ 0.060000] printk: console [mc-1] enabled
[ 0.060000] random: get_random_bytes called from init_oops_id+0x35/0x40 with crng_init=0
[ 0.060000] TAP version 14
[ 0.060000] # Subtest: kunit-resource-test
[ 0.060000] 1..5
[ 0.060000] ok 1 - kunit_resource_test_init_resources
[ 0.060000] ok 2 - kunit_resource_test_alloc_resource
[ 0.060000] ok 3 - kunit_resource_test_destroy_resource
[ 0.060000] foo bar #
[ 0.060000] ok 4 - kunit_resource_test_cleanup_resources
[ 0.060000] ok 5 - kunit_resource_test_proper_free_ordering
[ 0.060000] ok 1 - kunit-resource-test
[ 0.060000] foo bar # non-kunit output
[ 0.060000] # Subtest: kunit-try-catch-test
[ 0.060000] 1..2
[ 0.060000] ok 1 - kunit_test_try_catch_successful_try_no_catch
[ 0.060000] ok 2 - kunit_test_try_catch_unsuccessful_try_does_catch
[ 0.060000] ok 2 - kunit-try-catch-test
[ 0.060000] # Subtest: string-stream-test
[ 0.060000] 1..3
[ 0.060000] ok 1 - string_stream_test_empty_on_creation
[ 0.060000] ok 2 - string_stream_test_not_empty_after_add
[ 0.060000] ok 3 - string_stream_test_get_string
[ 0.060000] ok 3 - string-stream-test
[ 0.060000] List of all partitions:
[ 0.060000] No filesystem could mount root, tried:
[ 0.060000]
[ 0.060000] Kernel panic - not syncing: VFS: Unable to mount root fs on unknown-block(98,0)
[ 0.060000] CPU: 0 PID: 1 Comm: swapper Not tainted 5.4.0-rc1-gea2dd7c0875e-dirty #2
[ 0.060000] Stack:
[ 0.060000] 602086f8 601bc260 705c0000 705c0000
[ 0.060000] 602086f8 6005fcec 705c0000 6002c6ab
[ 0.060000] 6005fcec 601bc260 705c0000 3000000010
@@ -0,0 +1,9 @@
KTAP version 1
1..1
KTAP version 1
# Subtest: suite
# module: example
1..1
# test.speed: slow
ok 1 test
ok 1 suite
@@ -0,0 +1,8 @@
KTAP version 1
1..1
KTAP version 1
1..3
ok 1 case_1
ok 2 case_2
ok 3 case_3
ok 1 suite
@@ -0,0 +1,7 @@
KTAP version 1
1..1
KTAP version 1
# Subtest: suite
1..1
ok 1 test
ok 1 suite
@@ -0,0 +1,34 @@
printk: console [mc-1] enabled
random: get_random_bytes called from init_oops_id+0x35/0x40 with crng_init=0
TAP version 14
1..3
# Subtest: kunit-resource-test
1..5
ok 1 - kunit_resource_test_init_resources
ok 2 - kunit_resource_test_alloc_resource
ok 3 - kunit_resource_test_destroy_resource
foo bar #
ok 4 - kunit_resource_test_cleanup_resources
ok 5 - kunit_resource_test_proper_free_ordering
ok 1 - kunit-resource-test
foo bar # non-kunit output
# Subtest: kunit-try-catch-test
1..2
ok 1 - kunit_test_try_catch_successful_try_no_catch
ok 2 - kunit_test_try_catch_unsuccessful_try_does_catch
ok 2 - kunit-try-catch-test
# Subtest: string-stream-test
1..3
ok 1 - string_stream_test_empty_on_creation
ok 2 - string_stream_test_not_empty_after_add
ok 3 - string_stream_test_get_string
ok 3 - string-stream-test
List of all partitions:
No filesystem could mount root, tried:
Kernel panic - not syncing: VFS: Unable to mount root fs on unknown-block(98,0)
CPU: 0 PID: 1 Comm: swapper Not tainted 5.4.0-rc1-gea2dd7c0875e-dirty #2
Stack:
602086f8 601bc260 705c0000 705c0000
602086f8 6005fcec 705c0000 6002c6ab
6005fcec 601bc260 705c0000 3000000010
@@ -0,0 +1,34 @@
[ 0.060000] printk: console [mc-1] enabled
[ 0.060000] random: get_random_bytes called from init_oops_id+0x35/0x40 with crng_init=0
[ 0.060000] TAP version 14
[ 0.060000] 1..3
[ 0.060000] # Subtest: kunit-resource-test
[ 0.060000] 1..5
[ 0.060000] ok 1 - kunit_resource_test_init_resources
[ 0.060000] ok 2 - kunit_resource_test_alloc_resource
[ 0.060000] ok 3 - kunit_resource_test_destroy_resource
[ 0.060000] foo bar #
[ 0.060000] ok 4 - kunit_resource_test_cleanup_resources
[ 0.060000] ok 5 - kunit_resource_test_proper_free_ordering
[ 0.060000] ok 1 - kunit-resource-test
[ 0.060000] foo bar # non-kunit output
[ 0.060000] # Subtest: kunit-try-catch-test
[ 0.060000] 1..2
[ 0.060000] ok 1 - kunit_test_try_catch_successful_try_no_catch
[ 0.060000] ok 2 - kunit_test_try_catch_unsuccessful_try_does_catch
[ 0.060000] ok 2 - kunit-try-catch-test
[ 0.060000] # Subtest: string-stream-test
[ 0.060000] 1..3
[ 0.060000] ok 1 - string_stream_test_empty_on_creation
[ 0.060000] ok 2 - string_stream_test_not_empty_after_add
[ 0.060000] ok 3 - string_stream_test_get_string
[ 0.060000] ok 3 - string-stream-test
[ 0.060000] List of all partitions:
[ 0.060000] No filesystem could mount root, tried:
[ 0.060000]
[ 0.060000] Kernel panic - not syncing: VFS: Unable to mount root fs on unknown-block(98,0)
[ 0.060000] CPU: 0 PID: 1 Comm: swapper Not tainted 5.4.0-rc1-gea2dd7c0875e-dirty #2
[ 0.060000] Stack:
[ 0.060000] 602086f8 601bc260 705c0000 705c0000
[ 0.060000] 602086f8 6005fcec 705c0000 6002c6ab
[ 0.060000] 6005fcec 601bc260 705c0000 3000000010
@@ -0,0 +1,17 @@
#
# Automatically generated file; DO NOT EDIT.
# User Mode Linux/x86 4.12.0-rc3 Kernel Configuration
#
CONFIG_UML=y
CONFIG_MMU=y
#
# UML-specific options
#
#
# Host processor type and features
#
# CONFIG_MK8 is not set
CONFIG_TEST=y
CONFIG_EXAMPLE_TEST=y
@@ -0,0 +1,15 @@
TAP version 14
1..2
# Subtest: string-stream-test
1..3
ok 1 - string_stream_test_empty_on_creation # SKIP all tests skipped
ok 2 - string_stream_test_not_empty_after_add # SKIP all tests skipped
ok 3 - string_stream_test_get_string # SKIP all tests skipped
ok 1 - string-stream-test # SKIP
# Subtest: example
1..2
# example_simple_test: initializing
ok 1 - example_simple_test # SKIP all tests skipped
# example_skip_test: initializing
ok 2 - example_skip_test # SKIP this test should be skipped
ok 2 - example # SKIP
@@ -0,0 +1,15 @@
TAP version 14
1..2
# Subtest: string-stream-test
1..3
ok 1 - string_stream_test_empty_on_creation
ok 2 - string_stream_test_not_empty_after_add
ok 3 - string_stream_test_get_string
ok 1 - string-stream-test
# Subtest: example
1..2
# example_simple_test: initializing
ok 1 - example_simple_test
# example_skip_test: initializing
ok 2 - example_skip_test # SKIP this test should be skipped
ok 2 - example
@@ -0,0 +1,16 @@
KTAP version 1
1..2
# Subtest: sysctl_test
1..1
# sysctl_test_dointvec_null_tbl_data: sysctl_test_dointvec_null_tbl_data passed
ok 1 - sysctl_test_dointvec_null_tbl_data
kunit sysctl_test: all tests passed
ok 1 - sysctl_test
# Subtest: example
1..1
init_suite
# example_simple_test: initializing
# example_simple_test: example_simple_test passed
ok 1 example_simple_test
kunit example: all tests passed
ok 2 example