Skip to content

Fix and re-enable ctest desktop tests on x86 #1043

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 19 commits into from
Aug 8, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
19 commits
Select commit Hold shift + click to select a range
0ef9e17
MsToAbsoluteTimespecTest added
dconeybe Aug 5, 2022
b020310
enable unit tests for ubuntu x86
dconeybe Aug 5, 2022
d5fc8d3
specify --output-on-failure to ctest
dconeybe Aug 5, 2022
b3f2ee7
Patch in the MsToAbsoluteTimespec integer overflow fix
dconeybe Aug 5, 2022
53f8359
time_test.cc: Fix NormalizeTest on 32-bit platforms
dconeybe Aug 5, 2022
851df4b
time_test.cc: Replace printf with std::cout in GetTimestampEpochTest …
dconeybe Aug 5, 2022
7827651
time_test.cc: format code
dconeybe Aug 5, 2022
0c48250
server_values_test.cc: fix 32-bit flakiness in ServerTimestamp
dconeybe Aug 5, 2022
2fc3f3a
Merge remote-tracking branch 'origin/main' into MsToAbsoluteTimespecT…
dconeybe Aug 5, 2022
096a75e
server_values_test.cc: fix other uses of time() to work on 32-bit arc…
dconeybe Aug 5, 2022
8fc4827
desktop.yml: enable x86 unit tests on windows and macOS too
dconeybe Aug 5, 2022
c3afb6f
pthread_condvar.h: Fix ConditionVariable::TimedWait() on 32-bit platf…
dconeybe Aug 5, 2022
7fd70c0
pthread_condvar.h: delete the templated TimedWait() method since it's…
dconeybe Aug 5, 2022
41c2b87
desktop.yml: add --output-on-failure to ctest on windows/macos
dconeybe Aug 5, 2022
96bae2d
time_test.cc: clean up a confusing comment about tv_nsec's max value …
dconeybe Aug 5, 2022
f31cb1e
Add back the templated TimedWait() method since it is actually used.
dconeybe Aug 5, 2022
f21a633
Merge remote-tracking branch 'origin/dconeybe/ConditionVariableTimedW…
dconeybe Aug 6, 2022
da99323
desktop.yml: re-disable x86 tests on windows, cuz they're still broken
dconeybe Aug 6, 2022
b4dc432
time_test.cc: add back a blank line that was needlessly deleted
dconeybe Aug 6, 2022
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 3 additions & 4 deletions .github/workflows/desktop.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
13 changes: 3 additions & 10 deletions app/src/pthread_condvar.h
Original file line number Diff line number Diff line change
Expand Up @@ -58,18 +58,11 @@ class ConditionVariable {
// Returns true otherwise
template <class Predicate>
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, &current_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, &current_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.
Expand Down
6 changes: 0 additions & 6 deletions app/src/time.h
Original file line number Diff line number Diff line change
Expand Up @@ -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 +
Expand Down
21 changes: 5 additions & 16 deletions app/tests/time_test.cc
Original file line number Diff line number Diff line change
Expand Up @@ -18,23 +18,15 @@

#include <time.h>

#include <iostream>
#include <string>

#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;
Expand Down Expand Up @@ -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);
}
Expand Down
10 changes: 5 additions & 5 deletions database/tests/desktop/core/server_values_test.cc
Original file line number Diff line number Diff line change
Expand Up @@ -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<int64_t>(time(nullptr)) * 1000L;

Variant result = GenerateServerValues(0);

Expand All @@ -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<int64_t>(time(nullptr)) * 1000L;

Variant result = GenerateServerValues(5000);

Expand Down Expand Up @@ -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<int64_t>(time(nullptr)) * 1000L;
Variant timestamp = ServerTimestamp();
Variant server_values = GenerateServerValues(0);

Expand All @@ -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<int64_t>(time(nullptr)) * 1000L;
Variant nested_map_variant = std::map<Variant, Variant>{
std::make_pair("aaa", 100),
std::make_pair("bbb", 200),
Expand All @@ -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<int64_t>(time(nullptr)) * 1000L;
Variant merge(std::map<Variant, Variant>{
std::make_pair("aaa", 100),
std::make_pair("bbb", 200),
Expand Down