aboutsummaryrefslogtreecommitdiff
path: root/src/transport/test_transport_plugin_cmd_simple_send.c
diff options
context:
space:
mode:
Diffstat (limited to 'src/transport/test_transport_plugin_cmd_simple_send.c')
-rw-r--r--src/transport/test_transport_plugin_cmd_simple_send.c99
1 files changed, 80 insertions, 19 deletions
diff --git a/src/transport/test_transport_plugin_cmd_simple_send.c b/src/transport/test_transport_plugin_cmd_simple_send.c
index c4f7fcfe3..ac5c01075 100644
--- a/src/transport/test_transport_plugin_cmd_simple_send.c
+++ b/src/transport/test_transport_plugin_cmd_simple_send.c
@@ -37,10 +37,30 @@
37 37
38#define BASE_DIR "testdir" 38#define BASE_DIR "testdir"
39 39
40struct GNUNET_MQ_MessageHandler *handlers; 40/**
41 * The name for a specific test environment directory.
42 *
43 */
44char *testdir;
41 45
46/**
47 * The name for the configuration file of the specific node.
48 *
49 */
50char *cfgname;
51
52/**
53 * Flag indicating if all peers have been started.
54 *
55 */
42unsigned int are_all_peers_started; 56unsigned int are_all_peers_started;
43 57
58
59/**
60 * Function called to check a message of type GNUNET_TRANSPORT_TESTING_SIMPLE_MTYPE being
61 * received.
62 *
63 */
44static int 64static int
45check_test (void *cls, 65check_test (void *cls,
46 const struct GNUNET_TRANSPORT_TESTING_TestMessage *message) 66 const struct GNUNET_TRANSPORT_TESTING_TestMessage *message)
@@ -48,6 +68,12 @@ check_test (void *cls,
48 return GNUNET_OK; 68 return GNUNET_OK;
49} 69}
50 70
71
72/**
73 * Function called to handle a message of type GNUNET_TRANSPORT_TESTING_SIMPLE_MTYPE
74 * being received.
75 *
76 */
51static void 77static void
52handle_test (void *cls, 78handle_test (void *cls,
53 const struct GNUNET_TRANSPORT_TESTING_TestMessage *message) 79 const struct GNUNET_TRANSPORT_TESTING_TestMessage *message)
@@ -56,6 +82,12 @@ handle_test (void *cls,
56 "message received\n"); 82 "message received\n");
57} 83}
58 84
85
86/**
87 * Function called to check a message of type GNUNET_TRANSPORT_TESTING_SIMPLE_MTYPE2
88 * being received.
89 *
90 */
59static int 91static int
60check_test2 (void *cls, 92check_test2 (void *cls,
61 const struct GNUNET_TRANSPORT_TESTING_TestMessage *message) 93 const struct GNUNET_TRANSPORT_TESTING_TestMessage *message)
@@ -63,6 +95,12 @@ check_test2 (void *cls,
63 return GNUNET_OK; 95 return GNUNET_OK;
64} 96}
65 97
98
99/**
100 * Function called to handle a message of type GNUNET_TRANSPORT_TESTING_SIMPLE_MTYPE2
101 * being received.
102 *
103 */
66static void 104static void
67handle_test2 (void *cls, 105handle_test2 (void *cls,
68 const struct GNUNET_TRANSPORT_TESTING_TestMessage *message) 106 const struct GNUNET_TRANSPORT_TESTING_TestMessage *message)
@@ -71,6 +109,11 @@ handle_test2 (void *cls,
71 "message received\n"); 109 "message received\n");
72} 110}
73 111
112
113/**
114 * Callback to set the flag indicating all peers started. Will be called via the plugin api.
115 *
116 */
74static void 117static void
75all_peers_started () 118all_peers_started ()
76{ 119{
@@ -80,6 +123,17 @@ all_peers_started ()
80 are_all_peers_started); 123 are_all_peers_started);
81} 124}
82 125
126
127/**
128 * Function to start a local test case.
129 *
130 * @param write_message Callback to send a message to the master loop.
131 * @param router_ip Global address of the network namespace.
132 * @param node_ip Local address of a node i a network namespace.
133 * @param m The number of the node in a network namespace.
134 * @param n The number of the network namespace.
135 * @param local_m The number of nodes in a network namespace.
136 */
83static void 137static void
84start_testcase (TESTING_CMD_HELPER_write_cb write_message, char *router_ip, 138start_testcase (TESTING_CMD_HELPER_write_cb write_message, char *router_ip,
85 char *node_ip, 139 char *node_ip,
@@ -87,12 +141,9 @@ start_testcase (TESTING_CMD_HELPER_write_cb write_message, char *router_ip,
87 char *n, 141 char *n,
88 char *local_m) 142 char *local_m)
89{ 143{
90 char *testdir;
91 char *cfgname;
92 144
93 GNUNET_asprintf (&cfgname, 145 GNUNET_asprintf (&cfgname,
94 "%s%s.conf", 146 "test_transport_api2_tcp_node%s.conf",
95 "test_transport_api2_tcp_node",
96 n); 147 n);
97 148
98 LOG (GNUNET_ERROR_TYPE_ERROR, 149 LOG (GNUNET_ERROR_TYPE_ERROR,
@@ -103,12 +154,18 @@ start_testcase (TESTING_CMD_HELPER_write_cb write_message, char *router_ip,
103 "node ip: %s\n", 154 "node ip: %s\n",
104 node_ip); 155 node_ip);
105 156
106 testdir = GNUNET_malloc (strlen (BASE_DIR) + strlen (m) + strlen (n) 157 GNUNET_asprintf (&testdir,
158 "%s%s%s",
159 BASE_DIR,
160 m,
161 n);
162
163 /*testdir = GNUNET_malloc (strlen (BASE_DIR) + strlen (m) + strlen (n)
107 + 1); 164 + 1);
108 165
109 strcpy (testdir, BASE_DIR); 166 strcpy (testdir, BASE_DIR);
110 strcat (testdir, m); 167 strcat (testdir, m);
111 strcat (testdir, n); 168 strcat (testdir, n);*/
112 169
113 struct GNUNET_MQ_MessageHandler handlers[] = { 170 struct GNUNET_MQ_MessageHandler handlers[] = {
114 GNUNET_MQ_hd_var_size (test, 171 GNUNET_MQ_hd_var_size (test,
@@ -123,30 +180,32 @@ start_testcase (TESTING_CMD_HELPER_write_cb write_message, char *router_ip,
123 }; 180 };
124 181
125 struct GNUNET_TESTING_Command commands[] = { 182 struct GNUNET_TESTING_Command commands[] = {
126 GNUNET_TESTING_cmd_system_create ("system-create-1", 183 GNUNET_TESTING_cmd_system_create ("system-create",
127 testdir), 184 testdir),
128 GNUNET_TRANSPORT_cmd_start_peer ("start-peer-1", 185 GNUNET_TRANSPORT_cmd_start_peer ("start-peer",
129 "system-create-1", 186 "system-create",
130 m, 187 m,
131 n, 188 n,
132 local_m, 189 local_m,
133 handlers, 190 handlers,
134 cfgname), 191 cfgname),
135 GNUNET_TESTING_cmd_send_peer_ready ("send-peer-ready-1", 192 GNUNET_TESTING_cmd_send_peer_ready ("send-peer-ready",
136 write_message), 193 write_message),
137 GNUNET_TESTING_cmd_block_until_all_peers_started ("block-1", 194 GNUNET_TESTING_cmd_block_until_all_peers_started ("block",
138 &are_all_peers_started), 195 &are_all_peers_started),
139 GNUNET_TRANSPORT_cmd_connect_peers ("connect-peers-1", 196 GNUNET_TRANSPORT_cmd_connect_peers ("connect-peers",
140 "start-peer-1", 197 "start-peer"),
141 "this is useless"), 198 GNUNET_TRANSPORT_cmd_send_simple ("send-simple",
142 GNUNET_TRANSPORT_cmd_send_simple ("send-simple-1",
143 m, 199 m,
144 n, 200 n,
145 (atoi (n) - 1) * atoi (local_m) + atoi ( 201 (atoi (n) - 1) * atoi (local_m) + atoi (
146 m), 202 m),
147 "start-peer-1", 203 "start-peer"),
148 "this is useless"), 204 GNUNET_TRANSPORT_cmd_stop_peer ("stop-peer",
149 GNUNET_TESTING_cmd_local_test_finished ("local-test-finished-1", 205 "start-peer"),
206 GNUNET_TESTING_cmd_system_destroy ("system-destroy",
207 "system-create"),
208 GNUNET_TESTING_cmd_local_test_finished ("local-test-finished",
150 write_message) 209 write_message)
151 }; 210 };
152 211
@@ -187,6 +246,8 @@ libgnunet_test_transport_plugin_cmd_simple_send_done (void *cls)
187 struct GNUNET_TESTING_PluginFunctions *api = cls; 246 struct GNUNET_TESTING_PluginFunctions *api = cls;
188 247
189 GNUNET_free (api); 248 GNUNET_free (api);
249 GNUNET_free (testdir);
250 GNUNET_free (cfgname);
190 return NULL; 251 return NULL;
191} 252}
192 253