Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commit 3445164

Browse files
lucasssvazpre-commit-ci-lite[bot]
andauthored
test(psram): Add PSRAM test (#10409)
* test(psram): Add PSRAM test * fix(test): Hide pointer arithmetic warning * ci(pre-commit): Apply automatic fixes * fix(json): Remove FQBNs for the test --------- Co-authored-by: pre-commit-ci-lite[bot] <117423508+pre-commit-ci-lite[bot]@users.noreply.github.com>
1 parent 0d5d50e commit 3445164

File tree

3 files changed

+128
-0
lines changed

3 files changed

+128
-0
lines changed

‎tests/validation/psram/ci.json

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
{
2+
"platforms": {
3+
"qemu": false,
4+
"wokwi": false
5+
},
6+
"requires": [
7+
"CONFIG_SPIRAM=y"
8+
],
9+
"targets": {
10+
"esp32c3": false,
11+
"esp32c6": false,
12+
"esp32h2": false
13+
}
14+
}

‎tests/validation/psram/psram.ino

Lines changed: 112 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,112 @@
1+
#include <Arduino.h>
2+
#include <unity.h>
3+
4+
#define MAX_TEST_SIZE 512 * 1024 // 512KB
5+
6+
void *buf = NULL;
7+
8+
void test_malloc_success(void) {
9+
buf = ps_malloc(MAX_TEST_SIZE);
10+
TEST_ASSERT_NOT_NULL(buf);
11+
free(buf);
12+
buf = NULL;
13+
}
14+
15+
void test_calloc_success(void) {
16+
buf = ps_calloc(MAX_TEST_SIZE, 1);
17+
TEST_ASSERT_NOT_NULL(buf);
18+
free(buf);
19+
buf = NULL;
20+
}
21+
22+
void test_realloc_success(void) {
23+
buf = ps_malloc(MAX_TEST_SIZE);
24+
TEST_ASSERT_NOT_NULL(buf);
25+
buf = ps_realloc(buf, MAX_TEST_SIZE + 1024);
26+
TEST_ASSERT_NOT_NULL(buf);
27+
free(buf);
28+
buf = NULL;
29+
}
30+
31+
void test_malloc_fail(void) {
32+
buf = ps_malloc(0xFFFFFFFF);
33+
TEST_ASSERT_NULL(buf);
34+
}
35+
36+
void test_memset_all_zeroes(void) {
37+
memset(buf, 0, MAX_TEST_SIZE);
38+
for (size_t i = 0; i < MAX_TEST_SIZE; i++) {
39+
TEST_ASSERT_EQUAL(0, ((uint8_t *)buf)[i]);
40+
}
41+
}
42+
43+
void test_memset_all_ones(void) {
44+
memset(buf, 0xFF, MAX_TEST_SIZE);
45+
for (size_t i = 0; i < MAX_TEST_SIZE; i++) {
46+
TEST_ASSERT_EQUAL(0xFF, ((uint8_t *)buf)[i]);
47+
}
48+
}
49+
50+
void test_memset_alternating(void) {
51+
for (size_t i = 0; i < MAX_TEST_SIZE; i++) {
52+
((uint8_t *)buf)[i] = i % 2 == 0 ? 0x00 : 0xFF;
53+
}
54+
memset(buf, 0xAA, MAX_TEST_SIZE);
55+
for (size_t i = 0; i < MAX_TEST_SIZE; i++) {
56+
TEST_ASSERT_EQUAL(0xAA, ((uint8_t *)buf)[i]);
57+
}
58+
}
59+
60+
void test_memset_random(void) {
61+
for (size_t i = 0; i < MAX_TEST_SIZE; i++) {
62+
((uint8_t *)buf)[i] = random(0, 256);
63+
}
64+
memset(buf, 0x55, MAX_TEST_SIZE);
65+
for (size_t i = 0; i < MAX_TEST_SIZE; i++) {
66+
TEST_ASSERT_EQUAL(0x55, ((uint8_t *)buf)[i]);
67+
}
68+
}
69+
70+
void test_memcpy(void) {
71+
void *buf2 = malloc(1024); // 1KB
72+
TEST_ASSERT_NOT_NULL(buf2);
73+
memset(buf, 0x55, MAX_TEST_SIZE);
74+
memset(buf2, 0xAA, 1024);
75+
76+
#pragma GCC diagnostic push
77+
#pragma GCC diagnostic ignored "-Wpointer-arith"
78+
79+
for (size_t i = 0; i < MAX_TEST_SIZE; i += 1024) {
80+
memcpy(buf + i, buf2, 1024);
81+
}
82+
83+
for (size_t i = 0; i < MAX_TEST_SIZE; i += 1024) {
84+
TEST_ASSERT_NULL(memcmp(buf + i, buf2, 1024));
85+
}
86+
87+
#pragma GCC diagnostic pop
88+
89+
free(buf2);
90+
}
91+
92+
void setup() {
93+
Serial.begin(115200);
94+
while (!Serial) {
95+
delay(10);
96+
}
97+
98+
UNITY_BEGIN();
99+
RUN_TEST(test_malloc_success);
100+
RUN_TEST(test_malloc_fail);
101+
RUN_TEST(test_calloc_success);
102+
RUN_TEST(test_realloc_success);
103+
buf = ps_malloc(MAX_TEST_SIZE);
104+
RUN_TEST(test_memset_all_zeroes);
105+
RUN_TEST(test_memset_all_ones);
106+
RUN_TEST(test_memset_alternating);
107+
RUN_TEST(test_memset_random);
108+
RUN_TEST(test_memcpy);
109+
UNITY_END();
110+
}
111+
112+
void loop() {}

‎tests/validation/psram/test_psram.py

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
def test_psram(dut):
2+
dut.expect_unity_test_output(timeout=120)

0 commit comments

Comments
(0)

AltStyle によって変換されたページ (->オリジナル) /