Merge branch 'ci/migrate_esp-tls_unit_test_app' into 'master'

ci: Migrate esp-tls unit tests from unit-test-app to component-test-app

Closes IDF-5571

See merge request espressif/esp-idf!20099
pull/9803/head
Mahavir Jain 2022-09-16 14:34:44 +08:00
commit 961bdde289
16 zmienionych plików z 105 dodań i 51 usunięć

Wyświetl plik

@ -1,3 +0,0 @@
idf_component_register(SRC_DIRS "."
PRIV_REQUIRES test_utils esp-tls)
target_compile_options(${COMPONENT_LIB} PRIVATE "-Wno-format")

Wyświetl plik

@ -0,0 +1,7 @@
#This is the project CMakeLists.txt file for the test subproject
cmake_minimum_required(VERSION 3.16)
set(EXTRA_COMPONENT_DIRS "$ENV{IDF_PATH}/tools/unit-test-app/components")
include($ENV{IDF_PATH}/tools/cmake/project.cmake)
project(esp-tls_test)

Wyświetl plik

@ -0,0 +1,2 @@
| Supported Targets | ESP32 | ESP32-C2 | ESP32-C3 | ESP32-S2 | ESP32-S3 |
| ----------------- | ----- | -------- | -------- | -------- | -------- |

Wyświetl plik

@ -0,0 +1,3 @@
idf_component_register(SRC_DIRS "."
PRIV_REQUIRES test_utils esp-tls unity
WHOLE_ARCHIVE)

Wyświetl plik

@ -0,0 +1,60 @@
/*
* SPDX-FileCopyrightText: 2021-2022 Espressif Systems (Shanghai) CO LTD
*
* SPDX-License-Identifier: Apache-2.0
*/
#include "freertos/FreeRTOS.h"
#include "freertos/task.h"
#include "unity.h"
#include "memory_checks.h"
#include "soc/soc_caps.h"
#if SOC_SHA_SUPPORT_PARALLEL_ENG
#include "sha/sha_parallel_engine.h"
#elif SOC_SHA_SUPPORT_DMA
#include "sha/sha_dma.h"
#else
#include "sha/sha_block.h"
#endif
#if SOC_SHA_SUPPORT_SHA512
#define SHA_TYPE SHA2_512
#else
#define SHA_TYPE SHA2_256
#endif //SOC_SHA_SUPPORT_SHA512
/* setUp runs before every test */
void setUp(void)
{
// Execute esp_sha operation to allocate internal SHA semaphore memory
// which is considered as leaked otherwise
const uint8_t input_buffer[64] = {0};
uint8_t output_buffer[64];
esp_sha(SHA_TYPE, input_buffer, sizeof(input_buffer), output_buffer);
test_utils_record_free_mem();
TEST_ESP_OK(test_utils_set_leak_level(0, ESP_LEAK_TYPE_CRITICAL, ESP_COMP_LEAK_GENERAL));
TEST_ESP_OK(test_utils_set_leak_level(0, ESP_LEAK_TYPE_WARNING, ESP_COMP_LEAK_GENERAL));
}
/* tearDown runs after every test */
void tearDown(void)
{
/* some FreeRTOS stuff is cleaned up by idle task */
vTaskDelay(5);
/* clean up some of the newlib's lazy allocations */
esp_reent_cleanup();
/* check if unit test has caused heap corruption in any heap */
TEST_ASSERT_MESSAGE( heap_caps_check_integrity(MALLOC_CAP_INVALID, true), "The test has corrupted the heap");
test_utils_finish_and_evaluate_leaks(test_utils_get_leak_level(ESP_LEAK_TYPE_WARNING, ESP_COMP_LEAK_ALL),
test_utils_get_leak_level(ESP_LEAK_TYPE_CRITICAL, ESP_COMP_LEAK_ALL));
}
void app_main(void)
{
unity_run_menu();
}

Wyświetl plik

@ -11,14 +11,6 @@
#include "esp_log.h"
#include "esp_mac.h"
#include "sys/socket.h"
#if SOC_SHA_SUPPORT_PARALLEL_ENG
#include "sha/sha_parallel_engine.h"
#elif SOC_SHA_SUPPORT_DMA
#include "sha/sha_dma.h"
#else
#include "sha/sha_block.h"
#endif
#include "test_utils.h"
const char *test_cert_pem = "-----BEGIN CERTIFICATE-----\n"\
"MIICrDCCAZQCCQD88gCs5AFs/jANBgkqhkiG9w0BAQsFADAYMRYwFAYDVQQDDA1F\n"\
@ -67,40 +59,16 @@ const char *test_key_pem = "-----BEGIN PRIVATE KEY-----\n"\
"Aogx44Fozd1t2hYcozPuZD4s\n"\
"-----END PRIVATE KEY-----\n";
#if SOC_SHA_SUPPORT_SHA512
#define SHA_TYPE SHA2_512
#else
#define SHA_TYPE SHA2_256
#endif //SOC_SHA_SUPPORT_SHA512
static void test_leak_setup(const char *file, long line)
TEST_CASE("esp-tls init deinit", "[esp-tls]")
{
uint8_t mac[6];
struct timeval te;
gettimeofday(&te, NULL); // get current time
esp_read_mac(mac, ESP_MAC_WIFI_STA);
printf("%s:%ld: time=%jd.%lds, mac:" MACSTR "\n", file, line, (intmax_t)te.tv_sec, te.tv_usec, MAC2STR(mac));
// Execute esp_sha operation to allocate internal SHA semaphore memory
// which is considered as leaked otherwise
const uint8_t input_buffer[64];
uint8_t output_buffer[64];
esp_sha(SHA_TYPE, input_buffer, sizeof(input_buffer), output_buffer);
test_utils_record_free_mem();
}
TEST_CASE("esp-tls init deinit", "[esp-tls][leaks=0]")
{
test_leak_setup(__FILE__, __LINE__);
struct esp_tls *tls = esp_tls_init();
TEST_ASSERT_NOT_NULL(tls);
int ret = esp_tls_conn_destroy(tls);
TEST_ASSERT_EQUAL(0, ret);
}
TEST_CASE("esp-tls global_ca_store set free", "[esp-tls][leaks=0]")
TEST_CASE("esp-tls global_ca_store set free", "[esp-tls]")
{
test_leak_setup(__FILE__, __LINE__);
esp_err_t ret = esp_tls_init_global_ca_store();
TEST_ASSERT_EQUAL(ESP_OK, ret);
ret = esp_tls_set_global_ca_store((const unsigned char *)test_cert_pem, strlen(test_cert_pem) + 1);
@ -109,9 +77,8 @@ TEST_CASE("esp-tls global_ca_store set free", "[esp-tls][leaks=0]")
}
#ifdef CONFIG_ESP_TLS_SERVER
TEST_CASE("esp_tls_server session create delete", "[esp-tls][leaks=0]")
TEST_CASE("esp_tls_server session create delete", "[esp-tls]")
{
test_leak_setup(__FILE__, __LINE__);
struct esp_tls *tls = esp_tls_init();
TEST_ASSERT_NOT_NULL(tls);
esp_tls_cfg_server_t cfg = {
@ -126,5 +93,6 @@ TEST_CASE("esp_tls_server session create delete", "[esp-tls][leaks=0]")
TEST_ASSERT_LESS_THAN_INT(0, ret);
// free the allocated memory.
esp_tls_server_session_delete(tls);
}
#endif

Wyświetl plik

@ -0,0 +1,12 @@
# SPDX-FileCopyrightText: 2021-2022 Espressif Systems (Shanghai) CO LTD
# SPDX-License-Identifier: Apache-2.0
import pytest
from pytest_embedded import Dut
@pytest.mark.supported_targets
@pytest.mark.generic
def test_esp_tls(dut: Dut) -> None:
dut.expect_exact('Press ENTER to see the list of tests')
dut.write('*')
dut.expect_unity_test_output()

Wyświetl plik

@ -0,0 +1,10 @@
# General options for additional checks
CONFIG_HEAP_POISONING_COMPREHENSIVE=y
CONFIG_COMPILER_WARN_WRITE_STRINGS=y
CONFIG_BOOTLOADER_LOG_LEVEL_WARN=y
CONFIG_FREERTOS_WATCHPOINT_END_OF_STACK=y
CONFIG_COMPILER_STACK_CHECK_MODE_STRONG=y
CONFIG_COMPILER_STACK_CHECK=y
CONFIG_ESP_TASK_WDT=n
CONFIG_ESP_TLS_SERVER=y

Wyświetl plik

@ -1,3 +1,3 @@
# This config is split between targets since different component needs to be excluded (esp32, esp32s2)
CONFIG_IDF_TARGET="esp32"
TEST_EXCLUDE_COMPONENTS=bt app_update freertos esp_hw_support esp_ipc esp_pm esp_system esp_timer driver heap pthread soc spi_flash vfs test_utils experimental_cpp_component esp-tls
TEST_EXCLUDE_COMPONENTS=bt app_update freertos esp_hw_support esp_ipc esp_pm esp_system esp_timer driver heap pthread soc spi_flash vfs test_utils experimental_cpp_component

Wyświetl plik

@ -1,3 +1,3 @@
# This config is split between targets since different component needs to be excluded
CONFIG_IDF_TARGET="esp32c3"
TEST_EXCLUDE_COMPONENTS=bt app_update esp_pm freertos esp_hw_support esp_ipc esp_system esp_timer driver heap pthread soc spi_flash vfs lwip spiffs experimental_cpp_component perfmon esp-tls test_utils
TEST_EXCLUDE_COMPONENTS=bt app_update esp_pm freertos esp_hw_support esp_ipc esp_system esp_timer driver heap pthread soc spi_flash vfs lwip spiffs experimental_cpp_component perfmon test_utils

Wyświetl plik

@ -1,3 +1,3 @@
# This config is split between targets since different component needs to be excluded (esp32, esp32s2)
CONFIG_IDF_TARGET="esp32s2"
TEST_EXCLUDE_COMPONENTS=bt app_update freertos esp_hw_support esp_ipc esp_pm esp_system esp_timer driver heap pthread soc spi_flash vfs experimental_cpp_component esp-tls
TEST_EXCLUDE_COMPONENTS=bt app_update freertos esp_hw_support esp_ipc esp_pm esp_system esp_timer driver heap pthread soc spi_flash vfs experimental_cpp_component

Wyświetl plik

@ -1,3 +1,3 @@
# This config is split between targets since different component needs to be excluded (esp32, esp32s2)
CONFIG_IDF_TARGET="esp32s3"
TEST_EXCLUDE_COMPONENTS=bt app_update freertos esp32s3 esp_ipc esp_pm esp_system esp_timer driver heap pthread soc spi_flash vfs experimental_cpp_component esp-tls test_utils
TEST_EXCLUDE_COMPONENTS=bt app_update freertos esp32s3 esp_ipc esp_pm esp_system esp_timer driver heap pthread soc spi_flash vfs experimental_cpp_component test_utils

Wyświetl plik

@ -1,5 +0,0 @@
# As this is protocol specific, only test for one target.
CONFIG_IDF_TARGET="esp32"
TEST_COMPONENTS=esp-tls
TEST_EXCLUDE_COMPONENTS=bt
CONFIG_ESP_TLS_SERVER=y

Wyświetl plik

@ -1,5 +1,5 @@
CONFIG_IDF_TARGET="esp32"
TEST_EXCLUDE_COMPONENTS=bt app_update driver esp_hw_support esp_ipc esp_pm esp_system esp_timer mbedtls spi_flash test_utils heap pthread soc experimental_cpp_component esp-tls freertos sdmmc
TEST_EXCLUDE_COMPONENTS=bt app_update driver esp_hw_support esp_ipc esp_pm esp_system esp_timer mbedtls spi_flash test_utils heap pthread soc experimental_cpp_component freertos sdmmc
CONFIG_SPIRAM=y
CONFIG_ESP_INT_WDT_TIMEOUT_MS=800
CONFIG_SPIRAM_OCCUPY_NO_HOST=y

Wyświetl plik

@ -1,6 +1,6 @@
# This config is split between targets since different component needs to be included (esp32, esp32s2)
CONFIG_IDF_TARGET="esp32"
TEST_EXCLUDE_COMPONENTS=bt app_update freertos esp_hw_support esp_ipc esp_pm esp_system esp_timer driver heap pthread soc spi_flash vfs test_utils experimental_cpp_component esp-tls
TEST_EXCLUDE_COMPONENTS=bt app_update freertos esp_hw_support esp_ipc esp_pm esp_system esp_timer driver heap pthread soc spi_flash vfs test_utils experimental_cpp_component
CONFIG_COMPILER_OPTIMIZATION_SIZE=y
CONFIG_BOOTLOADER_COMPILER_OPTIMIZATION_SIZE=y
CONFIG_COMPILER_OPTIMIZATION_ASSERTIONS_SILENT=y

Wyświetl plik

@ -1,6 +1,6 @@
# This config is split between targets since different component needs to be excluded (esp32, esp32s2)
CONFIG_IDF_TARGET="esp32"
TEST_EXCLUDE_COMPONENTS=bt app_update freertos esp_hw_support esp_system esp_pm esp_ipc esp_timer driver heap pthread soc spi_flash vfs test_utils experimental_cpp_component esp-tls
TEST_EXCLUDE_COMPONENTS=bt app_update freertos esp_hw_support esp_system esp_pm esp_ipc esp_timer driver heap pthread soc spi_flash vfs test_utils experimental_cpp_component
CONFIG_MEMMAP_SMP=n
CONFIG_FREERTOS_UNICORE=y
CONFIG_ESP32_RTCDATA_IN_FAST_MEM=y