-test cases setup for lockmanager
authorSree Harsha Totakura <totakura@in.tum.de>
Thu, 26 Apr 2012 22:41:37 +0000 (22:41 +0000)
committerSree Harsha Totakura <totakura@in.tum.de>
Thu, 26 Apr 2012 22:41:37 +0000 (22:41 +0000)
src/include/gnunet_lockmanager_service.h
src/lockmanager/Makefile.am
src/lockmanager/gnunet-service-lockmanager.c
src/lockmanager/lockmanager.conf.in
src/lockmanager/lockmanager_api.c
src/lockmanager/test_lockmanager_api.c [new file with mode: 0644]
src/lockmanager/test_lockmanager_api.conf [new file with mode: 0644]

index 6f63fd529f15cb00493529053cebd247619089a1..daa910dc9030193147d3de4042b2050699d33b91 100644 (file)
@@ -35,6 +35,8 @@ extern "C"
 #endif
 #endif
 
+#include "gnunet_configuration_lib.h"
+
 /**
  * Opaque handle for the lockmanager service
  */
index d6e3a5e4eb417bd419de9ecd70a0a32860c7a132..f86ac72a51a086530ca18d89d456c6295cdbf944 100644 (file)
@@ -35,4 +35,20 @@ libgnunetlockmanager_la_LIBADD = \
   $(XLIB)
 libgnunetlockmanager_la_LDFLAGS = \
   $(GN_LIB_LDFLAGS) $(WINFLAGS) \
-  -version-info 0:0:0
\ No newline at end of file
+  -version-info 0:0:0
+
+check_PROGRAMS = \
+  test-lockmanager-api
+
+EXTRA_DIST = \
+  test_lockmanager_api.conf
+
+if ENABLE_TEST_RUN
+TESTS = $(check_PROGRAMS)
+endif
+
+test_lockmanager_api_SOURCES = \
+  test_lockmanager_api.c
+test_lockmanager_api_LDADD = \
+  $(top_builddir)/src/util/libgnunetutil.la \
+  libgnunetlockmanager.la
index 1c228cc3a9d45d594d4d4bf97f77611291c9e3c5..5735f65b14ea161c41d5bbbc8afed52383dcf526 100644 (file)
@@ -105,7 +105,7 @@ int main (int argc, char *const *argv)
 {
   int ret;
 
-  GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "main()\n");
+  LOG (GNUNET_ERROR_TYPE_DEBUG, "main()\n");
   ret = 
     (GNUNET_OK ==
      GNUNET_SERVICE_run (argc,
@@ -114,6 +114,6 @@ int main (int argc, char *const *argv)
                          GNUNET_SERVICE_OPTION_NONE,
                          &lockmanager_run,
                          NULL)) ? 0 : 1;
-  GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "main() END\n");
+  LOG (GNUNET_ERROR_TYPE_DEBUG, "main() END\n");
   return ret;
 }
index 6a91b3e25ff6f58a1ebedddca4279b0abc5d6177..75b9244dc66a3bcde8f5f35ab7ce520f2cc360ef 100644 (file)
@@ -4,7 +4,7 @@ AUTOSTART = YES
 HOSTNAME = localhost
 HOME = $SERVICEHOME
 CONFIG = $DEFAULTCONFIG
-BINARY = gnunet-service-lockmanger
+BINARY = gnunet-service-lockmanager
 ACCEPT_FROM = 127.0.0.1;
 ACCEPT_FROM6 = ::1;
 UNIXPATH = /tmp/gnunet-service-lockmanager.sock
index 311f43b0f9b7fed3ce2fe541c39ca79c7060b3fa..bfd06275c24cc8198d7119b7e7fe6273755fbc59 100644 (file)
@@ -130,7 +130,7 @@ handle_server_crash (void *cls,
                      const struct GNUNET_MessageHeader *msg)
 {
   LOG (GNUNET_ERROR_TYPE_DEBUG,
-       "Lockmanger service went down\n");
+       "Lockmanager service not available or went down\n");
 
 }
 
@@ -179,11 +179,13 @@ GNUNET_LOCKMANAGER_connect (const struct GNUNET_CONFIGURATION_Handle *cfg)
 {
   struct GNUNET_LOCKMANAGER_Handle *h;
 
+  LOG (GNUNET_ERROR_TYPE_DEBUG, "%s()\n", __func__);
   h = GNUNET_malloc (sizeof (struct GNUNET_LOCKMANAGER_Handle));
   h->conn = GNUNET_CLIENT_connect ("lockmanager", cfg);
   if (NULL == h->conn)
     {
       GNUNET_free (h);
+      LOG (GNUNET_ERROR_TYPE_DEBUG, "%s() END\n", __func__);
       return NULL;
     }
   
@@ -192,10 +194,13 @@ GNUNET_LOCKMANAGER_connect (const struct GNUNET_CONFIGURATION_Handle *cfg)
                          NULL,
                          GNUNET_TIME_UNIT_FOREVER_REL);
   
-  GNUNET_CLIENT_receive (h->conn,
-                         &handle_success,
-                         h,
-                         GNUNET_TIME_UNIT_FOREVER_REL);
+  /* FIXME: Assertions fail in client.c if trying to receive multiple messages */
+  /* GNUNET_CLIENT_receive (h->conn, */
+  /*                        &handle_success, */
+  /*                        h, */
+  /*                        GNUNET_TIME_UNIT_FOREVER_REL); */
+
+  LOG (GNUNET_ERROR_TYPE_DEBUG, "%s() END\n", __func__);
   return h;
 }
 
@@ -208,8 +213,10 @@ GNUNET_LOCKMANAGER_connect (const struct GNUNET_CONFIGURATION_Handle *cfg)
 void
 GNUNET_LOCKMANAGER_disconnect (struct GNUNET_LOCKMANAGER_Handle *handle)
 {
+  LOG (GNUNET_ERROR_TYPE_DEBUG, "%s()\n", __func__);
   GNUNET_CLIENT_disconnect (handle->conn);
   GNUNET_free (handle);
+  LOG (GNUNET_ERROR_TYPE_DEBUG, "%s() END\n", __func__);
 }
 
 
@@ -249,7 +256,7 @@ GNUNET_LOCKMANAGER_acquire_lock (struct GNUNET_LOCKMANAGER_Handle *handle,
   struct GNUNET_LOCKMANAGER_Message *msg;
   uint16_t msg_size;
   
-
+  LOG (GNUNET_ERROR_TYPE_DEBUG, "%s()\n", __func__);
   r = GNUNET_malloc (sizeof (struct GNUNET_LOCKMANAGER_LockingRequest));
   r->domain_name_length = strlen (domain_name) + 1;
   r->handle = handle;
@@ -271,6 +278,7 @@ GNUNET_LOCKMANAGER_acquire_lock (struct GNUNET_LOCKMANAGER_Handle *handle,
                                          GNUNET_NO,
                                          *transmit_notify,
                                          msg);
+  LOG (GNUNET_ERROR_TYPE_DEBUG, "%s() END\n", __func__);
   return r;
 }
 
@@ -288,6 +296,7 @@ void
 GNUNET_LOCKMANAGER_cancel_request (struct GNUNET_LOCKMANAGER_LockingRequest
                                    *request)
 {
+  LOG (GNUNET_ERROR_TYPE_DEBUG, "%s()\n", __func__);
   /* FIXME: Stop ACQUIRE retransmissions */
   if (GNUNET_LOCKMANAGER_SUCCESS == request->status)
     {
@@ -309,5 +318,6 @@ GNUNET_LOCKMANAGER_cancel_request (struct GNUNET_LOCKMANAGER_LockingRequest
                                            &transmit_notify,
                                            msg);
     }
+    LOG (GNUNET_ERROR_TYPE_DEBUG, "%s() END\n", __func__);
   GNUNET_free (request);
 }
diff --git a/src/lockmanager/test_lockmanager_api.c b/src/lockmanager/test_lockmanager_api.c
new file mode 100644 (file)
index 0000000..144f7b4
--- /dev/null
@@ -0,0 +1,141 @@
+/*
+     This file is part of GNUnet.
+     (C) 2012 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 lockmanager/test_lockmanager_api.c
+ * @brief Test cases for lockmanager_api.c
+ * @author Sree Harsha Totakura
+ */
+
+#include "platform.h"
+#include "gnunet_util_lib.h"
+#include "gnunet_lockmanager_service.h"
+
+#define VERBOSE 1
+
+#define VERBOSE_ARM 1
+
+#define LOG(kind,...) \
+  GNUNET_log_from (kind, "test-lockmanager-api",__VA_ARGS__)
+
+#define TIME_REL_SECONDS(min) \
+  GNUNET_TIME_relative_multiply (GNUNET_TIME_UNIT_SECONDS, min)
+
+/**
+ * The testing result
+ */
+static int result;
+
+/**
+ * The process id of the GNUNET ARM process
+ */
+static struct GNUNET_OS_Process *arm_pid = NULL;
+
+/**
+ * Configuration Handle
+ */
+struct GNUNET_CONFIGURATION_Handle *config;
+
+/**
+ * Testing function
+ *
+ * @param cls NULL
+ * @param tc the task context
+ */
+static void
+test (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc)
+{  
+  struct GNUNET_LOCKMANAGER_Handle *handle;
+
+  handle = GNUNET_LOCKMANAGER_connect (config);
+  GNUNET_assert (NULL != handle);
+  
+  GNUNET_LOCKMANAGER_disconnect (handle);
+  if (0 != GNUNET_OS_process_kill (arm_pid, SIGTERM))
+    {
+      LOG (GNUNET_ERROR_TYPE_DEBUG,
+           "Kill gnunet-service-arm manually\n");
+    }
+  GNUNET_OS_process_wait (arm_pid);
+  GNUNET_OS_process_close (arm_pid);
+  result = GNUNET_OK;
+}
+
+
+/**
+ * Main point of test execution
+ */
+static void
+run (void *cls, char *const *args, const char *cfgfile,
+     const struct GNUNET_CONFIGURATION_Handle *cfg)
+{
+  config = GNUNET_CONFIGURATION_dup (cfg);
+  arm_pid = 
+    GNUNET_OS_start_process (GNUNET_YES, NULL, NULL, "gnunet-service-arm",
+                             "gnunet-service-arm",
+#if VERBOSE_ARM
+                             "-L", "DEBUG",
+#endif
+                             "-c", "test_lockmanager_api.conf", NULL);
+
+  GNUNET_assert (NULL != arm_pid);
+  GNUNET_SCHEDULER_add_delayed (TIME_REL_SECONDS (1),
+                                &test,
+                                NULL);
+}
+
+
+/**
+ * Main function
+ */
+int main (int argc, char **argv)
+{
+  int ret;
+
+  char *const argv2[] = { "test-lockmanager-api",
+                          "-c", "test_lockmanager_api.conf",
+#if VERBOSE
+                          "-L", "DEBUG",
+#endif
+                          NULL
+  };
+  
+  struct GNUNET_GETOPT_CommandLineOption options[] = {
+    GNUNET_GETOPT_OPTION_END
+  };
+
+  ret =
+    GNUNET_PROGRAM_run ((sizeof (argv2) / sizeof (char *)) - 1, argv2,
+                        "test-lockmanager-api", "nohelp", options, &run, NULL);
+
+  if (GNUNET_OK != ret)
+  {
+    GNUNET_log (GNUNET_ERROR_TYPE_WARNING, "run failed with error code %d\n",
+                ret);
+    return 1;
+  }
+  if (GNUNET_SYSERR == result)
+  {
+    GNUNET_log (GNUNET_ERROR_TYPE_WARNING, "test failed\n");
+    return 1;
+  }
+  GNUNET_log (GNUNET_ERROR_TYPE_INFO, "test ok\n");
+  return 0;
+}
diff --git a/src/lockmanager/test_lockmanager_api.conf b/src/lockmanager/test_lockmanager_api.conf
new file mode 100644 (file)
index 0000000..b6a2917
--- /dev/null
@@ -0,0 +1,73 @@
+[lockmanager]
+DEBUG = YES
+AUTOSTART = YES
+PORT = 12112
+ACCEPT_FROM = 127.0.0.1;
+HOSTNAME = localhost
+# PREFIX = valgrind --leak-check=full
+# PREFIX = xterm -geometry 100x85 -T peer1 -e gdb --args
+
+[fs]
+AUTOSTART = NO
+
+[resolver]
+AUTOSTART = NO
+
+[mesh]
+AUTOSTART = NO
+
+[dht]
+AUTOSTART = NO
+
+[block]
+plugins = dht test
+
+[dhtcache]
+QUOTA = 1 MB
+DATABASE = sqlite
+
+[transport]
+PLUGINS = tcp
+DEBUG = NO
+ACCEPT_FROM6 = ::1;
+ACCEPT_FROM = 127.0.0.1;
+NEIGHBOUR_LIMIT = 50
+PORT = 12365
+
+[ats]
+WAN_QUOTA_OUT = 3932160
+WAN_QUOTA_IN = 3932160
+
+[core]
+PORT = 12092
+
+[arm]
+DEFAULTSERVICES = core lockmanager
+PORT = 12366
+DEBUG = NO
+
+[transport-tcp]
+TIMEOUT = 300 s
+PORT = 12368
+
+[TESTING]
+NUM_PEERS = 5
+WEAKRANDOM = YES
+DEBUG = YES
+HOSTKEYSFILE = ../../contrib/testing_hostkeys.dat
+MAX_CONCURRENT_SSH = 10
+USE_PROGRESSBARS = YES
+PEERGROUP_TIMEOUT = 2400 s
+
+[gnunetd]
+HOSTKEY = $SERVICEHOME/.hostkey
+
+[PATHS]
+DEFAULTCONFIG = test_lockmanager_api.conf
+SERVICEHOME = /tmp/test-lockmanager/
+
+[dns]
+AUTOSTART = NO
+
+[nse]
+AUTOSTART = NO