summaryrefslogtreecommitdiff
path: root/unittest
diff options
context:
space:
mode:
authorSergei Golubchik <serg@mariadb.org>2018-12-29 23:44:45 +0100
committerSergei Golubchik <serg@mariadb.org>2018-12-29 23:44:45 +0100
commitaeefd26ecb1089678e343c64998749e9f2e3a1e4 (patch)
treea96f5fdff65a6d0a05d195a74a32bbb4aa0a58c1 /unittest
parent50c9469be821e1942a8a9c5f37132e1855c40c86 (diff)
parent802ce9672ff630bbef08235e0e39bf599075f985 (diff)
downloadmariadb-git-aeefd26ecb1089678e343c64998749e9f2e3a1e4.tar.gz
Merge branch '10.0' into 10.1
Diffstat (limited to 'unittest')
-rw-r--r--unittest/mysys/lf-t.c5
-rw-r--r--unittest/mysys/my_atomic-t.c17
-rw-r--r--unittest/mysys/thr_template.c31
-rw-r--r--unittest/mysys/waiting_threads-t.c4
4 files changed, 11 insertions, 46 deletions
diff --git a/unittest/mysys/lf-t.c b/unittest/mysys/lf-t.c
index cb0c2853d13..80f58856940 100644
--- a/unittest/mysys/lf-t.c
+++ b/unittest/mysys/lf-t.c
@@ -48,9 +48,6 @@ pthread_handler_t test_lf_pinbox(void *arg)
pins= lf_pinbox_get_pins(&lf_allocator.pinbox);
}
lf_pinbox_put_pins(pins);
- pthread_mutex_lock(&mutex);
- if (!--running_threads) pthread_cond_signal(&cond);
- pthread_mutex_unlock(&mutex);
if (with_my_thread_init)
my_thread_end();
@@ -105,7 +102,6 @@ pthread_handler_t test_lf_alloc(void *arg)
bad|= lf_allocator.mallocs - lf_alloc_pool_count(&lf_allocator);
#endif
}
- if (!--running_threads) pthread_cond_signal(&cond);
pthread_mutex_unlock(&mutex);
if (with_my_thread_init)
@@ -172,7 +168,6 @@ pthread_handler_t test_lf_hash(void *arg)
lf_hash.size, inserts, scans);
bad|= lf_hash.count;
}
- if (!--running_threads) pthread_cond_signal(&cond);
pthread_mutex_unlock(&mutex);
if (with_my_thread_init)
my_thread_end();
diff --git a/unittest/mysys/my_atomic-t.c b/unittest/mysys/my_atomic-t.c
index 0f21c33455e..3198da6836d 100644
--- a/unittest/mysys/my_atomic-t.c
+++ b/unittest/mysys/my_atomic-t.c
@@ -29,9 +29,6 @@ pthread_handler_t test_atomic_add(void *arg)
my_atomic_add32(&bad, x);
my_atomic_add32(&bad, -x);
}
- pthread_mutex_lock(&mutex);
- if (!--running_threads) pthread_cond_signal(&cond);
- pthread_mutex_unlock(&mutex);
return 0;
}
@@ -47,13 +44,6 @@ pthread_handler_t test_atomic_add64(void *arg)
my_atomic_add64(&a64, x);
my_atomic_add64(&a64, -x);
}
- pthread_mutex_lock(&mutex);
- if (!--running_threads)
- {
- bad= (a64 != 0);
- pthread_cond_signal(&cond);
- }
- pthread_mutex_unlock(&mutex);
return 0;
}
@@ -83,9 +73,6 @@ pthread_handler_t test_atomic_fas(void *arg)
my_atomic_add32(&bad, -x);
- pthread_mutex_lock(&mutex);
- if (!--running_threads) pthread_cond_signal(&cond);
- pthread_mutex_unlock(&mutex);
return 0;
}
@@ -109,9 +96,6 @@ pthread_handler_t test_atomic_cas(void *arg)
ok= my_atomic_cas32(&bad, &y, y-x);
} while (!ok) ;
}
- pthread_mutex_lock(&mutex);
- if (!--running_threads) pthread_cond_signal(&cond);
- pthread_mutex_unlock(&mutex);
return 0;
}
@@ -146,4 +130,5 @@ void do_tests()
}
a64=0;
test_concurrently("my_atomic_add64", test_atomic_add64, THREADS, CYCLES);
+ bad= (a64 != 0);
}
diff --git a/unittest/mysys/thr_template.c b/unittest/mysys/thr_template.c
index 38999022da0..de68aca6d36 100644
--- a/unittest/mysys/thr_template.c
+++ b/unittest/mysys/thr_template.c
@@ -20,35 +20,34 @@
#include <tap.h>
volatile uint32 bad;
-pthread_attr_t thr_attr;
pthread_mutex_t mutex;
-pthread_cond_t cond;
-uint running_threads;
void do_tests();
void test_concurrently(const char *test, pthread_handler handler, int n, int m)
{
- pthread_t t;
+ pthread_t *threads= malloc(n * sizeof(pthread_t));
+ int i;
ulonglong now= my_interval_timer();
+ assert(threads);
bad= 0;
diag("Testing %s with %d threads, %d iterations... ", test, n, m);
- for (running_threads= n ; n ; n--)
+ for (i= n; i; i--)
{
- if (pthread_create(&t, &thr_attr, handler, &m) != 0)
+ if (pthread_create(&threads[i], 0, handler, &m) != 0)
{
diag("Could not create thread");
abort();
}
}
- pthread_mutex_lock(&mutex);
- while (running_threads)
- pthread_cond_wait(&cond, &mutex);
- pthread_mutex_unlock(&mutex);
+
+ for (i= n; i; i--)
+ pthread_join(threads[i], 0);
now= my_interval_timer() - now;
+ free(threads);
ok(!bad, "tested %s in %g secs (%d)", test, ((double)now)/1e9, bad);
}
@@ -60,9 +59,6 @@ int main(int argc __attribute__((unused)), char **argv)
DBUG_SET_INITIAL(argv[1]);
pthread_mutex_init(&mutex, 0);
- pthread_cond_init(&cond, 0);
- pthread_attr_init(&thr_attr);
- pthread_attr_setdetachstate(&thr_attr,PTHREAD_CREATE_DETACHED);
#define CYCLES 3000
#define THREADS 30
@@ -71,16 +67,7 @@ int main(int argc __attribute__((unused)), char **argv)
do_tests();
- /*
- workaround until we know why it crashes randomly on some machine
- (BUG#22320).
- */
-#ifdef NOT_USED
- sleep(2);
-#endif
pthread_mutex_destroy(&mutex);
- pthread_cond_destroy(&cond);
- pthread_attr_destroy(&thr_attr);
my_end(0);
return exit_status();
}
diff --git a/unittest/mysys/waiting_threads-t.c b/unittest/mysys/waiting_threads-t.c
index 56b2f967c00..ac481e0fe99 100644
--- a/unittest/mysys/waiting_threads-t.c
+++ b/unittest/mysys/waiting_threads-t.c
@@ -136,10 +136,8 @@ retry:
pthread_mutex_unlock(&lock);
pthread_mutex_unlock(& thds[id].lock);
wt_thd_destroy(& thds[id].thd);
-
- if (!--running_threads) /* now, signal when everybody is done with deinit */
- pthread_cond_signal(&cond);
pthread_mutex_unlock(&mutex);
+
DBUG_PRINT("wt", ("exiting"));
my_thread_end();
return 0;