touch_element: move unit tests to test_app

This commit is contained in:
wangyuanze
2022-08-01 16:58:53 +08:00
parent 48ce5d7c01
commit b239b03aa7
25 changed files with 149 additions and 109 deletions

View File

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

View File

@@ -1,17 +1,8 @@
// Copyright 2016-2020 Espressif Systems (Shanghai) PTE LTD /*
// * SPDX-FileCopyrightText: 2016-2022 Espressif Systems (Shanghai) CO LTD
// Licensed under the Apache License, Version 2.0 (the "License"); *
// you may not use this file except in compliance with the License. * SPDX-License-Identifier: Apache-2.0
// 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.
#pragma once #pragma once
#include "touch_element/touch_element.h" #include "touch_element/touch_element.h"

View File

@@ -1,16 +1,8 @@
// Copyright 2016-2020 Espressif Systems (Shanghai) PTE LTD /*
// * SPDX-FileCopyrightText: 2016-2022 Espressif Systems (Shanghai) CO LTD
// Licensed under the Apache License, Version 2.0 (the "License"); *
// you may not use this file except in compliance with the License. * SPDX-License-Identifier: Apache-2.0
// 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.
#pragma once #pragma once

View File

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

View File

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

View File

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

View File

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

View File

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

View File

@@ -1,3 +1,8 @@
/*
* SPDX-FileCopyrightText: 2022 Espressif Systems (Shanghai) CO LTD
*
* SPDX-License-Identifier: Unlicense OR CC0-1.0
*/
#include <stdio.h> #include <stdio.h>
#include <string.h> #include <string.h>
#include <stdlib.h> #include <stdlib.h>

View File

@@ -1,3 +1,8 @@
/*
* SPDX-FileCopyrightText: 2022 Espressif Systems (Shanghai) CO LTD
*
* SPDX-License-Identifier: Unlicense OR CC0-1.0
*/
/* ---------------------------------------------------------- README ------------------------------------------------ /* ---------------------------------------------------------- README ------------------------------------------------
* This doc is aimed at explain some important code block and do some records for the test result, if developer or * 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. * 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++) { for (int i = 0; i < 30; i++) {
printf("Integration test... (%d/30)\n", i + 1); printf("Integration test... (%d/30)\n", i + 1);
touch_elem_message_t valid_message; 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)); valid_message.element_type = (random() % (TOUCH_ELEM_TYPE_MATRIX + 1));
if (valid_message.element_type == TOUCH_ELEM_TYPE_BUTTON) { if (valid_message.element_type == TOUCH_ELEM_TYPE_BUTTON) {
uint32_t button_index = random() % BUTTON_CHANNEL_NUM; uint32_t button_index = random() % BUTTON_CHANNEL_NUM;
valid_message.handle = button_handle[button_index]; valid_message.handle = button_handle[button_index];
touch_button_message_t button_message = { button_message.event = TOUCH_BUTTON_EVT_ON_PRESS;
.event = TOUCH_BUTTON_EVT_ON_PRESS
};
memcpy(valid_message.child_msg, &button_message, sizeof(button_message)); //Construct child message memcpy(valid_message.child_msg, &button_message, sizeof(button_message)); //Construct child message
xQueueSend(monitor.valid_msg_handle, &valid_message, portMAX_DELAY); xQueueSend(monitor.valid_msg_handle, &valid_message, portMAX_DELAY);
test_button_event_simulator(valid_message.handle, button_message.event); test_button_event_simulator(valid_message.handle, button_message.event);
} else if (valid_message.element_type == TOUCH_ELEM_TYPE_SLIDER) { } else if (valid_message.element_type == TOUCH_ELEM_TYPE_SLIDER) {
valid_message.handle = slider_handle; valid_message.handle = slider_handle;
touch_slider_message_t slider_message = { slider_message.event = TOUCH_SLIDER_EVT_ON_PRESS;
.event = TOUCH_SLIDER_EVT_ON_PRESS, slider_message.position = 0; //No check
.position = 0 //No check
};
memcpy(valid_message.child_msg, &slider_message, sizeof(slider_message)); //Construct child message memcpy(valid_message.child_msg, &slider_message, sizeof(slider_message)); //Construct child message
xQueueSend(monitor.valid_msg_handle, &valid_message, portMAX_DELAY); xQueueSend(monitor.valid_msg_handle, &valid_message, portMAX_DELAY);
test_slider_event_simulator(valid_message.handle, slider_message.event, 1); 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_x_axis_index = random() % MATRIX_CHANNEL_NUM_X;
uint32_t matrix_y_axis_index = random() % MATRIX_CHANNEL_NUM_Y; uint32_t matrix_y_axis_index = random() % MATRIX_CHANNEL_NUM_Y;
valid_message.handle = matrix_handle; valid_message.handle = matrix_handle;
touch_matrix_message_t matrix_message = { matrix_message.event = TOUCH_MATRIX_EVT_ON_PRESS;
.event = TOUCH_MATRIX_EVT_ON_PRESS, matrix_message.position.x_axis = matrix_x_axis_index;
.position.x_axis = matrix_x_axis_index, matrix_message.position.y_axis = matrix_y_axis_index;
.position.y_axis = matrix_y_axis_index, matrix_message.position.index = matrix_x_axis_index * MATRIX_CHANNEL_NUM_Y + matrix_y_axis_index;
.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 memcpy(valid_message.child_msg, &matrix_message, sizeof(matrix_message)); //Construct child message
xQueueSend(monitor.valid_msg_handle, &valid_message, portMAX_DELAY); xQueueSend(monitor.valid_msg_handle, &valid_message, portMAX_DELAY);
test_matrix_event_simulator(valid_message.handle, matrix_message.event, matrix_message.position.index); 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)); os_ret = xSemaphoreTake(monitor.response_sig_handle, pdMS_TO_TICKS(500));
TEST_ASSERT_MESSAGE(os_ret == pdPASS, "response queue timeout (500ms)"); TEST_ASSERT_MESSAGE(os_ret == pdPASS, "response queue timeout (500ms)");
if (valid_message.element_type == TOUCH_ELEM_TYPE_BUTTON) { if (valid_message.element_type == TOUCH_ELEM_TYPE_BUTTON) {
touch_button_message_t button_message;
button_message.event = TOUCH_BUTTON_EVT_ON_RELEASE; button_message.event = TOUCH_BUTTON_EVT_ON_RELEASE;
memcpy(valid_message.child_msg, &button_message, sizeof(button_message)); memcpy(valid_message.child_msg, &button_message, sizeof(button_message));
xQueueSend(monitor.valid_msg_handle, &valid_message, portMAX_DELAY); xQueueSend(monitor.valid_msg_handle, &valid_message, portMAX_DELAY);
test_button_event_simulator(valid_message.handle, button_message.event); test_button_event_simulator(valid_message.handle, button_message.event);
} else if (valid_message.element_type == TOUCH_ELEM_TYPE_SLIDER) { } else if (valid_message.element_type == TOUCH_ELEM_TYPE_SLIDER) {
touch_slider_message_t slider_message;
slider_message.event = TOUCH_SLIDER_EVT_ON_RELEASE; slider_message.event = TOUCH_SLIDER_EVT_ON_RELEASE;
memcpy(valid_message.child_msg, &slider_message, sizeof(slider_message)); memcpy(valid_message.child_msg, &slider_message, sizeof(slider_message));
xQueueSend(monitor.valid_msg_handle, &valid_message, portMAX_DELAY); xQueueSend(monitor.valid_msg_handle, &valid_message, portMAX_DELAY);
test_slider_event_simulator(valid_message.handle, slider_message.event, 1); test_slider_event_simulator(valid_message.handle, slider_message.event, 1);
} else if (valid_message.element_type == TOUCH_ELEM_TYPE_MATRIX) { } else if (valid_message.element_type == TOUCH_ELEM_TYPE_MATRIX) {
touch_matrix_message_t matrix_message;
matrix_message.event = TOUCH_MATRIX_EVT_ON_RELEASE; matrix_message.event = TOUCH_MATRIX_EVT_ON_RELEASE;
memcpy(valid_message.child_msg, &matrix_message, sizeof(matrix_message)); memcpy(valid_message.child_msg, &matrix_message, sizeof(matrix_message));
xQueueSend(monitor.valid_msg_handle, &valid_message, portMAX_DELAY); xQueueSend(monitor.valid_msg_handle, &valid_message, portMAX_DELAY);

View File

@@ -1,3 +1,8 @@
/*
* SPDX-FileCopyrightText: 2022 Espressif Systems (Shanghai) CO LTD
*
* SPDX-License-Identifier: Unlicense OR CC0-1.0
*/
#include <stdio.h> #include <stdio.h>
#include <string.h> #include <string.h>
#include <stdlib.h> #include <stdlib.h>

View File

@@ -1,3 +1,8 @@
/*
* SPDX-FileCopyrightText: 2022 Espressif Systems (Shanghai) CO LTD
*
* SPDX-License-Identifier: Unlicense OR CC0-1.0
*/
#include <stdio.h> #include <stdio.h>
#include <string.h> #include <string.h>
#include <stdlib.h> #include <stdlib.h>

View File

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

View File

@@ -0,0 +1 @@
CONFIG_COMPILER_OPTIMIZATION_NONE=y

View File

@@ -0,0 +1 @@
CONFIG_COMPILER_OPTIMIZATION_PERF=y

View File

@@ -0,0 +1,3 @@
CONFIG_FREERTOS_HZ=1000
CONFIG_ESP_TASK_WDT=n
CONFIG_ESP_MAIN_TASK_STACK_SIZE=8192

View File

@@ -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. * SPDX-FileCopyrightText: 2016-2022 Espressif Systems (Shanghai) CO LTD
// You may obtain a copy of the License at *
// * SPDX-License-Identifier: Apache-2.0
// 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.
#include <string.h> #include <string.h>
#include <sys/queue.h> #include <sys/queue.h>

View File

@@ -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. * SPDX-FileCopyrightText: 2016-2022 Espressif Systems (Shanghai) CO LTD
// You may obtain a copy of the License at *
// * SPDX-License-Identifier: Apache-2.0
// 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.
#include <string.h> #include <string.h>
#include <sys/queue.h> #include <sys/queue.h>

View File

@@ -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. * SPDX-FileCopyrightText: 2016-2022 Espressif Systems (Shanghai) CO LTD
// You may obtain a copy of the License at *
// * SPDX-License-Identifier: Apache-2.0
// 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.
#include <string.h> #include <string.h>
#include <sys/queue.h> #include <sys/queue.h>

View File

@@ -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 * SPDX-License-Identifier: CC0-1.0
*/ */

View File

@@ -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 * SPDX-License-Identifier: CC0-1.0
*/ */

View File

@@ -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 * SPDX-License-Identifier: CC0-1.0
*/ */

View File

@@ -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 * SPDX-License-Identifier: CC0-1.0
*/ */

View File

@@ -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 * SPDX-License-Identifier: CC0-1.0
*/ */

View File

@@ -1321,15 +1321,6 @@ components/tcp_transport/test/test_transport_connect.c
components/tcp_transport/test/test_transport_fixtures.c components/tcp_transport/test/test_transport_fixtures.c
components/tcp_transport/transport_utils.c components/tcp_transport/transport_utils.c
components/tinyusb/additions/include/tusb_config.h 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/esp32ulp_mapgen.py
components/ulp/test/esp32/test_ulp_as.c components/ulp/test/esp32/test_ulp_as.c
components/unity/include/priv/setjmp.h 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/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_master/main/app_main.c
examples/peripherals/spi_slave_hd/segment_mode/seg_slave/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/example_test.py
examples/peripherals/twai/twai_alert_and_recovery/main/twai_alert_and_recovery_example_main.c examples/peripherals/twai/twai_alert_and_recovery/main/twai_alert_and_recovery_example_main.c
examples/peripherals/twai/twai_network/example_test.py examples/peripherals/twai/twai_network/example_test.py