diff options
Diffstat (limited to 'src/service/testing/testing_api_cmd_local_test_prepared.c')
-rw-r--r-- | src/service/testing/testing_api_cmd_local_test_prepared.c | 112 |
1 files changed, 112 insertions, 0 deletions
diff --git a/src/service/testing/testing_api_cmd_local_test_prepared.c b/src/service/testing/testing_api_cmd_local_test_prepared.c new file mode 100644 index 000000000..2b1525077 --- /dev/null +++ b/src/service/testing/testing_api_cmd_local_test_prepared.c | |||
@@ -0,0 +1,112 @@ | |||
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_local_test_prepared.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 "gnunet_testing_plugin.h" | ||
30 | #include "gnunet_testing_barrier.h" | ||
31 | #include "gnunet_testing_netjail_lib.h" | ||
32 | #include "testing_cmds.h" | ||
33 | |||
34 | /** | ||
35 | * Generic logging shortcut | ||
36 | */ | ||
37 | #define LOG(kind, ...) GNUNET_log (kind, __VA_ARGS__) | ||
38 | |||
39 | |||
40 | /** | ||
41 | * This function prepares an array with traits. | ||
42 | * | ||
43 | */ | ||
44 | enum GNUNET_GenericReturnValue | ||
45 | local_test_prepared_traits (void *cls, | ||
46 | const void **ret, | ||
47 | const char *trait, | ||
48 | unsigned int index) | ||
49 | { | ||
50 | struct LocalPreparedState *lfs = cls; | ||
51 | struct GNUNET_TESTING_Trait traits[] = { | ||
52 | GNUNET_TESTING_make_trait_local_prepared_state ((const void *) lfs), | ||
53 | GNUNET_TESTING_trait_end () | ||
54 | }; | ||
55 | return GNUNET_TESTING_get_trait (traits, | ||
56 | ret, | ||
57 | trait, | ||
58 | index); | ||
59 | } | ||
60 | |||
61 | |||
62 | /** | ||
63 | * The cleanup function of this cmd frees resources the cmd allocated. | ||
64 | * | ||
65 | */ | ||
66 | static void | ||
67 | local_test_prepared_cleanup (void *cls) | ||
68 | { | ||
69 | struct LocalPreparedState *lfs = cls; | ||
70 | |||
71 | GNUNET_free (lfs); | ||
72 | } | ||
73 | |||
74 | |||
75 | /** | ||
76 | * This function sends a GNUNET_MESSAGE_TYPE_CMDS_HELPER_LOCAL_TESTS_PREPARED message to the master loop. | ||
77 | * | ||
78 | */ | ||
79 | static void | ||
80 | local_test_prepared_run (void *cls, | ||
81 | struct GNUNET_TESTING_Interpreter *is) | ||
82 | { | ||
83 | struct GNUNET_TESTING_LocalPreparedState *lfs = cls; | ||
84 | |||
85 | struct GNUNET_TESTING_CommandLocalTestPrepared *reply; | ||
86 | size_t msg_length; | ||
87 | |||
88 | msg_length = sizeof(struct GNUNET_TESTING_CommandLocalTestPrepared); | ||
89 | reply = GNUNET_new (struct GNUNET_TESTING_CommandLocalTestPrepared); | ||
90 | reply->header.type = htons ( | ||
91 | GNUNET_MESSAGE_TYPE_CMDS_HELPER_LOCAL_TEST_PREPARED); | ||
92 | reply->header.size = htons ((uint16_t) msg_length); | ||
93 | lfs->write_message ((struct GNUNET_MessageHeader *) reply, msg_length); | ||
94 | } | ||
95 | |||
96 | |||
97 | struct GNUNET_TESTING_Command | ||
98 | GNUNET_TESTING_cmd_local_test_prepared (const char *label, | ||
99 | GNUNET_TESTING_cmd_helper_write_cb | ||
100 | write_message) | ||
101 | { | ||
102 | struct GNUNET_TESTING_LocalPreparedState *lfs; | ||
103 | |||
104 | lfs = GNUNET_new (struct GNUNET_TESTING_LocalPreparedState); | ||
105 | lfs->write_message = write_message; | ||
106 | |||
107 | return GNUNET_TESTING_command_new (lfs, label, | ||
108 | &local_test_prepared_run, | ||
109 | &local_test_prepared_cleanup, | ||
110 | &local_test_prepared_traits, | ||
111 | &lfs->ac); | ||
112 | } | ||