diff options
Diffstat (limited to 'src/service/testing/testing_api_cmd_system_destroy.c')
-rw-r--r-- | src/service/testing/testing_api_cmd_system_destroy.c | 111 |
1 files changed, 111 insertions, 0 deletions
diff --git a/src/service/testing/testing_api_cmd_system_destroy.c b/src/service/testing/testing_api_cmd_system_destroy.c new file mode 100644 index 000000000..45adfd0da --- /dev/null +++ b/src/service/testing/testing_api_cmd_system_destroy.c | |||
@@ -0,0 +1,111 @@ | |||
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_destroy.c | ||
23 | * @brief cmd to destroy 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 | /** | ||
35 | * Struct to hold information for callbacks. | ||
36 | * | ||
37 | */ | ||
38 | struct TestSystemState | ||
39 | { | ||
40 | // Label of the cmd which started the test system. | ||
41 | const char *create_label; | ||
42 | }; | ||
43 | |||
44 | |||
45 | /** | ||
46 | * The run method of this cmd will remove the test environment for a node. | ||
47 | * | ||
48 | */ | ||
49 | static void | ||
50 | system_destroy_run (void *cls, | ||
51 | struct GNUNET_TESTING_Interpreter *is) | ||
52 | { | ||
53 | struct TestSystemState *tss = cls; | ||
54 | const struct GNUNET_TESTING_Command *system_cmd; | ||
55 | const struct GNUNET_TESTING_System *tl_system; | ||
56 | |||
57 | system_cmd = GNUNET_TESTING_interpreter_lookup_command (is, | ||
58 | tss->create_label); | ||
59 | GNUNET_TESTING_get_trait_test_system (system_cmd, | ||
60 | &tl_system); | ||
61 | GNUNET_TESTING_system_destroy ((struct GNUNET_TESTING_System *) tl_system, | ||
62 | GNUNET_YES); | ||
63 | } | ||
64 | |||
65 | |||
66 | /** | ||
67 | * The cleanup function of this cmd frees resources the cmd allocated. | ||
68 | * | ||
69 | */ | ||
70 | static void | ||
71 | system_destroy_cleanup (void *cls) | ||
72 | { | ||
73 | struct TestSystemState *tss = cls; | ||
74 | |||
75 | GNUNET_free (tss); | ||
76 | } | ||
77 | |||
78 | |||
79 | /** | ||
80 | * Trait function of this cmd does nothing. | ||
81 | * | ||
82 | */ | ||
83 | static enum GNUNET_GenericReturnValue | ||
84 | system_destroy_traits (void *cls, | ||
85 | const void **ret, | ||
86 | const char *trait, | ||
87 | unsigned int index) | ||
88 | { | ||
89 | return GNUNET_OK; | ||
90 | } | ||
91 | |||
92 | |||
93 | /** | ||
94 | * Create command. | ||
95 | * | ||
96 | * @param label name for command. | ||
97 | * @param create_label Label of the cmd which started the test system. | ||
98 | * @return command. | ||
99 | */ | ||
100 | struct GNUNET_TESTING_Command | ||
101 | GNUNET_TESTING_cmd_system_destroy (const char *label, | ||
102 | const char *create_label) | ||
103 | { | ||
104 | struct TestSystemState *tss; | ||
105 | |||
106 | tss = GNUNET_new (struct TestSystemState); | ||
107 | tss->create_label = create_label; | ||
108 | return GNUNET_TESTING_command_new (tss, label, &system_destroy_run, | ||
109 | &system_destroy_cleanup, | ||
110 | &system_destroy_traits, NULL); | ||
111 | } | ||