aboutsummaryrefslogtreecommitdiff
path: root/src/testbed/testbed_api_cmd_local_test_finished.c
diff options
context:
space:
mode:
Diffstat (limited to 'src/testbed/testbed_api_cmd_local_test_finished.c')
-rw-r--r--src/testbed/testbed_api_cmd_local_test_finished.c129
1 files changed, 129 insertions, 0 deletions
diff --git a/src/testbed/testbed_api_cmd_local_test_finished.c b/src/testbed/testbed_api_cmd_local_test_finished.c
new file mode 100644
index 000000000..8829f1b9a
--- /dev/null
+++ b/src/testbed/testbed_api_cmd_local_test_finished.c
@@ -0,0 +1,129 @@
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_api_cmd_block_until_all_peers_started.c
23 * @brief cmd to block the interpreter loop until all peers started.
24 * @author t3sserakt
25 */
26#include "platform.h"
27#include "gnunet_util_lib.h"
28#include "gnunet_testing_ng_lib.h"
29#include "testbed_helper.h"
30
31/**
32 * Generic logging shortcut
33 */
34#define LOG(kind, ...) GNUNET_log (kind, __VA_ARGS__)
35
36struct LocalFinishedState
37{
38 TESTBED_CMD_HELPER_write_cb write_message;
39
40 struct GNUNET_CMDS_LOCAL_FINISHED *reply;
41};
42
43
44static int
45local_test_finished_traits (void *cls,
46 const void **ret,
47 const char *trait,
48 unsigned int index)
49{
50 return GNUNET_OK;
51}
52
53
54static void
55local_test_finished_cleanup (void *cls,
56 const struct GNUNET_TESTING_Command *cmd)
57{
58 struct LocalFinishedState *lfs = cls;
59
60 GNUNET_free (lfs->reply);
61 GNUNET_free (lfs);
62}
63
64
65static void
66local_test_finished_run (void *cls,
67 const struct GNUNET_TESTING_Command *cmd,
68 struct GNUNET_TESTING_Interpreter *is)
69{
70 struct LocalFinishedState *lfs = cls;
71
72 struct GNUNET_CMDS_LOCAL_FINISHED *reply;
73 size_t msg_length;
74
75 LOG (GNUNET_ERROR_TYPE_ERROR,
76 "We got here 12!\n");
77
78 msg_length = sizeof(struct GNUNET_CMDS_LOCAL_FINISHED);
79 reply = GNUNET_new (struct GNUNET_CMDS_LOCAL_FINISHED);
80 reply->header.type = htons (GNUNET_MESSAGE_TYPE_CMDS_HELPER_LOCAL_FINISHED);
81 reply->header.size = htons ((uint16_t) msg_length);
82 lfs->reply = reply;
83 lfs->write_message ((struct GNUNET_MessageHeader *) reply, msg_length);
84
85 LOG (GNUNET_ERROR_TYPE_ERROR,
86 "We got here 13!\n");
87}
88
89
90static int
91local_test_finished_finish (void *cls,
92 GNUNET_SCHEDULER_TaskCallback cont,
93 void *cont_cls)
94{
95 // This will stop the local loop without shutting down the scheduler, because we do not call the continuation, which is the interpreter_next method.
96 return GNUNET_YES;
97}
98
99
100/**
101 * Create command.
102 *
103 * @param label name for command.
104 * @return command.
105 */
106struct GNUNET_TESTING_Command
107GNUNET_TESTING_cmd_local_test_finished (const char *label,
108 TESTBED_CMD_HELPER_write_cb
109 write_message)
110{
111 struct LocalFinishedState *lfs;
112
113 LOG (GNUNET_ERROR_TYPE_ERROR,
114 "We got here 11!\n");
115
116 lfs = GNUNET_new (struct LocalFinishedState);
117 lfs->write_message = write_message;
118
119 struct GNUNET_TESTING_Command cmd = {
120 .cls = lfs,
121 .label = label,
122 .run = &local_test_finished_run,
123 .finish = &local_test_finished_finish,
124 .cleanup = &local_test_finished_cleanup,
125 .traits = &local_test_finished_traits
126 };
127
128 return cmd;
129}