Skip to content
This repository was archived by the owner on Nov 26, 2025. It is now read-only.

Commit 6290968

Browse files
committed
[doc] simplify the command and improved oscomp related README
1 parent 5603008 commit 6290968

5 files changed

Lines changed: 247 additions & 29 deletions

File tree

Makefile

Lines changed: 5 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
AX_ROOT ?= $(PWD)/.arceos
22
AX_TESTCASE ?= nimbos
33
ARCH ?= x86_64
4+
LOG ?= off
45
AX_TESTCASES_LIST=$(shell cat ./apps/$(AX_TESTCASE)/testcase_list | tr '\n' ',')
56
FEATURES ?= fp_simd
67

@@ -33,10 +34,9 @@ else
3334
$(error ARCH must be one of x86_64, aarch64, riscv64, loongarch64)
3435
endif
3536

36-
all:
37-
# Build for os competition
38-
RUSTUP_TOOLCHAIN=nightly-2025-01-18 $(MAKE) test_build ARCH=riscv64 AX_TESTCASE=oscomp BUS=mmio FEATURES=lwext4_rs
39-
RUSTUP_TOOLCHAIN=nightly-2025-01-18 $(MAKE) test_build ARCH=loongarch64 AX_TESTCASE=oscomp FEATURES=lwext4_rs
37+
include scripts/make/oscomp.mk
38+
39+
all: oscomp_build
4040

4141
# export dummy config for clippy
4242
clippy: defconfig
@@ -55,21 +55,9 @@ user_apps:
5555
fi
5656
@mv ./disk.img $(AX_ROOT)/disk.img
5757

58-
test:
58+
test: defconfig
5959
@./scripts/app_test.sh
6060

61-
oscomp_test:
62-
@./scripts/oscomp_test.sh
63-
64-
test_build: ax_root defconfig
65-
@cp -r $(PWD)/bin/* /root/.cargo/bin
66-
@make -C $(AX_ROOT) A=$(PWD) EXTRA_CONFIG=$(EXTRA_CONFIG) build
67-
@if [ "$(ARCH)" = "riscv64" ]; then \
68-
cp $(OUT_BIN) kernel-rv; \
69-
else \
70-
cp $(OUT_ELF) kernel-la; \
71-
fi
72-
7361
defconfig build run justrun debug disasm: ax_root
7462
@make -C $(AX_ROOT) A=$(PWD) EXTRA_CONFIG=$(EXTRA_CONFIG) $@
7563

README.md

Lines changed: 86 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -142,4 +142,89 @@ Note: Arguments like `NET`, `BLK`, and `GRAPHIC` enable devices in QEMU, which t
142142

143143
## Test for oscomp testcases
144144

145-
We can run [testcases of the OS competition](https://github.com/oscomp/testsuits-for-oskernel/tree/pre-2025) with StarryOS. Guidence can be found in [Starry-Tutorial](https://azure-stars.github.io/Starry-Tutorial-Book/ch01-04.html#在-os-比赛上测试-starry).
145+
We can run [testcases of the OS competition](https://github.com/oscomp/testsuits-for-oskernel/tree/pre-2025) with StarryOS. Guidence can be found in [Starry-Tutorial](https://azure-stars.github.io/Starry-Tutorial-Book/ch03-02.html).
146+
147+
148+
And you can run the testcases with the following commands:
149+
150+
```bash
151+
# Clone the base repository
152+
./scripts/get_deps.sh
153+
154+
# run the testcases of oscomp on x86_64
155+
$ make oscomp_run ARCH=x86_64 # If it reports an error: -accel kvm: failed to initialize kvm: Permission denied, please add `ACCEL=n` argument.
156+
157+
# run the testcases of oscomp on riscv64
158+
$ make oscomp_run ARCH=riscv64
159+
160+
# run the testcases of oscomp on aarch64
161+
$ make oscomp_run ARCH=aarch64
162+
163+
# run the testcases of oscomp on loongarch64
164+
$ make oscomp_run ARCH=loongarch64
165+
```
166+
167+
To run more testcases from oscomp, you can refer to the [oscomp README](./apps/oscomp/README.md).
168+
169+
## How to add new testcases
170+
171+
To allow the kernel to run user-written test cases, temporary test cases can be created. The specific steps are as follows:
172+
173+
1. Create a temporary test case folder
174+
175+
```sh
176+
cd apps && mkdir custom && cd custom
177+
```
178+
179+
2. Create a `Makefile` in the current directory and fill in the following content:
180+
181+
```makefile
182+
all: build
183+
184+
build:
185+
186+
clean:
187+
rm -rf *.out
188+
```
189+
190+
The reason for creating an empty build `Makefile` is that when Starry packages test case images, it will first execute the test case's build program by default. However, since our temporary test case does not currently have a defined build program, `make all` does not need to perform any operations.
191+
192+
3. Copy your compiled executable file into the current directory.
193+
194+
Let's take a `hello_world` example. Create a `hello.c` file in the current directory and write the following content:
195+
196+
```c
197+
#include "syscall.h"
198+
199+
int main()
200+
{
201+
char msg[] = "Hello, World!\n";
202+
write(1, msg, sizeof(msg));
203+
return 0;
204+
}
205+
```
206+
207+
Then, run the following command to compile it:
208+
209+
```sh
210+
x86_64-linux-musl-gcc -static hello.c -o hello
211+
```
212+
213+
This generates an x86_64 executable file in the current folder. Of course, you can also complete the compilation process elsewhere and directly copy the executable file into the current directory.
214+
215+
4. Create a `testcase_list` file in the current directory and add the relative path of the executable file that needs to be executed. Note that this path should be relative to `apps/custom` (i.e., the current directory). In our example, the content should be:
216+
217+
```sh
218+
hello
219+
```
220+
221+
5. Return to the project root directory and run the following command:
222+
223+
```sh
224+
sudo ./build_img.sh -fs ext4 -file apps/custom
225+
cp disk.img .arceos/disk.img
226+
make defconfig
227+
make AX_TESTCASE=custom EXTRA_CONFIG=../configs/x86_64.toml ARCH=x86_64 BLK=y NET=y FEATURES=fp_simd,lwext4_rs LOG=off ACCEL=n run
228+
```
229+
230+
This completes the execution of the custom test case.

apps/oscomp/README.md

Lines changed: 120 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -14,21 +14,131 @@ musl/basic/exit
1414
Then Starry will find `musl/basic/brk` from the sdcard images.And the working directory in the sdcard is default `/`.
1515

1616
## Judge scripts
17+
1718
Files like `judge_**.py` are the scripts that judge whether the output of the kernel is correct or not. The format ot the scripts can be seen at [judge](https://github.com/Azure-stars/oskernel-testsuits-cooperation/tree/master/judge).
1819

1920
When run `make oscomp_test` in the root directory, the testcases in the `testcase_list` will be run and the result will be shown in the terminal. And these scripts will be run to judge whether the output is correct or not.
2021

2122
## How to add new testcases
2223

23-
1. Enable testcases in the `judge_**.py` script. You can find `TODO` fields in the script and add the new testcases in the corresponding place. The format of the command can be seen in [judge](https://github.com/Azure-stars/oskernel-testsuits-cooperation/tree/master/judge).
24+
### Add basic testcases
25+
26+
If we want to add `write` testcase, then we need:
27+
28+
1. Enable testcases in the [judge_basic.py](./judge_basic.py)。An example is that if the `target_testcase` in [judge_basic.py](./judge_basic.py) is below:
29+
30+
```sh
31+
target_testcases = [
32+
"test_brk",
33+
"test_chdir",
34+
"test_execve",
35+
"test_pipe",
36+
]
37+
```
38+
39+
Then we need to enable `write` testcase by rewriting it as
40+
41+
```sh
42+
target_testcases = [
43+
"test_brk",
44+
"test_chdir",
45+
"test_execve",
46+
"test_pipe",
47+
"test_write",
48+
]
49+
```
50+
51+
2. Add the testcase in the [oscomp_test.sh](../../scripts/oscomp_test.sh)。An example is that if the `basic_testlist` in [oscomp_test.sh](../../scripts/oscomp_test.sh) is below:
52+
53+
```sh
54+
# TODO: add more basic testcases
55+
basic_testlist=(
56+
"/$LIBC/basic/brk"
57+
"/$LIBC/basic/chdir"
58+
"/$LIBC/basic/clone" # add the new testcase here
59+
)
60+
```
61+
62+
Then we need to enable `write` testcase by rewriting it as
63+
64+
```sh
65+
# TODO: add more basic testcases
66+
basic_testlist=(
67+
"/$LIBC/basic/brk"
68+
"/$LIBC/basic/chdir"
69+
"/$LIBC/basic/clone"
70+
"/$LIBC/basic/write"
71+
)
72+
```
73+
74+
### Add libc testcases
75+
76+
The standard of the [judge_libctest.py](./judge_libctest.py) can be seen at [judge-std](https://github.com/Azure-stars/oskernel-testsuits-cooperation/tree/master/judge/judge_libctest.py).
77+
78+
If we want to add `entry-static.exe basename` testcase, and the `libctest_baseline` in the [judge_libctest.py](./judge_libctest.py) is as below:
79+
80+
```python
81+
libctest_baseline = """
82+
========== START entry-static.exe argv ==========
83+
Pass!
84+
========== END entry-static.exe argv ==========
85+
"""
86+
```
87+
88+
Then we need to enable `entry-static.exe basename` testcase by rewriting it as
89+
90+
```python
91+
libctest_baseline = """
92+
========== START entry-static.exe argv ==========
93+
Pass!
94+
========== END entry-static.exe argv ==========
95+
========== START entry-static.exe basename ==========
96+
Pass!
97+
========== END entry-static.exe basename ==========
98+
"""
99+
```
100+
101+
That is, we **append the instructions or results used in the evaluation** to the script.
102+
103+
### Add busybox testcases
104+
105+
The standard of the [judge_busybox.py](./judge_busybox.py) can be seen at [judge-std](https://github.com/Azure-stars/oskernel-testsuits-cooperation/tree/master/judge/judge_busybox.py).
106+
107+
If we want to add `echo "#### independent command test"` testcase, and the `busybox_baseline` in the [judge_busybox.py](./judge_busybox.py) is as below:
108+
109+
```python
110+
cmd = """"""
111+
```
112+
113+
Then we need to enable `echo "#### independent command test"` testcase by rewriting it as
114+
115+
```python
116+
cmd = """
117+
echo "#### independent command test"
118+
"""
119+
```
120+
121+
### Add lua testcases
122+
123+
The standard of the [judge_lua.py](./judge_lua.py) can be seen at [judge-std](https://github.com/Azure-stars/oskernel-testsuits-cooperation/tree/master/judge/judge_lua.py).
124+
125+
If we want to add `max_min.lua` testcase, and the `cmd` in the [judge_lua.py](./judge_lua.py) is as below:
126+
127+
```python
128+
cmds = """"""
129+
```
130+
131+
Then we need to enable `max_min.lua` testcase by rewriting it as
132+
133+
```python
134+
cmds = """
135+
max_min.lua
136+
"""
137+
```
138+
139+
140+
### About iozone testcases
24141

25-
2. If the testcase belongs to `basic`, you need to add it in the `./scripts/oscomp_test.sh`. You can find `TODO` fields in the script and add the new testcases in the corresponding place. An example to add `clone` testcases are shown below:
142+
IOZONE is a special testcase, and the standard of the [judge_iozone.py](./judge_iozone.py) can be seen at [judge-std](https://github.com/Azure-stars/oskernel-testsuits-cooperation/tree/master/judge/judge_iozone.py).It measures both correctness and performance.
26143

27-
```shell
28-
# TODO: add more basic testcases
29-
basic_testlist=(
30-
"/$LIBC/basic/brk"
31-
"/$LIBC/basic/chdir"
32-
"/$LIBC/basic/clone" # add the new testcase here
33-
)
34-
```
144+
So we will directly enable all its subtest cases by rewriting `iozone_baseline` in the [judge_iozone.py](./judge_iozone.py) to that in the [judge-std](https://github.com/Azure-stars/oskernel-testsuits-cooperation/tree/master/judge/judge_iozone.py).

apps/oscomp/testcase_list

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
/musl/busybox sh /musl/libctest_testcode.sh
1+
/musl/basic/waitpid

scripts/make/oscomp.mk

Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,35 @@
1+
# Command to build and run testcases for oscomp
2+
3+
oscomp_binary: ax_root defconfig
4+
@cp -r $(PWD)/bin/* /root/.cargo/bin
5+
@make -C $(AX_ROOT) A=$(PWD) EXTRA_CONFIG=$(EXTRA_CONFIG) build
6+
@if [ "$(ARCH)" = "riscv64" ]; then \
7+
cp $(OUT_BIN) kernel-rv; \
8+
else \
9+
cp $(OUT_ELF) kernel-la; \
10+
fi
11+
12+
oscomp_build:
13+
# Build for os competition
14+
RUSTUP_TOOLCHAIN=nightly-2025-01-18 $(MAKE) oscomp_binary ARCH=riscv64 AX_TESTCASE=oscomp BUS=mmio FEATURES=lwext4_rs
15+
RUSTUP_TOOLCHAIN=nightly-2025-01-18 $(MAKE) oscomp_binary ARCH=loongarch64 AX_TESTCASE=oscomp FEATURES=lwext4_rs
16+
17+
oscomp_test: defconfig
18+
# Test for os competition online
19+
@./scripts/oscomp_test.sh
20+
21+
IMG_URL := https://github.com/Azure-stars/testsuits-for-oskernel/releases/download/v0.1/sdcard-$(ARCH).img.gz
22+
23+
define load_img
24+
@if [ ! -f $(PWD)/sdcard-$(ARCH).img ]; then \
25+
wget $(IMG_URL); \
26+
gunzip $(PWD)/sdcard-$(ARCH).img.gz; \
27+
fi
28+
cp $(PWD)/sdcard-$(ARCH).img $(AX_ROOT)/disk.img
29+
endef
30+
31+
oscomp_run: ax_root defconfig
32+
$(call load_img)
33+
$(MAKE) AX_TESTCASE=oscomp BLK=y NET=y FEATURES=fp_simd,lwext4_rs LOG=$(LOG) run
34+
35+
.PHONY: oscomp_binary oscomp_build oscomp_test oscomp_run

0 commit comments

Comments
 (0)