Skip to content

Commit

Permalink
Add test harness and test ring
Browse files Browse the repository at this point in the history
Signed-off-by: Nick Spinale <[email protected]>
  • Loading branch information
nspin committed Jan 6, 2024
1 parent 0740758 commit 88b3103
Show file tree
Hide file tree
Showing 24 changed files with 923 additions and 14 deletions.
38 changes: 38 additions & 0 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

4 changes: 4 additions & 0 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -51,9 +51,11 @@ members = [
"crates/private/tests/root-task/c",
"crates/private/tests/root-task/config",
"crates/private/tests/root-task/core-libs",
"crates/private/tests/root-task/default-test-harness",
"crates/private/tests/root-task/loader",
"crates/private/tests/root-task/mbedtls",
"crates/private/tests/root-task/panicking",
"crates/private/tests/root-task/ring-test-harness",
"crates/private/tests/root-task/tls",
"crates/sel4",
"crates/sel4-async/block-io",
Expand Down Expand Up @@ -109,6 +111,7 @@ members = [
"crates/sel4-platform-info/types",
"crates/sel4-render-elf-with-data",
"crates/sel4-root-task",
"crates/sel4-root-task/default-test-harness",
"crates/sel4-root-task/macros",
"crates/sel4-runtime-common",
"crates/sel4-rustfmt-helper",
Expand All @@ -118,6 +121,7 @@ members = [
"crates/sel4-shared-ring-buffer/bookkeeping",
"crates/sel4-shared-ring-buffer/smoltcp",
"crates/sel4-sync",
"crates/sel4-test-harness",
"crates/sel4/bitfield-ops",
"crates/sel4/bitfield-parser",
"crates/sel4/bitfield-parser/test",
Expand Down
19 changes: 19 additions & 0 deletions crates/private/tests/root-task/default-test-harness/Cargo.nix
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
#
# Copyright 2023, Colias Group, LLC
#
# SPDX-License-Identifier: BSD-2-Clause
#

{ mk, localCrates, versions }:

mk {
package.name = "tests-root-task-default-test-harness";
dependencies = {
inherit (versions) log;
};
dev-dependencies = {
test = let package = "sel4-root-task-default-test-harness"; in localCrates.${package} // {
inherit package;
};
};
}
24 changes: 24 additions & 0 deletions crates/private/tests/root-task/default-test-harness/Cargo.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
#
# Copyright 2023, Colias Group, LLC
#
# SPDX-License-Identifier: BSD-2-Clause
#
#
# This file is generated from './Cargo.nix'. You can edit this file directly
# if you are not using this project's Cargo manifest management tools.
# See 'hacking/cargo-manifest-management/README.md' for more information.
#

[package]
name = "tests-root-task-default-test-harness"
version = "0.1.0"
authors = ["Nick Spinale <[email protected]>"]
edition = "2021"
license = "BSD-2-Clause"

[dependencies]
log = "0.4.17"

[dev-dependencies.test]
path = "../../../../sel4-root-task/default-test-harness"
package = "sel4-root-task-default-test-harness"
36 changes: 36 additions & 0 deletions crates/private/tests/root-task/default-test-harness/src/lib.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
//
// Copyright 2023, Colias Group, LLC
//
// SPDX-License-Identifier: BSD-2-Clause
//

#![no_std]

#[cfg(test)]
mod test {
#[test]
fn foo() {}

#[test]
#[should_panic]
fn bar() {
assert!(false);
}
}

mod m {
#[cfg(test)]
mod test {
#[test]
fn foo() {}

#[ignore = "a reason"]
#[test]
fn bar() {
assert!(false);
}
}
}

// cargo rustc $h --target aarch64-sel4 -p tests-root-task-default-test-harness --profile=check -- --test -Zunpretty=expanded
// cargo rustc $h --target riscv64imac-sel4 -p tests-root-task-default-test-harness --profile=check -- --test -Zunpretty=expanded
34 changes: 34 additions & 0 deletions crates/private/tests/root-task/ring-test-harness/Cargo.nix
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
#
# Copyright 2023, Colias Group, LLC
#
# SPDX-License-Identifier: BSD-2-Clause
#

{ mk, localCrates, versions }:

mk rec {
package.name = "tests-root-task-ring-test-harness";
dependencies = {
inherit (localCrates)
sel4
sel4-root-task
sel4-test-harness
;
sel4-newlib = localCrates.sel4-newlib // {
features = [
"nosys"
"all-symbols"
"sel4-panicking-env"
];
};
getrandom = {
version = "0.2.10";
features = [ "custom" ];
};
rand = {
version = "0.8.5";
default-features = false;
features = [ "small_rng" ];
};
};
}
28 changes: 28 additions & 0 deletions crates/private/tests/root-task/ring-test-harness/Cargo.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
#
# Copyright 2023, Colias Group, LLC
#
# SPDX-License-Identifier: BSD-2-Clause
#
#
# This file is generated from './Cargo.nix'. You can edit this file directly
# if you are not using this project's Cargo manifest management tools.
# See 'hacking/cargo-manifest-management/README.md' for more information.
#

[package]
name = "tests-root-task-ring-test-harness"
version = "0.1.0"
authors = ["Nick Spinale <[email protected]>"]
edition = "2021"
license = "BSD-2-Clause"

[dependencies]
getrandom = { version = "0.2.10", features = ["custom"] }
rand = { version = "0.8.5", default-features = false, features = ["small_rng"] }
sel4 = { path = "../../../../sel4" }
sel4-root-task = { path = "../../../../sel4-root-task" }
sel4-test-harness = { path = "../../../../sel4-test-harness" }

[dependencies.sel4-newlib]
path = "../../../../sel4-newlib"
features = ["nosys", "all-symbols", "sel4-panicking-env"]
58 changes: 58 additions & 0 deletions crates/private/tests/root-task/ring-test-harness/src/lib.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,58 @@
//
// Copyright 2023, Colias Group, LLC
//
// SPDX-License-Identifier: BSD-2-Clause
//

#![no_std]
#![no_main]
#![feature(cfg_target_thread_local)]
#![feature(thread_local)]

use core::cell::RefCell;

use rand::rngs::SmallRng;
use rand::{RngCore, SeedableRng};

use sel4_newlib as _;
use sel4_root_task::root_task;
use sel4_test_harness::run_test_main;

pub use sel4_test_harness::for_generated_code::*;

const HEAP_SIZE: usize = 256 * 1024 * 1024;

#[root_task(heap_size = HEAP_SIZE)]
fn main(_bootinfo: &sel4::BootInfo) -> ! {
seed_insecure_dummy_rng(0);
run_test_main();
sel4::BootInfo::init_thread_tcb().tcb_suspend().unwrap();
unreachable!()
}

#[cfg(not(target_thread_local))]
compile_error!("");

#[thread_local]
static RNG: RefCell<Option<SmallRng>> = RefCell::new(None);

pub fn seed_insecure_dummy_rng(seed: u64) {
assert!(RNG.replace(Some(SmallRng::seed_from_u64(seed))).is_none());
}

pub fn insecure_dummy_rng(buf: &mut [u8]) -> Result<(), getrandom::Error> {
if 1_u32.swap_bytes() == 0 {
panic!()
}
RNG.borrow_mut().as_mut().unwrap().fill_bytes(buf);
Ok(())
}

getrandom::register_custom_getrandom!(insecure_dummy_rng);

// https://github.com/rust-lang/compiler-builtins/pull/563
#[cfg(any(target_arch = "riscv32", target_arch = "riscv64"))]
#[no_mangle]
pub extern "C" fn __bswapsi2(u: u32) -> u32 {
u.swap_bytes()
}
18 changes: 18 additions & 0 deletions crates/sel4-root-task/default-test-harness/Cargo.nix
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
#
# Copyright 2023, Colias Group, LLC
#
# SPDX-License-Identifier: BSD-2-Clause
#

{ mk, localCrates, versions }:

mk rec {
package.name = "sel4-root-task-default-test-harness";
dependencies = {
inherit (localCrates)
sel4
sel4-root-task
sel4-test-harness
;
};
}
22 changes: 22 additions & 0 deletions crates/sel4-root-task/default-test-harness/Cargo.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
#
# Copyright 2023, Colias Group, LLC
#
# SPDX-License-Identifier: BSD-2-Clause
#
#
# This file is generated from './Cargo.nix'. You can edit this file directly
# if you are not using this project's Cargo manifest management tools.
# See 'hacking/cargo-manifest-management/README.md' for more information.
#

[package]
name = "sel4-root-task-default-test-harness"
version = "0.1.0"
authors = ["Nick Spinale <[email protected]>"]
edition = "2021"
license = "BSD-2-Clause"

[dependencies]
sel4 = { path = "../../sel4" }
sel4-root-task = { path = ".." }
sel4-test-harness = { path = "../../sel4-test-harness" }
22 changes: 22 additions & 0 deletions crates/sel4-root-task/default-test-harness/src/lib.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
//
// Copyright 2023, Colias Group, LLC
//
// SPDX-License-Identifier: BSD-2-Clause
//

#![no_std]
#![no_main]

use sel4_root_task::root_task;
use sel4_test_harness::run_test_main;

pub use sel4_test_harness::for_generated_code::*;

const HEAP_SIZE: usize = 64 * 1024 * 1024;

#[root_task(heap_size = HEAP_SIZE)]
fn main(_bootinfo: &sel4::BootInfo) -> ! {
run_test_main();
sel4::BootInfo::init_thread_tcb().tcb_suspend().unwrap();
unreachable!()
}
22 changes: 22 additions & 0 deletions crates/sel4-test-harness/Cargo.nix
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
#
# Copyright 2023, Colias Group, LLC
#
# SPDX-License-Identifier: BSD-2-Clause
#

{ mk, localCrates, mkDefaultFrontmatterWithReuseArgs, defaultReuseFrontmatterArgs }:

mk rec {
nix.frontmatter = mkDefaultFrontmatterWithReuseArgs (defaultReuseFrontmatterArgs // {
licenseID = package.license;
});
package.name = "sel4-test-harness";
package.license = "MIT OR Apache-2.0";
dependencies = {
inherit (localCrates)
sel4-panicking-env
sel4-panicking
sel4-immediate-sync-once-cell
;
};
}
Loading

0 comments on commit 88b3103

Please sign in to comment.