aboutsummaryrefslogtreecommitdiff
path: root/src/dhtu
diff options
context:
space:
mode:
authorChristian Grothoff <christian@grothoff.org>2021-10-04 12:15:43 +0200
committerChristian Grothoff <christian@grothoff.org>2021-10-04 12:15:43 +0200
commitf146e80752e73247acb9d6c7463188a82d26a774 (patch)
tree13ed03d817ce04daa133507778ac6a1b71bf147f /src/dhtu
parent7ecc3a03a0670a1620c603502c9958b95e6dc1d0 (diff)
downloadgnunet-f146e80752e73247acb9d6c7463188a82d26a774.tar.gz
gnunet-f146e80752e73247acb9d6c7463188a82d26a774.zip
-taking a first stab at cleaning up the testing mess
Diffstat (limited to 'src/dhtu')
-rw-r--r--src/dhtu/Makefile.am15
-rw-r--r--src/dhtu/test_dhtu_ip.c39
-rw-r--r--src/dhtu/testing_dhtu_cmd_send.c170
3 files changed, 191 insertions, 33 deletions
diff --git a/src/dhtu/Makefile.am b/src/dhtu/Makefile.am
index 61ca84ee3..772bee60a 100644
--- a/src/dhtu/Makefile.am
+++ b/src/dhtu/Makefile.am
@@ -41,6 +41,21 @@ libgnunet_plugin_dhtu_gnunet_la_LDFLAGS = \
41 $(GN_PLUGIN_LDFLAGS) 41 $(GN_PLUGIN_LDFLAGS)
42 42
43 43
44lib_LTLIBRARIES = \
45 libgnunettestingdhtu.la
46
47libgnunettestingdhtu_la_SOURCES = \
48 testing_dhtu_cmd_send.c
49libgnunettestingdhtu_la_LIBADD = \
50 $(top_builddir)/src/testing/libgnunettesting.la \
51 $(top_builddir)/src/util/libgnunetutil.la \
52 $(LTLIBINTL)
53libgnunettestingdhtu_la_LDFLAGS = \
54 $(GN_LIB_LDFLAGS) \
55 -version-info 0:0:0
56
57
58
44test_dhtu_ip_SOURCES = \ 59test_dhtu_ip_SOURCES = \
45 test_dhtu_ip.c 60 test_dhtu_ip.c
46test_dhtu_ip_LDADD = \ 61test_dhtu_ip_LDADD = \
diff --git a/src/dhtu/test_dhtu_ip.c b/src/dhtu/test_dhtu_ip.c
index f350905b8..eb886e994 100644
--- a/src/dhtu/test_dhtu_ip.c
+++ b/src/dhtu/test_dhtu_ip.c
@@ -32,20 +32,9 @@
32#define CONFIG_FILE "test_dhtu_ip.conf" 32#define CONFIG_FILE "test_dhtu_ip.conf"
33 33
34 34
35/** 35int
36 * Return value of the test. 36main (int argc,
37 * 37 char *const *argv)
38 */
39static int rv;
40
41
42/**
43 * Main function to run the test cases.
44 *
45 * @param cls not used.
46 */
47static void
48run (void *cls)
49{ 38{
50 struct GNUNET_TESTING_Command commands[] = { 39 struct GNUNET_TESTING_Command commands[] = {
51 GNUNET_TESTING_cmd_netjail_start_v2 ("netjail-start", 40 GNUNET_TESTING_cmd_netjail_start_v2 ("netjail-start",
@@ -55,23 +44,7 @@ run (void *cls)
55 GNUNET_TESTING_cmd_end () 44 GNUNET_TESTING_cmd_end ()
56 }; 45 };
57 46
58 (void) cls; 47 return GNUNET_TESTING_main (NULL,
59 if (GNUNET_OK != 48 commands,
60 GNUNET_TESTING_run (NULL, /* config file */ 49 TIMEOUT);
61 commands,
62 TIMEOUT))
63 {
64 GNUNET_break (0);
65 rv = EXIT_FAILURE;
66 }
67}
68
69
70int
71main (int argc,
72 char *const *argv)
73{
74 GNUNET_SCHEDULER_run (&run,
75 NULL);
76 return rv;
77} 50}
diff --git a/src/dhtu/testing_dhtu_cmd_send.c b/src/dhtu/testing_dhtu_cmd_send.c
new file mode 100644
index 000000000..129a31205
--- /dev/null
+++ b/src/dhtu/testing_dhtu_cmd_send.c
@@ -0,0 +1,170 @@
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 testing/testing_dhtu_cmd_send.c
23 * @brief use DHTU to send a message
24 * @author Christian Grothoff
25 */
26#include "platform.h"
27#include "gnunet_testing_ng_lib.h"
28
29
30/**
31 * State for the 'send' command.
32 */
33struct SendState
34{
35
36 /**
37 * Function to call when done.
38 */
39 GNUNET_SCHEDULER_TaskCallback cont;
40
41 /**
42 * Closure for @e cont.
43 */
44 void *cont_cls;
45
46 enum GNUNET_GenericReturnValue finished;
47};
48
49
50/**
51 *
52 *
53 * @param cls a `struct SendState`
54 */
55static void
56send_cleanup (void *cls)
57{
58 struct SendState *ss = cls;
59
60 GNUNET_free (ss);
61}
62
63
64/**
65 * Return trains of the ``send`` command.
66 *
67 * @param cls closure.
68 * @param[out] ret result
69 * @param trait name of the trait.
70 * @param index index number of the object to offer.
71 * @return #GNUNET_OK on success.
72 * #GNUNET_NO if no trait was found
73 */
74static enum GNUNET_GenericReturnValue
75send_traits (void *cls,
76 const void **ret,
77 const char *trait,
78 unsigned int index)
79{
80 return GNUNET_NO;
81}
82
83
84/**
85 * Run the 'send' command.
86 *
87 * @param cls closure.
88 * @param is interpreter state.
89 */
90static void
91send_run (void *cls,
92 struct GNUNET_TESTING_Interpreter *is)
93{
94 struct SendState *ss = cls;
95
96#if 0
97 other_cmd = GNUNET_TESTING_interpreter_lookup_command (ss->other_label);
98 GNUNET_TESTING_get_trait_XXX (other_cmd,
99 &data);
100#endif
101 ss->finished = GNUNET_OK;
102}
103
104
105/**
106 * This function checks the flag NetJailState#finished, if this cmd finished.
107 *
108 * @param cls a `struct SendState`
109 * @param cont function to call upon completion, can be NULL
110 * @param cont_cls closure for @a cont
111 * @return
112 * #GNUNET_NO if the command is still running and @a cont will be called later
113 * #GNUNET_OK if the command completed successfully and @a cont was called
114 * #GNUNET_SYSERR if the operation @a cont was NOT called
115 */
116static enum GNUNET_GenericReturnValue
117send_finish (void *cls,
118 GNUNET_SCHEDULER_TaskCallback cont,
119 void *cont_cls)
120{
121 struct SendState *ss = cls;
122
123 switch (ss->finished)
124 {
125 case GNUNET_OK:
126 cont (cont_cls);
127 break;
128 case GNUNET_SYSERR:
129 GNUNET_break (0);
130 break;
131 case GNUNET_NO:
132 if (NULL != ss->cont)
133 {
134 GNUNET_break (0);
135 return GNUNET_SYSERR;
136 }
137 ss->cont = cont;
138 ss->cont_cls = cont_cls;
139 break;
140 }
141 return ss->finished;
142}
143
144
145/**
146 * Create 'send' command.
147 *
148 * @param label name for command.
149 * @return command.
150 */
151struct GNUNET_TESTING_Command
152GNUNET_TESTING_DHTU_cmd_send (const char *label)
153{
154 struct SendState *ss;
155
156 ss = GNUNET_new (struct SendState);
157
158 {
159 struct GNUNET_TESTING_Command cmd = {
160 .cls = ss,
161 .label = label,
162 .run = &send_run,
163 .finish = &send_finish,
164 .cleanup = &send_cleanup,
165 .traits = &send_traits
166 };
167
168 return cmd;
169 }
170}