From 0a5fa9b477bd6e0e35caf1d06561f7b69c17d049 Mon Sep 17 00:00:00 2001 From: Lucas Saavedra Vaz <32426024+lucasssvaz@users.noreply.github.com> Date: Sun, 4 Aug 2024 16:54:14 -0300 Subject: [PATCH] new tests --- tests/validation/cpu/ci.json | 5 + tests/validation/cpu/cpu.ino | 35 ++++++ tests/validation/cpu/test_cpu.py | 2 + tests/validation/deep_sleep/ci.json | 5 + tests/validation/deep_sleep/deep_sleep.ino | 113 ++++++++++++++++++ .../validation/deep_sleep/test_deep_sleep.py | 2 + 6 files changed, 162 insertions(+) create mode 100644 tests/validation/cpu/ci.json create mode 100644 tests/validation/cpu/cpu.ino create mode 100644 tests/validation/cpu/test_cpu.py create mode 100644 tests/validation/deep_sleep/ci.json create mode 100644 tests/validation/deep_sleep/deep_sleep.ino create mode 100644 tests/validation/deep_sleep/test_deep_sleep.py diff --git a/tests/validation/cpu/ci.json b/tests/validation/cpu/ci.json new file mode 100644 index 00000000000..54da33b6176 --- /dev/null +++ b/tests/validation/cpu/ci.json @@ -0,0 +1,5 @@ +{ + "platforms": { + "qemu": false + } +} diff --git a/tests/validation/cpu/cpu.ino b/tests/validation/cpu/cpu.ino new file mode 100644 index 00000000000..203a3e8f2ef --- /dev/null +++ b/tests/validation/cpu/cpu.ino @@ -0,0 +1,35 @@ +/* CPU test + * + * Tests miscellaneous CPU functions like changing the CPU frequency, checking the CPU frequency, + * reading the CPU temperature, etc. + */ + +#include +#include + +/* Utility global variables */ + +/* Test functions */ + +#if SOC_TEMP_SENSOR_SUPPORTED +void get_cpu_temperature() { + float temp = temperatureRead(); + log_d("CPU temperature: %f", temp); + TEST_ASSERT_FLOAT_IS_NOT_NAN(temp); + TEST_ASSERT_FLOAT_WITHIN(40.0, 30.0, temp); +} +#endif + +/* Main functions */ + +void setup() { + UNITY_BEGIN(); + + #if SOC_TEMP_SENSOR_SUPPORTED + RUN_TEST(get_cpu_temperature); + #endif + + UNITY_END(); +} + +void loop() {} diff --git a/tests/validation/cpu/test_cpu.py b/tests/validation/cpu/test_cpu.py new file mode 100644 index 00000000000..bf9c0078999 --- /dev/null +++ b/tests/validation/cpu/test_cpu.py @@ -0,0 +1,2 @@ +def test_cpu(dut): + dut.expect_unity_test_output(timeout=120) diff --git a/tests/validation/deep_sleep/ci.json b/tests/validation/deep_sleep/ci.json new file mode 100644 index 00000000000..54da33b6176 --- /dev/null +++ b/tests/validation/deep_sleep/ci.json @@ -0,0 +1,5 @@ +{ + "platforms": { + "qemu": false + } +} diff --git a/tests/validation/deep_sleep/deep_sleep.ino b/tests/validation/deep_sleep/deep_sleep.ino new file mode 100644 index 00000000000..cb1edd0b317 --- /dev/null +++ b/tests/validation/deep_sleep/deep_sleep.ino @@ -0,0 +1,113 @@ +/* + * This sketch tests the deep sleep functionality of the ESP32 + */ + +#include + +// Timer +#define uS_TO_S_FACTOR 1000000ULL /* Conversion factor for micro seconds to seconds */ +#define TIME_TO_SLEEP 5 /* Time ESP32 will go to sleep (in seconds) */ + +// Touchpad +#if CONFIG_IDF_TARGET_ESP32 +#define THRESHOLD 1000 /* Greater the value, more the sensitivity */ +#else +#define THRESHOLD 0 /* Lower the value, more the sensitivity */ +#endif + +// External wakeup +#define BUTTON_PIN_BITMASK(GPIO) (1ULL << GPIO) // 2 ^ GPIO_NUMBER in hex +#define WAKEUP_GPIO GPIO_NUM_33 // Only RTC IO are allowed - ESP32 Pin example + +RTC_DATA_ATTR int bootCount = 0; + +void print_wakeup_reason() { + esp_sleep_wakeup_cause_t wakeup_reason; + + wakeup_reason = esp_sleep_get_wakeup_cause(); + + Serial.print("Wakeup reason: "); + + switch (wakeup_reason) { + case ESP_SLEEP_WAKEUP_EXT0: Serial.println("rtc_io"); break; + case ESP_SLEEP_WAKEUP_EXT1: Serial.println("rtc_cntl"); break; + case ESP_SLEEP_WAKEUP_TIMER: Serial.println("timer"); break; + case ESP_SLEEP_WAKEUP_TOUCHPAD: Serial.println("touchpad"); break; + case ESP_SLEEP_WAKEUP_ULP: Serial.println("ulp"); break; + default: Serial.println("power_up"); break; + } +} + +void setup_timer() { + esp_sleep_enable_timer_wakeup(TIME_TO_SLEEP * uS_TO_S_FACTOR); +} + +void setup_touchpad() { + #if CONFIG_IDF_TARGET_ESP32 || CONFIG_IDF_TARGET_ESP32S2 || CONFIG_IDF_TARGET_ESP32S3 + touchSleepWakeUpEnable(T1, THRESHOLD); + #else + esp_sleep_enable_timer_wakeup(10); + #endif +} + +void setup_rtc_io() { + #if CONFIG_IDF_TARGET_ESP32 || CONFIG_IDF_TARGET_ESP32S2 || CONFIG_IDF_TARGET_ESP32S3 + esp_sleep_enable_ext0_wakeup(WAKEUP_GPIO, 1); + rtc_gpio_pullup_en(WAKEUP_GPIO); + rtc_gpio_pulldown_dis(WAKEUP_GPIO); + #else + esp_sleep_enable_timer_wakeup(10); + #endif +} + +void setup_rtc_cntl() { + #if CONFIG_IDF_TARGET_ESP32 || CONFIG_IDF_TARGET_ESP32S2 || CONFIG_IDF_TARGET_ESP32S3 + esp_sleep_enable_ext1_wakeup_io(BUTTON_PIN_BITMASK(WAKEUP_GPIO), ESP_EXT1_WAKEUP_ANY_HIGH); + rtc_gpio_pulldown_dis(WAKEUP_GPIO); + rtc_gpio_pullup_en(WAKEUP_GPIO); + #else + esp_sleep_enable_timer_wakeup(10); + #endif +} + + + +void setup() { + Serial.begin(115200); + while (!Serial) { + delay(10); + } + + //Increment boot number and print it every reboot + ++bootCount; + Serial.println("Boot number: " + String(bootCount)); + + //Print the wakeup reason for ESP32 + print_wakeup_reason(); + Serial.flush(); + + if (bootCount == 1) { + // Timer + setup_timer(); + } else if (bootCount == 2) { + // Touchpad + setup_touchpad(); + } else if (bootCount == 3) { + // rtc_io + setup_rtc_io(); + } else if (bootCount == 4) { + // rtc_cntl + setup_rtc_cntl(); + } + else { + return; + } + + esp_deep_sleep_start(); + Serial.println("This will never be printed"); + +} + +void loop() { + //This is not going to be called +} diff --git a/tests/validation/deep_sleep/test_deep_sleep.py b/tests/validation/deep_sleep/test_deep_sleep.py new file mode 100644 index 00000000000..c942bd32e21 --- /dev/null +++ b/tests/validation/deep_sleep/test_deep_sleep.py @@ -0,0 +1,2 @@ +def test_deep_sleep(dut): + dut.expect_exact("Entering deep sleep")