diff --git a/.github/workflows/desktop.yml b/.github/workflows/desktop.yml index 3d5c5073d..cacba1782 100644 --- a/.github/workflows/desktop.yml +++ b/.github/workflows/desktop.yml @@ -234,21 +234,20 @@ jobs: LANG: en_US run: | cd build - ctest --repeat until-pass:3 + ctest --repeat until-pass:3 --output-on-failure - name: Run unit tests (linux) # Linux exists as its own standalone execution step in order to invoke # platform-specific `ulimit` to enable crash collection. The ulimit # command must be invoked in same shell instance of that runs the # tests. - # TODO: Enable tests for x86 once they are all working - if: startsWith(matrix.os, 'ubuntu') && matrix.architecture != 'x86' + if: startsWith(matrix.os, 'ubuntu') env: LANG: en_US run: | ulimit -c unlimited cd build - sudo ctest --repeat until-pass:3 + sudo ctest --repeat until-pass:3 --output-on-failure - name: Prep bins for achive (linux) # Copies all of the binary files into one directory for ease in diff --git a/app/src/pthread_condvar.h b/app/src/pthread_condvar.h index b265500c1..e21807595 100644 --- a/app/src/pthread_condvar.h +++ b/app/src/pthread_condvar.h @@ -58,18 +58,11 @@ class ConditionVariable { // Returns true otherwise template bool TimedWait(pthread_mutex_t* lock, Predicate predicate, int milliseconds) { - timespec end_time, current_time; - clock_gettime(CLOCK_REALTIME, &end_time); - end_time.tv_nsec += milliseconds * kNanosecondsPerMillisecond; - int64_t end_time_ms = TimespecToMs(end_time); - NormalizeTimespec(&end_time); - - clock_gettime(CLOCK_REALTIME, ¤t_time); - int64_t current_time_ms = TimespecToMs(current_time); + int64_t end_time_ms = TimespecToMs(MsToAbsoluteTimespec(milliseconds)); + int64_t current_time_ms = TimespecToMs(MsToAbsoluteTimespec(0)); while (!predicate() && current_time_ms < end_time_ms) { TimedWait(lock, end_time_ms - current_time_ms); - clock_gettime(CLOCK_REALTIME, ¤t_time); - current_time_ms = TimespecToMs(current_time); + current_time_ms = TimespecToMs(MsToAbsoluteTimespec(0)); } // If time isn't up, AND the predicate is true, then we return true. // False otherwise. diff --git a/app/src/time.h b/app/src/time.h index a60bd7a3e..08f88d538 100644 --- a/app/src/time.h +++ b/app/src/time.h @@ -63,12 +63,6 @@ inline void Sleep(int64_t milliseconds) { } #if !FIREBASE_PLATFORM_WINDOWS -// Utility function for normalizing a timespec. -inline void NormalizeTimespec(timespec* t) { - t->tv_sec += t->tv_nsec / kNanosecondsPerSecond; - t->tv_nsec %= kNanosecondsPerSecond; -} - // Utility function, for converting a timespec struct into milliseconds. inline int64_t TimespecToMs(timespec tm) { return tm.tv_sec * firebase::internal::kMillisecondsPerSecond + diff --git a/app/tests/time_test.cc b/app/tests/time_test.cc index a2a2c0ea7..c2cd62643 100644 --- a/app/tests/time_test.cc +++ b/app/tests/time_test.cc @@ -18,23 +18,15 @@ #include +#include +#include + #include "gmock/gmock.h" #include "gtest/gtest.h" namespace { #ifndef WIN32 -// Test that the normalize function works, for timespecs -TEST(TimeTests, NormalizeTest) { - timespec t; - t.tv_sec = 2; - t.tv_nsec = firebase::internal::kNanosecondsPerSecond * 5.5; - firebase::internal::NormalizeTimespec(&t); - - EXPECT_EQ(t.tv_sec, 7); - EXPECT_EQ(t.tv_nsec, firebase::internal::kNanosecondsPerSecond * 0.5); -} - // Test the various conversions to and from timespecs. TEST(TimeTests, ConversionTests) { timespec t; @@ -97,11 +89,8 @@ TEST(TimeTests, GetTimestampEpochTest) { // Print out the epoch time so that we can verify the timestamp from the log // This is the easiest way to verify if the function works in all platform -#ifdef __linux__ - printf("%lu -> %lu (%ld)\n", start, end, error); -#else - printf("%llu -> %llu (%lld)\n", start, end, error); -#endif // __linux__ + std::cout << std::to_string(start) << " -> " << std::to_string(end) << " (" + << std::to_string(error) << ")" << std::endl; EXPECT_GE(end, start + 500); } diff --git a/database/tests/desktop/core/server_values_test.cc b/database/tests/desktop/core/server_values_test.cc index b0040c78b..c772869ac 100644 --- a/database/tests/desktop/core/server_values_test.cc +++ b/database/tests/desktop/core/server_values_test.cc @@ -37,7 +37,7 @@ TEST(ServerValues, ServerTimestamp) { } TEST(ServerValues, GenerateServerValues) { - int64_t current_time_ms = time(nullptr) * 1000; + int64_t current_time_ms = static_cast(time(nullptr)) * 1000L; Variant result = GenerateServerValues(0); @@ -50,7 +50,7 @@ TEST(ServerValues, GenerateServerValues) { } TEST(ServerValues, GenerateServerValuesWithTimeOffset) { - int64_t current_time_ms = time(nullptr) * 1000; + int64_t current_time_ms = static_cast(time(nullptr)) * 1000L; Variant result = GenerateServerValues(5000); @@ -160,7 +160,7 @@ TEST(ServerValues, ResolveDeferredValueNestedMap) { } TEST(ServerValues, ResolveDeferredValueTimestamp) { - int64_t current_time_ms = time(nullptr) * 1000; + int64_t current_time_ms = static_cast(time(nullptr)) * 1000L; Variant timestamp = ServerTimestamp(); Variant server_values = GenerateServerValues(0); @@ -171,7 +171,7 @@ TEST(ServerValues, ResolveDeferredValueTimestamp) { } TEST(ServerValues, ResolveDeferredValueSnapshot) { - int64_t current_time_ms = time(nullptr) * 1000; + int64_t current_time_ms = static_cast(time(nullptr)) * 1000L; Variant nested_map_variant = std::map{ std::make_pair("aaa", 100), std::make_pair("bbb", 200), @@ -196,7 +196,7 @@ TEST(ServerValues, ResolveDeferredValueSnapshot) { } TEST(ServerValues, ResolveDeferredValueMerge) { - int64_t current_time_ms = time(nullptr) * 1000; + int64_t current_time_ms = static_cast(time(nullptr)) * 1000L; Variant merge(std::map{ std::make_pair("aaa", 100), std::make_pair("bbb", 200),