Tweak test_hashtab_thrash test to allow the critical threads to execute.
[asterisk/asterisk.git] / tests / test_hashtab_thrash.c
index 373922b..619090a 100644 (file)
@@ -58,10 +58,20 @@ struct hash_test {
        int preload;
        /*! When to give up on the tests */
        struct timeval deadline;
+       /*! The actual test object */
+       struct ast_test *test;
 };
 
 static int is_timed_out(struct hash_test const *data) {
-       return ast_tvdiff_us(data->deadline, ast_tvnow()) < 0;
+       struct timeval now = ast_tvnow();
+       int val = ast_tvdiff_us(data->deadline, now) < 0;
+       if (val) {
+               /* tv_usec is suseconds_t, which could be int or long */
+               ast_test_status_update(data->test, "Now: %ld.%06ld Deadline: %ld.%06ld\n",
+                       now.tv_sec, (long)now.tv_usec,
+                       data->deadline.tv_sec, (long)data->deadline.tv_usec);
+       }
+       return val;
 }
 
 /*! /brief Create test element */
@@ -198,7 +208,7 @@ static void *hash_test_count(void *d)
 
                if (last_count == count) {
                        /* Allow other threads to run. */
-                       sched_yield();
+                       usleep(1);
                } else if (last_count > count) {
                        /* Make sure the hashtable never shrinks */
                        return "hashtab unexpectedly shrank";
@@ -233,6 +243,7 @@ AST_TEST_DEFINE(hash_test)
        }
 
        ast_test_status_update(test, "Executing hash concurrency test...\n");
+       data.test = test;
        data.preload = MAX_HASH_ENTRIES / 2;
        data.max_grow = MAX_HASH_ENTRIES - data.preload;
        data.deadline = ast_tvadd(ast_tvnow(), ast_tv(MAX_TEST_SECONDS, 0));