47#define MAX_HASH_ENTRIES 15000
52#define HASH_BUCKETS 151
54#define COUNT_SLEEP_US 500
55#define MAX_TEST_SECONDS 60
85 const int buflen = 12;
91 needed = snprintf(keybuf, buflen,
"key%08x", (
unsigned)i);
103 for (i = 0; i < data->
max_grow; ++i) {
106 printf(
"Growth timed out at %d\n", i);
107 return "Growth timed out";
111 return "Allocation failed";
125 unsigned seed = time(
NULL);
136 return "Lookup timed out";
146 i = rand_r(&seed) %
max;
149 return "Allocation failed";
154 if (from_ao2 ==
NULL) {
155 return "Key unexpectedly missing";
168 for (i = 1; i < data->
preload; ++i) {
173 return "Allocation failed";
181 return "Could not find object to delete";
185 return "Shrink timed out";
196 if (strncmp(ht,
"key0", 4) == 0) {
214 if (last_count == count) {
217 }
else if (last_count > count) {
219 return "ao2 container unexpectedly shrank";
223 return "Count timed out";
238 const char *lhs_str = lhs;
239 const char *rhs_str = rhs;
240 if (strcasecmp(lhs_str, rhs_str) == 0) {
251 pthread_t grow_thread, count_thread, lookup_thread, shrink_thread;
252 void *thread_results;
257 info->name =
"thrash";
258 info->category =
"/main/astobj2/";
259 info->summary =
"Testing astobj2 container concurrency";
260 info->description =
"Test astobj2 container concurrency correctness.";
280 for (i = 1; i < data.
preload; ++i) {
300 pthread_join(grow_thread, &thread_results);
301 if (thread_results !=
NULL) {
303 (
char *)thread_results);
307 pthread_join(count_thread, &thread_results);
308 if (thread_results !=
NULL) {
310 (
char *)thread_results);
314 pthread_join(lookup_thread, &thread_results);
315 if (thread_results !=
NULL) {
317 (
char *)thread_results);
321 pthread_join(shrink_thread, &thread_results);
322 if (thread_results !=
NULL) {
324 (
char *)thread_results);
330 "Invalid ao2 container size. Expected: %d, Actual: %d\n",
Asterisk main include file. File version handling, generic pbx functions.
#define ao2_link(container, obj)
Add an object to a container.
@ AO2_ALLOC_OPT_LOCK_MUTEX
#define ao2_callback(c, flags, cb_fn, arg)
ao2_callback() is a generic function that applies cb_fn() to all objects in a container,...
int ao2_container_count(struct ao2_container *c)
Returns the number of elements in a container.
#define ao2_find(container, arg, flags)
#define ao2_ref(o, delta)
Reference/unreference an object and return the old refcount.
#define ao2_alloc(data_size, destructor_fn)
#define ao2_container_alloc_hash(ao2_options, container_options, n_buckets, hash_fn, sort_fn, cmp_fn)
Allocate and initialize a hash container with the desired number of buckets.
Generic (perhaps overly so) hashtable implementation Hash Table support in Asterisk.
unsigned int ast_hashtab_hash_string_nocase(const void *obj)
Hashes a string to a number ignoring case.
Asterisk locking-related definitions:
int ast_atomic_fetchadd_int(volatile int *p, int v)
Atomically add v to *p and return the previous value of *p.
Asterisk module definitions.
#define AST_MODULE_INFO_STANDARD(keystr, desc)
#define ASTERISK_GPL_KEY
The text the key() function should return.
@ AST_MODULE_LOAD_SUCCESS
struct ao2_container * to_be_thrashed
#define AST_TEST_REGISTER(cb)
#define ast_test_status_update(a, b, c...)
#define AST_TEST_UNREGISTER(cb)
static void * hash_test_lookup(void *d)
static void * hash_test_shrink(void *d)
static int is_timed_out(struct hash_test const *data)
static void ht_delete(void *obj)
Free test element.
static int increment_count(void *obj, void *arg, int flags)
static void * hash_test_count(void *d)
static int compare_strings(void *lhs, void *rhs, int flags)
AST_TEST_DEFINE(hash_test)
static int hash_string(const void *obj, const int flags)
static char * ht_new(int i)
Create test element.
static int load_module(void)
static int unload_module(void)
static void * hash_test_grow(void *d)
Grow the hash data as specified.
Time-related functions and macros.
int64_t ast_tvdiff_us(struct timeval end, struct timeval start)
Computes the difference (in microseconds) between two struct timeval instances.
struct timeval ast_tvadd(struct timeval a, struct timeval b)
Returns the sum of two timevals a + b.
struct timeval ast_tvnow(void)
Returns current timeval. Meant to replace calls to gettimeofday().
struct timeval ast_tv(ast_time_t sec, ast_suseconds_t usec)
Returns a timeval from sec, usec.
#define ast_pthread_create(a, b, c, d)