Skip to content

Enhance tests TODO #1

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Draft
wants to merge 3 commits into
base: master
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
18 changes: 14 additions & 4 deletions tests/validation/gpio/diagram.esp32.json
Original file line number Diff line number Diff line change
Expand Up @@ -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": {}
}
}
14 changes: 12 additions & 2 deletions tests/validation/gpio/diagram.esp32c3.json
Original file line number Diff line number Diff line change
Expand Up @@ -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": {}
}
}
14 changes: 12 additions & 2 deletions tests/validation/gpio/diagram.esp32c6.json
Original file line number Diff line number Diff line change
Expand Up @@ -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": {}
}
}
14 changes: 12 additions & 2 deletions tests/validation/gpio/diagram.esp32h2.json
Original file line number Diff line number Diff line change
Expand Up @@ -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": {}
}
}
9 changes: 6 additions & 3 deletions tests/validation/gpio/diagram.esp32p4.json
Original file line number Diff line number Diff line change
Expand Up @@ -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": {}
}
}
14 changes: 12 additions & 2 deletions tests/validation/gpio/diagram.esp32s2.json
Original file line number Diff line number Diff line change
Expand Up @@ -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": {}
}
}
18 changes: 14 additions & 4 deletions tests/validation/gpio/diagram.esp32s3.json
Original file line number Diff line number Diff line change
Expand Up @@ -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": {}
}
}
66 changes: 47 additions & 19 deletions tests/validation/gpio/gpio.ino
Original file line number Diff line number Diff line change
Expand Up @@ -2,30 +2,58 @@
#include <unity.h>

#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));
Comment on lines +15 to +16
Copy link
Preview

Copilot AI Jun 13, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

[nitpick] Replace the raw C assert() with a Unity assertion macro (e.g., TEST_ASSERT_EQUAL) for consistent test reporting.

Suggested change
assert(digitalRead(BTN) == 1);
TEST_ASSERT_EQUAL(HIGH, digitalRead(BTN));
TEST_ASSERT_EQUAL(HIGH, digitalRead(BTN));
TEST_ASSERT_EQUAL(HIGH, digitalRead(BTN));

Copilot uses AI. Check for mistakes.

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");
Copy link
Preview

Copilot AI Jun 13, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This print message doesn’t match scenario.yaml, which expects "GPIO write - basic START". Update it to match the scenario.

Suggested change
Serial.println("GPIO write - basic test");
Serial.println("GPIO write - basic START");

Copilot uses AI. Check for mistakes.

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() {}
54 changes: 31 additions & 23 deletions tests/validation/gpio/scenario.yaml
Original file line number Diff line number Diff line change
@@ -1,40 +1,48 @@
name: Pushbutton counter test
version: 1
author: Jan Prochazka ([email protected])
author: Jan Prochazka ([email protected]) + Jakub Andrysek ([email protected])

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"
13 changes: 1 addition & 12 deletions tests/validation/gpio/test_gpio.py
Original file line number Diff line number Diff line change
Expand Up @@ -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")
7 changes: 7 additions & 0 deletions tests/validation/gpio_interrupt/ci.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
{
"platforms": {
"hardware": false,
"qemu": false,
"wokwi": true
}
}
Loading