-draft of new low-level testing code structure
authorChristian Grothoff <christian@grothoff.org>
Sat, 5 May 2012 18:11:27 +0000 (18:11 +0000)
committerChristian Grothoff <christian@grothoff.org>
Sat, 5 May 2012 18:11:27 +0000 (18:11 +0000)
src/include/gnunet_testing_lib-new.h
src/testing/testing_new.c

index 0943d6d06ee99bc232f4c90d544ad9bd7f86f5a8..0121f4c52b70299c4f89289900e474c689595db0 100644 (file)
@@ -77,9 +77,12 @@ GNUNET_TESTING_system_create (const char *tmppath,
  * Free system resources.
  *
  * @param system system to be freed
+ * @param remove_paths should the 'tmppath' and all subdirectories
+ *        be removed (clean up on shutdown)?
  */
 void
-GNUNET_TESTING_system_destroy (struct GNUNET_TESTING_System *system);
+GNUNET_TESTING_system_destroy (struct GNUNET_TESTING_System *system,
+                              int remove_paths);
 
 
 /**
index cc341e0370539f5aaf493875299d471d107802c0..33065e954630b74b9863e830698455917a0a79ce 100644 (file)
  */
 struct GNUNET_TESTING_System
 {
+  /**
+   * Prefix (i.e. "/tmp/gnunet-testing/") we prepend to each
+   * SERVICEHOME. 
+   */
+  char *tmppath;
+
+  /**
+   * Bitmap where each TCP port that has already been reserved for
+   * some GNUnet peer is recorded.  Note that we additionally need to
+   * test if a port is already in use by non-GNUnet components before
+   * assigning it to a peer/service.  If we detect that a port is
+   * already in use, we also mark it in this bitmap.  So all the bits
+   * that are zero merely indicate ports that MIGHT be available for
+   * peers.
+   */
+  uint32_t reserved_tcp_ports[65536 / 32];
+
+  /**
+   * Bitmap where each UDP port that has already been reserved for
+   * some GNUnet peer is recorded.  Note that we additionally need to
+   * test if a port is already in use by non-GNUnet components before
+   * assigning it to a peer/service.  If we detect that a port is
+   * already in use, we also mark it in this bitmap.  So all the bits
+   * that are zero merely indicate ports that MIGHT be available for
+   * peers.
+   */
+  uint32_t reserved_udp_ports[65536 / 32];
+
+  /**
+   * Counter we use to make service home paths unique on this system;
+   * the full path consists of the tmppath and this number.  Each
+   * UNIXPATH for a peer is also modified to include the respective
+   * path counter to ensure uniqueness.  This field is incremented
+   * by one for each configured peer.  Even if peers are destroyed,
+   * we never re-use path counters.
+   */
+  uint32_t path_counter;
 };
 
 
@@ -47,6 +84,26 @@ struct GNUNET_TESTING_System
  */
 struct GNUNET_TESTING_Peer
 {
+
+  /**
+   * Path to the configuration file for this peer.
+   */
+  char *cfgfile;
+
+  /**
+   * Binary to be executed during 'GNUNET_TESTING_peer_start'.
+   * Typically 'gnunet-service-arm' (but can be set to a 
+   * specific service by 'GNUNET_TESTING_service_run' if
+   * necessary).
+   */ 
+  char *main_binary;
+  
+  /**
+   * Handle to the running binary of the service, NULL if the
+   * peer/service is currently not running.
+   */
+  struct GNUNET_OS_Process *main_process;
+
 };
 
 
@@ -73,14 +130,68 @@ GNUNET_TESTING_system_create (const char *tmppath,
  * Free system resources.
  *
  * @param system system to be freed
+ * @param remove_paths should the 'tmppath' and all subdirectories
+ *        be removed (clean up on shutdown)?
  */
 void
-GNUNET_TESTING_system_destroy (struct GNUNET_TESTING_System *system)
+GNUNET_TESTING_system_destroy (struct GNUNET_TESTING_System *system,
+                              int remove_paths)
+{
+  GNUNET_break (0);
+}
+
+
+/**
+ * Reserve a TCP or UDP port for a peer.
+ *
+ * @param system system to use for reservation tracking
+ * @param is_tcp GNUNET_YES for TCP ports, GNUNET_NO for UDP
+ * @return 0 if no free port was available
+ */
+// static 
+uint16_t 
+reserve_port (struct GNUNET_TESTING_System *system,
+             int is_tcp)
 {
   GNUNET_break (0);
+  return 0;
 }
 
 
+/**
+ * Release reservation of a TCP or UDP port for a peer
+ * (used during GNUNET_TESTING_peer_destroy).
+ *
+ * @param system system to use for reservation tracking
+ * @param is_tcp GNUNET_YES for TCP ports, GNUNET_NO for UDP
+ * @param port reserved port to release
+ */
+// static 
+void
+release_port (struct GNUNET_TESTING_System *system,
+             int is_tcp,
+             uint16_t port)
+{
+  GNUNET_break (0);
+}
+
+
+/**
+ * Reserve a SERVICEHOME path for a peer.
+ *
+ * @param system system to use for reservation tracking
+ * @return NULL on error, otherwise fresh unique path to use
+ *         as the servicehome for the peer
+ */
+// static 
+char *
+reserve_path (struct GNUNET_TESTING_System *system)
+{
+  GNUNET_break (0);
+  return NULL;
+}            
+
+
 /**
  * Testing includes a number of pre-created hostkeys for
  * faster peer startup.  This function can be used to
@@ -124,7 +235,11 @@ GNUNET_TESTING_hostkey_get (uint32_t key_number,
  */
 int
 GNUNET_TESTING_configuration_create (struct GNUNET_TESTING_System *system,
-                                    struct GNUNET_CONFIGURATION_Handle *cfg);
+                                    struct GNUNET_CONFIGURATION_Handle *cfg)
+{
+  GNUNET_break (0);
+  return GNUNET_SYSERR;
+}
 
 
 /**