Skip to content

Commit 573feda

Browse files
author
gojimmypi
committed
add const_byte_ptr_test for Xtensa -mforce-l32 check
1 parent 678a658 commit 573feda

1 file changed

Lines changed: 42 additions & 0 deletions

File tree

wolfcrypt/test/test.c

Lines changed: 42 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -55,6 +55,9 @@
5555
#endif
5656
#endif
5757

58+
const byte const_byte_array[] = "A+Gd\0\0\0";
59+
#define CBPTR_EXPECTED 'A'
60+
5861
#if defined(WOLFSSL_TRACK_MEMORY_VERBOSE) && !defined(WOLFSSL_STATIC_MEMORY)
5962
#ifdef WOLFSSL_TEST_MAX_RELATIVE_HEAP_ALLOCS
6063
static ssize_t max_relative_heap_allocs = WOLFSSL_TEST_MAX_RELATIVE_HEAP_ALLOCS;
@@ -13556,9 +13559,41 @@ static wc_test_ret_t simple_mem_test(int sz)
1355613559
}
1355713560
#endif
1355813561

13562+
/* If successful, returns the first letter of the byte array `in`.
13563+
**
13564+
** This is a deceptively simple test of a read-only embedded Linux file system.
13565+
** (e.g CFLAGS `-mfdpic` and `-mforce-l32`) for Xtensa Linux ESP32. When the
13566+
** `-mforce-l32` is missing, access to `in` will fail with Illegal Instruction.
13567+
** Const is on read-only memory-mapped file system, *not* loaded in app memory.
13568+
**
13569+
** Edit with caution. See PR #6523. */
13570+
static wc_test_ret_t const_byte_ptr_test(const byte* in, word32 *outJ)
13571+
{
13572+
wc_test_ret_t ret = 0;
13573+
volatile word32 j = -1; /* must be volatile to properly detect error */
13574+
13575+
ret = (wc_test_ret_t)*in; /* accessed *in value. */
13576+
j = *outJ; /* Found index to use in const array. */
13577+
13578+
if (j == 0) {
13579+
#ifdef WOLFSSL_DEBUG
13580+
printf("Testing const byte ptr reference...\n");
13581+
#endif
13582+
/* although j is zero, in[0] does not detect the Illegal instruction */
13583+
ret = in[j]; /* The big test: can we actually access the `in` data? */
13584+
}
13585+
else {
13586+
ret = -1;
13587+
}
13588+
13589+
return ret;
13590+
}
13591+
1355913592
WOLFSSL_TEST_SUBROUTINE wc_test_ret_t memory_test(void)
1356013593
{
1356113594
wc_test_ret_t ret = 0;
13595+
word32 j = 0; /* used in embedded const pointer test */
13596+
1356213597
#if defined(COMPLEX_MEM_TEST) || defined(WOLFSSL_STATIC_MEMORY)
1356313598
int i;
1356413599
#endif
@@ -13704,6 +13739,13 @@ WOLFSSL_TEST_SUBROUTINE wc_test_ret_t memory_test(void)
1370413739
}
1370513740
#endif
1370613741

13742+
if (ret == 0) {
13743+
/* This test is only interesting on embedded R/O Flash systems */
13744+
if (const_byte_ptr_test(const_byte_array, &j) != CBPTR_EXPECTED) {
13745+
ret = 1;
13746+
}
13747+
}
13748+
1370713749
return ret;
1370813750
}
1370913751

0 commit comments

Comments
 (0)