summaryrefslogtreecommitdiff
path: root/unittest
diff options
context:
space:
mode:
authorSergei Golubchik <serg@mysql.com>2009-01-15 22:27:36 +0100
committerSergei Golubchik <serg@mysql.com>2009-01-15 22:27:36 +0100
commit9c96fde1206f254d0dd25dbe2cc1706c44e4bdea (patch)
treefdc0957f7f6b91f43a88bc18e6c37c7fd94fa911 /unittest
parente01f6c8971c5598ea4868bb62bf6eb81a3bab945 (diff)
downloadmariadb-git-9c96fde1206f254d0dd25dbe2cc1706c44e4bdea.tar.gz
post-review fixes
include/atomic/generic-msvc.h: prevent possible compiler warnings include/lf.h: comments, better definition for LF_HASH_OVERHEAD include/maria.h: define MARIA_CANNOT_ROLLBACK here include/my_pthread.h: avoid possible name clash include/waiting_threads.h: comments, const, move WT_RESOURCE to waiting_threads.c mysql-test/suite/maria/r/maria_notembedded.result: new test mysql-test/suite/maria/t/maria_notembedded.test: new test - 5-way deadlock mysys/lf_hash.c: better definition for LF_HASH_OVERHEAD mysys/my_static.c: comment mysys/my_thr_init.c: casts mysys/waiting_threads.c: comments, asserts, etc server-tools/instance-manager/parse.cc: fix my_init_dynamic_array() to follow new calling conventions sql/mysqld.cc: call wt_init after set_proper_floating_point_mode sql/sql_class.h: comment storage/maria/ha_maria.cc: move MARIA_CANNOT_ROLLBACK to a common header storage/maria/ma_commit.c: comment storage/maria/ma_write.c: comments, check for HA_ERR_FOUND_DUPP_KEY storage/maria/trnman.c: comments, assert storage/maria/trnman.h: comments storage/maria/unittest/trnman-t.c: be paranoid unittest/mysys/lf-t.c: comments unittest/mysys/waiting_threads-t.c: comments, safety, memory leak
Diffstat (limited to 'unittest')
-rw-r--r--unittest/mysys/lf-t.c12
-rw-r--r--unittest/mysys/my_atomic-t.c2
-rw-r--r--unittest/mysys/thr_template.c2
-rw-r--r--unittest/mysys/waiting_threads-t.c26
4 files changed, 27 insertions, 15 deletions
diff --git a/unittest/mysys/lf-t.c b/unittest/mysys/lf-t.c
index 1a424c19e22..61b7ae08cf5 100644
--- a/unittest/mysys/lf-t.c
+++ b/unittest/mysys/lf-t.c
@@ -1,4 +1,4 @@
-/* Copyright (C) 2006 MySQL AB
+/* Copyright (C) 2008-2008 MySQL AB, 2008-2009 Sun Microsystems, Inc.
This program is free software; you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
@@ -13,6 +13,12 @@
along with this program; if not, write to the Free Software
Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA */
+/**
+ @file
+
+ Unit tests for lock-free algorithms of mysys
+*/
+
#include "thr_template.c"
#include <lf.h>
@@ -47,6 +53,10 @@ pthread_handler_t test_lf_pinbox(void *arg)
return 0;
}
+/*
+ thread local data area, allocated using lf_alloc.
+ union is required to enforce the minimum required element size (sizeof(ptr))
+*/
typedef union {
int32 data;
void *not_used;
diff --git a/unittest/mysys/my_atomic-t.c b/unittest/mysys/my_atomic-t.c
index 26591ad35d2..b98f3379a4a 100644
--- a/unittest/mysys/my_atomic-t.c
+++ b/unittest/mysys/my_atomic-t.c
@@ -1,4 +1,4 @@
-/* Copyright (C) 2006 MySQL AB
+/* Copyright (C) 2006-2008 MySQL AB, 2008 Sun Microsystems, Inc.
This program is free software; you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
diff --git a/unittest/mysys/thr_template.c b/unittest/mysys/thr_template.c
index 900abb2f736..1ac03e474fd 100644
--- a/unittest/mysys/thr_template.c
+++ b/unittest/mysys/thr_template.c
@@ -1,4 +1,4 @@
-/* Copyright (C) 2006 MySQL AB
+/* Copyright (C) 2006-2008 MySQL AB, 2008 Sun Microsystems, Inc.
This program is free software; you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
diff --git a/unittest/mysys/waiting_threads-t.c b/unittest/mysys/waiting_threads-t.c
index 953b02f3eb9..157835087b5 100644
--- a/unittest/mysys/waiting_threads-t.c
+++ b/unittest/mysys/waiting_threads-t.c
@@ -1,4 +1,4 @@
-/* Copyright (C) 2006 MySQL AB
+/* Copyright (C) 2008 MySQL AB, 2008-2009 Sun Microsystems, Inc.
This program is free software; you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
@@ -16,7 +16,6 @@
#include "thr_template.c"
#include <waiting_threads.h>
#include <m_string.h>
-#include <locale.h>
struct test_wt_thd {
WT_THD thd;
@@ -31,6 +30,7 @@ ulong wt_timeout_long=10000, wt_deadlock_search_depth_long=15;
#define reset(ARRAY) bzero(ARRAY, sizeof(ARRAY))
+/* see explanation of the kill strategies in waiting_threads.h */
enum { LATEST, RANDOM, YOUNGEST, LOCKS } kill_strategy;
WT_RESOURCE_TYPE restype={ wt_resource_id_memcmp, 0};
@@ -68,13 +68,14 @@ pthread_handler_t test_wt(void *arg)
res= 0;
+ /* prepare for waiting for a random number of random threads */
for (j= n= (rnd() % THREADS)/10; !res && j >= 0; j--)
{
retry:
- i= rnd() % (THREADS-1);
- if (i >= id) i++;
+ i= rnd() % (THREADS-1); /* pick a random thread */
+ if (i >= id) i++; /* with a number from 0 to THREADS-1 excluding ours */
- for (k=n; k >=j; k--)
+ for (k=n; k >=j; k--) /* the one we didn't pick before */
if (blockers[k] == i)
goto retry;
blockers[j]= i;
@@ -121,7 +122,7 @@ retry:
#define DEL "(deleted)"
char *x=malloc(strlen(thds[id].thd.name)+sizeof(DEL)+1);
strxmov(x, thds[id].thd.name, DEL, 0);
- thds[id].thd.name=x; /* it's a memory leak, go on, shoot me */
+ thds[id].thd.name=x;
}
#endif
@@ -165,8 +166,8 @@ void do_one_test()
void do_tests()
{
- plan(12);
- compile_time_assert(THREADS >= 3);
+ plan(14);
+ compile_time_assert(THREADS >= 4);
DBUG_PRINT("wt", ("================= initialization ==================="));
@@ -206,22 +207,22 @@ void do_tests()
pthread_mutex_lock(&lock);
bad= wt_thd_cond_timedwait(& thds[0].thd, &lock);
pthread_mutex_unlock(&lock);
- ok(bad == ETIMEDOUT, "timeout test returned %d", bad);
+ ok(bad == WT_TIMEOUT, "timeout test returned %d", bad);
ok_wait(0,1,0);
ok_wait(1,2,1);
ok_deadlock(2,0,2);
pthread_mutex_lock(&lock);
- wt_thd_cond_timedwait(& thds[0].thd, &lock);
- wt_thd_cond_timedwait(& thds[1].thd, &lock);
+ ok(wt_thd_cond_timedwait(& thds[0].thd, &lock) == WT_TIMEOUT, "as always");
+ ok(wt_thd_cond_timedwait(& thds[1].thd, &lock) == WT_TIMEOUT, "as always");
wt_thd_release_all(& thds[0].thd);
wt_thd_release_all(& thds[1].thd);
wt_thd_release_all(& thds[2].thd);
wt_thd_release_all(& thds[3].thd);
pthread_mutex_unlock(&lock);
- for (cnt=0; cnt < 3; cnt++)
+ for (cnt=0; cnt < 4; cnt++)
{
wt_thd_destroy(& thds[cnt].thd);
wt_thd_lazy_init(& thds[cnt].thd,
@@ -261,6 +262,7 @@ void do_tests()
wt_thd_release_all(& thds[cnt].thd);
wt_thd_destroy(& thds[cnt].thd);
pthread_mutex_destroy(& thds[cnt].lock);
+ free(thds[cnt].thd.name);
}
pthread_mutex_unlock(&lock);
wt_end();