test framework layout

master
able 2022-08-05 06:22:23 -05:00
parent 558b98a1d8
commit 291be7b10d
11 changed files with 183 additions and 36 deletions

View File

@ -24,7 +24,9 @@ run-args = [
"pcspk",
"-device",
"VGA",
# "-device", "virtio-gpu-pci",
"-device",
"virtio-gpu-pci",
# "-machine", "pcspk-audiodev=0",
@ -49,7 +51,6 @@ test-args = [
lazy_static = { version = "1.4.0", features = ["spin_no_std"] }
qrcode = { path = "../qrcode-rust" }
bitflags = "1.2.1"
linked_list_allocator = "0.9.0"
lliw = "0.2.0"
spin = "0.9"
pretty-hex = "0.2.1"
@ -63,6 +64,9 @@ versioning = { git = "https://git.ablecorp.us/able/aos_userland" }
pc-keyboard = "0.5"
# mini-backtrace = "0.1"
[dependencies.linked_list_allocator]
version = "0.9.0"
features = ["use_spin_nightly"]
[dependencies.log]
version = "0.4.17"
default-features = false

View File

@ -6,8 +6,7 @@ user_processes = ["shell"]
enabled = true
level = "Trace"
log_to_serial = true
filter = ["ableos::ps2_mouse"]
# "ableos::vterm"]
filter = ["ableos::ps2_mouse", "ableos::vterm"]
[tests]

View File

@ -1,6 +1,12 @@
/*
* Copyright (c) 2022, able <abl3theabove@gmail.com>
*
* SPDX-License-Identifier: MPL-2.0
*/
use core::panic::PanicInfo;
use crate::{arch::gdt, print, println, rhai_shell::KEYBUFF};
use crate::{arch::gdt, println, rhai_shell::KEYBUFF};
use cpuio::outb;
use pic8259::ChainedPics;
use qrcode::QrCode;

View File

@ -49,7 +49,7 @@ impl Display for PciDeviceInfo {
let vendor_name = name_for_vendor_id(self.vendor_id);
writeln!(
f,
"Device {:X} | Bus {:X} | Vendor: {}",
"Device {} | Bus {:X} | Vendor: {}",
self.device, self.bus, vendor_name
)?;
writeln!(
@ -88,11 +88,18 @@ impl Display for PciDeviceInfo {
/// Converts a u16 vendor id into a human-readable name.
pub fn name_for_vendor_id(vendor_id: u16) -> String {
match vendor_id {
0x8086 => "Intel Corp. (0x8086)".into(),
0x1234 => "QEMU (0x1234)".into(),
_ => format!("Unknown({:#06X})", vendor_id),
}
let mut ret = match vendor_id {
0x1234 => "\0PINK\0QEMU (0x1234)".into(),
0x1AF4 => "\0PINK\0VirtIO (0x1AF4)".into(),
0x5333 => "\0YELLOW\0S3 Incorporated (0x5333)".into(),
0x8086 => "\0BLUE\0Intel Corp. (0x8086)".into(),
_ => format!("\0BROWN\0Unknown({:#06X})", vendor_id),
};
// trace!("{}", ret);
ret.push_str("\0RESET\0");
ret
}
/// Brute force scans for devices 0-31 on buses 0-255.

View File

@ -1,3 +1,9 @@
/*
* Copyright (c) 2022, Able <able@ablecorp.us>
*
* SPDX-License-Identifier: MPL-2.0
*/
//! main library for the AbleOS kernel.
//! exposing all the kernel functionality to the rest of the kernel.
//!
@ -11,6 +17,9 @@
naked_functions,
prelude_import,
)]
#![feature(custom_test_frameworks)]
#![test_runner(crate::test_runner)]
#![reexport_test_harness_main = "test_main"]
#[macro_use]
pub extern crate log;
@ -74,8 +83,8 @@ pub mod ipc;
pub mod panic;
mod unicode_utils;
pub mod vga_e;
// pub mod vgai;
pub mod vterm;
// pub mod vgai;
#[prelude_import]
pub use prelude::rust_2021::*;
@ -94,3 +103,12 @@ pub use scratchpad::*;
pub use utils::*;
pub use virtio::*;
pub use wasm::*;
#[cfg(test)]
pub mod tests;
#[cfg(test)]
pub use tests::test_kernel_main;
#[cfg(test)]
use crate::tests::test_runner;

View File

@ -1,3 +1,9 @@
/*
* Copyright (c) 2022, Able <able@ablecorp.us>
*
* SPDX-License-Identifier: MPL-2.0
*/
use crate::{kmain::KERNEL_CONF, time::fetch_time};
use lliw::Fg;
use log::{Level, LevelFilter, Metadata, Record, SetLoggerError};
@ -18,22 +24,13 @@ impl log::Log for SimpleLogger {
use Fg::*;
let color = match record.level() {
log::Level::Error => (Fg::Red, "$RED$"),
log::Level::Warn => (Fg::LightYellow, "$LIGHTYELLOW$"),
log::Level::Info => (Fg::LightWhite, "$LIGHTGRAY$"),
log::Level::Debug => (Fg::Blue, "$BLUE$"),
log::Level::Trace => (Fg::Yellow, "$YELLOW$"),
log::Level::Error => (Fg::Red, "\0RED\0"),
log::Level::Warn => (Fg::LightYellow, "\0LIGHTYELLOW\0"),
log::Level::Info => (Fg::LightWhite, "\0LIGHTGREY\0"),
log::Level::Debug => (Fg::Blue, "\0BLUE\0"),
log::Level::Trace => (Fg::Yellow, "\0YELLOW\0"),
};
/*
let msg = format!(
"[{}{}$RESET$][$GREEN${}$RESET$]{}\n",
color.1,
record.level(),
time_float,
record.args()
);
*/
let mod_path = match record.module_path() {
Some(p) => {
if KERNEL_CONF.logging.filter.contains(&p.to_string()) {
@ -50,16 +47,29 @@ impl log::Log for SimpleLogger {
None => 0,
};
let msg = format!(
// "[{}{}$RESET$][$GREEN${}$RESET$]{}\n",
"[{}{:05}\0RESET\0][\0GREEN\0{}\0RESET\0][\0BLUE\0{}@{}\0RESET\0] {}",
color.1,
record.level(),
time_float,
mod_path,
line,
record.args(),
);
println!("{msg}");
if KERNEL_CONF.logging.log_to_serial {
serial_println!(
"[{}{:05}{}][{}{}{}][{}{}@{}{}] {}",
color.0,
record.level(),
Fg::Reset,
Fg::Green,
Reset,
Green,
time_float,
Reset,
Fg::Blue,
Blue,
mod_path,
line,
Reset,

View File

@ -1,8 +1,14 @@
/*
* Copyright (c) 2022, able <abl3theabove@gmail.com>
*
* SPDX-License-Identifier: MPL-2.0
*/
use core::panic::PanicInfo;
use log::error;
use crate::arch::interrupts::{bsod, BSODSource};
#[cfg(not(test))]
#[panic_handler]
fn panic_handler(info: &PanicInfo) -> ! {
error!("{:?}", info);

View File

@ -1,5 +1,12 @@
/*
* Copyright (c) 2022, Able <able@ablecorp.us>
*
* SPDX-License-Identifier: MPL-2.0
*/
use crate::arch::drivers::sysinfo::master;
use crate::arch::interrupts::{reset_pit_for_cpu, set_pit_2};
use crate::devices::pci::brute_force_scan;
use crate::image::mono_bitmap::bruh;
use crate::systeminfo::{KERNEL_VERSION, RELEASE_TYPE};
use crate::time::fetch_time;
@ -64,13 +71,14 @@ pub fn scratchpad() {
// bruh();
// panic!(":>");
println!("\0RED\0OHNO\0RESET\0");
// for c in 0..144_697 {
// trace!("{:?}", char::from_u32(c));
// }
// bruh();
for x in brute_force_scan() {
println!("{}", x);
}
disable();
let tick_time = fetch_time();

70
ableos/src/tests/mod.rs Normal file
View File

@ -0,0 +1,70 @@
/*
* Copyright (c) 2022, able <abl3theabove@gmail.com>
*
* SPDX-License-Identifier: MPL-2.0
*/
use core::panic::PanicInfo;
use kernel::arch::arch::sloop;
pub trait Testable {
fn run(&self) -> ();
}
impl<T> Testable for T
where
T: Fn(),
{
fn run(&self) {
serial_print!("{}...\t", core::any::type_name::<T>());
self();
serial_println!("[ok]");
}
}
pub fn test_runner(tests: &[&dyn Testable]) {
serial_println!("Running {} tests", tests.len());
for test in tests {
test.run();
}
exit_qemu(QemuExitCode::Success);
}
pub fn test_panic_handler(info: &PanicInfo) -> ! {
serial_println!("[failed]\n");
serial_println!("Error: {}\n", info);
exit_qemu(QemuExitCode::Failed);
}
#[panic_handler]
fn panic(info: &PanicInfo) -> ! {
test_panic_handler(info);
}
#[derive(Debug, Clone, Copy, PartialEq, Eq)]
#[repr(u32)]
pub enum QemuExitCode {
Success = 0x10,
Failed = 0x11,
}
pub fn exit_qemu(exit_code: QemuExitCode) -> ! {
use x86_64::instructions::port::Port;
unsafe {
let mut port = Port::new(0xf4);
port.write(exit_code as u32);
}
loop {}
}
entry_point!(test_kernel_main);
/// Entry point for `cargo test`
pub fn test_kernel_main(boot_info: &'static BootInfo) -> ! {
// init(boot_info.physical_memory_offset);
test_main();
loop {}
}
use bootloader::{entry_point, BootInfo};
// use crate::test_main;

View File

@ -1,3 +1,9 @@
/*
* Copyright (c) 2022, able <abl3theabove@gmail.com>
*
* SPDX-License-Identifier: MPL-2.0
*/
use crate::{
kmain::KERNEL_CONF,
network::socket::{SimpleSock, Socket, SocketReturns},

View File

@ -1,8 +1,9 @@
/*
* Copyright (c) 2022, Umut İnan Erdoğan <umutinanerdogan@pm.me>
*
* SPDX-License-Identifier: MPL-2.0
*/
* Copyright (c) 2022, Umut İnan Erdoğan <umutinanerdogan@pm.me>
* Copyright (c) 2022, able <abl3theabove@gmail.com>
*
* SPDX-License-Identifier: MPL-2.0
*/
use std::{fs, process::Command};
@ -18,6 +19,8 @@ enum Subcommand {
Help,
Run,
Empty,
/// Run all tests for all architectures
Test,
Unknown(String),
}
@ -27,6 +30,7 @@ impl Subcommand {
"doc" => Subcommand::Doc,
"help" => Subcommand::Help,
"run" => Subcommand::Run,
"test" => Subcommand::Test,
"" => Subcommand::Empty,
unknown => Subcommand::Unknown(unknown.to_string()),
}
@ -44,6 +48,15 @@ fn main() {
let options = options();
match options.subcommand {
Subcommand::Test => {
Command::new("cargo")
.args(["test", "--target=json_targets/x86_64-ableos.json"])
.current_dir(fs::canonicalize("./ableos").unwrap())
.status()
.unwrap();
// panic!("Test Infrastructure missing");
}
Subcommand::Doc => {
let machine_text = options
.arguments