2023-12-13 18:31:10 +08:00
|
|
|
#include <gtest/gtest.h>
|
|
|
|
|
|
2024-05-16 10:13:43 +08:00
|
|
|
#include "times.h"
|
2023-12-13 18:31:10 +08:00
|
|
|
|
2024-05-16 10:13:43 +08:00
|
|
|
TEST(TIMES, TEST)
|
2023-12-13 18:31:10 +08:00
|
|
|
{
|
2024-03-15 15:36:26 +08:00
|
|
|
uint64_t last_sec = 0;
|
|
|
|
|
uint64_t last_msec = 0;
|
|
|
|
|
uint64_t curr_sec = 0;
|
|
|
|
|
uint64_t curr_msec = 0;
|
2023-12-13 18:31:10 +08:00
|
|
|
|
2024-05-16 10:13:43 +08:00
|
|
|
stellar_update_time_cache();
|
|
|
|
|
last_sec = stellar_get_monotonic_time_sec();
|
|
|
|
|
last_msec = stellar_get_monotonic_time_msec();
|
2023-12-13 18:31:10 +08:00
|
|
|
|
2024-03-15 15:36:26 +08:00
|
|
|
usleep(1000); // 1ms
|
2024-05-16 10:13:43 +08:00
|
|
|
stellar_update_time_cache();
|
|
|
|
|
curr_sec = stellar_get_monotonic_time_sec();
|
|
|
|
|
curr_msec = stellar_get_monotonic_time_msec();
|
2024-03-15 15:36:26 +08:00
|
|
|
printf("After usleep(1000)\n");
|
|
|
|
|
printf("last_sec: %lu, last_msec: %lu\n", last_sec, last_msec);
|
|
|
|
|
printf("curr_sec: %lu, curr_msec: %lu\n", curr_sec, curr_msec);
|
|
|
|
|
EXPECT_TRUE(curr_sec == last_sec);
|
2024-04-16 18:34:41 +08:00
|
|
|
EXPECT_TRUE(curr_msec - last_msec >= 1);
|
2024-03-15 15:36:26 +08:00
|
|
|
|
|
|
|
|
usleep(1000 * 1000); // 1s
|
2024-05-16 10:13:43 +08:00
|
|
|
stellar_update_time_cache();
|
2024-03-15 15:36:26 +08:00
|
|
|
last_sec = curr_sec;
|
|
|
|
|
last_msec = curr_msec;
|
2024-05-16 10:13:43 +08:00
|
|
|
curr_sec = stellar_get_monotonic_time_sec();
|
|
|
|
|
curr_msec = stellar_get_monotonic_time_msec();
|
2024-03-15 15:36:26 +08:00
|
|
|
printf("After usleep(1000 * 1000)\n");
|
|
|
|
|
printf("last_sec: %lu, last_msec: %lu\n", last_sec, last_msec);
|
|
|
|
|
printf("curr_sec: %lu, curr_msec: %lu\n", curr_sec, curr_msec);
|
|
|
|
|
EXPECT_TRUE(curr_sec - last_sec == 1);
|
2024-04-16 18:34:41 +08:00
|
|
|
EXPECT_TRUE(curr_msec - last_msec >= 1000);
|
2023-12-13 18:31:10 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
int main(int argc, char **argv)
|
|
|
|
|
{
|
|
|
|
|
::testing::InitGoogleTest(&argc, argv);
|
|
|
|
|
return RUN_ALL_TESTS();
|
|
|
|
|
}
|