gnunet-svn
[Top][All Lists]
Advanced

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

[GNUnet-SVN] r26726 - in gnunet/src: include testbed


From: gnunet
Subject: [GNUnet-SVN] r26726 - in gnunet/src: include testbed
Date: Tue, 2 Apr 2013 18:54:35 +0200

Author: harsha
Date: 2013-04-02 18:54:35 +0200 (Tue, 02 Apr 2013)
New Revision: 26726

Added:
   gnunet/src/testbed/test_testbed_api_peers_manage_services.c
Modified:
   gnunet/src/include/gnunet_testbed_service.h
   gnunet/src/testbed/Makefile.am
   gnunet/src/testbed/gnunet-service-testbed.c
Log:
- test case for starting/stopping peer's services


Modified: gnunet/src/include/gnunet_testbed_service.h
===================================================================
--- gnunet/src/include/gnunet_testbed_service.h 2013-04-02 15:51:11 UTC (rev 
26725)
+++ gnunet/src/include/gnunet_testbed_service.h 2013-04-02 16:54:35 UTC (rev 
26726)
@@ -882,6 +882,30 @@
 
 
 /**
+ * Start or stop given service at a peer.  This should not be called to
+ * start/stop the peer's ARM service.  Use GNUNET_TESTBED_peer_start(),
+ * GNUNET_TESTBED_peer_stop() for starting/stopping peer's ARM service.  
Success
+ * or failure of the generated operation is signalled through the controller
+ * event callback and/or operation completion callback.
+ *
+ * @param op_cls the closure for the operation
+ * @param peer the peer whose service is to be started/stopped
+ * @param service_name the name of the service
+ * @param cb the operation completion callback
+ * @param cb_cls the closure for the operation completion callback
+ * @param start 1 to start the service; 0 to stop the service
+ * @return an operation handle; NULL upon error (peer not running)
+ */
+struct GNUNET_TESTBED_Operation *
+GNUNET_TESTBED_peer_manage_service (void *op_cls,
+                                    struct GNUNET_TESTBED_Peer *peer,
+                                    const char *service_name,
+                                    GNUNET_TESTBED_OperationCompletionCallback 
cb,
+                                    void *cb_cls,
+                                    unsigned int start);
+
+
+/**
  * Stops and destroys all peers.  Is equivalent of calling
  * GNUNET_TESTBED_peer_stop() and GNUNET_TESTBED_peer_destroy() on all peers,
  * except that the peer stop event and operation finished event corresponding 
to

Modified: gnunet/src/testbed/Makefile.am
===================================================================
--- gnunet/src/testbed/Makefile.am      2013-04-02 15:51:11 UTC (rev 26725)
+++ gnunet/src/testbed/Makefile.am      2013-04-02 16:54:35 UTC (rev 26726)
@@ -102,6 +102,7 @@
 
 check_PROGRAMS = \
   test_testbed_api_hosts \
+  test_gnunet_helper_testbed \
   test_testbed_api_controllerlink \
   test_testbed_api_2peers_1controller \
   test_testbed_api_3peers_3controllers \
@@ -111,7 +112,7 @@
   test_testbed_api_testbed_run \
   test_testbed_api_test \
   test_testbed_api_test_timeout \
-  test_gnunet_helper_testbed \
+  test_testbed_api_peers_manage_services \
   test_testbed_api_topology \
   test_testbed_api_topology_clique \
   test_testbed_api_testbed_run_topologyrandom \
@@ -139,6 +140,7 @@
   test_testbed_api_test \
   test_testbed_api_test_timeout \
   test_testbed_api_statistics \
+  test_testbed_api_peers_manage_services \
   test_testbed_api_topology \
   test_testbed_api_topology_clique \
   test_testbed_api_testbed_run_topologyrandom \
@@ -295,6 +297,12 @@
  $(top_builddir)/src/util/libgnunetutil.la \
  libgnunettestbed.la
 
+test_testbed_api_peers_manage_services_SOURCES = \
+ test_testbed_api_peers_manage_services.c
+test_testbed_api_peers_manage_services_LDADD = \
+ $(top_builddir)/src/util/libgnunetutil.la \
+ libgnunettestbed.la
+
 EXTRA_DIST = \
   test_testbed_api.conf \
   test_testbed_api_test_timeout.conf \

Modified: gnunet/src/testbed/gnunet-service-testbed.c
===================================================================
--- gnunet/src/testbed/gnunet-service-testbed.c 2013-04-02 15:51:11 UTC (rev 
26725)
+++ gnunet/src/testbed/gnunet-service-testbed.c 2013-04-02 16:54:35 UTC (rev 
26726)
@@ -25,6 +25,7 @@
  */
 
 #include "gnunet-service-testbed.h"
+#include "gnunet_arm_service.h"
 
 #include <zlib.h>
 
@@ -2137,7 +2138,7 @@
   }
   else
     send_operation_success_msg (mctx->client, mctx->op_id);
-  GNUNET_free (emsg);
+  GNUNET_free_non_null (emsg);
   cleanup_mctx (mctx);
 }
 

Copied: gnunet/src/testbed/test_testbed_api_peers_manage_services.c (from rev 
26722, gnunet/src/testbed/test_testbed_api_statistics.c)
===================================================================
--- gnunet/src/testbed/test_testbed_api_peers_manage_services.c                 
        (rev 0)
+++ gnunet/src/testbed/test_testbed_api_peers_manage_services.c 2013-04-02 
16:54:35 UTC (rev 26726)
@@ -0,0 +1,211 @@
+/*
+      This file is part of GNUnet
+      (C) 2008--2013 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 3, 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 testbed/test_testbed_api_peers_manage_services.c
+ * @brief testcase for testing GNUNET_TESTBED_peer_manage_service()
+ *          implementation
+ * @author Sree Harsha Totakura <address@hidden> 
+ */
+
+#include "platform.h"
+#include "gnunet_common.h"
+#include "gnunet_testbed_service.h"
+
+/**
+ * Number of peers we want to start
+ */
+#define NUM_PEERS 2
+
+/**
+ * The array of peers; we get them from the testbed
+ */
+static struct GNUNET_TESTBED_Peer **peers;
+
+/**
+ * Operation handle
+ */
+static struct GNUNET_TESTBED_Operation *op;
+
+/**
+ * dummy pointer
+ */
+static void *dummy_cls = (void *) 0xDEAD0001;
+
+/**
+ * Abort task identifier
+ */
+static GNUNET_SCHEDULER_TaskIdentifier abort_task;
+
+/**
+ * States in this test
+ */
+enum {
+
+  /**
+   * Test has just been initialized
+   */
+  STATE_INIT,
+
+  /**
+   * Peers have been started
+   */
+  STATE_PEERS_STARTED,
+  
+  /**
+   * statistics service went down
+   */
+  STATE_SERVICE_DOWN,
+
+  /**
+   * statistics service went up
+   */
+  STATE_SERVICE_UP,
+
+  /**
+   * Testing completed successfully
+   */
+  STATE_OK
+} state;
+
+/**
+ * Fail testcase
+ */
+#define FAIL_TEST(cond, ret) do {                               \
+    if (!(cond)) {                                              \
+      GNUNET_break(0);                                          \
+      if (GNUNET_SCHEDULER_NO_TASK != abort_task)               \
+        GNUNET_SCHEDULER_cancel (abort_task);                   \
+      abort_task = GNUNET_SCHEDULER_add_now (&do_abort, NULL);  \
+      ret;                                                      \
+    }                                                           \
+  } while (0)
+
+
+/**
+ * Abort task
+ *
+ * @param cls NULL
+ * @param tc scheduler task context
+ */
+static void
+do_abort (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc)
+{
+  GNUNET_log (GNUNET_ERROR_TYPE_ERROR, "Test timed out -- Aborting\n");
+  abort_task = GNUNET_SCHEDULER_NO_TASK;
+  if (NULL != op)
+  {  
+    GNUNET_TESTBED_operation_done (op);
+    op = NULL;
+  }
+  GNUNET_SCHEDULER_shutdown();
+}
+
+
+/**
+ * Callback to be called when an operation is completed
+ *
+ * @param cls the callback closure from functions generating an operation
+ * @param op the operation that has been finished
+ * @param emsg error message in case the operation has failed; will be NULL if
+ *          operation has executed successfully.
+ */
+static void
+op_comp_cb (void *cls,
+            struct GNUNET_TESTBED_Operation *op,
+            const char *emsg)
+{
+  FAIL_TEST (cls == dummy_cls, return);
+  FAIL_TEST (NULL == emsg, return);
+  GNUNET_TESTBED_operation_done (op);
+  op = NULL;
+  switch (state)
+  {
+  case STATE_PEERS_STARTED:
+    state = STATE_SERVICE_DOWN;
+    op = GNUNET_TESTBED_peer_manage_service (dummy_cls,
+                                             peers[1],
+                                             "statistics",
+                                             op_comp_cb,
+                                             dummy_cls,
+                                             1);
+    break;
+  case STATE_SERVICE_DOWN:
+    state = STATE_SERVICE_UP;
+    GNUNET_SCHEDULER_cancel (abort_task);
+    abort_task = GNUNET_SCHEDULER_NO_TASK;
+    state = STATE_OK;
+    GNUNET_SCHEDULER_shutdown ();
+    break;
+  default:
+    FAIL_TEST (0, return);
+  }
+}
+
+
+/**
+ * Signature of a main function for a testcase.
+ *
+ * @param cls closure
+ * @param num_peers number of peers in 'peers'
+ * @param peers_ handle to peers run in the testbed
+ * @param links_succeeded the number of overlay link connection attempts that
+ *          succeeded
+ * @param links_failed the number of overlay link connection attempts that
+ *          failed
+ */
+static void
+test_master (void *cls, unsigned int num_peers,
+             struct GNUNET_TESTBED_Peer **peers_,
+             unsigned int links_succeeded,
+             unsigned int links_failed)
+{
+  FAIL_TEST (NUM_PEERS == num_peers, return);
+  state = STATE_PEERS_STARTED;
+  peers = peers_;
+  op = GNUNET_TESTBED_peer_manage_service (dummy_cls,
+                                           peers[1],
+                                           "statistics",
+                                           op_comp_cb,
+                                           dummy_cls,
+                                           0);
+  FAIL_TEST (NULL != op, return);
+  abort_task = GNUNET_SCHEDULER_add_delayed (GNUNET_TIME_relative_multiply
+                                             (GNUNET_TIME_UNIT_MINUTES, 1),
+                                             &do_abort, NULL);
+}
+
+
+/**
+ * Main function
+ */
+int
+main (int argc, char **argv)
+{
+  state = STATE_INIT;
+  (void) GNUNET_TESTBED_test_run ("test_testbed_api_statistics",
+                                  "test_testbed_api_statistics.conf",
+                                  NUM_PEERS,
+                                  1LL, NULL, NULL,
+                                  &test_master, NULL);
+  if (STATE_OK != state)
+    return 1;
+  return 0;
+}




reply via email to

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