test_system_time.c 955 B

1234567891011121314151617181920212223242526272829303132333435363738
  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. #elif CONFIG_IDF_TARGET_ESP32H2
  13. #include "esp32h2/clk.h"
  14. #endif
  15. TEST_CASE("Test effect of rtc clk calibration compensation on system time", "[esp_system]")
  16. {
  17. uint32_t prev_cal = esp_clk_slowclk_cal_get();
  18. int64_t t1 = esp_system_get_time();
  19. // Modify calibration value
  20. esp_clk_slowclk_cal_set(prev_cal/2);
  21. // Internally, the origin point of rtc clk has been adjusted
  22. // so that t2 > t1 remains true
  23. int64_t t2 = esp_system_get_time();
  24. TEST_ASSERT_GREATER_THAN(t1, t2);
  25. // Restore calibration value
  26. esp_clk_slowclk_cal_set(prev_cal);
  27. t2 = esp_system_get_time();
  28. TEST_ASSERT_GREATER_THAN(t1, t2);
  29. }