Skip to content

Commit f1d5859

Browse files
committed
tests/esp: Add complex PSRAM test
1 parent ff30bf0 commit f1d5859

File tree

6 files changed

+93
-13
lines changed

6 files changed

+93
-13
lines changed

testing/esp/test_apps/gen_ut_app/configs/psram_dual

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,9 @@ CONFIG_SPIRAM_MEMTEST=y
2121
CONFIG_SPIRAM_CACHE_WORKAROUND=y
2222
CONFIG_SPIRAM_BANKSWITCH_ENABLE=y
2323
CONFIG_SPIRAM_BANKSWITCH_RESERVE=8
24+
CONFIG_SPIRAM_USE_MALLOC=y
25+
CONFIG_SPIRAM_MALLOC_ALWAYSINTERNAL=16384
26+
CONFIG_SPIRAM_MALLOC_RESERVE_INTERNAL=32768
2427

2528
#
2629
# PSRAM clock and cs IO for ESP32-DOWD

testing/esp/test_apps/gen_ut_app/configs/psram_single

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,9 @@ CONFIG_SPIRAM_MEMTEST=y
2222
CONFIG_SPIRAM_CACHE_WORKAROUND=y
2323
CONFIG_SPIRAM_BANKSWITCH_ENABLE=y
2424
CONFIG_SPIRAM_BANKSWITCH_RESERVE=8
25+
CONFIG_SPIRAM_USE_MALLOC=y
26+
CONFIG_SPIRAM_MALLOC_ALWAYSINTERNAL=16384
27+
CONFIG_SPIRAM_MALLOC_RESERVE_INTERNAL=32768
2528

2629
#
2730
# PSRAM clock and cs IO for ESP32-DOWD

testing/esp/test_apps/gen_ut_app/main/gen_ut_app.c

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,9 @@
1616
#include "freertos/xtensa_api.h"
1717
#include "xtensa/core-macros.h"
1818
#endif
19+
#if UT_IDF_VER >= MAKE_UT_IDF_VER(5,0,0,0)
20+
#include "esp_memory_utils.h"
21+
#endif
1922
#include "driver/gpio.h"
2023
#include "test_timer.h"
2124
#define LOG_LOCAL_LEVEL CONFIG_LOG_DEFAULT_LEVEL

testing/esp/test_apps/gen_ut_app/main/gen_ut_app.h

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -39,6 +39,13 @@
3939
volatile static const int _nm_ ## _break_ln = __LINE__ + _shft_; \
4040
s_tmp_ln = _nm_ ## _break_ln;
4141

42+
#define TEST_BREAK_LBL(_nm_) \
43+
__asm__ __volatile__ ( \
44+
".global "#_nm_"\n" \
45+
".type "#_nm_",@function\n" \
46+
#_nm_":\n" \
47+
::)
48+
4249
// used to prevent linker from optimizing out the variables holding BP line numbers
4350
volatile static int s_tmp_ln = 0;
4451

testing/esp/test_apps/gen_ut_app/main/special_tests.c

Lines changed: 55 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
#include <string.h>
12
#include "driver/gpio.h"
23
#include "freertos/FreeRTOS.h"
34
#include "freertos/task.h"
@@ -54,16 +55,7 @@ static void cache_check_task(void *pvParameter)
5455

5556
static void psram_check_task(void *pvParameter)
5657
{
57-
#if !CONFIG_IDF_TARGET_ESP32 && UT_IDF_VER < MAKE_UT_IDF_VER(5,0,0,0)
58-
/* In ESP32S3/S2, PSRAM is mapped from high to low. Check s_mapped_vaddr_start at esp32s3/spiram.c
59-
There is a plan to change from low to high same as ESP32
60-
Follow up jira https://jira.espressif.com:8443/browse/IDF-4318
61-
*/
62-
uint32_t *mem = (uint32_t *)SOC_EXTRAM_DATA_HIGH - (SPIRAM_TEST_ARRAY_SZ * (xPortGetCoreID() + 1));
63-
#else
64-
uint32_t *mem = (uint32_t *)SOC_EXTRAM_DATA_LOW;
65-
#endif
66-
mem += xPortGetCoreID() * SPIRAM_TEST_ARRAY_SZ;
58+
uint32_t *mem = (uint32_t *)heap_caps_malloc(sizeof(uint32_t)*SPIRAM_TEST_ARRAY_SZ, MALLOC_CAP_DEFAULT|MALLOC_CAP_SPIRAM);
6759
for (int i = 0, k = 0x20; i < SPIRAM_TEST_ARRAY_SZ; i++, k++) {
6860
mem[i] = k;
6961
}
@@ -148,6 +140,52 @@ static void divide_by_zero_exc(void *pvParameter)
148140
: "+r"(a2) : "r"(a3)
149141
);
150142
}
143+
144+
static bool mem_check(uint8_t *mem, uint32_t mem_sz)
145+
{
146+
const uint8_t buf[256] = {0};
147+
148+
for (uint32_t i = 0; i < mem_sz;) {
149+
uint32_t cmp_sz = mem_sz > sizeof(buf) ? sizeof(buf) : mem_sz;
150+
if (memcmp(&mem[i], buf, cmp_sz)) {
151+
return false;
152+
}
153+
i += cmp_sz;
154+
mem_sz -= cmp_sz;
155+
}
156+
return true;
157+
}
158+
159+
// GH issue reported for ESP32-S3. See https://github.com/espressif/openocd-esp32/issues/264
160+
TEST_DECL(gh264_psram_check, "test_special.PsramTests*.test_psram_with_flash_breakpoints_gh264")
161+
{
162+
uint32_t alloc_sz = 100000;
163+
164+
while (1) {
165+
// CONFIG_SPIRAM_MALLOC_ALWAYSINTERNAL == 16384, so any block larger than this
166+
// will be forced into PSRAM. The following shows an overwrite.
167+
// 24540 works; 24541 begins to show overwrite; 1000000 is massive overwrite
168+
uint8_t *obj = calloc(alloc_sz,sizeof(uint8_t));
169+
assert(obj);
170+
printf("Allocated %u bytes @ %p\n", (unsigned int)alloc_sz, obj);
171+
172+
// Test breakpoints, to be set when you are stopped at app_main.
173+
// - if you only set "b 15" then "c", when it breaks do an "x/128xb obj" you'll see 0's as you should
174+
// - but if you set "b 15" AND "b 16" AND "b 17" then "c", when it breaks you'll see bad values
175+
assert(mem_check(obj, alloc_sz));
176+
TEST_BREAK_LBL(gh264_psram_check_bp_1);
177+
printf("breakpoint 1\n"); TEST_BREAK_LOC(gh264_psram_check_1);
178+
assert(mem_check(obj, alloc_sz));
179+
TEST_BREAK_LBL(gh264_psram_check_bp_2);
180+
printf("breakpoint 2\n"); TEST_BREAK_LOC(gh264_psram_check_2);
181+
assert(mem_check(obj, alloc_sz));
182+
TEST_BREAK_LBL(gh264_psram_check_bp_3);
183+
printf("breakpoint 3\n"); TEST_BREAK_LOC(gh264_psram_check_3);
184+
185+
free(obj);
186+
alloc_sz /= 2;
187+
}
188+
}
151189
#endif
152190

153191
volatile static int s_var1;
@@ -262,6 +300,13 @@ ut_result_t special_test_do(int test_num)
262300
}
263301
#endif
264302
default:
303+
#if CONFIG_IDF_TARGET_ARCH_XTENSA
304+
if (TEST_ID_MATCH(TEST_ID_PATTERN(gh264_psram_check), test_num))
305+
{
306+
xTaskCreatePinnedToCore(TEST_ENTRY(gh264_psram_check), "gh264_psram_check_task", 4096, NULL, 5, NULL, portNUM_PROCESSORS-1);
307+
break;
308+
}
309+
#endif
265310
return UT_UNSUPPORTED;
266311
}
267312
return UT_OK;

testing/esp/test_special.py

Lines changed: 22 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -162,9 +162,9 @@ def test_stub_logs(self):
162162
# We expect at least len(expected_strings) for one core.
163163
self.assertTrue(found_line_count >= len(expected_strings))
164164

165-
# to be skipped for any board with ESP32-S2 chip
166-
# TODO: enable these tests when PSRAM is supported for ESP32-S2
167-
@skip_for_chip(['esp32s2', 'esp32c3', 'esp32c2'])
165+
166+
# PSRAM is supported for Xtensa chips only
167+
@only_for_arch(['xtensa'])
168168
class PsramTestsImpl:
169169
""" PSRAM specific test cases generic for dual and single core modes
170170
"""
@@ -191,6 +191,25 @@ def test_psram_with_flash_breakpoints(self):
191191
# break at vTaskDelay
192192
self.run_to_bp_and_check(dbg.TARGET_STOP_REASON_BP, 'vTaskDelay', ['vTaskDelay%d' % (i % 2)], outmost_func_name='psram_check_task')
193193

194+
def test_psram_with_flash_breakpoints_gh264(self):
195+
"""
196+
GH issue reported for ESP32-S3. See https://github.com/espressif/openocd-esp32/issues/264
197+
This test checks that PSRAM memory contents ard not corrupted when using flash SW breakpoints.
198+
1) Select appropriate sub-test number on target.
199+
2) Resume target, wait for the program to stop at the places where we set breakpoints.
200+
3) Target program checks PSRAM memory contents and calls 'assert()' in case of error,
201+
so test expects propgram to be stopped on breakpoints only. Stop at the call to 'assert()' is a failure.
202+
"""
203+
# 2 HW breaks + 1 flash SW break + RAM SW break
204+
bps = ['gh264_psram_check_bp_1', 'gh264_psram_check_bp_2', 'gh264_psram_check_bp_3']
205+
for f in bps:
206+
self.add_bp(f)
207+
for i in range(3):
208+
self.run_to_bp_and_check_location(dbg.TARGET_STOP_REASON_BP, 'gh264_psram_check_task', 'gh264_psram_check_1')
209+
self.run_to_bp_and_check_location(dbg.TARGET_STOP_REASON_BP, 'gh264_psram_check_task', 'gh264_psram_check_2')
210+
self.run_to_bp_and_check_location(dbg.TARGET_STOP_REASON_BP, 'gh264_psram_check_task', 'gh264_psram_check_3')
211+
212+
194213
########################################################################
195214
# TESTS DEFINITION WITH SPECIAL TESTS #
196215
########################################################################

0 commit comments

Comments
 (0)