1 #include "unity.h"
2 #include "esp_attr.h"
3 #include "esp_log.h"
4 #include "soc/soc.h"
5 
6 static __NOINIT_ATTR uint32_t s_noinit;
7 static RTC_NOINIT_ATTR uint32_t s_rtc_noinit;
8 static RTC_DATA_ATTR uint32_t s_rtc_data;
9 static RTC_RODATA_ATTR uint32_t s_rtc_rodata;
10 static RTC_FAST_ATTR uint32_t s_rtc_force_fast;
11 static RTC_SLOW_ATTR uint32_t s_rtc_force_slow;
12 
13 extern int _rtc_noinit_start;
14 extern int _rtc_noinit_end;
15 extern int _rtc_data_start;
16 extern int _rtc_data_end;
17 extern int _noinit_start;
18 extern int _noinit_end;
19 extern int _rtc_force_fast_start;
20 extern int _rtc_force_fast_end;
21 extern int _rtc_force_slow_start;
22 extern int _rtc_force_slow_end;
23 
24 
data_in_segment(void * ptr,int * seg_start,int * seg_end)25 static bool data_in_segment(void *ptr, int *seg_start, int *seg_end)
26 {
27     return ((intptr_t)ptr < (intptr_t)seg_end) && \
28            ((intptr_t)ptr >= (intptr_t)seg_start);
29 }
30 
31 TEST_CASE("Attributes place variables into correct sections", "[ld]")
32 {
33     TEST_ASSERT(data_in_segment(&s_noinit, &_noinit_start, &_noinit_end));
34     TEST_ASSERT(data_in_segment(&s_rtc_noinit, &_rtc_noinit_start, &_rtc_noinit_end));
35     TEST_ASSERT(data_in_segment(&s_rtc_data, &_rtc_data_start, &_rtc_data_end));
36     TEST_ASSERT(data_in_segment(&s_rtc_rodata, &_rtc_data_start, &_rtc_data_end));
37     TEST_ASSERT(data_in_segment(&s_rtc_force_fast, &_rtc_force_fast_start, &_rtc_force_fast_end));
38     TEST_ASSERT(data_in_segment(&s_rtc_force_slow, &_rtc_force_slow_start, &_rtc_force_slow_end));
39 
40 #if CONFIG_ESP32_RTCDATA_IN_FAST_MEM   || \
41     CONFIG_ESP32S2_RTCDATA_IN_FAST_MEM || \
42     CONFIG_ESP32S3_RTCDATA_IN_FAST_MEM || \
43     CONFIG_ESP32C3_RTCDATA_IN_FAST_MEM
44     TEST_ASSERT(data_in_segment(&s_rtc_data, (int*) SOC_RTC_DRAM_LOW, (int*) SOC_RTC_DRAM_HIGH));
45     TEST_ASSERT(data_in_segment(&s_rtc_rodata, (int*) SOC_RTC_DRAM_LOW, (int*) SOC_RTC_DRAM_HIGH));
46     TEST_ASSERT(data_in_segment(&s_rtc_noinit, (int*) SOC_RTC_DRAM_LOW, (int*) SOC_RTC_DRAM_HIGH));
47 #else
48     TEST_ASSERT(data_in_segment(&s_rtc_data, (int*) SOC_RTC_DATA_LOW, (int*) SOC_RTC_DATA_HIGH));
49     TEST_ASSERT(data_in_segment(&s_rtc_rodata, (int*) SOC_RTC_DATA_LOW, (int*) SOC_RTC_DATA_HIGH));
50     TEST_ASSERT(data_in_segment(&s_rtc_noinit, (int*) SOC_RTC_DATA_LOW, (int*) SOC_RTC_DATA_HIGH));
51 #endif
52 
53     TEST_ASSERT(data_in_segment(&s_rtc_force_fast, (int*) SOC_RTC_DRAM_LOW, (int*) SOC_RTC_DRAM_HIGH));
54     TEST_ASSERT(data_in_segment(&s_rtc_force_slow, (int*) SOC_RTC_DATA_LOW, (int*) SOC_RTC_DATA_HIGH));
55 }
56