Adicionar primeiro
This commit is contained in:
@@ -0,0 +1,9 @@
|
||||
# The following lines of boilerplate have to be in your project's CMakeLists
|
||||
# in this exact order for cmake to work correctly
|
||||
cmake_minimum_required(VERSION 3.5)
|
||||
|
||||
set(EXTRA_COMPONENT_DIRS "$ENV{IDF_PATH}/tools/unit-test-app/components"
|
||||
"../../ntc_driver")
|
||||
|
||||
include($ENV{IDF_PATH}/tools/cmake/project.cmake)
|
||||
project(ntc_driver_test)
|
||||
@@ -0,0 +1,3 @@
|
||||
idf_component_register(SRC_DIRS "."
|
||||
PRIV_INCLUDE_DIRS "."
|
||||
PRIV_REQUIRES unity ntc_driver)
|
||||
@@ -0,0 +1,73 @@
|
||||
/*
|
||||
* SPDX-FileCopyrightText: 2024 Espressif Systems (Shanghai) CO LTD
|
||||
*
|
||||
* SPDX-License-Identifier: Apache-2.0
|
||||
*/
|
||||
|
||||
#include "freertos/FreeRTOS.h"
|
||||
#include "freertos/task.h"
|
||||
#include "soc/soc_caps.h"
|
||||
#include "unity.h"
|
||||
|
||||
#include "ntc_driver.h"
|
||||
|
||||
#define TEST_MEMORY_LEAK_THRESHOLD (-460)
|
||||
|
||||
const static char *TAG = "NTC_DRIVER_TEST";
|
||||
|
||||
static size_t before_free_8bit;
|
||||
static size_t before_free_32bit;
|
||||
|
||||
TEST_CASE("test_ntc_driver", "[ntc_driver]")
|
||||
{
|
||||
ntc_config_t ntc_config = {
|
||||
.b_value = 3950,
|
||||
.r25_ohm = 10000,
|
||||
.fixed_ohm = 10000,
|
||||
.vdd_mv = 3300,
|
||||
.circuit_mode = CIRCUIT_MODE_NTC_GND,
|
||||
.atten = ADC_ATTEN_DB_11,
|
||||
.channel = ADC_CHANNEL_3,
|
||||
.unit = ADC_UNIT_1
|
||||
};
|
||||
|
||||
ntc_device_handle_t ntc = NULL;
|
||||
adc_oneshot_unit_handle_t adc_handle = NULL;
|
||||
ESP_ERROR_CHECK(ntc_dev_create(&ntc_config, &ntc, &adc_handle));
|
||||
ESP_ERROR_CHECK(ntc_dev_get_adc_handle(ntc, &adc_handle));
|
||||
|
||||
float temp = 0.0;
|
||||
for (int i = 0; i < 10; i++) {
|
||||
if (ntc_dev_get_temperature(ntc, &temp) == ESP_OK) {
|
||||
ESP_LOGI(TAG, "NTC temperature = %.2f ℃", temp);
|
||||
}
|
||||
}
|
||||
ESP_ERROR_CHECK(ntc_dev_delete(ntc));
|
||||
}
|
||||
|
||||
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)
|
||||
{
|
||||
printf("NTC DRIVER TEST \n");
|
||||
unity_run_menu();
|
||||
}
|
||||
@@ -0,0 +1,41 @@
|
||||
# SPDX-FileCopyrightText: 2024Espressif Systems (Shanghai) CO LTD
|
||||
# SPDX-License-Identifier: Apache-2.0
|
||||
|
||||
'''
|
||||
Steps to run these cases:
|
||||
- Build
|
||||
- . ${IDF_PATH}/export.sh
|
||||
- pip install idf_build_apps
|
||||
- python tools/build_apps.py components/sensors/ntc_driver/test_apps -t esp32
|
||||
- Test
|
||||
- pip install -r tools/requirements/requirement.pytest.txt
|
||||
- pytest components/sensors/ntc_driver/test_apps --target esp32
|
||||
'''
|
||||
|
||||
import pytest
|
||||
from pytest_embedded import Dut
|
||||
|
||||
@pytest.mark.target('esp32')
|
||||
@pytest.mark.target('esp32c3')
|
||||
@pytest.mark.target('esp32c6')
|
||||
@pytest.mark.target('esp32s3')
|
||||
@pytest.mark.env('generic')
|
||||
@pytest.mark.parametrize(
|
||||
'config',
|
||||
[
|
||||
'defaults',
|
||||
],
|
||||
)
|
||||
def test_ntc_driver(dut: Dut)-> None:
|
||||
dut.run_all_single_board_cases()
|
||||
|
||||
@pytest.mark.target('esp32c2')
|
||||
@pytest.mark.env('xtal_26mhz')
|
||||
@pytest.mark.parametrize(
|
||||
'config , baud',
|
||||
[
|
||||
('c2_xtal_26mhz', '74880'),
|
||||
],
|
||||
)
|
||||
def test_ntc_driver_esp32c2(dut: Dut)-> None:
|
||||
dut.run_all_single_board_cases()
|
||||
Reference in New Issue
Block a user