Support compiling for host, allowing unit tests.

This commit is contained in:
4lDO2
2024-09-14 11:00:14 +02:00
parent a0d0eac8aa
commit ef499f81fc
3 changed files with 4 additions and 37 deletions
+3 -7
View File
@@ -49,8 +49,8 @@
#![feature(naked_functions)]
#![feature(sync_unsafe_cell)]
#![feature(variant_count)]
#![no_std]
#![no_main]
#![cfg_attr(not(test), no_std)]
#![cfg_attr(not(test), no_main)]
#[macro_use]
extern crate alloc;
@@ -147,11 +147,7 @@ mod syscall;
/// Time
mod time;
/// Tests
#[cfg(test)]
mod tests;
#[global_allocator]
#[cfg_attr(not(test), global_allocator)]
static ALLOCATOR: allocator::Allocator = allocator::Allocator;
/// Get the current CPU's scheduling ID
-29
View File
@@ -1,29 +0,0 @@
use syscall::{self, Error};
/// Test stdio
#[test]
fn stdio() {
// Test opening stdin
assert_eq!(syscall::open(b"debug:", 0), Ok(0));
// Test opening stdout
assert_eq!(syscall::open(b"debug:", 0), Ok(1));
// Test opening stderr
assert_eq!(syscall::open(b"debug:", 0), Ok(2));
// Test writing stdout
let stdout_str = b"STDOUT";
assert_eq!(syscall::write(1, stdout_str), Ok(stdout_str.len()));
// Test writing stderr
let stderr_str = b"STDERR";
assert_eq!(syscall::write(2, stderr_str), Ok(stderr_str.len()));
}
/// Test that invalid reads/writes cause errors
#[test]
fn invalid_path() {
assert_eq!(syscall::read(999, &mut []), Err(Error::new(syscall::EBADF)));
assert_eq!(syscall::write(999, &[]), Err(Error::new(syscall::EBADF)));
}
+1 -1
Submodule syscall updated: c751f76248...e4cc6bfcd5