原創|使用教程|編輯:張莉|2025-10-31 13:40:42.610|閱讀 42 次
概述:在嵌入式開發中,尤其是基于ARM架構的安全關鍵領域,單元測試是驗證代碼在目標硬件上運行時行為正確性的關鍵環節,對于保障最終產品的可靠性至關重要。下面將介紹如何利用Parasoft C/C++test開展單元測試,包括配置、執行及解決可能遇到的許可證問題,完成從靜態檢查到動態運行的完整測試閉環。
#慧都22周年慶大促·界面/圖表報表/文檔/IDE/IOT/測試等千款熱門軟控件火熱促銷中>>
在嵌入式開發中,尤其是基于ARM架構的安全關鍵領域,單元測試是驗證代碼在目標硬件上運行時行為正確性的關鍵環節,對于保障最終產品的可靠性至關重要。前面介紹了Parasoft C/C++test在ARM DS-5環境中的集成步驟,包括插件安裝、項目配置及靜態分析的實現過程。下面將介紹如何利用Parasoft C/C++test開展單元測試,包括配置、執行及解決可能遇到的許可證問題,完成從靜態檢查到動態運行的完整測試閉環。
單元測試
對于DS-5項目需要使用如下內建配置作為基準并修改

復制之后對如下圖所示部分根據實際項目做修改:
修改為:
執行的時候必須連接實際硬件,DS-5并沒有提供軟件仿真器,并且需要另一個許可證,如下所示:
對 /calendar 的 "Run DS-5 Test Executable (Software Model)" 開始(執行) ... 正在收集用于執行的測試... ...完成。 執行流程準備中... ...完成。 用戶信息... This execution flow starts external processes using predefined command lines, please review these commands and adjust to suit your environment. ...完成。 屬性的設置: stub_config_file = D:\workspace\DS-5\.cpptest\calendar\unit-data\current_tubf179707/stubconfig.xml 屬性的設置: stub_config_header_file = D:\workspace\DS-5\.cpptest\calendar\unit-data\current_tubf179707/cpptest_stubconfig.h 屬性的設置: sm_exe = D:\DS-5\sw\models\bin\FVP_EB_Cortex-A8 測試用例查找中... ...完成。 [calendar.c] 源代碼預編譯中: /calendar/calendar.c ... [calendar.c] ...結果是最新的。 正在為 /calendar/calendar.c 追加包括的測試用例 ... ...結果是最新的。 [calendar.c] 插樁準備中: /calendar/calendar.c ... [calendar.c] ...結果是最新的。 為: /calendar/calendar.c 的靜態覆蓋率數據讀取中... ...完成。 靜態覆蓋數據發送中... ...完成。 樁函數源代碼插樁中: D:\Parasoft\C++testforEclipse\10.3\engine\etc\safestubs\safe_stubs_win32.c ... ...結果是最新的。 符號數據讀取中... ...完成。 正在檢查缺少的定義... ...結果是最新的。 可用的定義數據讀取中... ...完成。 正在分析缺少的定義... ...完成。 樁函數配置中... 為函數: int scanf(const char *__restrict__, ...) 使用 原始 定義 為函數: int printf(const char *__restrict__, ...) 使用 原始 定義 為函數: void nextday(void) 使用 原始 定義 為函數: void calcDaysInMonth(void) 使用 原始 定義 ...完成。 樁函數配置頭文件創建中... ...結果是最新的。 測試運行文件創建中... ...結果是最新的。 運行時庫構建中... 源代碼編譯中: D:\Parasoft\C++testforEclipse\10.3\engine\runtime\src\CppTestApi.c ... ...結果是最新的。 源代碼編譯中: D:\Parasoft\C++testforEclipse\10.3\engine\runtime\src\CppTestCoverage.c ... ...結果是最新的。 源代碼編譯中: D:\Parasoft\C++testforEclipse\10.3\engine\runtime\src\CppTestErrorMessages.c ... ...結果是最新的。 源代碼編譯中: D:\Parasoft\C++testforEclipse\10.3\engine\runtime\src\CppTestMemoryAnalysis.c ... ...結果是最新的。 源代碼編譯中: D:\Parasoft\C++testforEclipse\10.3\engine\runtime\src\CppTestMessage.c ... ...結果是最新的。 源代碼編譯中: D:\Parasoft\C++testforEclipse\10.3\engine\runtime\src\CppTestRuntime.c ... ...結果是最新的。 源代碼編譯中: D:\Parasoft\C++testforEclipse\10.3\engine\runtime\src\CppTestStackTrace.c ... ...結果是最新的。 源代碼編譯中: D:\Parasoft\C++testforEclipse\10.3\engine\runtime\src\CppTestStreams.c ... ...結果是最新的。 源代碼編譯中: D:\Parasoft\C++testforEclipse\10.3\engine\runtime\src\CppTestThread.c ... ...結果是最新的。 源代碼編譯中: D:\Parasoft\C++testforEclipse\10.3\engine\runtime\src\CppTestThreadData.c ... ...結果是最新的。 源代碼編譯中: D:\Parasoft\C++testforEclipse\10.3\engine\runtime\src\CppTestTime.c ... ...結果是最新的。 源代碼編譯中: D:\Parasoft\C++testforEclipse\10.3\engine\runtime\src\CppTestTypeLimits.c ... ...結果是最新的。 源代碼編譯中: D:\Parasoft\C++testforEclipse\10.3\engine\runtime\src\CppTestUtils.c ... ...結果是最新的。 源代碼編譯中: D:\Parasoft\C++testforEclipse\10.3\engine\runtime\src\common\CppTestAlloc.c ... ...結果是最新的。 源代碼編譯中: D:\Parasoft\C++testforEclipse\10.3\engine\runtime\src\common\CppTestList.c ... ...結果是最新的。 源代碼編譯中: D:\Parasoft\C++testforEclipse\10.3\engine\runtime\src\common\CppTestMarshall.c ... ...結果是最新的。 源代碼編譯中: D:\Parasoft\C++testforEclipse\10.3\engine\runtime\src\common\CppTestMemory.c ... ...結果是最新的。 源代碼編譯中: D:\Parasoft\C++testforEclipse\10.3\engine\runtime\src\common\CppTestProperties.c ... ...結果是最新的。 源代碼編譯中: D:\Parasoft\C++testforEclipse\10.3\engine\runtime\src\common\CppTestString.c ... ...結果是最新的。 源代碼編譯中: D:\Parasoft\C++testforEclipse\10.3\engine\runtime\src\common\CppTestTree.c ... ...結果是最新的。 源代碼編譯中: D:\Parasoft\C++testforEclipse\10.3\engine\runtime\src\transport\CppTestTransport.c ... ...結果是最新的。 源代碼編譯中: D:\Parasoft\C++testforEclipse\10.3\engine\runtime\src\transport\CppTestTransportFile.c ... ...結果是最新的。 源代碼編譯中: D:\Parasoft\C++testforEclipse\10.3\engine\runtime\src\transport\CppTestTransportFileBuffered.c ... ...結果是最新的。 源代碼編譯中: D:\Parasoft\C++testforEclipse\10.3\engine\runtime\src\transport\CppTestTransportFileSplit.c ... ...結果是最新的。 源代碼編譯中: D:\Parasoft\C++testforEclipse\10.3\engine\runtime\src\transport\CppTestTransportHewSimIO.c ... ...結果是最新的。 源代碼編譯中: D:\Parasoft\C++testforEclipse\10.3\engine\runtime\src\transport\CppTestTransportITM.c ... ...結果是最新的。 源代碼編譯中: D:\Parasoft\C++testforEclipse\10.3\engine\runtime\src\transport\CppTestTransportLauterbachFDX.c ... ...結果是最新的。 源代碼編譯中: D:\Parasoft\C++testforEclipse\10.3\engine\runtime\src\transport\CppTestTransportNXT.c ... ...結果是最新的。 源代碼編譯中: D:\Parasoft\C++testforEclipse\10.3\engine\runtime\src\transport\CppTestTransportRenrxGDB.c ... ...結果是最新的。 源代碼編譯中: D:\Parasoft\C++testforEclipse\10.3\engine\runtime\src\transport\CppTestTransportRS232Common.c ... ...結果是最新的。 源代碼編譯中: D:\Parasoft\C++testforEclipse\10.3\engine\runtime\src\transport\CppTestTransportRS232STM32F103ZE.c ... ...結果是最新的。 源代碼編譯中: D:\Parasoft\C++testforEclipse\10.3\engine\runtime\src\transport\CppTestTransportRS232Unix.c ... ...結果是最新的。 源代碼編譯中: D:\Parasoft\C++testforEclipse\10.3\engine\runtime\src\transport\CppTestTransportRS232Win32.c ... ...結果是最新的。 源代碼編譯中: D:\Parasoft\C++testforEclipse\10.3\engine\runtime\src\transport\CppTestTransportTemplate.c ... ...結果是最新的。 源代碼編譯中: D:\Parasoft\C++testforEclipse\10.3\engine\runtime\src\transport\CppTestTransportUnixSocket.c ... ...結果是最新的。 源代碼編譯中: D:\Parasoft\C++testforEclipse\10.3\engine\runtime\src\transport\CppTestTransportUnixSocketUDP.c ... ...結果是最新的。 源代碼編譯中: D:\Parasoft\C++testforEclipse\10.3\engine\runtime\src\transport\CppTestTransportWinSocket.c ... ...結果是最新的。 ...完成。 [calendar.c] 插樁的源代碼編譯中: /calendar/calendar.c ... [safe_stubs_win32.c] 插樁的源代碼編譯中: D:\Parasoft\C++testforEclipse\10.3\engine\etc\safestubs\safe_stubs_win32.c ... [cpptest_testrunner.c] 源代碼編譯中: D:\workspace\DS-5\.cpptest\calendar\unit-data\current_tubf179707\cpptest_testrunner.c ... [safe_stubs_win32.c] ...結果是最新的。 [calendar.c] ...結果是最新的。 [cpptest_testrunner.c] ...結果是最新的。 測試項目鏈接中... ...結果是最新的。 移除文件 D:\workspace\DS-5\.cpptest\calendar\unit-data\current_tubf179707/cpptest_results.tlog 移除文件 D:\workspace\DS-5\.cpptest\calendar\unit-data\current_tubf179707/cpptest_results.clog Running Test Executable... D:\DS-5\sw\models\bin\FVP_EB_Cortex-A8 -a D:\workspace\DS-5\.cpptest\calendar\unit-data\current_tubf179707/calendarTest.axf -C coretile.core.semihosting-cmd_line="D:\workspace\DS-5\.cpptest\calendar\unit-data\current_tubf179707/calendarTest.axf --start-after=0" terminal_0: Listening for serial connection on port 5000 terminal_1: Listening for serial connection on port 5001 terminal_3: Listening for serial connection on port 5002 terminal_2: Listening for serial connection on port 5003 WARNING: baseboard.mmc: MMC backing store file mmc.dat could not be used INFO: baseboard.mmc backing store: no image file connected Error: No License found: ERROR: License check failed! Either the license file or the license server could not be found. Please set the environment variable 'ARMLMD_LICENSE_FILE' to your license file location or refer to the ARM_FLEXnet_Guide for instructions on where to obtain a license file, where to install the license file, and how to setup a license server. Error Code : -1 Fatal Error: Call of CADISimulationFactory::Instantiate(..) did not return a CADISimulation. ...完成。 測試日志讀取中... 找不到測試日志文件。: D:\workspace\DS-5\.cpptest\calendar\unit-data\current_tubf179707\cpptest_results.tlog 請確保: 1. 測試可執行文件 "D:\workspace\DS-5\.cpptest\calendar\unit-data\current_tubf179707\calendarTest.axf" 正常構建并運行 2. 當運行測試時所有的依賴 DLL 在 PATH 環境變量中都可用 ...失敗。 對 /calendar 的 "Run DS-5 Test Executable (Software Model)" (執行)由于錯誤而結束。檢查上述日志詳情。 臨時覆蓋率數據清除中... ...完成。
通過創建專用的DS-5測試配置并調整編譯器與鏈接器設置,成功實現了在目標硬件上執行單元測試。該方案有效驗證了代碼的運行時行為,與靜態分析形成互補。Parasoft C/C++test與ARM DS-5的深度集成,為構建高可靠性嵌入式軟件提供了從靜態檢測到動態驗證的完整質量保障體系。
關于慧都
慧都科技(EVGET)成?于2003年,是?家?業數字化解決?案公司,?期專注于軟件、油?與制造?業。公司基于深?的業務理解與管理洞察,以系統化的業務建模驅動技術落地,幫助企業實現智能化運營與?期競爭優勢。
慧都科技作為Parasoft公司在中國區的官方授權合作伙伴,為國內企業提供Parasoft C/C++test產品的正版授權、定制化部署與全生命周期技術支持與服務。我們致力于助力客戶精準貫徹功能安全標準、全面提升軟件開發效率、有效管控項目風險,最終構建符合國際標準的高質量軟件體系。
本站文章除注明轉載外,均為本站原創或翻譯。歡迎任何形式的轉載,但請務必注明出處、不得修改原文相關鏈接,如果存在內容上的異議請郵件反饋至chenjj@ke049m.cn