Skip to content

Commit

Permalink
kunit: Introduce get_file_path() helper
Browse files Browse the repository at this point in the history
Helper allows to derive file names depending on --build_dir argument.

Signed-off-by: Andy Shevchenko <andriy.shevchenko@linux.intel.com>
Reviewed-by: Brendan Higgins <brendanhiggins@google.com>
Tested-by: Brendan Higgins <brendanhiggins@google.com>
Signed-off-by: Shuah Khan <skhan@linuxfoundation.org>
  • Loading branch information
Andy Shevchenko authored and Shuah Khan committed Nov 30, 2020
1 parent b650545 commit f3ed003
Showing 1 changed file with 9 additions and 15 deletions.
24 changes: 9 additions & 15 deletions tools/testing/kunit/kunit_kernel.py
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,11 @@
BROKEN_ALLCONFIG_PATH = 'tools/testing/kunit/configs/broken_on_uml.config'
OUTFILE_PATH = 'test.log'

def get_file_path(build_dir, default):
if build_dir:
default = os.path.join(build_dir, default)
return default

class ConfigError(Exception):
"""Represents an error trying to configure the Linux kernel."""

Expand Down Expand Up @@ -97,9 +102,7 @@ def make(self, jobs, build_dir, make_options):

def linux_bin(self, params, timeout, build_dir):
"""Runs the Linux UML binary. Must be named 'linux'."""
linux_bin = './linux'
if build_dir:
linux_bin = os.path.join(build_dir, 'linux')
linux_bin = get_file_path(build_dir, 'linux')
outfile = get_outfile_path(build_dir)
with open(outfile, 'w') as output:
process = subprocess.Popen([linux_bin] + params,
Expand All @@ -108,22 +111,13 @@ def linux_bin(self, params, timeout, build_dir):
process.wait(timeout)

def get_kconfig_path(build_dir):
kconfig_path = KCONFIG_PATH
if build_dir:
kconfig_path = os.path.join(build_dir, KCONFIG_PATH)
return kconfig_path
return get_file_path(build_dir, KCONFIG_PATH)

def get_kunitconfig_path(build_dir):
kunitconfig_path = KUNITCONFIG_PATH
if build_dir:
kunitconfig_path = os.path.join(build_dir, KUNITCONFIG_PATH)
return kunitconfig_path
return get_file_path(build_dir, KUNITCONFIG_PATH)

def get_outfile_path(build_dir):
outfile_path = OUTFILE_PATH
if build_dir:
outfile_path = os.path.join(build_dir, OUTFILE_PATH)
return outfile_path
return get_file_path(build_dir, OUTFILE_PATH)

class LinuxSourceTree(object):
"""Represents a Linux kernel source tree with KUnit tests."""
Expand Down

0 comments on commit f3ed003

Please sign in to comment.