1 /*
2 * SPDX-FileCopyrightText: 2022 Espressif Systems (Shanghai) CO LTD
3 *
4 * SPDX-License-Identifier: Apache-2.0
5 */
6 #include <string.h>
7 #include "unity.h"
8 #include "esp_attr.h"
9
10 /* Global variables that should be part of the coredump */
11 COREDUMP_IRAM_DATA_ATTR uint32_t var_iram = 0x42;
12 COREDUMP_DRAM_ATTR uint32_t var_dram = 0x43;
13 COREDUMP_RTC_DATA_ATTR uint32_t var_rtc = 0x44;
14 COREDUMP_RTC_FAST_ATTR uint32_t var_rtcfast = 0x45;
15
16 /* Memory regions to dump, defined at compile time. */
17 extern int _coredump_dram_start;
18 extern int _coredump_dram_end;
19 extern int _coredump_iram_start;
20 extern int _coredump_iram_end;
21 extern int _coredump_rtc_start;
22 extern int _coredump_rtc_end;
23 extern int _coredump_rtc_fast_start;
24 extern int _coredump_rtc_fast_end;
25
is_addr_in_region(void * addr,uint8_t * region,int region_size)26 static inline bool is_addr_in_region(void* addr, uint8_t* region, int region_size)
27 {
28 const void* start = (void*) region;
29 const void* end = (void*) (region + region_size);
30 return addr >= start && addr < end;
31 }
32
33 TEST_CASE("test variables presence in core dump sections", "[espcoredump]")
34 {
35 uint32_t section_start = 0;
36 uint32_t section_size = 0;
37
38 /* Check DRAM coredump section */
39 section_start = (uint32_t)&_coredump_dram_start;
40 section_size = (uint8_t *)&_coredump_dram_end - (uint8_t *)&_coredump_dram_start;
41 TEST_ASSERT(section_size > 0);
42 TEST_ASSERT(is_addr_in_region(&var_dram, (uint8_t*) section_start, section_size));
43 #if IRAM_8BIT_ACCESSIBLE
44 /* Check IRAM coredump section */
45 section_start = (uint32_t)&_coredump_iram_start;
46 section_size = (uint8_t *)&_coredump_iram_end - (uint8_t *)&_coredump_iram_start;
47 TEST_ASSERT(section_size > 0);
48 TEST_ASSERT(is_addr_in_region(&var_iram, (uint8_t*) section_start, section_size));
49 #endif
50 /* Check RTC coredump section */
51 section_start = (uint32_t)&_coredump_rtc_start;
52 section_size = (uint8_t *)&_coredump_rtc_end - (uint8_t *)&_coredump_rtc_start;
53 TEST_ASSERT(section_size > 0);
54 TEST_ASSERT(is_addr_in_region(&var_rtc, (uint8_t*) section_start, section_size));
55 /* Check RTC Fast coredump section */
56 section_start = (uint32_t)&_coredump_rtc_fast_start;
57 section_size = (uint8_t *)&_coredump_rtc_fast_end - (uint8_t *)&_coredump_rtc_fast_start;
58 TEST_ASSERT(section_size > 0);
59 TEST_ASSERT(is_addr_in_region(&var_rtcfast, (uint8_t*) section_start, section_size));
60 }
61