starting with component unit testing (running on device)
Signed-off-by: Peter Siegmund <developer@mars3142.org>
This commit is contained in:
@@ -1,3 +0,0 @@
|
|||||||
idf_component_register(SRCS "osr_ble.c"
|
|
||||||
INCLUDE_DIRS "."
|
|
||||||
PRIV_REQUIRES "nvs_flash")
|
|
2
components/logger/CMakeLists.txt
Normal file
2
components/logger/CMakeLists.txt
Normal file
@@ -0,0 +1,2 @@
|
|||||||
|
idf_component_register(SRCS "logger.c"
|
||||||
|
INCLUDE_DIRS "include")
|
5
components/logger/include/logger.h
Normal file
5
components/logger/include/logger.h
Normal file
@@ -0,0 +1,5 @@
|
|||||||
|
#pragma once
|
||||||
|
|
||||||
|
int add(int a, int b);
|
||||||
|
|
||||||
|
void log_message(const char* message);
|
11
components/logger/logger.c
Normal file
11
components/logger/logger.c
Normal file
@@ -0,0 +1,11 @@
|
|||||||
|
#include "logger.h"
|
||||||
|
|
||||||
|
#include <stdio.h>
|
||||||
|
|
||||||
|
int add(int a, int b) {
|
||||||
|
return a + b;
|
||||||
|
}
|
||||||
|
|
||||||
|
void log_message(const char* message) {
|
||||||
|
printf("%s\n", message);
|
||||||
|
}
|
3
components/logger/test/CMakeLists.txt
Normal file
3
components/logger/test/CMakeLists.txt
Normal file
@@ -0,0 +1,3 @@
|
|||||||
|
idf_component_register(SRC_DIRS "."
|
||||||
|
INCLUDE_DIRS "."
|
||||||
|
REQUIRES cmock logger)
|
7
components/logger/test/logger_test.c
Normal file
7
components/logger/test/logger_test.c
Normal file
@@ -0,0 +1,7 @@
|
|||||||
|
#include "unity.h"
|
||||||
|
|
||||||
|
#include "logger.h"
|
||||||
|
|
||||||
|
TEST_CASE("Add two numbers", "[logger]") {
|
||||||
|
TEST_ASSERT_EQUAL(3, add(1, 2));
|
||||||
|
}
|
@@ -1,2 +1,5 @@
|
|||||||
idf_component_register(SRCS "main.c"
|
idf_component_register(SRCS "main.c" "osr_ble.c"
|
||||||
INCLUDE_DIRS ".")
|
INCLUDE_DIRS "."
|
||||||
|
PRIV_REQUIRES
|
||||||
|
nvs_flash
|
||||||
|
logger)
|
||||||
|
51
main/main.c
51
main/main.c
@@ -1,19 +1,58 @@
|
|||||||
#include <esp_task_wdt.h>
|
#include <esp_task_wdt.h>
|
||||||
#include <stdio.h>
|
#include <stdio.h>
|
||||||
|
#include "esp_chip_info.h"
|
||||||
|
#include "esp_flash.h"
|
||||||
|
#include "esp_log.h"
|
||||||
#include "osr_ble.h"
|
#include "osr_ble.h"
|
||||||
|
#include "sdkconfig.h"
|
||||||
|
|
||||||
|
#include "logger.h"
|
||||||
|
|
||||||
|
#define TAG "app"
|
||||||
|
|
||||||
|
void esp32_info() {
|
||||||
|
/* Print chip information */
|
||||||
|
esp_chip_info_t chip_info;
|
||||||
|
uint32_t flash_size;
|
||||||
|
esp_chip_info(&chip_info);
|
||||||
|
printf("This is %s chip with %d CPU core(s), %s%s%s%s, ", CONFIG_IDF_TARGET,
|
||||||
|
chip_info.cores,
|
||||||
|
(chip_info.features & CHIP_FEATURE_WIFI_BGN) ? "WiFi/" : "",
|
||||||
|
(chip_info.features & CHIP_FEATURE_BT) ? "BT" : "",
|
||||||
|
(chip_info.features & CHIP_FEATURE_BLE) ? "BLE" : "",
|
||||||
|
(chip_info.features & CHIP_FEATURE_IEEE802154)
|
||||||
|
? ", 802.15.4 (Zigbee/Thread)"
|
||||||
|
: "");
|
||||||
|
|
||||||
|
unsigned major_rev = chip_info.revision / 100;
|
||||||
|
unsigned minor_rev = chip_info.revision % 100;
|
||||||
|
printf("silicon revision v%d.%d, ", major_rev, minor_rev);
|
||||||
|
if (esp_flash_get_size(NULL, &flash_size) != ESP_OK) {
|
||||||
|
printf("Get flash size failed");
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
printf(
|
||||||
|
"%" PRIu32 "MB %s flash\n", flash_size / (uint32_t)(1024 * 1024),
|
||||||
|
(chip_info.features & CHIP_FEATURE_EMB_FLASH) ? "embedded" : "external");
|
||||||
|
|
||||||
|
printf("Minimum free heap size: %" PRIu32 " bytes\n",
|
||||||
|
esp_get_minimum_free_heap_size());
|
||||||
|
}
|
||||||
|
|
||||||
void setup() {
|
void setup() {
|
||||||
osr_ble_init();
|
osr_ble_init();
|
||||||
|
log_message("Hello World!");
|
||||||
}
|
}
|
||||||
|
|
||||||
void loop() {
|
void loop(void* args) {
|
||||||
ESP_ERROR_CHECK(esp_task_wdt_reset());
|
while (1) {
|
||||||
|
vTaskDelay(pdMS_TO_TICKS(1000));
|
||||||
|
ESP_LOGI(TAG, "Hello World!");
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void app_main() {
|
void app_main() {
|
||||||
setup();
|
setup();
|
||||||
while (1) {
|
xTaskCreatePinnedToCore(loop, "loop", 4096, NULL, 5, NULL, 1);
|
||||||
loop();
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
@@ -1,3 +1,4 @@
|
|||||||
[pytest]
|
[pytest]
|
||||||
addopts = --embedded-services esp,idf -s
|
addopts = --embedded-services esp,idf -s
|
||||||
python_files = *.py
|
python_files = *.py
|
||||||
|
timeout = 60
|
||||||
|
16
test/CMakeLists.txt
Normal file
16
test/CMakeLists.txt
Normal file
@@ -0,0 +1,16 @@
|
|||||||
|
# This is the project CMakeLists.txt file for the test subproject
|
||||||
|
cmake_minimum_required(VERSION 3.16)
|
||||||
|
|
||||||
|
# Include the components directory of the main application:
|
||||||
|
#
|
||||||
|
set(EXTRA_COMPONENT_DIRS "../components")
|
||||||
|
|
||||||
|
# Set the components to include the tests for.
|
||||||
|
# This can be overriden from CMake cache:
|
||||||
|
# - when invoking CMake directly: cmake -D TEST_COMPONENTS="xxxxx" ..
|
||||||
|
# - when using idf.py: idf.py -T xxxxx build
|
||||||
|
#
|
||||||
|
set(TEST_COMPONENTS "logger" CACHE STRING "List of components to test")
|
||||||
|
|
||||||
|
include($ENV{IDF_PATH}/tools/cmake/project.cmake)
|
||||||
|
project(component_unit_test)
|
6
test/Makefile
Normal file
6
test/Makefile
Normal file
@@ -0,0 +1,6 @@
|
|||||||
|
test:
|
||||||
|
@echo "Running tests..."
|
||||||
|
@idf.py fullclean build
|
||||||
|
pytest
|
||||||
|
|
||||||
|
.PHONE: test
|
2
test/main/CMakeLists.txt
Normal file
2
test/main/CMakeLists.txt
Normal file
@@ -0,0 +1,2 @@
|
|||||||
|
idf_component_register(SRCS "components_test.c"
|
||||||
|
INCLUDE_DIRS ".")
|
16
test/main/components_test.c
Normal file
16
test/main/components_test.c
Normal file
@@ -0,0 +1,16 @@
|
|||||||
|
#include <stdio.h>
|
||||||
|
#include <string.h>
|
||||||
|
#include "unity.h"
|
||||||
|
|
||||||
|
static void print_banner(const char* text);
|
||||||
|
|
||||||
|
void app_main(void) {
|
||||||
|
print_banner("Running all the registered tests");
|
||||||
|
UNITY_BEGIN();
|
||||||
|
unity_run_all_tests();
|
||||||
|
UNITY_END();
|
||||||
|
}
|
||||||
|
|
||||||
|
static void print_banner(const char* text) {
|
||||||
|
printf("\n#### %s #####\n\n", text);
|
||||||
|
}
|
6
test/pytest_unittest.py
Normal file
6
test/pytest_unittest.py
Normal file
@@ -0,0 +1,6 @@
|
|||||||
|
import pytest
|
||||||
|
from pytest_embedded import Dut
|
||||||
|
|
||||||
|
def test_unit_test(dut: Dut) -> None:
|
||||||
|
dut.expect("0 Failures")
|
||||||
|
dut.expect("Returned from app_main")
|
2
test/sdkconfig.defaults
Normal file
2
test/sdkconfig.defaults
Normal file
@@ -0,0 +1,2 @@
|
|||||||
|
# disable watchdog
|
||||||
|
CONFIG_ESP_TASK_WDT_EN=n
|
@@ -1,2 +0,0 @@
|
|||||||
def test_main(dut):
|
|
||||||
dut.expect('waiting for download')
|
|
Reference in New Issue
Block a user