test_system_time.c 898 B

123456789101112131415161718192021222324252627282930313233343536
  1. #include <stdio.h>
  2. #include "unity.h"
  3. #include "esp_private/system_internal.h"
  4. #if CONFIG_IDF_TARGET_ESP32
  5. #include "esp32/clk.h"
  6. #elif CONFIG_IDF_TARGET_ESP32S2
  7. #include "esp32s2/clk.h"
  8. #elif CONFIG_IDF_TARGET_ESP32S3
  9. #include "esp32s3/clk.h"
  10. #elif CONFIG_IDF_TARGET_ESP32C3
  11. #include "esp32c3/clk.h"
  12. #endif
  13. TEST_CASE("Test effect of rtc clk calibration compensation on system time", "[esp_system]")
  14. {
  15. uint32_t prev_cal = esp_clk_slowclk_cal_get();
  16. int64_t t1 = esp_system_get_time();
  17. // Modify calibration value
  18. esp_clk_slowclk_cal_set(prev_cal/2);
  19. // Internally, the origin point of rtc clk has been adjusted
  20. // so that t2 > t1 remains true
  21. int64_t t2 = esp_system_get_time();
  22. TEST_ASSERT_GREATER_THAN(t1, t2);
  23. // Restore calibration value
  24. esp_clk_slowclk_cal_set(prev_cal);
  25. t2 = esp_system_get_time();
  26. TEST_ASSERT_GREATER_THAN(t1, t2);
  27. }