gnunet-svn
[Top][All Lists]
Advanced

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

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


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

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

Added:
   GNUnet/src/util/cron/timertest.c
   GNUnet/src/util/threads/shutdowntest2.c
Log:
makeing some check targets work

Added: GNUnet/src/util/cron/timertest.c
===================================================================
--- GNUnet/src/util/cron/timertest.c    2006-08-21 05:13:02 UTC (rev 3284)
+++ GNUnet/src/util/cron/timertest.c    2006-08-21 05:13:22 UTC (rev 3285)
@@ -0,0 +1,83 @@
+/*
+     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 util/cron/timertest.c
+ * @brief tests precision of timing for cron
+ */
+
+#include "gnunet_util.h"
+#include "platform.h"
+
+static void semaphore_up(void * ctx) {
+  struct SEMAPHORE * sem = ctx;
+  SEMAPHORE_UP(sem);
+}
+
+static int check() {
+  struct SEMAPHORE * sem;
+  unsigned long long cumDelta;
+  cron_t now;
+  cron_t last;
+
+  sem = SEMAPHORE_CREATE(0);
+
+  startCron();
+  cumDelta = 0;
+
+#define MAXV2 1500
+#define INCR2 113
+  for (i=50;i<MAXV2+50;i+=INCR2) {
+    last = get_time();
+    addCronJob(&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);


Property changes on: GNUnet/src/util/cron/timertest.c
___________________________________________________________________
Name: svn:eol-style
   + native

Added: GNUnet/src/util/threads/shutdowntest2.c
===================================================================
--- GNUnet/src/util/threads/shutdowntest2.c     2006-08-21 05:13:02 UTC (rev 
3284)
+++ GNUnet/src/util/threads/shutdowntest2.c     2006-08-21 05:13:22 UTC (rev 
3285)
@@ -0,0 +1,52 @@
+/*
+     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 util/threads/shutdowntest2.c
+ * @brief testcase for util/threads/shutdown.c
+ */
+
+#include "gnunet_util.h"
+#include "platform.h"
+
+static int check() {
+  if (GNUNET_SHUTDOWN_TEST() != NO)
+    return 1;
+#ifndef MINGW
+  kill(getpid(), SIGINT);
+#else
+  GenerateConsoleCtrlEvent(CTRL_C_EVENT, 0);
+#endif
+  if (GNUNET_SHUTDOWN_TEST() != YES)
+    return 2;
+  GNUNET_SHUTDOWN_WAITFOR();
+  return 0;
+}
+
+int main(int argc,
+        char * argv[]){
+  int ret;
+
+  ret = check();
+
+  return ret;
+}
+
+/* end of shutdowntest2.c */


Property changes on: GNUnet/src/util/threads/shutdowntest2.c
___________________________________________________________________
Name: svn:eol-style
   + native





reply via email to

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