|
55 | 55 | #endif |
56 | 56 | #endif |
57 | 57 |
|
| 58 | +const byte const_byte_array[] = "A+Gd\0\0\0"; |
| 59 | +#define CBPTR_EXPECTED 'A' |
| 60 | + |
58 | 61 | #if defined(WOLFSSL_TRACK_MEMORY_VERBOSE) && !defined(WOLFSSL_STATIC_MEMORY) |
59 | 62 | #ifdef WOLFSSL_TEST_MAX_RELATIVE_HEAP_ALLOCS |
60 | 63 | 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) |
13556 | 13559 | } |
13557 | 13560 | #endif |
13558 | 13561 |
|
| 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 | + |
13559 | 13592 | WOLFSSL_TEST_SUBROUTINE wc_test_ret_t memory_test(void) |
13560 | 13593 | { |
13561 | 13594 | wc_test_ret_t ret = 0; |
| 13595 | + word32 j = 0; /* used in embedded const pointer test */ |
| 13596 | + |
13562 | 13597 | #if defined(COMPLEX_MEM_TEST) || defined(WOLFSSL_STATIC_MEMORY) |
13563 | 13598 | int i; |
13564 | 13599 | #endif |
@@ -13704,6 +13739,13 @@ WOLFSSL_TEST_SUBROUTINE wc_test_ret_t memory_test(void) |
13704 | 13739 | } |
13705 | 13740 | #endif |
13706 | 13741 |
|
| 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 | + |
13707 | 13749 | return ret; |
13708 | 13750 | } |
13709 | 13751 |
|
|
0 commit comments