23RCSID(
"$Id: e814fcdb0537af7bc1e7863f31dd14eb312ef5ce $")
25#include <freeradius-devel/io/atomic_queue.h>
26#include <freeradius-devel/util/debug.h>
27#include <freeradius-devel/util/table.h>
66 fprintf(stderr,
"usage: atomic_queue_test [OPTS]\n");
67 fprintf(stderr,
" -s size set queue size.\n");
68 fprintf(stderr,
" -t type queue type to test, 'talloc' or 'malloc' (default: both).\n");
69 fprintf(stderr,
" -x Debugging mode.\n");
89 if (
debug_lvl > 1) printf(
"Filling with %d\n", size);
95 for (i = 0; i < size; i++) {
100 fprintf(stderr,
"Failed pushing at %d\n", i);
106 printf(
"iteration %d\n", i);
119 fprintf(stderr,
"Pushed an entry past the end of the queue.");
135 for (i = 0; i < size; i++) {
137 fprintf(stderr,
"Failed popping at %d\n", i);
141 val = (intptr_t)
data;
142 if (val != (i +
OFFSET)) {
143 fprintf(stderr,
"Pop expected %d, got %d\n",
150 printf(
"iteration %d\n", i);
160 fprintf(stderr,
"Popped an entry past the end of the queue.");
180 fprintf(stderr,
"Failed allocating talloc queue\n");
197 TALLOC_CTX *owner_ctx;
199 owner_ctx = talloc_new(ctx);
202 fprintf(stderr,
"Failed allocating raw queue\n");
206 if (talloc_total_blocks(owner_ctx) != 2) {
207 fprintf(stderr,
"Expected owner handle to be the only child of ctx, found %zu blocks\n",
208 talloc_total_blocks(owner_ctx));
223int main(
int argc,
char *argv[])
229 bool any_selected =
false;
234 while ((c = getopt(argc, argv,
"hs:t:x")) != -1)
switch (c) {
242 fprintf(stderr,
"Unknown queue type '%s'\n", optarg);
245 selected[
type] =
true;
258 argc -= (optind - 1);
259 argv += (optind - 1);
263 if (any_selected && !selected[
type])
continue;
fr_atomic_queue_t * fr_atomic_queue_malloc(TALLOC_CTX *ctx, size_t size)
Create fixed-size atomic queue outside the talloc hierarchy, owned by a talloc context.
bool fr_atomic_queue_pop(fr_atomic_queue_t *aq, void **p_data)
Pop a pointer from the atomic queue.
void fr_atomic_queue_debug(FILE *fp, fr_atomic_queue_t *aq)
Dump an atomic queue.
bool fr_atomic_queue_push(fr_atomic_queue_t *aq, void *data)
Push a pointer into the atomic queue.
void fr_atomic_queue_free(fr_atomic_queue_t **aq)
Free an atomic queue if it's not freed by ctx.
fr_atomic_queue_t * fr_atomic_queue_talloc(TALLOC_CTX *ctx, size_t size)
Create fixed-size atomic queue.
Structure to hold the atomic queue.
int main(int argc, char *argv[])
static void test_malloc(TALLOC_CTX *ctx, int size)
Queue allocated outside talloc, but owned by a talloc context.
static fr_table_num_sorted_t const queue_type_table[]
static void queue_exercise(fr_atomic_queue_t *aq, int size)
Fill the queue to capacity, check it refuses one more, then drain it.
static size_t queue_type_table_len
void(* queue_test_t)(TALLOC_CTX *ctx, int size)
static queue_test_t const queue_tests[QUEUE_TYPE_MAX]
static void test_talloc(TALLOC_CTX *ctx, int size)
Queue allocated inside the talloc hierarchy.
queue_type_t
Which allocator the queue under test comes from.
@ QUEUE_TYPE_MALLOC
fr_atomic_queue_malloc, raw queue owned by a talloc handle.
@ QUEUE_TYPE_TALLOC
fr_atomic_queue_talloc, queue lives in the talloc hierarchy.
static NEVER_RETURNS void usage(void)
void request_verify(UNUSED char const *file, UNUSED int line, UNUSED request_t *request)
static uint8_t request[4]
#define NEVER_RETURNS
Should be placed before the function return type.
#define L(_str)
Helper for initialising arrays of string literals.
static fr_atomic_queue_t ** aq
#define fr_exit_now(_x)
Exit without calling atexit() handlers, producing a log message in debug builds.
fr_aka_sim_id_type_t type
#define fr_table_value_by_str(_table, _name, _def)
Convert a string to a value using a sorted or ordered table.
#define fr_table_str_by_value(_table, _number, _def)
Convert an integer to a string.
An element in a lexicographically sorted array of name to num mappings.
#define talloc_autofree_context
The original function is deprecated, so replace it with our version.