cmock: added cmock as component

* changing dependencies from unity->cmock
* added component.mk and Makefile.projbuild
* ignore test dir in gen_esp_err_to_name.py
* added some brief introduction of CMock in IDF
pull/5919/head
Jakob Hasse 2020-08-05 10:16:32 +08:00
rodzic 5c5c7c4449
commit 20c068ef3b
59 zmienionych plików z 100 dodań i 60 usunięć

4
.gitmodules vendored
Wyświetl plik

@ -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

Wyświetl plik

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

Wyświetl plik

@ -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
)

Wyświetl plik

@ -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)

Wyświetl plik

@ -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)
endif()
PRIV_REQUIRES cmock nvs_flash bt)
endif()

Wyświetl plik

@ -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

Wyświetl plik

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

Wyświetl plik

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

Wyświetl plik

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

Wyświetl plik

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

Wyświetl plik

@ -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)

Wyświetl plik

@ -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
)

Wyświetl plik

@ -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()

Wyświetl plik

@ -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()

Wyświetl plik

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

Wyświetl plik

@ -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
)

Wyświetl plik

@ -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)

Wyświetl plik

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

Wyświetl plik

@ -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)

Wyświetl plik

@ -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)

Wyświetl plik

@ -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()

Wyświetl plik

@ -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)

Wyświetl plik

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

Wyświetl plik

@ -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"

Wyświetl plik

@ -1,7 +1,7 @@
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)
endif()
endif()

Wyświetl plik

@ -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
)

Wyświetl plik

@ -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()

Wyświetl plik

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

Wyświetl plik

@ -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
)

Wyświetl plik

@ -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
)

Wyświetl plik

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

Wyświetl plik

@ -2,7 +2,7 @@ if(TESTS_ALL EQUAL 1)
message("not linking libsodium tests, use '-T libsodium' to test it")
else()
get_filename_component(LS_TESTDIR "${CMAKE_CURRENT_LIST_DIR}/../libsodium/test/default" ABSOLUTE)
set(TEST_CASES "chacha20;aead_chacha20poly1305;box;box2;ed25519_convert;sign;hash")
foreach(test_case ${TEST_CASES})
@ -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.
@ -33,4 +33,4 @@ else()
# this seems odd, but it prevents the libsodium test harness from
# trying to write to a file!
add_definitions(-DBROWSER_TESTS)
endif()
endif()

Wyświetl plik

@ -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)

Wyświetl plik

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

Wyświetl plik

@ -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)

Wyświetl plik

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

Wyświetl plik

@ -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)

Wyświetl plik

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

Wyświetl plik

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

Wyświetl plik

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

Wyświetl plik

@ -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)

Wyświetl plik

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

Wyświetl plik

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

Wyświetl plik

@ -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)

Wyświetl plik

@ -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)

Wyświetl plik

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

Wyświetl plik

@ -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)

Wyświetl plik

@ -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")

Wyświetl plik

@ -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)

Wyświetl plik

@ -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
)

Wyświetl plik

@ -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)

Wyświetl plik

@ -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.

Wyświetl plik

@ -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)

Wyświetl plik

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

Wyświetl plik

@ -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

Wyświetl plik

@ -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']

Wyświetl plik

@ -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)

Wyświetl plik

@ -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)