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

Change-Id: I1a79892ba3c934879a171789e0edb357277acae4
diff --git a/tests/CommonLibs/TimevalTest.cpp b/tests/CommonLibs/TimevalTest.cpp
index b4746f2..f579878 100644
--- a/tests/CommonLibs/TimevalTest.cpp
+++ b/tests/CommonLibs/TimevalTest.cpp
@@ -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");
 }
diff --git a/tests/CommonLibs/TimevalTest.ok b/tests/CommonLibs/TimevalTest.ok
index c97031d..a965a70 100644
--- a/tests/CommonLibs/TimevalTest.ok
+++ b/tests/CommonLibs/TimevalTest.ok
@@ -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