【推理引擎】在 VS Code 調試 ONNXRuntime 的測試單元
背景:在學習如何往ONNXRuntime中添加新運算元時,參考了官方測試程式碼:
onnxruntime/test/shared_lib/test_inference.cc
,程式碼內部使用GTest作為單元測試工具。為了清楚地學習運行過程,一步一步地調試是不可缺少的。
開始調試前需要以Debug方式編譯程式碼庫,同時別忘了開啟測試開關:
// cmake/CMakeLists.txt
...
option(onnxruntime_BUILD_UNIT_TESTS "Build ONNXRuntime unit tests" ON)
...
編譯完成之後,在 build/Linux/Debug
文件夾下有一個可執行程式:onnxruntime_shared_lib_test
,當然,文件夾下還有其它關於測試的可執行程式,比如onnxruntime_test_all、onnxruntime_perf_test、onnx_test_runner
等等。
接著需要在 .vscode/launch.json
文件中添加調試資訊:
{
"configurations": [
{
"name": "(gdb) Launch",
"type": "cppdbg",
"request": "launch",
"program": "${workspaceFolder}/build/Linux/Debug/onnxruntime_shared_lib_test",
"args": [
],
"stopAtEntry": false,
"cwd": "${workspaceFolder}/onnxruntime/test/",
"environment": [],
"externalConsole": false,
"MIMode": "gdb",
"setupCommands": [
{
"description": "Enable pretty-printing for gdb",
"text": "-enable-pretty-printing",
"ignoreFailures": true
},
{
"description": "Set Disassembly Flavor to Intel",
"text": "-gdb-set disassembly-flavor intel",
"ignoreFailures": true
}
]
}
]
}
配置內容幾乎都是自動生成的,我們只改動了其中兩項:
"program": "${workspaceFolder}/build/Linux/Debug/onnxruntime_shared_lib_test"
:配置調試程式的路徑"cwd": "${workspaceFolder}/onnxruntime/test/"
:解決相對路徑問題
至此,我們就可以「愉快地」開始接下來的調試任務了。