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
67 changes: 67 additions & 0 deletions config/app-blocklist.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,67 @@
# =========================================================
# DADK 应用程序黑名单配置文件模板
# =========================================================
#
# 应用程序黑名单功能允许用户指定不希望编译和安装的应用程序。
# 当黑名单中的应用程序被检测到时,DADK 会根据配置自动跳过这些应用程序的构建和安装过程。

# =========================================================
# 全局配置选项
# =========================================================

# 是否启用严格模式(可选)
# - true(默认):严格模式,跳过被屏蔽的应用程序并记录警告
# - false:非严格模式,只记录警告但不跳过应用程序
strict = true

# 是否在日志中显示被跳过的应用(可选)
# - true(默认):在日志中显示被跳过的应用程序信息
# - false:静默模式,不显示被跳过的应用程序
log_skipped = true

# =========================================================
# 被屏蔽的应用程序列表
# =========================================================
#
# 支持以下匹配方式:
# 1. 精确匹配: name = "app1"
# 2. 版本匹配: name = "openssl@1.1.1"
# 3. 通配符名称: name = "test-*"
# 4. 通配符版本: name = "nginx@1.*"
# 5. 复合模式: name = "lib*@2.*"
#
# 每个应用可以选择性地提供屏蔽原因(reason)


# =========================================================
# 配置说明和注意事项
# =========================================================
#
# 1. **依赖关系**:如果其他应用程序依赖被屏蔽的应用程序,构建过程可能会失败。
# 请确保处理好依赖关系。
#
# 2. **模式匹配优先级**:
# - 精确匹配 > 版本匹配 > 模式匹配
# - 如果有多个模式都匹配,使用第一个匹配的结果
#
# 3. **通配符语法**:
# - "*" 匹配任意数量的字符(包括0个)
# - "?" 匹配单个字符
# - 支持在名称和版本中使用通配符
#
# 4. **版本格式**:
# - 版本号使用 "@" 符号分隔,如 "app@1.0.0"
# - 版本号支持通配符,如 "app@1.*"
#
# 5. **配置文件路径**:
# - 默认路径:config/app-blocklist.toml
# - 可在 dadk-manifest.toml 中通过 app-blocklist-config 字段自定义路径
#
# 6. **字段说明**:
# - name:应用程序名称或匹配模式(必需)
# - reason:屏蔽原因说明(可选,建议提供以便调试和维护)

# 屏蔽gvisor系统调用测试
[[blocked_apps]]
name = "gvisor syscall tests"
reason = "由于文件较大,因此屏蔽。如果要允许系统调用测试,则把这几行取消注释即可"
2 changes: 1 addition & 1 deletion config/rootfs.toml
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
# Filesystem type (options: `fat32`)
fs_type = "fat32"
# Size of the rootfs disk image (eg, `1G`, `1024M`)
size = "1G"
size = "2G"

[partition]
# Partition type (options: "none", "mbr", "gpt")
Expand Down
4 changes: 4 additions & 0 deletions dadk-manifest.toml
Original file line number Diff line number Diff line change
Expand Up @@ -22,3 +22,7 @@ cache-root-dir = "bin/dadk_cache"
# User configuration directory path
# 这个字段只是临时用于兼容旧版本,v0.2版本重构完成后会删除
user-config-dir = "user/dadk/config"

# Application blocklist configuration file path
app-blocklist-config = "config/app-blocklist.toml"

79 changes: 79 additions & 0 deletions docs/kernel/ktest/gvisor_syscall_test.rst
Original file line number Diff line number Diff line change
@@ -0,0 +1,79 @@
==============================
gVisor 系统调用测试
==============================

DragonOS 集成了 gVisor 系统调用测试套件,用于验证操作系统系统调用实现的兼容性和正确性。

概述
========

gVisor 是 Google 开发的容器运行时沙箱,包含了大量的系统调用兼容性测试。这些测试用于验证操作系统的系统调用实现是否符合 Linux 标准。

主要特性:

- **全面的测试覆盖**:包含数百个系统调用测试用例
- **白名单机制**:默认只运行已验证的测试,逐步完善支持
- **黑名单过滤**:可针对每个测试程序屏蔽特定的测试用例
- **自动化运行**:提供 Makefile 和脚本简化测试流程

快速开始
==========

1. 进入测试目录:

.. code-block:: bash

cd user/apps/tests/syscall/gvisor

2. 在Linux运行白名单测试(自动下载测试套件):

.. code-block:: bash

make test

3. 如果需要运行测试,请先修改配置文件:

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

.. code-block:: toml

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

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

进入安装目录并运行测试程序:

.. code-block:: bash

cd /opt/tests/gvisor
./gvisor-test-runner --help

使用 ``./gvisor-test-runner`` 可以运行具体的测试用例。

5. 查看详细文档:

请参阅 `user/apps/tests/syscall/gvisor/README.md` 获取完整的使用说明。

测试机制
==========

白名单模式
-----------

测试框架默认启用白名单模式,只运行 ``whitelist.txt`` 中指定的测试程序。这允许逐步验证 DragonOS 的系统调用实现。

黑名单过滤
-----------

对于每个测试程序,可以通过 ``blocklists/`` 目录下的文件屏蔽特定的测试用例。这对于跳过暂不支持或不稳定的测试非常有用。

更多详细信息
==============

关于 gVisor 系统调用测试的详细使用方法、配置选项和开发指南,请查看测试目录下的 README.md 文档:

- 文档位置:`user/apps/tests/syscall/gvisor/README.md`

2 changes: 2 additions & 0 deletions docs/kernel/ktest/index.rst
Original file line number Diff line number Diff line change
Expand Up @@ -17,3 +17,5 @@
:maxdepth: 1
:caption: 目录

gvisor_syscall_test.rst

2 changes: 1 addition & 1 deletion user/Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ user_sub_dirs = apps

DADK_VERSION=$(shell dadk -V | awk 'END {print $$2}')
# 最小的DADK版本
MIN_DADK_VERSION = 0.4.0
MIN_DADK_VERSION = 0.5.0
DADK_CACHE_DIR = $(ROOT_PATH)/bin/dadk_cache

ECHO:
Expand Down
2 changes: 2 additions & 0 deletions user/apps/tests/syscall/gvisor/.gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
/tests/
/results/
105 changes: 105 additions & 0 deletions user/apps/tests/syscall/gvisor/Makefile
Original file line number Diff line number Diff line change
@@ -0,0 +1,105 @@
# gvisor系统调用测试 Makefile
# 用于DragonOS项目

# Rust工具链配置
TOOLCHAIN="+nightly-2025-08-10-x86_64-unknown-linux-gnu"
RUSTFLAGS+=""

ifdef DADK_CURRENT_BUILD_DIR
# 如果是在dadk中编译,那么安装到dadk的安装目录中
INSTALL_DIR = $(DADK_CURRENT_BUILD_DIR)
else
# 如果是在本地编译,那么安装到当前目录下的install目录中
INSTALL_DIR = ./install
endif

ifeq ($(ARCH), x86_64)
export RUST_TARGET=x86_64-unknown-linux-musl
else ifeq ($(ARCH), riscv64)
export RUST_TARGET=riscv64gc-unknown-linux-gnu
else
# 默认为x86_64,用于本地编译
export RUST_TARGET=x86_64-unknown-linux-musl
endif

.PHONY: all build install download test list run clean help

# 默认目标:构建并安装
all: build install

# 显示帮助信息
help:
@echo "gvisor系统调用测试 Makefile"
@echo ""
@echo "可用目标:"
@echo " all - 构建并安装测试运行器(默认)"
@echo " build - 构建Rust测试运行器"
@echo " install - 安装测试运行器和必要文件"
@echo " download - 下载gvisor测试套件"
@echo " test - 运行白名单中的测试"
@echo " list - 列出所有可用测试"
@echo " run - 运行测试并传递参数(如:make run ARGS=\"-v epoll_test\")"
@echo " clean - 清理测试文件和结果"
@echo " help - 显示此帮助信息"
@echo ""
@echo "环境变量:"
@echo " SYSCALL_TEST_WORKDIR - 测试工作目录(默认: /tmp/gvisor_tests)"
@echo " TEST_TIMEOUT - 单个测试超时时间(默认: 300秒)"

# 构建Rust测试运行器
build:
@echo "构建gvisor测试运行器..."
@cd runner && RUSTFLAGS=$(RUSTFLAGS) cargo $(TOOLCHAIN) build --target $(RUST_TARGET) --release

# 下载测试套件
download:
@echo "下载gvisor测试套件..."
@./download_tests.sh

# 安装到目标目录
install: build
@echo "安装gvisor测试套件到 $(INSTALL_DIR)"
@mkdir -p $(INSTALL_DIR)
# 安装Rust测试运行器二进制文件
@cp -f runner/target/$(RUST_TARGET)/release/runner $(INSTALL_DIR)/gvisor-test-runner
# 安装测试配置文件
@cp -f whitelist.txt $(INSTALL_DIR)/
@cp -rf blocklists $(INSTALL_DIR)/
# 安装下载脚本(用于目标系统上下载测试)
@cp -f download_tests.sh $(INSTALL_DIR)/
@chmod +x $(INSTALL_DIR)/download_tests.sh
@chmod +x $(INSTALL_DIR)/gvisor-test-runner
@echo "安装完成"

# 运行测试
test: build
@echo "运行gvisor系统调用测试..."
@if [ ! -d tests ]; then \
echo "测试套件不存在,正在下载..."; \
./download_tests.sh; \
fi
@./runner/target/$(RUST_TARGET)/release/runner

# 列出所有测试
list: build
@if [ ! -d tests ]; then \
echo "测试套件不存在,正在下载..."; \
./download_tests.sh; \
fi
@./runner/target/$(RUST_TARGET)/release/runner --list

# 运行测试并传递参数
run: build
@if [ ! -d tests ]; then \
echo "测试套件不存在,正在下载..."; \
./download_tests.sh; \
fi
@./runner/target/$(RUST_TARGET)/release/runner $(ARGS)

# 清理
clean:
@echo "清理测试文件和结果..."
@rm -rf results/
@rm -f gvisor-syscalls-tests.tar.xz
@cd runner && cargo clean
@echo "清理完成"
Loading
Loading