Commit 312b3e50 authored by Jonathan Schwender's avatar Jonathan Schwender Committed by Stefan Lankes
Browse files

Runner: Exit qemu via debug device

Using the standard sys_exit when running on qemu, results in the return code being dropped and qemu always exiting with 0. This commit introduces exiting qemu via a debug device, which allows passing a return code.
parent 297eb8bd
......@@ -40,6 +40,9 @@ newlib = []
pci = []
acpi = []
[dev-dependencies]
x86_64 = "0.11.0"
[dependencies]
bitflags = "1.2"
#cfg-if = "0.1"
......
......@@ -2,6 +2,7 @@
#![no_main]
extern crate hermit;
extern crate x86_64;
use hermit::{print, println};
// Workaround since the "real" runtime_entry function (defined in libstd) is not available,
......@@ -11,12 +12,32 @@ extern "C"
fn runtime_entry(argc: i32, argv: *const *const u8, _env: *const *const u8) -> ! {
let res = main(argc as isize, argv);
match res {
Ok(_) => hermit::sys_exit(0),
Err(_) => hermit::sys_exit(1), //ToDo: sys_exit exitcode doesn't seem to get passed to qemu
Ok(_) => exit_qemu(QemuExitCode::Success),
Err(_) => exit_qemu(QemuExitCode::Failed),
// sys_exit argument doesn't actually get used, gets silently dropped!
// Maybe this is not possible on QEMU?
// https://os.phil-opp.com/testing/#exiting-qemu device needed?
}
println!("Failed to debug exit qemu");
hermit::sys_exit(0); //sys_exit exitcode on qemu gets silently dropped
}
#[derive(Debug, Clone, Copy, PartialEq, Eq)]
#[repr(u32)]
pub enum QemuExitCode {
Success = 0x10,
Failed = 0x11,
}
pub fn exit_qemu(exit_code: QemuExitCode) {
use x86_64::instructions::port::Port;
unsafe {
let mut port = Port::new(0xf4);
port.write(exit_code as u32);
}
}
......
......@@ -36,7 +36,7 @@ def run_test(process_args):
def validate_test(returncode, output, test_exe_path):
print("returncode ", returncode)
# ToDo handle expected failures
if returncode != 0:
if returncode != 33:
return False
# ToDo parse output for panic
return True
......@@ -70,7 +70,8 @@ qemu_base_arguments = ['qemu-system-x86_64',
'-serial', 'stdio',
'-kernel', BOOTLOADER_PATH,
# skip initrd - it depends on test executable
'-cpu', 'qemu64,apic,fsgsbase,rdtscp,xsave,fxsr'
'-cpu', 'qemu64,apic,fsgsbase,rdtscp,xsave,fxsr',
'-device', 'isa-debug-exit,iobase=0xf4,iosize=0x04'
]
ok_tests: int = 0
failed_tests: int = 0
......
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment