浏览代码

esp32/test: add spiram noinit test case

Devan Lai 6 年之前
父节点
当前提交
a542f1b67d
共有 1 个文件被更改,包括 41 次插入0 次删除
  1. 41 0
      components/esp_common/test/test_attr.c

+ 41 - 0
components/esp_common/test/test_attr.c

@@ -2,6 +2,8 @@
 #include "esp_attr.h"
 #include "esp_log.h"
 #include "soc/soc.h"
+#include "esp_system.h"
+#include "esp32/spiram.h"
 
 static __NOINIT_ATTR uint32_t s_noinit;
 static RTC_NOINIT_ATTR uint32_t s_rtc_noinit;
@@ -53,3 +55,42 @@ TEST_CASE("Attributes place variables into correct sections", "[ld]")
     TEST_ASSERT(data_in_segment(&s_rtc_force_fast, (int*) SOC_RTC_DRAM_LOW, (int*) SOC_RTC_DRAM_HIGH));
     TEST_ASSERT(data_in_segment(&s_rtc_force_slow, (int*) SOC_RTC_DATA_LOW, (int*) SOC_RTC_DATA_HIGH));
 }
+
+
+#if CONFIG_SPIRAM_ALLOW_NOINIT_SEG_EXTERNAL_MEMORY
+
+#define TEST_BUFFER_SIZE (16*1024/4)
+static EXT_RAM_NOINIT_ATTR uint32_t s_noinit_buffer[TEST_BUFFER_SIZE];
+
+static void write_spiram_and_reset(void)
+{
+    // Fill the noinit buffer
+    printf("Filling buffer\n");
+    for (uint32_t i = 0; i < TEST_BUFFER_SIZE; i++) {
+        s_noinit_buffer[i] = i ^ 0x55555555U;
+    }
+    printf("Flushing cache\n");
+    // Flush the cache out to SPIRAM before resetting.
+    esp_spiram_writeback_cache();
+
+    printf("Restarting\n");
+    // Reset to test that noinit memory is left intact.
+    esp_restart();
+}
+
+static void check_spiram_contents(void)
+{
+    // Confirm that the memory contents are still what we expect
+    uint32_t error_count = 0;
+    for (uint32_t i = 0; i < TEST_BUFFER_SIZE; i++) {
+        if (s_noinit_buffer[i] != (i ^ 0x55555555U)) {
+            error_count++;
+        }
+    }
+    printf("Found %" PRIu32 " memory errors\n", error_count);
+    TEST_ASSERT(error_count == 0);
+}
+
+TEST_CASE_MULTIPLE_STAGES("Spiram test noinit memory", "[spiram]", write_spiram_and_reset, check_spiram_contents);
+
+#endif // CONFIG_SPIRAM_ALLOW_NOINIT_SEG_EXTERNAL_MEMORY