mirror of
https://github.com/espressif/esp-idf.git
synced 2024-10-05 20:47:46 -04:00
feat(esp_hid): migrate the tests from unit-test-app
This commit is contained in:
parent
b8444c2234
commit
9e20bf4f06
@ -1,4 +0,0 @@
|
||||
idf_component_register(SRC_DIRS "."
|
||||
INCLUDE_DIRS "."
|
||||
REQUIRES cmock test_utils esp_hid)
|
||||
target_compile_options(${COMPONENT_LIB} PRIVATE "-Wno-format")
|
8
components/esp_hid/test_apps/.build-test-rules.yml
Normal file
8
components/esp_hid/test_apps/.build-test-rules.yml
Normal file
@ -0,0 +1,8 @@
|
||||
# Documentation: .gitlab/ci/README.md#manifest-file-to-control-the-buildtest-apps
|
||||
|
||||
components/esp_hid/test_apps:
|
||||
enable:
|
||||
- if: IDF_TARGET in ["esp32", "esp32c3"]
|
||||
reason: Testing on one chip per architecture is currently enough
|
||||
depends_components:
|
||||
- esp_hid
|
9
components/esp_hid/test_apps/CMakeLists.txt
Normal file
9
components/esp_hid/test_apps/CMakeLists.txt
Normal file
@ -0,0 +1,9 @@
|
||||
cmake_minimum_required(VERSION 3.16)
|
||||
|
||||
include($ENV{IDF_PATH}/tools/cmake/project.cmake)
|
||||
set(COMPONENTS main)
|
||||
list(PREPEND SDKCONFIG_DEFAULTS
|
||||
"$ENV{IDF_PATH}/tools/test_apps/configs/sdkconfig.debug_helpers"
|
||||
"sdkconfig.defaults")
|
||||
|
||||
project(esp_hid_test)
|
@ -1,4 +1,28 @@
|
||||
### Tests have been generated with the following code
|
||||
| Supported Targets | ESP32 | ESP32-C3 |
|
||||
| ----------------- | ----- | -------- |
|
||||
|
||||
# esp_hid unit tests
|
||||
|
||||
The unit tests are currently run only on the chips listed above just to save CI resources. If you are adding some tests which need to run on a different chip, update [.build-test-rules.yml](../.build-test-rules.yml), adding the chip you need.
|
||||
|
||||
When adding new test cases, check if the `depends_components` list in `.build-test-rules.yml` needs to be updated to include additional components. The test app will only be built and tested when these components are modified.
|
||||
|
||||
To build and run this test app, using esp32c3 target for example:
|
||||
|
||||
```bash
|
||||
idf.py set-target esp32c3
|
||||
idf.py build flash monitor
|
||||
```
|
||||
|
||||
To run tests using pytest:
|
||||
|
||||
```bash
|
||||
idf.py set-target esp32c3
|
||||
idf.py build
|
||||
pytest --target=esp32c3
|
||||
```
|
||||
|
||||
### Code used to generate tests
|
||||
|
||||
```c
|
||||
|
4
components/esp_hid/test_apps/main/CMakeLists.txt
Normal file
4
components/esp_hid/test_apps/main/CMakeLists.txt
Normal file
@ -0,0 +1,4 @@
|
||||
idf_component_register(SRCS "test_esp_hid_main.c"
|
||||
"test_esp_hid.c"
|
||||
PRIV_REQUIRES unity esp_hid
|
||||
WHOLE_ARCHIVE)
|
@ -1,16 +1,9 @@
|
||||
// Copyright 2015-2019 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: 2019-2023 Espressif Systems (Shanghai) CO LTD
|
||||
*
|
||||
* SPDX-License-Identifier: Apache-2.0
|
||||
*/
|
||||
|
||||
#pragma once
|
||||
|
||||
const unsigned char hidReportMap[] = {
|
@ -1,16 +1,8 @@
|
||||
// Copyright 2015-2019 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: 2019-2023 Espressif Systems (Shanghai) CO LTD
|
||||
*
|
||||
* SPDX-License-Identifier: Apache-2.0
|
||||
*/
|
||||
|
||||
#include <stdio.h>
|
||||
#include <stdlib.h>
|
||||
@ -18,7 +10,6 @@
|
||||
#include <sys/unistd.h>
|
||||
#include "unity.h"
|
||||
#include "unity_test_runner.h"
|
||||
#include "test_utils.h"
|
||||
#include "esp_log.h"
|
||||
#include "esp_hid_common.h"
|
||||
#include "hid_descriptor.h"
|
48
components/esp_hid/test_apps/main/test_esp_hid_main.c
Normal file
48
components/esp_hid/test_apps/main/test_esp_hid_main.c
Normal file
@ -0,0 +1,48 @@
|
||||
/*
|
||||
* SPDX-FileCopyrightText: 2023 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_DEFAULT 0
|
||||
static int leak_threshold = TEST_MEMORY_LEAK_THRESHOLD_DEFAULT;
|
||||
void set_leak_threshold(int threshold)
|
||||
{
|
||||
leak_threshold = threshold;
|
||||
}
|
||||
|
||||
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 >= 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");
|
||||
|
||||
leak_threshold = TEST_MEMORY_LEAK_THRESHOLD_DEFAULT;
|
||||
}
|
||||
|
||||
void app_main(void)
|
||||
{
|
||||
printf("Running esp_hid component tests\n");
|
||||
unity_run_menu();
|
||||
}
|
12
components/esp_hid/test_apps/pytest_esp_hid.py
Normal file
12
components/esp_hid/test_apps/pytest_esp_hid.py
Normal file
@ -0,0 +1,12 @@
|
||||
# SPDX-FileCopyrightText: 2022-2023 Espressif Systems (Shanghai) CO LTD
|
||||
# SPDX-License-Identifier: CC0-1.0
|
||||
|
||||
import pytest
|
||||
from pytest_embedded import Dut
|
||||
|
||||
|
||||
@pytest.mark.generic
|
||||
@pytest.mark.esp32
|
||||
@pytest.mark.esp32c3
|
||||
def test_esp_hid(dut: Dut) -> None:
|
||||
dut.run_all_single_board_cases()
|
1
components/esp_hid/test_apps/sdkconfig.defaults
Normal file
1
components/esp_hid/test_apps/sdkconfig.defaults
Normal file
@ -0,0 +1 @@
|
||||
CONFIG_ESP_TASK_WDT_CHECK_IDLE_TASK_CPU0=n
|
@ -419,8 +419,6 @@ components/esp_hid/private/bt_hidd.h
|
||||
components/esp_hid/private/bt_hidh.h
|
||||
components/esp_hid/private/esp_hidd_private.h
|
||||
components/esp_hid/src/esp_hid_common.c
|
||||
components/esp_hid/test/hid_descriptor.h
|
||||
components/esp_hid/test/test_esp_hid.c
|
||||
components/esp_local_ctrl/src/esp_local_ctrl_handler.c
|
||||
components/esp_local_ctrl/src/esp_local_ctrl_priv.h
|
||||
components/esp_local_ctrl/src/esp_local_ctrl_transport_ble.c
|
||||
|
Loading…
Reference in New Issue
Block a user