From 69410d476e00f3fc6841e13e9f6f6fa8549220a1 Mon Sep 17 00:00:00 2001 From: Lucas Saavedra Vaz <32426024+lucasssvaz@users.noreply.github.com> Date: Wed, 2 Oct 2024 13:53:24 -0300 Subject: [PATCH 1/4] test(psram): Add PSRAM test --- tests/validation/psram/ci.json | 26 +++++++ tests/validation/psram/psram.ino | 107 +++++++++++++++++++++++++++ tests/validation/psram/test_psram.py | 2 + 3 files changed, 135 insertions(+) create mode 100644 tests/validation/psram/ci.json create mode 100644 tests/validation/psram/psram.ino create mode 100644 tests/validation/psram/test_psram.py diff --git a/tests/validation/psram/ci.json b/tests/validation/psram/ci.json new file mode 100644 index 00000000000..1a58a39eb52 --- /dev/null +++ b/tests/validation/psram/ci.json @@ -0,0 +1,26 @@ +{ + "fqbn": { + "esp32": [ + "espressif:esp32:esp32:PSRAM=enabled" + ], + "esp32s2": [ + "espressif:esp32:esp32s2:PSRAM=enabled" + ], + "esp32s3": [ + "espressif:esp32:esp32s3:PSRAM=opi,USBMode=default", + "espressif:esp32:esp32s3:PSRAM=enabled,USBMode=default" + ] + }, + "platforms": { + "qemu": false, + "wokwi": false + }, + "requires": [ + "CONFIG_SPIRAM=y" + ], + "targets": { + "esp32c3": false, + "esp32c6": false, + "esp32h2": false + } +} diff --git a/tests/validation/psram/psram.ino b/tests/validation/psram/psram.ino new file mode 100644 index 00000000000..68123ab8b4e --- /dev/null +++ b/tests/validation/psram/psram.ino @@ -0,0 +1,107 @@ +#include +#include + +#define MAX_TEST_SIZE 512 * 1024 // 512KB + +void *buf = NULL; + +void test_malloc_success(void) { + buf = ps_malloc(MAX_TEST_SIZE); + TEST_ASSERT_NOT_NULL(buf); + free(buf); + buf = NULL; +} + +void test_calloc_success(void) { + buf = ps_calloc(MAX_TEST_SIZE, 1); + TEST_ASSERT_NOT_NULL(buf); + free(buf); + buf = NULL; +} + +void test_realloc_success(void) { + buf = ps_malloc(MAX_TEST_SIZE); + TEST_ASSERT_NOT_NULL(buf); + buf = ps_realloc(buf, MAX_TEST_SIZE + 1024); + TEST_ASSERT_NOT_NULL(buf); + free(buf); + buf = NULL; +} + +void test_malloc_fail(void) { + buf = ps_malloc(0xFFFFFFFF); + TEST_ASSERT_NULL(buf); +} + +void test_memset_all_zeroes(void) { + memset(buf, 0, MAX_TEST_SIZE); + for (size_t i = 0; i < MAX_TEST_SIZE; i++) { + TEST_ASSERT_EQUAL(0, ((uint8_t *)buf)[i]); + } +} + +void test_memset_all_ones(void) { + memset(buf, 0xFF, MAX_TEST_SIZE); + for (size_t i = 0; i < MAX_TEST_SIZE; i++) { + TEST_ASSERT_EQUAL(0xFF, ((uint8_t *)buf)[i]); + } +} + +void test_memset_alternating(void) { + for (size_t i = 0; i < MAX_TEST_SIZE; i++) { + ((uint8_t *)buf)[i] = i % 2 == 0 ? 0x00 : 0xFF; + } + memset(buf, 0xAA, MAX_TEST_SIZE); + for (size_t i = 0; i < MAX_TEST_SIZE; i++) { + TEST_ASSERT_EQUAL(0xAA, ((uint8_t *)buf)[i]); + } +} + +void test_memset_random(void) { + for (size_t i = 0; i < MAX_TEST_SIZE; i++) { + ((uint8_t *)buf)[i] = random(0, 256); + } + memset(buf, 0x55, MAX_TEST_SIZE); + for (size_t i = 0; i < MAX_TEST_SIZE; i++) { + TEST_ASSERT_EQUAL(0x55, ((uint8_t *)buf)[i]); + } +} + +void test_memcpy(void) { + void *buf2 = malloc(1024); // 1KB + TEST_ASSERT_NOT_NULL(buf2); + memset(buf, 0x55, MAX_TEST_SIZE); + memset(buf2, 0xAA, 1024); + + for (size_t i = 0; i < MAX_TEST_SIZE; i += 1024) { + memcpy(buf + i, buf2, 1024); + } + + for (size_t i = 0; i < MAX_TEST_SIZE; i += 1024) { + TEST_ASSERT_NULL(memcmp(buf + i, buf2, 1024)); + } + + free(buf2); +} + +void setup() { + Serial.begin(115200); + while (!Serial) { + delay(10); + } + + UNITY_BEGIN(); + RUN_TEST(test_malloc_success); + RUN_TEST(test_malloc_fail); + RUN_TEST(test_calloc_success); + RUN_TEST(test_realloc_success); + buf = ps_malloc(MAX_TEST_SIZE); + RUN_TEST(test_memset_all_zeroes); + RUN_TEST(test_memset_all_ones); + RUN_TEST(test_memset_alternating); + RUN_TEST(test_memset_random); + RUN_TEST(test_memcpy); + UNITY_END(); +} + +void loop() {} diff --git a/tests/validation/psram/test_psram.py b/tests/validation/psram/test_psram.py new file mode 100644 index 00000000000..7bd1d9d735d --- /dev/null +++ b/tests/validation/psram/test_psram.py @@ -0,0 +1,2 @@ +def test_psram(dut): + dut.expect_unity_test_output(timeout=120) From 9694b8908d379688c46bbdf4d131435f06b649d1 Mon Sep 17 00:00:00 2001 From: Lucas Saavedra Vaz <32426024+lucasssvaz@users.noreply.github.com> Date: Thu, 3 Oct 2024 01:15:31 -0300 Subject: [PATCH 2/4] fix(test): Hide pointer arithmetic warning --- tests/validation/psram/psram.ino | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/tests/validation/psram/psram.ino b/tests/validation/psram/psram.ino index 68123ab8b4e..22086b97197 100644 --- a/tests/validation/psram/psram.ino +++ b/tests/validation/psram/psram.ino @@ -73,6 +73,9 @@ void test_memcpy(void) { memset(buf, 0x55, MAX_TEST_SIZE); memset(buf2, 0xAA, 1024); +#pragma GCC diagnostic push +#pragma GCC diagnostic ignored "-Wpointer-arith" + for (size_t i = 0; i < MAX_TEST_SIZE; i += 1024) { memcpy(buf + i, buf2, 1024); } @@ -81,6 +84,8 @@ void test_memcpy(void) { TEST_ASSERT_NULL(memcmp(buf + i, buf2, 1024)); } +#pragma GCC diagnostic pop + free(buf2); } From 35ae346e2aa2b6b46d3b02c40eccab68b2075542 Mon Sep 17 00:00:00 2001 From: "pre-commit-ci-lite[bot]" <117423508+pre-commit-ci-lite[bot]@users.noreply.github.com> Date: Fri, 4 Oct 2024 10:50:51 +0000 Subject: [PATCH 3/4] ci(pre-commit): Apply automatic fixes --- tests/validation/psram/psram.ino | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/tests/validation/psram/psram.ino b/tests/validation/psram/psram.ino index 22086b97197..1304fe85cc1 100644 --- a/tests/validation/psram/psram.ino +++ b/tests/validation/psram/psram.ino @@ -68,7 +68,7 @@ void test_memset_random(void) { } void test_memcpy(void) { - void *buf2 = malloc(1024); // 1KB + void *buf2 = malloc(1024); // 1KB TEST_ASSERT_NOT_NULL(buf2); memset(buf, 0x55, MAX_TEST_SIZE); memset(buf2, 0xAA, 1024); From c9b433a0e217fad3baf0e811f792beb4729b8f6e Mon Sep 17 00:00:00 2001 From: Lucas Saavedra Vaz <32426024+lucasssvaz@users.noreply.github.com> Date: Fri, 4 Oct 2024 10:03:24 -0300 Subject: [PATCH 4/4] fix(json): Remove FQBNs for the test --- tests/validation/psram/ci.json | 12 ------------ 1 file changed, 12 deletions(-) diff --git a/tests/validation/psram/ci.json b/tests/validation/psram/ci.json index 1a58a39eb52..fc34574cf37 100644 --- a/tests/validation/psram/ci.json +++ b/tests/validation/psram/ci.json @@ -1,16 +1,4 @@ { - "fqbn": { - "esp32": [ - "espressif:esp32:esp32:PSRAM=enabled" - ], - "esp32s2": [ - "espressif:esp32:esp32s2:PSRAM=enabled" - ], - "esp32s3": [ - "espressif:esp32:esp32s3:PSRAM=opi,USBMode=default", - "espressif:esp32:esp32s3:PSRAM=enabled,USBMode=default" - ] - }, "platforms": { "qemu": false, "wokwi": false