GNUnet 0.22.1
testing_api_main.c
Go to the documentation of this file.
1/*
2 This file is part of GNUnet
3 Copyright (C) 2021-2024 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
28#include "platform.h"
29#include "gnunet_util_lib.h"
30#include "gnunet_testing_lib.h"
31
32
37{
38
43
48
53
57 int rv;
58};
59
60
67static void
68handle_result (void *cls,
70{
71 struct MainParams *mp = cls;
72
73 mp->is = NULL;
74 switch (rv)
75 {
76 case GNUNET_OK:
77 mp->rv = EXIT_SUCCESS;
78 break;
79 case GNUNET_NO:
80 mp->rv = 77;
81 break;
82 case GNUNET_SYSERR:
83 mp->rv = EXIT_FAILURE;
84 break;
85 }
87 "Test exits with status %d\n",
88 mp->rv);
90}
91
92
93static void
94do_shutdown (void *cls)
95{
96 struct MainParams *mp = cls;
97
98 if (NULL != mp->is)
99 {
101 "Terminating test due to shutdown\n");
103 }
104}
105
106
112static void
113loop_run (void *cls)
114{
115 struct MainParams *mp = cls;
116
117 mp->is = GNUNET_TESTING_run (mp->commands,
118 mp->timeout,
120 mp);
122 mp);
123}
124
125
126int
128 const struct GNUNET_TESTING_Command *commands,
130{
131 struct MainParams mp = {
133 .timeout = timeout,
134 .rv = EXIT_SUCCESS
135 };
136
138 &mp);
139 return mp.rv;
140}
static struct GNUNET_TIME_Relative timeout
User defined timestamp for completing operations.
Definition: gnunet-arm.c:118
static struct VoipCommand commands[]
List of supported commands.
struct GNUNET_TESTING_Interpreter * GNUNET_TESTING_run(const struct GNUNET_TESTING_Command *commands, struct GNUNET_TIME_Relative timeout, GNUNET_TESTING_ResultCallback rc, void *rc_cls)
Run the testsuite.
void GNUNET_TESTING_interpreter_fail(struct GNUNET_TESTING_Interpreter *is)
Current command failed, clean up and fail the test case.
#define GNUNET_log(kind,...)
GNUNET_GenericReturnValue
Named constants for return values.
@ GNUNET_OK
@ GNUNET_NO
@ GNUNET_SYSERR
@ GNUNET_ERROR_TYPE_WARNING
@ GNUNET_ERROR_TYPE_INFO
void GNUNET_SCHEDULER_shutdown(void)
Request the shutdown of a scheduler.
Definition: scheduler.c:566
void GNUNET_SCHEDULER_run(GNUNET_SCHEDULER_TaskCallback task, void *task_cls)
Initialize and run scheduler.
Definition: scheduler.c:724
struct GNUNET_SCHEDULER_Task * GNUNET_SCHEDULER_add_shutdown(GNUNET_SCHEDULER_TaskCallback task, void *task_cls)
Schedule a new task to be run on shutdown, that is when a CTRL-C signal is received,...
Definition: scheduler.c:1338
A command to be run by the interpreter.
Global state of the interpreter, used by a command to access information about other commands.
Time for relative time used by GNUnet, in microseconds.
Closure for loop_run().
int rv
Set to #EXIT_FAILURE on error.
const struct GNUNET_TESTING_Command * commands
NULL-label terminated array of commands.
struct GNUNET_TIME_Relative timeout
Global timeout for the test.
struct GNUNET_TESTING_Interpreter * is
The interpreter.
static void handle_result(void *cls, enum GNUNET_GenericReturnValue rv)
Function called with the final result of the test.
static void do_shutdown(void *cls)
int GNUNET_TESTING_main(const struct GNUNET_TESTING_Command *commands, struct GNUNET_TIME_Relative timeout)
Start a GNUnet scheduler event loop and run the testsuite.
static void loop_run(void *cls)
Main function to run the test cases.