diff options
Diffstat (limited to 'src/testing')
-rw-r--r-- | src/testing/Makefile.am | 1 | ||||
-rw-r--r-- | src/testing/testing_api_cmd_system_destroy.c | 122 |
2 files changed, 123 insertions, 0 deletions
diff --git a/src/testing/Makefile.am b/src/testing/Makefile.am index 15469a310..c01e9bdbd 100644 --- a/src/testing/Makefile.am +++ b/src/testing/Makefile.am | |||
@@ -50,6 +50,7 @@ libgnunettesting_la_SOURCES = \ | |||
50 | testing_api_cmd_netjail_stop.c \ | 50 | testing_api_cmd_netjail_stop.c \ |
51 | testing.c testing.h \ | 51 | testing.c testing.h \ |
52 | testing_api_cmd_system_create.c \ | 52 | testing_api_cmd_system_create.c \ |
53 | testing_api_cmd_system_destroy.c \ | ||
53 | testing_api_cmd_batch.c \ | 54 | testing_api_cmd_batch.c \ |
54 | testing_api_cmd_hello_world.c \ | 55 | testing_api_cmd_hello_world.c \ |
55 | testing_api_cmd_hello_world_birth.c \ | 56 | testing_api_cmd_hello_world_birth.c \ |
diff --git a/src/testing/testing_api_cmd_system_destroy.c b/src/testing/testing_api_cmd_system_destroy.c new file mode 100644 index 000000000..e94d8dad0 --- /dev/null +++ b/src/testing/testing_api_cmd_system_destroy.c | |||
@@ -0,0 +1,122 @@ | |||
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_lib.h" | ||
30 | |||
31 | |||
32 | /** | ||
33 | * Struct to hold information for callbacks. | ||
34 | * | ||
35 | */ | ||
36 | struct TestSystemState | ||
37 | { | ||
38 | // Label of the cmd which started the test system. | ||
39 | const char *create_label; | ||
40 | }; | ||
41 | |||
42 | |||
43 | /** | ||
44 | * The run method of this cmd will remove the test environment for a node. | ||
45 | * | ||
46 | */ | ||
47 | static void | ||
48 | system_destroy_run (void *cls, | ||
49 | const struct GNUNET_TESTING_Command *cmd, | ||
50 | struct GNUNET_TESTING_Interpreter *is) | ||
51 | { | ||
52 | struct TestSystemState *tss = cls; | ||
53 | const struct GNUNET_TESTING_Command *system_cmd; | ||
54 | struct GNUNET_TESTING_System *tl_system; | ||
55 | |||
56 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, | ||
57 | "system destroy\n"); | ||
58 | |||
59 | system_cmd = GNUNET_TESTING_interpreter_lookup_command (tss->create_label); | ||
60 | GNUNET_TESTING_get_trait_test_system (system_cmd, | ||
61 | &tl_system); | ||
62 | GNUNET_TESTING_system_destroy (tl_system, GNUNET_YES); | ||
63 | |||
64 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, | ||
65 | "system destroyed\n"); | ||
66 | } | ||
67 | |||
68 | |||
69 | /** | ||
70 | * The cleanup function of this cmd frees resources the cmd allocated. | ||
71 | * | ||
72 | */ | ||
73 | static void | ||
74 | system_destroy_cleanup (void *cls, | ||
75 | const struct GNUNET_TESTING_Command *cmd) | ||
76 | { | ||
77 | struct TestSystemState *tss = cls; | ||
78 | |||
79 | GNUNET_free (tss); | ||
80 | } | ||
81 | |||
82 | |||
83 | /** | ||
84 | * Trait function of this cmd does nothing. | ||
85 | * | ||
86 | */ | ||
87 | static int | ||
88 | system_destroy_traits (void *cls, | ||
89 | const void **ret, | ||
90 | const char *trait, | ||
91 | unsigned int index) | ||
92 | { | ||
93 | return GNUNET_OK; | ||
94 | } | ||
95 | |||
96 | |||
97 | /** | ||
98 | * Create command. | ||
99 | * | ||
100 | * @param label name for command. | ||
101 | * @param create_label Label of the cmd which started the test system. | ||
102 | * @return command. | ||
103 | */ | ||
104 | struct GNUNET_TESTING_Command | ||
105 | GNUNET_TESTING_cmd_system_destroy (const char *label, | ||
106 | const char *create_label) | ||
107 | { | ||
108 | struct TestSystemState *tss; | ||
109 | |||
110 | tss = GNUNET_new (struct TestSystemState); | ||
111 | tss->create_label = create_label; | ||
112 | |||
113 | struct GNUNET_TESTING_Command cmd = { | ||
114 | .cls = tss, | ||
115 | .label = label, | ||
116 | .run = &system_destroy_run, | ||
117 | .cleanup = &system_destroy_cleanup, | ||
118 | .traits = &system_destroy_traits | ||
119 | }; | ||
120 | |||
121 | return cmd; | ||
122 | } | ||