Skip to content

Commit 86a634b

Browse files
committed
feat(tests): expand GPIO test scenarios
1 parent 422e526 commit 86a634b

File tree

10 files changed

+160
-72
lines changed

10 files changed

+160
-72
lines changed

tests/validation/gpio/diagram.esp32.json

Lines changed: 14 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -13,16 +13,26 @@
1313
{
1414
"type": "wokwi-pushbutton",
1515
"id": "btn1",
16-
"top": -13,
17-
"left": -19.2,
16+
"top": 83,
17+
"left": 9.6,
1818
"attrs": { "color": "green" }
19+
},
20+
{
21+
"type": "wokwi-led",
22+
"id": "led1",
23+
"top": -39.6,
24+
"left": -41.4,
25+
"rotate": 90,
26+
"attrs": { "color": "red" }
1927
}
2028
],
2129
"connections": [
2230
[ "esp32:RX", "$serialMonitor:TX", "", [] ],
2331
[ "esp32:TX", "$serialMonitor:RX", "", [] ],
2432
[ "btn1:1.l", "esp32:0", "blue", [ "h-19.2", "v48", "h-38.4" ] ],
25-
[ "btn1:2.r", "esp32:GND.1", "black", [ "h19.4", "v173", "h-269.2", "v-98.23" ] ]
33+
[ "btn1:2.r", "esp32:GND.1", "black", [ "h19.4", "v173", "h-269.2", "v-98.23" ] ],
34+
[ "esp32:GND.2", "led1:C", "black", [ "v0" ] ],
35+
[ "esp32:4", "led1:A", "green", [ "h0" ] ]
2636
],
2737
"dependencies": {}
28-
}
38+
}

tests/validation/gpio/diagram.esp32c3.json

Lines changed: 12 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -16,13 +16,23 @@
1616
"top": -22.6,
1717
"left": -19.2,
1818
"attrs": { "color": "green" }
19+
},
20+
{
21+
"type": "wokwi-led",
22+
"id": "led1",
23+
"top": 28,
24+
"left": -286.6,
25+
"rotate": 270,
26+
"attrs": { "color": "red" }
1927
}
2028
],
2129
"connections": [
2230
[ "esp32:RX", "$serialMonitor:TX", "", [] ],
2331
[ "esp32:TX", "$serialMonitor:RX", "", [] ],
2432
[ "btn1:1.l", "esp32:0", "blue", [ "h-28.8", "v144", "h-144", "v-95.7" ] ],
25-
[ "btn1:2.r", "esp32:GND.1", "black", [ "h19.4", "v173", "h-269.2", "v-98.23" ] ]
33+
[ "btn1:2.r", "esp32:GND.1", "black", [ "h19.4", "v173", "h-269.2", "v-98.23" ] ],
34+
[ "esp32:GND.4", "led1:C", "black", [ "h0" ] ],
35+
[ "esp32:4", "led1:A", "green", [ "v0" ] ]
2636
],
2737
"dependencies": {}
28-
}
38+
}

tests/validation/gpio/diagram.esp32c6.json

Lines changed: 12 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -16,13 +16,23 @@
1616
"top": -22.6,
1717
"left": -19.2,
1818
"attrs": { "color": "green" }
19+
},
20+
{
21+
"type": "wokwi-led",
22+
"id": "led1",
23+
"top": 56.8,
24+
"left": -286.6,
25+
"rotate": 270,
26+
"attrs": { "color": "red" }
1927
}
2028
],
2129
"connections": [
2230
[ "esp32:RX", "$serialMonitor:TX", "", [] ],
2331
[ "esp32:TX", "$serialMonitor:RX", "", [] ],
2432
[ "btn1:1.l", "esp32:0", "blue", [ "h-19.2", "v-96", "h-163.2", "v93.77" ] ],
25-
[ "btn1:2.r", "esp32:GND.1", "black", [ "h19.4", "v173", "h-269.2", "v-98.23" ] ]
33+
[ "btn1:2.r", "esp32:GND.1", "black", [ "h19.4", "v173", "h-269.2", "v-98.23" ] ],
34+
[ "esp32:GND.1", "led1:C", "black", [ "h0" ] ],
35+
[ "esp32:4", "led1:A", "green", [ "h0" ] ]
2636
],
2737
"dependencies": {}
28-
}
38+
}

tests/validation/gpio/diagram.esp32h2.json

Lines changed: 12 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -16,13 +16,23 @@
1616
"top": -22.6,
1717
"left": -19.2,
1818
"attrs": { "color": "green" }
19+
},
20+
{
21+
"type": "wokwi-led",
22+
"id": "led1",
23+
"top": -0.8,
24+
"left": -267.4,
25+
"rotate": 270,
26+
"attrs": { "color": "red" }
1927
}
2028
],
2129
"connections": [
2230
[ "esp32:RX", "$serialMonitor:TX", "", [] ],
2331
[ "esp32:TX", "$serialMonitor:RX", "", [] ],
2432
[ "btn1:1.l", "esp32:0", "blue", [ "h-19.2", "v-96", "h-163.2", "v93.77" ] ],
25-
[ "btn1:2.r", "esp32:GND.1", "black", [ "h19.4", "v173", "h-269.2", "v-98.23" ] ]
33+
[ "btn1:2.r", "esp32:GND.1", "black", [ "h19.4", "v173", "h-269.2", "v-98.23" ] ],
34+
[ "esp32:GND.2", "led1:C", "black", [ "h0" ] ],
35+
[ "esp32:4", "led1:A", "green", [ "h-29.14", "v-26.57" ] ]
2636
],
2737
"dependencies": {}
28-
}
38+
}

tests/validation/gpio/diagram.esp32p4.json

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -16,13 +16,16 @@
1616
"top": -128.2,
1717
"left": -19.2,
1818
"attrs": { "color": "green", "bounce": "1" }
19-
}
19+
},
20+
{ "type": "wokwi-led", "id": "led1", "top": -138, "left": -92.2, "attrs": { "color": "red" } }
2021
],
2122
"connections": [
2223
[ "esp32:38", "$serialMonitor:TX", "", [] ],
2324
[ "esp32:37", "$serialMonitor:RX", "", [] ],
2425
[ "btn1:2.r", "esp32:GND.3", "black", [ "h19.4", "v29" ] ],
25-
[ "esp32:0", "btn1:1.l", "blue", [ "h-48", "v-67.2" ] ]
26+
[ "esp32:0", "btn1:1.l", "blue", [ "h-48", "v-67.2" ] ],
27+
[ "esp32:GND.1", "led1:C", "black", [ "v0" ] ],
28+
[ "esp32:4", "led1:A", "green", [ "v-19.2", "h-48" ] ]
2629
],
2730
"dependencies": {}
28-
}
31+
}

tests/validation/gpio/diagram.esp32s2.json

Lines changed: 12 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -16,13 +16,23 @@
1616
"top": -22.6,
1717
"left": -19.2,
1818
"attrs": { "color": "green" }
19+
},
20+
{
21+
"type": "wokwi-led",
22+
"id": "led1",
23+
"top": -0.8,
24+
"left": -277,
25+
"rotate": 270,
26+
"attrs": { "color": "red" }
1927
}
2028
],
2129
"connections": [
2230
[ "esp32:RX", "$serialMonitor:TX", "", [] ],
2331
[ "esp32:TX", "$serialMonitor:RX", "", [] ],
2432
[ "btn1:1.l", "esp32:0", "blue", [ "h-28.8", "v-57.6", "h-144", "v42.71" ] ],
25-
[ "btn1:2.r", "esp32:GND.1", "black", [ "h19.4", "v173", "h-269.2", "v-98.23" ] ]
33+
[ "btn1:2.r", "esp32:GND.1", "black", [ "h19.4", "v173", "h-269.2", "v-98.23" ] ],
34+
[ "esp32:GND.1", "led1:C", "black", [ "h-67.47", "v-167.51" ] ],
35+
[ "esp32:4", "led1:A", "green", [ "h0" ] ]
2636
],
2737
"dependencies": {}
28-
}
38+
}

tests/validation/gpio/diagram.esp32s3.json

Lines changed: 14 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -13,16 +13,26 @@
1313
{
1414
"type": "wokwi-pushbutton",
1515
"id": "btn1",
16-
"top": -22.6,
17-
"left": -19.2,
16+
"top": 83,
17+
"left": 9.6,
1818
"attrs": { "color": "green" }
19+
},
20+
{
21+
"type": "wokwi-led",
22+
"id": "led1",
23+
"top": 66.4,
24+
"left": -257.8,
25+
"rotate": 270,
26+
"attrs": { "color": "red", "flip": "" }
1927
}
2028
],
2129
"connections": [
2230
[ "esp32:RX", "$serialMonitor:TX", "", [] ],
2331
[ "esp32:TX", "$serialMonitor:RX", "", [] ],
2432
[ "btn1:1.l", "esp32:0", "blue", [ "h-38.4", "v105.78" ] ],
25-
[ "btn1:2.r", "esp32:GND.1", "black", [ "h19.4", "v221", "h-269.2", "v-57.42" ] ]
33+
[ "btn1:2.r", "esp32:GND.3", "green", [ "h19.4", "v48.2", "h-144.4", "v0.18" ] ],
34+
[ "esp32:4", "led1:A", "green", [ "h0" ] ],
35+
[ "esp32:GND.1", "led1:C", "black", [ "h0" ] ]
2636
],
2737
"dependencies": {}
28-
}
38+
}

tests/validation/gpio/gpio.ino

Lines changed: 47 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -2,30 +2,58 @@
22
#include <unity.h>
33

44
#define BTN 0
5+
#define LED 4
56

6-
void test_button() {
7-
Serial.println("Button test");
8-
static int count = 0;
9-
static int lastState = HIGH;
10-
while (count < 3) {
11-
int state = digitalRead(BTN);
12-
if (state != lastState) {
13-
if (state == LOW) {
14-
count++;
15-
Serial.print("Button pressed ");
16-
Serial.print(count);
17-
Serial.println(" times");
18-
}
19-
lastState = state;
20-
}
21-
delay(10);
22-
}
7+
void setUp(void) {}
8+
9+
void tearDown(void) {}
10+
11+
void test_read_basic(void) {
12+
Serial.println("GPIO read - basic START");
13+
14+
pinMode(BTN, INPUT_PULLUP);
15+
assert(digitalRead(BTN) == 1);
16+
TEST_ASSERT_EQUAL(HIGH, digitalRead(BTN));
17+
Serial.println("BTN read as HIGH after pinMode INPUT_PULLUP");
18+
19+
delay(1000);
20+
TEST_ASSERT_EQUAL(LOW, digitalRead(BTN));
21+
Serial.println("BTN read as LOW");
22+
23+
delay(1000);
24+
TEST_ASSERT_EQUAL(HIGH, digitalRead(BTN));
25+
Serial.println("BTN read as HIGH");
26+
}
27+
28+
void test_write_basic(void) {
29+
Serial.println("GPIO write - basic test");
30+
pinMode(LED, OUTPUT);
31+
delay(1000);
32+
Serial.println("GPIO LED set to OUTPUT");
33+
delay(2000);
34+
35+
digitalWrite(LED, HIGH);
36+
delay(1000);
37+
Serial.println("LED set to HIGH");
38+
39+
delay(3000);
40+
digitalWrite(LED, LOW);
41+
Serial.println("LED set to LOW");
2342
}
2443

44+
2545
void setup() {
2646
Serial.begin(115200);
27-
pinMode(BTN, INPUT_PULLUP);
28-
test_button();
47+
while (!Serial) {
48+
;
49+
}
50+
51+
UNITY_BEGIN();
52+
RUN_TEST(test_read_basic);
53+
RUN_TEST(test_write_basic);
54+
UNITY_END();
55+
56+
Serial.println("GPIO test END");
2957
}
3058

3159
void loop() {}

tests/validation/gpio/scenario.yaml

Lines changed: 30 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -3,38 +3,46 @@ version: 1
33
author: Jan Prochazka ([email protected])
44

55
steps:
6-
- wait-serial: "Button test"
6+
#### GPIO read - basic test
7+
- wait-serial: "GPIO read - basic START"
8+
- wait-serial: "BTN read as HIGH after pinMode INPUT_PULLUP"
79

8-
# Need for 1s delay for scenario to run properly
9-
- delay: 5000ms
10-
11-
# Press once
10+
# Set the button to HIGH
1211
- set-control:
1312
part-id: btn1
1413
control: pressed
1514
value: 1
16-
- delay: 2000ms
15+
16+
- wait-serial: "BTN read as LOW"
17+
18+
# Set the button to LOW
1719
- set-control:
1820
part-id: btn1
1921
control: pressed
2022
value: 0
21-
- delay: 3000ms
23+
- wait-serial: "BTN read as HIGH"
2224

23-
# Press 2nd time
24-
- set-control:
25-
part-id: btn1
26-
control: pressed
27-
value: 1
28-
- delay: 2000ms
29-
- set-control:
30-
part-id: btn1
31-
control: pressed
25+
26+
27+
#### GPIO write - basic test
28+
- wait-serial: "GPIO write - basic START"
29+
- wait-serial: "GPIO LED set to OUTPUT"
30+
- expect-pin:
31+
part-id: led1
32+
pin: A # Anode pin
3233
value: 0
33-
- delay: 3000ms
3434

35-
# Press for the 3rd time
36-
- set-control:
37-
part-id: btn1
38-
control: pressed
35+
- wait-serial: 'LED set to HIGH'
36+
- expect-pin:
37+
part-id: led1
38+
pin: A # Anode pin
3939
value: 1
40-
- wait-serial: "Button pressed 3 times"
40+
- wait-serial: 'LED set to LOW'
41+
- expect-pin:
42+
part-id: led1
43+
pin: A # Anode pin
44+
value: 0
45+
46+
47+
#### GPIO end test
48+
- wait-serial: "GPIO test END"

tests/validation/gpio/test_gpio.py

Lines changed: 1 addition & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -2,15 +2,4 @@
22

33

44
def test_gpio(dut):
5-
LOGGER = logging.getLogger(__name__)
6-
7-
dut.expect_exact("Button test")
8-
9-
LOGGER.info("Expecting button press 1")
10-
dut.expect_exact("Button pressed 1 times")
11-
12-
LOGGER.info("Expecting button press 2")
13-
dut.expect_exact("Button pressed 2 times")
14-
15-
LOGGER.info("Expecting button press 3")
16-
dut.expect_exact("Button pressed 3 times")
5+
dut.expect_exact("GPIO test END")

0 commit comments

Comments
 (0)