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
10 changes: 7 additions & 3 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -155,7 +155,7 @@ run-docker: check_arch

test-syscall: check_arch
@echo "构建运行并执行syscall测试"
bash user/apps/tests/syscall/gvisor/enable_compile_gvisor.sh
bash user/apps/tests/syscall/gvisor/toggle_compile_gvisor.sh enable
$(MAKE) all -j $(NPROCS)
@if [ "$(DISK_SAVE_MODE)" = "1" ]; then \
echo "磁盘节省模式启用,正在清理用户程序构建缓存..."; \
Expand All @@ -164,8 +164,12 @@ test-syscall: check_arch
$(MAKE) write_diskimage || exit 1
$(MAKE) qemu-nographic AUTO_TEST=syscall SYSCALL_TEST_DIR=/opt/tests/gvisor &
sleep 5
bash user/apps/tests/syscall/gvisor/monitor_test_results.sh || { bash user/apps/tests/syscall/gvisor/disable_compile_gvisor.sh; exit 1; }
bash user/apps/tests/syscall/gvisor/disable_compile_gvisor.sh
@{ \
status=0; \
bash user/apps/tests/syscall/gvisor/monitor_test_results.sh || status=$$?; \
bash user/apps/tests/syscall/gvisor/toggle_compile_gvisor.sh disable; \
exit $$status; \
}

fmt: check_arch
@echo "格式化代码"
Expand Down
21 changes: 6 additions & 15 deletions config/app-blocklist.toml
Original file line number Diff line number Diff line change
Expand Up @@ -62,19 +62,10 @@ log_skipped = true
# - reason:屏蔽原因说明(可选,建议提供以便调试和维护)

# 屏蔽gvisor系统调用测试
[[blocked_apps]]
name = "gvisor syscall tests"
reason = "由于文件较大,因此屏蔽。如果要允许系统调用测试,则把这几行取消注释即可"

[[blocked_apps]]
name = "NovaShell"
reason = "工具链版本有问题,应为nightly-2025-8-10"

[[blocked_apps]]
name = "test_ebpf_new"
reason = "2025.11.17,aya上游发版有问题,导致ci过不了,暂时禁用"

[[blocked_apps]]
name = "test_ebpf_tp"
reason = "2025.11.17,aya上游发版有问题,导致ci过不了,暂时禁用"
blocked_apps = [
{ name = "gvisor syscall tests", reason = "由于文件较大,因此屏蔽。如果要允许系统调用测试,则把这行取消注释即可" },
{ name = "NovaShell", reason = "工具链版本有问题,应为nightly-2025-8-10" },
{ name = "test_ebpf_new", reason = "2025.11.17,aya上游发版有问题,导致ci过不了,暂时禁用" },
{ name = "test_ebpf_tp", reason = "2025.11.17,aya上游发版有问题,导致ci过不了,暂时禁用" },
]

17 changes: 8 additions & 9 deletions docs/kernel/ktest/gvisor_syscall_test.rst
Original file line number Diff line number Diff line change
Expand Up @@ -21,12 +21,12 @@ gVisor 是 Google 开发的容器运行时沙箱,包含了大量的系统调

执行`make test-syscall`命令。该命令将启动DragonOS并自动执行gvisor syscall测试套件,测试完成后会退出qemu。同时根据测试用例成功率选择是成功返回还是失败返回,成功率不等于100%则失败返回。该命令的执行流程如下:

1. 执行`enable_compile_gvisor.sh`注释`app-blocklist.toml`中有关于屏蔽gvisor测试套的配置
1. 执行 `toggle_compile_gvisor.sh enable` 注释 `app-blocklist.toml` 中与 gvisor 测试套件相关的屏蔽配置
2. 编译DragonOS
3. 写入镜像
4. 后台qemu无图形模式启动DragonOS,同时设置环境变量`AUTO_TEST`(自动测试选项,目前仅支持syscall测试)和`SYSCALL_TEST_DIR`(测试套所在目录),这两个环境变量会通过命令行参数传递到DragonOS。然后当busybox init进程执行rcS脚本时,该脚本会通过`AUTO_TEST`选项执行对应的测试
5. 执行`monitor_test_results.sh`定时查看qemu串口输出内容,并根据测试结果选择成功返回还是失败返回
6. 执行`disable_compile_gvisor.sh`取消`app-blocklist.toml`中有关于屏蔽gvisor测试套的配置注释
6. 执行 `toggle_compile_gvisor.sh disable` 取消 `app-blocklist.toml` 中相关配置的注释,恢复默认屏蔽状态

对应的workflow配置文件为`test-x86.yml`

Expand All @@ -45,16 +45,15 @@ gVisor 是 Google 开发的容器运行时沙箱,包含了大量的系统调

make test

3. 如果需要运行测试,请先修改配置文件
3. 如果需要运行测试,可通过脚本快速修改配置

编辑 `config/app-blocklist.toml`,注释掉以下内容:
.. code-block:: bash

.. code-block:: toml
# 启用 gVisor 测试(注释 blocklist 配置)
bash user/apps/tests/syscall/gvisor/toggle_compile_gvisor.sh enable

# 屏蔽gvisor系统调用测试
# [[blocked_apps]]
# name = "gvisor syscall tests"
# reason = "由于文件较大,因此屏蔽。如果要允许系统调用测试,则把这几行取消注释即可"
# 测试完成后恢复默认屏蔽
bash user/apps/tests/syscall/gvisor/toggle_compile_gvisor.sh disable

4. 在 DragonOS 系统内运行测试:

Expand Down
1 change: 1 addition & 0 deletions tools/write_disk_image.sh
Original file line number Diff line number Diff line change
Expand Up @@ -104,6 +104,7 @@ mkdir -p ${mount_folder}/dev
mkdir -p ${mount_folder}/proc
mkdir -p ${mount_folder}/usr
mkdir -p ${mount_folder}/root
mkdir -p ${mount_folder}/tmp

if [ "$FS_TYPE" = "vfat" ] || [ "$FS_TYPE" = "fat32" ]; then
cp -rL ${root_folder}/bin/sysroot/* ${mount_folder}/
Expand Down
9 changes: 0 additions & 9 deletions user/apps/tests/syscall/gvisor/disable_compile_gvisor.sh

This file was deleted.

19 changes: 0 additions & 19 deletions user/apps/tests/syscall/gvisor/enable_compile_gvisor.sh

This file was deleted.

114 changes: 114 additions & 0 deletions user/apps/tests/syscall/gvisor/toggle_compile_gvisor.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,114 @@
#!/bin/bash

set -euo pipefail

usage() {
cat >&2 <<'EOF'
用法: toggle_compile_gvisor.sh <enable|disable>
enable 注释 gVisor 配置行,允许编译
disable 取消注释 gVisor 配置行,继续屏蔽
EOF
exit 1
}

ACTION="${1:-}"
shift || true

case "$ACTION" in
enable|disable) ;;
*) usage ;;
esac

SCRIPT_DIR="$(cd -- "$(dirname "$0")" && pwd)"
REPO_ROOT="$(cd -- "$SCRIPT_DIR/../../../../.." && pwd)"
CONFIG_FILE="$REPO_ROOT/config/app-blocklist.toml"
TMP_FILE="${CONFIG_FILE}.tmp"
TARGET_PATTERN='name[[:space:]]*=[[:space:]]*"gvisor syscall tests"'

if [ ! -f "$CONFIG_FILE" ]; then
echo "错误:配置文件不存在: $CONFIG_FILE" >&2
exit 1
fi

if [ ! -w "$CONFIG_FILE" ]; then
echo "错误:配置文件不可写: $CONFIG_FILE" >&2
exit 1
fi

cleanup() {
rm -f "$TMP_FILE"
}
trap cleanup EXIT

if ! awk -v action="$ACTION" -v pattern="$TARGET_PATTERN" '
function comment_line(line, indent, rest) {
if (line ~ /^[[:space:]]*$/) {
return line
}
if (line ~ /^[[:space:]]*#/) {
return line
}
match(line, /^[[:space:]]*/)
indent = substr(line, 1, RLENGTH)
rest = substr(line, RLENGTH + 1)
if (rest == "") {
return indent "#"
}
return indent "# " rest
}

function uncomment_line(line, indent, rest) {
if (line ~ /^[[:space:]]*$/) {
return line
}
match(line, /^[[:space:]]*/)
indent = substr(line, 1, RLENGTH)
rest = substr(line, RLENGTH + 1)
while (rest ~ /^#/) {
sub(/^# ?/, "", rest)
}
return indent rest
}

BEGIN {
matched = 0
}

{
line = $0
tmp = line
sub(/^[[:space:]]*# ?/, "", tmp)
if (!matched && tmp ~ pattern) {
if (action == "enable") {
if (line ~ /^[[:space:]]*#/) {
print line
} else {
print comment_line(line)
}
} else {
if (line ~ /^[[:space:]]*#/) {
print uncomment_line(line)
} else {
print line
}
}
matched = 1
next
}
print line
}

END {
if (!matched) {
exit 1
}
}
' "$CONFIG_FILE" > "$TMP_FILE"; then
echo "错误:未找到 gVisor 配置行" >&2
exit 1
fi

mv "$TMP_FILE" "$CONFIG_FILE"
trap - EXIT
cleanup

Loading