aboutsummaryrefslogtreecommitdiff
path: root/src/testing/testing_api_cmd_local_test_finished.c
diff options
context:
space:
mode:
authort3sserakt <t3ss@posteo.de>2021-08-17 19:57:12 +0200
committert3sserakt <t3ss@posteo.de>2021-08-17 19:57:12 +0200
commit32a8c505c1fa27bb43c4e7c8d288566d51417f56 (patch)
tree0328fe50b6a099b5020fe6d1e01cbd6b96ecd18a /src/testing/testing_api_cmd_local_test_finished.c
parent1e063cd73452396778cf00127346b9b08a922317 (diff)
downloadgnunet-32a8c505c1fa27bb43c4e7c8d288566d51417f56.tar.gz
gnunet-32a8c505c1fa27bb43c4e7c8d288566d51417f56.zip
- moved test code from testbed to testing
Diffstat (limited to 'src/testing/testing_api_cmd_local_test_finished.c')
-rw-r--r--src/testing/testing_api_cmd_local_test_finished.c131
1 files changed, 131 insertions, 0 deletions
diff --git a/src/testing/testing_api_cmd_local_test_finished.c b/src/testing/testing_api_cmd_local_test_finished.c
new file mode 100644
index 000000000..5b74d4e04
--- /dev/null
+++ b/src/testing/testing_api_cmd_local_test_finished.c
@@ -0,0 +1,131 @@
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 "testing_cmds.h"
30
31/**
32 * Generic logging shortcut
33 */
34#define LOG(kind, ...) GNUNET_log (kind, __VA_ARGS__)
35
36struct LocalFinishedState
37{
38 TESTING_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 LOG (GNUNET_ERROR_TYPE_ERROR,
97 "Stopping local loop\n");
98 return GNUNET_YES;
99}
100
101
102/**
103 * Create command.
104 *
105 * @param label name for command.
106 * @return command.
107 */
108struct GNUNET_TESTING_Command
109GNUNET_TESTING_cmd_local_test_finished (const char *label,
110 TESTING_CMD_HELPER_write_cb
111 write_message)
112{
113 struct LocalFinishedState *lfs;
114
115 LOG (GNUNET_ERROR_TYPE_ERROR,
116 "We got here 11!\n");
117
118 lfs = GNUNET_new (struct LocalFinishedState);
119 lfs->write_message = write_message;
120
121 struct GNUNET_TESTING_Command cmd = {
122 .cls = lfs,
123 .label = label,
124 .run = &local_test_finished_run,
125 .finish = &local_test_finished_finish,
126 .cleanup = &local_test_finished_cleanup,
127 .traits = &local_test_finished_traits
128 };
129
130 return cmd;
131}