Merge branch 'feature/cmock_component' into 'master'

cmock as component replacing unity

See merge request espressif/esp-idf!9859
This commit is contained in:
Ivan Grokhotkov 2020-09-10 16:06:20 +08:00
commit b6467257b9
59 changed files with 100 additions and 60 deletions

4
.gitmodules vendored
View File

@ -86,3 +86,7 @@
[submodule "examples/peripherals/secure_element/atecc608_ecdsa/components/esp-cryptoauthlib"]
path = examples/peripherals/secure_element/atecc608_ecdsa/components/esp-cryptoauthlib
url = ../../espressif/esp-cryptoauthlib.git
[submodule "components/cmock/CMock"]
path = components/cmock/CMock
url = ../../ThrowTheSwitch/CMock.git

View File

@ -1,3 +1,3 @@
idf_component_register(SRC_DIRS "."
PRIV_INCLUDE_DIRS "."
PRIV_REQUIRES unity)
PRIV_REQUIRES cmock)

View File

@ -1,4 +1,4 @@
idf_component_register(SRC_DIRS "."
PRIV_INCLUDE_DIRS "."
PRIV_REQUIRES unity test_utils app_update bootloader_support nvs_flash
PRIV_REQUIRES cmock test_utils app_update bootloader_support nvs_flash
)

View File

@ -1,3 +1,3 @@
idf_component_register(SRC_DIRS "."
PRIV_INCLUDE_DIRS "."
PRIV_REQUIRES unity bootloader_support app_update)
PRIV_REQUIRES cmock bootloader_support app_update)

View File

@ -1,5 +1,5 @@
if(CONFIG_BT_ENABLED OR CMAKE_BUILD_EARLY_EXPANSION)
idf_component_register(SRC_DIRS "."
PRIV_INCLUDE_DIRS "."
PRIV_REQUIRES unity nvs_flash bt)
PRIV_REQUIRES cmock nvs_flash bt)
endif()

View File

@ -0,0 +1,5 @@
# Although unity is a submodule of cmock, we still depend on the unity component in IDF.
# This is because CI currently doesn't checkout submodules recursively.
idf_component_register(SRCS "CMock/src/cmock.c"
REQUIRES unity
INCLUDE_DIRS "CMock/src")

@ -0,0 +1 @@
Subproject commit eeecc49ce8af123cf8ad40efdb9673e37b56230f

View File

@ -0,0 +1 @@
CPPFLAGS += -DUNITY_INCLUDE_CONFIG_H

View File

@ -0,0 +1,4 @@
#
# Component Makefile
#

View File

@ -1,3 +1,3 @@
idf_component_register(SRC_DIRS .
PRIV_INCLUDE_DIRS .
PRIV_REQUIRES unity test_utils console)
PRIV_REQUIRES cmock test_utils console)

View File

@ -1,3 +1,3 @@
idf_component_register(SRC_DIRS "."
PRIV_INCLUDE_DIRS "."
PRIV_REQUIRES unity)
PRIV_REQUIRES cmock)

View File

@ -1,3 +1,3 @@
idf_component_register(SRC_DIRS . param_test touch_sensor_test adc_dma_test dac_dma_test
PRIV_INCLUDE_DIRS include param_test/include touch_sensor_test/include
PRIV_REQUIRES unity test_utils driver nvs_flash esp_serial_slave_link infrared_tools esp_adc_cal)
PRIV_REQUIRES cmock test_utils driver nvs_flash esp_serial_slave_link infrared_tools esp_adc_cal)

View File

@ -1,5 +1,5 @@
idf_component_register(SRC_DIRS "."
PRIV_INCLUDE_DIRS "." "include"
PRIV_INCLUDE_DIRS "../private_include"
PRIV_REQUIRES unity test_utils efuse bootloader_support
PRIV_REQUIRES cmock test_utils efuse bootloader_support
)

View File

@ -1,7 +1,7 @@
if(IDF_TARGET STREQUAL "esp32")
idf_component_register(SRC_DIRS .
PRIV_INCLUDE_DIRS .
PRIV_REQUIRES unity test_utils nvs_flash ulp esp_common
PRIV_REQUIRES cmock test_utils nvs_flash ulp esp_common
)
target_link_libraries(${COMPONENT_LIB} INTERFACE "-u ld_include_test_dport_xt_highint5")
endif()

View File

@ -1,7 +1,7 @@
if(IDF_TARGET STREQUAL "esp32s2")
idf_component_register(SRC_DIRS .
PRIV_INCLUDE_DIRS .
PRIV_REQUIRES unity test_utils nvs_flash ulp esp_common
PRIV_REQUIRES cmock test_utils nvs_flash ulp esp_common
)
endif()

View File

@ -1,2 +1,3 @@
idf_component_register(SRC_DIRS .
PRIV_REQUIRES unity test_utils spi_flash)
PRIV_REQUIRES cmock test_utils spi_flash
)

View File

@ -1,4 +1,4 @@
idf_component_register(SRC_DIRS .
PRIV_INCLUDE_DIRS .
PRIV_REQUIRES unity test_utils esp_eth esp_http_client
PRIV_REQUIRES cmock test_utils esp_eth esp_http_client
)

View File

@ -1,3 +1,3 @@
idf_component_register(SRC_DIRS "."
PRIV_INCLUDE_DIRS . ../private_include
PRIV_REQUIRES unity test_utils esp_event driver)
PRIV_REQUIRES cmock test_utils esp_event driver)

View File

@ -1,3 +1,3 @@
idf_component_register(SRC_DIRS "."
INCLUDE_DIRS "."
REQUIRES unity test_utils esp_hid)
REQUIRES cmock test_utils esp_hid)

View File

@ -1,3 +1,3 @@
idf_component_register(SRC_DIRS "."
PRIV_INCLUDE_DIRS "."
PRIV_REQUIRES unity test_utils esp_http_client)
PRIV_REQUIRES cmock test_utils esp_http_client)

View File

@ -1,3 +1,3 @@
idf_component_register(SRC_DIRS "."
PRIV_INCLUDE_DIRS "."
PRIV_REQUIRES unity test_utils esp_http_server)
PRIV_REQUIRES cmock test_utils esp_http_server)

View File

@ -1,6 +1,6 @@
if(IDF_TARGET STREQUAL "esp32")
idf_component_register(SRC_DIRS "."
PRIV_INCLUDE_DIRS "."
PRIV_REQUIRES unity test_utils)
PRIV_REQUIRES cmock test_utils)
endif()

View File

@ -1,3 +1,3 @@
idf_component_register(SRC_DIRS "."
PRIV_INCLUDE_DIRS "../private_include" "."
PRIV_REQUIRES unity test_utils esp_netif nvs_flash)
PRIV_REQUIRES cmock test_utils esp_netif nvs_flash)

View File

@ -1,3 +1,3 @@
idf_component_register(SRC_DIRS "."
PRIV_INCLUDE_DIRS "."
PRIV_REQUIRES unity test_utils)
PRIV_REQUIRES cmock test_utils)

View File

@ -1,6 +1,6 @@
idf_component_register(SRC_DIRS .
PRIV_INCLUDE_DIRS . ${CMAKE_CURRENT_BINARY_DIR}
PRIV_REQUIRES unity test_utils)
PRIV_REQUIRES cmock test_utils)
if(IDF_TARGET STREQUAL "esp32")
add_custom_command(OUTPUT "${CMAKE_CURRENT_BINARY_DIR}/test_tjpgd_logo.h"

View File

@ -1,6 +1,6 @@
idf_component_register(SRC_DIRS "."
PRIV_INCLUDE_DIRS "../private_include"
PRIV_REQUIRES unity test_utils)
PRIV_REQUIRES cmock test_utils)
if(CONFIG_ESP_TIMER_IMPL_FRC2)
idf_build_set_property(COMPILE_DEFINITIONS "-DESP_TIMER_DYNAMIC_OVERFLOW_VAL" APPEND)

View File

@ -1,4 +1,4 @@
idf_component_register(SRC_DIRS .
PRIV_INCLUDE_DIRS . ${CMAKE_CURRENT_BINARY_DIR}
PRIV_REQUIRES unity test_utils nvs_flash ulp esp_common
PRIV_REQUIRES cmock test_utils nvs_flash ulp esp_common
)

View File

@ -3,5 +3,5 @@ if(TESTS_ALL EQUAL 1)
else()
idf_component_register(SRC_DIRS "."
PRIV_INCLUDE_DIRS "."
PRIV_REQUIRES unity nvs_flash)
PRIV_REQUIRES cmock nvs_flash)
endif()

View File

@ -1,3 +1,3 @@
idf_component_register(SRC_DIRS "."
PRIV_INCLUDE_DIRS "."
PRIV_REQUIRES unity expat)
PRIV_REQUIRES cmock expat)

View File

@ -1,5 +1,5 @@
idf_component_register(SRC_DIRS .
PRIV_INCLUDE_DIRS .
PRIV_REQUIRES unity test_utils vfs fatfs
PRIV_REQUIRES cmock test_utils vfs fatfs
EMBED_TXTFILES fatfs.img
)

View File

@ -1,4 +1,4 @@
idf_component_register(SRC_DIRS .
PRIV_INCLUDE_DIRS .
PRIV_REQUIRES unity test_utils esp_ipc
PRIV_REQUIRES cmock test_utils esp_ipc
)

View File

@ -1,3 +1,3 @@
idf_component_register(SRC_DIRS "."
PRIV_INCLUDE_DIRS "."
PRIV_REQUIRES unity test_utils heap)
PRIV_REQUIRES cmock test_utils heap)

View File

@ -12,7 +12,7 @@ else()
idf_component_register(SRCS "${TEST_CASES_FILES}" "test_sodium.c"
PRIV_INCLUDE_DIRS "." "${LS_TESTDIR}/../quirks"
PRIV_REQUIRES unity libsodium)
PRIV_REQUIRES cmock libsodium)
# The libsodium test suite is designed to be run each test case as an executable on a desktop computer and uses
# filesytem to write & then compare contents of each file.

View File

@ -1,6 +1,6 @@
idf_component_register(SRC_DIRS "."
PRIV_INCLUDE_DIRS "."
PRIV_REQUIRES unity test_utils mbedtls libsodium
PRIV_REQUIRES cmock test_utils mbedtls libsodium
EMBED_TXTFILES server_cert_chain.pem prvtkey.pem server_cert_bundle)

View File

@ -1,2 +1,2 @@
idf_component_register(SRC_DIRS "."
PRIV_REQUIRES unity test_utils mdns)
PRIV_REQUIRES cmock test_utils mdns)

View File

@ -1,2 +1,2 @@
idf_component_register(SRC_DIRS "."
PRIV_REQUIRES unity test_utils mqtt nvs_flash app_update)
PRIV_REQUIRES cmock test_utils mqtt nvs_flash app_update)

View File

@ -1,3 +1,3 @@
idf_component_register(SRC_DIRS "."
PRIV_INCLUDE_DIRS "."
PRIV_REQUIRES unity test_utils)
PRIV_REQUIRES cmock test_utils)

View File

@ -1,3 +1,3 @@
idf_component_register(SRC_DIRS "."
PRIV_INCLUDE_DIRS "."
PRIV_REQUIRES unity test_utils nvs_flash bootloader_support)
PRIV_REQUIRES cmock test_utils nvs_flash bootloader_support)

View File

@ -1,2 +1,2 @@
idf_component_register(SRC_DIRS "."
PRIV_REQUIRES unity test_utils openssl)
PRIV_REQUIRES cmock test_utils openssl)

View File

@ -1,3 +1,3 @@
idf_component_register(SRC_DIRS "."
PRIV_INCLUDE_DIRS "."
PRIV_REQUIRES unity test_utils)
PRIV_REQUIRES cmock test_utils)

View File

@ -1,3 +1,3 @@
idf_component_register(SRC_DIRS "."
PRIV_INCLUDE_DIRS "."
PRIV_REQUIRES unity xtensa perfmon)
PRIV_REQUIRES cmock xtensa perfmon)

View File

@ -1,4 +1,4 @@
idf_component_register(SRC_DIRS "."
PRIV_INCLUDE_DIRS "."
PRIV_INCLUDE_DIRS "../proto-c/"
PRIV_REQUIRES unity mbedtls protocomm protobuf-c)
PRIV_REQUIRES cmock mbedtls protocomm protobuf-c)

View File

@ -1,3 +1,3 @@
idf_component_register(SRC_DIRS "."
PRIV_INCLUDE_DIRS "."
PRIV_REQUIRES unity test_utils pthread)
PRIV_REQUIRES cmock test_utils pthread)

View File

@ -1,4 +1,4 @@
idf_component_register(SRC_DIRS "."
PRIV_INCLUDE_DIRS "."
PRIV_REQUIRES unity sdmmc
PRIV_REQUIRES cmock sdmmc
)

View File

@ -2,4 +2,4 @@ idf_build_get_property(soc_name IDF_TARGET)
idf_component_register(SRC_DIRS "."
PRIV_INCLUDE_DIRS "${include_dirs}"
PRIV_REQUIRES unity test_utils)
PRIV_REQUIRES cmock test_utils)

View File

@ -5,5 +5,5 @@ endif()
idf_component_register(SRC_DIRS "."
EXCLUDE_SRCS "${exclude_srcs}"
PRIV_INCLUDE_DIRS "."
PRIV_REQUIRES unity test_utils spi_flash bootloader_support app_update)
PRIV_REQUIRES cmock test_utils spi_flash bootloader_support app_update)

View File

@ -1,3 +1,3 @@
idf_component_register(SRC_DIRS "."
PRIV_INCLUDE_DIRS "."
PRIV_REQUIRES unity test_utils spiffs)
PRIV_REQUIRES cmock test_utils spiffs)

View File

@ -1,3 +1,3 @@
idf_component_register(SRC_DIRS "."
PRIV_INCLUDE_DIRS "../private_include" "."
PRIV_REQUIRES unity test_utils tcp_transport)
PRIV_REQUIRES cmock test_utils tcp_transport)

View File

@ -1,6 +1,6 @@
idf_component_register(SRC_DIRS ${IDF_TARGET}
PRIV_INCLUDE_DIRS .
PRIV_REQUIRES unity ulp soc esp_common)
PRIV_REQUIRES cmock ulp soc esp_common)
if(IDF_TARGET STREQUAL "esp32")
set(ulp_sources "ulp/test_jumps_esp32.S")

View File

@ -1,3 +1,3 @@
idf_component_register(SRC_DIRS "."
PRIV_INCLUDE_DIRS .
PRIV_REQUIRES unity test_utils vfs fatfs spiffs)
PRIV_REQUIRES cmock test_utils vfs fatfs spiffs)

View File

@ -1,5 +1,5 @@
idf_component_register(SRC_DIRS .
PRIV_INCLUDE_DIRS .
PRIV_REQUIRES unity test_utils wear_levelling
PRIV_REQUIRES cmock test_utils wear_levelling
EMBED_FILES test_partition_v1.bin
)

View File

@ -1,7 +1,7 @@
idf_component_register(SRC_DIRS "."
PRIV_INCLUDE_DIRS "." "${CMAKE_CURRENT_BINARY_DIR}"
PRIV_INCLUDE_DIRS "../src"
PRIV_REQUIRES unity esp_common test_utils wpa_supplicant mbedtls)
PRIV_REQUIRES cmock esp_common test_utils wpa_supplicant mbedtls)
idf_component_get_property(esp_supplicant_dir wpa_supplicant COMPONENT_DIR)

View File

@ -304,5 +304,26 @@ of time spent on waiting for code/data in case of a cache miss, then subtract th
One limitation of the cache compensated timer is that the task that benchmarked functions should be pinned to a core. This is due to each core having its own event counters that are independent of each other. For example, if ``ccomp_timer_start`` gets called on one core, put to sleep by the scheduler, wakes up, and gets rescheduled on the other core, then the corresponding ``ccomp_timer_stop`` will be invalid.
invalid.
Mocks
-----------------------------------------
ESP-IDF has a component which integrates the CMock mocking framework.
CMock usually uses Unity as a submodule, but due to some Espressif-internal limitations with CI, we still have Unity as an ordinary module in ESP-IDF.
To use the IDF-supplied Unity component which isn't a submodule, the build system needs to pass an environment variable ``UNITY_IDR`` to CMock.
This variable simply contains the path to the Unity directory in IDF, e.g. ``export "UNITY_DIR=${IDF_PATH}/components/unity/unity"``.
Refer to :component_file:`cmock/CMock/lib/cmock_generator.rb` to see how the Unity directory is determined in CMock.
An example cmake build command to create mocks of a component inside that component's CMakeLists.txt may look like this:
.. code-block:: cmake
add_custom_command(
OUTPUT ${MOCK_OUTPUT}
COMMAND ruby ${CMOCK_DIR}/lib/cmock.rb -o${CMAKE_CURRENT_SOURCE_DIR}/mock/mock_config.yaml ${MOCK_HEADERS}
COMMAND ${CMAKE_COMMAND} -E env "UNITY_DIR=${IDF_PATH}/components/unity/unity" ruby ${CMOCK_DIR}/lib/cmock.rb -o${CMAKE_CURRENT_SOURCE_DIR}/mock/mock_config.yaml ${MOCK_HEADERS}
)
${MOCK_OUTPUT} contains all CMock generated output files, ${MOCK_HEADERS} contains all headers to be mocked and ${CMOCK_DIR} needs to be set to CMock directory inside IDF. ${CMAKE_COMMAND} is automatically set.
Refer to :component_file:`cmock/CMock/docs/CMock_Summary.md` for more details on how CMock works and how to create and use mocks.

View File

@ -1,3 +1,3 @@
idf_component_register(SRC_DIRS "."
PRIV_INCLUDE_DIRS .
PRIV_REQUIRES unity test_utils experimental_cpp_component)
PRIV_REQUIRES cmock test_utils experimental_cpp_component)

View File

@ -1,3 +1,3 @@
idf_component_register(SRC_DIRS "."
INCLUDE_DIRS "."
REQUIRES unity testable)
REQUIRES cmock testable)

View File

@ -85,6 +85,9 @@ components/unity/unity/src/unity_internals.h
components/unity/include/unity_config.h
components/unity/include/unity_test_runner.h
components/cmock/CMock/src/cmock.h
components/cmock/CMock/src/cmock_internals.h
### Here are the files that do not compile for some reason
#
components/app_trace/include/esp_sysview_trace.h

View File

@ -45,7 +45,7 @@ ignore_files = ['components/mdns/test_afl_fuzz_host/esp32_compat.h', # us
]
# add directories here which should not be parsed
ignore_dirs = ('examples')
ignore_dirs = ('examples', 'components/cmock/CMock/test')
# macros from here have higher priorities in case of collisions
priority_headers = ['components/esp_common/include/esp_err.h']

View File

@ -5,7 +5,7 @@ idf_component_register(SRCS "ccomp_timer.c"
"ccomp_timer_impl.c"
INCLUDE_DIRS include
PRIV_INCLUDE_DIRS private_include
REQUIRES spi_flash idf_test unity
REQUIRES spi_flash idf_test cmock
PRIV_REQUIRES perfmon esp_ipc)

View File

@ -1,3 +1,3 @@
idf_component_register(SRC_DIRS "."
PRIV_INCLUDE_DIRS "."
PRIV_REQUIRES unity test_utils perfmon esp_ipc)
PRIV_REQUIRES cmock test_utils perfmon esp_ipc)