kunit: add --make_options
The kunit.py utility builds an ARCH=um kernel and then runs it. Add optional --make_options flag to kunit.py allowing for the operator to specify extra build options. This allows use of the clang compiler for kunit: tools/testing/kunit/kunit.py run --defconfig \ --make_options CC=clang --make_options HOSTCC=clang Signed-off-by: Greg Thelen <gthelen@google.com> Reviewed-by: Brendan Higgins <brendanhiggins@google.com> Reviewed-by: Nathan Chancellor <natechancellor@gmail.com> Tested-by: David Gow <davidgow@google.com> Signed-off-by: Brendan Higgins <brendanhiggins@google.com> Signed-off-by: Shuah Khan <skhan@linuxfoundation.org>
This commit is contained in:
Родитель
021ed9f551
Коммит
0476e69f39
|
@ -24,7 +24,7 @@ KunitResult = namedtuple('KunitResult', ['status','result'])
|
||||||
|
|
||||||
KunitRequest = namedtuple('KunitRequest', ['raw_output','timeout', 'jobs',
|
KunitRequest = namedtuple('KunitRequest', ['raw_output','timeout', 'jobs',
|
||||||
'build_dir', 'defconfig',
|
'build_dir', 'defconfig',
|
||||||
'alltests'])
|
'alltests', 'make_options'])
|
||||||
|
|
||||||
KernelDirectoryPath = sys.argv[0].split('tools/testing/kunit/')[0]
|
KernelDirectoryPath = sys.argv[0].split('tools/testing/kunit/')[0]
|
||||||
|
|
||||||
|
@ -49,7 +49,7 @@ def get_kernel_root_path():
|
||||||
def run_tests(linux: kunit_kernel.LinuxSourceTree,
|
def run_tests(linux: kunit_kernel.LinuxSourceTree,
|
||||||
request: KunitRequest) -> KunitResult:
|
request: KunitRequest) -> KunitResult:
|
||||||
config_start = time.time()
|
config_start = time.time()
|
||||||
success = linux.build_reconfig(request.build_dir)
|
success = linux.build_reconfig(request.build_dir, request.make_options)
|
||||||
config_end = time.time()
|
config_end = time.time()
|
||||||
if not success:
|
if not success:
|
||||||
return KunitResult(KunitStatus.CONFIG_FAILURE, 'could not configure kernel')
|
return KunitResult(KunitStatus.CONFIG_FAILURE, 'could not configure kernel')
|
||||||
|
@ -59,7 +59,8 @@ def run_tests(linux: kunit_kernel.LinuxSourceTree,
|
||||||
build_start = time.time()
|
build_start = time.time()
|
||||||
success = linux.build_um_kernel(request.alltests,
|
success = linux.build_um_kernel(request.alltests,
|
||||||
request.jobs,
|
request.jobs,
|
||||||
request.build_dir)
|
request.build_dir,
|
||||||
|
request.make_options)
|
||||||
build_end = time.time()
|
build_end = time.time()
|
||||||
if not success:
|
if not success:
|
||||||
return KunitResult(KunitStatus.BUILD_FAILURE, 'could not build kernel')
|
return KunitResult(KunitStatus.BUILD_FAILURE, 'could not build kernel')
|
||||||
|
@ -125,6 +126,10 @@ def main(argv, linux=None):
|
||||||
help='Run all KUnit tests through allyesconfig',
|
help='Run all KUnit tests through allyesconfig',
|
||||||
action='store_true')
|
action='store_true')
|
||||||
|
|
||||||
|
run_parser.add_argument('--make_options',
|
||||||
|
help='X=Y make option, can be repeated.',
|
||||||
|
action='append')
|
||||||
|
|
||||||
cli_args = parser.parse_args(argv)
|
cli_args = parser.parse_args(argv)
|
||||||
|
|
||||||
if cli_args.subcommand == 'run':
|
if cli_args.subcommand == 'run':
|
||||||
|
@ -149,7 +154,8 @@ def main(argv, linux=None):
|
||||||
cli_args.jobs,
|
cli_args.jobs,
|
||||||
cli_args.build_dir,
|
cli_args.build_dir,
|
||||||
cli_args.defconfig,
|
cli_args.defconfig,
|
||||||
cli_args.alltests)
|
cli_args.alltests,
|
||||||
|
cli_args.make_options)
|
||||||
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)
|
||||||
|
|
|
@ -40,8 +40,10 @@ class LinuxSourceTreeOperations(object):
|
||||||
except subprocess.CalledProcessError as e:
|
except subprocess.CalledProcessError as e:
|
||||||
raise ConfigError(e.output)
|
raise ConfigError(e.output)
|
||||||
|
|
||||||
def make_olddefconfig(self, build_dir):
|
def make_olddefconfig(self, build_dir, make_options):
|
||||||
command = ['make', 'ARCH=um', 'olddefconfig']
|
command = ['make', 'ARCH=um', 'olddefconfig']
|
||||||
|
if make_options:
|
||||||
|
command.extend(make_options)
|
||||||
if build_dir:
|
if build_dir:
|
||||||
command += ['O=' + build_dir]
|
command += ['O=' + build_dir]
|
||||||
try:
|
try:
|
||||||
|
@ -68,8 +70,10 @@ class LinuxSourceTreeOperations(object):
|
||||||
kunit_parser.print_with_timestamp(
|
kunit_parser.print_with_timestamp(
|
||||||
'Starting Kernel with all configs takes a few minutes...')
|
'Starting Kernel with all configs takes a few minutes...')
|
||||||
|
|
||||||
def make(self, jobs, build_dir):
|
def make(self, jobs, build_dir, make_options):
|
||||||
command = ['make', 'ARCH=um', '--jobs=' + str(jobs)]
|
command = ['make', 'ARCH=um', '--jobs=' + str(jobs)]
|
||||||
|
if make_options:
|
||||||
|
command.extend(make_options)
|
||||||
if build_dir:
|
if build_dir:
|
||||||
command += ['O=' + build_dir]
|
command += ['O=' + build_dir]
|
||||||
try:
|
try:
|
||||||
|
@ -128,19 +132,19 @@ class LinuxSourceTree(object):
|
||||||
return False
|
return False
|
||||||
return True
|
return True
|
||||||
|
|
||||||
def build_config(self, build_dir):
|
def build_config(self, build_dir, make_options):
|
||||||
kconfig_path = get_kconfig_path(build_dir)
|
kconfig_path = get_kconfig_path(build_dir)
|
||||||
if build_dir and not os.path.exists(build_dir):
|
if build_dir and not os.path.exists(build_dir):
|
||||||
os.mkdir(build_dir)
|
os.mkdir(build_dir)
|
||||||
self._kconfig.write_to_file(kconfig_path)
|
self._kconfig.write_to_file(kconfig_path)
|
||||||
try:
|
try:
|
||||||
self._ops.make_olddefconfig(build_dir)
|
self._ops.make_olddefconfig(build_dir, make_options)
|
||||||
except ConfigError as e:
|
except ConfigError as e:
|
||||||
logging.error(e)
|
logging.error(e)
|
||||||
return False
|
return False
|
||||||
return self.validate_config(build_dir)
|
return self.validate_config(build_dir)
|
||||||
|
|
||||||
def build_reconfig(self, build_dir):
|
def build_reconfig(self, build_dir, make_options):
|
||||||
"""Creates a new .config if it is not a subset of the .kunitconfig."""
|
"""Creates a new .config if it is not a subset of the .kunitconfig."""
|
||||||
kconfig_path = get_kconfig_path(build_dir)
|
kconfig_path = get_kconfig_path(build_dir)
|
||||||
if os.path.exists(kconfig_path):
|
if os.path.exists(kconfig_path):
|
||||||
|
@ -149,19 +153,19 @@ class LinuxSourceTree(object):
|
||||||
if not self._kconfig.is_subset_of(existing_kconfig):
|
if not self._kconfig.is_subset_of(existing_kconfig):
|
||||||
print('Regenerating .config ...')
|
print('Regenerating .config ...')
|
||||||
os.remove(kconfig_path)
|
os.remove(kconfig_path)
|
||||||
return self.build_config(build_dir)
|
return self.build_config(build_dir, make_options)
|
||||||
else:
|
else:
|
||||||
return True
|
return True
|
||||||
else:
|
else:
|
||||||
print('Generating .config ...')
|
print('Generating .config ...')
|
||||||
return self.build_config(build_dir)
|
return self.build_config(build_dir, make_options)
|
||||||
|
|
||||||
def build_um_kernel(self, alltests, jobs, build_dir):
|
def build_um_kernel(self, alltests, jobs, build_dir, make_options):
|
||||||
if alltests:
|
if alltests:
|
||||||
self._ops.make_allyesconfig()
|
self._ops.make_allyesconfig()
|
||||||
try:
|
try:
|
||||||
self._ops.make_olddefconfig(build_dir)
|
self._ops.make_olddefconfig(build_dir, make_options)
|
||||||
self._ops.make(jobs, build_dir)
|
self._ops.make(jobs, build_dir, make_options)
|
||||||
except (ConfigError, BuildError) as e:
|
except (ConfigError, BuildError) as e:
|
||||||
logging.error(e)
|
logging.error(e)
|
||||||
return False
|
return False
|
||||||
|
|
Загрузка…
Ссылка в новой задаче