Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
46 changes: 13 additions & 33 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -36,23 +36,21 @@ else
PROFILE_DIR := release
endif

# 评测内核默认启用 oscomp 特性:启动时探测双盘、把测试镜像挂到 /tests,
# 由 rootfs 的 rcS 自动跑测试并主动关机(赛题要求“自动运行 + 自动关闭”)。
# 评测内核默认启用 oscomp 特性:使用单盘 rootfs(内含 /tests
# 由 rootfs 的 rcS 自动跑 musl 测试并主动关机(赛题要求“自动运行 + 自动关闭”)。
# 本地交互式开发请用 `make run`(os/Makefile,不带 oscomp)。
OSCOMP_FEATURE ?= --features oscomp

# 本地复现评测用 QEMU 参数(可在命令行覆盖,如 `make run-oscomp-rv OSCOMP_RV_MEM=2G`)。
# 测试镜像默认取仓库根的 sdcard-{rv,la}.img;rootfs 用 make all 产出的 disk{,-la}.img。
TESTIMG_RV ?= sdcard-rv.img
TESTIMG_LA ?= sdcard-la.img
# rootfs 用 make all 产出的 disk{,-la}.img,里面已经包含 /tests/{musl,glibc}。
OSCOMP_RV_MEM ?= 4G
OSCOMP_RV_SMP ?= 1
OSCOMP_LA_MEM ?= 4G
OSCOMP_LA_SMP ?= 1

.PHONY: docker build_docker fmt run build clean clean-all gdb
.PHONY: all kernel-rv kernel-la os-cargo-config
.PHONY: run-oscomp-rv run-oscomp-la prepare-testimg-rv prepare-testimg-la
.PHONY: run-oscomp-rv run-oscomp-la

docker:
docker run --rm -it -v ${PWD}:/mnt -w /mnt --name comix ${DOCKER_TAG} bash
Expand Down Expand Up @@ -131,42 +129,24 @@ disk-la.img: kernel-la
cp -f $(OS_DIR)/fs-loongarch.img disk-la.img

# ------------------------------------------------------------
# 本地复现评测:启动 QEMU,挂测试镜像(x0) + 我们的 rootfs(x1)
# 内核自动跑测试并主动关机;-no-reboot 让关机时 QEMU 退出。
# 本地复现评测:启动 QEMU,只挂单盘 rootfs(内含 /tests)
# 内核自动跑 musl 测试并主动关机;-no-reboot 让关机时 QEMU 退出。
# 设备型号对齐 os/qemu-run.sh(riscv: virtio-mmio)与 os/qemu-loongarch-run.sh(loongarch: pci)。
# ------------------------------------------------------------
prepare-testimg-rv:
@test -f "$(TESTIMG_RV)" || ( \
echo "[OSCOMP] 缺少 RISC-V 测试镜像: $(TESTIMG_RV)"; \
echo "[OSCOMP] 请把官方测试镜像放到该路径,或用 TESTIMG_RV=... 覆盖。"; \
exit 1; )
@echo "[OSCOMP] 使用 RISC-V 测试镜像: $(TESTIMG_RV)"

prepare-testimg-la:
@test -f "$(TESTIMG_LA)" || ( \
echo "[OSCOMP] 缺少 LoongArch 测试镜像: $(TESTIMG_LA)"; \
echo "[OSCOMP] 请把官方测试镜像放到该路径,或用 TESTIMG_LA=... 覆盖。"; \
exit 1; )
@echo "[OSCOMP] 使用 LoongArch 测试镜像: $(TESTIMG_LA)"

run-oscomp-rv: kernel-rv disk.img prepare-testimg-rv
@echo "[OSCOMP] 运行 RISC-V QEMU(测试镜像 + rootfs,自动跑测试并关机)"
run-oscomp-rv: kernel-rv disk.img
@echo "[OSCOMP] 运行 RISC-V QEMU(单盘 rootfs + tests,自动跑测试并关机)"
qemu-system-riscv64 -machine virt -kernel kernel-rv -m $(OSCOMP_RV_MEM) -nographic \
-smp $(OSCOMP_RV_SMP) -bios default -no-reboot -rtc base=utc \
-drive file=$(TESTIMG_RV),if=none,format=raw,id=x0 \
-drive file=disk.img,if=none,format=raw,id=x0 \
-device virtio-blk-device,drive=x0,bus=virtio-mmio-bus.0 \
-drive file=disk.img,if=none,format=raw,id=x1 \
-device virtio-blk-device,drive=x1,bus=virtio-mmio-bus.1 \
-device virtio-net-device,netdev=net -netdev user,id=net

run-oscomp-la: kernel-la disk-la.img prepare-testimg-la
@echo "[OSCOMP] 运行 LoongArch QEMU(测试镜像 + rootfs,自动跑测试并关机)"
run-oscomp-la: kernel-la disk-la.img
@echo "[OSCOMP] 运行 LoongArch QEMU(单盘 rootfs + tests,自动跑测试并关机)"
qemu-system-loongarch64 -machine virt -kernel kernel-la -m $(OSCOMP_LA_MEM) -nographic \
-smp $(OSCOMP_LA_SMP) -no-reboot -rtc base=utc \
-drive file=$(TESTIMG_LA),if=none,format=raw,id=x0 \
-drive file=disk-la.img,if=none,format=raw,id=x0 \
-device virtio-blk-pci,drive=x0 \
-drive file=disk-la.img,if=none,format=raw,id=x1 \
-device virtio-blk-pci,drive=x1 \
-device virtio-net-pci,netdev=net0 \
-netdev user,id=net0,hostfwd=tcp::5555-:5555,hostfwd=udp::5555-:5555

Expand Down Expand Up @@ -217,4 +197,4 @@ help:
@echo "Examples:"
@echo " make build # Build for RISC-V"
@echo " make build ARCH=loongarch # Build for LoongArch"
@echo " make run ARCH=loongarch # Run LoongArch kernel"
@echo " make run ARCH=loongarch # Run LoongArch kernel"
44 changes: 10 additions & 34 deletions data/loongarch_musl/etc/init.d/rcS
Original file line number Diff line number Diff line change
Expand Up @@ -52,29 +52,10 @@ echo "Mounting file systems via fstab..."
echo "System initialization finished."

run_oscomp_tests_if_present() {
# 评测测试镜像由内核挂到 /tests(init_oscomp_filesystems())。
# 检测到官方测试脚本就非交互地依次执行,跑完主动关机
# rootfs 内置 /tests。当前自动入口只跑 musl 分组;
# glibc 分组保留在镜像中,后续需要时直接调整本脚本
[ -d /tests ] || return 1

# 官方测试二进制硬编码了 ELF 解释器路径(如 /lib64/ld-linux-*.so.*)。
# 我们是 musl rootfs,把测试镜像里的 glibc loader/库软链到常见 ABI libdir 以便加载。
if [ -d /tests/glibc/lib ]; then
[ -d /lib ] || /bin/mkdir -p /lib
[ -d /lib64 ] || /bin/mkdir -p /lib64
for f in /tests/glibc/lib/ld-linux-*.so.*; do
[ -f "$f" ] || continue
base="${f##*/}"
/bin/ln -sf "$f" "/lib/$base"
/bin/ln -sf "$f" "/lib64/$base"
done
for base in libc.so.6 libm.so.6 libpthread.so.0 libdl.so.2 librt.so.1 libresolv.so.2; do
if [ -f "/tests/glibc/lib/$base" ]; then
/bin/ln -sf "/tests/glibc/lib/$base" "/lib/$base"
/bin/ln -sf "/tests/glibc/lib/$base" "/lib64/$base"
fi
done
fi

scripts=""
add_script() {
# 简单去重,避免 VFS 把 /tests 暴露成 /tests/tests 之类的病态情况。
Expand All @@ -84,24 +65,19 @@ run_oscomp_tests_if_present() {
scripts="$scripts $1"
}

# 1) /tests 根下的脚本。
for f in /tests/*_testcode.sh; do
[ -f "$f" ] || continue
add_script "$f"
done

# 2) 下一层:/tests/*/*,匹配官方镜像布局 /tests/glibc/*.sh、/tests/musl/*.sh。
for d in /tests/*; do
[ -d "$d" ] || continue
[ "$d" = "/tests/tests" ] && continue
for f in "$d"/*_testcode.sh; do
add_scripts_in_dir() {
dir="$1"
[ -d "$dir" ] || return 0
for f in "$dir"/*_testcode.sh; do
[ -f "$f" ] || continue
add_script "$f"
done
done
}

add_scripts_in_dir /tests/musl
[ -n "$scripts" ] || return 1

echo "[OSCOMP] detected test scripts under /tests; running in rcS"
echo "[OSCOMP] detected musl test scripts under /tests; running in rcS"
export PATH="/bin:/sbin:/usr/bin:/usr/sbin:/tests"
export HOME="/"

Expand Down
41 changes: 10 additions & 31 deletions data/risc-v_musl/etc/init.d/rcS
Original file line number Diff line number Diff line change
Expand Up @@ -52,26 +52,10 @@ echo "Mounting file systems via fstab..."
echo "System initialization finished."

run_oscomp_tests_if_present() {
# 评测测试镜像由内核挂到 /tests(init_oscomp_filesystems())。
# 检测到官方测试脚本就非交互地依次执行,跑完主动关机
# rootfs 内置 /tests。当前自动入口只跑 musl 分组;
# glibc 分组保留在镜像中,后续需要时直接调整本脚本
[ -d /tests ] || return 1

# 官方测试二进制硬编码了 ELF 解释器路径(如 /lib/ld-linux-*.so.*)。
# 我们是 musl rootfs,把测试镜像里的 glibc loader/库软链到 /lib 以便加载。
if [ -d /tests/glibc/lib ]; then
[ -d /lib ] || /bin/mkdir -p /lib
for f in /tests/glibc/lib/ld-linux-*.so.*; do
[ -f "$f" ] || continue
base="${f##*/}"
/bin/ln -sf "$f" "/lib/$base"
done
for base in libc.so.6 libm.so.6 libpthread.so.0 libdl.so.2 librt.so.1 libresolv.so.2; do
if [ -f "/tests/glibc/lib/$base" ]; then
/bin/ln -sf "/tests/glibc/lib/$base" "/lib/$base"
fi
done
fi

scripts=""
add_script() {
# 简单去重,避免 VFS 把 /tests 暴露成 /tests/tests 之类的病态情况。
Expand All @@ -81,24 +65,19 @@ run_oscomp_tests_if_present() {
scripts="$scripts $1"
}

# 1) /tests 根下的脚本。
for f in /tests/*_testcode.sh; do
[ -f "$f" ] || continue
add_script "$f"
done

# 2) 下一层:/tests/*/*,匹配官方镜像布局 /tests/glibc/*.sh、/tests/musl/*.sh。
for d in /tests/*; do
[ -d "$d" ] || continue
[ "$d" = "/tests/tests" ] && continue
for f in "$d"/*_testcode.sh; do
add_scripts_in_dir() {
dir="$1"
[ -d "$dir" ] || return 0
for f in "$dir"/*_testcode.sh; do
[ -f "$f" ] || continue
add_script "$f"
done
done
}

add_scripts_in_dir /tests/musl
[ -n "$scripts" ] || return 1

echo "[OSCOMP] detected test scripts under /tests; running in rcS"
echo "[OSCOMP] detected musl test scripts under /tests; running in rcS"
export PATH="/bin:/sbin:/usr/bin:/usr/sbin:/tests"
export HOME="/"

Expand Down
Loading
Loading