userland: native testing

This commit is contained in:
Ciro Santilli 六四事件 法轮功
2019-05-05 00:00:00 +00:00
parent 5daad53289
commit 8509f17a84
37 changed files with 142 additions and 45 deletions

View File

@@ -984,16 +984,20 @@ cd userland
Source: link:userland/c/hello.c[].
Build an entire directory:
Build an entire directory and test it:
....
cd userland
./build c
./test c
....
Build the current directory:
Build the current directory and test it:
....
cd userland/c
./build
./test
....
Note however that if you run this from link:userland/[] toplevel, it would try to build the link:userland/libs/[] folder, which depends on certain libraries being installed on the host, e.g. <<blas>>.
@@ -1005,21 +1009,10 @@ cd linux-kernel-module-cheat
./build --download-dependencies userland-host
....
The `build` scripts inside link:userland/[] are just symlinks to link:build-userland-in-tree[] which you can also use from toplevel as:
Pass custom compiler options:
....
./build-userland-in-tree
./build-userland-in-tree c
./build-userland-in-tree c/hello.c
./build-userland-in-tree userland/c/hello.c
....
which is in turn just a thin wrapper around link:build-userland[], so you can use any option supported by that script freely.
Pass custom compiler options with:
....
./build-userland --ccflags='-foptimize-sibling-calls -foptimize-strlen' --force-rebuild
./build --ccflags='-foptimize-sibling-calls -foptimize-strlen' --force-rebuild
....
Here we used `--force-rebuild` to force rebuild since the sources weren't modified since the last build.
@@ -1027,19 +1020,48 @@ Here we used `--force-rebuild` to force rebuild since the sources weren't modifi
Some CLI options have more specialized flags, e.g. `-O` optimization level:
....
./build-userland --optimization-level 3 --force-rebuild
./build --optimization-level 3 --force-rebuild
....
See also <<user-mode-static-executables>> for `--static`.
Do a more clean out-of-tree build and run the program instead:
The `build` scripts inside link:userland/[] are just symlinks to link:build-userland-in-tree[] which you can also use from toplevel as:
....
./build-userland-in-tree
./build-userland-in-tree userland/c
./build-userland-in-tree userland/c/hello.c
....
`build-userland-in-tre` is in turn just a thin wrapper around link:build-userland[]:
....
./build-userland --gcc-which host --in-tree userland/c
....
So you can use any option supported by `build-userland` script freely with `build-userland-in-tree` and `build`.
The situation is analogous for link:userland/test[], link:test-user-mode-in-tree[] and link:test-user-mode[].
Do a more clean out-of-tree build instead and run the program:
....
./build-userland --gcc-which host --userland-build-id host
"$(./getvar --userland-build-id host userland_build_dir)/hello.out"
./run --emulator native --userland userland/c/hello.c --userland-build-id host
....
Here we put the host executables in a separate <<build-variants,build-variant>> to avoid conflict with Buildroot builds.
Here we:
* put the host executables in a separate <<build-variants,build-variant>> to avoid conflict with Buildroot builds.
* ran with the `--emulator native` option to run the program natively
In this case you can debub the program with:
....
./run --debug-vm --emulator native --userland userland/c/hello.c --userland-build-id host
....
as shown at: <<debug-the-emulator>>, although direct GDB host usage works as well of course.
===== Userland setup getting started full system

View File

@@ -116,10 +116,18 @@ consts['userland_out_exts'] = [
consts['config_file'] = os.path.join(consts['data_dir'], 'config.py')
consts['magic_fail_string'] = b'lkmc_test_fail'
consts['baremetal_lib_basename'] = 'lib'
consts['emulator_userland_only_short_to_long_dict'] = collections.OrderedDict([
('n', 'native'),
])
consts['all_userland_only_emulators'] = set()
for key in consts['emulator_userland_only_short_to_long_dict']:
consts['all_userland_only_emulators'].add(key)
consts['all_userland_only_emulators'].add(consts['emulator_userland_only_short_to_long_dict'][key])
consts['emulator_short_to_long_dict'] = collections.OrderedDict([
('q', 'qemu'),
('g', 'gem5'),
])
consts['emulator_short_to_long_dict'].update(consts['emulator_userland_only_short_to_long_dict'])
consts['all_long_emulators'] = [consts['emulator_short_to_long_dict'][k] for k in consts['emulator_short_to_long_dict']]
consts['emulator_choices'] = set()
for key in consts['emulator_short_to_long_dict']:
@@ -495,7 +503,7 @@ and then inspect separate outputs later in different output directories.
self.add_argument(
'--all-emulators', default=False,
help='''\
Run action for all supported --emulators emulators. Ignore --emulators.
Run action for all supported emulators. Ignore --emulator.
'''.format(emulators_string)
)
self.add_argument(
@@ -508,6 +516,11 @@ Run action for all supported --emulators emulators. Ignore --emulators.
help='''\
Emulator to use. If given multiple times, semantics are similar to --arch.
Valid emulators: {}
"native" means running natively on host. It is only supported for userland,
and you must have built the program for native running, see:
https://github.com/cirosantilli/linux-kernel-module-cheat#userland-setup-getting-started-natively
Incompatible archs are skipped.
'''.format(emulators_string)
)
self._is_common = False
@@ -1044,6 +1057,11 @@ lunch aosp_{}-eng
for arch in real_archs:
if arch in env['arch_short_to_long_dict']:
arch = env['arch_short_to_long_dict'][arch]
if emulator == 'native':
if env['userland'] is None:
raise Exception('Emulator only supported in user mode: {}'.format(emulator))
if arch != env['host_arch']:
continue
if self.is_arch_supported(arch):
if not env['dry_run']:
start_time = time.time()
@@ -1150,22 +1168,7 @@ lunch aosp_{}-eng
Convert a convenient shorthand user input string to paths of existing files
in the source tree.
Input path file extensions are ignored.
All the following input paths would be equivalent for
magic_in_dir == '/full/path/to/userland'
- hello
- hello.
- hello.c
- hello.out
- userland/hello
- userland/hello.
- userland/hello.c
- userland/hello.out
- /full/path/to/userland/hello
- /full/path/to/userland/hello.
- /full/path/to/userland/hello.c
Ensure that the path lies inside source_tree_root.
Multiple matches may happen if multiple multiple exts files exist.
E.g., after an in-tree build, in_path='hello' and exts=['.c', '.out']
@@ -1183,7 +1186,7 @@ lunch aosp_{}-eng
- /full/path/to/userland/arch
Note however that this potentially prevents differentiation between
files and directories: e.g. if you had both a file arch.c and a directory arch,
files and directories: e.g. if you had both a file arch.c and a directory arch/,
and exts=['', '.c'], then both would get matched.
'''
in_path = os.path.abspath(in_path)

11
run
View File

@@ -39,8 +39,13 @@ Ctrl +C kills the QEMU simulator instead of being passed to the guest.
'''
)
self.add_argument(
'-D', '--debug-vm', default=False,
help='Run GDB on the emulator itself.'
'-D',
'--debug-vm',
default=False,
help='''\
Run GDB on the emulator itself.
For --emulator native, this debugs the target program.
'''
)
self.add_argument(
'--debug-vm-args', default='',
@@ -669,7 +674,7 @@ Extra options to append at the end of the emulator command line.
])
cmd.extend(extra_emulator_args)
cmd.extend(self.env['extra_emulator_args'])
if self.env['emulator'] == 'qemu' and self.env['userland']:
if self.env['userland'] and self.env['emulator'] in ('qemu', 'native'):
# The program and arguments must come at the every end of the CLI.
cmd.extend([self.resolve_userland_executable(self.env['userland']), LF])
if self.env['userland_args'] is not None:

View File

@@ -8,13 +8,17 @@ import example_properties
from thread_pool import ThreadPool
class Main(common.TestCliFunction):
def __init__(self):
super().__init__(
description='''\
def __init__(self, *args, **kwargs):
if not 'description' in kwargs:
kwargs['description'] = '''\
https://github.com/cirosantilli/linux-kernel-module-cheat#user-mode-tests
TODO: expose all userland relevant ./run args here as well somehow.
''',
)
'''
if not 'defaults' in kwargs:
kwargs['defaults'] = {}
if not 'userland' in kwargs['defaults']:
kwargs['defaults']['userland'] = ''
super().__init__(*args, **kwargs)
self.add_argument(
'tests',
nargs='*',

31
test-user-mode-in-tree Executable file
View File

@@ -0,0 +1,31 @@
#!/usr/bin/env python3
import imp
import os
import subprocess
git_root = subprocess.check_output([
'git',
'rev-parse',
'--show-toplevel',
]).decode().rstrip()
test_user_mode = imp.load_source(
'test_user_mode',
os.path.join(git_root, 'test-user-mode')
)
class Main(test_user_mode.Main):
def __init__(self):
super().__init__(
description='''\
https://github.com/cirosantilli/linux-kernel-module-cheat#userland-setup-getting-started-natively
''',
defaults={
'emulators': ['native'],
'in_tree': True,
'tests': ['.'],
}
)
if __name__ == '__main__':
Main().cli()

View File

@@ -0,0 +1 @@
../test

View File

@@ -0,0 +1 @@
../test

View File

@@ -0,0 +1 @@
../test

View File

@@ -0,0 +1 @@
../test

View File

@@ -0,0 +1 @@
../test

View File

@@ -0,0 +1 @@
../test

1
userland/arch/aarch64/test Symbolic link
View File

@@ -0,0 +1 @@
../test

View File

@@ -0,0 +1 @@
../test

View File

@@ -0,0 +1 @@
../test

1
userland/arch/arm/c/test Symbolic link
View File

@@ -0,0 +1 @@
../test

View File

@@ -0,0 +1 @@
../test

View File

@@ -0,0 +1 @@
../test

View File

@@ -0,0 +1 @@
../test

1
userland/arch/arm/test Symbolic link
View File

@@ -0,0 +1 @@
../test

1
userland/arch/test Symbolic link
View File

@@ -0,0 +1 @@
../test

View File

@@ -0,0 +1 @@
../test

View File

@@ -0,0 +1 @@
../test

1
userland/arch/x86_64/c/test Symbolic link
View File

@@ -0,0 +1 @@
../test

View File

@@ -0,0 +1 @@
../test

View File

@@ -0,0 +1 @@
../test

1
userland/arch/x86_64/test Symbolic link
View File

@@ -0,0 +1 @@
../test

1
userland/c/test Symbolic link
View File

@@ -0,0 +1 @@
../test

1
userland/cpp/test Symbolic link
View File

@@ -0,0 +1 @@
../test

1
userland/gcc/test Symbolic link
View File

@@ -0,0 +1 @@
../test

View File

@@ -0,0 +1 @@
../test

1
userland/libs/eigen/test Symbolic link
View File

@@ -0,0 +1 @@
../test

1
userland/libs/libdrm/test Symbolic link
View File

@@ -0,0 +1 @@
../test

1
userland/libs/openblas/test Symbolic link
View File

@@ -0,0 +1 @@
../test

1
userland/libs/test Symbolic link
View File

@@ -0,0 +1 @@
../test

1
userland/linux/test Symbolic link
View File

@@ -0,0 +1 @@
../test

1
userland/posix/test Symbolic link
View File

@@ -0,0 +1 @@
../test

1
userland/test Symbolic link
View File

@@ -0,0 +1 @@
../test-user-mode-in-tree