diff options
author | t3sserakt <t3ss@posteo.de> | 2021-08-17 19:57:12 +0200 |
---|---|---|
committer | t3sserakt <t3ss@posteo.de> | 2021-08-17 19:57:12 +0200 |
commit | 32a8c505c1fa27bb43c4e7c8d288566d51417f56 (patch) | |
tree | 0328fe50b6a099b5020fe6d1e01cbd6b96ecd18a /src/transport/test_transport_plugin_cmd_simple_send.c | |
parent | 1e063cd73452396778cf00127346b9b08a922317 (diff) | |
download | gnunet-32a8c505c1fa27bb43c4e7c8d288566d51417f56.tar.gz gnunet-32a8c505c1fa27bb43c4e7c8d288566d51417f56.zip |
- moved test code from testbed to testing
Diffstat (limited to 'src/transport/test_transport_plugin_cmd_simple_send.c')
-rw-r--r-- | src/transport/test_transport_plugin_cmd_simple_send.c | 194 |
1 files changed, 194 insertions, 0 deletions
diff --git a/src/transport/test_transport_plugin_cmd_simple_send.c b/src/transport/test_transport_plugin_cmd_simple_send.c new file mode 100644 index 000000000..c4f7fcfe3 --- /dev/null +++ b/src/transport/test_transport_plugin_cmd_simple_send.c | |||
@@ -0,0 +1,194 @@ | |||
1 | /* | ||
2 | This file is part of GNUnet | ||
3 | Copyright (C) 2021 GNUnet e.V. | ||
4 | |||
5 | GNUnet is free software: you can redistribute it and/or modify it | ||
6 | under the terms of the GNU Affero General Public License as published | ||
7 | by the Free Software Foundation, either version 3 of the License, | ||
8 | or (at your option) any later version. | ||
9 | |||
10 | GNUnet is distributed in the hope that it will be useful, but | ||
11 | WITHOUT ANY WARRANTY; without even the implied warranty of | ||
12 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU | ||
13 | Affero General Public License for more details. | ||
14 | |||
15 | You should have received a copy of the GNU Affero General Public License | ||
16 | along with this program. If not, see <http://www.gnu.org/licenses/>. | ||
17 | |||
18 | SPDX-License-Identifier: AGPL3.0-or-later | ||
19 | */ | ||
20 | |||
21 | /** | ||
22 | * @file testbed/plugin_cmd_simple_send.c | ||
23 | * @brief a plugin to provide the API for running test cases. | ||
24 | * @author t3sserakt | ||
25 | */ | ||
26 | #include "platform.h" | ||
27 | #include "gnunet_testing_ng_lib.h" | ||
28 | #include "gnunet_util_lib.h" | ||
29 | #include "gnunet_transport_application_service.h" | ||
30 | #include "transport-testing2.h" | ||
31 | #include "transport-testing-cmds.h" | ||
32 | |||
33 | /** | ||
34 | * Generic logging shortcut | ||
35 | */ | ||
36 | #define LOG(kind, ...) GNUNET_log (kind, __VA_ARGS__) | ||
37 | |||
38 | #define BASE_DIR "testdir" | ||
39 | |||
40 | struct GNUNET_MQ_MessageHandler *handlers; | ||
41 | |||
42 | unsigned int are_all_peers_started; | ||
43 | |||
44 | static int | ||
45 | check_test (void *cls, | ||
46 | const struct GNUNET_TRANSPORT_TESTING_TestMessage *message) | ||
47 | { | ||
48 | return GNUNET_OK; | ||
49 | } | ||
50 | |||
51 | static void | ||
52 | handle_test (void *cls, | ||
53 | const struct GNUNET_TRANSPORT_TESTING_TestMessage *message) | ||
54 | { | ||
55 | LOG (GNUNET_ERROR_TYPE_ERROR, | ||
56 | "message received\n"); | ||
57 | } | ||
58 | |||
59 | static int | ||
60 | check_test2 (void *cls, | ||
61 | const struct GNUNET_TRANSPORT_TESTING_TestMessage *message) | ||
62 | { | ||
63 | return GNUNET_OK; | ||
64 | } | ||
65 | |||
66 | static void | ||
67 | handle_test2 (void *cls, | ||
68 | const struct GNUNET_TRANSPORT_TESTING_TestMessage *message) | ||
69 | { | ||
70 | LOG (GNUNET_ERROR_TYPE_ERROR, | ||
71 | "message received\n"); | ||
72 | } | ||
73 | |||
74 | static void | ||
75 | all_peers_started () | ||
76 | { | ||
77 | are_all_peers_started = GNUNET_YES; | ||
78 | LOG (GNUNET_ERROR_TYPE_ERROR, | ||
79 | "setting are_all_peers_started: %d\n", | ||
80 | are_all_peers_started); | ||
81 | } | ||
82 | |||
83 | static void | ||
84 | start_testcase (TESTING_CMD_HELPER_write_cb write_message, char *router_ip, | ||
85 | char *node_ip, | ||
86 | char *m, | ||
87 | char *n, | ||
88 | char *local_m) | ||
89 | { | ||
90 | char *testdir; | ||
91 | char *cfgname; | ||
92 | |||
93 | GNUNET_asprintf (&cfgname, | ||
94 | "%s%s.conf", | ||
95 | "test_transport_api2_tcp_node", | ||
96 | n); | ||
97 | |||
98 | LOG (GNUNET_ERROR_TYPE_ERROR, | ||
99 | "plugin cfgname: %s\n", | ||
100 | cfgname); | ||
101 | |||
102 | LOG (GNUNET_ERROR_TYPE_ERROR, | ||
103 | "node ip: %s\n", | ||
104 | node_ip); | ||
105 | |||
106 | testdir = GNUNET_malloc (strlen (BASE_DIR) + strlen (m) + strlen (n) | ||
107 | + 1); | ||
108 | |||
109 | strcpy (testdir, BASE_DIR); | ||
110 | strcat (testdir, m); | ||
111 | strcat (testdir, n); | ||
112 | |||
113 | struct GNUNET_MQ_MessageHandler handlers[] = { | ||
114 | GNUNET_MQ_hd_var_size (test, | ||
115 | GNUNET_TRANSPORT_TESTING_SIMPLE_MTYPE, | ||
116 | struct GNUNET_TRANSPORT_TESTING_TestMessage, | ||
117 | NULL), | ||
118 | GNUNET_MQ_hd_var_size (test2, | ||
119 | GNUNET_TRANSPORT_TESTING_SIMPLE_MTYPE2, | ||
120 | struct GNUNET_TRANSPORT_TESTING_TestMessage, | ||
121 | NULL), | ||
122 | GNUNET_MQ_handler_end () | ||
123 | }; | ||
124 | |||
125 | struct GNUNET_TESTING_Command commands[] = { | ||
126 | GNUNET_TESTING_cmd_system_create ("system-create-1", | ||
127 | testdir), | ||
128 | GNUNET_TRANSPORT_cmd_start_peer ("start-peer-1", | ||
129 | "system-create-1", | ||
130 | m, | ||
131 | n, | ||
132 | local_m, | ||
133 | handlers, | ||
134 | cfgname), | ||
135 | GNUNET_TESTING_cmd_send_peer_ready ("send-peer-ready-1", | ||
136 | write_message), | ||
137 | GNUNET_TESTING_cmd_block_until_all_peers_started ("block-1", | ||
138 | &are_all_peers_started), | ||
139 | GNUNET_TRANSPORT_cmd_connect_peers ("connect-peers-1", | ||
140 | "start-peer-1", | ||
141 | "this is useless"), | ||
142 | GNUNET_TRANSPORT_cmd_send_simple ("send-simple-1", | ||
143 | m, | ||
144 | n, | ||
145 | (atoi (n) - 1) * atoi (local_m) + atoi ( | ||
146 | m), | ||
147 | "start-peer-1", | ||
148 | "this is useless"), | ||
149 | GNUNET_TESTING_cmd_local_test_finished ("local-test-finished-1", | ||
150 | write_message) | ||
151 | }; | ||
152 | |||
153 | GNUNET_TESTING_run (NULL, | ||
154 | commands, | ||
155 | GNUNET_TIME_UNIT_FOREVER_REL); | ||
156 | |||
157 | } | ||
158 | |||
159 | |||
160 | /** | ||
161 | * Entry point for the plugin. | ||
162 | * | ||
163 | * @param cls NULL | ||
164 | * @return the exported block API | ||
165 | */ | ||
166 | void * | ||
167 | libgnunet_test_transport_plugin_cmd_simple_send_init (void *cls) | ||
168 | { | ||
169 | struct GNUNET_TESTING_PluginFunctions *api; | ||
170 | |||
171 | api = GNUNET_new (struct GNUNET_TESTING_PluginFunctions); | ||
172 | api->start_testcase = &start_testcase; | ||
173 | api->all_peers_started = &all_peers_started; | ||
174 | return api; | ||
175 | } | ||
176 | |||
177 | |||
178 | /** | ||
179 | * Exit point from the plugin. | ||
180 | * | ||
181 | * @param cls the return value from #libgnunet_test_transport_plugin_block_test_init | ||
182 | * @return NULL | ||
183 | */ | ||
184 | void * | ||
185 | libgnunet_test_transport_plugin_cmd_simple_send_done (void *cls) | ||
186 | { | ||
187 | struct GNUNET_TESTING_PluginFunctions *api = cls; | ||
188 | |||
189 | GNUNET_free (api); | ||
190 | return NULL; | ||
191 | } | ||
192 | |||
193 | |||
194 | /* end of plugin_cmd_simple_send.c */ | ||