Skip to content
This repository has been archived by the owner on Jul 23, 2024. It is now read-only.

Commit

Permalink
feat: intermediate process to get exit code and shutdown
Browse files Browse the repository at this point in the history
  • Loading branch information
llenotre committed Jun 9, 2024
1 parent 8a6b89d commit c05c00e
Show file tree
Hide file tree
Showing 3 changed files with 27 additions and 1 deletion.
8 changes: 8 additions & 0 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -3,5 +3,13 @@ name = "maestro-test"
version = "0.1.0"
edition = "2021"

[[bin]]
name = "maestro-test"
path = "src/main.rs"

[[bin]]
name = "init"
path = "src/boot.rs"

[dependencies]
libc = "0.2.153"
4 changes: 3 additions & 1 deletion build.sh
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,8 @@ mkfs.ext2 disk

# Fill filesystem
debugfs -wf - disk <<EOF
mkdir /dev
mkdir /sbin
write target/$TARGET/release/maestro-test /sbin/init
write target/$TARGET/release/init /sbin/init
write target/$TARGET/release/maestro-test /sbin/maestro-test
EOF
16 changes: 16 additions & 0 deletions src/boot.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
//! Boot stub for integration tests.
//!
//! This file exists to run the tests as a second process in order to retrieve the exit code, then shutdown the machine.
use std::process::Command;

pub fn main() {
let status = Command::new("/sbin/maestro-test").status().unwrap();
let cmd = if status.success() { -1 } else { -2 };
// Shutdown
unsafe {
libc::syscall(libc::SYS_reboot, 0xde145e83u32, 0x40367d6eu32, cmd, 0);
}
// Loop in case shutdown failed for some reason
loop {}
}

0 comments on commit c05c00e

Please sign in to comment.