diff options
Diffstat (limited to 'src/testing/testing_api_cmd_system_create.c')
-rw-r--r-- | src/testing/testing_api_cmd_system_create.c | 152 |
1 files changed, 0 insertions, 152 deletions
diff --git a/src/testing/testing_api_cmd_system_create.c b/src/testing/testing_api_cmd_system_create.c deleted file mode 100644 index f3a0b1a4c..000000000 --- a/src/testing/testing_api_cmd_system_create.c +++ /dev/null | |||
@@ -1,152 +0,0 @@ | |||
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_system_create.c | ||
23 | * @brief cmd to create a testing system handle. | ||
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_lib.h" | ||
30 | |||
31 | /** | ||
32 | * Struct to hold information for callbacks. | ||
33 | * | ||
34 | */ | ||
35 | struct TestSystemState | ||
36 | { | ||
37 | struct GNUNET_TESTING_System *test_system; | ||
38 | |||
39 | const char *testdir; | ||
40 | }; | ||
41 | |||
42 | |||
43 | /** | ||
44 | * The run method of this cmd will setup a test environment for a node. | ||
45 | * | ||
46 | */ | ||
47 | static void | ||
48 | system_create_run (void *cls, | ||
49 | const struct GNUNET_TESTING_Command *cmd, | ||
50 | struct GNUNET_TESTING_Interpreter *is) | ||
51 | { | ||
52 | struct TestSystemState *tss = cls; | ||
53 | |||
54 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, | ||
55 | "system create\n"); | ||
56 | |||
57 | tss->test_system = GNUNET_TESTING_system_create (tss->testdir, | ||
58 | NULL, | ||
59 | NULL, | ||
60 | NULL); | ||
61 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, | ||
62 | "system created\n"); | ||
63 | } | ||
64 | |||
65 | |||
66 | /** | ||
67 | * This function prepares an array with traits. | ||
68 | * | ||
69 | */ | ||
70 | static int | ||
71 | system_create_traits (void *cls, | ||
72 | const void **ret, | ||
73 | const char *trait, | ||
74 | unsigned int index) | ||
75 | { | ||
76 | struct TestSystemState *tss = cls; | ||
77 | struct GNUNET_TESTING_System *test_system = tss->test_system; | ||
78 | |||
79 | struct GNUNET_TESTING_Trait traits[] = { | ||
80 | { | ||
81 | .index = 0, | ||
82 | .trait_name = "test_system", | ||
83 | .ptr = (const void *) test_system, | ||
84 | }, | ||
85 | GNUNET_TESTING_trait_end () | ||
86 | }; | ||
87 | |||
88 | return GNUNET_TESTING_get_trait (traits, | ||
89 | ret, | ||
90 | trait, | ||
91 | index); | ||
92 | } | ||
93 | |||
94 | |||
95 | /** | ||
96 | * Function to get the trait with struct GNUNET_TESTING_System | ||
97 | * | ||
98 | * @param[out] test_system The struct GNUNET_TESTING_System. | ||
99 | * @return #GNUNET_OK if no error occurred, #GNUNET_SYSERR otherwise. | ||
100 | */ | ||
101 | int | ||
102 | GNUNET_TESTING_get_trait_test_system (const struct | ||
103 | GNUNET_TESTING_Command *cmd, | ||
104 | struct GNUNET_TESTING_System **test_system) | ||
105 | { | ||
106 | return cmd->traits (cmd->cls, | ||
107 | (const void **) test_system, | ||
108 | "test_system", | ||
109 | (unsigned int) 0); | ||
110 | } | ||
111 | |||
112 | |||
113 | /** | ||
114 | * The cleanup function of this cmd frees resources the cmd allocated. | ||
115 | * | ||
116 | */ | ||
117 | static void | ||
118 | system_create_cleanup (void *cls, | ||
119 | const struct GNUNET_TESTING_Command *cmd) | ||
120 | { | ||
121 | struct TestSystemState *tss = cls; | ||
122 | |||
123 | GNUNET_free (tss); | ||
124 | } | ||
125 | |||
126 | |||
127 | /** | ||
128 | * Create command. | ||
129 | * | ||
130 | * @param label name for command. | ||
131 | * @param label name for the test environment directory. | ||
132 | * @return command. | ||
133 | */ | ||
134 | struct GNUNET_TESTING_Command | ||
135 | GNUNET_TESTING_cmd_system_create (const char *label, | ||
136 | const char *testdir) | ||
137 | { | ||
138 | struct TestSystemState *tss; | ||
139 | |||
140 | tss = GNUNET_new (struct TestSystemState); | ||
141 | tss->testdir = testdir; | ||
142 | |||
143 | struct GNUNET_TESTING_Command cmd = { | ||
144 | .cls = tss, | ||
145 | .label = label, | ||
146 | .run = &system_create_run, | ||
147 | .cleanup = &system_create_cleanup, | ||
148 | .traits = &system_create_traits | ||
149 | }; | ||
150 | |||
151 | return cmd; | ||
152 | } | ||