diff --git a/.github/workflows/test.yml b/.github/workflows/test.yml index 9a10482..07bfd48 100644 --- a/.github/workflows/test.yml +++ b/.github/workflows/test.yml @@ -36,7 +36,8 @@ jobs: - name: Run app tests run: | make disk_img - make pre_libc && make test ARCH=${{ matrix.arch }} + make pre_libc + make test ARCH=${{ matrix.arch }} app-test-for-monolithic: runs-on: ${{ matrix.os }} @@ -66,4 +67,35 @@ jobs: - name: Run app tests run: | make disk_img - make test_monolithic ARCH=${{ matrix.arch }} \ No newline at end of file + make test_monolithic ARCH=${{ matrix.arch }} + app-test-for-ext4fs: + runs-on: ${{ matrix.os }} + strategy: + fail-fast: false + matrix: + os: [ubuntu-latest] + arch: [x86_64, riscv64, aarch64] + steps: + - uses: actions/checkout@v3 + - uses: actions-rs/toolchain@v1 + with: + profile: minimal + toolchain: ${{ env.rust-toolchain }} + components: rust-src + - uses: actions-rs/install@v0.1 + with: + crate: cargo-binutils + version: latest + use-tool-cache: true + - uses: ./.github/workflows/actions/setup-qemu + with: + qemu-version: ${{ env.qemu-version }} + - uses: ./.github/workflows/actions/setup-musl + with: + arch: ${{ matrix.arch }} + - name: Run app tests + run: | + sh ./build_img.sh -m ${{ matrix.arch }} -fs ext4 + make pre_libc + export MONOLITHIC_TESTCASE=other + make A=apps/monolithic_userboot APP_FEATURES=batch FEATURES="ext4fs" LOG=off run \ No newline at end of file diff --git a/Cargo.lock b/Cargo.lock index 6d72d17..704d40c 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -896,7 +896,7 @@ source = "git+https://github.com/Starry-OS/linked_list.git#3238ef86e8b27bfe13634 [[package]] name = "linux_syscall_api" version = "0.1.0" -source = "git+https://github.com/Starry-OS/linux_syscall_api.git#dbebb22c6703fa64cd7fa0f0dbb701747261b013" +source = "git+https://github.com/Starry-OS/linux_syscall_api.git#c5fa130381d6b3d9cb40b6351253ae237759179d" dependencies = [ "axconfig", "axerrno", diff --git a/README.md b/README.md index 0a0477c..05318cf 100644 --- a/README.md +++ b/README.md @@ -52,7 +52,6 @@ $ cargo install kbuild $ mkdir crates # Load crates - $ kbuild patch add linux_syscall_api $ kbuild patch add axstarry @@ -66,4 +65,10 @@ $ kbuild patch remove axstarry # Please verify that crates don't have any uncommitted changes before removing them. -``` \ No newline at end of file +``` + +## Notes + +- Please remove unnecessary dependencies in `Cargo.toml` before your commit. +- After pulling a new crate to the local workspace, maybe you need to execute `make clean` to update the cache. + diff --git a/apps/monolithic_userboot/src/batch.rs b/apps/monolithic_userboot/src/batch.rs index c50e030..1e6a39e 100644 --- a/apps/monolithic_userboot/src/batch.rs +++ b/apps/monolithic_userboot/src/batch.rs @@ -3,69 +3,83 @@ extern crate alloc; use alloc::boxed::Box; #[allow(dead_code)] -pub const SDCARD_TESTCASES: &[&str] = &[ - // "./runtest.exe -w entry-static.exe socket", - // "busybox du", - // "./MediaServer -h", - // "busybox sh ./test_all.sh", - // "./riscv64-linux-musl-native/bin/riscv64-linux-musl-gcc ./hello.c -static", - // "./a.out", - // "./time-test", - // "./interrupts-test-1", - // "./interrupts-test-2", - // "./copy-file-range-test-1", - // "./copy-file-range-test-2", - // "./copy-file-range-test-3", - // "./copy-file-range-test-4", - // "busybox echo hello", - // "busybox sh ./unixbench_testcode.sh", - // "busybox echo hello", - // "busybox sh ./iperf_testcode.sh", - // "busybox echo hello", - // "busybox sh busybox_testcode.sh", - // "busybox echo hello", - // "busybox sh ./iozone_testcode.sh", - // "busybox echo latency measurements", - // "lmbench_all lat_syscall -P 1 null", - // "lmbench_all lat_syscall -P 1 read", - // "lmbench_all lat_syscall -P 1 write", - // "busybox mkdir -p /var/tmp", - // "busybox touch /var/tmp/lmbench", - // "lmbench_all lat_syscall -P 1 stat /var/tmp/lmbench", - // "lmbench_all lat_syscall -P 1 fstat /var/tmp/lmbench", - // "lmbench_all lat_syscall -P 1 open /var/tmp/lmbench", - // "lmbench_all lat_select -n 100 -P 1 file", - // "lmbench_all lat_sig -P 1 install", - // "lmbench_all lat_sig -P 1 catch", - // "lmbench_all lat_sig -P 1 prot lat_sig", - // "lmbench_all lat_pipe -P 1", - // "lmbench_all lat_proc -P 1 fork", - // "lmbench_all lat_proc -P 1 exec", - // "busybox cp hello /tmp", - // "lmbench_all lat_proc -P 1 shell", - // "lmbench_all lmdd label=\"File /var/tmp/XXX write bandwidth:\" of=/var/tmp/XXX move=1m fsync=1 print=3", - // "lmbench_all lat_pagefault -P 1 /var/tmp/XXX", - // "lmbench_all lat_mmap -P 1 512k /var/tmp/XXX", - // "busybox echo file system latency", - // "lmbench_all lat_fs /var/tmp", - // "busybox echo Bandwidth measurements", - // "lmbench_all bw_pipe -P 1", - // "lmbench_all bw_file_rd -P 1 512k io_only /var/tmp/XXX", - // "lmbench_all bw_file_rd -P 1 512k open2close /var/tmp/XXX", - // "lmbench_all bw_mmap_rd -P 1 512k mmap_only /var/tmp/XXX", - // "lmbench_all bw_mmap_rd -P 1 512k open2close /var/tmp/XXX", - // "busybox echo context switch overhead", - // "lmbench_all lat_ctx -P 1 -s 32 2 4 8 16 24 32 64 96", - "busybox sh libctest_testcode.sh", - // "busybox sh lua_testcode.sh", - // "libc-bench", - // "busybox sh ./netperf_testcode.sh", - // "busybox sh ./cyclictest_testcode.sh", +const BUSYBOX_TESTCASES: &[&str] = &[ + "busybox sh busybox_testcode.sh", + "busybox sh lua_testcode.sh", ]; +#[allow(dead_code)] +const LIBC_TESTCASES: &[&str] = &["libctest_testcode.sh", "libc-bench"]; + +#[allow(dead_code)] +const NET_TESTCASES: &[&str] = &[ + "busybox sh netperf_testcode.sh", + "busybox sh iperf_testcode.sh", +]; + +#[allow(dead_code)] +const LMBENCH_TESTCASES: &[&str] = &[ + "busybox echo latency measurements", + "lmbench_all lat_syscall -P 1 null", + "lmbench_all lat_syscall -P 1 read", + "lmbench_all lat_syscall -P 1 write", + "busybox mkdir -p /var/tmp", + "busybox touch /var/tmp/lmbench", + "lmbench_all lat_syscall -P 1 stat /var/tmp/lmbench", + "lmbench_all lat_syscall -P 1 fstat /var/tmp/lmbench", + "lmbench_all lat_syscall -P 1 open /var/tmp/lmbench", + "lmbench_all lat_select -n 100 -P 1 file", + "lmbench_all lat_sig -P 1 install", + "lmbench_all lat_sig -P 1 catch", + "lmbench_all lat_sig -P 1 prot lat_sig", + "lmbench_all lat_pipe -P 1", + "lmbench_all lat_proc -P 1 fork", + "lmbench_all lat_proc -P 1 exec", + "busybox cp hello /tmp", + "lmbench_all lat_proc -P 1 shell", + "lmbench_all lmdd label=\"File /var/tmp/XXX write bandwidth:\" of=/var/tmp/XXX move=1m fsync=1 print=3", + "lmbench_all lat_pagefault -P 1 /var/tmp/XXX", + "lmbench_all lat_mmap -P 1 512k /var/tmp/XXX", + "busybox echo file system latency", + "lmbench_all lat_fs /var/tmp", + "busybox echo Bandwidth measurements", + "lmbench_all bw_pipe -P 1", + "lmbench_all bw_file_rd -P 1 512k io_only /var/tmp/XXX", + "lmbench_all bw_file_rd -P 1 512k open2close /var/tmp/XXX", + "lmbench_all bw_mmap_rd -P 1 512k mmap_only /var/tmp/XXX", + "lmbench_all bw_mmap_rd -P 1 512k open2close /var/tmp/XXX", + "busybox echo context switch overhead", + "lmbench_all lat_ctx -P 1 -s 32 2 4 8 16 24 32 64 96", +]; + +#[allow(dead_code)] +const IOZONE_TESTCASES: &[&str] = &["busybox sh ./iozone_testcode.sh"]; + +/// FIXME: This test case is not working +#[allow(dead_code)] +const UNIX_TESTCASES: &[&str] = &["busybox sh ./unixbench_testcode.sh"]; + +#[allow(dead_code)] +const CYCLE_TESTCASES: &[&str] = &["busybox sh ./cyclictest_testcode.sh"]; + +#[allow(dead_code)] +const OTHER_TESTCASES: &[&str] = &["./time-test"]; + #[allow(unused)] pub fn run_batch_testcases() { - let mut test_iter = Box::new(SDCARD_TESTCASES.iter()); + let testcase_str = option_env!("MONOLITHIC_TESTCASE").unwrap_or(""); + let mut test_iter = match testcase_str { + "busybox" => Box::new(BUSYBOX_TESTCASES.iter()), + "libc" => Box::new(LIBC_TESTCASES.iter()), + "net" => Box::new(NET_TESTCASES.iter()), + "lmbench" => Box::new(LMBENCH_TESTCASES.iter()), + "iozone" => Box::new(IOZONE_TESTCASES.iter()), + "unixbench" => Box::new(UNIX_TESTCASES.iter()), + "cycle" => Box::new(CYCLE_TESTCASES.iter()), + "other" => Box::new(OTHER_TESTCASES.iter()), + _ => Box::new(LIBC_TESTCASES.iter()), + }; + for testcase in test_iter { axstarry::run_testcase(testcase); } diff --git a/build_img.sh b/build_img.sh index aa6cbcb..653f7ea 100755 --- a/build_img.sh +++ b/build_img.sh @@ -14,71 +14,41 @@ display_help() { echo "" echo "./build_img.sh -m [arch] -fs [filesystem] -file [testcast]" + # 若不指定参数,则使用默认的测例 + echo " -m | --arch architecture: x86_64|riscv64|aarch64" + echo " -fs | --filesystem filesystem: ext4|fat32" + echo " -file | --testcase If not specified, use the default testcases" + echo " default testcases:" + echo " x86_64: x86_64_linux_musl" + echo " riscv64: riscv64_linux_musl" + echo " aarch64: aarch64-linux-musl" + echo " -h | --help display help" echo "" exit 1 } -while [ -n "$1" ]; do +# 可能接受三类参数 -m [arch] -fs [filesystem] -file [testcast] +# 但是不一定只有一个参数,所以使用 while 循环 +while [ "$1" != "" ]; do case $1 in - -m) - shift - arch="$1" - ;; - -fs) - shift - fs="$1" - ;; - -file) - shift - FILE="$1" - ;; - riscv64) - arch=riscv64 - ;; - x86_64) - arch=x86_64 - ;; - aarch64) - arch=aarch64 - ;; - fat32) - fs=fat32 - ;; - ext4) - fs=ext4 - ;; - riscv64_linux_musl) - FILE=riscv64_linux_musl - ;; - riscv64_gcc) - FILE=riscv64_gcc - ;; - riscv64_redis) - FILE=riscv64_redis - ;; - x86_64_linux_musl) - FILE=x86_64_linux_musl - ;; - x86_64_ZLM) - FILE=x86_64_ZLM - ;; - riscv64_libctest_dynamic) - FILE=riscv64_libctest_dynamic - ;; - riscv64_libctest_static) - FILE=riscv64_libctest_static - ;; - aarch64-linux-musl) - FILE=aarch64-linux-musl - ;; - *) - display_help - ;; + -m | --arch ) shift + arch=$1 + ;; + -fs | --filesystem ) shift + fs=$1 + ;; + -file | --testcase ) shift + FILE=$1 + ;; + -h | --help ) display_help + exit + ;; + * ) display_help + exit 1 esac shift done - if [ -z "$FILE" ]; then # use default testcases if [ "$arch" = "riscv64" ]; then FILE=riscv64_linux_musl @@ -87,6 +57,7 @@ if [ -z "$FILE" ]; then # use default testcases elif [ "$arch" = "aarch64" ]; then FILE=aarch64-linux-musl else + echo "Unknown architecture: $arch" exit 1 fi fi @@ -101,9 +72,13 @@ dd if=/dev/zero of=disk.img bs=4M count=30 if [ "$fs" = "ext4" ]; then mkfs.ext4 -t ext4 disk.img -else +else if [ "$fs" = "fat32" ]; then fs=fat32 mkfs.vfat -F 32 disk.img +else + echo "Unknown filesystem: $fs" + exit 1 +fi fi mkdir -p mnt diff --git a/scripts/test/app_test_for_monolithic.sh b/scripts/test/app_test_for_monolithic.sh index dd28b72..a03b3e1 100755 --- a/scripts/test/app_test_for_monolithic.sh +++ b/scripts/test/app_test_for_monolithic.sh @@ -25,13 +25,20 @@ if [ "$ARCH" != "x86_64" ] && [ "$ARCH" != "riscv64" ] && [ "$ARCH" != "aarch64" exit $S_FAILED fi +# TODO: add iozone, unixbench, cycle, etc. +testcase_list=( + "busybox" + "libc" + "net" +) + function run_and_compare() { local args=$1 local actual=$2 echo -ne " run with \"${BLOD_C}$args${END_C}\": " # if the app contain "apps/monolithic_userboot", then make disk img - sh ./build_img.sh $ARCH + sh ./build_img.sh -m $ARCH make -C "$ROOT" A="$APP" $args > "$actual" 2>&1 if [ $? -ne 0 ]; then @@ -64,27 +71,33 @@ function test_one() { rm -f "$actual" MSG= - run_and_compare "$args" "$actual" - local res=$? + # 遍历 testcase_list,进行多次测试 + for testcase in ${testcase_list[@]}; do + # 重置 MONOLITHIC_TESTCASE + echo -e " Monolithic testcase: $testcase" + export MONOLITHIC_TESTCASE=$testcase + run_and_compare "$args" "$actual" + local res=$? - if [ $res -ne $S_PASS ]; then - EXIT_STATUS=$res - if [ $res == $S_FAILED ]; then - echo -e "${RED_C}failed!${END_C} $RUN_TIME" - elif [ $res == $S_TIMEOUT ]; then - echo -e "${YELLOW_C}timeout!${END_C} $RUN_TIME" - elif [ $res == $S_BUILD_FAILED ]; then - echo -e "${RED_C}build failed!${END_C}" - fi - if [ ! -z "$MSG" ]; then - echo -e " $MSG" + if [ $res -ne $S_PASS ]; then + EXIT_STATUS=$res + if [ $res == $S_FAILED ]; then + echo -e "${RED_C}failed!${END_C} $RUN_TIME" + elif [ $res == $S_TIMEOUT ]; then + echo -e "${YELLOW_C}timeout!${END_C} $RUN_TIME" + elif [ $res == $S_BUILD_FAILED ]; then + echo -e "${RED_C}build failed!${END_C}" + fi + if [ ! -z "$MSG" ]; then + echo -e " $MSG" + fi + echo -e "${RED_C}actual output${END_C}:" + cat "$actual" + else + echo -e "${GREEN_C}passed!${END_C} $RUN_TIME" + # rm -f "$actual" fi - echo -e "${RED_C}actual output${END_C}:" - cat "$actual" - else - echo -e "${GREEN_C}passed!${END_C} $RUN_TIME" - # rm -f "$actual" - fi + done } if [ -z "$1" ]; then