GNUnet  0.11.x
testing_api_cmd_local_test_finished.c
Go to the documentation of this file.
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 
26 #include "platform.h"
27 #include "gnunet_util_lib.h"
28 #include "gnunet_testing_ng_lib.h"
29 #include "testing_cmds.h"
30 
34 #define LOG(kind, ...) GNUNET_log (kind, __VA_ARGS__)
35 
36 
42 {
48 
54 };
55 
56 
61 static int
63  const void **ret,
64  const char *trait,
65  unsigned int index)
66 {
67  return GNUNET_OK;
68 }
69 
70 
75 static void
77  const struct GNUNET_TESTING_Command *cmd)
78 {
79  struct LocalFinishedState *lfs = cls;
80 
81  GNUNET_free (lfs->reply);
82  GNUNET_free (lfs);
83 }
84 
85 
90 static void
92  const struct GNUNET_TESTING_Command *cmd,
94 {
95  struct LocalFinishedState *lfs = cls;
96 
97  struct GNUNET_CMDS_LOCAL_FINISHED *reply;
98  size_t msg_length;
99 
100  msg_length = sizeof(struct GNUNET_CMDS_LOCAL_FINISHED);
101  reply = GNUNET_new (struct GNUNET_CMDS_LOCAL_FINISHED);
103  reply->header.size = htons ((uint16_t) msg_length);
104  lfs->reply = reply;
105  lfs->write_message ((struct GNUNET_MessageHeader *) reply, msg_length);
106 }
107 
108 
113 static int
116  void *cont_cls)
117 {
119  "Stopping local loop\n");
120  return GNUNET_YES;
121 }
122 
123 
135 {
136  struct LocalFinishedState *lfs;
137 
138  lfs = GNUNET_new (struct LocalFinishedState);
140 
141  struct GNUNET_TESTING_Command cmd = {
142  .cls = lfs,
143  .label = label,
144  .run = &local_test_finished_run,
145  .finish = &local_test_finished_finish,
146  .cleanup = &local_test_finished_cleanup,
147  .traits = &local_test_finished_traits
148  };
149 
150  return cmd;
151 }
static int ret
Return value of the commandline.
Definition: gnunet-abd.c:81
static int write_message(uint16_t message_type, const char *data, size_t data_length)
Write message to the master process.
@ GNUNET_OK
Definition: gnunet_common.h:95
@ GNUNET_YES
Definition: gnunet_common.h:97
void(* TESTING_CMD_HELPER_write_cb)(struct GNUNET_MessageHeader *message, size_t msg_length)
@ GNUNET_ERROR_TYPE_DEBUG
#define GNUNET_new(type)
Allocate a struct or union of the given type.
#define GNUNET_free(ptr)
Wrapper around free.
#define GNUNET_MESSAGE_TYPE_CMDS_HELPER_LOCAL_FINISHED
void(* GNUNET_SCHEDULER_TaskCallback)(void *cls)
Signature of the main function of a task.
struct GNUNET_MessageHeader header
Type is GNUNET_MESSAGE_TYPE_CMDS_HELPER_LOCAL_FINISHED.
Definition: testing_cmds.h:85
Header for all communications.
uint16_t type
The type of the message (GNUNET_MESSAGE_TYPE_XXXX), in big-endian format.
uint16_t size
The length of the struct (in bytes, including the length field itself), in big-endian format.
A command to be run by the interpreter.
const char * label
Label for the command.
void * cls
Closure for all commands with command-specific context information.
Global state of the interpreter, used by a command to access information about other commands.
Definition: testing.h:35
Struct to hold information for callbacks.
TESTING_CMD_HELPER_write_cb write_message
Callback to write messages to the master loop.
struct GNUNET_CMDS_LOCAL_FINISHED * reply
The message send back to the master loop.
struct GNUNET_TESTING_Command GNUNET_TESTING_cmd_local_test_finished(const char *label, TESTING_CMD_HELPER_write_cb write_message)
Create command.
static int local_test_finished_finish(void *cls, GNUNET_SCHEDULER_TaskCallback cont, void *cont_cls)
This finish function will stop the local loop without shutting down the scheduler,...
static int local_test_finished_traits(void *cls, const void **ret, const char *trait, unsigned int index)
Trait function of this cmd does nothing.
static void local_test_finished_cleanup(void *cls, const struct GNUNET_TESTING_Command *cmd)
The cleanup function of this cmd frees resources the cmd allocated.
static void local_test_finished_run(void *cls, const struct GNUNET_TESTING_Command *cmd, struct GNUNET_TESTING_Interpreter *is)
This function sends a GNUNET_MESSAGE_TYPE_CMDS_HELPER_LOCAL_FINISHED message to the master loop.
#define LOG(kind,...)
Generic logging shortcut.
struct GNUNET_TESTING_Interpreter * is
Message formats for communication between testing cmds helper and testcase plugins.