The FreeRADIUS server  $Id: 15bac2a4c627c01d1aa2047687b3418955ac7f00 $
schedule_test.c
Go to the documentation of this file.
1 /*
2  * schedule_test.c Tests for the scheduler
3  *
4  * Version: $Id: 848ad9d7760d336c923d3ca8b3e059135a24fe72 $
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 
23 RCSID("$Id: 848ad9d7760d336c923d3ca8b3e059135a24fe72 $")
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/debug.h>
29 #include <freeradius-devel/util/inet.h>
30 #include <freeradius-devel/util/md5.h>
31 #include <freeradius-devel/util/syserror.h>
32 
33 #include <sys/event.h>
34 #include <stdio.h>
35 #include <string.h>
36 #include <pthread.h>
37 
38 #ifdef HAVE_GETOPT_H
39 # include <getopt.h>
40 #endif
41 
42 
43 static int debug_lvl = 0;
44 
45 static NEVER_RETURNS void usage(void)
46 {
47  fprintf(stderr, "usage: schedule_test [OPTS]\n");
48  fprintf(stderr, " -n <num> Start num network threads\n");
49  fprintf(stderr, " -w <num> Start num worker threads\n");
50  fprintf(stderr, " -x Debugging mode.\n");
51 
52  fr_exit_now(EXIT_FAILURE);
53 }
54 
55 int main(int argc, char *argv[])
56 {
57  int c;
58  int num_networks = 1;
59  int num_workers = 2;
60  TALLOC_CTX *autofree = talloc_autofree_context();
61  fr_schedule_t *sched;
62 
63  fr_time_start();
64 
66 
67  while ((c = getopt(argc, argv, "n:w:x")) != -1) switch (c) {
68  case 'n':
69  num_networks = atoi(optarg);
70  if ((num_networks <= 0) || (num_networks > 16)) usage();
71  break;
72 
73  case 'w':
74  num_workers = atoi(optarg);
75  if ((num_workers <= 0) || (num_workers > 1024)) usage();
76  break;
77 
78  case 'x':
79  debug_lvl++;
80  fr_debug_lvl++;
81  break;
82 
83  case 'h':
84  default:
85  usage();
86  }
87 
88 #if 0
89  argc -= (optind - 1);
90  argv += (optind - 1);
91 #endif
92 
93  sched = fr_schedule_create(autofree, NULL, &default_log, L_DBG_LVL_MAX, num_networks, num_workers, NULL, NULL);
94  if (!sched) {
95  fprintf(stderr, "schedule_test: Failed to create scheduler\n");
96  fr_exit_now(EXIT_FAILURE);
97  }
98 
99  sleep(1);
100 
101  (void) fr_schedule_destroy(&sched);
102 
103  return 0;
104 }
#define RCSID(id)
Definition: build.h:444
#define NEVER_RETURNS
Should be placed before the function return type.
Definition: build.h:311
#define fr_exit_now(_x)
Exit without calling atexit() handlers, producing a log message in debug builds.
Definition: debug.h:232
int fr_log_init_legacy(fr_log_t *log, bool daemonize)
Initialise file descriptors based on logging destination.
Definition: log.c:923
int fr_debug_lvl
Definition: log.c:42
fr_log_t default_log
Definition: log.c:290
@ L_DBG_LVL_MAX
Lowest priority debug messages (-xxxxx | -Xxxx).
Definition: log.h:74
static TALLOC_CTX * autofree
Definition: radclient-ng.c:104
static int num_workers
Definition: radius1_test.c:70
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:409
int fr_schedule_destroy(fr_schedule_t **sc_to_free)
Destroy a scheduler, and tell its child threads to exit.
Definition: schedule.c:703
The scheduler.
Definition: schedule.c:125
int main(int argc, char *argv[])
Definition: schedule_test.c:55
static NEVER_RETURNS void usage(void)
Definition: schedule_test.c:45
static int debug_lvl
Definition: schedule_test.c:43
#define talloc_autofree_context
The original function is deprecated, so replace it with our version.
Definition: talloc.h:51
int fr_time_start(void)
Initialize the local time.
Definition: time.c:150