This is merely a historical archive of years 2008-2021, before the migration to mailman3.
A maintained and still updated list archive can be found at https://lists.osmocom.org/hyperkitty/list/gerrit-log@lists.osmocom.org/.
Harald Welte gerrit-no-reply at lists.osmocom.orgHarald Welte has submitted this change and it was merged. ( https://gerrit.osmocom.org/12282 ) Change subject: TimevalTest: Make test deterministic with fake time ...................................................................... TimevalTest: Make test deterministic with fake time Change-Id: I74e577a0142fb6d1ef3630e02aff9910b191bff9 --- M tests/CommonLibs/TimevalTest.cpp 1 file changed, 18 insertions(+), 7 deletions(-) Approvals: Harald Welte: Looks good to me, approved Jenkins Builder: Verified diff --git a/tests/CommonLibs/TimevalTest.cpp b/tests/CommonLibs/TimevalTest.cpp index 61a92c9..b822982 100644 --- a/tests/CommonLibs/TimevalTest.cpp +++ b/tests/CommonLibs/TimevalTest.cpp @@ -31,34 +31,45 @@ #include <assert.h> #include <sys/time.h> +extern "C" { +#include <osmocom/core/timer.h> +} + using namespace std; int main(int argc, char *argv[]) { - long last_remaining = 10000; + + osmo_clock_override_enable(CLOCK_REALTIME, true); + + struct timespec *clk = osmo_clock_override_gettimespec(CLOCK_REALTIME); + clk->tv_sec = 0; + clk->tv_nsec = 1000; + + long last_remaining = 10000; /*10 sec */ Timeval then(last_remaining); assert(then.elapsed() == -last_remaining); cerr << then << " elapsed: " << then.elapsed() << endl; /* Check that last_remaining parameter affects setting time in the future */ - usleep(10000); + osmo_clock_override_add(CLOCK_REALTIME, 0, 10*1000*1000); double increased_time_secs = Timeval().seconds(); - assert(increased_time_secs <= then.seconds()); + assert(increased_time_secs < then.seconds()); struct timespec invariant_time = then.timespec(); int loops = 0; while (!then.passed()) { struct timespec tspecnow = then.timespec(); - cerr << "now: " << Timeval().seconds() << " then: " << then << " remaining: " << then.remaining() << endl; + cerr << "["<< loops << "] now: " << Timeval().seconds() << " then: " << then << " remaining: " << then.remaining() << endl; assert(last_remaining >= then.remaining()); assert(tspecnow.tv_sec == invariant_time.tv_sec && tspecnow.tv_nsec == invariant_time.tv_nsec); - usleep(500000); + osmo_clock_override_add(CLOCK_REALTIME, 0, 500000*1000); loops++; } cerr << "now: " << Timeval() << " then: " << then << " remaining: " << then.remaining() << endl; - assert(then.remaining() <= 0); - assert(loops >= 18); + assert(then.remaining() == -10); + assert(loops == 20); printf("Done\n"); } -- To view, visit https://gerrit.osmocom.org/12282 To unsubscribe, or for help writing mail filters, visit https://gerrit.osmocom.org/settings Gerrit-Project: osmo-trx Gerrit-Branch: master Gerrit-MessageType: merged Gerrit-Change-Id: I74e577a0142fb6d1ef3630e02aff9910b191bff9 Gerrit-Change-Number: 12282 Gerrit-PatchSet: 2 Gerrit-Owner: Pau Espin Pedrol <pespin at sysmocom.de> Gerrit-Reviewer: Harald Welte <laforge at gnumonks.org> Gerrit-Reviewer: Jenkins Builder (1000002) -------------- next part -------------- An HTML attachment was scrubbed... URL: <http://lists.osmocom.org/pipermail/gerrit-log/attachments/20181213/b89b6795/attachment.htm>