From c1c02ffefdf41d2ad4fdd2fc9bdfedcd85bc85f2 Mon Sep 17 00:00:00 2001 From: koniifer Date: Sat, 23 Nov 2024 16:51:39 +0000 Subject: [PATCH 1/4] silly string --- Cargo.lock | 50 ++++----- sysdata/libraries/stn/src/math.hb | 10 ++ sysdata/libraries/stn/src/string.hb | 153 ++++++++++++++++++++++++++++ 3 files changed, 188 insertions(+), 25 deletions(-) diff --git a/Cargo.lock b/Cargo.lock index 2f07974b..8dc4baa1 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -213,12 +213,12 @@ dependencies = [ [[package]] name = "hbbytecode" version = "0.1.0" -source = "git+https://git.ablecorp.us/AbleOS/holey-bytes.git#37dd13cab295aa9e74d704b3345685b4428d149a" +source = "git+https://git.ablecorp.us/AbleOS/holey-bytes.git#86ca959ea3eae1cb32298e135a444820583d24a0" [[package]] name = "hblang" version = "0.1.0" -source = "git+https://git.ablecorp.us/AbleOS/holey-bytes.git#37dd13cab295aa9e74d704b3345685b4428d149a" +source = "git+https://git.ablecorp.us/AbleOS/holey-bytes.git#86ca959ea3eae1cb32298e135a444820583d24a0" dependencies = [ "hashbrown", "hbbytecode", @@ -229,7 +229,7 @@ dependencies = [ [[package]] name = "hbvm" version = "0.1.0" -source = "git+https://git.ablecorp.us/AbleOS/holey-bytes.git#37dd13cab295aa9e74d704b3345685b4428d149a" +source = "git+https://git.ablecorp.us/AbleOS/holey-bytes.git#86ca959ea3eae1cb32298e135a444820583d24a0" dependencies = [ "hbbytecode", ] @@ -424,9 +424,9 @@ checksum = "02034f8f6b3e7bf050f310fbaf6db0018b8e54b75598d0a4c97172054752fede" [[package]] name = "litemap" -version = "0.7.3" +version = "0.7.4" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "643cb0b8d4fcc284004d5fd0d67ccf61dfffadb7f75e1e71bc420f4688a3a704" +checksum = "4ee93343901ab17bd981295f2cf0026d4ad018c7c31ba84549a4ddbb47a45104" [[package]] name = "lock_api" @@ -503,9 +503,9 @@ checksum = "e3148f5046208a5d56bcfc03053e3ca6334e51da8dfb19b6cdc8b306fae3283e" [[package]] name = "proc-macro2" -version = "1.0.89" +version = "1.0.92" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "f139b0662de085916d1fb67d2b4169d1addddda1919e696f3252b740b629986e" +checksum = "37d3544b3f2748c54e147655edb5025752e2303145b5aefb3c3ea2c78b973bb0" dependencies = [ "unicode-ident", ] @@ -584,9 +584,9 @@ dependencies = [ [[package]] name = "rustls" -version = "0.23.17" +version = "0.23.18" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "7f1a745511c54ba6d4465e8d5dfbd81b45791756de28d4981af70d6dca128f1e" +checksum = "9c9cc1d47e243d655ace55ed38201c19ae02c148ae56412ab8750e8f0166ab7f" dependencies = [ "log", "once_cell", @@ -717,9 +717,9 @@ checksum = "13c2bddecc57b384dee18652358fb23172facb8a2c51ccc10d74c157bdea3292" [[package]] name = "syn" -version = "2.0.87" +version = "2.0.89" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "25aa4ce346d03a6dcd68dd8b4010bcb74e54e62c90c573f394c46eae99aba32d" +checksum = "44d46482f1c1c87acd84dea20c1bf5ebff4c757009ed6bf19cfd36fb10e92c4e" dependencies = [ "proc-macro2", "quote", @@ -800,9 +800,9 @@ dependencies = [ [[package]] name = "unicode-ident" -version = "1.0.13" +version = "1.0.14" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "e91b56cd4cadaeb79bbf1a5645f6b4f8dc5bde8834ad5894a8db35fda9efa1fe" +checksum = "adb9e6ca4f869e1180728b7950e35922a7fc6397f7b641499e8f3ef06e50dc83" [[package]] name = "unicode-xid" @@ -833,9 +833,9 @@ dependencies = [ [[package]] name = "url" -version = "2.5.3" +version = "2.5.4" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "8d157f1b96d14500ffdc1f10ba712e780825526c03d9a49b4d0324b0d9113ada" +checksum = "32f8b686cadd1473f4bd0117a5d28d36b1ade384ea9b5069a1c40aefed7fda60" dependencies = [ "form_urlencoded", "idna", @@ -876,9 +876,9 @@ checksum = "9c8d87e72b64a3b4db28d11ce29237c246188f4f51057d65a7eab63b7987e423" [[package]] name = "webpki-roots" -version = "0.26.6" +version = "0.26.7" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "841c67bff177718f1d4dfefde8d8f0e78f9b6589319ba88312f567fc5841a958" +checksum = "5d642ff16b7e79272ae451b7322067cdc17cadf68c23264be9d94a32319efe7e" dependencies = [ "rustls-pki-types", ] @@ -1035,9 +1035,9 @@ dependencies = [ [[package]] name = "yoke" -version = "0.7.4" +version = "0.7.5" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "6c5b1314b079b0930c31e3af543d8ee1757b1951ae1e1565ec704403a7240ca5" +checksum = "120e6aef9aa629e3d4f52dc8cc43a015c7724194c97dfaf45180d2daf2b77f40" dependencies = [ "serde", "stable_deref_trait", @@ -1047,9 +1047,9 @@ dependencies = [ [[package]] name = "yoke-derive" -version = "0.7.4" +version = "0.7.5" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "28cc31741b18cb6f1d5ff12f5b7523e3d6eb0852bbbad19d73905511d9849b95" +checksum = "2380878cad4ac9aac1e2435f3eb4020e8374b5f13c296cb75b4620ff8e229154" dependencies = [ "proc-macro2", "quote", @@ -1059,18 +1059,18 @@ dependencies = [ [[package]] name = "zerofrom" -version = "0.1.4" +version = "0.1.5" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "91ec111ce797d0e0784a1116d0ddcdbea84322cd79e5d5ad173daeba4f93ab55" +checksum = "cff3ee08c995dee1859d998dea82f7374f2826091dd9cd47def953cae446cd2e" dependencies = [ "zerofrom-derive", ] [[package]] name = "zerofrom-derive" -version = "0.1.4" +version = "0.1.5" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "0ea7b4a3637ea8669cedf0f1fd5c286a17f3de97b8dd5a70a6c167a1730e63a5" +checksum = "595eed982f7d355beb85837f651fa22e90b3c044842dc7f2c2842c086f295808" dependencies = [ "proc-macro2", "quote", diff --git a/sysdata/libraries/stn/src/math.hb b/sysdata/libraries/stn/src/math.hb index d60495c1..b868cd87 100644 --- a/sysdata/libraries/stn/src/math.hb +++ b/sysdata/libraries/stn/src/math.hb @@ -10,6 +10,16 @@ $max := fn($Expr: type, a: Expr, b: Expr): Expr { $sign := fn($Expr: type, x: Expr): i8 { return @bitcast(x > 0) - @bitcast(x < 0) } +$log := fn($Expr: type, base: uint, x: Expr): uint { + // if x <= 0 {} + // if base <= 1 {} + result := 0 + loop if x < base break else { + x /= base + result += 1 + } + return result +} Vec2 := fn($Expr: type): type { return struct {x: Expr, y: Expr} diff --git a/sysdata/libraries/stn/src/string.hb b/sysdata/libraries/stn/src/string.hb index e6174980..cb78cd43 100644 --- a/sysdata/libraries/stn/src/string.hb +++ b/sysdata/libraries/stn/src/string.hb @@ -60,4 +60,157 @@ equals := fn(lhs: ^u8, rhs: ^u8): bool { lhs += 1 rhs += 1 } +} + +clear := fn(ptr: ^u8): void { + loop if *ptr == 0 break else { + *ptr = 0 + ptr += 1 + } +} + +split_once := fn(haystack: ^u8, needle: u8): ?^u8 { + loop if *haystack == needle return haystack else if *haystack == 0 return null else haystack += 1 +} + +split_once_str := fn(haystack: ^u8, needle: ^u8): ?^u8 { + if *needle == 0 return null + + loop if *haystack == 0 return null else { + if *haystack == *needle { + h := haystack + n := needle + + loop { + n += 1 + h += 1 + if *n == 0 { + return haystack + } else if *h == 0 | *h != *n { + break + } + } + } + haystack += 1 + } +} + +Split := struct { + str: ^u8, + needle: u8, + done: bool, +} + +split := fn(iter: ^u8, needle: u8): Split { + return .( + iter, + needle, + false, + ) +} + +iter_split := fn(iter: ^Split): ?^u8 { + if iter.done | *iter.str == 0 { + return null + } + + next := split_once(iter.str + 1, iter.needle) + + if next == null { + iter.done = true + return iter.str + } + s := iter.str + iter.str = next + 1 + + return s +} + +SplitStr := struct { + str: ^u8, + needle: ^u8, + done: bool, +} + +split_str := fn(iter: ^u8, needle: ^u8): SplitStr { + return .( + iter, + needle, + false, + ) +} + +iter_split_str := fn(iter: ^SplitStr): ?^u8 { + if iter.done | *iter.str == 0 { + return null + } + + next := split_once_str(iter.str, iter.needle) + + if next == null { + iter.done = true + return iter.str + } + + s := iter.str + + iter.str = next + length(iter.needle) + + return s +} + +find_once := fn(haystack: ^u8, needle: u8): ?uint { + return @bitcast(@inline(split_once, haystack, needle) - haystack) +} + +find_once_str := fn(haystack: ^u8, needle: ^u8): ?uint { + return @bitcast(@inline(split_once_str, haystack, needle) - haystack) +} + +count := fn(haystack: ^u8, needle: ^u8): uint { + c := 0 + loop if *haystack == needle { + c += 1 + haystack += 1 + } else if *haystack == 0 return c else haystack += 1 +} + +count_str := fn(haystack: ^u8, needle: ^u8): uint { + if *needle == 0 return 0 + c := 0 + loop if *haystack == 0 return c else { + if *haystack == *needle { + h := haystack + n := needle + + loop { + n += 1 + h += 1 + if *n == 0 { + c += 1 + break + } else if *h == 0 | *h != *n { + break + } + } + } + haystack += 1 + } +} + +left_trim := fn(str: ^u8, sub: ^u8): ^u8 { + original := str + if *str == *sub { + loop if *sub == 0 { + return str + } else if *str != *sub { + return original + } else if *str == 0 { + return original + } else { + str += 1 + sub += 1 + } + } + return str } \ No newline at end of file From 7b7e02976d08e61b6bd43c6dc2880802163fd704 Mon Sep 17 00:00:00 2001 From: koniifer Date: Sat, 23 Nov 2024 18:06:48 +0000 Subject: [PATCH 2/4] random change --- sysdata/libraries/stn/src/random.hb | 12 ++++++++++-- 1 file changed, 10 insertions(+), 2 deletions(-) diff --git a/sysdata/libraries/stn/src/random.hb b/sysdata/libraries/stn/src/random.hb index a7e5ec29..bf2917ca 100644 --- a/sysdata/libraries/stn/src/random.hb +++ b/sysdata/libraries/stn/src/random.hb @@ -1,7 +1,15 @@ -any := fn($Expr: type): Expr { +$any := fn($Expr: type): Expr { return *@eca(3, 4, &@as(Expr, idk), @sizeof(Expr)) } -range := fn($Expr: type, min: Expr, max: Expr): Expr { +$range := fn($Expr: type, min: Expr, max: Expr): Expr { return *@eca(3, 4, &@as(Expr, idk), @sizeof(Expr)) % (max - min) + *@bitcast(&1) + min +} + +$fill := fn($Expr: type, ptr: ^Expr): void { + return @eca(3, 4, ptr, @sizeof(Expr)) +} + +$fill_buffer := fn(buf: ^u8, len: uint): void { + return @eca(3, 4, buf, len) } \ No newline at end of file From ab8b2309ae6e9f144b06610d1f5fa195239719d9 Mon Sep 17 00:00:00 2001 From: funky Date: Sun, 24 Nov 2024 11:12:24 +1100 Subject: [PATCH 3/4] Nix Flake Support nix-shell is broken on both my systems, so better be safe than sorry. --- flake.lock | 96 ++++++++++++++++++++++++++++++++++++++++++++++++++++++ flake.nix | 30 +++++++++++++++++ 2 files changed, 126 insertions(+) create mode 100644 flake.lock create mode 100644 flake.nix diff --git a/flake.lock b/flake.lock new file mode 100644 index 00000000..1a38c50f --- /dev/null +++ b/flake.lock @@ -0,0 +1,96 @@ +{ + "nodes": { + "flake-utils": { + "inputs": { + "systems": "systems" + }, + "locked": { + "lastModified": 1731533236, + "narHash": "sha256-l0KFg5HjrsfsO/JpG+r7fRrqm12kzFHyUHqHCVpMMbI=", + "owner": "numtide", + "repo": "flake-utils", + "rev": "11707dc2f618dd54ca8739b309ec4fc024de578b", + "type": "github" + }, + "original": { + "owner": "numtide", + "repo": "flake-utils", + "type": "github" + } + }, + "nixpkgs": { + "locked": { + "lastModified": 1732014248, + "narHash": "sha256-y/MEyuJ5oBWrWAic/14LaIr/u5E0wRVzyYsouYY3W6w=", + "owner": "NixOS", + "repo": "nixpkgs", + "rev": "23e89b7da85c3640bbc2173fe04f4bd114342367", + "type": "github" + }, + "original": { + "owner": "NixOS", + "ref": "nixos-unstable", + "repo": "nixpkgs", + "type": "github" + } + }, + "nixpkgs_2": { + "locked": { + "lastModified": 1728538411, + "narHash": "sha256-f0SBJz1eZ2yOuKUr5CA9BHULGXVSn6miBuUWdTyhUhU=", + "owner": "NixOS", + "repo": "nixpkgs", + "rev": "b69de56fac8c2b6f8fd27f2eca01dcda8e0a4221", + "type": "github" + }, + "original": { + "owner": "NixOS", + "ref": "nixpkgs-unstable", + "repo": "nixpkgs", + "type": "github" + } + }, + "root": { + "inputs": { + "flake-utils": "flake-utils", + "nixpkgs": "nixpkgs", + "rust-overlay": "rust-overlay" + } + }, + "rust-overlay": { + "inputs": { + "nixpkgs": "nixpkgs_2" + }, + "locked": { + "lastModified": 1732328983, + "narHash": "sha256-RHt12f/slrzDpSL7SSkydh8wUE4Nr4r23HlpWywed9E=", + "owner": "oxalica", + "repo": "rust-overlay", + "rev": "ed8aa5b64f7d36d9338eb1d0a3bb60cf52069a72", + "type": "github" + }, + "original": { + "owner": "oxalica", + "repo": "rust-overlay", + "type": "github" + } + }, + "systems": { + "locked": { + "lastModified": 1681028828, + "narHash": "sha256-Vy1rq5AaRuLzOxct8nz4T6wlgyUR7zLU309k9mBC768=", + "owner": "nix-systems", + "repo": "default", + "rev": "da67096a3b9bf56a91d16901293e51ba5b49a27e", + "type": "github" + }, + "original": { + "owner": "nix-systems", + "repo": "default", + "type": "github" + } + } + }, + "root": "root", + "version": 7 +} diff --git a/flake.nix b/flake.nix new file mode 100644 index 00000000..82a7b69e --- /dev/null +++ b/flake.nix @@ -0,0 +1,30 @@ +{ + description = "A devShell example"; + + inputs = { + nixpkgs.url = "github:NixOS/nixpkgs/nixos-unstable"; + rust-overlay.url = "github:oxalica/rust-overlay"; + flake-utils.url = "github:numtide/flake-utils"; + }; + + outputs = { self, nixpkgs, rust-overlay, flake-utils }: + flake-utils.lib.eachDefaultSystem (system: + let + overlays = [ (import rust-overlay) ]; + pkgs = import nixpkgs { + inherit system overlays; + }; + + rustToolchain = pkgs.pkgsBuildHost.rust-bin.fromRustupToolchainFile ./rust-toolchain.toml; + in + with pkgs; + { + devShells.default = mkShell { + buildInputs = [ + rustToolchain + qemu_full + ]; + }; + } + ); +} From 80ae717dd9af1e27e9846cc21923cf47e8e17474 Mon Sep 17 00:00:00 2001 From: funky Date: Sun, 24 Nov 2024 11:21:39 +1100 Subject: [PATCH 4/4] Introduced kernel testing system ktest This commit also fixed a small issue with panic handler formatting --- Cargo.lock | 9 ++++++++ kernel/Cargo.toml | 3 +++ kernel/ktest_macro/Cargo.toml | 11 ++++++++++ kernel/ktest_macro/src/lib.rs | 29 +++++++++++++++++++++++++ kernel/lds/x86_64.ld | 7 ++++++ kernel/src/kmain.rs | 15 +++++++------ kernel/src/ktest.rs | 38 +++++++++++++++++++++++++++++++++ kernel/src/lib.rs | 19 ++++++----------- repbuild/src/main.rs | 40 ++++++++++++++++++++++++++++++++--- 9 files changed, 149 insertions(+), 22 deletions(-) create mode 100644 kernel/ktest_macro/Cargo.toml create mode 100644 kernel/ktest_macro/src/lib.rs create mode 100644 kernel/src/ktest.rs diff --git a/Cargo.lock b/Cargo.lock index 8dc4baa1..baaf1a60 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -392,6 +392,7 @@ dependencies = [ "derive_more", "hashbrown", "hbvm", + "ktest_macro", "limine", "log", "sbi", @@ -404,6 +405,14 @@ dependencies = [ "xml", ] +[[package]] +name = "ktest_macro" +version = "0.1.0" +dependencies = [ + "quote", + "syn", +] + [[package]] name = "lazy_static" version = "1.5.0" diff --git a/kernel/Cargo.toml b/kernel/Cargo.toml index 9cbe8956..9cee4de7 100644 --- a/kernel/Cargo.toml +++ b/kernel/Cargo.toml @@ -3,12 +3,15 @@ edition = "2021" name = "kernel" version = "0.2.0" +[features] +ktest = [] [dependencies] # embedded-graphics = "0.8" hbvm = { git = "https://git.ablecorp.us/AbleOS/holey-bytes.git", features = [ "nightly", ] } +ktest_macro = { path = "ktest_macro" } log = "0.4" spin = "0.9" slab = { version = "0.4", default-features = false } diff --git a/kernel/ktest_macro/Cargo.toml b/kernel/ktest_macro/Cargo.toml new file mode 100644 index 00000000..5c85e6cc --- /dev/null +++ b/kernel/ktest_macro/Cargo.toml @@ -0,0 +1,11 @@ +[package] +edition = "2021" +name = "ktest_macro" +version = "0.1.0" + +[lib] +proc-macro = true + +[dependencies] +quote = "1.0.37" +syn = { version = "2.0.89", features = ["full"] } \ No newline at end of file diff --git a/kernel/ktest_macro/src/lib.rs b/kernel/ktest_macro/src/lib.rs new file mode 100644 index 00000000..c1c3a8a3 --- /dev/null +++ b/kernel/ktest_macro/src/lib.rs @@ -0,0 +1,29 @@ +extern crate proc_macro; +extern crate quote; +extern crate syn; +use { + proc_macro::TokenStream, + quote::quote, + syn::{parse_macro_input, ItemFn} +}; + +#[proc_macro_attribute] +pub fn ktest(_attr: TokenStream, item: TokenStream) -> TokenStream { + let input = parse_macro_input!(item as ItemFn); + let test_name = &input.sig.ident; + let static_var_name = syn::Ident::new( + &format!("__ktest_{}", test_name), + test_name.span(), + ); + let out = quote! { + // #[cfg(feature = "ktest")] + #input + + // #[cfg(feature = "ktest")] + #[unsafe(link_section = ".note.ktest")] + #[used] + pub static #static_var_name: fn() = #test_name; + }; + + TokenStream::from(out) +} \ No newline at end of file diff --git a/kernel/lds/x86_64.ld b/kernel/lds/x86_64.ld index 19ee79f6..84e8c4d7 100644 --- a/kernel/lds/x86_64.ld +++ b/kernel/lds/x86_64.ld @@ -40,6 +40,13 @@ SECTIONS *(.data .data.*) *(.got .got.*) } :data + + /* Add the .ktest section for test functions */ + .note.ktest : { + __ktest_start = .; /* Mark the beginning of the section */ + *(.note.ktest) /* Include all items in the .ktest section */ + __ktest_end = .; /* Mark the end of the section */ + } .bss : { *(COMMON) diff --git a/kernel/src/kmain.rs b/kernel/src/kmain.rs index ec87c6f8..625b9cd7 100644 --- a/kernel/src/kmain.rs +++ b/kernel/src/kmain.rs @@ -22,6 +22,14 @@ use { pub fn kmain(_cmdline: &str, boot_modules: BootModules) -> ! { debug!("Entered kmain"); + #[cfg(feature = "ktest")] { + use crate::ktest; + debug!("TESTING"); + ktest::test_main(); + + loop {}; + } + // let kcmd = build_cmd("Kernel Command Line", cmdline); // trace!("Cmdline: {kcmd:?}"); @@ -148,10 +156,3 @@ pub static IPC_BUFFERS: Lazy> = Lazy::new(|| { Mutex::new(bufs) }); - -#[test_case] -fn trivial_assertion() { - trace!("trivial assertion... "); - assert_eq!(1, 1); - info!("[ok]"); -} diff --git a/kernel/src/ktest.rs b/kernel/src/ktest.rs new file mode 100644 index 00000000..43a2a11a --- /dev/null +++ b/kernel/src/ktest.rs @@ -0,0 +1,38 @@ +pub use ktest_macro::ktest; +use log::debug; + +extern "C" { + static __ktest_start: fn(); + static __ktest_end: fn(); +} + +// TODO: Get test_fn linker name (may require no_mangle in macro) +// More info on tests (run the rest even if panic) +// Implement ktest for arm and riscv (Later problems, see below) +// Allow for arch specific tests (Leave for now) +// Allow for ktest test name attr +// Usefull message at the end of testing +pub fn test_main() { + unsafe { + let mut current_test = &__ktest_start as *const fn(); + let mut current = 1; + let test_end = &__ktest_end as *const fn(); + + while current_test < test_end { + let test_fn = *current_test; + + debug!("Running test {}", current); + + test_fn(); + debug!("Test {} passed", current); + + current_test = current_test.add(1); + current += 1; + } + } +} + +#[ktest] +pub fn trivial_assertion() { + assert_eq!(1, 1); +} \ No newline at end of file diff --git a/kernel/src/lib.rs b/kernel/src/lib.rs index f5bf86f8..52956ecd 100644 --- a/kernel/src/lib.rs +++ b/kernel/src/lib.rs @@ -2,6 +2,7 @@ //! Named akern. //! Akern is woefully undersupported at the moment but we are looking to add support improve hardware discovery and make our lives as kernel and operating system developers easier and better #![no_std] +#![no_main] #![feature( slice_split_once, exclusive_wrapper, @@ -10,11 +11,9 @@ lazy_get, alloc_error_handler, ptr_sub_ptr, - custom_test_frameworks, naked_functions, - pointer_is_aligned_to + pointer_is_aligned_to, )] -#![test_runner(crate::test_runner)] #![allow(dead_code, internal_features, static_mut_refs)] extern crate alloc; @@ -33,6 +32,10 @@ mod memory; mod task; mod utils; +// #[cfg(feature = "tests")] +mod ktest; + +use alloc::string::ToString; use versioning::Version; /// Kernel's version @@ -56,15 +59,7 @@ fn panic(info: &core::panic::PanicInfo) -> ! { )); } - let msg = info.message(); + let msg = info.message().to_string().replace("\n", "\r\n"); let _ = crate::arch::log(format_args!("{msg}\r\n")); loop {} } - -#[cfg(test)] -fn test_runner(tests: &[&dyn Fn()]) { - println!("Running {} tests", tests.len()); - for test in tests { - test(); - } -} diff --git a/repbuild/src/main.rs b/repbuild/src/main.rs index 2741ef52..5a80bf49 100644 --- a/repbuild/src/main.rs +++ b/repbuild/src/main.rs @@ -27,6 +27,7 @@ fn main() -> Result<(), Error> { let mut release = false; let mut debuginfo = false; let mut target = Target::X86_64; + let mut tests = false; for arg in args { if arg == "-r" || arg == "--release" { release = true; @@ -38,17 +39,42 @@ fn main() -> Result<(), Error> { target = Target::Aarch64; } else if arg == "avx2" { target = Target::X86_64Avx2; + } else if arg == "--ktest" { + tests = true; } else { return Err(report!(Error::InvalidSubCom)); } } - build(release, target, debuginfo).change_context(Error::Build) + build(release, target, debuginfo, tests).change_context(Error::Build) } + // Some("test" | "t") => { + // let mut release = false; + // let mut debuginfo = false; + // let mut target = Target::X86_64; + // for arg in args { + // if arg == "-r" || arg == "--release" { + // release = true; + // } else if arg == "-d" || arg == "--debuginfo" { + // debuginfo = true; + // } else if arg == "rv64" || arg == "riscv64" || arg == "riscv64-virt" { + // target = Target::Riscv64Virt; + // } else if arg == "arm64" || arg == "aarch64" || arg == "aarch64-virt" { + // target = Target::Aarch64; + // } else if arg == "avx2" { + // target = Target::X86_64Avx2; + // } else { + // return Err(report!(Error::InvalidSubCom)); + // } + // } + + // test(release, target, debuginfo).change_context(Error::Build) + // } Some("run" | "r") => { let mut release = false; let mut debuginfo = false; let mut target = Target::X86_64; + let mut tests = false; let mut do_accel = true; for arg in args { if arg == "-r" || arg == "--release" { @@ -63,12 +89,14 @@ fn main() -> Result<(), Error> { do_accel = false; } else if arg == "avx2" { target = Target::X86_64Avx2; + } else if arg == "--ktest" { + tests = true; } else { return Err(report!(Error::InvalidSubCom)); } } - build(release, target, debuginfo)?; + build(release, target, debuginfo, tests)?; run(release, target, do_accel) } Some("help" | "h") => { @@ -82,6 +110,7 @@ fn main() -> Result<(), Error> { " -r / --release: build in release mode\n", " -d / --debuginfo: build with debug info\n", " --noaccel: run without acceleration (e.g, no kvm)\n", + " --ktest: Enables tests via ktest\n", "[ rv64 / riscv64 / riscv64-virt / aarch64 / arm64 / aarch64-virt / avx2 ]: sets target" ),); Ok(()) @@ -310,7 +339,7 @@ fn copy_file_to_img(fpath: &str, fs: &FileSystem) { .expect("Copy failed"); } -fn build(release: bool, target: Target, debuginfo: bool) -> Result<(), Error> { +fn build(release: bool, target: Target, debuginfo: bool, tests: bool) -> Result<(), Error> { let fs = get_fs().change_context(Error::Io)?; let mut com = Command::new("cargo"); com.current_dir("kernel"); @@ -322,6 +351,10 @@ fn build(release: bool, target: Target, debuginfo: bool) -> Result<(), Error> { com.env("RUSTFLAGS", "-Cdebug-assertions=true"); } + if tests { + com.args(["--features", "ktest"]); + } + if target == Target::Riscv64Virt { com.args(["--target", "targets/riscv64-virt-ableos.json"]); } @@ -473,6 +506,7 @@ fn run(release: bool, target: Target, do_accel: bool) -> Result<(), Error> { } } + fn fetch_ovmf(target: Target) -> Result { let (ovmf_url, ovmf_path) = match target { Target::X86_64 | Target::X86_64Avx2 => (