mirror of
https://github.com/cirosantilli/linux-kernel-module-cheat.git
synced 2026-01-23 02:05:57 +01:00
Split test kernel modules to a separate script.
Notice that Python sucks and does SIGPIPE annoyances, for now work around by grepping the output file... Fix the exit status read check with 'b', it broke down occasionally with: UnicodeDecodeError: 'utf-8' codec can't decode byte 0xff in position 1832: invalid start byte
This commit is contained in:
11
README.adoc
11
README.adoc
@@ -10184,7 +10184,7 @@ Testing that should be done for every functional patch.
|
||||
|
||||
===== Guest testing
|
||||
|
||||
Build for all stable archs and run basic fast tests:
|
||||
Run all tests:
|
||||
|
||||
....
|
||||
./build-all
|
||||
@@ -10199,6 +10199,15 @@ Sources:
|
||||
* link:build-all[]
|
||||
* link:test[]
|
||||
|
||||
Test just the kernel modules:
|
||||
|
||||
....
|
||||
./test-kernel-modules
|
||||
echo $?
|
||||
....
|
||||
|
||||
Source: link:test-kernel-module[]
|
||||
|
||||
Test that the Internet works:
|
||||
|
||||
....
|
||||
|
||||
12
common.py
12
common.py
@@ -310,10 +310,19 @@ def run_cmd(
|
||||
del env[key]
|
||||
if show_cmd:
|
||||
print_cmd(cmd, cmd_file, extra_env=extra_env)
|
||||
|
||||
# Otherwise Ctrl + C gives:
|
||||
# - ugly Python stack trace for gem5 (QEMU takes over terminal and is fine).
|
||||
# - kills Python, and that then kills GDB: https://stackoverflow.com/questions/19807134/does-python-always-raise-an-exception-if-you-do-ctrlc-when-a-subprocess-is-exec
|
||||
sigint_old = signal.getsignal(signal.SIGINT)
|
||||
signal.signal(signal.SIGINT, signal.SIG_IGN)
|
||||
|
||||
# Otherwise BrokenPipeError when piping through | grep
|
||||
# But if I do this, my terminal gets broken at the end. Why, why, why.
|
||||
# https://stackoverflow.com/questions/14207708/ioerror-errno-32-broken-pipe-python
|
||||
# Ignoring the exception is not enough as it prints a warning anyways.
|
||||
#sigpipe_old = signal.getsignal(signal.SIGPIPE)
|
||||
#signal.signal(signal.SIGPIPE, signal.SIG_DFL)
|
||||
# https://stackoverflow.com/questions/15535240/python-popen-write-to-stdout-and-log-file-simultaneously/52090802#52090802
|
||||
with subprocess.Popen(cmd, stdout=stdout, stderr=stderr, env=env, **kwargs) as proc:
|
||||
if out_file is not None:
|
||||
@@ -327,7 +336,8 @@ def run_cmd(
|
||||
logfile.write(byte)
|
||||
else:
|
||||
break
|
||||
signal.signal(signal.SIGINT, signal.SIG_DFL)
|
||||
signal.signal(signal.SIGINT, sigint_old)
|
||||
#signal.signal(signal.SIGPIPE, sigpipe_old)
|
||||
return proc.returncode
|
||||
|
||||
def setup(parser, **extra_args):
|
||||
|
||||
10
run
10
run
@@ -105,9 +105,7 @@ def main(args, extra_args=None):
|
||||
raise_rootfs_not_found()
|
||||
common.raw_to_qcow2(prebuilt=args.prebuilt, reverse=True)
|
||||
if not os.path.exists(common.vmlinux):
|
||||
# This would allow us to run the prebuilt QEMU Linux image.
|
||||
# but TODO cannot convert Image to vmlinux on aarch64:
|
||||
# run-detectors: unable to find an interpreter for
|
||||
# This is to run gem5 from a prebuilt download.
|
||||
if not os.path.exists(common.linux_image):
|
||||
raise Exception('Linux kernel image not found. Did you compile it?\n' \
|
||||
'Tried: ' + common.vmlinux)
|
||||
@@ -305,11 +303,11 @@ def main(args, extra_args=None):
|
||||
if args.gem5:
|
||||
# We have to do some parsing here because gem5 exits with status 0 even when panic happens.
|
||||
# Grepping for '^panic: ' does not work because some errors don't show that message.
|
||||
panic_msg = '--- BEGIN LIBC BACKTRACE ---$'
|
||||
panic_msg = b'--- BEGIN LIBC BACKTRACE ---$'
|
||||
else:
|
||||
panic_msg = 'Kernel panic - not syncing'
|
||||
panic_msg = b'Kernel panic - not syncing'
|
||||
panic_re = re.compile(panic_msg)
|
||||
with open(common.termout_file, 'r') as logfile:
|
||||
with open(common.termout_file, 'br') as logfile:
|
||||
for line in logfile:
|
||||
if panic_re.search(line):
|
||||
common.log_error('simulation error detected by parsing logs')
|
||||
|
||||
2
test
2
test
@@ -1,4 +1,4 @@
|
||||
#!/usr/bin/env bash
|
||||
set -eu
|
||||
./bench-boot -t "${1:-1}"
|
||||
./run -F '/test_all.sh;/poweroff.out' | grep -q lkmc_test_pass
|
||||
./test-kernel-modules
|
||||
|
||||
7
test-kernel-modules
Executable file
7
test-kernel-modules
Executable file
@@ -0,0 +1,7 @@
|
||||
#!/usr/bin/env bash
|
||||
set -eu
|
||||
root_dir="$(cd "$(dirname "${BASH_SOURCE[0]}")" >/dev/null && pwd)"
|
||||
getvar="${root_dir}/getvar"
|
||||
termout_file="$("$getvar" termout_file)"
|
||||
./run --eval-busybox '/test_all.sh;/poweroff.out' --kvm
|
||||
grep -q lkmc_test_pass "$termout_file"
|
||||
Reference in New Issue
Block a user