gnunet-svn
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

[GNUnet-SVN] r3284 - in GNUnet/src/util: cron disk threads


From: grothoff
Subject: [GNUnet-SVN] r3284 - in GNUnet/src/util: cron disk threads
Date: Sun, 20 Aug 2006 22:13:07 -0700 (PDT)

Author: grothoff
Date: 2006-08-20 22:13:02 -0700 (Sun, 20 Aug 2006)
New Revision: 3284

Modified:
   GNUnet/src/util/cron/Makefile.am
   GNUnet/src/util/disk/Makefile.am
   GNUnet/src/util/disk/storagetest.c
   GNUnet/src/util/threads/Makefile.am
   GNUnet/src/util/threads/pthread.c
   GNUnet/src/util/threads/semaphoretest.c
   GNUnet/src/util/threads/shutdowntest.c
   GNUnet/src/util/threads/time.c
   GNUnet/src/util/threads/timertest.c
Log:
makeing some check targets work

Modified: GNUnet/src/util/cron/Makefile.am
===================================================================
--- GNUnet/src/util/cron/Makefile.am    2006-08-21 04:29:15 UTC (rev 3283)
+++ GNUnet/src/util/cron/Makefile.am    2006-08-21 05:13:02 UTC (rev 3284)
@@ -11,7 +11,8 @@
  $(top_builddir)/src/util/libgnunetutil.la  
 
 check_PROGRAMS = \
- crontest
+ crontest \
+ timertest
 
 TESTS = $(check_PROGRAMS)
 
@@ -20,3 +21,10 @@
 crontest_LDADD = \
  $(top_builddir)/src/util/libgnunetutil.la  
 
+
+
+timertest_SOURCES = \
+ timertest.c
+timertest_LDADD = \
+ $(top_builddir)/src/util/libgnunetutil.la  
+

Modified: GNUnet/src/util/disk/Makefile.am
===================================================================
--- GNUnet/src/util/disk/Makefile.am    2006-08-21 04:29:15 UTC (rev 3283)
+++ GNUnet/src/util/disk/Makefile.am    2006-08-21 05:13:02 UTC (rev 3284)
@@ -11,6 +11,8 @@
 check_PROGRAMS = \
  storagetest 
 
+TESTS = $(check_PROGRAMS)
+
 storagetest_SOURCES = \
  storagetest.c
 storagetest_LDADD = \

Modified: GNUnet/src/util/disk/storagetest.c
===================================================================
--- GNUnet/src/util/disk/storagetest.c  2006-08-21 04:29:15 UTC (rev 3283)
+++ GNUnet/src/util/disk/storagetest.c  2006-08-21 05:13:02 UTC (rev 3284)
@@ -1,5 +1,25 @@
+/*
+     This file is part of GNUnet.
+     (C) 2001, 2002, 2003, 2005, 2006 Christian Grothoff (and other 
contributing authors)
+
+     GNUnet is free software; you can redistribute it and/or modify
+     it under the terms of the GNU General Public License as published
+     by the Free Software Foundation; either version 2, or (at your
+     option) any later version.
+
+     GNUnet is distributed in the hope that it will be useful, but
+     WITHOUT ANY WARRANTY; without even the implied warranty of
+     MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
+     General Public License for more details.
+
+     You should have received a copy of the GNU General Public License
+     along with GNUnet; see the file COPYING.  If not, write to the
+     Free Software Foundation, Inc., 59 Temple Place - Suite 330,
+     Boston, MA 02111-1307, USA.
+*/
+
 /**
- * @file test/storagetest.c
+ * @file util/disk/storagetest.c
  * @brief testcase for the storage module
  * @author Christian Grothoff
  */
@@ -9,46 +29,40 @@
 
 #define TESTSTRING "Hello World\0"
 
-/**
- * Perform option parsing from the command line.
- */
-static int parseCommandLine(int argc,
-                           char * argv[]) {
-  return OK;
-}
-
 static int testReadWrite() {
-  HashCode512 ha;
-  EncName filename;
   char tmp[100];
 
-  hash(TESTSTRING,
-       strlen(TESTSTRING),
-       &ha);
-  hash2enc(&ha, &filename);
-  writeFile((char*)&filename, TESTSTRING, strlen(TESTSTRING), "644");
-  tmp[readFile((char*)&filename, 100, tmp)] = '\0';
-  if (memcmp(tmp,TESTSTRING,strlen(TESTSTRING)+1) == 0)
-    return 0;
-  else {
+  disk_file_write(NULL,
+                 ".testfile",
+                 TESTSTRING, 
+                 strlen(TESTSTRING), 
+                 "644");
+  tmp[disk_file_read(NULL,
+                    ".testfile",
+                    100, 
+                    tmp)] = '\0';
+  if (0 != memcmp(tmp,
+                 TESTSTRING,
+                 strlen(TESTSTRING)+1)) {
     fprintf(stderr,
            "Error in testReadWrite: *%s* != *%s* for file %s\n",
-           tmp,TESTSTRING,(char*)&filename);
+           tmp,
+           TESTSTRING,
+           ".testfile");
     return 1;
   }
+  UNLINK(".testfile");
+  return 0;
 }
 
 int main(int argc, char * argv[]) {
   int failureCount = 0;
 
-  initUtil(argc, argv, &parseCommandLine);
   failureCount += testReadWrite();
-  doneUtil();
-  if (failureCount == 0)
-    return 0;
-  else {
+  if (failureCount != 0) {
     fprintf(stderr,
             "\n\n%d TESTS FAILED!\n\n",failureCount);
     return -1;
   }
+  return 0;
 } /* end of main */

Modified: GNUnet/src/util/threads/Makefile.am
===================================================================
--- GNUnet/src/util/threads/Makefile.am 2006-08-21 04:29:15 UTC (rev 3283)
+++ GNUnet/src/util/threads/Makefile.am 2006-08-21 05:13:02 UTC (rev 3284)
@@ -16,6 +16,7 @@
 check_PROGRAMS = \
  semaphoretest \
  shutdowntest \
+ shutdowntest2 \
  timertest 
 
 TESTS = $(check_PROGRAMS)
@@ -30,6 +31,11 @@
 shutdowntest_LDADD = \
  $(top_builddir)/src/util/libgnunetutil.la  
 
+shutdowntest2_SOURCES = \
+ shutdowntest2.c
+shutdowntest2_LDADD = \
+ $(top_builddir)/src/util/libgnunetutil.la  
+
 timertest_SOURCES = \
  timertest.c
 timertest_LDADD = \

Modified: GNUnet/src/util/threads/pthread.c
===================================================================
--- GNUnet/src/util/threads/pthread.c   2006-08-21 04:29:15 UTC (rev 3283)
+++ GNUnet/src/util/threads/pthread.c   2006-08-21 05:13:02 UTC (rev 3284)
@@ -224,6 +224,7 @@
 #elif WINDOWS
   SleepEx(delay, TRUE);
 #else
+  printf("Select!\n");
   /* fall back to select */
   timeout.tv_sec
     = delay / CRON_UNIT_TO_SECONDS;

Modified: GNUnet/src/util/threads/semaphoretest.c
===================================================================
--- GNUnet/src/util/threads/semaphoretest.c     2006-08-21 04:29:15 UTC (rev 
3283)
+++ GNUnet/src/util/threads/semaphoretest.c     2006-08-21 05:13:02 UTC (rev 
3284)
@@ -1,6 +1,6 @@
 /*
      This file is part of GNUnet.
-     (C) 2001, 2002, 2003, 2004 Christian Grothoff (and other contributing 
authors)
+     (C) 2001, 2002, 2003, 2004, 2006 Christian Grothoff (and other 
contributing authors)
 
      GNUnet is free software; you can redistribute it and/or modify
      it under the terms of the GNU General Public License as published
@@ -18,7 +18,7 @@
      Boston, MA 02111-1307, USA.
 */
 /**
- * @file test/semaphore.c
+ * @file util/threads/semaphoretest.c
  * @brief testcase for util/threads/semaphore.c
  */
 
@@ -26,95 +26,89 @@
 #include "platform.h"
 
 #include <sys/types.h>
-#ifndef MINGW             /* PORT-ME MINGW */
 
+static struct MUTEX * lock;
 
-static Mutex lock;
+static struct SEMAPHORE * sem;
 
-static Semaphore * sem;
-
 static volatile int sv;
 
 static volatile int tv;
 
-static void lockIt() {
+static void * lockIt(void * unused) {
   sv = 0;
-  fprintf(stderr, ".");
   while (sv == 0)
     PTHREAD_SLEEP(50 * cronMILLIS); /* busy waiting may not always work */
-  MUTEX_LOCK(&lock);
+  MUTEX_LOCK(lock);
   sv = 1;
-  MUTEX_UNLOCK(&lock);
+  MUTEX_UNLOCK(lock);
   sv = 2;
   tv = 2;
+  return NULL;
 }
 
-static void bigStack() {
+static void * bigStack(void * unused) {
   int i;
   char big[1024 * 100];
 
-  fprintf(stderr, ".");
   for (i=0;i<1024*100;i++)
     big[i] = (char) i;
+  return NULL;
 }
 
 static int testPTHREAD_CREATE() {
-  PTHREAD_T pt;
+  struct PTHREAD * pt;
   void * unused;
 
   sv = -1; tv = 0;
-  fprintf(stderr, ".");
-  MUTEX_CREATE(&lock);
-  PTHREAD_CREATE(&pt,
-                (PThreadMain)&lockIt,
-                NULL,
-                1024);
-  PTHREAD_DETACH(&pt);
+  lock = MUTEX_CREATE(NO);
+  pt = PTHREAD_CREATE(&lockIt,
+                     NULL,
+                     1024);
   while (tv != 2) {
     sv = 1;
     PTHREAD_SLEEP(50 * cronMILLIS); /* busy waiting may not always work */
   }
-  MUTEX_DESTROY(&lock);
-  PTHREAD_CREATE(&pt,
-                (PThreadMain)&bigStack,
-                NULL,
-                1024*100 + 25000); /* fails by segfault */
-  PTHREAD_JOIN(&pt, &unused);
+  PTHREAD_JOIN(pt, &unused);
+  MUTEX_DESTROY(lock);
+  pt = PTHREAD_CREATE(&bigStack,
+                     NULL,
+                     1024*100 + 25000); /* fails by segfault */
+  PTHREAD_JOIN(pt, &unused);
   return 0;
 }
 
 static int testMutex() {
-  PTHREAD_T pt;
+  struct PTHREAD * pt;
   void * unused;
-  MUTEX_CREATE(&lock);
+  
+  lock = MUTEX_CREATE(NO);
 
   sv = 1;
   tv = 0;
-  PTHREAD_CREATE(&pt,
-                (PThreadMain)&lockIt,
-                NULL,
-                1024);
+  pt = PTHREAD_CREATE(&lockIt,
+                     NULL,
+                     1024);
   while (sv == 1)
     PTHREAD_SLEEP(50 * cronMILLIS); /* busy waiting may not always work */
-  MUTEX_LOCK(&lock);
+  MUTEX_LOCK(lock);
   sv = 5; /* release lockIt from while sv==0 loop,
             blocks it on lock */
-  fprintf(stderr, ".");
 
   if (sv != 5) {
-    MUTEX_UNLOCK(&lock);
+    MUTEX_UNLOCK(lock);
     while (tv != 2)
       PTHREAD_SLEEP(50 * cronMILLIS); /* busy waiting may not always work */
-    MUTEX_DESTROY(&lock);
+    MUTEX_DESTROY(lock);
     printf("MUTEX test failed at %s:%u\n",
           __FILE__, __LINE__);
     return 1; /* error */
   } else {
-    MUTEX_UNLOCK(&lock);
+    MUTEX_UNLOCK(lock);
     while (tv != 2)
       PTHREAD_SLEEP(50 * cronMILLIS); /* busy waiting may not always work */
-    PTHREAD_JOIN(&pt, &unused);
-    MUTEX_DESTROY(&lock);
+    PTHREAD_JOIN(pt, &unused);
+    MUTEX_DESTROY(lock);
     return 0; /* ok */
   }
 }
@@ -122,74 +116,70 @@
 static int testRecursiveMutex() {
   int i;
 
-  fprintf(stderr, ".");
-  MUTEX_CREATE_RECURSIVE(&lock);
+  lock = MUTEX_CREATE(YES);
   for (i=0;i<50;i++)
-    MUTEX_LOCK(&lock);
+    MUTEX_LOCK(lock);
   for (i=0;i<50;i++)
-    MUTEX_UNLOCK(&lock);
-  MUTEX_DESTROY(&lock);
+    MUTEX_UNLOCK(lock);
+  MUTEX_DESTROY(lock);
   return 0; /* ok -- fails by hanging!*/
 }
 
-static void semUpDown() {
+static void * semUpDown(void * unused) {
   int i;
 
-  fprintf(stderr, ".");
   for (i=0;i<42;i++)
-    SEMAPHORE_DOWN(sem); /* fails by blocking */
-  if (SEMAPHORE_DOWN_NONBLOCKING(sem) != SYSERR) {
+    SEMAPHORE_DOWN(sem, YES); /* fails by blocking */
+  if (SEMAPHORE_DOWN(sem, NO) != SYSERR) {
     SEMAPHORE_DESTROY(sem);
     printf("SEMAPHORE_DOWN_NONBLOCKING failed at %s:%u\n"
           "Testcase deadlocked.\n",
           __FILE__, __LINE__);
-    return; /* will halt testcase! */
+    return NULL; /* will halt testcase! */
   }
   for (i=0;i<42;i++)
     SEMAPHORE_UP(sem);
+  return NULL;
 }
 
 static int testSemaphore() {
   int i;
-  PTHREAD_T pt;
+  struct PTHREAD * pt;
   void * unused;
 
   sem = SEMAPHORE_CREATE(42);
-  fprintf(stderr, ".");
   for (i=0;i<42;i++)
-    SEMAPHORE_DOWN(sem); /* fails by blocking */
-  if (SEMAPHORE_DOWN_NONBLOCKING(sem) != SYSERR) {
+    SEMAPHORE_DOWN(sem, YES); /* fails by blocking */
+  if (SEMAPHORE_DOWN(sem, NO) != SYSERR) {
     SEMAPHORE_DESTROY(sem);
     printf("SEMAPHORE_DOWN_NONBLOCKING failed at %s:%u\n",
           __FILE__, __LINE__);
     return 1;
   }
-  for (i=0;i<42;i++)
+  for (i=0;i<42;i++) 
     SEMAPHORE_UP(sem);
   for (i=0;i<42;i++)
-    if (OK != SEMAPHORE_DOWN_NONBLOCKING(sem)) {
+    if (SYSERR == SEMAPHORE_DOWN(sem, NO)) {
       SEMAPHORE_DESTROY(sem);
-      printf("SEMAPHORE_DOWN_NONBLOCKING failed at %s:%u\n",
-            __FILE__, __LINE__);
+      printf("SEMAPHORE_DOWN_NONBLOCKING failed at %s:%u iteration %d\n",
+            __FILE__, __LINE__, i);
       return 1;
     }
-  if (SEMAPHORE_DOWN_NONBLOCKING(sem) != SYSERR) {
+  if (SEMAPHORE_DOWN(sem, NO) != SYSERR) {
     SEMAPHORE_DESTROY(sem);
     printf("SEMAPHORE_DOWN_NONBLOCKING failed at %s:%u\n",
           __FILE__, __LINE__);
     return 1;
   }
-  fprintf(stderr, ".");
-  PTHREAD_CREATE(&pt,
-                (PThreadMain)&semUpDown,
-                NULL,
-                1024);
+  pt = PTHREAD_CREATE(&semUpDown,
+                     NULL,
+                     1024);
   for (i=0;i<42;i++)
     SEMAPHORE_UP(sem);
-  PTHREAD_JOIN(&pt, &unused);
+  PTHREAD_JOIN(pt, &unused);
   for (i=0;i<42;i++)
-    SEMAPHORE_DOWN(sem);
-  if (SEMAPHORE_DOWN_NONBLOCKING(sem) != SYSERR) {
+    SEMAPHORE_DOWN(sem, YES);
+  if (SEMAPHORE_DOWN(sem, NO) != SYSERR) {
     SEMAPHORE_DESTROY(sem);
     printf("SEMAPHORE_DOWN_NONBLOCKING failed at %s:%u\n",
           __FILE__, __LINE__);
@@ -198,58 +188,13 @@
   return 0;
 }
 
-/**
- * Perform option parsing from the command line.
- */
-static int parseCommandLine(int argc,
-                           char * argv[]) {
-  char c;
-
-  while (1) {
-    int option_index = 0;
-    static struct GNoption long_options[] = {
-      { "loglevel",1, 0, 'L' },
-      { "config",  1, 0, 'c' },
-      { 0,0,0,0 }
-    };
-
-    c = GNgetopt_long(argc,
-                     argv,
-                     "c:L:",
-                     long_options,
-                     &option_index);
-
-    if (c == -1)
-      break;  /* No more flags to process */
-
-    switch(c) {
-    case 'L':
-      FREENONNULL(setConfigurationString("GNUNET",
-                                        "LOGLEVEL",
-                                        GNoptarg));
-      break;
-    case 'c':
-      FREENONNULL(setConfigurationString("FILES",
-                                        "gnunet.conf",
-                                        GNoptarg));
-      break;
-    } /* end of parsing commandline */
-  }
-  return OK;
-}
-#endif /* PORT-ME MINGW */
-
-int main(int argc, char * argv[]){
+int main(int argc, 
+        char * argv[]){
   int ret = 0;
 
-#ifndef MINGW
-  initUtil(argc, argv, &parseCommandLine);
   ret += testPTHREAD_CREATE();
   ret += testMutex();
   ret += testRecursiveMutex();
   ret += testSemaphore();
-  fprintf(stderr, "\n");
-  doneUtil();
-#endif
   return ret;
 }

Modified: GNUnet/src/util/threads/shutdowntest.c
===================================================================
--- GNUnet/src/util/threads/shutdowntest.c      2006-08-21 04:29:15 UTC (rev 
3283)
+++ GNUnet/src/util/threads/shutdowntest.c      2006-08-21 05:13:02 UTC (rev 
3284)
@@ -1,94 +1,47 @@
+/*
+     This file is part of GNUnet.
+     (C) 2001, 2002, 2003, 2004, 2006 Christian Grothoff (and other 
contributing authors)
+
+     GNUnet is free software; you can redistribute it and/or modify
+     it under the terms of the GNU General Public License as published
+     by the Free Software Foundation; either version 2, or (at your
+     option) any later version.
+
+     GNUnet is distributed in the hope that it will be useful, but
+     WITHOUT ANY WARRANTY; without even the implied warranty of
+     MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
+     General Public License for more details.
+
+     You should have received a copy of the GNU General Public License
+     along with GNUnet; see the file COPYING.  If not, write to the
+     Free Software Foundation, Inc., 59 Temple Place - Suite 330,
+     Boston, MA 02111-1307, USA.
+*/
+
 /**
- * @file test/shutdowntest.c
- * @brief testcase for util/shutdown.c
+ * @file util/threads/shutdowntest.c
+ * @brief testcase for util/threads/shutdown.c
  */
 
 #include "gnunet_util.h"
 #include "platform.h"
 
-static pid_t myPID;
-
 static int check() {
-  /* first, test / SIGINT (simulated) */
-  initializeShutdownHandlers();
-  if (testShutdown() != NO)
+  if (GNUNET_SHUTDOWN_TEST() != NO)
     return 1;
-#ifndef MINGW
-  kill(myPID, SIGINT);
-#else
-  GenerateConsoleCtrlEvent(CTRL_C_EVENT, 0);
-#endif
-  if (testShutdown() != YES)
+  GNUNET_SHUTDOWN_INITIATE();
+  if (GNUNET_SHUTDOWN_TEST() != YES)
     return 2;
-  wait_for_shutdown();
-  doneShutdownHandlers();
-
-  /* now, test "run_shutdown" */
-  initializeShutdownHandlers();
-  if (testShutdown() != NO)
-    return 3;
-  run_shutdown(42);
-  if (testShutdown() != YES)
-    return 4;
-  wait_for_shutdown();
-  doneShutdownHandlers();
-
+  GNUNET_SHUTDOWN_WAITFOR();
   return 0;
 }
 
-
-/**
- * Perform option parsing from the command line.
- */
-static int parseCommandLine(int argc,
-                           char * argv[]) {
-  char c;
-
-  while (1) {
-    int option_index = 0;
-    static struct GNoption long_options[] = {
-      { "config",  1, 0, 'c' },
-      { 0,0,0,0 }
-    };
-
-    c = GNgetopt_long(argc,
-                     argv,
-                     "c:",
-                     long_options,
-                     &option_index);
-
-    if (c == -1)
-      break;  /* No more flags to process */
-
-    switch(c) {
-    case 'c':
-      FREENONNULL(setConfigurationString("FILES",
-                                        "gnunet.conf",
-                                        GNoptarg));
-      break;
-    } /* end of parsing commandline */
-  }
-  FREENONNULL(setConfigurationString("GNUNETD",
-                                    "LOGFILE",
-                                    NULL));
-  FREENONNULL(setConfigurationString("GNUNETD",
-                                    "LOGLEVEL",
-                                    "WARNING"));
-  return OK;
-}
-
 int main(int argc,
         char * argv[]){
   int ret;
 
-  myPID = getpid();
-  initUtil(argc, argv, &parseCommandLine);
-
   ret = check();
-  if (ret != 0)
-    fprintf(stderr,
-           "ERROR %d\n", ret);
-  doneUtil();
+
   return ret;
 }
 

Modified: GNUnet/src/util/threads/time.c
===================================================================
--- GNUnet/src/util/threads/time.c      2006-08-21 04:29:15 UTC (rev 3283)
+++ GNUnet/src/util/threads/time.c      2006-08-21 05:13:02 UTC (rev 3284)
@@ -42,5 +42,5 @@
 #else
   gettimeofday(&tv, NULL);
 #endif
-  return (((cron_t)tv.tv_sec) * 1000) + (tv.tv_usec / 1000 / 1000);
+  return (((cron_t)tv.tv_sec) * 1000) + (tv.tv_usec / 1000);
 }

Modified: GNUnet/src/util/threads/timertest.c
===================================================================
--- GNUnet/src/util/threads/timertest.c 2006-08-21 04:29:15 UTC (rev 3283)
+++ GNUnet/src/util/threads/timertest.c 2006-08-21 05:13:02 UTC (rev 3284)
@@ -1,6 +1,25 @@
+/*
+     This file is part of GNUnet.
+     (C) 2001, 2002, 2003, 2004, 2006 Christian Grothoff (and other 
contributing authors)
+
+     GNUnet is free software; you can redistribute it and/or modify
+     it under the terms of the GNU General Public License as published
+     by the Free Software Foundation; either version 2, or (at your
+     option) any later version.
+
+     GNUnet is distributed in the hope that it will be useful, but
+     WITHOUT ANY WARRANTY; without even the implied warranty of
+     MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
+     General Public License for more details.
+
+     You should have received a copy of the GNU General Public License
+     along with GNUnet; see the file COPYING.  If not, write to the
+     Free Software Foundation, Inc., 59 Temple Place - Suite 330,
+     Boston, MA 02111-1307, USA.
+*/
 /**
- * @file test/timertest.c
- * @brief testcase for util/timer.c; also measures how
+ * @file util/threads/timertest.c
+ * @brief testcase for util/threads/timer.c; also measures how
  *  precise the timers are.  Expect values between 10 and 20 ms on
  *  modern machines.
  */
@@ -10,10 +29,6 @@
 
 #define VERBOSE NO
 
-static void semaphore_up(Semaphore * sem) {
-  SEMAPHORE_UP(sem);
-}
-
 static int check() {
   cron_t now;
   cron_t last;
@@ -21,39 +36,33 @@
   TIME_T tlast;
   int i;
   unsigned long long cumDelta;
-  Semaphore * sem;
 
   /* test that time/cronTime are monotonically
      increasing;
      measure precision of sleep and report;
      test that sleep is interrupted by signals; */
   last = now = get_time();
-  if (last != now)
-    return 1;
-  tlast = TIME(&tnow);
-  if (tlast != tnow)
-    return 2;
   while (now == last)
     now = get_time();
+  if (now < last)
+    return 1;
+  tnow = tlast = TIME(NULL);
   while (tnow == tlast)
     tnow = TIME(NULL);
-  if (now < last)
-    return 3;
   if (tnow < tlast)
-    return 4;
+    return 2;
   cumDelta = 0;
 #define INCR 47
 #define MAXV 1500
   for (i=0;i<MAXV;i+=INCR) {
-    cronTime(&last);
-    if (0 != PTHREAD_SLEEP(cronMILLIS * i))
-      return 5;
+    last = get_time();
+    PTHREAD_SLEEP(cronMILLIS * i);
     now = get_time();
 #if VERBOSE
     fprintf(stderr,
-           "%4u ms requested, got: %4lld ms\n",
-           i / cronMILLIS,
-           (now - last) / cronMILLIS);
+           "%4llu ms requested, got: %4llu ms\n",
+           i * cronMILLIS,
+           (now - last));
 #endif
     if (last + cronMILLIS * i < now)
       cumDelta += (now - (last+cronMILLIS*i));
@@ -61,7 +70,7 @@
       cumDelta += ((last+cronMILLIS*i) - now);
   }
   FPRINTF(stdout,
-         "Sleep precision: %llu ms.  ",
+         "Sleep precision: %llu ms. ",
          cumDelta / cronMILLIS / (MAXV/INCR));
   if (cumDelta <= 10 * cronMILLIS * MAXV / INCR)
     fprintf(stdout,
@@ -75,107 +84,15 @@
   else
     fprintf(stdout,
            "Timer precision is acceptable.\n");
-
-  sem = SEMAPHORE_CREATE(0);
-
-  startCron();
-  cumDelta = 0;
-
-#define MAXV2 1500
-#define INCR2 113
-  for (i=50;i<MAXV2+50;i+=INCR2) {
-    cronTime(&last);
-    addCronJob((CronJob) &semaphore_up,
-              i * cronMILLIS,
-              0,
-              sem);
-    SEMAPHORE_DOWN(sem);
-    now = get_time();
-    if (now < last + i)
-      now = last + i - now;
-    else
-      now = now - (last + i);
-    cumDelta += now;
-#if VERBOSE
-    FPRINTF(stderr,
-           "Sleep interrupted by signal within %llu ms of deadline (intended 
delay: %d ms).\n",
-           now,
-           i);
-#endif
-  }
-  FPRINTF(stdout,
-         "Sleep interrupt precision is %llums. ",
-         cumDelta / (MAXV2/INCR2) );
-  if (cumDelta <= 10 * cronMILLIS * MAXV2 / INCR2)
-    fprintf(stdout,
-           "Timer precision is excellent.\n");
-  else if (cumDelta <= 50 * cronMILLIS * MAXV2 / INCR2) /* 50ms average 
deviation */
-    fprintf(stdout,
-           "Timer precision is good.\n");
-  else if (cumDelta > 250 * cronMILLIS * MAXV2 / INCR2)
-    fprintf(stdout,
-           "Timer precision is awful.\n");
-  else
-    fprintf(stdout,
-           "Timer precision is acceptable.\n");
-
-  stopCron();
-  SEMAPHORE_DESTROY(sem);
-
   return 0;
 }
 
-
-/**
- * Perform option parsing from the command line.
- */
-static int parseCommandLine(int argc,
-                           char * argv[]) {
-  char c;
-
-  while (1) {
-    int option_index = 0;
-    static struct GNoption long_options[] = {
-      { "config",  1, 0, 'c' },
-      { 0,0,0,0 }
-    };
-
-    c = GNgetopt_long(argc,
-                     argv,
-                     "c:",
-                     long_options,
-                     &option_index);
-
-    if (c == -1)
-      break;  /* No more flags to process */
-
-    switch(c) {
-    case 'c':
-      FREENONNULL(setConfigurationString("FILES",
-                                        "gnunet.conf",
-                                        GNoptarg));
-      break;
-    } /* end of parsing commandline */
-  }
-  FREENONNULL(setConfigurationString("GNUNETD",
-                                    "LOGFILE",
-                                    NULL));
-  FREENONNULL(setConfigurationString("GNUNETD",
-                                    "LOGLEVEL",
-                                    "WARNING"));
-  return OK;
-}
-
 int main(int argc,
         char * argv[]){
   int ret;
-  initUtil(argc, argv, &parseCommandLine);
 
   ret = check();
-  if (ret != 0)
-    fprintf(stderr,
-           "ERROR %d\n", ret);
-  doneUtil();
+
   return ret;
 }
 





reply via email to

[Prev in Thread] Current Thread [Next in Thread]