This repository has been archived on 2025-09-14. You can view files and clone it, but cannot push or open issues or pull requests.
Files
stellar-stellar/src/times/test/gtest_times.cpp

43 lines
1.2 KiB
C++

#include <gtest/gtest.h>
#include "times.h"
TEST(TIMES, TEST)
{
uint64_t last_sec = 0;
uint64_t last_msec = 0;
uint64_t curr_sec = 0;
uint64_t curr_msec = 0;
last_sec = stellar_get_monotonic_time_sec();
last_msec = stellar_get_monotonic_time_msec();
usleep(1000); // 1ms
curr_sec = stellar_get_monotonic_time_sec();
curr_msec = stellar_get_monotonic_time_msec();
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);
EXPECT_TRUE(curr_msec - last_msec >= 1);
usleep(1000 * 1000); // 1s
last_sec = curr_sec;
last_msec = curr_msec;
curr_sec = stellar_get_monotonic_time_sec();
curr_msec = stellar_get_monotonic_time_msec();
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);
EXPECT_TRUE(curr_msec - last_msec >= 1000);
}
int main(int argc, char **argv)
{
::testing::InitGoogleTest(&argc, argv);
return RUN_ALL_TESTS();
}