Fix up alarm and pvcalarm tests
authorKevin Klues <klueska@cs.berkeley.edu>
Tue, 10 Jun 2014 16:33:45 +0000 (09:33 -0700)
committerKevin Klues <klueska@cs.berkeley.edu>
Tue, 10 Jun 2014 16:36:28 +0000 (09:36 -0700)
It appears that qeum doesn't properly virtualize the tsc accross vcores,
so calling read_tsc() in a situation where our vcores are actually
multiplexed on top of a single underlying linux task results in
incorrect values. The assertions in these tests have been changed to
make sure that AT LEAST the amount of time we expect has passed in real
time, rather than relying on the time counted per vcore.

user/utest/alarm.c
user/utest/pvcalarm.c

index 8fcbf61..721d635 100644 (file)
@@ -28,7 +28,7 @@ bool test_alarm(void) {
        then = tsc2usec(read_tsc());
        unset_alarm(&waiter);
        UT_ASSERT_M("Alarms finished too soon", then > (now + INTERVAL*count));
-       UT_ASSERT_M("Alarms finished too late", then < (now + INTERVAL*(count+1)));
+       UT_ASSERT_M("Alarms finished too late", then < (now + 2*INTERVAL*count));
        return true;
 }
 
index c76324b..c562de3 100644 (file)
@@ -8,7 +8,7 @@ TEST_SUITE("PVCALARMS");
 /* <--- Begin definition of test cases ---> */
 bool test_pvcalarms(void) {
        const int INTERVAL = 10000;
-       const int ITERATIONS = 100;
+       const int ITERS = 100;
        int count[max_vcores()];
        void pvcalarm_callback()
        {
@@ -25,13 +25,13 @@ bool test_pvcalarms(void) {
        now = tsc2usec(read_tsc());
        enable_pvcalarms(PVCALARM_PROF, INTERVAL, pvcalarm_callback);
        for (int i=0; i<max_vcores(); i++)
-               while(count[i] < ITERATIONS)
+               while(count[i] < ITERS)
                        cpu_relax();
-       then = tsc2usec(read_tsc());
        disable_pvcalarms();
+       then = tsc2usec(read_tsc());
 
-       UT_ASSERT_M("Alarms finished too soon", then > (now + INTERVAL*count[0]));
-       UT_ASSERT_M("Alarms finished too late", then < (now + 2*INTERVAL*count[0]));
+       UT_ASSERT_M("Alarms finished too soon", then > (now + INTERVAL*ITERS));
+       UT_ASSERT_M("Alarms finished too late", then < (now + 2*INTERVAL*ITERS));
        return true;
 }