The FreeRADIUS server $Id: 15bac2a4c627c01d1aa2047687b3418955ac7f00 $
Loading...
Searching...
No Matches
schedule_test.c
Go to the documentation of this file.
1/*
2 * schedule_test.c Tests for the scheduler
3 *
4 * Version: $Id: 5938360050b7e573879f330dad5689907c09339f $
5 *
6 * This program is free software; you can redistribute it and/or modify
7 * it under the terms of the GNU General Public License as published by
8 * the Free Software Foundation; either version 2 of the License, or
9 * (at your option) any later version.
10 *
11 * This program is distributed in the hope that it will be useful,
12 * but WITHOUT ANY WARRANTY; without even the implied warranty of
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 * GNU General Public License for more details.
15 *
16 * You should have received a copy of the GNU General Public License
17 * along with this program; if not, write to the Free Software
18 * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA
19 *
20 * @copyright 2016 Alan DeKok (aland@freeradius.org)
21 */
22
23RCSID("$Id: 5938360050b7e573879f330dad5689907c09339f $")
24
25#include <freeradius-devel/io/schedule.h>
26#include <freeradius-devel/util/time.h>
27#include <freeradius-devel/radius/defs.h>
28#include <freeradius-devel/util/inet.h>
29#include <freeradius-devel/util/md5.h>
30#include <freeradius-devel/util/syserror.h>
31
32#include <sys/event.h>
33#include <pthread.h>
34
35#ifdef HAVE_GETOPT_H
36# include <getopt.h>
37#endif
38
39
40static int debug_lvl = 0;
41
42static NEVER_RETURNS void usage(void)
43{
44 fprintf(stderr, "usage: schedule_test [OPTS]\n");
45 fprintf(stderr, " -n <num> Start num network threads\n");
46 fprintf(stderr, " -w <num> Start num worker threads\n");
47 fprintf(stderr, " -x Debugging mode.\n");
48
49 fr_exit_now(EXIT_FAILURE);
50}
51
52int main(int argc, char *argv[])
53{
54 int c;
55 int num_networks = 1;
56 int num_workers = 2;
57 TALLOC_CTX *autofree = talloc_autofree_context();
58 fr_schedule_t *sched;
59
61
63
64 while ((c = getopt(argc, argv, "n:w:x")) != -1) switch (c) {
65 case 'n':
66 num_networks = atoi(optarg);
67 if ((num_networks <= 0) || (num_networks > 16)) usage();
68 break;
69
70 case 'w':
71 num_workers = atoi(optarg);
72 if ((num_workers <= 0) || (num_workers > 1024)) usage();
73 break;
74
75 case 'x':
76 debug_lvl++;
78 break;
79
80 case 'h':
81 default:
82 usage();
83 }
84
85#if 0
86 argc -= (optind - 1);
87 argv += (optind - 1);
88#endif
89
90 sched = fr_schedule_create(autofree, NULL, &default_log, L_DBG_LVL_MAX, num_networks, num_workers, NULL, NULL);
91 if (!sched) {
92 fprintf(stderr, "schedule_test: Failed to create scheduler\n");
93 fr_exit_now(EXIT_FAILURE);
94 }
95
96 sleep(1);
97
98 (void) fr_schedule_destroy(&sched);
99
100 return 0;
101}
static TALLOC_CTX * autofree
Definition fuzzer.c:44
#define RCSID(id)
Definition build.h:506
#define NEVER_RETURNS
Should be placed before the function return type.
Definition build.h:334
static size_t num_workers
#define fr_exit_now(_x)
Exit without calling atexit() handlers, producing a log message in debug builds.
Definition debug.h:236
int fr_log_init_legacy(fr_log_t *log, bool daemonize)
Initialise file descriptors based on logging destination.
Definition log.c:901
int fr_debug_lvl
Definition log.c:40
fr_log_t default_log
Definition log.c:288
@ L_DBG_LVL_MAX
Lowest priority debug messages (-xxxxx | -Xxxx).
Definition log.h:71
fr_schedule_t * fr_schedule_create(TALLOC_CTX *ctx, fr_event_list_t *el, fr_log_t *logger, fr_log_lvl_t lvl, fr_schedule_thread_instantiate_t worker_thread_instantiate, fr_schedule_thread_detach_t worker_thread_detach, fr_schedule_config_t *config)
Create a scheduler and spawn the child threads.
Definition schedule.c:264
int fr_schedule_destroy(fr_schedule_t **sc_to_free)
Destroy a scheduler, and tell its child threads to exit.
Definition schedule.c:553
The scheduler.
Definition schedule.c:76
int main(int argc, char *argv[])
static NEVER_RETURNS void usage(void)
static int debug_lvl
#define talloc_autofree_context
The original function is deprecated, so replace it with our version.
Definition talloc.h:48
int fr_time_start(void)
Initialize the local time.
Definition time.c:150