From 347b65df921341bde83a54309ad3be5e56e59d23 Mon Sep 17 00:00:00 2001 From: nirenjan Date: Thu, 11 Nov 2021 07:02:21 -0800 Subject: [PATCH] Override `time` from libc Prior to this change, there were spurious build failures seen in Github CI, especially on macOS builds, where one test out of ~2000 would fail randomly. After adding an option to display the diagnostics, it was determined that the failure was only in the tests that included the timestamp. This was because the time call was returning different values between `test_setup` and `pinelog_log_message`. Even though they may have been called milliseconds apart, the time skew was enough to have a 1 second difference between the two returned values. This change overrides the `time` method from libc, and returns a static value. With this change, CI should work fine regardless of how slow the tests run. --- test_pinelog.c | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/test_pinelog.c b/test_pinelog.c index bb2ec46..9faccb2 100644 --- a/test_pinelog.c +++ b/test_pinelog.c @@ -34,6 +34,12 @@ static FILE *observed_stream_r; static char expected_output[1024]; static size_t expected_len; +time_t time(time_t *p) +{ + // Override the time function from libc + return 1636671600; +} + static void test_case(const char *desc, bool test) { test_id++;