Update pvcalarm test
authorKevin Klues <klueska@cs.berkeley.edu>
Wed, 4 Jun 2014 19:38:30 +0000 (12:38 -0700)
committerKevin Klues <klueska@cs.berkeley.edu>
Wed, 4 Jun 2014 19:45:49 +0000 (12:45 -0700)
Use pthread_lib_init() instead of uthread_lib_init(), which requires us
to set pthread_can_adjust_vcores to false.  Also, need to initalize
counts to 0, otherwise we miscount and break the timing loop early.

user/utest/pvcalarm.c

index b6283bb..2a5ce89 100644 (file)
@@ -1,53 +1,34 @@
 #include <utest.h>
-#include <vcore.h>
-#include <uthread.h>
-#include <event.h>
+#include <pthread.h>
 #include <pvcalarm.h>
 
 TEST_SUITE("PVCALARMS");
 
-void pvcalarm_vcore_entry()
-{
-       uint32_t vcoreid= vcore_id();
-
-       /* Drop back into main thread  for core 0 */
-       if (current_uthread) {
-               assert(vcoreid == 0);
-               run_current_uthread();
-       }
-
-       /* Other vcores get here, so enable notifs so they can get their alarm
-        * events */
-       enable_notifs(vcoreid);
-       while(1);
-}
-struct schedule_ops pvcalarm_sched_ops = {
-       .sched_entry = pvcalarm_vcore_entry,
-};
-struct schedule_ops *sched_ops = &pvcalarm_sched_ops;
-
 /* <--- Begin definition of test cases ---> */
 bool test_pvcalarms(void) {
        const int INTERVAL = 10000;
        const int ITERATIONS = 100;
-       int count[max_vcores() - num_vcores()];
+       int count[max_vcores()];
        void pvcalarm_callback()
        {
                __sync_fetch_and_add(&count[vcore_id()], 1);
        }
 
-       struct uthread dummy = {0};
-       uthread_lib_init(&dummy);
+       pthread_lib_init();
+       pthread_can_vcore_request(FALSE);
        vcore_request(max_vcores() - num_vcores());
+       for (int i=0; i<max_vcores(); i++)
+               count[i] = 0;
        
        uint64_t now, then;
        now = tsc2usec(read_tsc());
        enable_pvcalarms(PVCALARM_PROF, INTERVAL, pvcalarm_callback);
-       for (int i=0; i<num_vcores(); i++)
+       for (int i=0; i<max_vcores(); i++)
                while(count[i] < ITERATIONS)
                        cpu_relax();
        then = tsc2usec(read_tsc());
        disable_pvcalarms();
+
        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]));
        return true;