From 3c0abadfd05ccf7ed407c5fa8ad2fcf8b69fafcc Mon Sep 17 00:00:00 2001 From: Jeremy Soller Date: Mon, 14 Nov 2016 11:04:31 -0700 Subject: [PATCH] Implement more test arch features --- Makefile | 33 +++++++++++++++++++++++++++++- arch/test/src/interrupt.rs | 6 ++++++ arch/test/src/lib.rs | 3 +++ arch/test/src/time.rs | 7 +++++++ kernel/lib.rs | 1 - kernel/scheme/initfs.rs | 7 +++++++ kernel/syscall/process.rs | 41 +++++++++++++++++++------------------- 7 files changed, 75 insertions(+), 23 deletions(-) create mode 100644 arch/test/src/time.rs diff --git a/Makefile b/Makefile index 3263c47..81ef017 100644 --- a/Makefile +++ b/Makefile @@ -19,7 +19,7 @@ CARGO=RUSTC="$(RUSTC)" RUSTDOC="$(RUSTDOC)" cargo CARGOFLAGS=--target $(TARGET).json --release -- --cfg redox # Default targets -.PHONY: all clean doc ref update qemu bochs drivers schemes coreutils extrautils netutils userutils wireshark FORCE +.PHONY: all clean doc ref test update qemu bochs drivers schemes coreutils extrautils netutils userutils wireshark FORCE all: $(KBUILD)/harddrive.bin @@ -78,6 +78,37 @@ ref: FORCE cargo run --manifest-path crates/docgen/Cargo.toml -- programs/extrautils/src/bin/ filesystem/ref/ cargo run --manifest-path crates/docgen/Cargo.toml -- programs/netutils/src/ filesystem/ref/ +test: + cargo test + cargo test --manifest-path libstd/Cargo.toml + cargo test --manifest-path libstd_real/Cargo.toml + cargo test --manifest-path drivers/ahcid/Cargo.toml + cargo test --manifest-path drivers/e1000d/Cargo.toml + cargo test --manifest-path drivers/ps2d/Cargo.toml + cargo test --manifest-path drivers/pcid/Cargo.toml + cargo test --manifest-path drivers/rtl8168d/Cargo.toml + cargo test --manifest-path drivers/vesad/Cargo.toml + cargo test --manifest-path programs/acid/Cargo.toml + cargo test --manifest-path programs/init/Cargo.toml + cargo test --manifest-path programs/ion/Cargo.toml + cargo test --manifest-path programs/coreutils/Cargo.toml + cargo test --manifest-path programs/extrautils/Cargo.toml + cargo test --manifest-path programs/netutils/Cargo.toml + cargo test --manifest-path programs/orbutils/Cargo.toml + cargo test --manifest-path programs/pkgutils/Cargo.toml + cargo test --manifest-path programs/userutils/Cargo.toml + cargo test --manifest-path programs/smith/Cargo.toml + cargo test --manifest-path programs/tar/Cargo.toml + cargo test --manifest-path schemes/ethernetd/Cargo.toml + cargo test --manifest-path schemes/example/Cargo.toml + cargo test --manifest-path schemes/ipd/Cargo.toml + cargo test --manifest-path schemes/orbital/Cargo.toml + cargo test --manifest-path schemes/ptyd/Cargo.toml + cargo test --manifest-path schemes/randd/Cargo.toml + cargo test --manifest-path schemes/redoxfs/Cargo.toml + cargo test --manifest-path schemes/tcpd/Cargo.toml + cargo test --manifest-path schemes/udpd/Cargo.toml + update: cargo update cargo update --manifest-path libstd/Cargo.toml diff --git a/arch/test/src/interrupt.rs b/arch/test/src/interrupt.rs index df9d367..9e49020 100644 --- a/arch/test/src/interrupt.rs +++ b/arch/test/src/interrupt.rs @@ -23,6 +23,12 @@ pub unsafe fn halt() { ::std::thread::yield_now(); } +/// Pause instruction +#[inline(always)] +pub unsafe fn pause() { + +} + /// Set interrupts and nop #[inline(always)] pub unsafe fn enable_and_nop() { diff --git a/arch/test/src/lib.rs b/arch/test/src/lib.rs index f9d3660..8a155cd 100644 --- a/arch/test/src/lib.rs +++ b/arch/test/src/lib.rs @@ -38,3 +38,6 @@ pub mod interrupt; /// Initialization and main function pub mod main; + +/// Time functions +pub mod time; diff --git a/arch/test/src/time.rs b/arch/test/src/time.rs new file mode 100644 index 0000000..6f7889d --- /dev/null +++ b/arch/test/src/time.rs @@ -0,0 +1,7 @@ +pub fn monotonic() -> (u64, u64) { + (0, 0) +} + +pub fn realtime() -> (u64, u64) { + (0, 0) +} diff --git a/kernel/lib.rs b/kernel/lib.rs index 5a90e4e..b1daafc 100644 --- a/kernel/lib.rs +++ b/kernel/lib.rs @@ -48,7 +48,6 @@ use core::sync::atomic::{AtomicUsize, ATOMIC_USIZE_INIT, Ordering}; pub mod context; /// ELF file parsing -#[cfg(all(not(test), target_arch = "x86_64"))] pub mod elf; /// Schemes, filesystem handlers diff --git a/kernel/scheme/initfs.rs b/kernel/scheme/initfs.rs index 99f1f7d..4857426 100644 --- a/kernel/scheme/initfs.rs +++ b/kernel/scheme/initfs.rs @@ -8,6 +8,13 @@ use syscall::error::*; use syscall::flag::{MODE_DIR, MODE_FILE, SEEK_SET, SEEK_CUR, SEEK_END}; use syscall::scheme::Scheme; +#[cfg(test)] +mod gen { + use collections::BTreeMap; + pub fn gen() -> BTreeMap<&'static [u8], (&'static [u8], bool)> { BTreeMap::new() } +} + +#[cfg(not(test))] #[path="../../build/userspace/initfs.rs"] mod gen; diff --git a/kernel/syscall/process.rs b/kernel/syscall/process.rs index 87053af..ba623a4 100644 --- a/kernel/syscall/process.rs +++ b/kernel/syscall/process.rs @@ -2,12 +2,11 @@ use alloc::arc::Arc; use alloc::boxed::Box; use collections::{BTreeMap, Vec}; -use core::{mem, str}; +use core::{intrinsics, mem, str}; use core::ops::DerefMut; use spin::Mutex; use arch; -use arch::externs::memcpy; use arch::memory::{allocate_frame, allocate_frames, deallocate_frames, Frame}; use arch::paging::{ActivePageTable, InactivePageTable, Page, PhysicalAddress, VirtualAddress, entry}; use arch::paging::temporary_page::TemporaryPage; @@ -136,9 +135,9 @@ pub fn clone(flags: usize, stack_base: usize) -> Result { ); unsafe { - arch::externs::memcpy(new_memory.start_address().get() as *mut u8, - memory.start_address().get() as *const u8, - memory.size()); + intrinsics::copy(memory.start_address().get() as *const u8, + new_memory.start_address().get() as *mut u8, + memory.size()); } new_memory.remap(memory.flags(), true); @@ -157,9 +156,9 @@ pub fn clone(flags: usize, stack_base: usize) -> Result { ); unsafe { - arch::externs::memcpy(new_heap.start_address().get() as *mut u8, - heap.start_address().get() as *const u8, - heap.size()); + intrinsics::copy(heap.start_address().get() as *const u8, + new_heap.start_address().get() as *mut u8, + heap.size()); } new_heap.remap(heap.flags(), true); @@ -178,9 +177,9 @@ pub fn clone(flags: usize, stack_base: usize) -> Result { ); unsafe { - arch::externs::memcpy(new_stack.start_address().get() as *mut u8, - stack.start_address().get() as *const u8, - stack.size()); + intrinsics::copy(stack.start_address().get() as *const u8, + new_stack.start_address().get() as *mut u8, + stack.size()); } new_stack.remap(stack.flags(), true); @@ -201,9 +200,9 @@ pub fn clone(flags: usize, stack_base: usize) -> Result { }; unsafe { - arch::externs::memcpy(new_tls.mem.start_address().get() as *mut u8, - tls.master.get() as *const u8, - tls.file_size); + intrinsics::copy(tls.master.get() as *const u8, + new_tls.mem.start_address().get() as *mut u8, + tls.file_size); } new_tls.mem.remap(tls.mem.flags(), true); @@ -533,9 +532,9 @@ pub fn exec(path: &[u8], arg_ptrs: &[[usize; 2]]) -> Result { unsafe { // Copy file data - memcpy(segment.p_vaddr as *mut u8, - (elf.data.as_ptr() as usize + segment.p_offset as usize) as *const u8, - segment.p_filesz as usize); + intrinsics::copy((elf.data.as_ptr() as usize + segment.p_offset as usize) as *const u8, + segment.p_vaddr as *mut u8, + segment.p_filesz as usize); } let mut flags = entry::NO_EXECUTE | entry::USER_ACCESSIBLE; @@ -609,8 +608,8 @@ pub fn exec(path: &[u8], arg_ptrs: &[[usize; 2]]) -> Result { unsafe { // Copy file data - memcpy(tls.mem.start_address().get() as *mut u8, - master.get() as *const u8, + intrinsics::copy(master.get() as *const u8, + tls.mem.start_address().get() as *mut u8, file_size); } @@ -643,8 +642,8 @@ pub fn exec(path: &[u8], arg_ptrs: &[[usize; 2]]) -> Result { let mut arg_offset = 0; for arg in args.iter().rev() { unsafe { - memcpy((arch::USER_ARG_OFFSET + arg_offset) as *mut u8, - arg.as_ptr(), + intrinsics::copy(arg.as_ptr(), + (arch::USER_ARG_OFFSET + arg_offset) as *mut u8, arg.len()); }