Skip to content

Commit

Permalink
Merge branch 'test/move_touch_related_unit_tests_to_test_apps' into '…
Browse files Browse the repository at this point in the history
…master'

test: move touch related unit tests to test apps

Closes IDFCI-1283, IDFCI-1156, and IDF-5766

See merge request espressif/esp-idf!19348
  • Loading branch information
wangyz1997 committed Aug 9, 2022
2 parents fe2bd5c + 5e4ab64 commit debf2c0
Show file tree
Hide file tree
Showing 45 changed files with 383 additions and 202 deletions.
8 changes: 8 additions & 0 deletions components/driver/.build-test-rules.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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
4 changes: 2 additions & 2 deletions components/driver/test/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -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")
5 changes: 5 additions & 0 deletions components/driver/test_apps/touch_sensor_v1/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -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)
2 changes: 2 additions & 0 deletions components/driver/test_apps/touch_sensor_v1/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
| Supported Targets | ESP32 |
| ----------------- | ----- |
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
idf_component_register(SRCS "test_app_main.c" "test_touch_v1.c"
WHOLE_ARCHIVE
)
40 changes: 40 additions & 0 deletions components/driver/test_apps/touch_sensor_v1/main/test_app_main.c
Original file line number Diff line number Diff line change
@@ -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();
}
Original file line number Diff line number Diff line change
@@ -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
*/
Expand All @@ -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"
Expand All @@ -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"
Expand All @@ -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";

Expand All @@ -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.
Expand Down Expand Up @@ -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);
}
Expand Down Expand Up @@ -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);
Expand All @@ -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)
Expand Down Expand Up @@ -367,5 +376,3 @@ TEST_CASE("Touch Sensor interrupt test", "[touch]")
{
TEST_ESP_OK( test_touch_interrupt() );
}

#endif // CONFIG_IDF_TARGET_ESP32
Original file line number Diff line number Diff line change
@@ -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)
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
CONFIG_FREERTOS_HZ=1000
CONFIG_ESP_TASK_WDT=n
5 changes: 5 additions & 0 deletions components/driver/test_apps/touch_sensor_v2/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -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)
2 changes: 2 additions & 0 deletions components/driver/test_apps/touch_sensor_v2/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
| Supported Targets | ESP32-S2 | ESP32-S3 |
| ----------------- | -------- | -------- |
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
idf_component_register(SRCS "test_app_main.c" "test_touch_v2.c" "touch_scope.c"
WHOLE_ARCHIVE
)
41 changes: 41 additions & 0 deletions components/driver/test_apps/touch_sensor_v2/main/test_app_main.c
Original file line number Diff line number Diff line change
@@ -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();
}

0 comments on commit debf2c0

Please sign in to comment.