Add back timing selftest with new hardclock test
diff --git a/library/timing.c b/library/timing.c
index 4b29d7e..fe741b9 100644
--- a/library/timing.c
+++ b/library/timing.c
@@ -337,6 +337,25 @@
 #endif
 
 /*
+ * Busy-waits for the given number of milliseconds.
+ * Used for testing hardclock.
+ */
+static void busy_msleep( unsigned long msec )
+{
+    struct hr_time hires;
+    unsigned long i = 0; /* for busy-waiting */
+    volatile unsigned long j; /* to prevent optimisation */
+
+    (void) get_timer( &hires, 1 );
+
+    while( get_timer( &hires, 0 ) < msec )
+        i++;
+
+    j = i;
+    (void) j;
+}
+
+/*
  * Checkup routine
  *
  * Warning: this is work in progress, some tests may not be reliable enough
@@ -350,7 +369,7 @@
     struct hr_time hires;
 
     if( verbose != 0)
-        polarssl_printf( "  TIMING tests warning: will take some time!\n" );
+        polarssl_printf( "  TIMING tests note: will take some time!\n" );
 
     if( verbose != 0 )
         polarssl_printf( "  TIMING test #1 (m_sleep   / get_timer): " );
@@ -401,7 +420,7 @@
         polarssl_printf( "passed\n" );
 
     if( verbose != 0 )
-        polarssl_printf( "  TIMING test #3 (hardclock / m_sleep  ): " );
+        polarssl_printf( "  TIMING test #3 (hardclock / get_timer): " );
 
     /*
      * Allow one failure for possible counter wrapping.
@@ -420,15 +439,17 @@
     }
 
     /* Get a reference ratio cycles/ms */
+    millisecs = 1;
     cycles = hardclock();
-    m_sleep( 1 );
+    busy_msleep( millisecs );
     cycles = hardclock() - cycles;
-    ratio = cycles / 1;
+    ratio = cycles / millisecs;
 
+    /* Check that the ratio is mostly constant */
     for( millisecs = 2; millisecs <= 4; millisecs++ )
     {
         cycles = hardclock();
-        m_sleep( millisecs );
+        busy_msleep( millisecs );
         cycles = hardclock() - cycles;
 
         /* Allow variation up to 20% */
@@ -443,9 +464,6 @@
     if( verbose != 0 )
         polarssl_printf( "passed\n" );
 
-    if( verbose != 0 )
-        polarssl_printf( "\n" );
-
 #if defined(POLARSSL_NET_C)
     if( verbose != 0 )
         polarssl_printf( "  TIMING test #4 (net_usleep/ get_timer): " );
@@ -471,6 +489,9 @@
         polarssl_printf( "passed\n" );
 #endif /* POLARSSL_NET_C */
 
+    if( verbose != 0 )
+        polarssl_printf( "\n" );
+
     return( 0 );
 }