前言

单元测试是软件开发过程中非常重要的一环,只有“基础”牢固了,系统这座“大厦”才能稳定运行(抄自知乎)。

一、cmocka是什么?

cmocka is an elegant unit testing framework for C with support for mock objects. It only requires the standard C library, works on a range of computing platforms (including embedded) and with different compilers.

Features:

Tests written with cmocka are compiled into stand-alone executables and linked with the CMock library, the standard C library and module being tested. Any symbols external to the module being tested should be mocked - replaced with functions that return values determined by the test - within the test application. Even though significant differences may exist between the target execution environment of a code module and the environment used to test the code the unit testing is still valid since its goal is to test the logic of a code modules at a functional level and not necessarily all of its interactions with the target execution environment.

The CMocka library provides:

  • Support for mock objects.
  • Test fixtures.
  • Only requires a C library
  • Exception handling for signals (SIGSEGV, SIGILL, ...)
  • No use of fork()
  • Very well tested
  • Testing of memory leaks, buffer overflows and underflows.
  • A set of assert macros.
  • Several supported output formats (stdout, TAP, JUnit XML, Subunit)
  • License: Apache License 2.0

二、使用步骤

cmocka官网

cmocka使用说明

cmocka API说明


总结

Logo

openvela 操作系统专为 AIoT 领域量身定制,以轻量化、标准兼容、安全性和高度可扩展性为核心特点。openvela 以其卓越的技术优势,已成为众多物联网设备和 AI 硬件的技术首选,涵盖了智能手表、运动手环、智能音箱、耳机、智能家居设备以及机器人等多个领域。

更多推荐