Skip to content

Commit 296a9a4

Browse files
committed
feat(wokwi): Add simple CI test for push button
1 parent 1695e79 commit 296a9a4

10 files changed

+248
-0
lines changed

tests/gpio/.skip.hardware

Whitespace-only changes.

tests/gpio/.skip.qemu

Whitespace-only changes.

tests/gpio/esp32.diagram.json

+28
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
{
2+
"version": 1,
3+
"author": "P-R-O-C-H-Y",
4+
"editor": "wokwi",
5+
"parts": [
6+
{
7+
"type": "board-esp32-devkit-c-v4",
8+
"id": "esp32",
9+
"top": -57.6,
10+
"left": -177.56,
11+
"attrs": {}
12+
},
13+
{
14+
"type": "wokwi-pushbutton",
15+
"id": "btn1",
16+
"top": -13,
17+
"left": -19.2,
18+
"attrs": { "color": "green" }
19+
}
20+
],
21+
"connections": [
22+
[ "esp32:RX", "$serialMonitor:TX", "", [] ],
23+
[ "esp32:TX", "$serialMonitor:RX", "", [] ],
24+
[ "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" ] ]
26+
],
27+
"dependencies": {}
28+
}

tests/gpio/esp32c3.diagram.json

+28
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
{
2+
"version": 1,
3+
"author": "P-R-O-C-H-Y",
4+
"editor": "wokwi",
5+
"parts": [
6+
{
7+
"type": "board-esp32-c3-devkitm-1",
8+
"id": "esp32",
9+
"top": -57.6,
10+
"left": -177.56,
11+
"attrs": {}
12+
},
13+
{
14+
"type": "wokwi-pushbutton",
15+
"id": "btn1",
16+
"top": -22.6,
17+
"left": -19.2,
18+
"attrs": { "color": "green" }
19+
}
20+
],
21+
"connections": [
22+
[ "esp32:RX", "$serialMonitor:TX", "", [] ],
23+
[ "esp32:TX", "$serialMonitor:RX", "", [] ],
24+
[ "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" ] ]
26+
],
27+
"dependencies": {}
28+
}

tests/gpio/esp32c6.diagram.json

+28
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
{
2+
"version": 1,
3+
"author": "P-R-O-C-H-Y",
4+
"editor": "wokwi",
5+
"parts": [
6+
{
7+
"type": "board-esp32-c6-devkitc-1",
8+
"id": "esp32",
9+
"top": -57.6,
10+
"left": -177.56,
11+
"attrs": {}
12+
},
13+
{
14+
"type": "wokwi-pushbutton",
15+
"id": "btn1",
16+
"top": -22.6,
17+
"left": -19.2,
18+
"attrs": { "color": "green" }
19+
}
20+
],
21+
"connections": [
22+
[ "esp32:RX", "$serialMonitor:TX", "", [] ],
23+
[ "esp32:TX", "$serialMonitor:RX", "", [] ],
24+
[ "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" ] ]
26+
],
27+
"dependencies": {}
28+
}

tests/gpio/esp32h2.diagram.json

+28
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
{
2+
"version": 1,
3+
"author": "P-R-O-C-H-Y",
4+
"editor": "wokwi",
5+
"parts": [
6+
{
7+
"type": "board-esp32-h2-devkitm-1",
8+
"id": "esp32",
9+
"top": -57.6,
10+
"left": -177.56,
11+
"attrs": {}
12+
},
13+
{
14+
"type": "wokwi-pushbutton",
15+
"id": "btn1",
16+
"top": -22.6,
17+
"left": -19.2,
18+
"attrs": { "color": "green" }
19+
}
20+
],
21+
"connections": [
22+
[ "esp32:RX", "$serialMonitor:TX", "", [] ],
23+
[ "esp32:TX", "$serialMonitor:RX", "", [] ],
24+
[ "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" ] ]
26+
],
27+
"dependencies": {}
28+
}

tests/gpio/esp32s2.diagram.json

+28
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
{
2+
"version": 1,
3+
"author": "P-R-O-C-H-Y",
4+
"editor": "wokwi",
5+
"parts": [
6+
{
7+
"type": "board-esp32-s2-devkitm-1",
8+
"id": "esp32",
9+
"top": -57.6,
10+
"left": -177.56,
11+
"attrs": {}
12+
},
13+
{
14+
"type": "wokwi-pushbutton",
15+
"id": "btn1",
16+
"top": -22.6,
17+
"left": -19.2,
18+
"attrs": { "color": "green" }
19+
}
20+
],
21+
"connections": [
22+
[ "esp32:RX", "$serialMonitor:TX", "", [] ],
23+
[ "esp32:TX", "$serialMonitor:RX", "", [] ],
24+
[ "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" ] ]
26+
],
27+
"dependencies": {}
28+
}

tests/gpio/esp32s3.diagram.json

+28
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
{
2+
"version": 1,
3+
"author": "P-R-O-C-H-Y",
4+
"editor": "wokwi",
5+
"parts": [
6+
{
7+
"type": "board-esp32-s3-devkitc-1",
8+
"id": "esp32",
9+
"top": -57.6,
10+
"left": -177.56,
11+
"attrs": {}
12+
},
13+
{
14+
"type": "wokwi-pushbutton",
15+
"id": "btn1",
16+
"top": -22.6,
17+
"left": -19.2,
18+
"attrs": { "color": "green" }
19+
}
20+
],
21+
"connections": [
22+
[ "esp32:RX", "$serialMonitor:TX", "", [] ],
23+
[ "esp32:TX", "$serialMonitor:RX", "", [] ],
24+
[ "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" ] ]
26+
],
27+
"dependencies": {}
28+
}

tests/gpio/gpio.ino

+41
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,41 @@
1+
#include <Arduino.h>
2+
#include <unity.h>
3+
4+
#define BTN 0
5+
6+
void test_button()
7+
{
8+
Serial.println("Button test");
9+
static int count = 0;
10+
static int lastState = HIGH;
11+
while(count < 3)
12+
{
13+
int state = digitalRead(BTN);
14+
if (state != lastState)
15+
{
16+
if (state == LOW)
17+
{
18+
count++;
19+
Serial.print("Button pressed ");
20+
Serial.print(count);
21+
Serial.println(" times");
22+
}
23+
lastState = state;
24+
}
25+
delay(10);
26+
}
27+
TEST_ASSERT_EQUAL(3, count);
28+
}
29+
30+
void setup()
31+
{
32+
Serial.begin(115200);
33+
UNITY_BEGIN();
34+
pinMode(BTN, INPUT_PULLUP);
35+
RUN_TEST(test_button);
36+
UNITY_END();
37+
}
38+
39+
void loop()
40+
{
41+
}

tests/gpio/scenario.yaml

+39
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,39 @@
1+
name: Pushbutton counter test
2+
version: 1
3+
author: Jan Prochazka ([email protected])
4+
5+
steps:
6+
- wait-serial: 'Button test'
7+
8+
# Delay 1s (to make sure the test is ready to start)
9+
- delay: 1000ms
10+
# Press once
11+
- set-control:
12+
part-id: btn1
13+
control: pressed
14+
value: 1
15+
- delay: 200ms
16+
- set-control:
17+
part-id: btn1
18+
control: pressed
19+
value: 0
20+
- delay: 300ms
21+
22+
# Press 2nd time
23+
- set-control:
24+
part-id: btn1
25+
control: pressed
26+
value: 1
27+
- delay: 200ms
28+
- set-control:
29+
part-id: btn1
30+
control: pressed
31+
value: 0
32+
- delay: 300ms
33+
34+
# Press for the 3rd time
35+
- set-control:
36+
part-id: btn1
37+
control: pressed
38+
value: 1
39+
- wait-serial: 'Button pressed 3 times'

0 commit comments

Comments
 (0)