mirror of
https://github.com/cirosantilli/linux-kernel-module-cheat.git
synced 2026-01-25 11:11:35 +01:00
userland: move more userland/arch/ logic into property tree
This commit is contained in:
@@ -211,28 +211,10 @@ Default: build all examples that have their package dependencies met, e.g.:
|
||||
cc_flags_dir = cc_flags.copy()
|
||||
if dirpath_relative_root_components_len > 0:
|
||||
if dirpath_relative_root_components[0] == 'arch':
|
||||
if dirpath_relative_root_components_len > 1:
|
||||
if dirpath_relative_root_components[1] == self.env['arch']:
|
||||
cc_flags_dir.extend([
|
||||
'-I', os.path.join(self.env['userland_source_arch_arch_dir']), LF,
|
||||
'-I', os.path.join(self.env['userland_source_arch_dir']), LF,
|
||||
])
|
||||
if 'freestanding' in dirpath_relative_root_components:
|
||||
common_objs_dir = []
|
||||
cc_flags_dir.extend([
|
||||
'-ffreestanding', LF,
|
||||
'-nostdlib', LF,
|
||||
'-static', LF,
|
||||
])
|
||||
else:
|
||||
if 'c' in dirpath_relative_root_components:
|
||||
common_objs_dir = []
|
||||
else:
|
||||
common_objs_dir = [common_obj_asm]
|
||||
else:
|
||||
continue
|
||||
else:
|
||||
continue
|
||||
cc_flags_dir.extend([
|
||||
'-I', os.path.join(self.env['userland_source_arch_arch_dir']), LF,
|
||||
'-I', os.path.join(self.env['userland_source_arch_dir']), LF,
|
||||
])
|
||||
elif dirpath_relative_root_components[0] == 'libs':
|
||||
if dirpath_relative_root_components_len > 1:
|
||||
pkg_key = dirpath_relative_root_components[1]
|
||||
@@ -268,22 +250,25 @@ Default: build all examples that have their package dependencies met, e.g.:
|
||||
dirpath_relative_root,
|
||||
in_filename
|
||||
))
|
||||
if my_path_properties['pedantic']:
|
||||
cc_flags_file.extend(['-pedantic', LF])
|
||||
common_objs_file = common_objs_dir.copy()
|
||||
if my_path_properties['lkmc_common_obj']:
|
||||
common_objs_file.append(common_obj)
|
||||
error = thread_pool.submit({
|
||||
'c_std': my_path_properties['c_std'],
|
||||
'cc_flags': cc_flags_file + my_path_properties['cc_flags'],
|
||||
'cc_flags_after': cc_flags_after,
|
||||
'cxx_std': my_path_properties['cxx_std'],
|
||||
'extra_objs': common_objs_file,
|
||||
'in_path': in_path,
|
||||
'out_path': self.resolve_userland_executable(in_path),
|
||||
})
|
||||
if error is not None:
|
||||
raise common.ExitLoop()
|
||||
if my_path_properties.should_be_built(self.env['arch']):
|
||||
if my_path_properties['pedantic']:
|
||||
cc_flags_file.extend(['-pedantic', LF])
|
||||
common_objs_file = common_objs_dir.copy()
|
||||
if my_path_properties['extra_objs_lkmc_common']:
|
||||
common_objs_file.append(common_obj)
|
||||
if my_path_properties['extra_objs_userland_asm']:
|
||||
common_objs_file.append(common_obj_asm)
|
||||
error = thread_pool.submit({
|
||||
'c_std': my_path_properties['c_std'],
|
||||
'cc_flags': cc_flags_file + my_path_properties['cc_flags'],
|
||||
'cc_flags_after': cc_flags_after,
|
||||
'cxx_std': my_path_properties['cxx_std'],
|
||||
'extra_objs': common_objs_file,
|
||||
'in_path': in_path,
|
||||
'out_path': self.resolve_userland_executable(in_path),
|
||||
})
|
||||
if error is not None:
|
||||
raise common.ExitLoop()
|
||||
except common.ExitLoop:
|
||||
pass
|
||||
error = thread_pool.get_error()
|
||||
|
||||
16
common.py
16
common.py
@@ -1203,17 +1203,15 @@ lunch aosp_{}-eng
|
||||
|
||||
If the input path is a file, add the executable extension automatically.
|
||||
'''
|
||||
in_path_abs = os.path.abspath(in_path)
|
||||
magic_in_dir_abs = os.path.abspath(magic_in_dir)
|
||||
magic_out_dir_abs = os.path.abspath(magic_out_dir)
|
||||
if self.is_subpath(in_path_abs, magic_in_dir_abs):
|
||||
if self.is_subpath(in_path, magic_in_dir):
|
||||
# Abspath needed to remove the trailing `/.` which makes e.g. rmrf fail.
|
||||
out = os.path.abspath(os.path.join(
|
||||
magic_out_dir_abs,
|
||||
magic_out_dir,
|
||||
os.path.relpath(
|
||||
os.path.splitext(in_path_abs)[0],
|
||||
os.path.abspath(magic_in_dir_abs)
|
||||
)),
|
||||
)
|
||||
os.path.splitext(in_path)[0],
|
||||
magic_in_dir
|
||||
)
|
||||
))
|
||||
if os.path.isfile(in_path):
|
||||
out += executable_ext
|
||||
return out
|
||||
|
||||
@@ -23,7 +23,8 @@ class PathProperties:
|
||||
'exit_status',
|
||||
'interactive',
|
||||
# We should get rid of this if we ever properly implement dependency graphs.
|
||||
'lkmc_common_obj',
|
||||
'extra_objs_lkmc_common',
|
||||
'extra_objs_userland_asm',
|
||||
# We were lazy to properly classify why we are skipping these tests.
|
||||
# TODO get it done.
|
||||
'skip_run_unclassified',
|
||||
@@ -55,19 +56,23 @@ class PathProperties:
|
||||
other_tmp_properties['cc_flags'] = self.properties['cc_flags'] + other_tmp_properties['cc_flags']
|
||||
return self.properties.update(other_tmp_properties)
|
||||
|
||||
def should_be_tested(self, arch):
|
||||
def should_be_built(self, arch):
|
||||
return \
|
||||
not self['interactive'] and \
|
||||
not self['more_than_1s'] and \
|
||||
not self['no_executable'] and \
|
||||
not self['receives_signal'] and \
|
||||
not self['requires_kernel_modules'] and \
|
||||
not self['skip_run_unclassified'] and \
|
||||
(
|
||||
self['allowed_archs'] is None or
|
||||
arch in self['allowed_archs']
|
||||
)
|
||||
|
||||
def should_be_tested(self, arch):
|
||||
return \
|
||||
self.should_be_built(arch) and \
|
||||
not self['interactive'] and \
|
||||
not self['more_than_1s'] and \
|
||||
not self['receives_signal'] and \
|
||||
not self['requires_kernel_modules'] and \
|
||||
not self['skip_run_unclassified']
|
||||
|
||||
class PrefixTree:
|
||||
def __init__(self, path_properties_dict=None, children=None):
|
||||
if path_properties_dict is None:
|
||||
@@ -108,11 +113,19 @@ def get(test_path):
|
||||
|
||||
default_c_std = 'c11'
|
||||
default_cxx_std = 'c++17'
|
||||
gnu_extensions = {
|
||||
gnu_extension_properties = {
|
||||
'c_std': 'gnu11',
|
||||
'cc_pedantic': False,
|
||||
'cxx_std': 'gnu++17'
|
||||
}
|
||||
freestanding_properties = {
|
||||
'cc_flags': [
|
||||
'-ffreestanding', LF,
|
||||
'-nostdlib', LF,
|
||||
'-static', LF,
|
||||
],
|
||||
'extra_objs_userland_asm': False,
|
||||
}
|
||||
path_properties_tuples = (
|
||||
{
|
||||
'c_std': default_c_std,
|
||||
@@ -124,8 +137,9 @@ path_properties_tuples = (
|
||||
'cc_pedantic': True,
|
||||
'cxx_std': None,
|
||||
'exit_status': 0,
|
||||
'extra_objs_lkmc_common': False,
|
||||
'extra_objs_userland_asm': False,
|
||||
'interactive': False,
|
||||
'lkmc_common_obj': False,
|
||||
'skip_run_unclassified': False,
|
||||
'more_than_1s': False,
|
||||
'no_executable': False,
|
||||
@@ -142,7 +156,8 @@ path_properties_tuples = (
|
||||
'cc_flags': [
|
||||
'-fno-pie', LF,
|
||||
'-no-pie', LF,
|
||||
]
|
||||
],
|
||||
'extra_objs_userland_asm': True,
|
||||
},
|
||||
{
|
||||
'arm': (
|
||||
@@ -165,9 +180,33 @@ path_properties_tuples = (
|
||||
# So we just write divided inline assembly for now.
|
||||
'-masm-syntax-unified', LF,
|
||||
]
|
||||
},
|
||||
{
|
||||
'c': (
|
||||
{
|
||||
'extra_objs_userland_asm': False,
|
||||
},
|
||||
{
|
||||
'freestanding': freestanding_properties,
|
||||
},
|
||||
),
|
||||
'freestanding': freestanding_properties,
|
||||
}
|
||||
),
|
||||
'aarch64': (
|
||||
{'allowed_archs': {'aarch64'}},
|
||||
{
|
||||
'c': (
|
||||
{
|
||||
'extra_objs_userland_asm': False,
|
||||
},
|
||||
{
|
||||
'freestanding': freestanding_properties,
|
||||
},
|
||||
),
|
||||
'freestanding': freestanding_properties,
|
||||
}
|
||||
),
|
||||
'aarch64': {'allowed_archs': {'aarch64'}},
|
||||
'empty.S': {'no_executable': True},
|
||||
'fail.S': {'no_executable': True},
|
||||
'main.c': {'no_executable': True},
|
||||
@@ -175,11 +214,15 @@ path_properties_tuples = (
|
||||
{'allowed_archs': {'x86_64'}},
|
||||
{
|
||||
'c': (
|
||||
{},
|
||||
{
|
||||
'extra_objs_userland_asm': False,
|
||||
},
|
||||
{
|
||||
'freestanding': freestanding_properties,
|
||||
'ring0.c': {'receives_signal': True}
|
||||
}
|
||||
),
|
||||
'freestanding': freestanding_properties,
|
||||
}
|
||||
),
|
||||
}
|
||||
@@ -192,16 +235,16 @@ path_properties_tuples = (
|
||||
'infinite_loop.c': {'more_than_1s': True},
|
||||
}
|
||||
),
|
||||
'gcc': gnu_extensions,
|
||||
'kernel_modules': {**gnu_extensions, **{'requires_kernel_modules': True}},
|
||||
'gcc': gnu_extension_properties,
|
||||
'kernel_modules': {**gnu_extension_properties, **{'requires_kernel_modules': True}},
|
||||
'lkmc': (
|
||||
{'lkmc_common_obj': True},
|
||||
{'extra_objs_lkmc_common': True},
|
||||
{
|
||||
'assert_fail.c': {'exit_status': 1}
|
||||
}
|
||||
),
|
||||
'libs': {'skip_run_unclassified': True},
|
||||
'linux': {**gnu_extensions, **{'skip_run_unclassified': True}},
|
||||
'linux': {**gnu_extension_properties, **{'skip_run_unclassified': True}},
|
||||
'posix': (
|
||||
{},
|
||||
{
|
||||
|
||||
6
run
6
run
@@ -549,7 +549,11 @@ Extra options to append at the end of the emulator command line.
|
||||
debug_args = []
|
||||
cmd.extend(
|
||||
[
|
||||
os.path.join(self.env['qemu_build_dir'], '{}-linux-user'.format(self.env['arch']), 'qemu-{}'.format(self.env['arch'])), LF,
|
||||
os.path.join(
|
||||
self.env['qemu_build_dir'],
|
||||
'{}-linux-user'.format(self.env['arch']),
|
||||
'qemu-{}'.format(self.env['arch'])
|
||||
), LF,
|
||||
'-L', self.env['userland_library_dir'], LF,
|
||||
'-r', self.env['kernel_version'], LF,
|
||||
'-seed', '0', LF,
|
||||
|
||||
@@ -180,6 +180,14 @@ class ShellHelpers:
|
||||
f.write(cmd_string)
|
||||
self.chmod(cmd_file)
|
||||
|
||||
def rmrf(self, path):
|
||||
self.print_cmd(['rm', '-r', '-f', path, LF])
|
||||
if not self.dry_run and os.path.exists(path):
|
||||
if os.path.isdir(path):
|
||||
shutil.rmtree(path)
|
||||
else:
|
||||
os.unlink(path)
|
||||
|
||||
def run_cmd(
|
||||
self,
|
||||
cmd,
|
||||
@@ -309,14 +317,6 @@ class ShellHelpers:
|
||||
else:
|
||||
return [x for x in cmd if x != LF]
|
||||
|
||||
def rmrf(self, path):
|
||||
self.print_cmd(['rm', '-r', '-f', path, LF])
|
||||
if not self.dry_run and os.path.exists(path):
|
||||
if os.path.isdir(path):
|
||||
shutil.rmtree(path)
|
||||
else:
|
||||
os.unlink(path)
|
||||
|
||||
def walk(self, root):
|
||||
'''
|
||||
Extended walk that can take files or directories.
|
||||
|
||||
Reference in New Issue
Block a user