diff --git a/tests/validation/adc/adc.ino b/tests/validation/adc/adc.ino new file mode 100644 index 00000000000..5fa00cc453b --- /dev/null +++ b/tests/validation/adc/adc.ino @@ -0,0 +1,65 @@ +#include +#include + +#define BTN 0 +#define LED 4 + +#if CONFIG_IDF_TARGET_ESP32P4 +#define POT_PIN 53 +#else +#define POT_PIN 2 +#endif + + + +void setUp(void) {} + +void tearDown(void) {} + +void test_adc_potentiometer(void) { + Serial.println("ADC potentiometer test START"); + + // Configure ADC + analogReadResolution(12); // Set ADC resolution to 12 bits (0-4095) + analogSetAttenuation(ADC_11db); // Set attenuation for full 3.3V range + + Serial.println("Reading ADC values from potentiometer on GPIO2"); + + // Take multiple readings to test different potentiometer positions + for (int i = 0; i < 5; i++) { + int adcValue = analogRead(POT_PIN); + float voltage = (adcValue * 3.3) / 4095.0; + + Serial.print("ADC Reading "); + Serial.print(i + 1); + Serial.print(": "); + Serial.print(adcValue); + Serial.print(" ("); + Serial.print(voltage, 2); + Serial.println("V)"); + + // Test that ADC reading is within valid range + TEST_ASSERT_GREATER_OR_EQUAL(0, adcValue); + TEST_ASSERT_LESS_OR_EQUAL(4095, adcValue); + + delay(1000); // Wait 1 second between readings + } + + Serial.println("ADC potentiometer test completed successfully"); +} + + +void setup() { + Serial.begin(115200); + while (!Serial) { + ; + } + + UNITY_BEGIN(); + RUN_TEST(test_adc_potentiometer); + UNITY_END(); + + Serial.println("ADC test END"); +} + +void loop() {} diff --git a/tests/validation/adc/ci.json b/tests/validation/adc/ci.json new file mode 100644 index 00000000000..e27d5488313 --- /dev/null +++ b/tests/validation/adc/ci.json @@ -0,0 +1,7 @@ +{ + "platforms": { + "hardware": false, + "qemu": false, + "wokwi": true + } +} diff --git a/tests/validation/adc/diagram.esp32.json b/tests/validation/adc/diagram.esp32.json new file mode 100644 index 00000000000..5a0759bb5c9 --- /dev/null +++ b/tests/validation/adc/diagram.esp32.json @@ -0,0 +1,24 @@ +{ + "version": 1, + "author": "Jakub Andrýsek", + "editor": "wokwi", + "parts": [ + { "type": "board-esp32-devkit-c-v4", "id": "esp", "top": 0, "left": 0, "attrs": {} }, + { + "type": "wokwi-potentiometer", + "id": "pot1", + "top": 143.8, + "left": 165.3, + "rotate": 90, + "attrs": {} + } + ], + "connections": [ + [ "esp:TX", "$serialMonitor:RX", "", [] ], + [ "esp:RX", "$serialMonitor:TX", "", [] ], + [ "pot1:GND", "esp:GND.2", "black", [ "h-48", "v-143.82" ] ], + [ "pot1:VCC", "esp:5V", "red", [ "h0" ] ], + [ "esp:2", "pot1:SIG", "green", [ "h0" ] ] + ], + "dependencies": {} +} diff --git a/tests/validation/adc/diagram.esp32c3.json b/tests/validation/adc/diagram.esp32c3.json new file mode 100644 index 00000000000..e62f0689365 --- /dev/null +++ b/tests/validation/adc/diagram.esp32c3.json @@ -0,0 +1,24 @@ +{ + "version": 1, + "author": "Jakub Andrýsek", + "editor": "wokwi", + "parts": [ + { "type": "board-esp32-c3-devkitm-1", "id": "esp", "top": 0, "left": 0, "attrs": {} }, + { + "type": "wokwi-potentiometer", + "id": "pot1", + "top": 143.8, + "left": 165.3, + "rotate": 90, + "attrs": {} + } + ], + "connections": [ + [ "esp:TX", "$serialMonitor:RX", "", [] ], + [ "esp:RX", "$serialMonitor:TX", "", [] ], + [ "pot1:GND", "esp:GND.2", "black", [ "h-48", "v-143.82" ] ], + [ "pot1:VCC", "esp:3V3", "red", [ "h0" ] ], + [ "esp:2", "pot1:SIG", "green", [ "h0" ] ] + ], + "dependencies": {} +} diff --git a/tests/validation/adc/diagram.esp32c6.json b/tests/validation/adc/diagram.esp32c6.json new file mode 100644 index 00000000000..5dd00952372 --- /dev/null +++ b/tests/validation/adc/diagram.esp32c6.json @@ -0,0 +1,24 @@ +{ + "version": 1, + "author": "Jakub Andrýsek", + "editor": "wokwi", + "parts": [ + { "type": "board-esp32-c6-devkitc-1", "id": "esp", "top": 0, "left": 0, "attrs": {} }, + { + "type": "wokwi-potentiometer", + "id": "pot1", + "top": 143.8, + "left": 165.3, + "rotate": 90, + "attrs": {} + } + ], + "connections": [ + [ "esp:TX", "$serialMonitor:RX", "", [] ], + [ "esp:RX", "$serialMonitor:TX", "", [] ], + [ "pot1:GND", "esp:GND.2", "black", [ "h-48", "v-143.82" ] ], + [ "pot1:VCC", "esp:3V3", "red", [ "h0" ] ], + [ "esp:2", "pot1:SIG", "green", [ "h0" ] ] + ], + "dependencies": {} +} diff --git a/tests/validation/adc/diagram.esp32h2.json b/tests/validation/adc/diagram.esp32h2.json new file mode 100644 index 00000000000..b732b1be09c --- /dev/null +++ b/tests/validation/adc/diagram.esp32h2.json @@ -0,0 +1,24 @@ +{ + "version": 1, + "author": "Jakub Andrýsek", + "editor": "wokwi", + "parts": [ + { "type": "board-esp32-h2-devkitm-1", "id": "esp", "top": 0, "left": 0, "attrs": {} }, + { + "type": "wokwi-potentiometer", + "id": "pot1", + "top": 143.8, + "left": 165.3, + "rotate": 90, + "attrs": {} + } + ], + "connections": [ + [ "esp:TX", "$serialMonitor:RX", "", [] ], + [ "esp:RX", "$serialMonitor:TX", "", [] ], + [ "pot1:GND", "esp:GND.2", "black", [ "h-48", "v-143.82" ] ], + [ "pot1:VCC", "esp:3V3", "red", [ "h0" ] ], + [ "esp:2", "pot1:SIG", "green", [ "h0" ] ] + ], + "dependencies": {} +} diff --git a/tests/validation/adc/diagram.esp32p4.json b/tests/validation/adc/diagram.esp32p4.json new file mode 100644 index 00000000000..472384886b9 --- /dev/null +++ b/tests/validation/adc/diagram.esp32p4.json @@ -0,0 +1,18 @@ +{ + "version": 1, + "author": "Jakub Andrýsek", + "editor": "wokwi", + "parts": [ + { "type": "board-esp32-p4-function-ev", "id": "esp", "top": 0, "left": 0, "attrs": {} }, + { "type": "wokwi-potentiometer", "id": "pot1", "top": -115.4, "left": 261.3, "attrs": {} } + ], + "connections": [ + [ "esp:37", "$serialMonitor:RX", "", [] ], + [ "esp:38", "$serialMonitor:TX", "", [] ], + [ "pot1:GND", "esp:GND.2", "black", [ "h-48", "v-143.82" ] ], + [ "pot1:VCC", "esp:3V3", "red", [ "h0" ] ], + [ "esp:53", "pot1:SIG", "green", [ "h0" ] ], + [ "esp:5V.2", "pot1:VCC", "red", [ "v-27.92", "h119.07" ] ] + ], + "dependencies": {} +} \ No newline at end of file diff --git a/tests/validation/adc/diagram.esp32s2.json b/tests/validation/adc/diagram.esp32s2.json new file mode 100644 index 00000000000..012282683d6 --- /dev/null +++ b/tests/validation/adc/diagram.esp32s2.json @@ -0,0 +1,24 @@ +{ + "version": 1, + "author": "Jakub Andrýsek", + "editor": "wokwi", + "parts": [ + { "type": "board-esp32-s2-devkitm-1", "id": "esp", "top": 0, "left": 0, "attrs": {} }, + { + "type": "wokwi-potentiometer", + "id": "pot1", + "top": 143.8, + "left": 165.3, + "rotate": 90, + "attrs": {} + } + ], + "connections": [ + [ "esp:TX", "$serialMonitor:RX", "", [] ], + [ "esp:RX", "$serialMonitor:TX", "", [] ], + [ "pot1:GND", "esp:GND.2", "black", [ "h-48", "v-143.82" ] ], + [ "pot1:VCC", "esp:3V3", "red", [ "h0" ] ], + [ "esp:2", "pot1:SIG", "green", [ "h0" ] ] + ], + "dependencies": {} +} diff --git a/tests/validation/adc/diagram.esp32s3.json b/tests/validation/adc/diagram.esp32s3.json new file mode 100644 index 00000000000..acca72952cf --- /dev/null +++ b/tests/validation/adc/diagram.esp32s3.json @@ -0,0 +1,24 @@ +{ + "version": 1, + "author": "Jakub Andrýsek", + "editor": "wokwi", + "parts": [ + { "type": "board-esp32-s3-devkitc-1", "id": "esp", "top": 0, "left": 0, "attrs": {} }, + { + "type": "wokwi-potentiometer", + "id": "pot1", + "top": 143.8, + "left": 165.3, + "rotate": 90, + "attrs": {} + } + ], + "connections": [ + [ "esp:TX", "$serialMonitor:RX", "", [] ], + [ "esp:RX", "$serialMonitor:TX", "", [] ], + [ "pot1:GND", "esp:GND.2", "black", [ "h-48", "v-143.82" ] ], + [ "pot1:VCC", "esp:5V", "red", [ "h0" ] ], + [ "esp:2", "pot1:SIG", "green", [ "h0" ] ] + ], + "dependencies": {} +} \ No newline at end of file diff --git a/tests/validation/adc/scenario.yaml b/tests/validation/adc/scenario.yaml new file mode 100644 index 00000000000..50180b596ae --- /dev/null +++ b/tests/validation/adc/scenario.yaml @@ -0,0 +1,43 @@ +name: ADC potentiometer test +version: 1 +author: Jakub Andrysek (jakub.andrysek@espressif.com) + +steps: + #### ADC potentiometer test + - wait-serial: "ADC potentiometer test START" + - wait-serial: "Reading ADC values from potentiometer on GPIO2" + + # Set potentiometer to different positions and wait for readings + - set-control: + part-id: pot1 + control: position + value: 0.0 + - wait-serial: "ADC Reading 1:" + + - set-control: + part-id: pot1 + control: position + value: 0.25 + - wait-serial: "ADC Reading 2:" + + - set-control: + part-id: pot1 + control: position + value: 0.5 + - wait-serial: "ADC Reading 3:" + + - set-control: + part-id: pot1 + control: position + value: 0.75 + - wait-serial: "ADC Reading 4:" + + - set-control: + part-id: pot1 + control: position + value: 1.0 + - wait-serial: "ADC Reading 5:" + + - wait-serial: "ADC potentiometer test completed successfully" + + - wait-serial: "ADC test END" diff --git a/tests/validation/adc/test_adc.py b/tests/validation/adc/test_adc.py new file mode 100644 index 00000000000..048adff132e --- /dev/null +++ b/tests/validation/adc/test_adc.py @@ -0,0 +1,5 @@ +import logging + + +def test_gpio_interrupt(dut): + dut.expect_exact("ADC test END") diff --git a/tests/validation/gpio/diagram.esp32.json b/tests/validation/gpio/diagram.esp32.json index 05b28156e37..b240b056626 100644 --- a/tests/validation/gpio/diagram.esp32.json +++ b/tests/validation/gpio/diagram.esp32.json @@ -13,16 +13,26 @@ { "type": "wokwi-pushbutton", "id": "btn1", - "top": -13, - "left": -19.2, + "top": 83, + "left": 9.6, "attrs": { "color": "green" } + }, + { + "type": "wokwi-led", + "id": "led1", + "top": -39.6, + "left": -41.4, + "rotate": 90, + "attrs": { "color": "red" } } ], "connections": [ [ "esp32:RX", "$serialMonitor:TX", "", [] ], [ "esp32:TX", "$serialMonitor:RX", "", [] ], [ "btn1:1.l", "esp32:0", "blue", [ "h-19.2", "v48", "h-38.4" ] ], - [ "btn1:2.r", "esp32:GND.1", "black", [ "h19.4", "v173", "h-269.2", "v-98.23" ] ] + [ "btn1:2.r", "esp32:GND.1", "black", [ "h19.4", "v173", "h-269.2", "v-98.23" ] ], + [ "esp32:GND.2", "led1:C", "black", [ "v0" ] ], + [ "esp32:4", "led1:A", "green", [ "h0" ] ] ], "dependencies": {} -} +} \ No newline at end of file diff --git a/tests/validation/gpio/diagram.esp32c3.json b/tests/validation/gpio/diagram.esp32c3.json index c237e089ea2..18fdb200f78 100644 --- a/tests/validation/gpio/diagram.esp32c3.json +++ b/tests/validation/gpio/diagram.esp32c3.json @@ -16,13 +16,23 @@ "top": -22.6, "left": -19.2, "attrs": { "color": "green" } + }, + { + "type": "wokwi-led", + "id": "led1", + "top": 28, + "left": -286.6, + "rotate": 270, + "attrs": { "color": "red" } } ], "connections": [ [ "esp32:RX", "$serialMonitor:TX", "", [] ], [ "esp32:TX", "$serialMonitor:RX", "", [] ], [ "btn1:1.l", "esp32:0", "blue", [ "h-28.8", "v144", "h-144", "v-95.7" ] ], - [ "btn1:2.r", "esp32:GND.1", "black", [ "h19.4", "v173", "h-269.2", "v-98.23" ] ] + [ "btn1:2.r", "esp32:GND.1", "black", [ "h19.4", "v173", "h-269.2", "v-98.23" ] ], + [ "esp32:GND.4", "led1:C", "black", [ "h0" ] ], + [ "esp32:4", "led1:A", "green", [ "v0" ] ] ], "dependencies": {} -} +} \ No newline at end of file diff --git a/tests/validation/gpio/diagram.esp32c6.json b/tests/validation/gpio/diagram.esp32c6.json index 5020171f4e6..3a522c15b7d 100644 --- a/tests/validation/gpio/diagram.esp32c6.json +++ b/tests/validation/gpio/diagram.esp32c6.json @@ -16,13 +16,23 @@ "top": -22.6, "left": -19.2, "attrs": { "color": "green" } + }, + { + "type": "wokwi-led", + "id": "led1", + "top": 56.8, + "left": -286.6, + "rotate": 270, + "attrs": { "color": "red" } } ], "connections": [ [ "esp32:RX", "$serialMonitor:TX", "", [] ], [ "esp32:TX", "$serialMonitor:RX", "", [] ], [ "btn1:1.l", "esp32:0", "blue", [ "h-19.2", "v-96", "h-163.2", "v93.77" ] ], - [ "btn1:2.r", "esp32:GND.1", "black", [ "h19.4", "v173", "h-269.2", "v-98.23" ] ] + [ "btn1:2.r", "esp32:GND.1", "black", [ "h19.4", "v173", "h-269.2", "v-98.23" ] ], + [ "esp32:GND.1", "led1:C", "black", [ "h0" ] ], + [ "esp32:4", "led1:A", "green", [ "h0" ] ] ], "dependencies": {} -} +} \ No newline at end of file diff --git a/tests/validation/gpio/diagram.esp32h2.json b/tests/validation/gpio/diagram.esp32h2.json index 48189dcea9f..bfa94155afc 100644 --- a/tests/validation/gpio/diagram.esp32h2.json +++ b/tests/validation/gpio/diagram.esp32h2.json @@ -16,13 +16,23 @@ "top": -22.6, "left": -19.2, "attrs": { "color": "green" } + }, + { + "type": "wokwi-led", + "id": "led1", + "top": -0.8, + "left": -267.4, + "rotate": 270, + "attrs": { "color": "red" } } ], "connections": [ [ "esp32:RX", "$serialMonitor:TX", "", [] ], [ "esp32:TX", "$serialMonitor:RX", "", [] ], [ "btn1:1.l", "esp32:0", "blue", [ "h-19.2", "v-96", "h-163.2", "v93.77" ] ], - [ "btn1:2.r", "esp32:GND.1", "black", [ "h19.4", "v173", "h-269.2", "v-98.23" ] ] + [ "btn1:2.r", "esp32:GND.1", "black", [ "h19.4", "v173", "h-269.2", "v-98.23" ] ], + [ "esp32:GND.2", "led1:C", "black", [ "h0" ] ], + [ "esp32:4", "led1:A", "green", [ "h-29.14", "v-26.57" ] ] ], "dependencies": {} -} +} \ No newline at end of file diff --git a/tests/validation/gpio/diagram.esp32p4.json b/tests/validation/gpio/diagram.esp32p4.json index ffb0cde2775..8defa9d3935 100644 --- a/tests/validation/gpio/diagram.esp32p4.json +++ b/tests/validation/gpio/diagram.esp32p4.json @@ -16,13 +16,16 @@ "top": -128.2, "left": -19.2, "attrs": { "color": "green", "bounce": "1" } - } + }, + { "type": "wokwi-led", "id": "led1", "top": -138, "left": -92.2, "attrs": { "color": "red" } } ], "connections": [ [ "esp32:38", "$serialMonitor:TX", "", [] ], [ "esp32:37", "$serialMonitor:RX", "", [] ], [ "btn1:2.r", "esp32:GND.3", "black", [ "h19.4", "v29" ] ], - [ "esp32:0", "btn1:1.l", "blue", [ "h-48", "v-67.2" ] ] + [ "esp32:0", "btn1:1.l", "blue", [ "h-48", "v-67.2" ] ], + [ "esp32:GND.1", "led1:C", "black", [ "v0" ] ], + [ "esp32:4", "led1:A", "green", [ "v-19.2", "h-48" ] ] ], "dependencies": {} -} +} \ No newline at end of file diff --git a/tests/validation/gpio/diagram.esp32s2.json b/tests/validation/gpio/diagram.esp32s2.json index e3f850e193e..b670e6a168d 100644 --- a/tests/validation/gpio/diagram.esp32s2.json +++ b/tests/validation/gpio/diagram.esp32s2.json @@ -16,13 +16,23 @@ "top": -22.6, "left": -19.2, "attrs": { "color": "green" } + }, + { + "type": "wokwi-led", + "id": "led1", + "top": -0.8, + "left": -277, + "rotate": 270, + "attrs": { "color": "red" } } ], "connections": [ [ "esp32:RX", "$serialMonitor:TX", "", [] ], [ "esp32:TX", "$serialMonitor:RX", "", [] ], [ "btn1:1.l", "esp32:0", "blue", [ "h-28.8", "v-57.6", "h-144", "v42.71" ] ], - [ "btn1:2.r", "esp32:GND.1", "black", [ "h19.4", "v173", "h-269.2", "v-98.23" ] ] + [ "btn1:2.r", "esp32:GND.1", "black", [ "h19.4", "v173", "h-269.2", "v-98.23" ] ], + [ "esp32:GND.1", "led1:C", "black", [ "h-67.47", "v-167.51" ] ], + [ "esp32:4", "led1:A", "green", [ "h0" ] ] ], "dependencies": {} -} +} \ No newline at end of file diff --git a/tests/validation/gpio/diagram.esp32s3.json b/tests/validation/gpio/diagram.esp32s3.json index ad9f9e0308a..6d5802cf06c 100644 --- a/tests/validation/gpio/diagram.esp32s3.json +++ b/tests/validation/gpio/diagram.esp32s3.json @@ -13,16 +13,26 @@ { "type": "wokwi-pushbutton", "id": "btn1", - "top": -22.6, - "left": -19.2, + "top": 83, + "left": 9.6, "attrs": { "color": "green" } + }, + { + "type": "wokwi-led", + "id": "led1", + "top": 66.4, + "left": -257.8, + "rotate": 270, + "attrs": { "color": "red", "flip": "" } } ], "connections": [ [ "esp32:RX", "$serialMonitor:TX", "", [] ], [ "esp32:TX", "$serialMonitor:RX", "", [] ], [ "btn1:1.l", "esp32:0", "blue", [ "h-38.4", "v105.78" ] ], - [ "btn1:2.r", "esp32:GND.1", "black", [ "h19.4", "v221", "h-269.2", "v-57.42" ] ] + [ "btn1:2.r", "esp32:GND.3", "green", [ "h19.4", "v48.2", "h-144.4", "v0.18" ] ], + [ "esp32:4", "led1:A", "green", [ "h0" ] ], + [ "esp32:GND.1", "led1:C", "black", [ "h0" ] ] ], "dependencies": {} -} +} \ No newline at end of file diff --git a/tests/validation/gpio/gpio.ino b/tests/validation/gpio/gpio.ino index a5bec1cb5a3..33fdf127187 100644 --- a/tests/validation/gpio/gpio.ino +++ b/tests/validation/gpio/gpio.ino @@ -2,30 +2,58 @@ #include #define BTN 0 +#define LED 4 -void test_button() { - Serial.println("Button test"); - static int count = 0; - static int lastState = HIGH; - while (count < 3) { - int state = digitalRead(BTN); - if (state != lastState) { - if (state == LOW) { - count++; - Serial.print("Button pressed "); - Serial.print(count); - Serial.println(" times"); - } - lastState = state; - } - delay(10); - } +void setUp(void) {} + +void tearDown(void) {} + +void test_read_basic(void) { + Serial.println("GPIO read - basic START"); + + pinMode(BTN, INPUT_PULLUP); + assert(digitalRead(BTN) == 1); + TEST_ASSERT_EQUAL(HIGH, digitalRead(BTN)); + Serial.println("BTN read as HIGH after pinMode INPUT_PULLUP"); + + delay(1000); + TEST_ASSERT_EQUAL(LOW, digitalRead(BTN)); + Serial.println("BTN read as LOW"); + + delay(1000); + TEST_ASSERT_EQUAL(HIGH, digitalRead(BTN)); + Serial.println("BTN read as HIGH"); +} + +void test_write_basic(void) { + Serial.println("GPIO write - basic test"); + pinMode(LED, OUTPUT); + delay(1000); + Serial.println("GPIO LED set to OUTPUT"); + delay(2000); + + digitalWrite(LED, HIGH); + delay(1000); + Serial.println("LED set to HIGH"); + + delay(3000); + digitalWrite(LED, LOW); + Serial.println("LED set to LOW"); } + void setup() { Serial.begin(115200); - pinMode(BTN, INPUT_PULLUP); - test_button(); + while (!Serial) { + ; + } + + UNITY_BEGIN(); + RUN_TEST(test_read_basic); + RUN_TEST(test_write_basic); + UNITY_END(); + + Serial.println("GPIO test END"); } void loop() {} diff --git a/tests/validation/gpio/scenario.yaml b/tests/validation/gpio/scenario.yaml index 957f58b2176..41377b3dece 100644 --- a/tests/validation/gpio/scenario.yaml +++ b/tests/validation/gpio/scenario.yaml @@ -1,40 +1,48 @@ name: Pushbutton counter test version: 1 -author: Jan Prochazka (jan.prochazka@espressif.com) +author: Jan Prochazka (jan.prochazka@espressif.com) + Jakub Andrysek (jakub.andrysek@espressif.com) steps: - - wait-serial: "Button test" + #### GPIO read - basic test + - wait-serial: "GPIO read - basic START" + - wait-serial: "BTN read as HIGH after pinMode INPUT_PULLUP" - # Need for 1s delay for scenario to run properly - - delay: 5000ms - - # Press once + # Set the button to HIGH - set-control: part-id: btn1 control: pressed value: 1 - - delay: 2000ms + + - wait-serial: "BTN read as LOW" + + # Set the button to LOW - set-control: part-id: btn1 control: pressed value: 0 - - delay: 3000ms + - wait-serial: "BTN read as HIGH" - # Press 2nd time - - set-control: - part-id: btn1 - control: pressed - value: 1 - - delay: 2000ms - - set-control: - part-id: btn1 - control: pressed + + + #### GPIO write - basic test + - wait-serial: "GPIO write - basic START" + - wait-serial: "GPIO LED set to OUTPUT" + - expect-pin: + part-id: led1 + pin: A # Anode pin value: 0 - - delay: 3000ms - # Press for the 3rd time - - set-control: - part-id: btn1 - control: pressed + - wait-serial: 'LED set to HIGH' + - expect-pin: + part-id: led1 + pin: A # Anode pin value: 1 - - wait-serial: "Button pressed 3 times" + - wait-serial: 'LED set to LOW' + - expect-pin: + part-id: led1 + pin: A # Anode pin + value: 0 + + + #### GPIO end test + - wait-serial: "GPIO test END" diff --git a/tests/validation/gpio/test_gpio.py b/tests/validation/gpio/test_gpio.py index 8aa3a42dcc6..700cc1875bb 100644 --- a/tests/validation/gpio/test_gpio.py +++ b/tests/validation/gpio/test_gpio.py @@ -2,15 +2,4 @@ def test_gpio(dut): - LOGGER = logging.getLogger(__name__) - - dut.expect_exact("Button test") - - LOGGER.info("Expecting button press 1") - dut.expect_exact("Button pressed 1 times") - - LOGGER.info("Expecting button press 2") - dut.expect_exact("Button pressed 2 times") - - LOGGER.info("Expecting button press 3") - dut.expect_exact("Button pressed 3 times") + dut.expect_exact("GPIO test END") diff --git a/tests/validation/gpio_interrupt/ci.json b/tests/validation/gpio_interrupt/ci.json new file mode 100644 index 00000000000..e27d5488313 --- /dev/null +++ b/tests/validation/gpio_interrupt/ci.json @@ -0,0 +1,7 @@ +{ + "platforms": { + "hardware": false, + "qemu": false, + "wokwi": true + } +} diff --git a/tests/validation/gpio_interrupt/diagram.esp32.json b/tests/validation/gpio_interrupt/diagram.esp32.json new file mode 100644 index 00000000000..256f95cab89 --- /dev/null +++ b/tests/validation/gpio_interrupt/diagram.esp32.json @@ -0,0 +1,38 @@ +{ + "version": 1, + "author": "kubaandrysek", + "editor": "wokwi", + "parts": [ + { + "type": "board-esp32-devkit-c-v4", + "id": "esp32", + "top": -57.6, + "left": -177.56, + "attrs": {} + }, + { + "type": "wokwi-pushbutton", + "id": "btn1", + "top": 83, + "left": 9.6, + "attrs": { "color": "green" } + }, + { + "type": "wokwi-led", + "id": "led1", + "top": -39.6, + "left": -41.4, + "rotate": 90, + "attrs": { "color": "red" } + } + ], + "connections": [ + [ "esp32:RX", "$serialMonitor:TX", "", [] ], + [ "esp32:TX", "$serialMonitor:RX", "", [] ], + [ "btn1:1.l", "esp32:0", "blue", [ "h-19.2", "v48", "h-38.4" ] ], + [ "btn1:2.r", "esp32:GND.1", "black", [ "h19.4", "v173", "h-269.2", "v-98.23" ] ], + [ "esp32:GND.2", "led1:C", "black", [ "v0" ] ], + [ "esp32:4", "led1:A", "green", [ "h0" ] ] + ], + "dependencies": {} +} diff --git a/tests/validation/gpio_interrupt/diagram.esp32c3.json b/tests/validation/gpio_interrupt/diagram.esp32c3.json new file mode 100644 index 00000000000..96b2aa34881 --- /dev/null +++ b/tests/validation/gpio_interrupt/diagram.esp32c3.json @@ -0,0 +1,38 @@ +{ + "version": 1, + "author": "kubaandrysek", + "editor": "wokwi", + "parts": [ + { + "type": "board-esp32-c3-devkitm-1", + "id": "esp32", + "top": -57.6, + "left": -177.56, + "attrs": {} + }, + { + "type": "wokwi-pushbutton", + "id": "btn1", + "top": -22.6, + "left": -19.2, + "attrs": { "color": "green" } + }, + { + "type": "wokwi-led", + "id": "led1", + "top": 28, + "left": -286.6, + "rotate": 270, + "attrs": { "color": "red" } + } + ], + "connections": [ + [ "esp32:RX", "$serialMonitor:TX", "", [] ], + [ "esp32:TX", "$serialMonitor:RX", "", [] ], + [ "btn1:1.l", "esp32:0", "blue", [ "h-28.8", "v144", "h-144", "v-95.7" ] ], + [ "btn1:2.r", "esp32:GND.1", "black", [ "h19.4", "v173", "h-269.2", "v-98.23" ] ], + [ "esp32:GND.4", "led1:C", "black", [ "h0" ] ], + [ "esp32:4", "led1:A", "green", [ "v0" ] ] + ], + "dependencies": {} +} diff --git a/tests/validation/gpio_interrupt/diagram.esp32c6.json b/tests/validation/gpio_interrupt/diagram.esp32c6.json new file mode 100644 index 00000000000..8ce7d9f7144 --- /dev/null +++ b/tests/validation/gpio_interrupt/diagram.esp32c6.json @@ -0,0 +1,38 @@ +{ + "version": 1, + "author": "kubaandrysek", + "editor": "wokwi", + "parts": [ + { + "type": "board-esp32-c6-devkitc-1", + "id": "esp32", + "top": -57.6, + "left": -177.56, + "attrs": {} + }, + { + "type": "wokwi-pushbutton", + "id": "btn1", + "top": -22.6, + "left": -19.2, + "attrs": { "color": "green" } + }, + { + "type": "wokwi-led", + "id": "led1", + "top": 56.8, + "left": -286.6, + "rotate": 270, + "attrs": { "color": "red" } + } + ], + "connections": [ + [ "esp32:RX", "$serialMonitor:TX", "", [] ], + [ "esp32:TX", "$serialMonitor:RX", "", [] ], + [ "btn1:1.l", "esp32:0", "blue", [ "h-19.2", "v-96", "h-163.2", "v93.77" ] ], + [ "btn1:2.r", "esp32:GND.1", "black", [ "h19.4", "v173", "h-269.2", "v-98.23" ] ], + [ "esp32:GND.1", "led1:C", "black", [ "h0" ] ], + [ "esp32:4", "led1:A", "green", [ "h0" ] ] + ], + "dependencies": {} +} diff --git a/tests/validation/gpio_interrupt/diagram.esp32h2.json b/tests/validation/gpio_interrupt/diagram.esp32h2.json new file mode 100644 index 00000000000..9e9d7ed53e1 --- /dev/null +++ b/tests/validation/gpio_interrupt/diagram.esp32h2.json @@ -0,0 +1,38 @@ +{ + "version": 1, + "author": "kubaandrysek", + "editor": "wokwi", + "parts": [ + { + "type": "board-esp32-h2-devkitm-1", + "id": "esp32", + "top": -57.6, + "left": -177.56, + "attrs": {} + }, + { + "type": "wokwi-pushbutton", + "id": "btn1", + "top": -22.6, + "left": -19.2, + "attrs": { "color": "green" } + }, + { + "type": "wokwi-led", + "id": "led1", + "top": -0.8, + "left": -267.4, + "rotate": 270, + "attrs": { "color": "red" } + } + ], + "connections": [ + [ "esp32:RX", "$serialMonitor:TX", "", [] ], + [ "esp32:TX", "$serialMonitor:RX", "", [] ], + [ "btn1:1.l", "esp32:0", "blue", [ "h-19.2", "v-96", "h-163.2", "v93.77" ] ], + [ "btn1:2.r", "esp32:GND.1", "black", [ "h19.4", "v173", "h-269.2", "v-98.23" ] ], + [ "esp32:GND.2", "led1:C", "black", [ "h0" ] ], + [ "esp32:4", "led1:A", "green", [ "h-29.14", "v-26.57" ] ] + ], + "dependencies": {} +} diff --git a/tests/validation/gpio_interrupt/diagram.esp32p4.json b/tests/validation/gpio_interrupt/diagram.esp32p4.json new file mode 100644 index 00000000000..645cb5bac1a --- /dev/null +++ b/tests/validation/gpio_interrupt/diagram.esp32p4.json @@ -0,0 +1,32 @@ +{ + "version": 1, + "author": "kubaandrysek", + "editor": "wokwi", + "parts": [ + { + "type": "board-esp32-p4-function-ev", + "id": "esp32", + "top": -66.32, + "left": -277.63, + "attrs": {} + }, + { "type": "wokwi-led", "id": "led1", "top": -138, "left": -92.2, "attrs": { "color": "red" } }, + { + "type": "wokwi-pushbutton", + "id": "btn1", + "top": -199.2, + "left": 0.2, + "rotate": 180, + "attrs": { "color": "green" } + } + ], + "connections": [ + [ "esp32:38", "$serialMonitor:TX", "", [] ], + [ "esp32:37", "$serialMonitor:RX", "", [] ], + [ "esp32:GND.1", "led1:C", "black", [ "v0" ] ], + [ "esp32:4", "led1:A", "green", [ "v-19.2", "h-48" ] ], + [ "esp32:GND.3", "btn1:2.r", "black", [ "v0" ] ], + [ "esp32:0", "btn1:2.l", "green", [ "v-57.6", "h86.4", "v-76.6" ] ] + ], + "dependencies": {} +} \ No newline at end of file diff --git a/tests/validation/gpio_interrupt/diagram.esp32s2.json b/tests/validation/gpio_interrupt/diagram.esp32s2.json new file mode 100644 index 00000000000..e0228eb8040 --- /dev/null +++ b/tests/validation/gpio_interrupt/diagram.esp32s2.json @@ -0,0 +1,38 @@ +{ + "version": 1, + "author": "kubaandrysek", + "editor": "wokwi", + "parts": [ + { + "type": "board-esp32-s2-devkitm-1", + "id": "esp32", + "top": -57.6, + "left": -177.56, + "attrs": {} + }, + { + "type": "wokwi-pushbutton", + "id": "btn1", + "top": -22.6, + "left": -19.2, + "attrs": { "color": "green" } + }, + { + "type": "wokwi-led", + "id": "led1", + "top": -0.8, + "left": -277, + "rotate": 270, + "attrs": { "color": "red" } + } + ], + "connections": [ + [ "esp32:RX", "$serialMonitor:TX", "", [] ], + [ "esp32:TX", "$serialMonitor:RX", "", [] ], + [ "btn1:1.l", "esp32:0", "blue", [ "h-28.8", "v-57.6", "h-144", "v42.71" ] ], + [ "btn1:2.r", "esp32:GND.1", "black", [ "h19.4", "v173", "h-269.2", "v-98.23" ] ], + [ "esp32:GND.1", "led1:C", "black", [ "h-67.47", "v-167.51" ] ], + [ "esp32:4", "led1:A", "green", [ "h0" ] ] + ], + "dependencies": {} +} diff --git a/tests/validation/gpio_interrupt/diagram.esp32s3.json b/tests/validation/gpio_interrupt/diagram.esp32s3.json new file mode 100644 index 00000000000..1dc53dea172 --- /dev/null +++ b/tests/validation/gpio_interrupt/diagram.esp32s3.json @@ -0,0 +1,38 @@ +{ + "version": 1, + "author": "kubaandrysek", + "editor": "wokwi", + "parts": [ + { + "type": "board-esp32-s3-devkitc-1", + "id": "esp32", + "top": -57.6, + "left": -177.56, + "attrs": {} + }, + { + "type": "wokwi-pushbutton", + "id": "btn1", + "top": 83, + "left": 9.6, + "attrs": { "color": "green" } + }, + { + "type": "wokwi-led", + "id": "led1", + "top": 66.4, + "left": -257.8, + "rotate": 270, + "attrs": { "color": "red", "flip": "" } + } + ], + "connections": [ + [ "esp32:RX", "$serialMonitor:TX", "", [] ], + [ "esp32:TX", "$serialMonitor:RX", "", [] ], + [ "btn1:1.l", "esp32:0", "blue", [ "h-38.4", "v105.78" ] ], + [ "btn1:2.r", "esp32:GND.3", "green", [ "h19.4", "v48.2", "h-144.4", "v0.18" ] ], + [ "esp32:4", "led1:A", "green", [ "h0" ] ], + [ "esp32:GND.1", "led1:C", "black", [ "h0" ] ] + ], + "dependencies": {} +} diff --git a/tests/validation/gpio_interrupt/gpio_interrupt.ino b/tests/validation/gpio_interrupt/gpio_interrupt.ino new file mode 100644 index 00000000000..3c8bc816ec2 --- /dev/null +++ b/tests/validation/gpio_interrupt/gpio_interrupt.ino @@ -0,0 +1,272 @@ +#include +#include + +#define BTN 0 +#define LED 4 + +volatile int interruptCounter = 0; +volatile bool interruptFlag = false; +volatile unsigned long lastInterruptTime = 0; + +// Variables for interrupt with argument test +volatile int argInterruptCounter = 0; +volatile bool argInterruptFlag = false; +volatile int receivedArg = 0; + +void setUp(void) { + interruptCounter = 0; + interruptFlag = false; + lastInterruptTime = 0; + argInterruptCounter = 0; + argInterruptFlag = false; + receivedArg = 0; +} + +void tearDown(void) { + detachInterrupt(digitalPinToInterrupt(BTN)); +} + +void IRAM_ATTR buttonISR() { + unsigned long currentTime = millis(); + // Simple debouncing - ignore interrupts within 50ms + if (currentTime - lastInterruptTime > 50) { + interruptCounter = interruptCounter + 1; + interruptFlag = true; + lastInterruptTime = currentTime; + } +} + +void IRAM_ATTR buttonISRWithArg(void *arg) { + unsigned long currentTime = millis(); + // Simple debouncing - ignore interrupts within 50ms + if (currentTime - lastInterruptTime > 50) { + argInterruptCounter = argInterruptCounter + 1; + argInterruptFlag = true; + receivedArg = *(int*)arg; + lastInterruptTime = currentTime; + } +} + +void test_interrupt_attach_detach(void) { + Serial.println("GPIO interrupt - attach/detach test START"); + + pinMode(BTN, INPUT_PULLUP); + pinMode(LED, OUTPUT); + digitalWrite(LED, LOW); + + // Reset counters + interruptCounter = 0; + interruptFlag = false; + + // Attach interrupt on falling edge (button press) + attachInterrupt(digitalPinToInterrupt(BTN), buttonISR, FALLING); + Serial.println("Interrupt attached - FALLING edge"); + + // Wait for first button press + delay(1000); + Serial.println("Press button to trigger interrupt"); + + // Wait for interrupt to be triggered + unsigned long startTime = millis(); + while (!interruptFlag && (millis() - startTime < 5000)) { + delay(10); + } + + TEST_ASSERT_TRUE(interruptFlag); + TEST_ASSERT_EQUAL(1, interruptCounter); + Serial.println("First interrupt triggered successfully"); + + // Reset flag for next test + interruptFlag = false; + + // Wait for second button press + delay(1000); + Serial.println("Press button again to trigger second interrupt"); + + startTime = millis(); + while (!interruptFlag && (millis() - startTime < 5000)) { + delay(10); + } + + TEST_ASSERT_TRUE(interruptFlag); + TEST_ASSERT_EQUAL(2, interruptCounter); + Serial.println("Second interrupt triggered successfully"); + + // Now detach interrupt + detachInterrupt(digitalPinToInterrupt(BTN)); + Serial.println("Interrupt detached"); + + // Reset counters and test that interrupt no longer works + interruptCounter = 0; + interruptFlag = false; + + delay(1000); + Serial.println("Press button - should NOT trigger interrupt"); + + // Wait and verify no interrupt occurs + delay(3000); + TEST_ASSERT_FALSE(interruptFlag); + TEST_ASSERT_EQUAL(0, interruptCounter); + Serial.println("No interrupt triggered after detach - SUCCESS"); +} + +void test_interrupt_rising_falling(void) { + Serial.println("GPIO interrupt - rising/falling edge test START"); + + pinMode(BTN, INPUT_PULLUP); + + // Test FALLING edge + interruptCounter = 0; + interruptFlag = false; + + attachInterrupt(digitalPinToInterrupt(BTN), buttonISR, FALLING); + Serial.println("Testing FALLING edge interrupt"); + + delay(1000); + Serial.println("Press button for FALLING edge test"); + + unsigned long startTime = millis(); + while (!interruptFlag && (millis() - startTime < 5000)) { + delay(10); + } + + TEST_ASSERT_TRUE(interruptFlag); + Serial.println("FALLING edge interrupt worked"); + + detachInterrupt(digitalPinToInterrupt(BTN)); + + // Test RISING edge + interruptCounter = 0; + interruptFlag = false; + + attachInterrupt(digitalPinToInterrupt(BTN), buttonISR, RISING); + Serial.println("Testing RISING edge interrupt"); + + delay(1000); + Serial.println("Release button for RISING edge test"); + + startTime = millis(); + while (!interruptFlag && (millis() - startTime < 5000)) { + delay(10); + } + + TEST_ASSERT_TRUE(interruptFlag); + Serial.println("RISING edge interrupt worked"); + + detachInterrupt(digitalPinToInterrupt(BTN)); +} + +void test_interrupt_change(void) { + Serial.println("GPIO interrupt - CHANGE edge test START"); + + pinMode(BTN, INPUT_PULLUP); + + interruptCounter = 0; + interruptFlag = false; + + attachInterrupt(digitalPinToInterrupt(BTN), buttonISR, CHANGE); + Serial.println("Testing CHANGE edge interrupt"); + + delay(1000); + Serial.println("Press and release button for CHANGE test"); + + // Wait for button press (falling edge) + unsigned long startTime = millis(); + while (interruptCounter < 1 && (millis() - startTime < 5000)) { + delay(10); + } + + TEST_ASSERT_GREATER_OR_EQUAL(1, interruptCounter); + Serial.println("Button press detected"); + + // Wait for button release (rising edge) + startTime = millis(); + while (interruptCounter < 2 && (millis() - startTime < 5000)) { + delay(10); + } + + TEST_ASSERT_GREATER_OR_EQUAL(2, interruptCounter); + Serial.println("Button release detected - CHANGE interrupt worked"); + + detachInterrupt(digitalPinToInterrupt(BTN)); +} + +void test_interrupt_with_arg(void) { + Serial.println("GPIO interrupt - attachInterruptArg test START"); + + pinMode(BTN, INPUT_PULLUP); + + // Test data to pass to interrupt + int testArg = 42; + + // Reset counters + argInterruptCounter = 0; + argInterruptFlag = false; + receivedArg = 0; + + // Attach interrupt with argument on falling edge (button press) + attachInterruptArg(digitalPinToInterrupt(BTN), buttonISRWithArg, &testArg, FALLING); + Serial.println("Interrupt with argument attached - FALLING edge"); + + delay(1000); + Serial.println("Press button to trigger interrupt with argument"); + + // Wait for interrupt to be triggered + unsigned long startTime = millis(); + while (!argInterruptFlag && (millis() - startTime < 5000)) { + delay(10); + } + + TEST_ASSERT_TRUE(argInterruptFlag); + TEST_ASSERT_EQUAL(1, argInterruptCounter); + TEST_ASSERT_EQUAL(42, receivedArg); + Serial.println("Interrupt with argument triggered successfully"); + Serial.print("Received argument value: "); + Serial.println(receivedArg); + + // Test with different argument value + argInterruptFlag = false; + int newTestArg = 123; + + // Detach and reattach with new argument + detachInterrupt(digitalPinToInterrupt(BTN)); + attachInterruptArg(digitalPinToInterrupt(BTN), buttonISRWithArg, &newTestArg, FALLING); + Serial.println("Interrupt reattached with new argument value"); + + delay(1000); + Serial.println("Press button again to test new argument"); + + startTime = millis(); + while (!argInterruptFlag && (millis() - startTime < 5000)) { + delay(10); + } + + TEST_ASSERT_TRUE(argInterruptFlag); + TEST_ASSERT_EQUAL(2, argInterruptCounter); + TEST_ASSERT_EQUAL(123, receivedArg); + Serial.println("Second interrupt with new argument triggered successfully"); + Serial.print("New received argument value: "); + Serial.println(receivedArg); + + detachInterrupt(digitalPinToInterrupt(BTN)); + Serial.println("Interrupt with argument test completed"); +} + + +void setup() { + Serial.begin(115200); + while (!Serial) { + ; + } + + UNITY_BEGIN(); + RUN_TEST(test_interrupt_attach_detach); + RUN_TEST(test_interrupt_rising_falling); + RUN_TEST(test_interrupt_change); + RUN_TEST(test_interrupt_with_arg); + UNITY_END(); + + Serial.println("GPIO interrupt test END"); +} + +void loop() {} diff --git a/tests/validation/gpio_interrupt/scenario.yaml b/tests/validation/gpio_interrupt/scenario.yaml new file mode 100644 index 00000000000..537b7404ee0 --- /dev/null +++ b/tests/validation/gpio_interrupt/scenario.yaml @@ -0,0 +1,141 @@ +name: GPIO interrupt test +version: 1 +author: Jakub Andrysek (jakub.andrysek@espressif.com) + +steps: + #### GPIO interrupt - attach/detach test + - wait-serial: "GPIO interrupt - attach/detach test START" + - wait-serial: "Interrupt attached - FALLING edge" + - wait-serial: "Press button to trigger interrupt" + + # Simulate button press (falling edge) + - set-control: + part-id: btn1 + control: pressed + value: 1 + + - wait-serial: "First interrupt triggered successfully" + - wait-serial: "Press button again to trigger second interrupt" + + # Simulate button release and press again + - set-control: + part-id: btn1 + control: pressed + value: 0 + - delay: 100ms + - set-control: + part-id: btn1 + control: pressed + value: 1 + + - wait-serial: "Second interrupt triggered successfully" + - wait-serial: "Interrupt detached" + - wait-serial: "Press button - should NOT trigger interrupt" + + # Try to trigger interrupt after detach - should not work + - set-control: + part-id: btn1 + control: pressed + value: 0 + - delay: 100ms + - set-control: + part-id: btn1 + control: pressed + value: 1 + + - wait-serial: "No interrupt triggered after detach - SUCCESS" + + #### GPIO interrupt - rising/falling edge test + - wait-serial: "GPIO interrupt - rising/falling edge test START" + - wait-serial: "Testing FALLING edge interrupt" + - wait-serial: "Press button for FALLING edge test" + + # Ensure button starts unpressed, wait a bit, then press it (falling edge) + - set-control: + part-id: btn1 + control: pressed + value: 0 + - delay: 200ms + - set-control: + part-id: btn1 + control: pressed + value: 1 + + - wait-serial: "FALLING edge interrupt worked" + - wait-serial: "Testing RISING edge interrupt" + - wait-serial: "Release button for RISING edge test" + + # Test rising edge (release button) - button should already be pressed from previous test + - delay: 200ms + - set-control: + part-id: btn1 + control: pressed + value: 0 + + - wait-serial: "RISING edge interrupt worked" + + #### GPIO interrupt - CHANGE edge test + - wait-serial: "GPIO interrupt - CHANGE edge test START" + - wait-serial: "Testing CHANGE edge interrupt" + - wait-serial: "Press and release button for CHANGE test" + + # Ensure button starts unpressed, then press it (falling edge - first change) + - set-control: + part-id: btn1 + control: pressed + value: 0 + - delay: 100ms + - set-control: + part-id: btn1 + control: pressed + value: 1 + + - wait-serial: "Button press detected" + + # Release button (rising edge - second change) + - delay: 100ms + - set-control: + part-id: btn1 + control: pressed + value: 0 + + - wait-serial: "Button release detected - CHANGE interrupt worked" + + #### GPIO interrupt - attachInterruptArg test + - wait-serial: "GPIO interrupt - attachInterruptArg test START" + - wait-serial: "Interrupt with argument attached - FALLING edge" + - wait-serial: "Press button to trigger interrupt with argument" + + # Ensure button starts unpressed, then press it to trigger interrupt with argument + - set-control: + part-id: btn1 + control: pressed + value: 0 + - delay: 100ms + - set-control: + part-id: btn1 + control: pressed + value: 1 + + - wait-serial: "Interrupt with argument triggered successfully" + - wait-serial: "Received argument value: 42" + - wait-serial: "Interrupt reattached with new argument value" + - wait-serial: "Press button again to test new argument" + + # Press button again to test new argument value + - set-control: + part-id: btn1 + control: pressed + value: 0 + - delay: 100ms + - set-control: + part-id: btn1 + control: pressed + value: 1 + + - wait-serial: "Second interrupt with new argument triggered successfully" + - wait-serial: "New received argument value: 123" + - wait-serial: "Interrupt with argument test completed" + + #### GPIO interrupt test end + - wait-serial: "GPIO interrupt test END" diff --git a/tests/validation/gpio_interrupt/test_gpio_interrupt.py b/tests/validation/gpio_interrupt/test_gpio_interrupt.py new file mode 100644 index 00000000000..899bb6b9d0c --- /dev/null +++ b/tests/validation/gpio_interrupt/test_gpio_interrupt.py @@ -0,0 +1,6 @@ +import logging + + +def test_gpio_interrupt(dut): + """Test GPIO interrupt functionality including attach, detach, and different edge triggers.""" + dut.expect_exact("GPIO interrupt test END")