From 48ce5d7c018d428ab0d6d6580f9df1582c18730c Mon Sep 17 00:00:00 2001 From: wangyuanze Date: Mon, 8 Aug 2022 14:42:59 +0800 Subject: [PATCH 1/3] touch: adapt touch-related code to compile with -Wno-format flag --- .../test/touch_sensor_test/test_touch_v2.c | 91 ++++++++++--------- components/touch_element/CMakeLists.txt | 1 - components/touch_element/touch_button.c | 1 + components/touch_element/touch_element.c | 9 +- components/touch_element/touch_matrix.c | 7 +- 5 files changed, 56 insertions(+), 53 deletions(-) diff --git a/components/driver/test/touch_sensor_test/test_touch_v2.c b/components/driver/test/touch_sensor_test/test_touch_v2.c index 7424c8afe7..5ddd7cbe4a 100644 --- a/components/driver/test/touch_sensor_test/test_touch_v2.c +++ b/components/driver/test/touch_sensor_test/test_touch_v2.c @@ -11,6 +11,7 @@ #if CONFIG_IDF_TARGET_ESP32S2 || CONFIG_IDF_TARGET_ESP32S3 #include +#include #include "esp_system.h" #include "driver/touch_pad.h" #include "unity.h" @@ -114,7 +115,7 @@ static void printf_touch_hw_read(const char *str) printf("[%s] ", str); for (int i = 0; i < TEST_TOUCH_CHANNEL; i++) { touch_pad_read_raw_data(touch_list[i], &touch_value); - printf("[%d]%d ", touch_list[i], touch_value); + printf("[%d]%"PRIu32" ", touch_list[i], touch_value); } printf("\r\n"); } @@ -125,7 +126,7 @@ static void printf_touch_benchmark_read(const char *str) printf("[%s] ", str); for (int i = 0; i < TEST_TOUCH_CHANNEL; i++) { TEST_ESP_OK( touch_pad_read_benchmark(touch_list[i], &touch_value) ); - printf("[%d]%d ", touch_list[i], touch_value); + printf("[%d]%"PRIu32" ", touch_list[i], touch_value); } printf("\r\n"); } @@ -136,7 +137,7 @@ static void printf_touch_smooth_read(const char *str) printf("[%s] ", str); for (int i = 0; i < TEST_TOUCH_CHANNEL; i++) { touch_pad_filter_read_smooth(touch_list[i], &touch_value); - printf("[%d]%d ", touch_list[i], touch_value); + printf("[%d]%"PRIu32" ", touch_list[i], touch_value); } printf("\r\n"); } @@ -227,7 +228,7 @@ esp_err_t test_touch_sw_read(void) TEST_ESP_OK( touch_pad_sw_start() ); while (!touch_pad_meas_is_done()) ; TEST_ESP_OK( touch_pad_read_raw_data(touch_list[i], &touch_value[i]) ); - printf("T%d:[%4d] ", touch_list[i], touch_value[i]); + printf("T%d:[%4"PRIu32"] ", touch_list[i], touch_value[i]); TEST_ASSERT_NOT_EQUAL(TOUCH_READ_INVALID_VAL, touch_value[i]); } printf("\n"); @@ -246,7 +247,7 @@ esp_err_t test_touch_sw_read(void) TEST_ESP_OK( touch_pad_sw_start() ); while (!touch_pad_meas_is_done()) ; TEST_ESP_OK( touch_pad_read_raw_data(touch_list[i], &touch_push[i]) ); - printf("T%d:[%4d] ", touch_list[i], touch_push[i]); + printf("T%d:[%4"PRIu32"] ", touch_list[i], touch_push[i]); TEST_ASSERT_NOT_EQUAL(TOUCH_READ_INVALID_VAL, touch_push[i]); } printf("\n"); @@ -298,7 +299,7 @@ esp_err_t test_touch_timer_read(void) for (int i = 0; i < TEST_TOUCH_CHANNEL; i++) { TEST_ESP_OK( touch_pad_read_raw_data(touch_list[i], &touch_value[i]) ); TEST_ASSERT_NOT_EQUAL(TOUCH_READ_INVALID_VAL, touch_value[i]); - printf("T%d:[%4d] ", touch_list[i], touch_value[i]); + printf("T%d:[%4"PRIu32"] ", touch_list[i], touch_value[i]); } printf("\n"); for (int i = 0; i < TEST_TOUCH_CHANNEL; i++) { @@ -314,7 +315,7 @@ esp_err_t test_touch_timer_read(void) /* Read the touch sensor raw data in FSM mode. */ for (int i = 0; i < TEST_TOUCH_CHANNEL; i++) { TEST_ESP_OK( touch_pad_read_raw_data(touch_list[i], &touch_push[i]) ); - printf("T%d:[%4d] ", touch_list[i], touch_push[i]); + printf("T%d:[%4"PRIu32"] ", touch_list[i], touch_push[i]); TEST_ASSERT_NOT_EQUAL(TOUCH_READ_INVALID_VAL, touch_push[i]); } printf("\n"); @@ -472,7 +473,7 @@ int test_touch_base_parameter(touch_pad_t pad_num, int meas_time, int slp_time, } touch_temp = touch_value; - printf("T%d:[%4d] ", pad_num, touch_value); + printf("T%d:[%4"PRIu32"] ", pad_num, touch_value); val_sum += touch_value; // For check. vTaskDelay(20 / portTICK_PERIOD_MS); } @@ -544,7 +545,7 @@ static esp_err_t test_touch_check_ch_touched(uint32_t test_ch_num, uint32_t exce while (1) { if (pdTRUE == xQueueReceive(que_touch, &evt, exceed_time_ms / portTICK_PERIOD_MS)) { if (evt.intr_mask & TOUCH_PAD_INTR_MASK_ACTIVE) { - printf("0x%x, ", evt.pad_status); + printf("0x%"PRIx32", ", evt.pad_status); if (test_ch_num == __builtin_popcount(evt.pad_status)) { ret = ESP_OK; break; @@ -552,7 +553,7 @@ static esp_err_t test_touch_check_ch_touched(uint32_t test_ch_num, uint32_t exce } else if (evt.intr_mask & (TOUCH_PAD_INTR_MASK_DONE | TOUCH_PAD_INTR_MASK_SCAN_DONE)) { continue; } else { // If the interrupt type error, test error. - ESP_LOGI(TAG, "Touch[%d] intr error, status %d, evt_msk0x%x", evt.pad_num, evt.pad_status, evt.intr_mask); + ESP_LOGI(TAG, "Touch[%"PRIu32"] intr error, status %"PRIx32", evt_msk0x%x", evt.pad_num, evt.pad_status, evt.intr_mask); break; } } else { @@ -575,7 +576,7 @@ static esp_err_t test_touch_check_ch_released(uint32_t test_ch_num, uint32_t exc while (1) { if (pdTRUE == xQueueReceive(que_touch, &evt, exceed_time_ms / portTICK_PERIOD_MS)) { if (evt.intr_mask & TOUCH_PAD_INTR_MASK_INACTIVE) { - printf("0x%x, ", evt.pad_status); + printf("0x%"PRIx32", ", evt.pad_status); if ((TEST_TOUCH_CHANNEL - test_ch_num) == __builtin_popcount(evt.pad_status)) { ret = ESP_OK; break; @@ -583,7 +584,7 @@ static esp_err_t test_touch_check_ch_released(uint32_t test_ch_num, uint32_t exc } else if (evt.intr_mask & (TOUCH_PAD_INTR_MASK_DONE | TOUCH_PAD_INTR_MASK_SCAN_DONE)) { continue; } else { // If the interrupt type error, test error. - ESP_LOGI(TAG, "Touch[%d] intr error, status %d, evt_msk0x%x", evt.pad_num, evt.pad_status, evt.intr_mask); + ESP_LOGI(TAG, "Touch[%"PRIu32"] intr error, status %"PRIx32", evt_msk0x%x", evt.pad_num, evt.pad_status, evt.intr_mask); break; } } else { @@ -607,7 +608,7 @@ static esp_err_t test_touch_check_ch_touched_with_proximity(uint32_t test_ch_num while (1) { if (pdTRUE == xQueueReceive(que_touch, &evt, exceed_time_ms / portTICK_PERIOD_MS)) { if (evt.intr_mask & TOUCH_PAD_INTR_MASK_ACTIVE) { - printf("0x%x, ", evt.pad_status); + printf("0x%"PRIx32", ", evt.pad_status); if (test_ch_num == __builtin_popcount(evt.pad_status)) { ret = ESP_OK; break; @@ -618,14 +619,14 @@ static esp_err_t test_touch_check_ch_touched_with_proximity(uint32_t test_ch_num if (BIT(i) & ch_mask) { if (evt.pad_num == i) { if (count == evt.slp_proxi_cnt) { - esp_rom_printf("priximity base(%d) cnt(%d)\n", evt.slp_proxi_base, evt.slp_proxi_cnt); + esp_rom_printf("priximity base(%"PRIu32") cnt(%"PRIu32")\n", evt.slp_proxi_base, evt.slp_proxi_cnt); } } } } continue; } else { // If the interrupt type error, test error. - ESP_LOGI(TAG, "Touch[%d] intr error, status %d, evt_msk0x%x", evt.pad_num, evt.pad_status, evt.intr_mask); + ESP_LOGI(TAG, "Touch[%"PRIu32"] intr error, status %"PRIx32", evt_msk0x%x", evt.pad_num, evt.pad_status, evt.intr_mask); continue;; } } else { @@ -649,7 +650,7 @@ static esp_err_t test_touch_check_ch_released_with_proximity(uint32_t test_ch_nu while (1) { if (pdTRUE == xQueueReceive(que_touch, &evt, exceed_time_ms / portTICK_PERIOD_MS)) { if (evt.intr_mask & TOUCH_PAD_INTR_MASK_INACTIVE) { - printf("0x%x, ", evt.pad_status); + printf("0x%"PRIx32", ", evt.pad_status); if ((TEST_TOUCH_CHANNEL - test_ch_num) == __builtin_popcount(evt.pad_status)) { ret = ESP_OK; break; @@ -660,14 +661,14 @@ static esp_err_t test_touch_check_ch_released_with_proximity(uint32_t test_ch_nu if (BIT(i) & ch_mask) { if (evt.pad_num == i) { if (count == evt.slp_proxi_cnt) { - esp_rom_printf("priximity base(%d) cnt(%d)\n", evt.slp_proxi_base, evt.slp_proxi_cnt); + esp_rom_printf("priximity base(%"PRIu32") cnt(%"PRIu32")\n", evt.slp_proxi_base, evt.slp_proxi_cnt); } } } } continue; } else { // If the interrupt type error, test error. - ESP_LOGI(TAG, "Touch[%d] intr error, status %d, evt_msk0x%x", evt.pad_num, evt.pad_status, evt.intr_mask); + ESP_LOGI(TAG, "Touch[%"PRIu32"] intr error, status %"PRIx32", evt_msk0x%x", evt.pad_num, evt.pad_status, evt.intr_mask); continue;; } } else { @@ -705,7 +706,7 @@ static esp_err_t test_touch_check_ch_intr_scan_done(void) } else if (evt.intr_mask & (TOUCH_PAD_INTR_MASK_DONE | TOUCH_PAD_INTR_MASK_SCAN_DONE)) { continue; } else { // If the interrupt type error, test error. - ESP_LOGI(TAG, "Touch[%d] intr error, status %d, evt_msk0x%x", evt.pad_num, evt.pad_status, evt.intr_mask); + ESP_LOGI(TAG, "Touch[%"PRIu32"] intr error, status %"PRIx32", evt_msk0x%x", evt.pad_num, evt.pad_status, evt.intr_mask); break; } } else { @@ -737,7 +738,7 @@ static esp_err_t test_touch_check_ch_intr_timeout(touch_pad_t pad_num) touch_pad_timeout_resume(); break; } else { - esp_rom_printf("-timeout %x T[%d] status %d, evt_msk %x -\n", + esp_rom_printf("-timeout %x T[%"PRIu32"] status %"PRIx32", evt_msk %x -\n", s_touch_timeout_mask, evt.pad_num, evt.pad_status, evt.intr_mask); touch_pad_timeout_resume(); } @@ -832,7 +833,7 @@ esp_err_t test_touch_interrupt(void) TEST_ESP_OK( touch_pad_read_benchmark(touch_list[i], &touch_value) ); TEST_ESP_OK( touch_pad_filter_read_smooth(touch_list[i], &smooth) ); TEST_ESP_OK( touch_pad_set_thresh(touch_list[i], touch_value * TOUCH_INTR_THRESHOLD) ); - ESP_LOGI(TAG, "test init: touch pad [%d] base %d, smooth %d, thresh %d", + ESP_LOGI(TAG, "test init: touch pad [%d] base %"PRIu32", smooth %"PRIu32", thresh %"PRIu32"", touch_list[i], touch_value, smooth, (uint32_t)(touch_value * TOUCH_INTR_THRESHOLD)); } @@ -900,7 +901,7 @@ esp_err_t test_touch_scan_done_interrupt(void) TEST_ESP_OK( touch_pad_read_benchmark(touch_list[i], &touch_value) ); TEST_ESP_OK( touch_pad_filter_read_smooth(touch_list[i], &smooth) ); TEST_ESP_OK( touch_pad_set_thresh(touch_list[i], touch_value * TOUCH_INTR_THRESHOLD) ); - ESP_LOGI(TAG, "test init: touch pad [%d] base %d, smooth %d, thresh %d", \ + ESP_LOGI(TAG, "test init: touch pad [%d] base %"PRIu32", smooth %"PRIu32", thresh %"PRIu32"", \ touch_list[i], touch_value, smooth, (uint32_t)(touch_value * TOUCH_INTR_THRESHOLD)); } @@ -965,7 +966,7 @@ esp_err_t test_touch_timeout_interrupt(void) TEST_ESP_OK( touch_pad_read_benchmark(touch_list[i], &touch_value) ); TEST_ESP_OK( touch_pad_filter_read_smooth(touch_list[i], &smooth) ); TEST_ESP_OK( touch_pad_set_thresh(touch_list[i], touch_value * TOUCH_INTR_THRESHOLD) ); - ESP_LOGI(TAG, "test init: touch pad [%d] base %d, smooth %d, thresh %d", + ESP_LOGI(TAG, "test init: touch pad [%d] base %"PRIu32", smooth %"PRIu32", thresh %"PRIu32"", touch_list[i], touch_value, smooth, (uint32_t)(touch_value * TOUCH_INTR_THRESHOLD)); } /* Set timeout parameter */ @@ -1011,7 +1012,7 @@ TEST_CASE("Touch Sensor interrupt test (active, inactive, scan_done, timeout)", static void test_touch_measure_step(uint32_t step) { /* Fake the process of debounce. */ - // printf("measure cnt %d: [ ", step); + // printf("measure cnt %"PRIu32": [ ", step); for (int i = 0; i < step; i++) { for (int j = 0; j < TEST_TOUCH_CHANNEL; j++) { TEST_ESP_OK( touch_pad_sw_start() ); @@ -1067,7 +1068,7 @@ esp_err_t test_touch_filter_parameter_debounce(int deb_cnt) for (int i = 0; i < TEST_TOUCH_CHANNEL; i++) { TEST_ESP_OK( touch_pad_read_benchmark(touch_list[i], &touch_value) ); TEST_ESP_OK( touch_pad_set_thresh(touch_list[i], touch_value * TOUCH_INTR_THRESHOLD) ); - ESP_LOGI(TAG, "test init: touch pad [%d] base %d, thresh %d", \ + ESP_LOGI(TAG, "test init: touch pad [%d] base %"PRIu32", thresh %"PRIu32"", \ touch_list[i], touch_value, (uint32_t)(touch_value * TOUCH_INTR_THRESHOLD)); } @@ -1132,7 +1133,7 @@ esp_err_t test_touch_filter_parameter_reset(int reset_cnt) for (int i = 0; i < TEST_TOUCH_CHANNEL; i++) { TEST_ESP_OK( touch_pad_read_benchmark(touch_list[i], &touch_value) ); TEST_ESP_OK( touch_pad_set_thresh(touch_list[i], touch_value * TOUCH_INTR_THRESHOLD) ); - ESP_LOGI(TAG, "test init: touch pad [%d] base %d, thresh %d", \ + ESP_LOGI(TAG, "test init: touch pad [%d] base %"PRIu32", thresh %"PRIu32"", \ touch_list[i], touch_value, (uint32_t)(touch_value * TOUCH_INTR_THRESHOLD)); } @@ -1267,7 +1268,7 @@ esp_err_t test_touch_filter_parameter_jitter(int jitter_step) TEST_ESP_OK( touch_pad_read_benchmark(touch_list[i], &touch_value) ); //set interrupt threshold. TEST_ESP_OK( touch_pad_set_thresh(touch_list[i], touch_value * TOUCH_INTR_THRESHOLD) ); - ESP_LOGI(TAG, "test init: touch pad [%d] base %d, thresh %d", \ + ESP_LOGI(TAG, "test init: touch pad [%d] base %"PRIu32", thresh %"PRIu32"", \ touch_list[i], touch_value, (uint32_t)(touch_value * TOUCH_INTR_THRESHOLD)); } @@ -1400,7 +1401,7 @@ TEST_CASE("Touch Sensor denoise test (cap, level)", "[touch]") } else { /* If the value of denoise is approximately 0, The difference between touch reading is very small. Should skip value test. */ - ESP_LOGI(TAG, "denoise value is %d", denoise_val[0]); + ESP_LOGI(TAG, "denoise value is %"PRIu32"", denoise_val[0]); } ESP_LOGI(TAG, "*********** touch filter denoise cap level test ********************"); @@ -1416,7 +1417,7 @@ TEST_CASE("Touch Sensor denoise test (cap, level)", "[touch]") printf("denoise read: "); for (int i = 0; i < TOUCH_PAD_DENOISE_CAP_MAX - 1; i++) { TEST_ASSERT_GREATER_OR_EQUAL(denoise_val[i], denoise_val[i + 1]); - printf("%d ", denoise_val[i]); + printf("%"PRIu32" ", denoise_val[i]); } printf("\n"); } @@ -1557,11 +1558,11 @@ esp_err_t test_touch_proximity(int meas_num) /* The threshold of proximity pad is the sum of touch reading `meas_num` times */ TEST_ESP_OK( touch_pad_set_thresh(touch_list[i], meas_num * touch_value * (1 + TOUCH_INTR_THRESHOLD)) ); - ESP_LOGI(TAG, "proximity pad [%d] base %d, thresh %d", touch_list[i], touch_value, + ESP_LOGI(TAG, "proximity pad [%d] base %"PRIu32", thresh %"PRIu32"", touch_list[i], touch_value, (uint32_t)(meas_num * touch_value * (1 + TOUCH_INTR_THRESHOLD))); } else { TEST_ESP_OK( touch_pad_set_thresh(touch_list[i], touch_value * TOUCH_INTR_THRESHOLD) ); - ESP_LOGI(TAG, "touch pad [%d] base %d, thresh %d", \ + ESP_LOGI(TAG, "touch pad [%d] base %"PRIu32", thresh %"PRIu32"", \ touch_list[i], touch_value, (uint32_t)(touch_value * TOUCH_INTR_THRESHOLD)); } } @@ -1653,7 +1654,7 @@ esp_err_t test_touch_sleep_reading_stable(touch_pad_t sleep_pad) TEST_ESP_OK( touch_pad_read_benchmark(touch_list[i], &touch_value) ); TEST_ESP_OK( touch_pad_filter_read_smooth(touch_list[i], &smooth) ); TEST_ESP_OK( touch_pad_set_thresh(touch_list[i], touch_value * TOUCH_INTR_THRESHOLD) ); - ESP_LOGI(TAG, "test init: touch pad [%d] base %d, smooth %d, thresh %d", + ESP_LOGI(TAG, "test init: touch pad [%d] base %"PRIu32", smooth %"PRIu32", thresh %"PRIu32"", touch_list[i], touch_value, smooth, (uint32_t)(touch_value * TOUCH_INTR_THRESHOLD)); } @@ -1754,18 +1755,18 @@ uint32_t test_touch_sleep_pad_proximity(touch_pad_t sleep_pad, bool is_proximity if (touch_list[i] == sleep_pad) { touch_pad_sleep_channel_read_smooth(sleep_pad, &touch_value); touch_pad_sleep_set_threshold(sleep_pad, meas_num * touch_value * (1 + TOUCH_INTR_THRESHOLD)); - ESP_LOGI(TAG, "Sleep pad [%d] base %d, thresh %d", touch_list[i], touch_value, + ESP_LOGI(TAG, "Sleep pad [%d] base %"PRIu32", thresh %"PRIu32"", touch_list[i], touch_value, (uint32_t)(meas_num * touch_value * (1 + TOUCH_INTR_THRESHOLD))); } else if (touch_list[i] == sleep_pad) { touch_pad_sleep_channel_read_smooth(sleep_pad, &touch_value); /* The threshold of proximity pad is the sum of touch reading `meas_num` times */ touch_pad_sleep_set_threshold(sleep_pad, meas_num * touch_value * (1 + TOUCH_INTR_THRESHOLD)); - ESP_LOGI(TAG, "proximity pad [%d] base %d, thresh %d", touch_list[i], touch_value, + ESP_LOGI(TAG, "proximity pad [%d] base %"PRIu32", thresh %"PRIu32"", touch_list[i], touch_value, (uint32_t)(meas_num * touch_value * (1 + TOUCH_INTR_THRESHOLD))); } else { TEST_ESP_OK( touch_pad_read_benchmark(touch_list[i], &touch_value) ); TEST_ESP_OK( touch_pad_set_thresh(touch_list[i], touch_value * TOUCH_INTR_THRESHOLD) ); - ESP_LOGI(TAG, "touch pad [%d] base %d, thresh %d", \ + ESP_LOGI(TAG, "touch pad [%d] base %"PRIu32", thresh %"PRIu32"", \ touch_list[i], touch_value, (uint32_t)(touch_value * TOUCH_INTR_THRESHOLD)); } } @@ -1787,7 +1788,7 @@ uint32_t test_touch_sleep_pad_proximity(touch_pad_t sleep_pad, bool is_proximity TEST_ESP_OK( touch_pad_read_benchmark(touch_list[i], &touch_value) ); TEST_ESP_OK( touch_pad_filter_read_smooth(touch_list[i], &smooth) ); TEST_ESP_OK( touch_pad_set_thresh(touch_list[i], touch_value * TOUCH_INTR_THRESHOLD) ); - ESP_LOGI(TAG, "test init: touch pad [%d] base %d, smooth %d, thresh %d", + ESP_LOGI(TAG, "test init: touch pad [%d] base %"PRIu32", smooth %"PRIu32", thresh %"PRIu32"", touch_list[i], touch_value, smooth, (uint32_t)(touch_value * TOUCH_INTR_THRESHOLD)); } /* Sleep channel setting */ @@ -1808,7 +1809,7 @@ uint32_t test_touch_sleep_pad_proximity(touch_pad_t sleep_pad, bool is_proximity TEST_ESP_OK( touch_pad_proximity_get_data(sleep_pad, &measure_out) ); TEST_ESP_OK( touch_pad_sleep_channel_read_proximity_cnt(sleep_pad, &proximity_cnt) ); TEST_ESP_OK( touch_pad_sleep_get_threshold(sleep_pad, &touch_thres) ); - printf("touch slp smooth %d, base %d, proxi %d cnt %d thres%d status 0x%x\n", + printf("touch slp smooth %"PRIu32", base %"PRIu32", proxi %"PRIu32" cnt %"PRIu32" thres%"PRIu32" status 0x%"PRIx32"\n", smooth, touch_value, measure_out, proximity_cnt, touch_thres, touch_pad_get_status()); } @@ -1820,7 +1821,7 @@ uint32_t test_touch_sleep_pad_proximity(touch_pad_t sleep_pad, bool is_proximity TEST_ESP_OK( touch_pad_sleep_channel_read_benchmark(sleep_pad, &touch_value) ); TEST_ESP_OK( touch_pad_proximity_get_data(sleep_pad, &measure_out) ); TEST_ESP_OK( touch_pad_sleep_channel_read_proximity_cnt(sleep_pad, &proximity_cnt) ); - printf("touch slp smooth %d, base %d, proxi %d cnt %d status 0x%x\n", + printf("touch slp smooth %"PRIu32", base %"PRIu32", proxi %"PRIu32" cnt %"PRIu32" status 0x%"PRIx32"\n", smooth, touch_value, measure_out, proximity_cnt, touch_pad_get_status()); } } @@ -1899,7 +1900,7 @@ esp_err_t test_touch_sleep_pad_interrupt_wakeup_deep_sleep(touch_pad_t sleep_pad TEST_ESP_OK( touch_pad_read_benchmark(touch_list[i], &touch_value) ); TEST_ESP_OK( touch_pad_filter_read_smooth(touch_list[i], &smooth) ); TEST_ESP_OK( touch_pad_set_thresh(touch_list[i], touch_value * TOUCH_INTR_THRESHOLD) ); - ESP_LOGI(TAG, "test init: touch pad [%d] base %d, smooth %d, thresh %d", + ESP_LOGI(TAG, "test init: touch pad [%d] base %"PRIu32", smooth %"PRIu32", thresh %"PRIu32"", touch_list[i], touch_value, smooth, (uint32_t)(touch_value * TOUCH_INTR_THRESHOLD)); } @@ -1915,7 +1916,7 @@ esp_err_t test_touch_sleep_pad_interrupt_wakeup_deep_sleep(touch_pad_t sleep_pad TEST_ESP_OK( touch_pad_sleep_channel_read_smooth(sleep_pad, &smooth) ); TEST_ESP_OK( touch_pad_sleep_channel_read_data(sleep_pad, &raw) ); TEST_ESP_OK( touch_pad_sleep_channel_read_benchmark(sleep_pad, &touch_value) ); - printf("touch slp raw %d, smooth %d, base %d, status 0x%x\n", raw, smooth, touch_value, touch_pad_get_status()); + printf("touch slp raw %"PRIu32", smooth %"PRIu32", base %"PRIu32", status 0x%"PRIx32"\n", raw, smooth, touch_value, touch_pad_get_status()); test_touch_release_all(); TEST_ESP_OK( test_touch_check_ch_released(TEST_TOUCH_CHANNEL, TOUCH_EXCEED_TIME_MS) ); @@ -1923,7 +1924,7 @@ esp_err_t test_touch_sleep_pad_interrupt_wakeup_deep_sleep(touch_pad_t sleep_pad TEST_ESP_OK( touch_pad_sleep_channel_read_smooth(sleep_pad, &smooth) ); TEST_ESP_OK( touch_pad_sleep_channel_read_data(sleep_pad, &raw) ); TEST_ESP_OK( touch_pad_sleep_channel_read_benchmark(sleep_pad, &touch_value) ); - printf("touch slp raw %d, smooth %d, base %d, status 0x%x\n", raw, smooth, touch_value, touch_pad_get_status()); + printf("touch slp raw %"PRIu32", smooth %"PRIu32", base %"PRIu32", status 0x%"PRIx32"\n", raw, smooth, touch_value, touch_pad_get_status()); return ESP_OK; } @@ -1944,18 +1945,18 @@ static void test_deep_sleep_init(void) uint64_t wakeup_pin_mask = esp_sleep_get_ext1_wakeup_status(); if (wakeup_pin_mask != 0) { int pin = __builtin_ffsll(wakeup_pin_mask) - 1; - printf("Wake up from GPIO %d\n", pin); + printf("Wake up from GPIO %"PRIu32"\n", pin); } else { printf("Wake up from GPIO\n"); } break; } case ESP_SLEEP_WAKEUP_TIMER: { - printf("Wake up from timer. Time spent in deep sleep: %dms\n", sleep_time_ms); + printf("Wake up from timer. Time spent in deep sleep: %"PRIu32"ms\n", sleep_time_ms); break; } case ESP_SLEEP_WAKEUP_TOUCHPAD: { - printf("Wake up from touch on pad %d\n", esp_sleep_get_touchpad_wakeup_status()); + printf("Wake up from touch on pad %"PRIu32"\n", esp_sleep_get_touchpad_wakeup_status()); break; } case ESP_SLEEP_WAKEUP_UNDEFINED: @@ -2059,7 +2060,7 @@ void test_touch_slope_debug(int pad_num) TEST_ESP_OK( touch_pad_read_benchmark(touch_list[i], &touch_value) ); TEST_ESP_OK( touch_pad_filter_read_smooth(touch_list[i], &smooth) ); TEST_ESP_OK( touch_pad_set_thresh(touch_list[i], touch_value * TOUCH_THRESHOLD) ); - ESP_LOGI(TAG, "test init: touch pad [%d] base %d, smooth %d, thresh %d", \ + ESP_LOGI(TAG, "test init: touch pad [%d] base %"PRIu32", smooth %"PRIu32", thresh %"PRIu32"", \ touch_list[i], touch_value, smooth, (uint32_t)(touch_value * TOUCH_THRESHOLD)); } diff --git a/components/touch_element/CMakeLists.txt b/components/touch_element/CMakeLists.txt index b8b90e7efd..21a54d5aad 100644 --- a/components/touch_element/CMakeLists.txt +++ b/components/touch_element/CMakeLists.txt @@ -8,5 +8,4 @@ if(IDF_TARGET IN_LIST TOUCH_ELEMENT_COMPATIBLE_TARGETS) INCLUDE_DIRS include REQUIRES driver PRIV_REQUIRES esp_timer) - target_compile_options(${COMPONENT_LIB} PRIVATE "-Wno-format") endif() diff --git a/components/touch_element/touch_button.c b/components/touch_element/touch_button.c index 2ecceed198..fea5d8198a 100644 --- a/components/touch_element/touch_button.c +++ b/components/touch_element/touch_button.c @@ -12,6 +12,7 @@ #include #include +#include #include "freertos/FreeRTOS.h" #include "freertos/semphr.h" #include "esp_log.h" diff --git a/components/touch_element/touch_element.c b/components/touch_element/touch_element.c index 6622cc84cd..ec465c95b3 100644 --- a/components/touch_element/touch_element.c +++ b/components/touch_element/touch_element.c @@ -5,6 +5,7 @@ */ #include +#include #include "freertos/FreeRTOS.h" #include "freertos/semphr.h" #include "freertos/queue.h" @@ -402,7 +403,7 @@ static void te_proc_timer_cb(void *arg) ESP_LOGD(TE_DEBUG_TAG, "Set waterproof shield level"); } } - ESP_LOGD(TE_DEBUG_TAG, "read denoise channel %d", s_te_obj->denoise_channel_raw); + ESP_LOGD(TE_DEBUG_TAG, "read denoise channel %"PRIu32, s_te_obj->denoise_channel_raw); } else if (te_intr_msg.intr_type == TE_INTR_TIMEOUT) { //Timeout processing touch_pad_timeout_resume(); } @@ -516,7 +517,7 @@ esp_err_t te_dev_set_threshold(te_dev_t *device) { uint32_t smo_val = te_read_smooth_signal(device->channel); esp_err_t ret = touch_pad_set_thresh(device->channel, device->sens * smo_val); - ESP_LOGD(TE_DEBUG_TAG, "channel: %d, smo_val: %d", device->channel, smo_val); + ESP_LOGD(TE_DEBUG_TAG, "channel: %"PRIu8", smo_val: %"PRIu32, device->channel, smo_val); return ret; } @@ -812,14 +813,14 @@ static bool waterproof_channel_check(touch_pad_t channel_num) te_waterproof_handle_t waterproof_handle = s_te_obj->waterproof_handle; if (waterproof_shield_check_state()) { if (channel_num == waterproof_handle->shield_channel) { - ESP_LOGE(TE_TAG, "TOUCH_PAD_NUM%d has been used for waterproof shield channel," + ESP_LOGE(TE_TAG, "TOUCH_PAD_NUM%"PRIu8" has been used for waterproof shield channel," " please change the touch sensor channel or disable waterproof", channel_num); return true; } } if (waterproof_guard_check_state()) { if (channel_num == waterproof_handle->guard_device->channel) { - ESP_LOGE(TE_TAG, "TOUCH_PAD_NUM%d has been used for waterproof guard channel," + ESP_LOGE(TE_TAG, "TOUCH_PAD_NUM%"PRIu8" has been used for waterproof guard channel," " please change the touch sensor channel or disable waterproof", channel_num); return true; } diff --git a/components/touch_element/touch_matrix.c b/components/touch_element/touch_matrix.c index 89e24d126d..08f380f82d 100644 --- a/components/touch_element/touch_matrix.c +++ b/components/touch_element/touch_matrix.c @@ -12,6 +12,7 @@ #include #include +#include #include "freertos/FreeRTOS.h" #include "freertos/semphr.h" #include "esp_log.h" @@ -575,7 +576,7 @@ static void matrix_proc_state(te_matrix_handle_t matrix_handle) if (matrix_handle->current_state == TE_STATE_PRESS) { if (matrix_handle->last_state == TE_STATE_IDLE) { //IDLE ---> Press = On_Press matrix_update_position(matrix_handle, press_pos); - ESP_LOGD(TE_DEBUG_TAG, "matrix press (%d, %d)", matrix_handle->position.x_axis, matrix_handle->position.y_axis); + ESP_LOGD(TE_DEBUG_TAG, "matrix press (%"PRIu8", %"PRIu8")", matrix_handle->position.x_axis, matrix_handle->position.y_axis); if (event_mask & TOUCH_ELEM_EVENT_ON_PRESS) { matrix_handle->event = TOUCH_MATRIX_EVT_ON_PRESS; matrix_dispatch(matrix_handle, dispatch_method); @@ -583,7 +584,7 @@ static void matrix_proc_state(te_matrix_handle_t matrix_handle) } else if (matrix_handle->last_state == TE_STATE_PRESS) { //Press ---> Press = On_LongPress if (event_mask & TOUCH_ELEM_EVENT_ON_LONGPRESS) { if (++matrix_handle->trigger_cnt >= matrix_handle->trigger_thr) { - ESP_LOGD(TE_DEBUG_TAG, "matrix longpress (%d, %d)", matrix_handle->position.x_axis, matrix_handle->position.y_axis); + ESP_LOGD(TE_DEBUG_TAG, "matrix longpress (%"PRIu8", %"PRIu8")", matrix_handle->position.x_axis, matrix_handle->position.y_axis); matrix_handle->event = TOUCH_MATRIX_EVT_ON_LONGPRESS; matrix_dispatch(matrix_handle, dispatch_method); matrix_handle->trigger_cnt = 0; @@ -592,7 +593,7 @@ static void matrix_proc_state(te_matrix_handle_t matrix_handle) } } else if (matrix_handle->current_state == TE_STATE_RELEASE) { if (matrix_handle->last_state == TE_STATE_PRESS) { //Press ---> Release = On_Release - ESP_LOGD(TE_DEBUG_TAG, "matrix release (%d, %d)", matrix_handle->position.x_axis, matrix_handle->position.y_axis); + ESP_LOGD(TE_DEBUG_TAG, "matrix release (%"PRIu8", %"PRIu8")", matrix_handle->position.x_axis, matrix_handle->position.y_axis); if (event_mask & TOUCH_ELEM_EVENT_ON_RELEASE) { matrix_handle->event = TOUCH_MATRIX_EVT_ON_RELEASE; matrix_dispatch(matrix_handle, dispatch_method); From b239b03aa79229ba2856408852421c78b66b06c3 Mon Sep 17 00:00:00 2001 From: wangyuanze Date: Mon, 1 Aug 2022 16:58:53 +0800 Subject: [PATCH 2/3] touch_element: move unit tests to test_app --- .../touch_element/.build-test-rules.yml | 6 +++ .../include/touch_element/touch_button.h | 19 +++----- .../touch_element/touch_element_private.h | 18 +++----- components/touch_element/test/CMakeLists.txt | 10 ----- .../touch_element/test_apps/CMakeLists.txt | 5 +++ components/touch_element/test_apps/README.md | 2 + .../test_apps/main/CMakeLists.txt | 4 ++ .../test_apps/main/test_app_main.c | 43 +++++++++++++++++++ .../main}/test_touch_button.c | 5 +++ .../main}/test_touch_element.c | 34 ++++++++------- .../main}/test_touch_matrix.c | 5 +++ .../main}/test_touch_slider.c | 5 +++ .../test_apps/pytest_touch_element.py | 21 +++++++++ .../test_apps/sdkconfig.ci.opt_o0 | 1 + .../test_apps/sdkconfig.ci.opt_o2 | 1 + .../test_apps/sdkconfig.defaults | 3 ++ components/touch_element/touch_button.c | 16 +++---- components/touch_element/touch_matrix.c | 16 +++---- components/touch_element/touch_slider.c | 16 +++---- .../main/touch_button_example_main.c | 2 +- .../main/waterproof_example_main.c | 2 +- .../main/touch_elements_example_main.c | 2 +- .../main/touch_matrix_example_main.c | 2 +- .../main/touch_slider_example_main.c | 2 +- tools/ci/check_copyright_ignore.txt | 18 -------- 25 files changed, 149 insertions(+), 109 deletions(-) create mode 100644 components/touch_element/.build-test-rules.yml delete mode 100644 components/touch_element/test/CMakeLists.txt create mode 100644 components/touch_element/test_apps/CMakeLists.txt create mode 100644 components/touch_element/test_apps/README.md create mode 100644 components/touch_element/test_apps/main/CMakeLists.txt create mode 100644 components/touch_element/test_apps/main/test_app_main.c rename components/touch_element/{test => test_apps/main}/test_touch_button.c (99%) rename components/touch_element/{test => test_apps/main}/test_touch_element.c (96%) rename components/touch_element/{test => test_apps/main}/test_touch_matrix.c (99%) rename components/touch_element/{test => test_apps/main}/test_touch_slider.c (98%) create mode 100644 components/touch_element/test_apps/pytest_touch_element.py create mode 100644 components/touch_element/test_apps/sdkconfig.ci.opt_o0 create mode 100644 components/touch_element/test_apps/sdkconfig.ci.opt_o2 create mode 100644 components/touch_element/test_apps/sdkconfig.defaults diff --git a/components/touch_element/.build-test-rules.yml b/components/touch_element/.build-test-rules.yml new file mode 100644 index 0000000000..c210fd1b8c --- /dev/null +++ b/components/touch_element/.build-test-rules.yml @@ -0,0 +1,6 @@ +# Documentation: .gitlab/ci/README.md#manifest-file-to-control-the-buildtest-apps + +components/touch_element/test_apps: + enable: + - if: IDF_TARGET in ["esp32s2", "esp32s3"] + reason: only supports esp32s2 and esp32s3 diff --git a/components/touch_element/include/touch_element/touch_button.h b/components/touch_element/include/touch_element/touch_button.h index 76bc971a72..2b0c15dcef 100644 --- a/components/touch_element/include/touch_element/touch_button.h +++ b/components/touch_element/include/touch_element/touch_button.h @@ -1,17 +1,8 @@ -// Copyright 2016-2020 Espressif Systems (Shanghai) PTE LTD -// -// Licensed under the Apache License, Version 2.0 (the "License"); -// you may not use this file except in compliance with the License. -// You may obtain a copy of the License at -// -// http://www.apache.org/licenses/LICENSE-2.0 -// -// Unless required by applicable law or agreed to in writing, software -// distributed under the License is distributed on an "AS IS" BASIS, -// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -// See the License for the specific language governing permissions and -// limitations under the License. - +/* + * SPDX-FileCopyrightText: 2016-2022 Espressif Systems (Shanghai) CO LTD + * + * SPDX-License-Identifier: Apache-2.0 + */ #pragma once #include "touch_element/touch_element.h" diff --git a/components/touch_element/include/touch_element/touch_element_private.h b/components/touch_element/include/touch_element/touch_element_private.h index 85143157fe..49971ae2d4 100644 --- a/components/touch_element/include/touch_element/touch_element_private.h +++ b/components/touch_element/include/touch_element/touch_element_private.h @@ -1,16 +1,8 @@ -// Copyright 2016-2020 Espressif Systems (Shanghai) PTE LTD -// -// Licensed under the Apache License, Version 2.0 (the "License"); -// you may not use this file except in compliance with the License. -// You may obtain a copy of the License at -// -// http://www.apache.org/licenses/LICENSE-2.0 -// -// Unless required by applicable law or agreed to in writing, software -// distributed under the License is distributed on an "AS IS" BASIS, -// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -// See the License for the specific language governing permissions and -// limitations under the License. +/* + * SPDX-FileCopyrightText: 2016-2022 Espressif Systems (Shanghai) CO LTD + * + * SPDX-License-Identifier: Apache-2.0 + */ #pragma once diff --git a/components/touch_element/test/CMakeLists.txt b/components/touch_element/test/CMakeLists.txt deleted file mode 100644 index 9c02399984..0000000000 --- a/components/touch_element/test/CMakeLists.txt +++ /dev/null @@ -1,10 +0,0 @@ -set(TOUCH_ELEMENT_COMPATIBLE_TARGETS "esp32s2" "esp32s3") - -if(IDF_TARGET IN_LIST TOUCH_ELEMENT_COMPATIBLE_TARGETS) - idf_component_register(SRCS "test_touch_element.c" - "test_touch_button.c" - "test_touch_slider.c" - "test_touch_matrix.c" - PRIV_REQUIRES unity touch_element) - target_compile_options(${COMPONENT_LIB} PRIVATE "-Wno-format") -endif() diff --git a/components/touch_element/test_apps/CMakeLists.txt b/components/touch_element/test_apps/CMakeLists.txt new file mode 100644 index 0000000000..d31bc59565 --- /dev/null +++ b/components/touch_element/test_apps/CMakeLists.txt @@ -0,0 +1,5 @@ +# This is the project CMakeLists.txt file for the test subproject +cmake_minimum_required(VERSION 3.16) + +include($ENV{IDF_PATH}/tools/cmake/project.cmake) +project(touch_element_test) diff --git a/components/touch_element/test_apps/README.md b/components/touch_element/test_apps/README.md new file mode 100644 index 0000000000..af8190f914 --- /dev/null +++ b/components/touch_element/test_apps/README.md @@ -0,0 +1,2 @@ +| Supported Targets | ESP32-S2 | ESP32-S3 | +| ----------------- | -------- | -------- | diff --git a/components/touch_element/test_apps/main/CMakeLists.txt b/components/touch_element/test_apps/main/CMakeLists.txt new file mode 100644 index 0000000000..ebf7e88d23 --- /dev/null +++ b/components/touch_element/test_apps/main/CMakeLists.txt @@ -0,0 +1,4 @@ +idf_component_register(SRCS "test_app_main.c" "test_touch_element.c" "test_touch_button.c" + "test_touch_slider.c" "test_touch_matrix.c" + WHOLE_ARCHIVE +) diff --git a/components/touch_element/test_apps/main/test_app_main.c b/components/touch_element/test_apps/main/test_app_main.c new file mode 100644 index 0000000000..e6429bb6b2 --- /dev/null +++ b/components/touch_element/test_apps/main/test_app_main.c @@ -0,0 +1,43 @@ +/* + * SPDX-FileCopyrightText: 2022 Espressif Systems (Shanghai) CO LTD + * + * SPDX-License-Identifier: Apache-2.0 + */ + +#include "unity.h" +#include "unity_test_runner.h" +#include "esp_heap_caps.h" +#include "freertos/FreeRTOS.h" +#include "freertos/task.h" + +// Some resources are lazy allocated in gpio/dedicated_gpio/delta_sigma driver, the threshold is left for that case +#define TEST_MEMORY_LEAK_THRESHOLD (-400) + +static size_t before_free_8bit; +static size_t before_free_32bit; + +static void check_leak(size_t before_free, size_t after_free, const char *type) +{ + ssize_t delta = after_free - before_free; + printf("MALLOC_CAP_%s: Before %u bytes free, After %u bytes free (delta %d)\n", type, before_free, after_free, delta); + TEST_ASSERT_MESSAGE(delta >= TEST_MEMORY_LEAK_THRESHOLD, "memory leak"); +} + +void setUp(void) +{ + before_free_8bit = heap_caps_get_free_size(MALLOC_CAP_8BIT); + before_free_32bit = heap_caps_get_free_size(MALLOC_CAP_32BIT); +} + +void tearDown(void) +{ + size_t after_free_8bit = heap_caps_get_free_size(MALLOC_CAP_8BIT); + size_t after_free_32bit = heap_caps_get_free_size(MALLOC_CAP_32BIT); + check_leak(before_free_8bit, after_free_8bit, "8BIT"); + check_leak(before_free_32bit, after_free_32bit, "32BIT"); +} + +void app_main(void) +{ + unity_run_menu(); +} diff --git a/components/touch_element/test/test_touch_button.c b/components/touch_element/test_apps/main/test_touch_button.c similarity index 99% rename from components/touch_element/test/test_touch_button.c rename to components/touch_element/test_apps/main/test_touch_button.c index a8f6739696..24ae89e406 100644 --- a/components/touch_element/test/test_touch_button.c +++ b/components/touch_element/test_apps/main/test_touch_button.c @@ -1,3 +1,8 @@ +/* + * SPDX-FileCopyrightText: 2022 Espressif Systems (Shanghai) CO LTD + * + * SPDX-License-Identifier: Unlicense OR CC0-1.0 + */ #include #include #include diff --git a/components/touch_element/test/test_touch_element.c b/components/touch_element/test_apps/main/test_touch_element.c similarity index 96% rename from components/touch_element/test/test_touch_element.c rename to components/touch_element/test_apps/main/test_touch_element.c index 883195021a..6fee84bdde 100644 --- a/components/touch_element/test/test_touch_element.c +++ b/components/touch_element/test_apps/main/test_touch_element.c @@ -1,3 +1,8 @@ +/* + * SPDX-FileCopyrightText: 2022 Espressif Systems (Shanghai) CO LTD + * + * SPDX-License-Identifier: Unlicense OR CC0-1.0 + */ /* ---------------------------------------------------------- README ------------------------------------------------ * This doc is aimed at explain some important code block and do some records for the test result, if developer or * test-owner has some question in reading this code implementation, please read it first. @@ -312,22 +317,22 @@ static void test_integrat_btn_sld_mat(void) for (int i = 0; i < 30; i++) { printf("Integration test... (%d/30)\n", i + 1); touch_elem_message_t valid_message; + touch_button_message_t button_message; + touch_slider_message_t slider_message; + touch_matrix_message_t matrix_message; + valid_message.element_type = (random() % (TOUCH_ELEM_TYPE_MATRIX + 1)); if (valid_message.element_type == TOUCH_ELEM_TYPE_BUTTON) { uint32_t button_index = random() % BUTTON_CHANNEL_NUM; valid_message.handle = button_handle[button_index]; - touch_button_message_t button_message = { - .event = TOUCH_BUTTON_EVT_ON_PRESS - }; + button_message.event = TOUCH_BUTTON_EVT_ON_PRESS; memcpy(valid_message.child_msg, &button_message, sizeof(button_message)); //Construct child message xQueueSend(monitor.valid_msg_handle, &valid_message, portMAX_DELAY); test_button_event_simulator(valid_message.handle, button_message.event); } else if (valid_message.element_type == TOUCH_ELEM_TYPE_SLIDER) { valid_message.handle = slider_handle; - touch_slider_message_t slider_message = { - .event = TOUCH_SLIDER_EVT_ON_PRESS, - .position = 0 //No check - }; + slider_message.event = TOUCH_SLIDER_EVT_ON_PRESS; + slider_message.position = 0; //No check memcpy(valid_message.child_msg, &slider_message, sizeof(slider_message)); //Construct child message xQueueSend(monitor.valid_msg_handle, &valid_message, portMAX_DELAY); test_slider_event_simulator(valid_message.handle, slider_message.event, 1); @@ -335,33 +340,30 @@ static void test_integrat_btn_sld_mat(void) uint32_t matrix_x_axis_index = random() % MATRIX_CHANNEL_NUM_X; uint32_t matrix_y_axis_index = random() % MATRIX_CHANNEL_NUM_Y; valid_message.handle = matrix_handle; - touch_matrix_message_t matrix_message = { - .event = TOUCH_MATRIX_EVT_ON_PRESS, - .position.x_axis = matrix_x_axis_index, - .position.y_axis = matrix_y_axis_index, - .position.index = matrix_x_axis_index * MATRIX_CHANNEL_NUM_Y + matrix_y_axis_index - }; + matrix_message.event = TOUCH_MATRIX_EVT_ON_PRESS; + matrix_message.position.x_axis = matrix_x_axis_index; + matrix_message.position.y_axis = matrix_y_axis_index; + matrix_message.position.index = matrix_x_axis_index * MATRIX_CHANNEL_NUM_Y + matrix_y_axis_index; memcpy(valid_message.child_msg, &matrix_message, sizeof(matrix_message)); //Construct child message xQueueSend(monitor.valid_msg_handle, &valid_message, portMAX_DELAY); test_matrix_event_simulator(valid_message.handle, matrix_message.event, matrix_message.position.index); + } else { + TEST_ABORT(); } os_ret = xSemaphoreTake(monitor.response_sig_handle, pdMS_TO_TICKS(500)); TEST_ASSERT_MESSAGE(os_ret == pdPASS, "response queue timeout (500ms)"); if (valid_message.element_type == TOUCH_ELEM_TYPE_BUTTON) { - touch_button_message_t button_message; button_message.event = TOUCH_BUTTON_EVT_ON_RELEASE; memcpy(valid_message.child_msg, &button_message, sizeof(button_message)); xQueueSend(monitor.valid_msg_handle, &valid_message, portMAX_DELAY); test_button_event_simulator(valid_message.handle, button_message.event); } else if (valid_message.element_type == TOUCH_ELEM_TYPE_SLIDER) { - touch_slider_message_t slider_message; slider_message.event = TOUCH_SLIDER_EVT_ON_RELEASE; memcpy(valid_message.child_msg, &slider_message, sizeof(slider_message)); xQueueSend(monitor.valid_msg_handle, &valid_message, portMAX_DELAY); test_slider_event_simulator(valid_message.handle, slider_message.event, 1); } else if (valid_message.element_type == TOUCH_ELEM_TYPE_MATRIX) { - touch_matrix_message_t matrix_message; matrix_message.event = TOUCH_MATRIX_EVT_ON_RELEASE; memcpy(valid_message.child_msg, &matrix_message, sizeof(matrix_message)); xQueueSend(monitor.valid_msg_handle, &valid_message, portMAX_DELAY); diff --git a/components/touch_element/test/test_touch_matrix.c b/components/touch_element/test_apps/main/test_touch_matrix.c similarity index 99% rename from components/touch_element/test/test_touch_matrix.c rename to components/touch_element/test_apps/main/test_touch_matrix.c index 1f2ca7557f..da1f3abd1a 100644 --- a/components/touch_element/test/test_touch_matrix.c +++ b/components/touch_element/test_apps/main/test_touch_matrix.c @@ -1,3 +1,8 @@ +/* + * SPDX-FileCopyrightText: 2022 Espressif Systems (Shanghai) CO LTD + * + * SPDX-License-Identifier: Unlicense OR CC0-1.0 + */ #include #include #include diff --git a/components/touch_element/test/test_touch_slider.c b/components/touch_element/test_apps/main/test_touch_slider.c similarity index 98% rename from components/touch_element/test/test_touch_slider.c rename to components/touch_element/test_apps/main/test_touch_slider.c index 47d70ed70d..effd3ba068 100644 --- a/components/touch_element/test/test_touch_slider.c +++ b/components/touch_element/test_apps/main/test_touch_slider.c @@ -1,3 +1,8 @@ +/* + * SPDX-FileCopyrightText: 2022 Espressif Systems (Shanghai) CO LTD + * + * SPDX-License-Identifier: Unlicense OR CC0-1.0 + */ #include #include #include diff --git a/components/touch_element/test_apps/pytest_touch_element.py b/components/touch_element/test_apps/pytest_touch_element.py new file mode 100644 index 0000000000..e5651438df --- /dev/null +++ b/components/touch_element/test_apps/pytest_touch_element.py @@ -0,0 +1,21 @@ +# SPDX-FileCopyrightText: 2022 Espressif Systems (Shanghai) CO LTD +# SPDX-License-Identifier: Unlicense OR CC0-1.0 +import pytest +from pytest_embedded import Dut + + +@pytest.mark.esp32s2 +@pytest.mark.esp32s3 +@pytest.mark.generic +@pytest.mark.parametrize( + 'config', + [ + 'opt_o0', + 'opt_o2' + ], + indirect=True, +) +def test_touch_element(dut: Dut) -> None: + dut.expect_exact('Press ENTER to see the list of tests') + dut.write('*') + dut.expect_unity_test_output(timeout=120) diff --git a/components/touch_element/test_apps/sdkconfig.ci.opt_o0 b/components/touch_element/test_apps/sdkconfig.ci.opt_o0 new file mode 100644 index 0000000000..8c66af7708 --- /dev/null +++ b/components/touch_element/test_apps/sdkconfig.ci.opt_o0 @@ -0,0 +1 @@ +CONFIG_COMPILER_OPTIMIZATION_NONE=y diff --git a/components/touch_element/test_apps/sdkconfig.ci.opt_o2 b/components/touch_element/test_apps/sdkconfig.ci.opt_o2 new file mode 100644 index 0000000000..3c5a0fabea --- /dev/null +++ b/components/touch_element/test_apps/sdkconfig.ci.opt_o2 @@ -0,0 +1 @@ +CONFIG_COMPILER_OPTIMIZATION_PERF=y diff --git a/components/touch_element/test_apps/sdkconfig.defaults b/components/touch_element/test_apps/sdkconfig.defaults new file mode 100644 index 0000000000..3baab5a252 --- /dev/null +++ b/components/touch_element/test_apps/sdkconfig.defaults @@ -0,0 +1,3 @@ +CONFIG_FREERTOS_HZ=1000 +CONFIG_ESP_TASK_WDT=n +CONFIG_ESP_MAIN_TASK_STACK_SIZE=8192 diff --git a/components/touch_element/touch_button.c b/components/touch_element/touch_button.c index fea5d8198a..7a93d03f93 100644 --- a/components/touch_element/touch_button.c +++ b/components/touch_element/touch_button.c @@ -1,14 +1,8 @@ -// Licensed under the Apache License, Version 2.0 (the "License"); -// you may not use this file except in compliance with the License. -// You may obtain a copy of the License at -// -// http://www.apache.org/licenses/LICENSE-2.0 -// -// Unless required by applicable law or agreed to in writing, software -// distributed under the License is distributed on an "AS IS" BASIS, -// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -// See the License for the specific language governing permissions and -// limitations under the License. +/* + * SPDX-FileCopyrightText: 2016-2022 Espressif Systems (Shanghai) CO LTD + * + * SPDX-License-Identifier: Apache-2.0 + */ #include #include diff --git a/components/touch_element/touch_matrix.c b/components/touch_element/touch_matrix.c index 08f380f82d..8b61b07baf 100644 --- a/components/touch_element/touch_matrix.c +++ b/components/touch_element/touch_matrix.c @@ -1,14 +1,8 @@ -// Licensed under the Apache License, Version 2.0 (the "License"); -// you may not use this file except in compliance with the License. -// You may obtain a copy of the License at -// -// http://www.apache.org/licenses/LICENSE-2.0 -// -// Unless required by applicable law or agreed to in writing, software -// distributed under the License is distributed on an "AS IS" BASIS, -// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -// See the License for the specific language governing permissions and -// limitations under the License. +/* + * SPDX-FileCopyrightText: 2016-2022 Espressif Systems (Shanghai) CO LTD + * + * SPDX-License-Identifier: Apache-2.0 + */ #include #include diff --git a/components/touch_element/touch_slider.c b/components/touch_element/touch_slider.c index ad2b13924e..15acaa8802 100644 --- a/components/touch_element/touch_slider.c +++ b/components/touch_element/touch_slider.c @@ -1,14 +1,8 @@ -// Licensed under the Apache License, Version 2.0 (the "License"); -// you may not use this file except in compliance with the License. -// You may obtain a copy of the License at -// -// http://www.apache.org/licenses/LICENSE-2.0 -// -// Unless required by applicable law or agreed to in writing, software -// distributed under the License is distributed on an "AS IS" BASIS, -// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -// See the License for the specific language governing permissions and -// limitations under the License. +/* + * SPDX-FileCopyrightText: 2016-2022 Espressif Systems (Shanghai) CO LTD + * + * SPDX-License-Identifier: Apache-2.0 + */ #include #include diff --git a/examples/peripherals/touch_sensor/touch_element/touch_button/main/touch_button_example_main.c b/examples/peripherals/touch_sensor/touch_element/touch_button/main/touch_button_example_main.c index ef3f389c67..031106ab25 100644 --- a/examples/peripherals/touch_sensor/touch_element/touch_button/main/touch_button_example_main.c +++ b/examples/peripherals/touch_sensor/touch_element/touch_button/main/touch_button_example_main.c @@ -1,5 +1,5 @@ /* - * SPDX-FileCopyrightText: 2021 Espressif Systems (Shanghai) CO LTD + * SPDX-FileCopyrightText: 2021-2022 Espressif Systems (Shanghai) CO LTD * * SPDX-License-Identifier: CC0-1.0 */ diff --git a/examples/peripherals/touch_sensor/touch_element/touch_element_waterproof/main/waterproof_example_main.c b/examples/peripherals/touch_sensor/touch_element/touch_element_waterproof/main/waterproof_example_main.c index a8828f2e23..427d63cbbb 100644 --- a/examples/peripherals/touch_sensor/touch_element/touch_element_waterproof/main/waterproof_example_main.c +++ b/examples/peripherals/touch_sensor/touch_element/touch_element_waterproof/main/waterproof_example_main.c @@ -1,5 +1,5 @@ /* - * SPDX-FileCopyrightText: 2021 Espressif Systems (Shanghai) CO LTD + * SPDX-FileCopyrightText: 2021-2022 Espressif Systems (Shanghai) CO LTD * * SPDX-License-Identifier: CC0-1.0 */ diff --git a/examples/peripherals/touch_sensor/touch_element/touch_elements_combination/main/touch_elements_example_main.c b/examples/peripherals/touch_sensor/touch_element/touch_elements_combination/main/touch_elements_example_main.c index b89e42d224..4e529a1a63 100644 --- a/examples/peripherals/touch_sensor/touch_element/touch_elements_combination/main/touch_elements_example_main.c +++ b/examples/peripherals/touch_sensor/touch_element/touch_elements_combination/main/touch_elements_example_main.c @@ -1,5 +1,5 @@ /* - * SPDX-FileCopyrightText: 2021 Espressif Systems (Shanghai) CO LTD + * SPDX-FileCopyrightText: 2021-2022 Espressif Systems (Shanghai) CO LTD * * SPDX-License-Identifier: CC0-1.0 */ diff --git a/examples/peripherals/touch_sensor/touch_element/touch_matrix/main/touch_matrix_example_main.c b/examples/peripherals/touch_sensor/touch_element/touch_matrix/main/touch_matrix_example_main.c index 51507889bf..0ba483dc5a 100644 --- a/examples/peripherals/touch_sensor/touch_element/touch_matrix/main/touch_matrix_example_main.c +++ b/examples/peripherals/touch_sensor/touch_element/touch_matrix/main/touch_matrix_example_main.c @@ -1,5 +1,5 @@ /* - * SPDX-FileCopyrightText: 2021 Espressif Systems (Shanghai) CO LTD + * SPDX-FileCopyrightText: 2021-2022 Espressif Systems (Shanghai) CO LTD * * SPDX-License-Identifier: CC0-1.0 */ diff --git a/examples/peripherals/touch_sensor/touch_element/touch_slider/main/touch_slider_example_main.c b/examples/peripherals/touch_sensor/touch_element/touch_slider/main/touch_slider_example_main.c index 6ec3d32728..3ae4eb7f93 100644 --- a/examples/peripherals/touch_sensor/touch_element/touch_slider/main/touch_slider_example_main.c +++ b/examples/peripherals/touch_sensor/touch_element/touch_slider/main/touch_slider_example_main.c @@ -1,5 +1,5 @@ /* - * SPDX-FileCopyrightText: 2021 Espressif Systems (Shanghai) CO LTD + * SPDX-FileCopyrightText: 2021-2022 Espressif Systems (Shanghai) CO LTD * * SPDX-License-Identifier: CC0-1.0 */ diff --git a/tools/ci/check_copyright_ignore.txt b/tools/ci/check_copyright_ignore.txt index 062f951c32..bdaaa3d546 100644 --- a/tools/ci/check_copyright_ignore.txt +++ b/tools/ci/check_copyright_ignore.txt @@ -1321,15 +1321,6 @@ components/tcp_transport/test/test_transport_connect.c components/tcp_transport/test/test_transport_fixtures.c components/tcp_transport/transport_utils.c components/tinyusb/additions/include/tusb_config.h -components/touch_element/include/touch_element/touch_button.h -components/touch_element/include/touch_element/touch_element_private.h -components/touch_element/test/test_touch_button.c -components/touch_element/test/test_touch_element.c -components/touch_element/test/test_touch_matrix.c -components/touch_element/test/test_touch_slider.c -components/touch_element/touch_button.c -components/touch_element/touch_matrix.c -components/touch_element/touch_slider.c components/ulp/esp32ulp_mapgen.py components/ulp/test/esp32/test_ulp_as.c components/unity/include/priv/setjmp.h @@ -1753,15 +1744,6 @@ examples/peripherals/spi_slave_hd/append_mode/master/main/app_main.c examples/peripherals/spi_slave_hd/append_mode/slave/main/app_main.c examples/peripherals/spi_slave_hd/segment_mode/seg_master/main/app_main.c examples/peripherals/spi_slave_hd/segment_mode/seg_slave/main/app_main.c -examples/peripherals/touch_element/touch_button/main/touch_button_example_main.c -examples/peripherals/touch_element/touch_element_waterproof/main/waterproof_example_main.c -examples/peripherals/touch_element/touch_elements_combination/main/touch_elements_example_main.c -examples/peripherals/touch_element/touch_matrix/main/touch_matrix_example_main.c -examples/peripherals/touch_element/touch_slider/main/touch_slider_example_main.c -examples/peripherals/touch_pad_interrupt/main/esp32/tp_interrupt_main.c -examples/peripherals/touch_pad_interrupt/main/esp32s2/tp_interrupt_main.c -examples/peripherals/touch_pad_read/main/esp32/tp_read_main.c -examples/peripherals/touch_pad_read/main/esp32s2/tp_read_main.c examples/peripherals/twai/twai_alert_and_recovery/example_test.py examples/peripherals/twai/twai_alert_and_recovery/main/twai_alert_and_recovery_example_main.c examples/peripherals/twai/twai_network/example_test.py From 5e4ab6481fa5086dc802b82e759773e615a6fcc2 Mon Sep 17 00:00:00 2001 From: wangyuanze Date: Tue, 2 Aug 2022 19:01:40 +0800 Subject: [PATCH 3/3] touch_sensor: move unit tests to test_app --- components/driver/.build-test-rules.yml | 8 ++++ components/driver/test/CMakeLists.txt | 4 +- .../test_apps/touch_sensor_v1/CMakeLists.txt | 5 +++ .../test_apps/touch_sensor_v1/README.md | 2 + .../touch_sensor_v1/main/CMakeLists.txt | 3 ++ .../touch_sensor_v1/main/test_app_main.c | 40 +++++++++++++++++ .../touch_sensor_v1/main}/test_touch_v1.c | 29 ++++++++----- .../touch_sensor_v1/pytest_touch_sensor_v1.py | 12 ++++++ .../touch_sensor_v1/sdkconfig.defaults | 2 + .../test_apps/touch_sensor_v2/CMakeLists.txt | 5 +++ .../test_apps/touch_sensor_v2/README.md | 2 + .../touch_sensor_v2/main/CMakeLists.txt | 3 ++ .../touch_sensor_v2/main/test_app_main.c | 41 ++++++++++++++++++ .../touch_sensor_v2/main}/test_touch_v2.c | 43 ++++++++----------- .../touch_sensor_v2/main}/touch_scope.c | 2 +- .../touch_sensor_v2/main}/touch_scope.h | 2 +- .../touch_sensor_v2/pytest_touch_sensor_v2.py | 13 ++++++ .../touch_sensor_v2/sdkconfig.defaults | 2 + 18 files changed, 178 insertions(+), 40 deletions(-) create mode 100644 components/driver/test_apps/touch_sensor_v1/CMakeLists.txt create mode 100644 components/driver/test_apps/touch_sensor_v1/README.md create mode 100644 components/driver/test_apps/touch_sensor_v1/main/CMakeLists.txt create mode 100644 components/driver/test_apps/touch_sensor_v1/main/test_app_main.c rename components/driver/{test/touch_sensor_test => test_apps/touch_sensor_v1/main}/test_touch_v1.c (94%) create mode 100644 components/driver/test_apps/touch_sensor_v1/pytest_touch_sensor_v1.py create mode 100644 components/driver/test_apps/touch_sensor_v1/sdkconfig.defaults create mode 100644 components/driver/test_apps/touch_sensor_v2/CMakeLists.txt create mode 100644 components/driver/test_apps/touch_sensor_v2/README.md create mode 100644 components/driver/test_apps/touch_sensor_v2/main/CMakeLists.txt create mode 100644 components/driver/test_apps/touch_sensor_v2/main/test_app_main.c rename components/driver/{test/touch_sensor_test => test_apps/touch_sensor_v2/main}/test_touch_v2.c (97%) rename components/driver/{test/touch_sensor_test => test_apps/touch_sensor_v2/main}/touch_scope.c (98%) rename components/driver/{test/touch_sensor_test/include => test_apps/touch_sensor_v2/main}/touch_scope.h (89%) create mode 100644 components/driver/test_apps/touch_sensor_v2/pytest_touch_sensor_v2.py create mode 100644 components/driver/test_apps/touch_sensor_v2/sdkconfig.defaults diff --git a/components/driver/.build-test-rules.yml b/components/driver/.build-test-rules.yml index 69fef02250..a2f4dbc567 100644 --- a/components/driver/.build-test-rules.yml +++ b/components/driver/.build-test-rules.yml @@ -43,3 +43,11 @@ components/driver/test_apps/sdm: components/driver/test_apps/temperature_sensor: disable: - if: SOC_TEMP_SENSOR_SUPPORTED != 1 + +components/driver/test_apps/touch_sensor_v1: + disable: + - if: SOC_TOUCH_VERSION_1 != 1 + +components/driver/test_apps/touch_sensor_v2: + disable: + - if: SOC_TOUCH_VERSION_2 != 1 diff --git a/components/driver/test/CMakeLists.txt b/components/driver/test/CMakeLists.txt index d428eb0b32..ae79c8d854 100644 --- a/components/driver/test/CMakeLists.txt +++ b/components/driver/test/CMakeLists.txt @@ -1,5 +1,5 @@ -idf_component_register(SRC_DIRS . param_test touch_sensor_test dac_dma_test - PRIV_INCLUDE_DIRS include param_test/include touch_sensor_test/include +idf_component_register(SRC_DIRS . param_test dac_dma_test + PRIV_INCLUDE_DIRS include param_test/include PRIV_REQUIRES cmock test_utils driver nvs_flash esp_serial_slave_link esp_timer esp_adc esp_event esp_wifi) target_compile_options(${COMPONENT_LIB} PRIVATE "-Wno-format") diff --git a/components/driver/test_apps/touch_sensor_v1/CMakeLists.txt b/components/driver/test_apps/touch_sensor_v1/CMakeLists.txt new file mode 100644 index 0000000000..9cabb5df76 --- /dev/null +++ b/components/driver/test_apps/touch_sensor_v1/CMakeLists.txt @@ -0,0 +1,5 @@ +# This is the project CMakeLists.txt file for the test subproject +cmake_minimum_required(VERSION 3.16) + +include($ENV{IDF_PATH}/tools/cmake/project.cmake) +project(touch_sensor_v1_test) diff --git a/components/driver/test_apps/touch_sensor_v1/README.md b/components/driver/test_apps/touch_sensor_v1/README.md new file mode 100644 index 0000000000..f708a1985a --- /dev/null +++ b/components/driver/test_apps/touch_sensor_v1/README.md @@ -0,0 +1,2 @@ +| Supported Targets | ESP32 | +| ----------------- | ----- | diff --git a/components/driver/test_apps/touch_sensor_v1/main/CMakeLists.txt b/components/driver/test_apps/touch_sensor_v1/main/CMakeLists.txt new file mode 100644 index 0000000000..c13250644d --- /dev/null +++ b/components/driver/test_apps/touch_sensor_v1/main/CMakeLists.txt @@ -0,0 +1,3 @@ +idf_component_register(SRCS "test_app_main.c" "test_touch_v1.c" + WHOLE_ARCHIVE +) diff --git a/components/driver/test_apps/touch_sensor_v1/main/test_app_main.c b/components/driver/test_apps/touch_sensor_v1/main/test_app_main.c new file mode 100644 index 0000000000..896caa3200 --- /dev/null +++ b/components/driver/test_apps/touch_sensor_v1/main/test_app_main.c @@ -0,0 +1,40 @@ +/* + * SPDX-FileCopyrightText: 2022 Espressif Systems (Shanghai) CO LTD + * + * SPDX-License-Identifier: Apache-2.0 + */ + +#include "unity.h" +#include "unity_test_runner.h" +#include "esp_heap_caps.h" + +#define TEST_MEMORY_LEAK_THRESHOLD (-200) + +static size_t before_free_8bit; +static size_t before_free_32bit; + +static void check_leak(size_t before_free, size_t after_free, const char *type) +{ + ssize_t delta = after_free - before_free; + printf("MALLOC_CAP_%s: Before %u bytes free, After %u bytes free (delta %d)\n", type, before_free, after_free, delta); + TEST_ASSERT_MESSAGE(delta >= TEST_MEMORY_LEAK_THRESHOLD, "memory leak"); +} + +void setUp(void) +{ + before_free_8bit = heap_caps_get_free_size(MALLOC_CAP_8BIT); + before_free_32bit = heap_caps_get_free_size(MALLOC_CAP_32BIT); +} + +void tearDown(void) +{ + size_t after_free_8bit = heap_caps_get_free_size(MALLOC_CAP_8BIT); + size_t after_free_32bit = heap_caps_get_free_size(MALLOC_CAP_32BIT); + check_leak(before_free_8bit, after_free_8bit, "8BIT"); + check_leak(before_free_32bit, after_free_32bit, "32BIT"); +} + +void app_main(void) +{ + unity_run_menu(); +} diff --git a/components/driver/test/touch_sensor_test/test_touch_v1.c b/components/driver/test_apps/touch_sensor_v1/main/test_touch_v1.c similarity index 94% rename from components/driver/test/touch_sensor_test/test_touch_v1.c rename to components/driver/test_apps/touch_sensor_v1/main/test_touch_v1.c index ba734317d6..350c550b47 100644 --- a/components/driver/test/touch_sensor_test/test_touch_v1.c +++ b/components/driver/test_apps/touch_sensor_v1/main/test_touch_v1.c @@ -1,5 +1,5 @@ /* - * SPDX-FileCopyrightText: 2015-2021 Espressif Systems (Shanghai) CO LTD + * SPDX-FileCopyrightText: 2022 Espressif Systems (Shanghai) CO LTD * * SPDX-License-Identifier: Apache-2.0 */ @@ -8,7 +8,6 @@ Tests for the touch sensor device driver for ESP32 */ #include "sdkconfig.h" -#if CONFIG_IDF_TARGET_ESP32 #include "esp_system.h" #include "driver/touch_pad.h" @@ -17,8 +16,6 @@ #include "freertos/FreeRTOS.h" #include "freertos/task.h" #include "esp_log.h" -#include "nvs_flash.h" -#include "test_utils.h" #include "soc/rtc_cntl_reg.h" #include "soc/rtc_cntl_struct.h" #include "soc/sens_reg.h" @@ -28,6 +25,9 @@ #include "soc/rtc_io_reg.h" #include "soc/rtc_io_struct.h" #include "esp_rom_sys.h" +#if CONFIG_PM_ENABLE +#include "esp_pm.h" +#endif static const char *TAG = "test_touch"; @@ -40,9 +40,9 @@ static const char *TAG = "test_touch"; TEST_ASSERT_EQUAL_UINT32(REG_GET_FIELD(RTC_IO_DATE_REG, RTC_IO_IO_DATE), RTCIO.date.date); \ }) -#define TOUCH_READ_ERROR (100) -#define TEST_TOUCH_COUNT_NUM (10) -#define TEST_TOUCH_CHANNEL (3) +#define TOUCH_READ_ERROR_THRESH (0.1) // 10% error +#define TEST_TOUCH_COUNT_NUM (10) +#define TEST_TOUCH_CHANNEL (3) static touch_pad_t touch_list[TEST_TOUCH_CHANNEL] = { // TOUCH_PAD_NUM0, // TOUCH_PAD_NUM1 is GPIO0, for download. @@ -158,7 +158,7 @@ static esp_err_t test_touch_timer_read(void) for (int i = 0; i < TEST_TOUCH_CHANNEL; i++) { TEST_ESP_OK( touch_pad_read(touch_list[i], &touch_temp[i]) ); TEST_ASSERT_NOT_EQUAL(TOUCH_READ_INVALID_VAL, touch_temp[i]); - TEST_ASSERT_UINT32_WITHIN(TOUCH_READ_ERROR, touch_temp[i], touch_value[i]); + TEST_ASSERT_UINT32_WITHIN((uint32_t)((float)touch_temp[i]*TOUCH_READ_ERROR_THRESH), touch_temp[i], touch_value[i]); } vTaskDelay(50 / portTICK_PERIOD_MS); } @@ -192,7 +192,7 @@ static esp_err_t test_touch_filtered_read(void) TEST_ASSERT_NOT_EQUAL(TOUCH_READ_INVALID_VAL, touch_value); TEST_ESP_OK( touch_pad_read_filtered(touch_list[i], &touch_temp) ); TEST_ASSERT_NOT_EQUAL(TOUCH_READ_INVALID_VAL, touch_temp); - TEST_ASSERT_UINT32_WITHIN(TOUCH_READ_ERROR, touch_temp, touch_value); + TEST_ASSERT_UINT32_WITHIN((uint32_t)((float)touch_temp*TOUCH_READ_ERROR_THRESH), touch_temp, touch_value); printf("T%d:[%4d] ", touch_list[i], touch_value); } vTaskDelay(50 / portTICK_PERIOD_MS); @@ -207,11 +207,20 @@ static esp_err_t test_touch_filtered_read(void) // test the basic configuration function with right parameters and error parameters TEST_CASE("Touch Sensor all channel read test", "[touch]") { +#if CONFIG_PM_ENABLE + esp_pm_lock_handle_t pm_lock; + esp_pm_lock_create(ESP_PM_NO_LIGHT_SLEEP, 0, "test_touch", &pm_lock); + esp_pm_lock_acquire(pm_lock); +#endif TOUCH_REG_BASE_TEST(); test_touch_sw_read_test_runner(); TEST_ESP_OK( test_touch_sw_read() ); TEST_ESP_OK( test_touch_timer_read() ); TEST_ESP_OK( test_touch_filtered_read() ); +#if CONFIG_PM_ENABLE + esp_pm_lock_release(pm_lock); + esp_pm_lock_delete(pm_lock); +#endif } static int test_touch_parameter(touch_pad_t pad_num, int meas_time, int slp_time, int vol_h, int vol_l, int vol_a, int slope) @@ -367,5 +376,3 @@ TEST_CASE("Touch Sensor interrupt test", "[touch]") { TEST_ESP_OK( test_touch_interrupt() ); } - -#endif // CONFIG_IDF_TARGET_ESP32 diff --git a/components/driver/test_apps/touch_sensor_v1/pytest_touch_sensor_v1.py b/components/driver/test_apps/touch_sensor_v1/pytest_touch_sensor_v1.py new file mode 100644 index 0000000000..86edab8560 --- /dev/null +++ b/components/driver/test_apps/touch_sensor_v1/pytest_touch_sensor_v1.py @@ -0,0 +1,12 @@ +# SPDX-FileCopyrightText: 2022 Espressif Systems (Shanghai) CO LTD +# SPDX-License-Identifier: Unlicense OR CC0-1.0 +import pytest +from pytest_embedded import Dut + + +@pytest.mark.esp32 +@pytest.mark.generic +def test_touch_sensor_v1(dut: Dut) -> None: + dut.expect_exact('Press ENTER to see the list of tests') + dut.write('*') + dut.expect_unity_test_output(timeout=60) diff --git a/components/driver/test_apps/touch_sensor_v1/sdkconfig.defaults b/components/driver/test_apps/touch_sensor_v1/sdkconfig.defaults new file mode 100644 index 0000000000..b308cb2ddd --- /dev/null +++ b/components/driver/test_apps/touch_sensor_v1/sdkconfig.defaults @@ -0,0 +1,2 @@ +CONFIG_FREERTOS_HZ=1000 +CONFIG_ESP_TASK_WDT=n diff --git a/components/driver/test_apps/touch_sensor_v2/CMakeLists.txt b/components/driver/test_apps/touch_sensor_v2/CMakeLists.txt new file mode 100644 index 0000000000..59a612d92c --- /dev/null +++ b/components/driver/test_apps/touch_sensor_v2/CMakeLists.txt @@ -0,0 +1,5 @@ +# This is the project CMakeLists.txt file for the test subproject +cmake_minimum_required(VERSION 3.16) + +include($ENV{IDF_PATH}/tools/cmake/project.cmake) +project(touch_sensor_v2_test) diff --git a/components/driver/test_apps/touch_sensor_v2/README.md b/components/driver/test_apps/touch_sensor_v2/README.md new file mode 100644 index 0000000000..af8190f914 --- /dev/null +++ b/components/driver/test_apps/touch_sensor_v2/README.md @@ -0,0 +1,2 @@ +| Supported Targets | ESP32-S2 | ESP32-S3 | +| ----------------- | -------- | -------- | diff --git a/components/driver/test_apps/touch_sensor_v2/main/CMakeLists.txt b/components/driver/test_apps/touch_sensor_v2/main/CMakeLists.txt new file mode 100644 index 0000000000..ef5f0d8fa2 --- /dev/null +++ b/components/driver/test_apps/touch_sensor_v2/main/CMakeLists.txt @@ -0,0 +1,3 @@ +idf_component_register(SRCS "test_app_main.c" "test_touch_v2.c" "touch_scope.c" + WHOLE_ARCHIVE +) diff --git a/components/driver/test_apps/touch_sensor_v2/main/test_app_main.c b/components/driver/test_apps/touch_sensor_v2/main/test_app_main.c new file mode 100644 index 0000000000..0ea01c452c --- /dev/null +++ b/components/driver/test_apps/touch_sensor_v2/main/test_app_main.c @@ -0,0 +1,41 @@ +/* + * SPDX-FileCopyrightText: 2022 Espressif Systems (Shanghai) CO LTD + * + * SPDX-License-Identifier: Apache-2.0 + */ + +#include "unity.h" +#include "unity_test_runner.h" +#include "esp_heap_caps.h" + +// que_touch may be created in any case and reused among all cases so we can't free it, the threshold is left for that +#define TEST_MEMORY_LEAK_THRESHOLD (-500) + +static size_t before_free_8bit; +static size_t before_free_32bit; + +static void check_leak(size_t before_free, size_t after_free, const char *type) +{ + ssize_t delta = after_free - before_free; + printf("MALLOC_CAP_%s: Before %u bytes free, After %u bytes free (delta %d)\n", type, before_free, after_free, delta); + TEST_ASSERT_MESSAGE(delta >= TEST_MEMORY_LEAK_THRESHOLD, "memory leak"); +} + +void setUp(void) +{ + before_free_8bit = heap_caps_get_free_size(MALLOC_CAP_8BIT); + before_free_32bit = heap_caps_get_free_size(MALLOC_CAP_32BIT); +} + +void tearDown(void) +{ + size_t after_free_8bit = heap_caps_get_free_size(MALLOC_CAP_8BIT); + size_t after_free_32bit = heap_caps_get_free_size(MALLOC_CAP_32BIT); + check_leak(before_free_8bit, after_free_8bit, "8BIT"); + check_leak(before_free_32bit, after_free_32bit, "32BIT"); +} + +void app_main(void) +{ + unity_run_menu(); +} diff --git a/components/driver/test/touch_sensor_test/test_touch_v2.c b/components/driver/test_apps/touch_sensor_v2/main/test_touch_v2.c similarity index 97% rename from components/driver/test/touch_sensor_test/test_touch_v2.c rename to components/driver/test_apps/touch_sensor_v2/main/test_touch_v2.c index 5ddd7cbe4a..928cb09971 100644 --- a/components/driver/test/touch_sensor_test/test_touch_v2.c +++ b/components/driver/test_apps/touch_sensor_v2/main/test_touch_v2.c @@ -1,5 +1,5 @@ /* - * SPDX-FileCopyrightText: 2015-2022 Espressif Systems (Shanghai) CO LTD + * SPDX-FileCopyrightText: 2022 Espressif Systems (Shanghai) CO LTD * * SPDX-License-Identifier: Apache-2.0 */ @@ -8,7 +8,6 @@ Tests for the touch sensor device driver for ESP32-S2 & ESP32-S3 */ #include "sdkconfig.h" -#if CONFIG_IDF_TARGET_ESP32S2 || CONFIG_IDF_TARGET_ESP32S3 #include #include @@ -21,7 +20,6 @@ #include "freertos/semphr.h" #include "freertos/queue.h" #include "esp_log.h" -#include "test_utils.h" #include "soc/rtc_cntl_reg.h" #include "soc/rtc_cntl_struct.h" #include "soc/sens_reg.h" @@ -60,7 +58,7 @@ void test_pxp_deinit_io(void) #endif #define TOUCH_READ_INVALID_VAL (SOC_TOUCH_PAD_THRESHOLD_MAX) -#define TOUCH_READ_ERROR (100) +#define TOUCH_READ_ERROR_THRESH (0.1) // 10% error #define TOUCH_INTR_THRESHOLD (0.1) #define TOUCH_EXCEED_TIME_MS (1000) @@ -235,7 +233,7 @@ esp_err_t test_touch_sw_read(void) /* Check the stable of reading. */ for (int i = 0; i < TEST_TOUCH_CHANNEL; i++) { if (touch_temp[i]) { - TEST_ASSERT_UINT32_WITHIN(TOUCH_READ_ERROR, touch_temp[i], touch_value[i]); + TEST_ASSERT_UINT32_WITHIN((uint32_t)((float)touch_temp[i]*TOUCH_READ_ERROR_THRESH), touch_temp[i], touch_value[i]); } touch_temp[i] = touch_value[i]; } @@ -304,7 +302,7 @@ esp_err_t test_touch_timer_read(void) printf("\n"); for (int i = 0; i < TEST_TOUCH_CHANNEL; i++) { if (touch_temp[i]) { - TEST_ASSERT_UINT32_WITHIN(TOUCH_READ_ERROR, touch_temp[i], touch_value[i]); + TEST_ASSERT_UINT32_WITHIN((uint32_t)((float)touch_temp[i]*TOUCH_READ_ERROR_THRESH), touch_temp[i], touch_value[i]); } touch_temp[i] = touch_value[i]; } @@ -369,10 +367,10 @@ esp_err_t test_touch_filtered_read(void) TEST_ASSERT_NOT_EQUAL(TOUCH_READ_INVALID_VAL, touch_value[i]); TEST_ESP_OK( touch_pad_read_raw_data(touch_list[i], &touch_temp[i]) ); TEST_ASSERT_NOT_EQUAL(TOUCH_READ_INVALID_VAL, touch_temp[i]); - TEST_ASSERT_UINT32_WITHIN(TOUCH_READ_ERROR, touch_temp[i], touch_value[i]); + TEST_ASSERT_UINT32_WITHIN((uint32_t)((float)touch_temp[i]*TOUCH_READ_ERROR_THRESH), touch_temp[i], touch_value[i]); TEST_ESP_OK( touch_pad_filter_read_smooth(touch_list[i], &touch_temp[i]) ); TEST_ASSERT_NOT_EQUAL(TOUCH_READ_INVALID_VAL, touch_temp[i]); - TEST_ASSERT_UINT32_WITHIN(TOUCH_READ_ERROR, touch_temp[i], touch_value[i]); + TEST_ASSERT_UINT32_WITHIN((uint32_t)((float)touch_temp[i]*TOUCH_READ_ERROR_THRESH), touch_temp[i], touch_value[i]); } printf("touch filter init value:\n"); printf_touch_hw_read("raw "); @@ -386,13 +384,13 @@ esp_err_t test_touch_filtered_read(void) for (int i = 0; i < TEST_TOUCH_CHANNEL; i++) { TEST_ESP_OK( touch_pad_read_raw_data(touch_list[i], &touch_value[i]) ); TEST_ESP_OK( touch_pad_read_benchmark(touch_list[i], &touch_temp[i]) ); - TEST_ASSERT_UINT32_WITHIN(TOUCH_READ_ERROR, touch_temp[i], touch_value[i]); + TEST_ASSERT_UINT32_WITHIN((uint32_t)((float)touch_temp[i]*TOUCH_READ_ERROR_THRESH), touch_temp[i], touch_value[i]); TEST_ESP_OK( touch_pad_filter_read_smooth(touch_list[i], &touch_temp[i]) ); - TEST_ASSERT_UINT32_WITHIN(TOUCH_READ_ERROR, touch_temp[i], touch_value[i]); + TEST_ASSERT_UINT32_WITHIN((uint32_t)((float)touch_temp[i]*TOUCH_READ_ERROR_THRESH), touch_temp[i], touch_value[i]); } for (int i = 0; i < TEST_TOUCH_CHANNEL; i++) { if (touch_temp[i]) { - TEST_ASSERT_UINT32_WITHIN(TOUCH_READ_ERROR, touch_temp[i], touch_value[i]); + TEST_ASSERT_UINT32_WITHIN((uint32_t)((float)touch_temp[i]*TOUCH_READ_ERROR_THRESH), touch_temp[i], touch_value[i]); } touch_temp[i] = touch_value[i]; } @@ -461,15 +459,15 @@ int test_touch_base_parameter(touch_pad_t pad_num, int meas_time, int slp_time, /* Correctness of reading. Ideal: benchmark == raw data == smooth data. */ TEST_ESP_OK( touch_pad_read_raw_data(pad_num, &touch_value) ); TEST_ESP_OK( touch_pad_read_benchmark(pad_num, &touch_filter) ); - TEST_ASSERT_UINT32_WITHIN(TOUCH_READ_ERROR, touch_filter, touch_value); + TEST_ASSERT_UINT32_WITHIN((uint32_t)((float)touch_filter*TOUCH_READ_ERROR_THRESH), touch_filter, touch_value); TEST_ESP_OK( touch_pad_filter_read_smooth(pad_num, &touch_filter) ); - TEST_ASSERT_UINT32_WITHIN(TOUCH_READ_ERROR, touch_filter, touch_value); + TEST_ASSERT_UINT32_WITHIN((uint32_t)((float)touch_filter*TOUCH_READ_ERROR_THRESH), touch_filter, touch_value); /* Stable of reading */ TEST_ESP_OK( touch_pad_read_raw_data(pad_num, &touch_value) ); TEST_ASSERT_NOT_EQUAL(TOUCH_READ_INVALID_VAL, touch_value); if (touch_temp) { - TEST_ASSERT_UINT32_WITHIN(TOUCH_READ_ERROR, touch_temp, touch_value); + TEST_ASSERT_UINT32_WITHIN((uint32_t)((float)touch_temp*TOUCH_READ_ERROR_THRESH), touch_temp, touch_value); } touch_temp = touch_value; @@ -764,7 +762,6 @@ static void test_touch_intr_cb(void *arg) evt.pad_num = touch_pad_get_current_meas_channel(); if (!evt.intr_mask) { - esp_rom_printf("."); return; } if (evt.intr_mask & TOUCH_PAD_INTR_MASK_SCAN_DONE) { @@ -778,7 +775,6 @@ static void test_touch_intr_cb(void *arg) } if (evt.intr_mask & TOUCH_PAD_INTR_MASK_TIMEOUT) { s_touch_timeout_mask |= (BIT(evt.pad_num)); - esp_rom_printf("-%dtout-", SENS.sar_touch_status0.touch_scan_curr); } xQueueSendFromISR(que_touch, &evt, &task_awoken); @@ -1668,13 +1664,13 @@ esp_err_t test_touch_sleep_reading_stable(touch_pad_t sleep_pad) for (int i = 0; i < TEST_TOUCH_CHANNEL; i++) { TEST_ESP_OK( touch_pad_sleep_channel_read_data(sleep_pad, &touch_value) ); TEST_ESP_OK( touch_pad_sleep_channel_read_benchmark(sleep_pad, &touch_temp) ); - TEST_ASSERT_UINT32_WITHIN(TOUCH_READ_ERROR, touch_temp, touch_value); + TEST_ASSERT_UINT32_WITHIN((uint32_t)((float)touch_temp*TOUCH_READ_ERROR_THRESH), touch_temp, touch_value); TEST_ESP_OK( touch_pad_sleep_channel_read_smooth(sleep_pad, &touch_temp) ); - TEST_ASSERT_UINT32_WITHIN(TOUCH_READ_ERROR, touch_temp, touch_value); + TEST_ASSERT_UINT32_WITHIN((uint32_t)((float)touch_temp*TOUCH_READ_ERROR_THRESH), touch_temp, touch_value); } for (int i = 0; i < TEST_TOUCH_CHANNEL; i++) { if (touch_temp) { - TEST_ASSERT_UINT32_WITHIN(TOUCH_READ_ERROR, touch_temp, touch_value); + TEST_ASSERT_UINT32_WITHIN((uint32_t)((float)touch_temp*TOUCH_READ_ERROR_THRESH), touch_temp, touch_value); } touch_temp = touch_value; } @@ -1929,6 +1925,8 @@ esp_err_t test_touch_sleep_pad_interrupt_wakeup_deep_sleep(touch_pad_t sleep_pad return ESP_OK; } +#if !TEMPORARY_DISABLED_FOR_TARGETS(ESP32S2, ESP32S3) //TODO: IDF-5218 + #include #include "esp_sleep.h" @@ -1979,10 +1977,6 @@ static void test_deep_sleep_init(void) TEST_CASE("Touch Sensor sleep pad wakeup deep sleep test", "[touch][ignore]") { -//TODO: IDF-5218 -#if TEMPORARY_DISABLED_FOR_TARGETS(ESP32S2) - abort(); -#endif //TEMPORARY_DISABLED_FOR_TARGETS(..) test_deep_sleep_init(); /* Change the work duty of touch sensor to reduce current. */ @@ -1997,6 +1991,7 @@ TEST_CASE("Touch Sensor sleep pad wakeup deep sleep test", "[touch][ignore]") esp_deep_sleep_start(); } +#endif //TEMPORARY_DISABLED_FOR_TARGETS(..) #include "touch_scope.h" /* @@ -2140,5 +2135,3 @@ void test_touch_slope_debug(int pad_num) #endif TEST_ESP_OK( touch_pad_deinit() ); } - -#endif // CONFIG_IDF_TARGET_ESP32S2 || CONFIG_IDF_TARGET_ESP32S3 diff --git a/components/driver/test/touch_sensor_test/touch_scope.c b/components/driver/test_apps/touch_sensor_v2/main/touch_scope.c similarity index 98% rename from components/driver/test/touch_sensor_test/touch_scope.c rename to components/driver/test_apps/touch_sensor_v2/main/touch_scope.c index f9f995077e..94e30a131e 100644 --- a/components/driver/test/touch_sensor_test/touch_scope.c +++ b/components/driver/test_apps/touch_sensor_v2/main/touch_scope.c @@ -1,5 +1,5 @@ /* - * SPDX-FileCopyrightText: 2015-2021 Espressif Systems (Shanghai) CO LTD + * SPDX-FileCopyrightText: 2022 Espressif Systems (Shanghai) CO LTD * * SPDX-License-Identifier: Apache-2.0 */ diff --git a/components/driver/test/touch_sensor_test/include/touch_scope.h b/components/driver/test_apps/touch_sensor_v2/main/touch_scope.h similarity index 89% rename from components/driver/test/touch_sensor_test/include/touch_scope.h rename to components/driver/test_apps/touch_sensor_v2/main/touch_scope.h index d95647af1f..79993ea470 100644 --- a/components/driver/test/touch_sensor_test/include/touch_scope.h +++ b/components/driver/test_apps/touch_sensor_v2/main/touch_scope.h @@ -1,5 +1,5 @@ /* - * SPDX-FileCopyrightText: 2015-2021 Espressif Systems (Shanghai) CO LTD + * SPDX-FileCopyrightText: 2022 Espressif Systems (Shanghai) CO LTD * * SPDX-License-Identifier: Apache-2.0 */ diff --git a/components/driver/test_apps/touch_sensor_v2/pytest_touch_sensor_v2.py b/components/driver/test_apps/touch_sensor_v2/pytest_touch_sensor_v2.py new file mode 100644 index 0000000000..f21311808c --- /dev/null +++ b/components/driver/test_apps/touch_sensor_v2/pytest_touch_sensor_v2.py @@ -0,0 +1,13 @@ +# SPDX-FileCopyrightText: 2022 Espressif Systems (Shanghai) CO LTD +# SPDX-License-Identifier: Unlicense OR CC0-1.0 +import pytest +from pytest_embedded import Dut + + +@pytest.mark.esp32s2 +@pytest.mark.esp32s3 +@pytest.mark.generic +def test_touch_sensor_v2(dut: Dut) -> None: + dut.expect_exact('Press ENTER to see the list of tests') + dut.write('*') + dut.expect_unity_test_output(timeout=120) diff --git a/components/driver/test_apps/touch_sensor_v2/sdkconfig.defaults b/components/driver/test_apps/touch_sensor_v2/sdkconfig.defaults new file mode 100644 index 0000000000..b308cb2ddd --- /dev/null +++ b/components/driver/test_apps/touch_sensor_v2/sdkconfig.defaults @@ -0,0 +1,2 @@ +CONFIG_FREERTOS_HZ=1000 +CONFIG_ESP_TASK_WDT=n