Rename eval to syscall test and fix return value

This commit is contained in:
Zhang Junyang 2023-08-01 15:36:45 +08:00 committed by Tate, Hongliang Tian
parent d2cb607e3c
commit f674874e91
7 changed files with 93 additions and 44 deletions

View File

@ -6,7 +6,7 @@ runner = "cargo run --package jinux-build --"
kcheck = "check --target x86_64-custom.json -Zbuild-std=core,alloc,compiler_builtins -Zbuild-std-features=compiler-builtins-mem" kcheck = "check --target x86_64-custom.json -Zbuild-std=core,alloc,compiler_builtins -Zbuild-std-features=compiler-builtins-mem"
kbuild = "build --target x86_64-custom.json -Zbuild-std=core,alloc,compiler_builtins -Zbuild-std-features=compiler-builtins-mem" kbuild = "build --target x86_64-custom.json -Zbuild-std=core,alloc,compiler_builtins -Zbuild-std-features=compiler-builtins-mem"
krun = "run --target x86_64-custom.json -Zbuild-std=core,alloc,compiler_builtins -Zbuild-std-features=compiler-builtins-mem" krun = "run --target x86_64-custom.json -Zbuild-std=core,alloc,compiler_builtins -Zbuild-std-features=compiler-builtins-mem"
keval = "run --target x86_64-custom.json -Zbuild-std=core,alloc,compiler_builtins -Zbuild-std-features=compiler-builtins-mem -- --eval" ksctest = "run --target x86_64-custom.json -Zbuild-std=core,alloc,compiler_builtins -Zbuild-std-features=compiler-builtins-mem -- --syscall-test"
ktest = "test --target x86_64-custom.json -Zbuild-std=core,alloc,compiler_builtins -Zbuild-std-features=compiler-builtins-mem" ktest = "test --target x86_64-custom.json -Zbuild-std=core,alloc,compiler_builtins -Zbuild-std-features=compiler-builtins-mem"
component-check = "component check --target x86_64-custom.json -Zbuild-std=core,alloc,compiler_builtins -Zbuild-std-features=compiler-builtins-mem" component-check = "component check --target x86_64-custom.json -Zbuild-std=core,alloc,compiler_builtins -Zbuild-std-features=compiler-builtins-mem"

View File

@ -1,4 +1,4 @@
.PHONY: all build clean docs fmt run setup test tools eval .PHONY: all build clean docs fmt run setup test tools syscall_test syscall_bin
all: build all: build
@ -16,11 +16,14 @@ tools:
@cd services/libs/comp-sys && cargo install --path cargo-component @cd services/libs/comp-sys && cargo install --path cargo-component
run: build run: build
@cargo krun @cargo krun || exit $$(($$? >> 1)) # FIXME: Exit code manipulation is not needed using non-x86 QEMU
syscall_bin:
@make --no-print-directory -C regression/syscall_test
# Test Jinux in a QEMU guest VM and run a series of evaluations. # Test Jinux in a QEMU guest VM and run a series of evaluations.
eval: build syscall_test: syscall_bin build
@cargo keval @cargo ksctest || exit $$(($$? >> 1)) # FIXME: Exit code manipulation is not needed using non-x86 QEMU
# The usermode cargo test of Jinux frame and Jinux standard library. # The usermode cargo test of Jinux frame and Jinux standard library.
test: build test: build

View File

@ -75,14 +75,15 @@ cargo component-check
### Syscall Test ### Syscall Test
If we have already built the project for normal use, please clean the project before running syscall test. This command will build the syscall test binary and run Jinux with it in QEMU.
```bash ```bash
make clean make syscall_test
``` ```
For running syscall tests, we can run following command to build test binaries and run the OS for testing purpose. If you wish to test it interactively inside a shell in Jinux.
```bash ```
ENABLE_SYSCALL_TEST=1 make run make syscall_bin
make run
``` ```
Then, we can run the following script inside the OS to run all syscall test cases. Then, we can run the following script inside the OS to run all syscall test cases.

View File

@ -21,7 +21,7 @@ struct Args {
// Options. // Options.
/// Automatically run integration tests and exit. /// Automatically run integration tests and exit.
#[arg(short, long, default_value_t = false)] #[arg(short, long, default_value_t = false)]
eval: bool, syscall_test: bool,
/// Emulate Intel IOMMU by QEMU. /// Emulate Intel IOMMU by QEMU.
#[arg(short, long, default_value_t = false)] #[arg(short, long, default_value_t = false)]
@ -90,7 +90,7 @@ fn main() {
qemu_args.push("-drive"); qemu_args.push("-drive");
qemu_args.push(fs_image.as_str()); qemu_args.push(fs_image.as_str());
let bootdev_image = create_bootdev_image(args.path, args.eval); let bootdev_image = create_bootdev_image(args.path, args.syscall_test);
qemu_cmd.arg("-cdrom"); qemu_cmd.arg("-cdrom");
qemu_cmd.arg(bootdev_image.as_str()); qemu_cmd.arg(bootdev_image.as_str());

View File

@ -146,11 +146,16 @@ pub fn panic_handler() {
// println!("---END BACKTRACE---"); // println!("---END BACKTRACE---");
// } // }
} }
/// The exit code of x86 QEMU. In `qemu-system-x86_64` the exit code will be
/// `(code << 1) | 1`. So you could never let QEMU invoke `exit(0)`. Check
/// if the result is `0b01` instead.
#[cfg(target_arch = "x86_64")]
#[derive(Debug, Clone, Copy, PartialEq, Eq)] #[derive(Debug, Clone, Copy, PartialEq, Eq)]
#[repr(u32)] #[repr(u32)]
pub enum QemuExitCode { pub enum QemuExitCode {
Success = 0x10, Success = 0b0,
Failed = 0x11, Failed = 0b1,
} }
pub fn exit_qemu(exit_code: QemuExitCode) -> ! { pub fn exit_qemu(exit_code: QemuExitCode) -> ! {

View File

@ -5,37 +5,73 @@ INITRAMFS := $(BUILD_DIR)/initramfs
RAMDISK := $(BUILD_DIR)/ramdisk.cpio.gz RAMDISK := $(BUILD_DIR)/ramdisk.cpio.gz
SHELL := /bin/bash SHELL := /bin/bash
ifneq (, $(wildcard $(INITRAMFS)/. ))
INITRAMFS_DIRS := $(shell find $(INITRAMFS) -type d 2>/dev/null | sed 's/ /\\ /g' | sed 's/:/\\:/g' || true)
INITRAMFS_FILES := $(shell find $(INITRAMFS) -type f 2>/dev/null | sed 's/ /\\ /g' | sed 's/:/\\:/g' || true)
endif
.PHONY: all clean .PHONY: all clean
all: build all: build
$(INITRAMFS): TARGETS=\
@rm -rf $@ && mkdir -p $@ $(INITRAMFS)/lib/x86_64-linux-gnu \
@# Mkdir necessary folders $(INITRAMFS)/lib64 \
@mkdir -p $@/bin $@/etc $@/sbin $@/usr/bin $@/root $@/tmp $@/opt $@/proc $@/dev $@/lib64 $@/lib/x86_64-linux-gnu $(INITRAMFS)/bin \
@# Install busybox $(INITRAMFS)/usr/bin \
@/bin/busybox --install -s $@/bin $(INITRAMFS)/regression \
@cp /usr/bin/busybox $@/usr/bin $(INITRAMFS)/etc \
@# Copy necessary libs $(INITRAMFS)/sbin \
@cp -L /lib64/ld-linux-x86-64.so.2 $@/lib64 $(INITRAMFS)/root \
@cp -L /lib/x86_64-linux-gnu/libc.so.6 $@/lib/x86_64-linux-gnu $(INITRAMFS)/tmp \
@cp -L /lib/x86_64-linux-gnu/libstdc++.so.6 $@/lib/x86_64-linux-gnu $(INITRAMFS)/opt \
@cp -L /lib/x86_64-linux-gnu/libm.so.6 $@/lib/x86_64-linux-gnu $(INITRAMFS)/proc \
@cp -L /lib/x86_64-linux-gnu/libgcc_s.so.1 $@/lib/x86_64-linux-gnu $(INITRAMFS)/dev
@cp -L /lib/x86_64-linux-gnu/libpthread.so.0 $@/lib/x86_64-linux-gnu
@# Copy from apps
@make --no-print-directory -C apps
ifeq ($(ENABLE_SYSCALL_TEST), 1)
@# Copy syscall test suite
@make --no-print-directory -C syscall_test
endif
$(RAMDISK): $(INITRAMFS) $(INITRAMFS_DIRS) $(INITRAMFS_FILES) # Copy necessary libs
$(INITRAMFS)/lib/x86_64-linux-gnu:
@mkdir -p $@
@cp -L /lib/x86_64-linux-gnu/libc.so.6 $@
@cp -L /lib/x86_64-linux-gnu/libstdc++.so.6 $@
@cp -L /lib/x86_64-linux-gnu/libm.so.6 $@
@cp -L /lib/x86_64-linux-gnu/libgcc_s.so.1 $@
@cp -L /lib/x86_64-linux-gnu/libpthread.so.0 $@
$(INITRAMFS)/lib64:
@mkdir -p $@
@cp -L /lib64/ld-linux-x86-64.so.2 $@
# Install busybox
$(INITRAMFS)/bin:
@mkdir -p $@
@/bin/busybox --install -s $@
$(INITRAMFS)/usr/bin: $(INITRAMFS)/bin
@mkdir -p $@
@cp /usr/bin/busybox $@
# Copy from apps
$(INITRAMFS)/regression:
@make --no-print-directory -C apps
# Make necessary directories
$(INITRAMFS)/etc:
@mkdir -p $@
$(INITRAMFS)/sbin:
@mkdir -p $@
$(INITRAMFS)/root:
@mkdir -p $@
$(INITRAMFS)/tmp:
@mkdir -p $@
$(INITRAMFS)/opt:
@mkdir -p $@
$(INITRAMFS)/proc:
@mkdir -p $@
$(INITRAMFS)/dev:
@mkdir -p $@
$(RAMDISK): $(TARGETS)
@echo "Generating the ramdisk image..." @echo "Generating the ramdisk image..."
@(cd $(INITRAMFS); find . | cpio -o -H newc | gzip) > $@ @(cd $(INITRAMFS); find . | cpio -o -H newc | gzip) > $@

View File

@ -25,8 +25,8 @@ use crate::{
process::status::ProcessStatus, process::status::ProcessStatus,
thread::{kernel_thread::KernelThreadExt, Thread}, thread::{kernel_thread::KernelThreadExt, Thread},
}; };
use alloc::sync::Arc; use core::sync::atomic::Ordering;
use jinux_frame::{boot, exit_qemu}; use jinux_frame::{boot, exit_qemu, QemuExitCode};
use process::Process; use process::Process;
extern crate alloc; extern crate alloc;
@ -89,8 +89,12 @@ fn init_thread() {
loop { loop {
// If initproc becomes zombie, then exit qemu. // If initproc becomes zombie, then exit qemu.
if *initproc.status().lock() == ProcessStatus::Zombie { if *initproc.status().lock() == ProcessStatus::Zombie {
println!("Exit jinux."); let exit_code = if initproc.exit_code().load(Ordering::Relaxed) == 0 {
exit_qemu(jinux_frame::QemuExitCode::Success); QemuExitCode::Success
} else {
QemuExitCode::Failed
};
exit_qemu(exit_code);
} }
// We don't have preemptive scheduler now. // We don't have preemptive scheduler now.
// The long running init thread should yield its own execution to allow other tasks to go on. // The long running init thread should yield its own execution to allow other tasks to go on.