- Refactor reset_channels_to_idle_state to reset_channels_to_defaults and enhance functionality with direction reset logic. This is because some tilt test cases were failing due to modified run limit values in some of the previous core test cases. See #1089-3. - A relay channel listener has been added to diagnose channel states during tests. Refs #1089
110 lines
2.8 KiB
C
110 lines
2.8 KiB
C
|
|
#include <stdbool.h>
|
|
#include "esp_log.h"
|
|
#include "esp_system.h"
|
|
#include "unity.h"
|
|
#include "unity_internals.h"
|
|
#include "unity_test_runner.h"
|
|
#include "test_common.h"
|
|
|
|
#if CONFIG_RELAY_CHN_ENABLE_NVS
|
|
#include "nvs_flash.h"
|
|
#include "relay_chn_nvs.h"
|
|
#endif
|
|
|
|
|
|
#ifndef RELAY_CHN_UNITY_TEST_GROUP_TAG
|
|
#warning "RELAY_CHN_UNITY_TEST_GROUP_TAG is not defined, using default 'relay_chn'"
|
|
#define RELAY_CHN_UNITY_TEST_GROUP_TAG "relay_chn"
|
|
#endif
|
|
|
|
void setUp()
|
|
{
|
|
|
|
}
|
|
|
|
void tearDown()
|
|
{
|
|
reset_channels_to_defaults();
|
|
}
|
|
|
|
#if CONFIG_RELAY_CHN_ENABLE_NVS
|
|
static void test_nvs_flash_init(void)
|
|
{
|
|
esp_err_t ret;
|
|
#if CONFIG_RELAY_CHN_NVS_CUSTOM_PARTITION
|
|
ret = nvs_flash_init_partition(CONFIG_RELAY_CHN_NVS_CUSTOM_PARTITION_NAME);
|
|
ESP_LOGI(TEST_TAG, "test_nvs_flash_init: NVS flash init partition return: %s", esp_err_to_name(ret));
|
|
if (ret == ESP_ERR_NVS_NO_FREE_PAGES || ret == ESP_ERR_NVS_NEW_VERSION_FOUND) {
|
|
// NVS partition is truncated and needs to be erased
|
|
ret = nvs_flash_erase_partition(CONFIG_RELAY_CHN_NVS_CUSTOM_PARTITION_NAME);
|
|
if (ret == ESP_OK) {
|
|
ret = nvs_flash_init_partition(CONFIG_RELAY_CHN_NVS_CUSTOM_PARTITION_NAME);
|
|
}
|
|
}
|
|
#else
|
|
ret = nvs_flash_init();
|
|
ESP_LOGI(TEST_TAG, "test_nvs_flash_init: NVS flash init return: %s", esp_err_to_name(ret));
|
|
if (ret == ESP_ERR_NVS_NO_FREE_PAGES || ret == ESP_ERR_NVS_NEW_VERSION_FOUND) {
|
|
// NVS partition is truncated and needs to be erased
|
|
ret = nvs_flash_erase();
|
|
if (ret == ESP_OK) {
|
|
ret = nvs_flash_init();
|
|
}
|
|
}
|
|
#endif
|
|
TEST_ESP_OK(ret);
|
|
}
|
|
#endif
|
|
|
|
#if CONFIG_RELAY_CHN_ENABLE_NVS
|
|
static void test_nvs_flash_deinit(void)
|
|
{
|
|
esp_err_t ret;
|
|
#if CONFIG_RELAY_CHN_NVS_CUSTOM_PARTITION
|
|
ret = nvs_flash_deinit_partition(CONFIG_RELAY_CHN_NVS_CUSTOM_PARTITION_NAME);
|
|
#else
|
|
ret = nvs_flash_deinit();
|
|
#endif
|
|
TEST_ESP_OK(ret);
|
|
}
|
|
#endif
|
|
|
|
void app_main(void)
|
|
{
|
|
#if CONFIG_RELAY_CHN_ENABLE_NVS
|
|
// Init NVS once for all tests
|
|
test_nvs_flash_init();
|
|
#endif
|
|
|
|
// Create relay_chn once for all tests
|
|
TEST_ESP_OK(relay_chn_create(gpio_map, gpio_count));
|
|
|
|
UNITY_BEGIN();
|
|
|
|
// Log general test information
|
|
ESP_LOGI(TEST_TAG, "Available test count: %d", unity_get_test_count());
|
|
ESP_LOGI(TEST_TAG, "Running tests for tag: %s", RELAY_CHN_UNITY_TEST_GROUP_TAG);
|
|
|
|
if (strncmp(RELAY_CHN_UNITY_TEST_GROUP_TAG, "all", strlen("all")) == 0) {
|
|
unity_run_all_tests();
|
|
}
|
|
else {
|
|
unity_run_tests_by_tag(RELAY_CHN_UNITY_TEST_GROUP_TAG, false);
|
|
}
|
|
|
|
UNITY_END();
|
|
|
|
// Destroy relay_chn
|
|
relay_chn_destroy();
|
|
|
|
#if CONFIG_RELAY_CHN_ENABLE_NVS
|
|
// Deinit NVS
|
|
test_nvs_flash_deinit();
|
|
#endif
|
|
|
|
ESP_LOGI(TEST_TAG, "All tests complete.");
|
|
|
|
esp_restart(); // Restart to invoke qemu exit
|
|
}
|