diff --git a/tests/validation/cpu_misc/ci.json b/tests/validation/cpu_misc/ci.json new file mode 100644 index 00000000000..54da33b6176 --- /dev/null +++ b/tests/validation/cpu_misc/ci.json @@ -0,0 +1,5 @@ +{ + "platforms": { + "qemu": false + } +} diff --git a/tests/validation/cpu_misc/cpu_misc.ino b/tests/validation/cpu_misc/cpu_misc.ino new file mode 100644 index 00000000000..e0c1864e622 --- /dev/null +++ b/tests/validation/cpu_misc/cpu_misc.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 */ + +void get_cpu_temperature() { +#if SOC_TEMP_SENSOR_SUPPORTED + 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); +#else + log_d("CPU temperature not supported"); +#endif +} + +/* Main functions */ + +void setup() { + UNITY_BEGIN(); + + RUN_TEST(get_cpu_temperature); + + UNITY_END(); +} + +void loop() {} diff --git a/tests/validation/cpu_misc/test_cpu_misc.py b/tests/validation/cpu_misc/test_cpu_misc.py new file mode 100644 index 00000000000..2e260ca9b49 --- /dev/null +++ b/tests/validation/cpu_misc/test_cpu_misc.py @@ -0,0 +1,2 @@ +def test_cpu_misc(dut): + dut.expect_unity_test_output(timeout=120) diff --git a/tests/validation/sleep/ci.json b/tests/validation/sleep/ci.json new file mode 100644 index 00000000000..accee2b2135 --- /dev/null +++ b/tests/validation/sleep/ci.json @@ -0,0 +1,6 @@ +{ + "platforms": { + "qemu": false, + "wokwi": false + } +} diff --git a/tests/validation/sleep/sleep.ino b/tests/validation/sleep/sleep.ino new file mode 100644 index 00000000000..95df48c878f --- /dev/null +++ b/tests/validation/sleep/sleep.ino @@ -0,0 +1,120 @@ +/* + * This sketch tests the deep sleep functionality of the ESP32 + */ + +#include +#include "driver/rtc_io.h" +#include "driver/uart.h" + +// Timer +#define uS_TO_S_FACTOR 1000000ULL /* Conversion factor for micro seconds to seconds */ +#define TIME_TO_SLEEP 1 /* 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 + +#define TARGET_FREQ CONFIG_XTAL_FREQ + +RTC_DATA_ATTR int boot_count = 0; +uint32_t orig_freq = 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; + case ESP_SLEEP_WAKEUP_GPIO: Serial.println("gpio"); break; + case ESP_SLEEP_WAKEUP_UART: Serial.println("uart"); 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 SOC_TOUCH_SENSOR_SUPPORTED + touchSleepWakeUpEnable(T1, THRESHOLD); +#endif +} + +void setup_uart() { + uart_set_wakeup_threshold(UART_NUM_0, 9); // wake up with "aaa" string (9 positive edges) + esp_sleep_enable_uart_wakeup(UART_NUM_0); +} + +void setup() { + Serial.begin(115200); + while (!Serial) { + delay(10); + } + + orig_freq = getCpuFrequencyMhz(); + + //Increment boot number and print it every reboot + boot_count++; + Serial.println("Boot number: " + String(boot_count)); + + //Print the wakeup reason for ESP32 + print_wakeup_reason(); + Serial.flush(); +} + +void loop() { + // Disable all configured wakeup sources + esp_sleep_disable_wakeup_source(ESP_SLEEP_WAKEUP_ALL); + + if(Serial.available() > 0) { + String command = Serial.readString(); + command.trim(); + + if (command == "timer_deep") { + // Test timer wakeup from deep sleep + setup_timer(); + esp_deep_sleep_start(); + Serial.println("FAIL"); + while(1); + } else if (command == "touchpad_deep") { + // Test touchpad wakeup from deep sleep + setup_touchpad(); + esp_deep_sleep_start(); + Serial.println("FAIL"); + while(1); + } else if (command == "timer_light") { + // Test timer wakeup from light sleep + setup_timer(); + } else if (command == "timer_freq_light") { + // Test timer wakeup from light sleep while changing CPU frequency + setCpuFrequencyMhz(TARGET_FREQ); + setup_timer(); + } else if (command == "touchpad_light") { + // Test touchpad wakeup from light sleep + setup_touchpad(); + } else if (command == "uart_light") { + // Test external wakeup from light sleep using UART + setup_uart(); + } else { + Serial.println("FAIL"); + while(1); + } + + esp_light_sleep_start(); + Serial.println("Woke up from light sleep"); + print_wakeup_reason(); + Serial.flush(); + setCpuFrequencyMhz(orig_freq); + } +} diff --git a/tests/validation/sleep/test_sleep.py b/tests/validation/sleep/test_sleep.py new file mode 100644 index 00000000000..b583c079821 --- /dev/null +++ b/tests/validation/sleep/test_sleep.py @@ -0,0 +1,41 @@ +import logging +import time + +capabilities = { + "timer": ["esp32", "esp32s2", "esp32s3", "esp32c3", "esp32c6", "esp32h2"], + "touchpad": ["esp32", "esp32s2", "esp32s3"], + "uart": ["esp32", "esp32s2", "esp32s3", "esp32c3", "esp32c6", "esp32h2"] +} + +def test_sleep(dut): + LOGGER = logging.getLogger(__name__) + + # Deep Sleep + boot_count = 1 + dut.expect_exact("Boot number: {}".format(boot_count)) + dut.expect_exact("Wakeup reason: power_up") + + for capability, devices in capabilities.items(): + if dut.app.target in devices and capability != "uart": + LOGGER.info("Testing {} deep sleep capability".format(capability)) + boot_count += 1 + dut.write("{}_deep".format(capability)) + dut.expect_exact("Boot number: {}".format(boot_count)) + dut.expect_exact("Wakeup reason: {}".format(capability)) + + # Light Sleep + for capability, devices in capabilities.items(): + if dut.app.target in devices: + LOGGER.info("Testing {} light sleep capability".format(capability)) + dut.write("{}_light".format(capability)) + if capability == "uart": + time.sleep(5) + LOGGER.info("Sending 9 positive edges") + dut.write("aaa") # Send 9 positive edges + dut.expect_exact("Woke up from light sleep") + dut.expect_exact("Wakeup reason: {}".format(capability)) + if capability == "timer": + LOGGER.info("Testing timer light sleep capability with low frequency") + dut.write("timer_freq_light") + dut.expect_exact("Woke up from light sleep") + dut.expect_exact("Wakeup reason: timer")