Skip to content

Commit

Permalink
kunit: tool: Enable virtio/PCI by default on UML
Browse files Browse the repository at this point in the history
There are several tests which depend on PCI, and hence need a bunch of
extra options to run under UML. This makes it awkward to give
configuration instructions (whether in documentation, or as part of a
.kunitconfig file), as two separate, incompatible sets of config options
are required for UML and "most other architectures".

For non-UML architectures, it's possible to add default kconfig options
via the qemu_config python files, but there's no equivalent for UML. Add
a new tools/testing/kunit/configs/arch_uml.config file containing extra
kconfig options to use on UML.

Tested-by: José Expósito <jose.exposito89@gmail.com>
Reviewed-by: Daniel Latypov <dlatypov@google.com>
Signed-off-by: David Gow <davidgow@google.com>
Reviewed-by: Brendan Higgins <brendanhiggins@google.com>
Signed-off-by: Daniel Latypov <dlatypov@google.com>
Signed-off-by: Shuah Khan <skhan@linuxfoundation.org>
  • Loading branch information
David Gow authored and Shuah Khan committed Jul 8, 2022
1 parent 53b4662 commit 6fc3a86
Show file tree
Hide file tree
Showing 3 changed files with 27 additions and 4 deletions.
5 changes: 5 additions & 0 deletions tools/testing/kunit/configs/arch_uml.config
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
# Config options which are added to UML builds by default

# Enable virtio/pci, as a lot of tests require it.
CONFIG_VIRTIO_UML=y
CONFIG_UML_PCI_OVER_VIRTIO=y
14 changes: 10 additions & 4 deletions tools/testing/kunit/kunit_kernel.py
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@
OLD_KUNITCONFIG_PATH = 'last_used_kunitconfig'
DEFAULT_KUNITCONFIG_PATH = 'tools/testing/kunit/configs/default.config'
BROKEN_ALLCONFIG_PATH = 'tools/testing/kunit/configs/broken_on_uml.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')
Expand Down Expand Up @@ -53,7 +54,7 @@ def make_mrproper(self) -> None:
except subprocess.CalledProcessError as e:
raise ConfigError(e.output.decode())

def make_arch_qemuconfig(self, base_kunitconfig: kunit_config.Kconfig) -> kunit_config.Kconfig:
def make_arch_config(self, base_kunitconfig: kunit_config.Kconfig) -> kunit_config.Kconfig:
return base_kunitconfig

def make_allyesconfig(self, build_dir: str, make_options) -> None:
Expand Down Expand Up @@ -109,7 +110,7 @@ def __init__(self, qemu_arch_params: qemu_config.QemuArchParams, cross_compile:
self._kernel_command_line = qemu_arch_params.kernel_command_line + ' kunit_shutdown=reboot'
self._extra_qemu_params = qemu_arch_params.extra_qemu_params

def make_arch_qemuconfig(self, base_kunitconfig: kunit_config.Kconfig) -> kunit_config.Kconfig:
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
Expand Down Expand Up @@ -138,6 +139,11 @@ class LinuxSourceTreeOperationsUml(LinuxSourceTreeOperations):
def __init__(self, cross_compile=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 make_allyesconfig(self, build_dir: str, make_options) -> None:
stdout.print_with_timestamp(
'Enabling all CONFIGs for UML...')
Expand Down Expand Up @@ -298,7 +304,7 @@ def build_config(self, build_dir: str, make_options) -> bool:
if build_dir and not os.path.exists(build_dir):
os.mkdir(build_dir)
try:
self._kconfig = self._ops.make_arch_qemuconfig(self._kconfig)
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:
Expand Down Expand Up @@ -329,7 +335,7 @@ def build_reconfig(self, build_dir: str, make_options) -> bool:
return self.build_config(build_dir, make_options)

existing_kconfig = kunit_config.parse_file(kconfig_path)
self._kconfig = self._ops.make_arch_qemuconfig(self._kconfig)
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
Expand Down
12 changes: 12 additions & 0 deletions tools/testing/kunit/kunit_tool_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -430,6 +430,10 @@ def test_build_reconfig_no_config(self):
f.write('CONFIG_KUNIT=y')

tree = kunit_kernel.LinuxSourceTree(build_dir)
# Stub out the source tree operations, so we don't have
# the defaults for any given architecture get in the
# way.
tree._ops = kunit_kernel.LinuxSourceTreeOperations('none', None)
mock_build_config = mock.patch.object(tree, 'build_config').start()

# Should generate the .config
Expand All @@ -447,6 +451,10 @@ def test_build_reconfig_existing_config(self):
f.write('CONFIG_KUNIT=y\nCONFIG_KUNIT_TEST=y')

tree = kunit_kernel.LinuxSourceTree(build_dir)
# Stub out the source tree operations, so we don't have
# the defaults for any given architecture get in the
# way.
tree._ops = kunit_kernel.LinuxSourceTreeOperations('none', None)
mock_build_config = mock.patch.object(tree, 'build_config').start()

self.assertTrue(tree.build_reconfig(build_dir, make_options=[]))
Expand All @@ -463,6 +471,10 @@ def test_build_reconfig_remove_option(self):
f.write('CONFIG_KUNIT=y\nCONFIG_KUNIT_TEST=y')

tree = kunit_kernel.LinuxSourceTree(build_dir)
# Stub out the source tree operations, so we don't have
# the defaults for any given architecture get in the
# way.
tree._ops = kunit_kernel.LinuxSourceTreeOperations('none', None)
mock_build_config = mock.patch.object(tree, 'build_config').start()

# ... so we should trigger a call to build_config()
Expand Down

0 comments on commit 6fc3a86

Please sign in to comment.