高级构建和测试说明
用户模式单元测试
Asterinas 由多个 crate 组成,其中部分 crate 无需虚拟机环境,可通过标准的 cargo test 进行测试。这些 crate 已在根目录的 Makefile 中列出,可通过以下 Make 命令统一测试。
make test
要测试单个 crate,请进入 crate 的目录并调用 cargo test 。
内核模式单元测试
Asterinas 中的许多 crate 都需要虚拟机环境才能进行测试。这些 crate 的单元测试由 OSDK 提供支持。
make ktest
要测试内核模式下的单个 crate,请进入 crate 的目录并调用 cargo osdk test。
cd asterinas/ostd
cargo osdk test
集成测试
Regression Test
The following command builds and runs the regression test in test/initramfs/src/regression on Asterinas.
make run_kernel AUTO_TEST=regression
Conformance Test
The following command builds and runs the conformance test on Asterinas.
make run_kernel AUTO_TEST=conformance
To run conformance test interactively, start an instance of Asterinas with the conformance tests built and installed.
make run_kernel ENABLE_CONFORMANCE_TEST=true
Then, in the interactive shell, run the following script to start the conformance test.
/opt/run_conformance_test.sh
调试
使用 GDB 进行调试
要通过 QEMU GDB 支持 调试 Asterinas,你可以使用 debug profile 来编译 Asterinas,启动一个 Asterinas 实例,并在另一个终端中运行 GDB 交互式 shell。
使用 OSDK 启动一个支持 GDB 的 Asterinas 虚拟机,并等待调试连接:
make gdb_server
服务器将监听Makefile中指定的默认地址,即本地TCP端口:1234。你可以根据需要修改Makefile中的地址设置,更多关于地址的详细信息请运行cargo osdk run -h。
提供了两种与调试服务器交互的方式。
-
GDB 客户端:在另一个终端中启动 GDB 客户端。
make gdb_client -
VS Code: 需要CodeLLDB扩展。通过 OSDK 在终端执行
make gdb_server启动调试服务器后,系统会在.vscode目录下生成临时launch.json文件,原有 launch configs 将在服务器关闭后自动恢复。按F5(运行并调试)即可通过VS Code启动调试会话。首次中断时点击继续(或按F5)可恢复被暂停的服务器实例,程序将持续运行直至遇到您设置的第一个断点。
请注意,若在启用KVM的情况下进行调试,必须使用硬件辅助断点。具体方法参见GDB手册中的“hbreak“说明。