From b1e16a59a1283429498cc32c2c0b166208c05620 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Ciro=20Santilli=20=E5=85=AD=E5=9B=9B=E4=BA=8B=E4=BB=B6=20?= =?UTF-8?q?=E6=B3=95=E8=BD=AE=E5=8A=9F?= Date: Thu, 8 Nov 2018 22:00:03 +0000 Subject: [PATCH] baremetal: exit at the end of main instead of infinite loop run: interpret lkmc_test_fail as the last line of test as an error --- baremetal/arch/aarch64/floating_point.S | 25 +++++++++++++++++++++++++ baremetal/arch/aarch64/return.S | 4 ++++ baremetal/interactive/hello.c | 6 ++++++ baremetal/lib/aarch64.S | 3 ++- baremetal/lib/arm.S | 3 ++- baremetal/return.c | 3 +++ common.py | 5 +++++ run | 13 +++++++++++-- 8 files changed, 58 insertions(+), 4 deletions(-) create mode 100644 baremetal/arch/aarch64/floating_point.S create mode 100644 baremetal/arch/aarch64/return.S create mode 100644 baremetal/interactive/hello.c create mode 100644 baremetal/return.c diff --git a/baremetal/arch/aarch64/floating_point.S b/baremetal/arch/aarch64/floating_point.S new file mode 100644 index 0000000..e5ebebe --- /dev/null +++ b/baremetal/arch/aarch64/floating_point.S @@ -0,0 +1,25 @@ +/* https://github.com/cirosantilli/arm-assembly-cheat/blob/c19e187e98e99f2f4a042783ca238aa4eb2292ab/v8/floating_point.S */ + +.global main +main: + /* 1.5 + 2.5 == 4.0 */ + fmov d0, #1.5 + fmov d1, #2.5 + fadd d2, d0, d1 + fmov d3, #4.0 + fcmp d2, d3 + beq 1f + bl assert_fail +1: + + /* Now in 32-bit. */ + fmov s0, #1.5 + fmov s1, #2.5 + fadd s2, s0, s1 + fmov s3, #4.0 + fcmp s2, s3 + beq 1f + bl assert_fail +1: + + ret diff --git a/baremetal/arch/aarch64/return.S b/baremetal/arch/aarch64/return.S new file mode 100644 index 0000000..b16d907 --- /dev/null +++ b/baremetal/arch/aarch64/return.S @@ -0,0 +1,4 @@ +/* Return to ensure that the post main works. */ +.global main +main: + ret diff --git a/baremetal/interactive/hello.c b/baremetal/interactive/hello.c new file mode 100644 index 0000000..5cbeffb --- /dev/null +++ b/baremetal/interactive/hello.c @@ -0,0 +1,6 @@ +#include + +void main(void) { + puts("hello"); + return; +} diff --git a/baremetal/lib/aarch64.S b/baremetal/lib/aarch64.S index e61e812..861a783 100644 --- a/baremetal/lib/aarch64.S +++ b/baremetal/lib/aarch64.S @@ -8,4 +8,5 @@ mystart: ldr x0, =stack_top mov sp, x0 bl main - b . + mov x0, #0 + bl exit diff --git a/baremetal/lib/arm.S b/baremetal/lib/arm.S index c105839..ca08e8e 100644 --- a/baremetal/lib/arm.S +++ b/baremetal/lib/arm.S @@ -2,4 +2,5 @@ mystart: ldr sp, =stack_top bl main - b . + mov r0, #0 + bl exit diff --git a/baremetal/return.c b/baremetal/return.c new file mode 100644 index 0000000..9f56ddf --- /dev/null +++ b/baremetal/return.c @@ -0,0 +1,3 @@ +void main(void) { + return; +} diff --git a/common.py b/common.py index b221d47..768d89c 100644 --- a/common.py +++ b/common.py @@ -72,6 +72,7 @@ kernel_module_ext = '.ko' obj_ext = '.o' config_file = os.path.join(data_dir, 'config') command_prefix = '+ ' +magic_fail_string = b'lkmc_test_fail' if os.path.exists(config_file): config = imp.load_source('config', config_file) configs = {x:getattr(config, x) for x in dir(config) if not x.startswith('__')} @@ -774,6 +775,7 @@ def setup(parser): this_module.m5out_dir = os.path.join(this_module.gem5_run_dir, 'm5out') this_module.stats_file = os.path.join(this_module.m5out_dir, 'stats.txt') this_module.trace_txt_file = os.path.join(this_module.m5out_dir, 'trace.txt') + this_module.gem5_guest_terminal_file = os.path.join(this_module.m5out_dir, 'system.terminal') this_module.gem5_readfile = os.path.join(this_module.gem5_run_dir, 'readfile') this_module.gem5_termout_file = os.path.join(this_module.gem5_run_dir, 'termout.txt') this_module.qemu_run_dir = os.path.join(this_module.run_dir_base, 'qemu', args.arch, str(args.run_id)) @@ -782,6 +784,7 @@ def setup(parser): this_module.qemu_trace_txt_file = os.path.join(this_module.qemu_run_dir, 'trace.txt') this_module.qemu_termout_file = os.path.join(this_module.qemu_run_dir, 'termout.txt') this_module.qemu_rrfile = os.path.join(this_module.qemu_run_dir, 'rrfile') + this_module.qemu_guest_terminal_file = os.path.join(this_module.m5out_dir, qemu_termout_file) this_module.gem5_out_dir = os.path.join(this_module.out_dir, 'gem5') if args.gem5_build_dir is None: this_module.gem5_build_dir = os.path.join(this_module.gem5_out_dir, args.gem5_build_id, args.gem5_build_type) @@ -817,10 +820,12 @@ def setup(parser): this_module.executable = this_module.gem5_executable this_module.run_dir = this_module.gem5_run_dir this_module.termout_file = this_module.gem5_termout_file + this_module.guest_terminal_file = gem5_guest_terminal_file else: this_module.executable = this_module.qemu_executable this_module.run_dir = this_module.qemu_run_dir this_module.termout_file = this_module.qemu_termout_file + this_module.guest_terminal_file = qemu_guest_terminal_file this_module.gem5_config_dir = os.path.join(this_module.gem5_src_dir, 'configs') this_module.gem5_se_file = os.path.join(this_module.gem5_config_dir, 'example', 'se.py') this_module.gem5_fs_file = os.path.join(this_module.gem5_config_dir, 'example', 'fs.py') diff --git a/run b/run index e01ea26..eee22c3 100755 --- a/run +++ b/run @@ -392,11 +392,20 @@ def main(args, extra_args=None): else: panic_msg = b'Kernel panic - not syncing' panic_re = re.compile(panic_msg) + error_string_found = False 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') - return 1 + error_string_found = True + with open(common.guest_terminal_file, 'br') as logfile: + lines = logfile.readlines() + if lines: + last_line = lines[-1] + if last_line.rstrip() == common.magic_fail_string: + error_string_found = True + if error_string_found: + common.log_error('simulation error detected by parsing logs') + return 1 return 0 def get_argparse():