aboutsummaryrefslogtreecommitdiff
path: root/src/testing/testing_api_cmd_local_test_prepared.c
diff options
context:
space:
mode:
Diffstat (limited to 'src/testing/testing_api_cmd_local_test_prepared.c')
-rw-r--r--src/testing/testing_api_cmd_local_test_prepared.c93
1 files changed, 35 insertions, 58 deletions
diff --git a/src/testing/testing_api_cmd_local_test_prepared.c b/src/testing/testing_api_cmd_local_test_prepared.c
index 4e915c7c0..2554d6fec 100644
--- a/src/testing/testing_api_cmd_local_test_prepared.c
+++ b/src/testing/testing_api_cmd_local_test_prepared.c
@@ -35,41 +35,47 @@
35 35
36 36
37/** 37/**
38 * Struct to hold information for callbacks. 38 * This function prepares an array with traits.
39 * 39 *
40 */ 40 */
41struct LocalPreparedState 41enum GNUNET_GenericReturnValue
42local_test_prepared_traits (void *cls,
43 const void **ret,
44 const char *trait,
45 unsigned int index)
42{ 46{
43 /** 47 struct LocalPreparedState *lfs = cls;
44 * Callback to write messages to the master loop. 48 struct GNUNET_TESTING_Trait traits[] = {
45 * 49 {
46 */ 50 .index = 0,
47 TESTING_CMD_HELPER_write_cb write_message; 51 .trait_name = "state",
48 52 .ptr = (const void *) lfs,
49 /** 53 },
50 * The message send back to the master loop. 54 GNUNET_TESTING_trait_end ()
51 * 55 };
52 */ 56 return GNUNET_TESTING_get_trait (traits,
53 struct GNUNET_CMDS_LOCAL_TEST_PREPARED *reply; 57 ret,
54 58 trait,
55 /** 59 index);
56 * Flag indicating if all local tests finished. 60}
57 */
58 unsigned int *all_local_tests_prepared;
59};
60 61
61 62
62/** 63/**
63 * Trait function of this cmd does nothing. 64 * Function to get the trait with the struct LocalPreparedState.
65 *
66 * @param[out] lfs struct LocalPreparedState.
67 * @return #GNUNET_OK if no error occurred, #GNUNET_SYSERR otherwise.
64 * 68 *
65 */ 69 */
66static int 70enum GNUNET_GenericReturnValue
67local_test_prepared_traits (void *cls, 71GNUNET_TESTING_get_trait_local_prepared_state (
68 const void **ret, 72 const struct GNUNET_TESTING_Command *cmd,
69 const char *trait, 73 struct LocalPreparedState **lfs)
70 unsigned int index)
71{ 74{
72 return GNUNET_OK; 75 return cmd->traits (cmd->cls,
76 (const void **) lfs,
77 "state",
78 (unsigned int) 0);
73} 79}
74 80
75 81
@@ -78,12 +84,10 @@ local_test_prepared_traits (void *cls,
78 * 84 *
79 */ 85 */
80static void 86static void
81local_test_prepared_cleanup (void *cls, 87local_test_prepared_cleanup (void *cls)
82 const struct GNUNET_TESTING_Command *cmd)
83{ 88{
84 struct LocalPreparedState *lfs = cls; 89 struct LocalPreparedState *lfs = cls;
85 90
86 GNUNET_free (lfs->reply);
87 GNUNET_free (lfs); 91 GNUNET_free (lfs);
88} 92}
89 93
@@ -94,7 +98,6 @@ local_test_prepared_cleanup (void *cls,
94 */ 98 */
95static void 99static void
96local_test_prepared_run (void *cls, 100local_test_prepared_run (void *cls,
97 const struct GNUNET_TESTING_Command *cmd,
98 struct GNUNET_TESTING_Interpreter *is) 101 struct GNUNET_TESTING_Interpreter *is)
99{ 102{
100 struct LocalPreparedState *lfs = cls; 103 struct LocalPreparedState *lfs = cls;
@@ -107,34 +110,11 @@ local_test_prepared_run (void *cls,
107 reply->header.type = htons ( 110 reply->header.type = htons (
108 GNUNET_MESSAGE_TYPE_CMDS_HELPER_LOCAL_TEST_PREPARED); 111 GNUNET_MESSAGE_TYPE_CMDS_HELPER_LOCAL_TEST_PREPARED);
109 reply->header.size = htons ((uint16_t) msg_length); 112 reply->header.size = htons ((uint16_t) msg_length);
110 lfs->reply = reply;
111 lfs->write_message ((struct GNUNET_MessageHeader *) reply, msg_length); 113 lfs->write_message ((struct GNUNET_MessageHeader *) reply, msg_length);
112} 114}
113 115
114 116
115/** 117/**
116 * This finish function will stop the local loop without shutting down the scheduler, because we do not call the continuation, which is the interpreter_next method.
117 *
118 */
119static int
120local_test_prepared_finish (void *cls,
121 GNUNET_SCHEDULER_TaskCallback cont,
122 void *cont_cls)
123{
124 struct LocalPreparedState *lfs = cls;
125 unsigned int *ret = lfs->all_local_tests_prepared;
126
127 if (GNUNET_YES == *ret)
128 {
129 cont (cont_cls);
130 }
131
132 return *ret;
133
134}
135
136
137/**
138 * Create command. 118 * Create command.
139 * 119 *
140 * @param label name for command. 120 * @param label name for command.
@@ -145,21 +125,18 @@ local_test_prepared_finish (void *cls,
145struct GNUNET_TESTING_Command 125struct GNUNET_TESTING_Command
146GNUNET_TESTING_cmd_local_test_prepared (const char *label, 126GNUNET_TESTING_cmd_local_test_prepared (const char *label,
147 TESTING_CMD_HELPER_write_cb 127 TESTING_CMD_HELPER_write_cb
148 write_message, 128 write_message)
149 unsigned int *
150 all_local_tests_prepared)
151{ 129{
152 struct LocalPreparedState *lfs; 130 struct LocalPreparedState *lfs;
153 131
154 lfs = GNUNET_new (struct LocalPreparedState); 132 lfs = GNUNET_new (struct LocalPreparedState);
155 lfs->write_message = write_message; 133 lfs->write_message = write_message;
156 lfs->all_local_tests_prepared = all_local_tests_prepared;
157 134
158 struct GNUNET_TESTING_Command cmd = { 135 struct GNUNET_TESTING_Command cmd = {
159 .cls = lfs, 136 .cls = lfs,
160 .label = label, 137 .label = label,
161 .run = &local_test_prepared_run, 138 .run = &local_test_prepared_run,
162 .finish = &local_test_prepared_finish, 139 .ac = &lfs->ac,
163 .cleanup = &local_test_prepared_cleanup, 140 .cleanup = &local_test_prepared_cleanup,
164 .traits = &local_test_prepared_traits 141 .traits = &local_test_prepared_traits
165 }; 142 };