GNUnet  0.19.4
gnunet-service-test-barriers.c
Go to the documentation of this file.
1 /*
2  This file is part of GNUnet
3  Copyright (C) 2008--2013 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_testbed_service.h"
31 #include "test_testbed_api_barriers.h"
32 
36 #define LOG(type, ...) \
37  GNUNET_log (type, __VA_ARGS__);
38 
43 
44 static struct GNUNET_SCHEDULER_Task *tt;
45 
46 
52 static void
53 do_shutdown (void *cls)
54 {
55  if (NULL != wh)
56  {
58  wh = NULL;
59  }
60  if (NULL != tt)
61  {
63  tt = NULL;
64  }
65 }
66 
67 
78 static void
79 barrier_wait_cb (void *cls,
80  const char *name,
81  int status)
82 {
83  GNUNET_break (NULL == cls);
84  wh = NULL;
86 }
87 
88 
95 static void
96 do_wait (void *cls)
97 {
98  tt = NULL;
99  wh = GNUNET_TESTBED_barrier_wait (TEST_BARRIER_NAME,
101  NULL);
102  GNUNET_break (NULL != wh);
103 }
104 
105 
114 static void
115 run (void *cls,
116  char *const *args,
117  const char *cfgfile,
118  const struct GNUNET_CONFIGURATION_Handle *config)
119 {
120  unsigned int rsec;
121 
123  10);
126  rsec),
127  &do_wait,
128  NULL);
130 }
131 
132 
136 int
137 main (int argc, char **argv)
138 {
141  };
142  int ret;
143 
144  ret =
145  GNUNET_PROGRAM_run (argc, argv,
146  "test-barriers",
147  "nohelp",
148  options,
149  &run,
150  NULL);
151  return ret;
152 }
struct GNUNET_GETOPT_CommandLineOption GNUNET_GETOPT_OPTION_END
Definition: 002.c:13
struct GNUNET_GETOPT_CommandLineOption options[]
Definition: 002.c:5
static int ret
Return value of the commandline.
Definition: gnunet-abd.c:81
uint16_t status
See PRISM_STATUS_*-constants.
static struct GNUNET_TESTBED_BarrierWaitHandle * wh
Our barrier wait handle.
int main(int argc, char **argv)
Main.
static void do_wait(void *cls)
Task to wait for the barrier.
static void do_shutdown(void *cls)
Dummy task callback to keep us running forever.
static struct GNUNET_SCHEDULER_Task * tt
static void run(void *cls, char *const *args, const char *cfgfile, const struct GNUNET_CONFIGURATION_Handle *config)
Main run function.
static void barrier_wait_cb(void *cls, const char *name, int status)
Functions of this type are to be given as acallback argument to GNUNET_TESTBED_barrier_wait().
static const struct GNUNET_CONFIGURATION_Handle * config
API for writing tests and creating large-scale emulation testbeds for GNUnet.
uint32_t GNUNET_CRYPTO_random_u32(enum GNUNET_CRYPTO_Quality mode, uint32_t i)
Produce a random value.
@ GNUNET_CRYPTO_QUALITY_NONCE
Randomness for IVs etc.
@ GNUNET_OK
#define GNUNET_break(cond)
Use this for internal assertion violations that are not fatal (can be handled) but should not occur.
enum GNUNET_GenericReturnValue GNUNET_PROGRAM_run(int argc, char *const *argv, const char *binaryName, const char *binaryHelp, const struct GNUNET_GETOPT_CommandLineOption *options, GNUNET_PROGRAM_Main task, void *task_cls)
Run a standard GNUnet command startup sequence (initialize loggers and configuration,...
Definition: program.c:400
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:1334
void * GNUNET_SCHEDULER_cancel(struct GNUNET_SCHEDULER_Task *task)
Cancel the task with the specified identifier.
Definition: scheduler.c:975
struct GNUNET_SCHEDULER_Task * GNUNET_SCHEDULER_add_delayed(struct GNUNET_TIME_Relative delay, GNUNET_SCHEDULER_TaskCallback task, void *task_cls)
Schedule a new task to be run with a specified delay.
Definition: scheduler.c:1272
struct GNUNET_TESTBED_BarrierWaitHandle * GNUNET_TESTBED_barrier_wait(const char *name, GNUNET_TESTBED_barrier_wait_cb cb, void *cls)
Wait for a barrier to be crossed.
void GNUNET_TESTBED_barrier_wait_cancel(struct GNUNET_TESTBED_BarrierWaitHandle *h)
Cancel a barrier wait handle.
#define GNUNET_TIME_UNIT_SECONDS
One second.
struct GNUNET_TIME_Relative GNUNET_TIME_relative_multiply(struct GNUNET_TIME_Relative rel, unsigned long long factor)
Multiply relative time by a given factor.
Definition: time.c:484
const char * name
Definition of a command line option.
Entry in list of pending tasks.
Definition: scheduler.c:136