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