tests: Timeval: adapt to have reproducible output and enable autotest

Change-Id: I1a79892ba3c934879a171789e0edb357277acae4
This commit is contained in:
Pau Espin 2018-01-09 19:12:21 +01:00
parent 93d9b114b7
commit 2652f2bc39
3 changed files with 23 additions and 31 deletions

View File

@ -28,18 +28,31 @@
#include "Timeval.h"
#include <iostream>
#include <assert.h>
using namespace std;
int main(int argc, char *argv[])
{
Timeval then(10000);
cout << then.elapsed() << endl;
assert(then.elapsed() == -10000);
cerr << then << " elapsed: " << then.elapsed() << endl;
double then_seconds = then.seconds();
double last_now = Timeval().seconds();
long last_remaining = 10000;
int loops = 0;
while (!then.passed()) {
cout << "now: " << Timeval() << " then: " << then << " remaining: " << then.remaining() << endl;
double tnow = Timeval().seconds();
cerr << "now: " << tnow << " then: " << then << " remaining: " << then.remaining() << endl;
assert(last_now <= tnow && last_remaining >= then.remaining());
assert(then_seconds == then.seconds());
usleep(500000);
loops++;
}
cout << "now: " << Timeval() << " then: " << then << " remaining: " << then.remaining() << endl;
cerr << "now: " << Timeval() << " then: " << then << " remaining: " << then.remaining() << endl;
assert(then.remaining() <= 0);
assert(loops >= 18);
printf("Done\n");
}

View File

@ -1,22 +1 @@
-10000
now: 1515515602.357742 then: 1515515612.357710 remaining: 10000
now: 1515515602.857837 then: 1515515612.357710 remaining: 9500
now: 1515515603.357975 then: 1515515612.357710 remaining: 9000
now: 1515515603.858163 then: 1515515612.357710 remaining: 8500
now: 1515515604.358353 then: 1515515612.357710 remaining: 8000
now: 1515515604.858465 then: 1515515612.357710 remaining: 7500
now: 1515515605.358622 then: 1515515612.357710 remaining: 7000
now: 1515515605.858745 then: 1515515612.357710 remaining: 6499
now: 1515515606.358852 then: 1515515612.357710 remaining: 5999
now: 1515515606.859055 then: 1515515612.357710 remaining: 5499
now: 1515515607.359170 then: 1515515612.357710 remaining: 4999
now: 1515515607.859349 then: 1515515612.357710 remaining: 4499
now: 1515515608.359455 then: 1515515612.357710 remaining: 3999
now: 1515515608.859549 then: 1515515612.357710 remaining: 3499
now: 1515515609.359748 then: 1515515612.357710 remaining: 2998
now: 1515515609.859865 then: 1515515612.357710 remaining: 2498
now: 1515515610.360064 then: 1515515612.357710 remaining: 1998
now: 1515515610.860223 then: 1515515612.357710 remaining: 1498
now: 1515515611.360386 then: 1515515612.357710 remaining: 998
now: 1515515611.860592 then: 1515515612.357710 remaining: 498
now: 1515515612.360712 then: 1515515612.357710 remaining: -3
Done

View File

@ -32,11 +32,11 @@ AT_CLEANUP
#AT_CHECK([$abs_top_builddir/tests/CommonLibs/SocketsTest], [], [expout], [])
#AT_CLEANUP
#AT_SETUP([TimevalTest])
#AT_KEYWORDS([TimevalTest])
#cat $abs_srcdir/CommonLibs/TimevalTest.ok > expout
#AT_CHECK([$abs_top_builddir/tests/CommonLibs/TimevalTest], [], [expout], [])
#AT_CLEANUP
AT_SETUP([TimevalTest])
AT_KEYWORDS([TimevalTest])
cat $abs_srcdir/CommonLibs/TimevalTest.ok > expout
AT_CHECK([$abs_top_builddir/tests/CommonLibs/TimevalTest], [], [expout], [ignore])
AT_CLEANUP
AT_SETUP([VectorTest])
AT_KEYWORDS([VectorTest])