| 研究生: |
黃筠 Huang, Yun |
|---|---|
| 論文名稱: |
基於虛擬化硬體的自動化物聯網裝置韌體行為驅動測試工具 An Automated Behavior-Driven Testing Tool for IoT Device Firmware Based on Virtualized Hardware |
| 指導教授: |
廖峻鋒
許志堅 |
| 學位類別: |
碩士
Master |
| 系所名稱: |
傳播學院 - 數位內容碩士學位學程 Digital Content and Technologies |
| 論文出版年: | 2026 |
| 畢業學年度: | 114 |
| 語文別: | 中文 |
| 論文頁數: | 73 |
| 中文關鍵詞: | 物聯網 、自動化測試 、行為驅動開發 、Arduino 、虛擬化硬體 |
| 相關次數: | 點閱:4 下載:0 |
| 分享至: |
| 查詢本校圖書館目錄 查詢臺灣博碩士論文知識加值系統 勘誤回報 |
物聯網(Internet of Things, IoT)與人工智慧物聯網(Artificial Intelligence of Things, AIoT)快速發展,使各類感測器、控制器與智慧裝置廣泛應用於資料蒐集、環境監控與即時控制。Arduino 因具備低成本、易於使用及開源生態完整等特性,成為常見的物聯網開發平台。然而,其韌體測試通常依賴實體開發板、外部元件及人工操作,使測試流程難以自動化,也增加重現與維護成本。
為改善上述問題,本研究提出一套基於虛擬化硬體的韌體行為驅動測試工具。其主要特色包括:第一,以 Gherkin 的 Given--When--Then 結構建立可執行的韌體行為規格;第二,建立由底層硬體狀態到行為斷言的觀測機制,將 PWM 波形與硬體狀態轉換為 duty cycle、平均電壓及變化趨勢等可斷言結果;第三,以軟體模組模擬 USART 的資料到達、緩衝區、狀態旗標與中斷觸發等非同步通訊行為;第四,以 CPU cycle 為基礎設計時間推進、執行切片與週期性觀測機制,以支援時間相關韌體行為之驗證。本研究以 Arduino UNO 與 ATmega328P 為驗證平台,將原本依賴實體硬體的事件輸入與狀態觀測,轉換為可控制、可重現且可自動執行的測試流程。
本研究透過測試規格覆蓋度、PWM 輸出觀測準確性、USART 通訊一致性及時間策略消融實驗進行評估。結果顯示,本工具能支援多數 Arduino 官方範例的常見韌體互動情境,並能對 PWM、USART 與時間相關行為提供可重現的測試結果。整體而言,本工具可降低韌體測試對實體設備與人工觀測的依賴,並提升測試流程的自動化、可重現性與可維護性。
第一章緒論. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 1
1.1 研究背景與動機. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 1
1.2 研究目的與問題. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 9
1.2.1 研究目的. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 9
1.2.2 研究問題. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 10
1.3 研究特色與研究流程. . . . . . . . . . . . . . . . . . . . . . . . . . . 10
1.3.1 研究特色. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 10
1.3.2 研究流程. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 12
第二章文獻探討. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 14
2.1 韌體自動化測試. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 14
2.2 軟體測試種類與模擬策略. . . . . . . . . . . . . . . . . . . . . . . . . 16
2.2.1 測試層級與測試目的. . . . . . . . . . . . . . . . . . . . . . . 16
2.2.2 嵌入式系統的測試需求與常見策略. . . . . . . . . . . . . . . 17
2.2.3 測試替身(Test Doubles)之定義與分類. . . . . . . . . . . . 18
iii
2.2.4 本研究系統之測試種類定位與替身策略. . . . . . . . . . . . 22
2.3 驅動開發種類. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 24
2.3.1 Test-Driven Development(TDD) . . . . . . . . . . . . . . . . 24
2.3.2 Behavior-Driven Development(BDD) . . . . . . . . . . . . . 24
2.3.3 Acceptance Test-Driven Development(ATDD)與Specification
by Example(SBE) . . . . . . . . . . . . . . . . . . . . . . . . 25
2.4 既有方法比較與本研究定位. . . . . . . . . . . . . . . . . . . . . . . 26
第三章研究方法. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 28
3.1 系統架構. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 28
3.1.1 測試架構. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 29
3.1.2 系統運作流程. . . . . . . . . . . . . . . . . . . . . . . . . . . 31
3.2 測試規格與測試介面設計. . . . . . . . . . . . . . . . . . . . . . . . . 34
3.2.1 測試需求檔之可執行化設計. . . . . . . . . . . . . . . . . . . 34
3.2.2 動態編譯:由規格內嵌程式生成.hex . . . . . . . . . . . . . 35
3.2.3 測試介面設計. . . . . . . . . . . . . . . . . . . . . . . . . . . 35
3.3 模擬硬體環境執行. . . . . . . . . . . . . . . . . . . . . . . . . . . . . 37
3.3.1 執行器:韌體程式載入與時間推進. . . . . . . . . . . . . . . 38
3.3.2 控制器:事件輸入與狀態觀測的統一. . . . . . . . . . . . . . 38
3.3.3 USART 之通訊與中斷模擬. . . . . . . . . . . . . . . . . . . . 40
3.4 測試案例範例. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 42
3.4.1 測試種類與行為. . . . . . . . . . . . . . . . . . . . . . . . . . 42
3.4.2 典型測試案例實施說明. . . . . . . . . . . . . . . . . . . . . . 44
第四章評估與討論. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 49
4.1 測試規格覆蓋度分析. . . . . . . . . . . . . . . . . . . . . . . . . . . 49
4.1.1 實驗設計. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 50
4.1.2 實驗結果. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 50
4.1.3 討論. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 51
4.2 PWM 輸出觀測準確性. . . . . . . . . . . . . . . . . . . . . . . . . . . 52
4.2.1 實驗設計. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 52
4.2.2 實驗結果. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 54
4.2.3 討論. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 56
4.3 USART 通訊一致性. . . . . . . . . . . . . . . . . . . . . . . . . . . . 58
4.3.1 TX 壓力測試. . . . . . . . . . . . . . . . . . . . . . . . . . . . 58
4.3.2 RX 壓力測試. . . . . . . . . . . . . . . . . . . . . . . . . . . . 59
4.3.3 討論. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 62
4.4 時間推進與觀測策略消融分析. . . . . . . . . . . . . . . . . . . . . . 62
4.4.1 實驗設計. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 63
4.4.2 實驗結果. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 63
4.4.3 討論. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 64
4.5 研究問題討論. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 64
4.5.1 RQ1:Gherkin 與Step Definitions 是否能支援Arduino 韌體
常見互動情境? . . . . . . . . . . . . . . . . . . . . . . . . . . 65
4.5.2 RQ2:在虛擬硬體環境中底層硬體狀態是否能被轉換為可斷
言之行為結果? . . . . . . . . . . . . . . . . . . . . . . . . . . 65
4.5.3 RQ3:軟體機制是否能模擬真實硬體之非同步USART 通訊
行為? . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 66
4.5.4 RQ4:時間推進與觀測策略如何影響測試穩定性? . . . . . . 66
4.6 小結. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 67
第五章結論. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 68
參考文獻. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 70
附錄. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 73
Ahvar, E., Ahvar, S., and Lee, G. M. (2023). Artificial intelligence of things: Architectures, applications, and challenges. Springer Handbook of Internet of Things, pages 443–462.
Bergersen, E. (2013). Embedded unit testing framework. Master’s thesis, Norwegian University of Science and Technology.
Bures, M., Ahmed, B. S., Rechtberger, V., Klima, M., Trnka, M., Jaros, M., Bellekens, X., Almog, D., and Herout, P. (2021). Patriot: Iot automated interoperability and integration testing framework. In 2021 14th IEEE Conference on Software Testing, Verification and Validation (ICST), pages 454–459. IEEE.
Bures, M., Klima, M., Rechtberger, V., Bellekens, X., Tachtatzis, C., Atkinson, R., and Ahmed, B. S. (2020). Interoperability and integration testing methods for iot systems: A systematic mapping study. In International conference on software engineering and formal methods, pages 93–112. Springer.
Hou, K. M., Diao, X., Shi, H., Ding, H., Zhou, H., and De Vaulx, C. (2023). Trends and challenges in aiot/iiot/iot implementation. Sensors, 23(11):5074.
ISO/IEC/IEEE (2021). ISO/IEC/IEEE 29119-4:2021 Software and systems engineering —Software testing —Part 4: Test techniques. Standard.
Karlesky, M., Williams, G., Bereza, W., and Fletcher, M. (2007). Mocking the embedded world: Test-driven development, continuous integration, and design patterns. In Proc. Emb. Systems Conf, CA, USA, pages 1518–1532.
Lan, T.-C. and Liao, C.-F. (2023). Firmataspy: A firmata emulator to streamline interoperable automated testing for iot devices. In 2023 International Conference on Platform Technology and Service (PlatCon), pages 24–29. IEEE.
Lenka, R. K., Kumar, S., and Mamgain, S. (2018). Behavior driven development: Tools and challenges. In 2018 International Conference on Advances in Computing, Communication Control and Networking (ICACCCN), pages 1032–1037. IEEE.
Meszaros, G. (2007). xUnit test patterns: Refactoring test code. Pearson Education.
Meta Platforms, Inc. and Jest Contributors (2024). Jest: Delightful javascript testing. https://jestjs.io/. MIT License. Accessed: 2026-01-16.
Minani, J. B., Sabir, F., Moha, N., and Guéhéneuc, Y.-G. (2024). A systematic review of iot systems testing: Objectives, approaches, tools, and challenges. IEEE Transactions on Software Engineering, 50(4):785–815.
Miner, B. C. (2024). intel-hex: A JavaScript library for parsing and generating Intel HEX files. https://www.npmjs.com/package/intel-hex. Accessed: 2024-05-20.
Murad, G., Badarneh, A., Qusef, A., and Almasalha, F. (2018). Software testing techniques in iot. In 2018 8th International conference on computer science and information technology (CSIT), pages 17–21. IEEE.
Nezhad, A. S., Lukkien, J. J., and Mak, R. H. (2018). Behavior-driven development for real-time embedded systems. In 2018 IEEE 23rd International Conference on Emerging Technologies and Factory Automation (ETFA), volume 1, pages 59–66. IEEE.
Padmanabhan, M. (2022). Test case generation for arduino programming instructions using functional block diagrams. Trends in Sciences, 19(8):3472–3472.
Shaked, U. (2024). AVR8js: An arduino (8-bit avr) simulator in javascript. https://github.com/wokwi/avr8js. MIT License. Accessed: 2026-01-16.
Silva, T. R. (2016). Definition of a behavior-driven model for requirements specification and testing of interactive systems. In 2016 IEEE 24th International Requirements Engineering Conference (RE), pages 444–449. IEEE.
SmartBear Software (2024). Gherkin Reference — cucumber documentation. https://cucumber.io/docs/gherkin/reference/. Accessed: 2026-01-16.
Zafar, M. N., Afzal, W., and Enoiu, E. (2021). Towards a workflow for model-based testing of embedded systems. In Proceedings of the 12th International Workshop on Automating TEST Case Design, Selection, and Evaluation, pages 33–40.