Skip to content
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.

Commit 978b441

Browse files
lucasssvazpre-commit-ci-lite[bot]
andauthoredFeb 19, 2025
test(wokwi): Add I2C Master test and enable GPIO and PSRAM tests (espressif#10848)
* test(wokwi): Enable PSRAM test * fix(tests): Add missing diagram for ESP32-P4 * test(wokwi): Enable GPIO test * test(wokwi): Add I2C master test * fix(tests): Add missing requirement and improve logging * ci(pre-commit): Apply automatic fixes --------- Co-authored-by: pre-commit-ci-lite[bot] <117423508+pre-commit-ci-lite[bot]@users.noreply.github.com>
1 parent eec2af3 commit 978b441

15 files changed

+488
-8
lines changed
 

‎.github/scripts/tests_run.sh

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -48,10 +48,10 @@ function run_test {
4848
return 0
4949
fi
5050

51-
local right_target
52-
right_target=$(grep -E "^CONFIG_IDF_TARGET=\"$target\"$" "$sdkconfig_path")
53-
if [ -z "$right_target" ]; then
54-
printf "\033[91mError: Sketch %s compiled for different target\n\033[0m\n" "$sketchname"
51+
local compiled_target
52+
compiled_target=$(grep -E "CONFIG_IDF_TARGET=" "$sdkconfig_path" | cut -d'"' -f2)
53+
if [ "$compiled_target" != "$target" ]; then
54+
printf "\033[91mError: Sketch %s compiled for %s, expected %s\033[0m\n" "$sketchname" "$compiled_target" "$target"
5555
printf "\n\n\n"
5656
return 1
5757
fi

‎tests/requirements.txt

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,3 +5,4 @@ pytest-embedded-serial-esp==1.12.0
55
pytest-embedded-arduino==1.12.0
66
pytest-embedded-wokwi==1.12.0
77
pytest-embedded-qemu==1.12.0
8+
esptool==4.8.1

‎tests/validation/gpio/ci.json

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,6 @@
11
{
22
"platforms": {
33
"hardware": false,
4-
"qemu": false,
5-
"wokwi": false
4+
"qemu": false
65
}
76
}
Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
{
2+
"version": 1,
3+
"author": "lucasssvaz",
4+
"editor": "wokwi",
5+
"parts": [
6+
{
7+
"type": "board-esp32-p4-function-ev",
8+
"id": "esp32",
9+
"top": -66.32,
10+
"left": -277.63,
11+
"attrs": {}
12+
},
13+
{
14+
"type": "wokwi-pushbutton",
15+
"id": "btn1",
16+
"top": -128.2,
17+
"left": -19.2,
18+
"attrs": { "color": "green", "bounce": "1" }
19+
}
20+
],
21+
"connections": [
22+
[ "esp32:38", "$serialMonitor:TX", "", [] ],
23+
[ "esp32:37", "$serialMonitor:RX", "", [] ],
24+
[ "btn1:2.r", "esp32:GND.3", "black", [ "h19.4", "v29" ] ],
25+
[ "esp32:0", "btn1:1.l", "blue", [ "h-48", "v-67.2" ] ]
26+
],
27+
"dependencies": {}
28+
}

‎tests/validation/i2c_master/ci.json

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
{
2+
"platforms": {
3+
"hardware": false,
4+
"qemu": false
5+
},
6+
"requires": [
7+
"CONFIG_SOC_I2C_SUPPORTED=y"
8+
]
9+
}
Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
{
2+
"version": 1,
3+
"author": "lucasssvaz",
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+
{ "type": "wokwi-ds1307", "id": "rtc1", "top": -43.8, "left": -19.1, "attrs": {} }
14+
],
15+
"connections": [
16+
[ "esp32:RX", "$serialMonitor:TX", "", [] ],
17+
[ "esp32:TX", "$serialMonitor:RX", "", [] ],
18+
[ "esp32:22", "rtc1:SCL", "green", [ "h38.4", "v-9.6" ] ],
19+
[ "esp32:21", "rtc1:SDA", "blue", [ "h48", "v-28.8", "h19.2" ] ],
20+
[ "esp32:GND.2", "rtc1:GND", "black", [ "v0" ] ],
21+
[ "rtc1:5V", "esp32:5V", "red", [ "h-28.8", "v-67.6", "h-172.8", "v230.4" ] ]
22+
],
23+
"dependencies": {}
24+
}
Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
{
2+
"version": 1,
3+
"author": "lucasssvaz",
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+
{ "type": "wokwi-ds1307", "id": "rtc1", "top": -43.8, "left": -19.1, "attrs": {} }
14+
],
15+
"connections": [
16+
[ "esp32:RX", "$serialMonitor:TX", "", [] ],
17+
[ "esp32:TX", "$serialMonitor:RX", "", [] ],
18+
[ "rtc1:5V", "esp32:5V", "red", [ "h-28.8", "v-67.6", "h-172.8", "v230.4" ] ],
19+
[ "esp32:5V.1", "rtc1:5V", "red", [ "h-18.22", "v-144.3", "h153.6", "v48" ] ],
20+
[ "esp32:GND.10", "rtc1:GND", "black", [ "h56.16", "v9.3" ] ],
21+
[ "esp32:8", "rtc1:SDA", "green", [ "h17.76", "v-19.5" ] ],
22+
[ "esp32:9", "rtc1:SCL", "blue", [ "h0" ] ]
23+
],
24+
"dependencies": {}
25+
}
Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
{
2+
"version": 1,
3+
"author": "lucasssvaz",
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+
{ "type": "wokwi-ds1307", "id": "rtc1", "top": -43.8, "left": -19.1, "attrs": {} }
14+
],
15+
"connections": [
16+
[ "esp32:RX", "$serialMonitor:TX", "", [] ],
17+
[ "esp32:TX", "$serialMonitor:RX", "", [] ],
18+
[ "rtc1:5V", "esp32:5V", "red", [ "h-28.8", "v-67.6", "h-172.8", "v230.4" ] ],
19+
[ "esp32:5V.1", "rtc1:5V", "red", [ "h-18.22", "v-144.3", "h153.6", "v48" ] ],
20+
[ "esp32:GND.10", "rtc1:GND", "black", [ "h56.16", "v9.3" ] ],
21+
[ "esp32:23", "rtc1:SDA", "green", [ "h17.38", "v-23.51" ] ],
22+
[ "esp32:GND.4", "rtc1:GND", "black", [ "h55.78", "v-4.31" ] ],
23+
[ "esp32:22", "rtc1:SCL", "blue", [ "h26.98", "v-23.51" ] ]
24+
],
25+
"dependencies": {}
26+
}
Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
{
2+
"version": 1,
3+
"author": "lucasssvaz",
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+
{ "type": "wokwi-ds1307", "id": "rtc1", "top": -43.8, "left": -19.1, "attrs": {} }
14+
],
15+
"connections": [
16+
[ "esp32:RX", "$serialMonitor:TX", "", [] ],
17+
[ "esp32:TX", "$serialMonitor:RX", "", [] ],
18+
[ "esp32:GND.6", "rtc1:GND", "black", [ "h0" ] ],
19+
[ "esp32:5V", "rtc1:5V", "red", [ "h-29.14", "v-160.97", "h172.8", "v48" ] ],
20+
[ "esp32:12", "rtc1:SDA", "green", [ "h36.58", "v-36.17" ] ],
21+
[ "esp32:22", "rtc1:SCL", "blue", [ "v-7.37", "h46.18", "v-38.4" ] ]
22+
],
23+
"dependencies": {}
24+
}
Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
{
2+
"version": 1,
3+
"author": "lucasssvaz",
4+
"editor": "wokwi",
5+
"parts": [
6+
{
7+
"type": "board-esp32-p4-function-ev",
8+
"id": "esp32",
9+
"top": -57.6,
10+
"left": -177.56,
11+
"attrs": {}
12+
},
13+
{ "type": "wokwi-ds1307", "id": "rtc1", "top": -197.4, "left": 57.7, "attrs": {} }
14+
],
15+
"connections": [
16+
[ "esp32:38", "$serialMonitor:TX", "", [] ],
17+
[ "esp32:37", "$serialMonitor:RX", "", [] ],
18+
[ "esp32:5V.1", "rtc1:5V", "red", [ "v0" ] ],
19+
[ "esp32:GND.1", "rtc1:GND", "black", [ "v-133.52", "h5.53" ] ],
20+
[ "esp32:7", "rtc1:SDA", "green", [ "v0" ] ],
21+
[ "esp32:8", "rtc1:SCL", "blue", [ "h15.13", "v-114.12" ] ]
22+
],
23+
"dependencies": {}
24+
}
Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
{
2+
"version": 1,
3+
"author": "lucasssvaz",
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+
{ "type": "wokwi-ds1307", "id": "rtc1", "top": -43.8, "left": -19.1, "attrs": {} }
14+
],
15+
"connections": [
16+
[ "esp32:RX", "$serialMonitor:TX", "", [] ],
17+
[ "esp32:TX", "$serialMonitor:RX", "", [] ],
18+
[ "esp32:GND.2", "rtc1:GND", "black", [ "v0" ] ],
19+
[ "rtc1:5V", "esp32:5V", "red", [ "h-28.8", "v-67.6", "h-172.8", "v230.4" ] ],
20+
[ "esp32:8", "rtc1:SDA", "green", [ "h-19.47", "v-119.51", "h144", "v57.6" ] ],
21+
[ "esp32:9", "rtc1:SCL", "blue", [ "h-29.07", "v-138.71", "h144", "v76.8" ] ]
22+
],
23+
"dependencies": {}
24+
}
Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
{
2+
"version": 1,
3+
"author": "lucasssvaz",
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+
{ "type": "wokwi-ds1307", "id": "rtc1", "top": -43.8, "left": -19.1, "attrs": {} }
14+
],
15+
"connections": [
16+
[ "esp32:RX", "$serialMonitor:TX", "", [] ],
17+
[ "esp32:TX", "$serialMonitor:RX", "", [] ],
18+
[ "esp32:GND.2", "rtc1:GND", "black", [ "v0" ] ],
19+
[ "rtc1:5V", "esp32:5V", "red", [ "h-28.8", "v-67.6", "h-172.8", "v230.4" ] ],
20+
[ "esp32:8", "rtc1:SDA", "green", [ "h-19.47", "v-119.51", "h144", "v32.93", "h38.35" ] ],
21+
[ "esp32:9", "rtc1:SCL", "blue", [ "h-29.07", "v-138.71", "h144", "v32.93", "h47.95" ] ]
22+
],
23+
"dependencies": {}
24+
}
Lines changed: 271 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,271 @@
1+
/*
2+
I2C Master Test for
3+
*/
4+
5+
#include <Arduino.h>
6+
#include <unity.h>
7+
#include <Wire.h>
8+
9+
/* DS1307 functions */
10+
11+
const uint8_t DS1307_ADDR = 0x68;
12+
const uint8_t start_sec = 1;
13+
const uint8_t start_min = 2;
14+
const uint8_t start_hour = 3;
15+
const uint8_t start_day = 4;
16+
const uint8_t start_month = 5;
17+
const uint16_t start_year = 2020;
18+
19+
static uint8_t read_sec = 0;
20+
static uint8_t read_min = 0;
21+
static uint8_t read_hour = 0;
22+
static uint8_t read_day = 0;
23+
static uint8_t read_month = 0;
24+
static uint16_t read_year = 0;
25+
static int peek_data = -1;
26+
27+
const auto BCD2DEC = [](uint8_t num) -> uint8_t {
28+
return ((num / 16 * 10) + (num % 16));
29+
};
30+
31+
const auto DEC2BCD = [](uint8_t num) -> uint8_t {
32+
return ((num / 10 * 16) + (num % 10));
33+
};
34+
35+
void reset_read_values() {
36+
read_sec = 0;
37+
read_min = 0;
38+
read_hour = 0;
39+
read_day = 0;
40+
read_month = 0;
41+
read_year = 0;
42+
}
43+
44+
void ds1307_start(void) {
45+
uint8_t sec;
46+
47+
//Get seconds
48+
Wire.beginTransmission(DS1307_ADDR);
49+
Wire.write(0x00);
50+
Wire.endTransmission();
51+
Wire.requestFrom(DS1307_ADDR, 1);
52+
sec = Wire.read() & 0x7F; //Seconds without halt bit
53+
54+
//Set seconds and start clock
55+
Wire.beginTransmission(DS1307_ADDR);
56+
Wire.write(0x00);
57+
Wire.write(sec);
58+
Wire.endTransmission();
59+
}
60+
61+
void ds1307_stop(void) {
62+
uint8_t sec;
63+
64+
//Get seconds
65+
Wire.beginTransmission(DS1307_ADDR);
66+
Wire.write(0x00);
67+
Wire.endTransmission();
68+
Wire.requestFrom(DS1307_ADDR, 1);
69+
sec = Wire.read() | 0x80; //Seconds with halt bit
70+
71+
//Set seconds and halt clock
72+
Wire.beginTransmission(DS1307_ADDR);
73+
Wire.write(0x00);
74+
Wire.write(sec);
75+
Wire.endTransmission();
76+
}
77+
78+
void ds1307_get_time(uint8_t *sec, uint8_t *min, uint8_t *hour, uint8_t *day, uint8_t *month, uint16_t *year) {
79+
//Get time
80+
Wire.beginTransmission(DS1307_ADDR);
81+
Wire.write(0x00);
82+
Wire.endTransmission();
83+
Wire.requestFrom(DS1307_ADDR, 7);
84+
85+
TEST_ASSERT_EQUAL(7, Wire.available());
86+
87+
if (peek_data == -1 && Wire.peek() != -1) {
88+
peek_data = Wire.peek();
89+
}
90+
91+
*sec = BCD2DEC(Wire.read() & 0x7F); //Seconds without halt bit
92+
*min = BCD2DEC(Wire.read());
93+
*hour = BCD2DEC(Wire.read() & 0x3F);
94+
Wire.read(); //Ignore day of week
95+
*day = BCD2DEC(Wire.read());
96+
*month = BCD2DEC(Wire.read());
97+
*year = BCD2DEC(Wire.read()) + 2000;
98+
}
99+
100+
void ds1307_set_time(uint8_t sec, uint8_t min, uint8_t hour, uint8_t day, uint8_t month, uint16_t year) {
101+
Wire.beginTransmission(DS1307_ADDR);
102+
Wire.write(0x00);
103+
Wire.write(DEC2BCD(sec));
104+
Wire.write(DEC2BCD(min));
105+
Wire.write(DEC2BCD(hour));
106+
Wire.write(DEC2BCD(0)); //Ignore day of week
107+
Wire.write(DEC2BCD(day));
108+
Wire.write(DEC2BCD(month));
109+
Wire.write(DEC2BCD(year - 2000));
110+
Wire.endTransmission();
111+
}
112+
113+
/* Unity functions */
114+
115+
// This function is automatically called by unity before each test is run
116+
void setUp(void) {
117+
reset_read_values();
118+
Wire.begin();
119+
}
120+
121+
// This function is automatically called by unity after each test is run
122+
void tearDown(void) {
123+
//Reset time
124+
ds1307_set_time(start_sec, start_min, start_hour, start_day, start_month, start_year);
125+
126+
Wire.end();
127+
}
128+
129+
void rtc_set_time() {
130+
//Set time
131+
ds1307_set_time(start_sec, start_min, start_hour, start_day, start_month, start_year);
132+
133+
//Get time
134+
ds1307_get_time(&read_sec, &read_min, &read_hour, &read_day, &read_month, &read_year);
135+
136+
//Check time
137+
TEST_ASSERT_EQUAL(start_sec, read_sec);
138+
TEST_ASSERT_EQUAL(start_min, read_min);
139+
TEST_ASSERT_EQUAL(start_hour, read_hour);
140+
TEST_ASSERT_EQUAL(start_day, read_day);
141+
TEST_ASSERT_EQUAL(start_month, read_month);
142+
TEST_ASSERT_EQUAL(start_year, read_year);
143+
}
144+
145+
void rtc_run_clock() {
146+
uint8_t old_sec = 0;
147+
148+
//Run clock for 5 seconds
149+
ds1307_start();
150+
delay(5000);
151+
ds1307_stop();
152+
153+
//Get time
154+
ds1307_get_time(&read_sec, &read_min, &read_hour, &read_day, &read_month, &read_year);
155+
156+
//Check time
157+
TEST_ASSERT_UINT8_WITHIN(2, start_sec + 5, read_sec);
158+
TEST_ASSERT_EQUAL(start_min, read_min);
159+
TEST_ASSERT_EQUAL(start_hour, read_hour);
160+
TEST_ASSERT_EQUAL(start_day, read_day);
161+
TEST_ASSERT_EQUAL(start_month, read_month);
162+
TEST_ASSERT_EQUAL(start_year, read_year);
163+
164+
old_sec = read_sec;
165+
reset_read_values();
166+
167+
//Get time again to check that clock is stopped
168+
delay(2000);
169+
ds1307_get_time(&read_sec, &read_min, &read_hour, &read_day, &read_month, &read_year);
170+
171+
//Check time
172+
TEST_ASSERT_EQUAL(old_sec, read_sec);
173+
TEST_ASSERT_EQUAL(start_min, read_min);
174+
TEST_ASSERT_EQUAL(start_hour, read_hour);
175+
TEST_ASSERT_EQUAL(start_day, read_day);
176+
TEST_ASSERT_EQUAL(start_month, read_month);
177+
TEST_ASSERT_EQUAL(start_year, read_year);
178+
}
179+
180+
void change_clock() {
181+
//Get time
182+
ds1307_get_time(&read_sec, &read_min, &read_hour, &read_day, &read_month, &read_year);
183+
184+
//Check time
185+
TEST_ASSERT_EQUAL(start_sec, read_sec);
186+
TEST_ASSERT_EQUAL(start_min, read_min);
187+
TEST_ASSERT_EQUAL(start_hour, read_hour);
188+
TEST_ASSERT_EQUAL(start_day, read_day);
189+
TEST_ASSERT_EQUAL(start_month, read_month);
190+
TEST_ASSERT_EQUAL(start_year, read_year);
191+
192+
Wire.setClock(400000);
193+
reset_read_values();
194+
195+
TEST_ASSERT_EQUAL(400000, Wire.getClock());
196+
197+
//Get time
198+
ds1307_get_time(&read_sec, &read_min, &read_hour, &read_day, &read_month, &read_year);
199+
200+
//Check time
201+
TEST_ASSERT_EQUAL(start_sec, read_sec);
202+
TEST_ASSERT_EQUAL(start_min, read_min);
203+
TEST_ASSERT_EQUAL(start_hour, read_hour);
204+
TEST_ASSERT_EQUAL(start_day, read_day);
205+
TEST_ASSERT_EQUAL(start_month, read_month);
206+
TEST_ASSERT_EQUAL(start_year, read_year);
207+
}
208+
209+
void swap_pins() {
210+
Wire.setPins(SCL, SDA);
211+
Wire.begin();
212+
//Set time
213+
ds1307_set_time(start_sec, start_min, start_hour, start_day, start_month, start_year);
214+
215+
//Get time
216+
ds1307_get_time(&read_sec, &read_min, &read_hour, &read_day, &read_month, &read_year);
217+
218+
//Check time
219+
TEST_ASSERT_EQUAL(start_sec, read_sec);
220+
TEST_ASSERT_EQUAL(start_min, read_min);
221+
TEST_ASSERT_EQUAL(start_hour, read_hour);
222+
TEST_ASSERT_EQUAL(start_day, read_day);
223+
TEST_ASSERT_EQUAL(start_month, read_month);
224+
TEST_ASSERT_EQUAL(start_year, read_year);
225+
226+
Wire.setPins(SDA, SCL);
227+
}
228+
229+
void test_api() {
230+
int integer_ret;
231+
232+
// Set Buffer Size
233+
integer_ret = Wire.setBufferSize(32);
234+
TEST_ASSERT_EQUAL(32, integer_ret);
235+
integer_ret = Wire.setBufferSize(I2C_BUFFER_LENGTH);
236+
TEST_ASSERT_EQUAL(I2C_BUFFER_LENGTH, integer_ret);
237+
238+
// Set TimeOut
239+
Wire.setTimeOut(100);
240+
TEST_ASSERT_EQUAL(100, Wire.getTimeOut());
241+
242+
// Check if buffer can be peeked
243+
TEST_ASSERT_GREATER_THAN(-1, peek_data);
244+
245+
Wire.flush();
246+
}
247+
248+
/* Main */
249+
250+
void setup() {
251+
Serial.begin(115200);
252+
while (!Serial) {
253+
delay(10);
254+
}
255+
256+
log_d("Starting I2C Master");
257+
Wire.begin();
258+
259+
log_d("Starting tests");
260+
UNITY_BEGIN();
261+
RUN_TEST(rtc_set_time);
262+
RUN_TEST(rtc_run_clock);
263+
RUN_TEST(change_clock);
264+
RUN_TEST(swap_pins);
265+
RUN_TEST(test_api);
266+
UNITY_END();
267+
}
268+
269+
void loop() {
270+
vTaskDelete(NULL);
271+
}
Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
def test_i2c_master(dut):
2+
dut.expect_unity_test_output(timeout=240)

‎tests/validation/psram/ci.json

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,6 @@
11
{
22
"platforms": {
3-
"qemu": false,
4-
"wokwi": false
3+
"qemu": false
54
},
65
"requires": [
76
"CONFIG_SPIRAM=y"

0 commit comments

Comments
 (0)
Please sign in to comment.