Commit ff7b437f authored by Brendan Higgins's avatar Brendan Higgins Committed by Shuah Khan

kunit: defconfig: add defconfigs for building KUnit tests

Add defconfig for UML and a fragment that can be used to configure other
architectures for building KUnit tests. Add option to kunit_tool to use
a defconfig to create the kunitconfig.
Signed-off-by: default avatarBrendan Higgins <brendanhiggins@google.com>
Reviewed-by: default avatarGreg Kroah-Hartman <gregkh@linuxfoundation.org>
Reviewed-by: default avatarLogan Gunthorpe <logang@deltatee.com>
Reviewed-by: default avatarStephen Boyd <sboyd@kernel.org>
Signed-off-by: default avatarShuah Khan <skhan@linuxfoundation.org>
parent 6ebf5866
CONFIG_KUNIT=y
CONFIG_KUNIT_TEST=y
CONFIG_KUNIT_EXAMPLE_TEST=y
CONFIG_KUNIT=y
CONFIG_KUNIT_TEST=y
CONFIG_KUNIT_EXAMPLE_TEST=y
...@@ -11,6 +11,7 @@ import argparse ...@@ -11,6 +11,7 @@ import argparse
import sys import sys
import os import os
import time import time
import shutil
from collections import namedtuple from collections import namedtuple
from enum import Enum, auto from enum import Enum, auto
...@@ -21,7 +22,7 @@ import kunit_parser ...@@ -21,7 +22,7 @@ import kunit_parser
KunitResult = namedtuple('KunitResult', ['status','result']) KunitResult = namedtuple('KunitResult', ['status','result'])
KunitRequest = namedtuple('KunitRequest', ['raw_output','timeout', 'jobs', 'build_dir']) KunitRequest = namedtuple('KunitRequest', ['raw_output','timeout', 'jobs', 'build_dir', 'defconfig'])
class KunitStatus(Enum): class KunitStatus(Enum):
SUCCESS = auto() SUCCESS = auto()
...@@ -29,8 +30,16 @@ class KunitStatus(Enum): ...@@ -29,8 +30,16 @@ class KunitStatus(Enum):
BUILD_FAILURE = auto() BUILD_FAILURE = auto()
TEST_FAILURE = auto() TEST_FAILURE = auto()
def create_default_kunitconfig():
if not os.path.exists(kunit_kernel.KUNITCONFIG_PATH):
shutil.copyfile('arch/um/configs/kunit_defconfig',
kunit_kernel.KUNITCONFIG_PATH)
def run_tests(linux: kunit_kernel.LinuxSourceTree, def run_tests(linux: kunit_kernel.LinuxSourceTree,
request: KunitRequest) -> KunitResult: request: KunitRequest) -> KunitResult:
if request.defconfig:
create_default_kunitconfig()
config_start = time.time() config_start = time.time()
success = linux.build_reconfig(request.build_dir) success = linux.build_reconfig(request.build_dir)
config_end = time.time() config_end = time.time()
...@@ -72,7 +81,7 @@ def run_tests(linux: kunit_kernel.LinuxSourceTree, ...@@ -72,7 +81,7 @@ def run_tests(linux: kunit_kernel.LinuxSourceTree,
else: else:
return KunitResult(KunitStatus.SUCCESS, test_result) return KunitResult(KunitStatus.SUCCESS, test_result)
def main(argv, linux): def main(argv, linux=None):
parser = argparse.ArgumentParser( parser = argparse.ArgumentParser(
description='Helps writing and running KUnit tests.') description='Helps writing and running KUnit tests.')
subparser = parser.add_subparsers(dest='subcommand') subparser = parser.add_subparsers(dest='subcommand')
...@@ -99,13 +108,24 @@ def main(argv, linux): ...@@ -99,13 +108,24 @@ def main(argv, linux):
'directory.', 'directory.',
type=str, default=None, metavar='build_dir') type=str, default=None, metavar='build_dir')
run_parser.add_argument('--defconfig',
help='Uses a default kunitconfig.',
action='store_true')
cli_args = parser.parse_args(argv) cli_args = parser.parse_args(argv)
if cli_args.subcommand == 'run': if cli_args.subcommand == 'run':
if cli_args.defconfig:
create_default_kunitconfig()
if not linux:
linux = kunit_kernel.LinuxSourceTree()
request = KunitRequest(cli_args.raw_output, request = KunitRequest(cli_args.raw_output,
cli_args.timeout, cli_args.timeout,
cli_args.jobs, cli_args.jobs,
cli_args.build_dir) cli_args.build_dir,
cli_args.defconfig)
result = run_tests(linux, request) result = run_tests(linux, request)
if result.status != KunitStatus.SUCCESS: if result.status != KunitStatus.SUCCESS:
sys.exit(1) sys.exit(1)
...@@ -113,4 +133,4 @@ def main(argv, linux): ...@@ -113,4 +133,4 @@ def main(argv, linux):
parser.print_help() parser.print_help()
if __name__ == '__main__': if __name__ == '__main__':
main(sys.argv[1:], kunit_kernel.LinuxSourceTree()) main(sys.argv[1:])
...@@ -14,6 +14,7 @@ import os ...@@ -14,6 +14,7 @@ import os
import kunit_config import kunit_config
KCONFIG_PATH = '.config' KCONFIG_PATH = '.config'
KUNITCONFIG_PATH = 'kunitconfig'
class ConfigError(Exception): class ConfigError(Exception):
"""Represents an error trying to configure the Linux kernel.""" """Represents an error trying to configure the Linux kernel."""
...@@ -81,7 +82,7 @@ class LinuxSourceTree(object): ...@@ -81,7 +82,7 @@ class LinuxSourceTree(object):
def __init__(self): def __init__(self):
self._kconfig = kunit_config.Kconfig() self._kconfig = kunit_config.Kconfig()
self._kconfig.read_from_file('kunitconfig') self._kconfig.read_from_file(KUNITCONFIG_PATH)
self._ops = LinuxSourceTreeOperations() self._ops = LinuxSourceTreeOperations()
def clean(self): def clean(self):
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment