mirror of
https://github.com/espressif/esp-idf.git
synced 2025-09-30 19:19:21 +00:00
Temperature_sensor: Create new temperature sensor API
This commit is contained in:
@@ -0,0 +1,5 @@
|
||||
# This is the project CMakeLists.txt file for the test subproject
|
||||
cmake_minimum_required(VERSION 3.5)
|
||||
|
||||
include($ENV{IDF_PATH}/tools/cmake/project.cmake)
|
||||
project(test_app_include_temperature_sensor)
|
2
components/driver/test_apps/temperature_sensor/README.md
Normal file
2
components/driver/test_apps/temperature_sensor/README.md
Normal file
@@ -0,0 +1,2 @@
|
||||
| Supported Targets | ESP32-S2 | ESP32-S3 | ESP32-C3 |
|
||||
| ----------------- | -------- | -------- | -------- |
|
@@ -0,0 +1,7 @@
|
||||
set(srcs "test_app_main.c"
|
||||
"test_temperature_sensor.c")
|
||||
|
||||
idf_component_register(SRCS ${srcs}
|
||||
PRIV_REQUIRES driver unity)
|
||||
|
||||
target_link_libraries(${COMPONENT_LIB} INTERFACE "-u test_app_include_temperature_sensor")
|
@@ -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 (-600)
|
||||
|
||||
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,0 +1,81 @@
|
||||
/*
|
||||
* SPDX-FileCopyrightText: 2022 Espressif Systems (Shanghai) CO LTD
|
||||
*
|
||||
* SPDX-License-Identifier: Apache-2.0
|
||||
*/
|
||||
#include <stdio.h>
|
||||
#include <stdlib.h>
|
||||
#include "esp_log.h"
|
||||
#include "unity.h"
|
||||
#include "driver/temperature_sensor.h"
|
||||
|
||||
void test_app_include_temperature_sensor(void)
|
||||
{
|
||||
}
|
||||
|
||||
TEST_CASE("Temperature_sensor_driver_workflow_test", "[temperature_sensor]")
|
||||
{
|
||||
printf("Initializing Temperature sensor\n");
|
||||
float tsens_out;
|
||||
temperature_sensor_config_t temp_sensor = TEMPERAUTRE_SENSOR_CONFIG_DEFAULT(10, 50);
|
||||
temperature_sensor_handle_t temp_handle = NULL;
|
||||
TEST_ESP_OK(temperature_sensor_install(&temp_sensor, &temp_handle));
|
||||
TEST_ESP_OK(temperature_sensor_start(temp_handle));
|
||||
printf("Temperature sensor started\n");
|
||||
TEST_ESP_OK(temperature_sensor_get_celsius(temp_handle, &tsens_out));
|
||||
printf("Temperature out celsius %f°C\n", tsens_out);
|
||||
TEST_ESP_OK(temperature_sensor_stop(temp_handle));
|
||||
TEST_ESP_OK(temperature_sensor_uninstall(temp_handle));
|
||||
// Reconfig the temperature sensor.
|
||||
temp_sensor.range_min = -20;
|
||||
temp_sensor.range_max = 45;
|
||||
TEST_ESP_OK(temperature_sensor_install(&temp_sensor, &temp_handle));
|
||||
TEST_ESP_OK(temperature_sensor_start(temp_handle));
|
||||
printf("Temperature sensor started again\n");
|
||||
TEST_ESP_OK(temperature_sensor_get_celsius(temp_handle, &tsens_out));
|
||||
printf("Temperature out celsius %f°C\n", tsens_out);
|
||||
TEST_ESP_OK(temperature_sensor_stop(temp_handle));
|
||||
TEST_ESP_OK(temperature_sensor_uninstall(temp_handle));
|
||||
}
|
||||
|
||||
TEST_CASE("Double install error cause test", "[temperature_sensor]")
|
||||
{
|
||||
printf("Initializing Temperature sensor\n");
|
||||
temperature_sensor_config_t temp_sensor = TEMPERAUTRE_SENSOR_CONFIG_DEFAULT(10, 50);
|
||||
temperature_sensor_handle_t temp_handle = NULL;
|
||||
TEST_ESP_OK(temperature_sensor_install(&temp_sensor, &temp_handle));
|
||||
TEST_ESP_ERR(ESP_ERR_INVALID_STATE, temperature_sensor_install(&temp_sensor, &temp_handle));
|
||||
TEST_ESP_OK(temperature_sensor_uninstall(temp_handle));
|
||||
}
|
||||
|
||||
TEST_CASE("Double start error cause test", "[temperatere_sensor]")
|
||||
{
|
||||
printf("Initializing Temperature sensor\n");
|
||||
temperature_sensor_config_t temp_sensor = TEMPERAUTRE_SENSOR_CONFIG_DEFAULT(10, 50);
|
||||
temperature_sensor_handle_t temp_handle = NULL;
|
||||
TEST_ESP_OK(temperature_sensor_install(&temp_sensor, &temp_handle));
|
||||
TEST_ESP_OK(temperature_sensor_start(temp_handle));
|
||||
TEST_ESP_ERR(ESP_ERR_INVALID_STATE, temperature_sensor_start(temp_handle));
|
||||
TEST_ESP_OK(temperature_sensor_stop(temp_handle));
|
||||
TEST_ESP_OK(temperature_sensor_uninstall(temp_handle));
|
||||
}
|
||||
|
||||
TEST_CASE("Double Start-Stop test", "[temperature_sensor]")
|
||||
{
|
||||
printf("Initializing Temperature sensor\n");
|
||||
float tsens_out;
|
||||
temperature_sensor_config_t temp_sensor = TEMPERAUTRE_SENSOR_CONFIG_DEFAULT(10, 50);
|
||||
temperature_sensor_handle_t temp_handle = NULL;
|
||||
TEST_ESP_OK(temperature_sensor_install(&temp_sensor, &temp_handle));
|
||||
TEST_ESP_OK(temperature_sensor_start(temp_handle));
|
||||
printf("Temperature sensor started\n");
|
||||
TEST_ESP_OK(temperature_sensor_get_celsius(temp_handle, &tsens_out));
|
||||
printf("Temperature out celsius %f°C\n", tsens_out);
|
||||
TEST_ESP_OK(temperature_sensor_stop(temp_handle));
|
||||
TEST_ESP_OK(temperature_sensor_start(temp_handle));
|
||||
printf("Temperature sensor started again\n");
|
||||
TEST_ESP_OK(temperature_sensor_get_celsius(temp_handle, &tsens_out));
|
||||
printf("Temperature out celsius %f°C\n", tsens_out);
|
||||
TEST_ESP_OK(temperature_sensor_stop(temp_handle));
|
||||
TEST_ESP_OK(temperature_sensor_uninstall(temp_handle));
|
||||
}
|
@@ -0,0 +1,18 @@
|
||||
# SPDX-FileCopyrightText: 2021-2022 Espressif Systems (Shanghai) CO LTD
|
||||
# SPDX-License-Identifier: CC0-1.0
|
||||
|
||||
import pytest
|
||||
from pytest_embedded import Dut
|
||||
|
||||
|
||||
@pytest.mark.esp32s2
|
||||
@pytest.mark.esp32c3
|
||||
@pytest.mark.esp32s3
|
||||
@pytest.mark.generic
|
||||
@pytest.mark.parametrize('config', [
|
||||
'release',
|
||||
], indirect=True)
|
||||
def test_temperature_sensor_driver(dut: Dut) -> None:
|
||||
dut.expect('Press ENTER to see the list of tests')
|
||||
dut.write('*')
|
||||
dut.expect_unity_test_output(timeout=120)
|
@@ -0,0 +1,5 @@
|
||||
CONFIG_PM_ENABLE=y
|
||||
CONFIG_FREERTOS_USE_TICKLESS_IDLE=y
|
||||
CONFIG_COMPILER_OPTIMIZATION_SIZE=y
|
||||
CONFIG_BOOTLOADER_COMPILER_OPTIMIZATION_SIZE=y
|
||||
CONFIG_COMPILER_OPTIMIZATION_ASSERTIONS_SILENT=y
|
@@ -0,0 +1 @@
|
||||
CONFIG_ESP_TASK_WDT=n
|
Reference in New Issue
Block a user