The FreeRADIUS server $Id: a4e7f8c94e8038b7627bcf52356b7ed15955c1d7 $
Loading...
Searching...
No Matches
Data Structures | Macros | Typedefs | Enumerations | Functions | Variables
control_test.c File Reference
#include <freeradius-devel/server/base.h>
#include <freeradius-devel/io/control.h>
#include <freeradius-devel/util/debug.h>
#include <freeradius-devel/util/rand.h>
#include <freeradius-devel/util/syserror.h>
#include <freeradius-devel/util/talloc.h>
#include <freeradius-devel/util/semaphore.h>
#include <sys/event.h>
#include <sys/socket.h>
#include <pthread.h>
#include <sched.h>
+ Include dependency graph for control_test.c:

Go to the source code of this file.

Data Structures

struct  master_ctx_t
 
struct  my_message_t
 
struct  worker_args_t
 

Macros

#define CONTROL_MAGIC   0xabcd6809
 
#define MEM(x)   do { if (!(x)) { fprintf(stderr, "%s[%d] OUT OF MEMORY\n", __FILE__, __LINE__); _exit(EXIT_FAILURE); } } while (0)
 
#define MPRINT1   if (debug_lvl) printf
 
#define MPRINT2   if (debug_lvl >= 2) printf
 
#define MPRINT3   if (debug_lvl >= 3) printf
 

Typedefs

typedef enum control_test_event_t control_test_event_t
 Events on the test's control planes.
 
typedef enum control_test_socket_event_t control_test_socket_event_t
 Events whose messages carry a socket, numbered separately from those above.
 

Enumerations

enum  control_test_event_t : uint16_t { CONTROL_TEST_MESSAGE = 0 }
 Events on the test's control planes. More...
 
enum  control_test_socket_event_t : uint16_t { CONTROL_TEST_SOCKET = 0 }
 Events whose messages carry a socket, numbered separately from those above. More...
 

Functions

static _Atomic (size_t)
 
static void * control_master (void *arg)
 
static void * control_worker (void *arg)
 
int main (int argc, char *argv[])
 
static void recv_control_callback (void const *data, size_t data_size, UNUSED fr_time_t now, void *uctx)
 
static void recv_socket_callback (int sock, UNUSED fr_time_t now, void *uctx)
 Receive a socket, read the sending worker's id through it, send it back, and close it.
 
static void spin (uint32_t max_usec)
 Busy wait for a random time up to max_usec.
 
static void * watchdog_thread (UNUSED void *arg)
 Fail the test if the master stops receiving.
 

Variables

static int aq_size = 16
 
static fr_control_t ** control = NULL
 
static int debug_lvl = 0
 
static fr_event_list_t * el = NULL
 
static bool el_announces = false
 the master never announces, the event list does it.
 
static bool finished = false
 
static size_t max_messages = 10
 
static uint32_t max_pause_usec = 0
 workers pause up to this long between sends.
 
static size_t num_aq = 1
 
static size_t num_workers = 1
 
static bool single_aq = true
 
static uint32_t watchdog_secs = 30
 fail if the master makes no progress for this long.
 
static pthread_cond_t wd_cond = PTHREAD_COND_INITIALIZER
 
static pthread_mutex_t wd_mutex = PTHREAD_MUTEX_INITIALIZER
 

Data Structure Documentation

◆ master_ctx_t

struct master_ctx_t

Definition at line 109 of file control_test.c.

Data Fields
size_t num_messages
size_t num_sockets

◆ my_message_t

struct my_message_t

Definition at line 103 of file control_test.c.

Data Fields
size_t counter
uint32_t header
size_t worker

◆ worker_args_t

struct worker_args_t

Definition at line 63 of file control_test.c.

Data Fields
size_t id

Macro Definition Documentation

◆ CONTROL_MAGIC

#define CONTROL_MAGIC   0xabcd6809

Definition at line 47 of file control_test.c.

◆ MEM

#define MEM (   x)    do { if (!(x)) { fprintf(stderr, "%s[%d] OUT OF MEMORY\n", __FILE__, __LINE__); _exit(EXIT_FAILURE); } } while (0)

Definition at line 43 of file control_test.c.

◆ MPRINT1

#define MPRINT1   if (debug_lvl) printf

Definition at line 44 of file control_test.c.

◆ MPRINT2

#define MPRINT2   if (debug_lvl >= 2) printf

Definition at line 45 of file control_test.c.

◆ MPRINT3

#define MPRINT3   if (debug_lvl >= 3) printf

Definition at line 46 of file control_test.c.

Typedef Documentation

◆ control_test_event_t

Events on the test's control planes.

The test stands in for the network, and only needs one table.

◆ control_test_socket_event_t

Events whose messages carry a socket, numbered separately from those above.

Enumeration Type Documentation

◆ control_test_event_t

Events on the test's control planes.

The test stands in for the network, and only needs one table.

Enumerator
CONTROL_TEST_MESSAGE 

Definition at line 53 of file control_test.c.

◆ control_test_socket_event_t

Events whose messages carry a socket, numbered separately from those above.

Enumerator
CONTROL_TEST_SOCKET 

one end of a socketpair, with the worker's id in it.

Definition at line 59 of file control_test.c.

Function Documentation

◆ _Atomic()

static _Atomic ( size_t  )
static

Definition at line 82 of file control_test.c.

◆ control_master()

static void * control_master ( void *  arg)
static

Definition at line 215 of file control_test.c.

+ Here is the call graph for this function:

◆ control_worker()

static void * control_worker ( void *  arg)
static

Definition at line 291 of file control_test.c.

+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ main()

int main ( int  argc,
char *  argv[] 
)

Definition at line 395 of file control_test.c.

+ Here is the call graph for this function:

◆ recv_control_callback()

static void recv_control_callback ( void const *  data,
size_t  data_size,
UNUSED fr_time_t  now,
void *  uctx 
)
static

Definition at line 114 of file control_test.c.

+ Here is the caller graph for this function:

◆ recv_socket_callback()

static void recv_socket_callback ( int  sock,
UNUSED fr_time_t  now,
void *  uctx 
)
static

Receive a socket, read the sending worker's id through it, send it back, and close it.

Definition at line 131 of file control_test.c.

+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ spin()

static void spin ( uint32_t  max_usec)
static

Busy wait for a random time up to max_usec.

Deliberately a spin, so the worker never blocks and the master is the only thread which sleeps.

Definition at line 163 of file control_test.c.

+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ watchdog_thread()

static void * watchdog_thread ( UNUSED void *  arg)
static

Fail the test if the master stops receiving.

With the wakeup gated on the master announcing it is blocking, a missed wakeup leaves the master asleep with messages queued, which would otherwise hang the test rather than fail it.

Definition at line 181 of file control_test.c.

+ Here is the caller graph for this function:

Variable Documentation

◆ aq_size

int aq_size = 16
static

Definition at line 70 of file control_test.c.

◆ control

fr_control_t** control = NULL
static

Definition at line 72 of file control_test.c.

◆ debug_lvl

int debug_lvl = 0
static

Definition at line 67 of file control_test.c.

◆ el

fr_event_list_t* el = NULL
static

Definition at line 73 of file control_test.c.

◆ el_announces

bool el_announces = false
static

the master never announces, the event list does it.

Definition at line 71 of file control_test.c.

◆ finished

bool finished = false
static

Definition at line 81 of file control_test.c.

◆ max_messages

size_t max_messages = 10
static

Definition at line 68 of file control_test.c.

◆ max_pause_usec

uint32_t max_pause_usec = 0
static

workers pause up to this long between sends.

Definition at line 76 of file control_test.c.

◆ num_aq

size_t num_aq = 1
static

Definition at line 75 of file control_test.c.

◆ num_workers

size_t num_workers = 1
static

Definition at line 69 of file control_test.c.

◆ single_aq

bool single_aq = true
static

Definition at line 74 of file control_test.c.

◆ watchdog_secs

uint32_t watchdog_secs = 30
static

fail if the master makes no progress for this long.

Definition at line 77 of file control_test.c.

◆ wd_cond

pthread_cond_t wd_cond = PTHREAD_COND_INITIALIZER
static

Definition at line 80 of file control_test.c.

◆ wd_mutex

pthread_mutex_t wd_mutex = PTHREAD_MUTEX_INITIALIZER
static

Definition at line 79 of file control_test.c.