فهرست منبع

esp_system: test system time for rtc compensation

Renz Bagaporo 4 سال پیش
والد
کامیت
131bbbd5c4
1فایلهای تغییر یافته به همراه36 افزوده شده و 0 حذف شده
  1. 36 0
      components/esp_system/test/test_system_time.c

+ 36 - 0
components/esp_system/test/test_system_time.c

@@ -0,0 +1,36 @@
+#include <stdio.h>
+#include "unity.h"
+
+#include "esp_private/system_internal.h"
+
+#if CONFIG_IDF_TARGET_ESP32
+#include "esp32/clk.h"
+#elif CONFIG_IDF_TARGET_ESP32S2
+#include "esp32s2/clk.h"
+#elif CONFIG_IDF_TARGET_ESP32S3
+#include "esp32s3/clk.h"
+#elif CONFIG_IDF_TARGET_ESP32C3
+#include "esp32c3/clk.h"
+#endif
+
+TEST_CASE("Test effect of rtc clk calibration compensation on system time", "[esp_system]")
+{
+    uint32_t prev_cal = esp_clk_slowclk_cal_get();
+    int64_t t1 = esp_system_get_time();
+
+    // Modify calibration value
+    esp_clk_slowclk_cal_set(prev_cal/2);
+
+    // Internally, the origin point of rtc clk has been adjusted
+    // so that t2 > t1 remains true
+    int64_t t2 = esp_system_get_time();
+
+    TEST_ASSERT_GREATER_THAN(t1, t2);
+
+    // Restore calibration value
+    esp_clk_slowclk_cal_set(prev_cal);
+
+    t2 = esp_system_get_time();
+
+    TEST_ASSERT_GREATER_THAN(t1, t2);
+}