Skip to content

Commit

Permalink
Merge pull request #14 from YushiOMOTE/add-tests
Browse files Browse the repository at this point in the history
Add CI to run integration test
  • Loading branch information
YushiOMOTE authored Jul 13, 2024
2 parents 4886eef + 6a65efb commit b1a0501
Show file tree
Hide file tree
Showing 6 changed files with 132 additions and 2 deletions.
30 changes: 28 additions & 2 deletions .github/workflows/main.yml
Original file line number Diff line number Diff line change
@@ -1,8 +1,9 @@
name: Main

on:
- push
- pull_request
push:
branches: [master]
pull_request:

jobs:
test:
Expand All @@ -19,6 +20,31 @@ jobs:
rustup default ${{ matrix.rust }}
- run: cargo test --verbose

integration-test:
runs-on: ubuntu-latest
defaults:
run:
working-directory: testing
timeout-minutes: 15
steps:
- name: Checkout
uses: actions/checkout@v3
- name: Install Qemu
run: |
sudo apt update
sudo apt install qemu-system
- name: Install Rust
run: |
rustup update nightly --no-self-update
rustup default nightly
rustup target add x86_64-unknown-none
rustup component add rust-src
rustup component add llvm-tools-preview
- name: Install bootimage
run: |
cargo install bootimage
- run: cargo test --verbose

fmt:
runs-on: ubuntu-latest
steps:
Expand Down
6 changes: 6 additions & 0 deletions testing/.cargo/config.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
[build]
target = "x86_64-unknown-none"
rustflags = ["-Crelocation-model=static"]

[target.'cfg(target_os = "none")']
runner = "bootimage runner"
28 changes: 28 additions & 0 deletions testing/Cargo.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
[package]
name = "testing"
version = "0.1.0"
authors = ["Philipp Oppermann <[email protected]>"]
edition = "2018"

[[test]]
name = "basic"
harness = false

[dependencies]
bootloader = "0.9.10"
uart_16550 = "0.2.8"
spin = "0.5.0"
x86_64 = "0.15.1"
com_logger = { path = ".." }
log = "0.4.22"

[dependencies.lazy_static]
version = "1.3.0"
features = ["spin_no_std"]

[package.metadata.bootimage]
test-args = [
"-device", "isa-debug-exit,iobase=0xf4,iosize=0x04", "-serial", "stdio",
"-display", "none"
]
test-success-exit-code = 33
File renamed without changes.
54 changes: 54 additions & 0 deletions testing/src/lib.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,54 @@
#![feature(custom_test_frameworks)]
#![test_runner(crate::test_runner)]
#![reexport_test_harness_main = "test_main"]
#![no_std]
#![no_main]

use core::panic::PanicInfo;
use log::error;

#[derive(Debug, Clone, Copy, PartialEq, Eq)]
#[repr(u32)]
pub enum QemuExitCode {
Success = 0x10,
Failed = 0x11,
}

pub fn exit() {
exit_qemu(QemuExitCode::Success)
}

pub fn exit_qemu(exit_code: QemuExitCode) {
use x86_64::instructions::port::PortWriteOnly;

unsafe {
let mut port = PortWriteOnly::new(0xf4);
port.write(exit_code as u32);
}
}

pub fn test_runner(tests: &[&dyn Fn()]) {
for test in tests {
test();
}
exit_qemu(QemuExitCode::Success);
}

pub fn test_panic_handler(info: &PanicInfo) -> ! {
error!("{:#?}", info);
exit_qemu(QemuExitCode::Failed);
loop {}
}

#[cfg(test)]
#[no_mangle]
pub extern "C" fn _start() -> ! {
test_main();
loop {}
}

#[cfg(test)]
#[panic_handler]
fn panic(info: &PanicInfo) -> ! {
test_panic_handler(info)
}
16 changes: 16 additions & 0 deletions testing/tests/basic.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
#![no_std]
#![no_main]

use core::panic::PanicInfo;

#[no_mangle] // don't mangle the name of this function
pub extern "C" fn _start() {
com_logger::init();
log::info!("Hello world");
testing::exit();
}

#[panic_handler]
fn panic(info: &PanicInfo) -> ! {
testing::test_panic_handler(info)
}

0 comments on commit b1a0501

Please sign in to comment.