The FreeRADIUS server $Id: a4e7f8c94e8038b7627bcf52356b7ed15955c1d7 $
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: 56243d08c546d2ee6ef9a106547c92831f115f98 $
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: 56243d08c546d2ee6ef9a106547c92831f115f98 $")
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
40
41static NEVER_RETURNS void usage(void)
42{
43 fprintf(stderr, "usage: schedule_test [OPTS]\n");
44 fprintf(stderr, " -n <num> Start num network threads\n");
45 fprintf(stderr, " -w <num> Start num worker threads\n");
46 fprintf(stderr, " -x Debugging mode.\n");
47
48 fr_exit_now(EXIT_FAILURE);
49}
50
51int main(int argc, char *argv[])
52{
53 int c;
54 int num_networks = 1;
55 int num_workers = 2;
56 TALLOC_CTX *autofree = talloc_autofree_context();
57 fr_schedule_t *sched;
58
60
62
63 while ((c = getopt(argc, argv, "n:w:x")) != -1) switch (c) {
64 case 'n':
65 num_networks = atoi(optarg);
66 if ((num_networks <= 0) || (num_networks > 16)) usage();
67 break;
68
69 case 'w':
70 num_workers = atoi(optarg);
71 if ((num_workers <= 0) || (num_workers > 1024)) usage();
72 break;
73
74 case 'x':
76 break;
77
78 case 'h':
79 default:
80 usage();
81 }
82
83#if 0
84 argc -= (optind - 1);
85 argv += (optind - 1);
86#endif
87
88 sched = fr_schedule_create(autofree, false, NULL, &default_log, L_DBG_LVL_MAX, num_networks, num_workers, NULL, NULL);
89 if (!sched) {
90 fprintf(stderr, "schedule_test: Failed to create scheduler\n");
91 fr_exit_now(EXIT_FAILURE);
92 }
93
94 sleep(1);
95
96 (void) fr_schedule_destroy(&sched);
97
98 return 0;
99}
#define RCSID(id)
Definition build.h:603
#define NEVER_RETURNS
Should be placed before the function return type.
Definition build.h:413
TALLOC_CTX * autofree
Definition common.c:29
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:272
int fr_log_init_legacy(fr_log_t *log, bool daemonize)
Initialise file descriptors based on logging destination.
Definition log.c:1000
int fr_debug_lvl
Definition log.c:41
fr_log_t default_log
Definition log.c:308
@ L_DBG_LVL_MAX
Lowest priority debug messages (-xxxxx | -Xxxx).
Definition log.h:71
fr_schedule_t * fr_schedule_create(TALLOC_CTX *ctx, bool single_threaded, 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:292
int fr_schedule_destroy(fr_schedule_t **sc_to_free)
Destroy a scheduler, and tell its child threads to exit.
Definition schedule.c:597
The scheduler.
Definition schedule.c:77
int main(int argc, char *argv[])
static NEVER_RETURNS void usage(void)
#define talloc_autofree_context
The original function is deprecated, so replace it with our version.
Definition talloc.h:55
int fr_time_start(void)
Initialize the local time.
Definition time.c:157