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",
#define AST_MODULE_INFO_STANDARD(keystr, desc)
Asterisk locking-related definitions:
Asterisk main include file. File version handling, generic pbx functions.
int ao2_container_count(struct ao2_container *c)
Returns the number of elements in a container.
Time-related functions and macros.
#define ao2_callback(c, flags, cb_fn, arg)
Generic (perhaps overly so) hashtable implementation Hash Table support in Asterisk.
static int compare_strings(void *lhs, void *rhs, int flags)
#define AST_TEST_REGISTER(cb)
struct timeval ast_tvnow(void)
Returns current timeval. Meant to replace calls to gettimeofday().
AST_TEST_DEFINE(hash_test)
static int load_module(void)
int ast_atomic_fetchadd_int(volatile int *p, int v)
Atomically add v to *p and return the previous value of *p.
static int hash_string(const void *obj, const int flags)
static int unload_module(void)
#define ast_test_status_update(a, b, c...)
static void * hash_test_grow(void *d)
#define ao2_ref(o, delta)
#define ao2_container_alloc_hash(ao2_options, container_options, n_buckets, hash_fn, sort_fn, cmp_fn)
#define AST_TEST_UNREGISTER(cb)
struct timeval ast_tvadd(struct timeval a, struct timeval b)
Returns the sum of two timevals a + b.
#define ao2_alloc(data_size, destructor_fn)
#define ast_pthread_create(a, b, c, d)
static void * hash_test_lookup(void *d)
#define ao2_find(container, arg, flags)
static char * ht_new(int i)
struct timeval ast_tv(ast_time_t sec, ast_suseconds_t usec)
Returns a timeval from sec, usec.
static void ht_delete(void *obj)
struct ao2_container * to_be_thrashed
int64_t ast_tvdiff_us(struct timeval end, struct timeval start)
Computes the difference (in microseconds) between two struct timeval instances.
static void * hash_test_shrink(void *d)
unsigned int ast_hashtab_hash_string_nocase(const void *obj)
Hashes a string to a number ignoring case.
#define ASTERISK_GPL_KEY
The text the key() function should return.
Asterisk module definitions.
static void * hash_test_count(void *d)
static int increment_count(void *obj, void *arg, int flags)
static int is_timed_out(struct hash_test const *data)
#define ao2_link(container, obj)