From 0e056e62d148ff878d52ea3867be077e44ac3fc0 Mon Sep 17 00:00:00 2001 From: Kuro Date: Fri, 4 Jul 2025 13:42:45 +0200 Subject: [PATCH] feat: third commit --- .../debug/deps/rustversion-cf597c339519c569.d | 20 ++++++ lupos/target/x86_64-lupos/CACHEDIR.TAG | 3 + lupos/target/x86_64-lupos/debug/.cargo-lock | 0 .../invoked.timestamp | 1 + .../invoked.timestamp | 1 + .../output-lib-bitflags | 3 + .../run-build-script-build-script-build | 1 + .../run-build-script-build-script-build.json | 1 + .../invoked.timestamp | 1 + .../output-lib-scopeguard | 3 + .../invoked.timestamp | 1 + .../invoked.timestamp | 1 + .../build/lock_api-2de7117dbaa0347d/output | 1 + .../lock_api-2de7117dbaa0347d/root-output | 1 + .../build/lock_api-2de7117dbaa0347d/stderr | 9 +++ lupos/tests/basic_boot.rs | 28 ++++++++ lupos/tests/heap_allocation.rs | 70 +++++++++++++++++++ lupos/tests/should_panic.rs | 29 ++++++++ lupos/tests/stack_overflow.rs | 63 +++++++++++++++++ 19 files changed, 237 insertions(+) create mode 100644 lupos/target/debug/deps/rustversion-cf597c339519c569.d create mode 100644 lupos/target/x86_64-lupos/CACHEDIR.TAG create mode 100644 lupos/target/x86_64-lupos/debug/.cargo-lock create mode 100644 lupos/target/x86_64-lupos/debug/.fingerprint/bit_field-bde752551c203be4/invoked.timestamp create mode 100644 lupos/target/x86_64-lupos/debug/.fingerprint/bitflags-e1e6fea32e86a07b/invoked.timestamp create mode 100644 lupos/target/x86_64-lupos/debug/.fingerprint/bitflags-e1e6fea32e86a07b/output-lib-bitflags create mode 100644 lupos/target/x86_64-lupos/debug/.fingerprint/lock_api-2de7117dbaa0347d/run-build-script-build-script-build create mode 100644 lupos/target/x86_64-lupos/debug/.fingerprint/lock_api-2de7117dbaa0347d/run-build-script-build-script-build.json create mode 100644 lupos/target/x86_64-lupos/debug/.fingerprint/scopeguard-7e808608a84a0678/invoked.timestamp create mode 100644 lupos/target/x86_64-lupos/debug/.fingerprint/scopeguard-7e808608a84a0678/output-lib-scopeguard create mode 100644 lupos/target/x86_64-lupos/debug/.fingerprint/volatile-021319eea23380d9/invoked.timestamp create mode 100644 lupos/target/x86_64-lupos/debug/build/lock_api-2de7117dbaa0347d/invoked.timestamp create mode 100644 lupos/target/x86_64-lupos/debug/build/lock_api-2de7117dbaa0347d/output create mode 100644 lupos/target/x86_64-lupos/debug/build/lock_api-2de7117dbaa0347d/root-output create mode 100644 lupos/target/x86_64-lupos/debug/build/lock_api-2de7117dbaa0347d/stderr create mode 100644 lupos/tests/basic_boot.rs create mode 100644 lupos/tests/heap_allocation.rs create mode 100644 lupos/tests/should_panic.rs create mode 100644 lupos/tests/stack_overflow.rs diff --git a/lupos/target/debug/deps/rustversion-cf597c339519c569.d b/lupos/target/debug/deps/rustversion-cf597c339519c569.d new file mode 100644 index 0000000..1f40826 --- /dev/null +++ b/lupos/target/debug/deps/rustversion-cf597c339519c569.d @@ -0,0 +1,20 @@ +/home/kuro/vs-workspace/LupOS/lupos/target/debug/deps/rustversion-cf597c339519c569.d: /home/kuro/.cargo/registry/src/index.crates.io-1949cf8c6b5b557f/rustversion-1.0.17/src/lib.rs /home/kuro/.cargo/registry/src/index.crates.io-1949cf8c6b5b557f/rustversion-1.0.17/src/attr.rs /home/kuro/.cargo/registry/src/index.crates.io-1949cf8c6b5b557f/rustversion-1.0.17/src/bound.rs /home/kuro/.cargo/registry/src/index.crates.io-1949cf8c6b5b557f/rustversion-1.0.17/src/constfn.rs /home/kuro/.cargo/registry/src/index.crates.io-1949cf8c6b5b557f/rustversion-1.0.17/src/date.rs /home/kuro/.cargo/registry/src/index.crates.io-1949cf8c6b5b557f/rustversion-1.0.17/src/error.rs /home/kuro/.cargo/registry/src/index.crates.io-1949cf8c6b5b557f/rustversion-1.0.17/src/expand.rs /home/kuro/.cargo/registry/src/index.crates.io-1949cf8c6b5b557f/rustversion-1.0.17/src/expr.rs /home/kuro/.cargo/registry/src/index.crates.io-1949cf8c6b5b557f/rustversion-1.0.17/src/iter.rs /home/kuro/.cargo/registry/src/index.crates.io-1949cf8c6b5b557f/rustversion-1.0.17/src/release.rs /home/kuro/.cargo/registry/src/index.crates.io-1949cf8c6b5b557f/rustversion-1.0.17/src/time.rs /home/kuro/.cargo/registry/src/index.crates.io-1949cf8c6b5b557f/rustversion-1.0.17/src/token.rs /home/kuro/.cargo/registry/src/index.crates.io-1949cf8c6b5b557f/rustversion-1.0.17/src/version.rs /home/kuro/vs-workspace/LupOS/lupos/target/debug/build/rustversion-80895c343822e980/out/version.expr + +/home/kuro/vs-workspace/LupOS/lupos/target/debug/deps/librustversion-cf597c339519c569.so: /home/kuro/.cargo/registry/src/index.crates.io-1949cf8c6b5b557f/rustversion-1.0.17/src/lib.rs /home/kuro/.cargo/registry/src/index.crates.io-1949cf8c6b5b557f/rustversion-1.0.17/src/attr.rs /home/kuro/.cargo/registry/src/index.crates.io-1949cf8c6b5b557f/rustversion-1.0.17/src/bound.rs /home/kuro/.cargo/registry/src/index.crates.io-1949cf8c6b5b557f/rustversion-1.0.17/src/constfn.rs /home/kuro/.cargo/registry/src/index.crates.io-1949cf8c6b5b557f/rustversion-1.0.17/src/date.rs /home/kuro/.cargo/registry/src/index.crates.io-1949cf8c6b5b557f/rustversion-1.0.17/src/error.rs /home/kuro/.cargo/registry/src/index.crates.io-1949cf8c6b5b557f/rustversion-1.0.17/src/expand.rs /home/kuro/.cargo/registry/src/index.crates.io-1949cf8c6b5b557f/rustversion-1.0.17/src/expr.rs /home/kuro/.cargo/registry/src/index.crates.io-1949cf8c6b5b557f/rustversion-1.0.17/src/iter.rs /home/kuro/.cargo/registry/src/index.crates.io-1949cf8c6b5b557f/rustversion-1.0.17/src/release.rs /home/kuro/.cargo/registry/src/index.crates.io-1949cf8c6b5b557f/rustversion-1.0.17/src/time.rs /home/kuro/.cargo/registry/src/index.crates.io-1949cf8c6b5b557f/rustversion-1.0.17/src/token.rs /home/kuro/.cargo/registry/src/index.crates.io-1949cf8c6b5b557f/rustversion-1.0.17/src/version.rs /home/kuro/vs-workspace/LupOS/lupos/target/debug/build/rustversion-80895c343822e980/out/version.expr + +/home/kuro/.cargo/registry/src/index.crates.io-1949cf8c6b5b557f/rustversion-1.0.17/src/lib.rs: +/home/kuro/.cargo/registry/src/index.crates.io-1949cf8c6b5b557f/rustversion-1.0.17/src/attr.rs: +/home/kuro/.cargo/registry/src/index.crates.io-1949cf8c6b5b557f/rustversion-1.0.17/src/bound.rs: +/home/kuro/.cargo/registry/src/index.crates.io-1949cf8c6b5b557f/rustversion-1.0.17/src/constfn.rs: +/home/kuro/.cargo/registry/src/index.crates.io-1949cf8c6b5b557f/rustversion-1.0.17/src/date.rs: +/home/kuro/.cargo/registry/src/index.crates.io-1949cf8c6b5b557f/rustversion-1.0.17/src/error.rs: +/home/kuro/.cargo/registry/src/index.crates.io-1949cf8c6b5b557f/rustversion-1.0.17/src/expand.rs: +/home/kuro/.cargo/registry/src/index.crates.io-1949cf8c6b5b557f/rustversion-1.0.17/src/expr.rs: +/home/kuro/.cargo/registry/src/index.crates.io-1949cf8c6b5b557f/rustversion-1.0.17/src/iter.rs: +/home/kuro/.cargo/registry/src/index.crates.io-1949cf8c6b5b557f/rustversion-1.0.17/src/release.rs: +/home/kuro/.cargo/registry/src/index.crates.io-1949cf8c6b5b557f/rustversion-1.0.17/src/time.rs: +/home/kuro/.cargo/registry/src/index.crates.io-1949cf8c6b5b557f/rustversion-1.0.17/src/token.rs: +/home/kuro/.cargo/registry/src/index.crates.io-1949cf8c6b5b557f/rustversion-1.0.17/src/version.rs: +/home/kuro/vs-workspace/LupOS/lupos/target/debug/build/rustversion-80895c343822e980/out/version.expr: + +# env-dep:OUT_DIR=/home/kuro/vs-workspace/LupOS/lupos/target/debug/build/rustversion-80895c343822e980/out diff --git a/lupos/target/x86_64-lupos/CACHEDIR.TAG b/lupos/target/x86_64-lupos/CACHEDIR.TAG new file mode 100644 index 0000000..20d7c31 --- /dev/null +++ b/lupos/target/x86_64-lupos/CACHEDIR.TAG @@ -0,0 +1,3 @@ +Signature: 8a477f597d28d172789f06886806bc55 +# This file is a cache directory tag created by cargo. +# For information about cache directory tags see https://bford.info/cachedir/ diff --git a/lupos/target/x86_64-lupos/debug/.cargo-lock b/lupos/target/x86_64-lupos/debug/.cargo-lock new file mode 100644 index 0000000..e69de29 diff --git a/lupos/target/x86_64-lupos/debug/.fingerprint/bit_field-bde752551c203be4/invoked.timestamp b/lupos/target/x86_64-lupos/debug/.fingerprint/bit_field-bde752551c203be4/invoked.timestamp new file mode 100644 index 0000000..e00328d --- /dev/null +++ b/lupos/target/x86_64-lupos/debug/.fingerprint/bit_field-bde752551c203be4/invoked.timestamp @@ -0,0 +1 @@ +This file has an mtime of when this was started. \ No newline at end of file diff --git a/lupos/target/x86_64-lupos/debug/.fingerprint/bitflags-e1e6fea32e86a07b/invoked.timestamp b/lupos/target/x86_64-lupos/debug/.fingerprint/bitflags-e1e6fea32e86a07b/invoked.timestamp new file mode 100644 index 0000000..e00328d --- /dev/null +++ b/lupos/target/x86_64-lupos/debug/.fingerprint/bitflags-e1e6fea32e86a07b/invoked.timestamp @@ -0,0 +1 @@ +This file has an mtime of when this was started. \ No newline at end of file diff --git a/lupos/target/x86_64-lupos/debug/.fingerprint/bitflags-e1e6fea32e86a07b/output-lib-bitflags b/lupos/target/x86_64-lupos/debug/.fingerprint/bitflags-e1e6fea32e86a07b/output-lib-bitflags new file mode 100644 index 0000000..09f0c83 --- /dev/null +++ b/lupos/target/x86_64-lupos/debug/.fingerprint/bitflags-e1e6fea32e86a07b/output-lib-bitflags @@ -0,0 +1,3 @@ +{"$message_type":"diagnostic","message":"can't find crate for `core`","code":{"code":"E0463","explanation":"A crate was declared but cannot be found.\n\nErroneous code example:\n\n```compile_fail,E0463\nextern crate foo; // error: can't find crate\n```\n\nYou need to link your code to the relevant crate in order to be able to use it\n(through Cargo or the `-L` option of rustc, for example).\n\n## Common causes\n\n- The crate is not present at all. If using Cargo, add it to `[dependencies]`\n in Cargo.toml.\n- The crate is present, but under a different name. If using Cargo, look for\n `package = ` under `[dependencies]` in Cargo.toml.\n\n## Common causes for missing `std` or `core`\n\n- You are cross-compiling for a target which doesn't have `std` prepackaged.\n Consider one of the following:\n + Adding a pre-compiled version of std with `rustup target add`\n + Building std from source with `cargo build -Z build-std`\n + Using `#![no_std]` at the crate root, so you won't need `std` in the first\n place.\n- You are developing the compiler itself and haven't built libstd from source.\n You can usually build it with `x.py build library/std`. More information\n about x.py is available in the [rustc-dev-guide].\n\n[rustc-dev-guide]: https://rustc-dev-guide.rust-lang.org/building/how-to-build-and-run.html#building-the-compiler\n"},"level":"error","spans":[{"file_name":"/home/kuro/.cargo/registry/src/index.crates.io-1949cf8c6b5b557f/bitflags-2.5.0/src/lib.rs","byte_start":0,"byte_end":0,"line_start":1,"line_end":1,"column_start":1,"column_end":1,"is_primary":true,"text":[],"label":"can't find crate","suggested_replacement":null,"suggestion_applicability":null,"expansion":null}],"children":[{"message":"the `x86_64-lupos` target may not be installed","code":null,"level":"note","spans":[],"children":[],"rendered":null},{"message":"consider downloading the target with `rustup target add x86_64-lupos`","code":null,"level":"help","spans":[],"children":[],"rendered":null}],"rendered":"\u001b[0m\u001b[1m\u001b[38;5;9merror[E0463]\u001b[0m\u001b[0m\u001b[1m: can't find crate for `core`\u001b[0m\n\u001b[0m \u001b[0m\u001b[0m\u001b[1m\u001b[38;5;12m|\u001b[0m\n\u001b[0m \u001b[0m\u001b[0m\u001b[1m\u001b[38;5;12m= \u001b[0m\u001b[0m\u001b[1mnote\u001b[0m\u001b[0m: the `x86_64-lupos` target may not be installed\u001b[0m\n\u001b[0m \u001b[0m\u001b[0m\u001b[1m\u001b[38;5;12m= \u001b[0m\u001b[0m\u001b[1mhelp\u001b[0m\u001b[0m: consider downloading the target with `rustup target add x86_64-lupos`\u001b[0m\n\n"} +{"$message_type":"diagnostic","message":"aborting due to 1 previous error","code":null,"level":"error","spans":[],"children":[],"rendered":"\u001b[0m\u001b[1m\u001b[38;5;9merror\u001b[0m\u001b[0m\u001b[1m: aborting due to 1 previous error\u001b[0m\n\n"} +{"$message_type":"diagnostic","message":"For more information about this error, try `rustc --explain E0463`.","code":null,"level":"failure-note","spans":[],"children":[],"rendered":"\u001b[0m\u001b[1mFor more information about this error, try `rustc --explain E0463`.\u001b[0m\n"} diff --git a/lupos/target/x86_64-lupos/debug/.fingerprint/lock_api-2de7117dbaa0347d/run-build-script-build-script-build b/lupos/target/x86_64-lupos/debug/.fingerprint/lock_api-2de7117dbaa0347d/run-build-script-build-script-build new file mode 100644 index 0000000..fefeda3 --- /dev/null +++ b/lupos/target/x86_64-lupos/debug/.fingerprint/lock_api-2de7117dbaa0347d/run-build-script-build-script-build @@ -0,0 +1 @@ +724a9f581fd733e6 \ No newline at end of file diff --git a/lupos/target/x86_64-lupos/debug/.fingerprint/lock_api-2de7117dbaa0347d/run-build-script-build-script-build.json b/lupos/target/x86_64-lupos/debug/.fingerprint/lock_api-2de7117dbaa0347d/run-build-script-build-script-build.json new file mode 100644 index 0000000..bf90ee9 --- /dev/null +++ b/lupos/target/x86_64-lupos/debug/.fingerprint/lock_api-2de7117dbaa0347d/run-build-script-build-script-build.json @@ -0,0 +1 @@ +{"rustc":11410426090777951712,"features":"","declared_features":"","target":0,"profile":0,"path":0,"deps":[[4796557380116975802,"build_script_build",false,4012139224968854081]],"local":[{"Precalculated":"0.4.12"}],"rustflags":[],"config":0,"compile_kind":0} \ No newline at end of file diff --git a/lupos/target/x86_64-lupos/debug/.fingerprint/scopeguard-7e808608a84a0678/invoked.timestamp b/lupos/target/x86_64-lupos/debug/.fingerprint/scopeguard-7e808608a84a0678/invoked.timestamp new file mode 100644 index 0000000..e00328d --- /dev/null +++ b/lupos/target/x86_64-lupos/debug/.fingerprint/scopeguard-7e808608a84a0678/invoked.timestamp @@ -0,0 +1 @@ +This file has an mtime of when this was started. \ No newline at end of file diff --git a/lupos/target/x86_64-lupos/debug/.fingerprint/scopeguard-7e808608a84a0678/output-lib-scopeguard b/lupos/target/x86_64-lupos/debug/.fingerprint/scopeguard-7e808608a84a0678/output-lib-scopeguard new file mode 100644 index 0000000..98e3846 --- /dev/null +++ b/lupos/target/x86_64-lupos/debug/.fingerprint/scopeguard-7e808608a84a0678/output-lib-scopeguard @@ -0,0 +1,3 @@ +{"$message_type":"diagnostic","message":"can't find crate for `core`","code":{"code":"E0463","explanation":"A crate was declared but cannot be found.\n\nErroneous code example:\n\n```compile_fail,E0463\nextern crate foo; // error: can't find crate\n```\n\nYou need to link your code to the relevant crate in order to be able to use it\n(through Cargo or the `-L` option of rustc, for example).\n\n## Common causes\n\n- The crate is not present at all. If using Cargo, add it to `[dependencies]`\n in Cargo.toml.\n- The crate is present, but under a different name. If using Cargo, look for\n `package = ` under `[dependencies]` in Cargo.toml.\n\n## Common causes for missing `std` or `core`\n\n- You are cross-compiling for a target which doesn't have `std` prepackaged.\n Consider one of the following:\n + Adding a pre-compiled version of std with `rustup target add`\n + Building std from source with `cargo build -Z build-std`\n + Using `#![no_std]` at the crate root, so you won't need `std` in the first\n place.\n- You are developing the compiler itself and haven't built libstd from source.\n You can usually build it with `x.py build library/std`. More information\n about x.py is available in the [rustc-dev-guide].\n\n[rustc-dev-guide]: https://rustc-dev-guide.rust-lang.org/building/how-to-build-and-run.html#building-the-compiler\n"},"level":"error","spans":[{"file_name":"/home/kuro/.cargo/registry/src/index.crates.io-1949cf8c6b5b557f/scopeguard-1.2.0/src/lib.rs","byte_start":0,"byte_end":0,"line_start":1,"line_end":1,"column_start":1,"column_end":1,"is_primary":true,"text":[],"label":"can't find crate","suggested_replacement":null,"suggestion_applicability":null,"expansion":null}],"children":[{"message":"the `x86_64-lupos` target may not be installed","code":null,"level":"note","spans":[],"children":[],"rendered":null},{"message":"consider downloading the target with `rustup target add x86_64-lupos`","code":null,"level":"help","spans":[],"children":[],"rendered":null}],"rendered":"\u001b[0m\u001b[1m\u001b[38;5;9merror[E0463]\u001b[0m\u001b[0m\u001b[1m: can't find crate for `core`\u001b[0m\n\u001b[0m \u001b[0m\u001b[0m\u001b[1m\u001b[38;5;12m|\u001b[0m\n\u001b[0m \u001b[0m\u001b[0m\u001b[1m\u001b[38;5;12m= \u001b[0m\u001b[0m\u001b[1mnote\u001b[0m\u001b[0m: the `x86_64-lupos` target may not be installed\u001b[0m\n\u001b[0m \u001b[0m\u001b[0m\u001b[1m\u001b[38;5;12m= \u001b[0m\u001b[0m\u001b[1mhelp\u001b[0m\u001b[0m: consider downloading the target with `rustup target add x86_64-lupos`\u001b[0m\n\n"} +{"$message_type":"diagnostic","message":"aborting due to 1 previous error","code":null,"level":"error","spans":[],"children":[],"rendered":"\u001b[0m\u001b[1m\u001b[38;5;9merror\u001b[0m\u001b[0m\u001b[1m: aborting due to 1 previous error\u001b[0m\n\n"} +{"$message_type":"diagnostic","message":"For more information about this error, try `rustc --explain E0463`.","code":null,"level":"failure-note","spans":[],"children":[],"rendered":"\u001b[0m\u001b[1mFor more information about this error, try `rustc --explain E0463`.\u001b[0m\n"} diff --git a/lupos/target/x86_64-lupos/debug/.fingerprint/volatile-021319eea23380d9/invoked.timestamp b/lupos/target/x86_64-lupos/debug/.fingerprint/volatile-021319eea23380d9/invoked.timestamp new file mode 100644 index 0000000..e00328d --- /dev/null +++ b/lupos/target/x86_64-lupos/debug/.fingerprint/volatile-021319eea23380d9/invoked.timestamp @@ -0,0 +1 @@ +This file has an mtime of when this was started. \ No newline at end of file diff --git a/lupos/target/x86_64-lupos/debug/build/lock_api-2de7117dbaa0347d/invoked.timestamp b/lupos/target/x86_64-lupos/debug/build/lock_api-2de7117dbaa0347d/invoked.timestamp new file mode 100644 index 0000000..e00328d --- /dev/null +++ b/lupos/target/x86_64-lupos/debug/build/lock_api-2de7117dbaa0347d/invoked.timestamp @@ -0,0 +1 @@ +This file has an mtime of when this was started. \ No newline at end of file diff --git a/lupos/target/x86_64-lupos/debug/build/lock_api-2de7117dbaa0347d/output b/lupos/target/x86_64-lupos/debug/build/lock_api-2de7117dbaa0347d/output new file mode 100644 index 0000000..ad552e5 --- /dev/null +++ b/lupos/target/x86_64-lupos/debug/build/lock_api-2de7117dbaa0347d/output @@ -0,0 +1 @@ +cargo:rustc-cfg=has_const_fn_trait_bound diff --git a/lupos/target/x86_64-lupos/debug/build/lock_api-2de7117dbaa0347d/root-output b/lupos/target/x86_64-lupos/debug/build/lock_api-2de7117dbaa0347d/root-output new file mode 100644 index 0000000..2e535a7 --- /dev/null +++ b/lupos/target/x86_64-lupos/debug/build/lock_api-2de7117dbaa0347d/root-output @@ -0,0 +1 @@ +/home/kuro/vs-workspace/LupOS/lupos/target/x86_64-lupos/debug/build/lock_api-2de7117dbaa0347d/out \ No newline at end of file diff --git a/lupos/target/x86_64-lupos/debug/build/lock_api-2de7117dbaa0347d/stderr b/lupos/target/x86_64-lupos/debug/build/lock_api-2de7117dbaa0347d/stderr new file mode 100644 index 0000000..e65b130 --- /dev/null +++ b/lupos/target/x86_64-lupos/debug/build/lock_api-2de7117dbaa0347d/stderr @@ -0,0 +1,9 @@ +error: error loading target specification: could not find specification for target "x86_64-lupos" + | + = help: run `rustc --print target-list` for a list of built-in targets + +error: error loading target specification: could not find specification for target "x86_64-lupos" + | + = help: run `rustc --print target-list` for a list of built-in targets + +warning: autocfg could not probe for `std` diff --git a/lupos/tests/basic_boot.rs b/lupos/tests/basic_boot.rs new file mode 100644 index 0000000..e429b5a --- /dev/null +++ b/lupos/tests/basic_boot.rs @@ -0,0 +1,28 @@ +#![no_std] +#![no_main] +#![feature(custom_test_frameworks)] +#![test_runner(lupos::test_runner)] +#![reexport_test_harness_main = "test_main"] + +use core::panic::PanicInfo; +use lupos::println; + +#[test_case] +fn test_println() { + println!("test_println output"); +} +#[no_mangle] // don't mangle the name of this function +pub extern "C" fn _start() -> ! { + test_main(); + + loop {} +} + +fn test_runner(_tests: &[&dyn Fn()]) { + unimplemented!(); +} + +#[panic_handler] +fn panic(info: &PanicInfo) -> ! { + lupos::test_panic_handler(info) +} \ No newline at end of file diff --git a/lupos/tests/heap_allocation.rs b/lupos/tests/heap_allocation.rs new file mode 100644 index 0000000..3782fe8 --- /dev/null +++ b/lupos/tests/heap_allocation.rs @@ -0,0 +1,70 @@ +#![no_std] +#![no_main] +#![feature(custom_test_frameworks)] +#![test_runner(lupos::test_runner)] +#![reexport_test_harness_main = "test_main"] + +extern crate alloc; + +use alloc::{boxed::Box, vec::Vec}; +use lupos::allocator::HEAP_SIZE; +use bootloader::{entry_point, BootInfo}; +use core::panic::PanicInfo; + +entry_point!(main); + +fn main(boot_info: &'static BootInfo) -> ! { + use lupos::allocator; + use lupos::memory::{self, BootInfoFrameAllocator}; + use x86_64::VirtAddr; + + lupos::init(); + let phys_mem_offset = VirtAddr::new(boot_info.physical_memory_offset); + let mut mapper = unsafe { memory::init(phys_mem_offset) }; + let mut frame_allocator = unsafe { BootInfoFrameAllocator::init(&boot_info.memory_map) }; + allocator::init_heap(&mut mapper, &mut frame_allocator).expect("heap initialization failed"); + + test_main(); + loop {} +} + +#[test_case] +fn simple_allocation() { + let heap_value_1 = Box::new(41); + let heap_value_2 = Box::new(13); + assert_eq!(*heap_value_1, 41); + assert_eq!(*heap_value_2, 13); +} + +#[test_case] +fn large_vec() { + let n = 1000; + let mut vec = Vec::new(); + for i in 0..n { + vec.push(i); + } + assert_eq!(vec.iter().sum::(), (n - 1) * n / 2); +} + +#[test_case] +fn many_boxes() { + for i in 0..HEAP_SIZE { + let x = Box::new(i); + assert_eq!(*x, i); + } +} + +#[panic_handler] +fn panic(info: &PanicInfo) -> ! { + lupos::test_panic_handler(info) +} + +#[test_case] +fn many_boxes_long_lived() { + let long_lived = Box::new(1); // new + for i in 0..HEAP_SIZE { + let x = Box::new(i); + assert_eq!(*x, i); + } + assert_eq!(*long_lived, 1); // new +} \ No newline at end of file diff --git a/lupos/tests/should_panic.rs b/lupos/tests/should_panic.rs new file mode 100644 index 0000000..da2bc3a --- /dev/null +++ b/lupos/tests/should_panic.rs @@ -0,0 +1,29 @@ +#![no_std] +#![no_main] +#![feature(custom_test_frameworks)] +#![test_runner(test_runner)] +#![reexport_test_harness_main = "test_main"] + +use core::panic::PanicInfo; +use lupos::{QemuExitCode, exit_qemu, serial_println}; +use lupos::serial_print; + +#[no_mangle] +pub extern "C" fn _start() -> ! { + should_fail(); + serial_println!("[test did not panic]"); + exit_qemu(QemuExitCode::Failed); + loop{} +} + +fn should_fail() { + serial_print!("should_panic::should_fail...\t"); + assert_eq!(0, 1); +} + +#[panic_handler] +fn panic(_info: &PanicInfo) -> ! { + serial_println!("[ok]"); + exit_qemu(QemuExitCode::Success); + loop {} +} \ No newline at end of file diff --git a/lupos/tests/stack_overflow.rs b/lupos/tests/stack_overflow.rs new file mode 100644 index 0000000..f128264 --- /dev/null +++ b/lupos/tests/stack_overflow.rs @@ -0,0 +1,63 @@ +#![no_std] +#![no_main] +#![feature(abi_x86_interrupt)] + +use core::panic::PanicInfo; + +use lupos::serial_print; + +#[no_mangle] +pub extern "C" fn _start() -> ! { + serial_print!("stack_overflow::stack_overflow...\t"); + + lupos::gdt::init(); + init_test_idt(); + + // trigger a stack overflow + stack_overflow(); + + panic!("Execution continued after stack overflow"); +} + +#[allow(unconditional_recursion)] +fn stack_overflow() { + stack_overflow(); // for each recursion, the return address is pushed + volatile::Volatile::new(0).read(); // prevent tail recursion optimizations +} + +#[panic_handler] +fn panic(info: &PanicInfo) -> ! { + lupos::test_panic_handler(info) +} + +use lazy_static::lazy_static; +use x86_64::structures::idt::InterruptDescriptorTable; + +lazy_static! { + static ref TEST_IDT: InterruptDescriptorTable = { + let mut idt = InterruptDescriptorTable::new(); + unsafe { + idt.double_fault + .set_handler_fn(test_double_fault_handler) + .set_stack_index(lupos::gdt::DOUBLE_FAULT_IST_INDEX); + } + + idt + }; +} + +pub fn init_test_idt() { + TEST_IDT.load(); +} + +use lupos::{exit_qemu, QemuExitCode, serial_println}; +use x86_64::structures::idt::InterruptStackFrame; + +extern "x86-interrupt" fn test_double_fault_handler( + _stack_frame: InterruptStackFrame, + _error_code: u64, +) -> ! { + serial_println!("[ok]"); + exit_qemu(QemuExitCode::Success); + loop {} +} \ No newline at end of file