aboutsummaryrefslogtreecommitdiff
path: root/src/service/testbed/testbed_api_cmd_system_create.c
diff options
context:
space:
mode:
Diffstat (limited to 'src/service/testbed/testbed_api_cmd_system_create.c')
-rw-r--r--src/service/testbed/testbed_api_cmd_system_create.c121
1 files changed, 121 insertions, 0 deletions
diff --git a/src/service/testbed/testbed_api_cmd_system_create.c b/src/service/testbed/testbed_api_cmd_system_create.c
new file mode 100644
index 000000000..2f780ec73
--- /dev/null
+++ b/src/service/testbed/testbed_api_cmd_system_create.c
@@ -0,0 +1,121 @@
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_lib.h"
29#include "gnunet_testbed_lib.h"
30#include "gnunet_testing_testbed_lib.h"
31
32/**
33 * Struct to hold information for callbacks.
34 *
35 */
36struct TestSystemState
37{
38 struct GNUNET_TESTBED_System *test_system;
39
40 const char *testdir;
41};
42
43
44/**
45 * The run method of this cmd will setup a test environment for a node.
46 *
47 */
48static void
49system_create_run (void *cls,
50 struct GNUNET_TESTING_Interpreter *is)
51{
52 struct TestSystemState *tss = cls;
53
54 tss->test_system = GNUNET_TESTBED_system_create (tss->testdir,
55 NULL,
56 NULL);
57}
58
59
60/**
61 * This function prepares an array with traits.
62 *
63 */
64static int
65system_create_traits (void *cls,
66 const void **ret,
67 const char *trait,
68 unsigned int index)
69{
70 struct TestSystemState *tss = cls;
71 struct GNUNET_TESTING_Trait traits[] = {
72 GNUNET_TESTING_TESTBED_make_trait_test_system (
73 tss->test_system),
74 GNUNET_TESTING_trait_end ()
75 };
76
77 return GNUNET_TESTING_get_trait (traits,
78 ret,
79 trait,
80 index);
81}
82
83
84/**
85 * The cleanup function of this cmd frees resources the cmd allocated.
86 *
87 */
88static void
89system_create_cleanup (void *cls)
90{
91 struct TestSystemState *tss = cls;
92
93 GNUNET_TESTBED_system_destroy (tss->test_system,
94 GNUNET_YES);
95
96 GNUNET_free (tss);
97}
98
99
100/**
101 * Create command.
102 *
103 * @param label name for command.
104 * @param label name for the test environment directory.
105 * @return command.
106 */
107struct GNUNET_TESTING_Command
108GNUNET_TESTBED_cmd_system_create (const char *label,
109 const char *testdir)
110{
111 struct TestSystemState *tss;
112
113 tss = GNUNET_new (struct TestSystemState);
114 tss->testdir = testdir;
115
116 return GNUNET_TESTING_command_new (tss,
117 label,
118 &system_create_run,
119 &system_create_cleanup,
120 &system_create_traits);
121}