diff options
author | unknown <serg@janus.mylan> | 2006-08-17 15:20:58 +0200 |
---|---|---|
committer | unknown <serg@janus.mylan> | 2006-08-17 15:20:58 +0200 |
commit | 74d050d000ff9db79e36931988386fe7988f8dd2 (patch) | |
tree | c1314972c00652cda1f4feaca6bee4aeaf330fb7 /unittest | |
parent | d1a8a2c7345847fc750c2d36908913dedb052c9c (diff) | |
download | mariadb-git-74d050d000ff9db79e36931988386fe7988f8dd2.tar.gz |
maria transaction manager with unit tests
include/lf.h:
few lf API changes
mysys/lf_alloc-pin.c:
few lf API changes
mysys/lf_dynarray.c:
few lf API changes
mysys/lf_hash.c:
few lf API changes
storage/maria/Makefile.am:
transaction manager
unittest/Makefile.am:
maria transaction manager
unittest/mysys/my_atomic-t.c:
ensure that values are positive
storage/maria/trxman.h:
New BitKeeper file ``storage/maria/trxman.h''
unittest/maria/Makefile.am:
New BitKeeper file ``unittest/maria/Makefile.am''
unittest/maria/trxman-t.c:
New BitKeeper file ``unittest/maria/trxman-t.c''
storage/maria/trxman.c:
comment clarified
Diffstat (limited to 'unittest')
-rw-r--r-- | unittest/Makefile.am | 4 | ||||
-rw-r--r-- | unittest/maria/Makefile.am | 12 | ||||
-rw-r--r-- | unittest/maria/trxman-t.c | 138 | ||||
-rw-r--r-- | unittest/mysys/my_atomic-t.c | 17 |
4 files changed, 159 insertions, 12 deletions
diff --git a/unittest/Makefile.am b/unittest/Makefile.am index ca3291efde0..295ecd7186f 100644 --- a/unittest/Makefile.am +++ b/unittest/Makefile.am @@ -1,10 +1,10 @@ -SUBDIRS = mytap . mysys examples +SUBDIRS = mytap mysys maria examples noinst_SCRIPTS = unit EXTRA_DIST = unit.pl CLEANFILES = unit -unittests = mytap mysys +unittests = mytap mysys maria test: unit ./unit run $(unittests) diff --git a/unittest/maria/Makefile.am b/unittest/maria/Makefile.am new file mode 100644 index 00000000000..667d1e09a07 --- /dev/null +++ b/unittest/maria/Makefile.am @@ -0,0 +1,12 @@ + +AM_CPPFLAGS = @ZLIB_INCLUDES@ -I$(top_builddir)/include +AM_CPPFLAGS += -I$(top_srcdir)/include -I$(top_srcdir)/unittest/mytap + +LDADD = $(top_builddir)/unittest/mytap/libmytap.a \ + $(top_builddir)/storage/maria/libmaria.a \ + $(top_builddir)/mysys/libmysys.a \ + $(top_builddir)/dbug/libdbug.a \ + $(top_builddir)/strings/libmystrings.a + +noinst_PROGRAMS = trxman-t + diff --git a/unittest/maria/trxman-t.c b/unittest/maria/trxman-t.c new file mode 100644 index 00000000000..a29bf5abc8e --- /dev/null +++ b/unittest/maria/trxman-t.c @@ -0,0 +1,138 @@ +/* Copyright (C) 2006 MySQL AB + + 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 + the Free Software Foundation; either version 2 of the License, or + (at your option) any later version. + + This program is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + GNU General Public License for more details. + + You should have received a copy of the GNU General Public License + along with this program; if not, write to the Free Software + Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA */ + +#include <tap.h> + +#include <my_global.h> +#include <my_sys.h> +#include <my_atomic.h> +#include <lf.h> +#include "../../storage/maria/trxman.h" + +pthread_attr_t rt_attr; +pthread_mutex_t rt_mutex; +pthread_cond_t rt_cond; +int rt_num_threads; + +int litmus; + +/* template for a test: the goal is to have litmus==0 if the test passed + +#define ITER nnn +pthread_handler_t test_XXXXXXXX(void *arg) +{ + int m=(*(int *)arg)/ITER, x; + + for (x=((int)(intptr)(&m)); m ; m--) + { + // do something with litmus + } + // do something more with litmus + + pthread_mutex_lock(&rt_mutex); + rt_num_threads--; + if (!rt_num_threads) + { + diag("whatever diagnostics we want", blabla, foobar); + pthread_cond_signal(&rt_cond); + } + pthread_mutex_unlock(&rt_mutex); + return 0; +} +#undef ITER + +*/ + +/* + create and end (commit or rollback) transactions randomly +*/ +#define MAX_ITER 100 +pthread_handler_t test_trxman(void *arg) +{ + int m=(*(int *)arg); + uint x, y, i, j, n; + TRX *trx[MAX_ITER]; + + for (x=((int)(intptr)(&m)); m > 0; ) + { + y= x= (x*3628273133 + 1500450271) % 9576890767; /* three prime numbers */ + m-= n= x % MAX_ITER; + for (i=0; i < n; i++) + trx[i]=trxman_new_trx(); + for (i=0; i < n; i++) + { + y=(y*19 + 7) % 31; + trxman_end_trx(trx[i], y & 1); + } + } + + pthread_mutex_lock(&rt_mutex); + rt_num_threads--; + if (!rt_num_threads) + pthread_cond_signal(&rt_cond); + pthread_mutex_unlock(&rt_mutex); + return 0; +} +#undef MAX_ITER + +void run_test(const char *test, pthread_handler handler, int n, int m) +{ + pthread_t t; + ulonglong now=my_getsystime(); + + litmus= 0; + + diag("Testing %s with %d threads, %d iterations... ", test, n, m); + for (rt_num_threads=n ; n ; n--) + pthread_create(&t, &rt_attr, handler, &m); + pthread_mutex_lock(&rt_mutex); + while (rt_num_threads) + pthread_cond_wait(&rt_cond, &rt_mutex); + pthread_mutex_unlock(&rt_mutex); + now=my_getsystime()-now; + ok(litmus == 0, "tested %s in %g secs (%d)", test, ((double)now)/1e7, litmus); +} + +int global_malloc=0; +int main() +{ + plan(1); + + if (my_atomic_initialize()) + return exit_status(); + + my_init(); + + pthread_attr_init(&rt_attr); + pthread_attr_setdetachstate(&rt_attr,PTHREAD_CREATE_DETACHED); + pthread_mutex_init(&rt_mutex, 0); + pthread_cond_init(&rt_cond, 0); + +#define CYCLES 10000 +#define THREADS 10 + + trxman_init(); + run_test("trxman", test_trxman, THREADS,CYCLES); + trxman_destroy(); + diag("mallocs: %d\n", global_malloc); + + pthread_mutex_destroy(&rt_mutex); + pthread_cond_destroy(&rt_cond); + pthread_attr_destroy(&rt_attr); + my_end(0); + return exit_status(); +} + diff --git a/unittest/mysys/my_atomic-t.c b/unittest/mysys/my_atomic-t.c index 1e7206441eb..8962131d45a 100644 --- a/unittest/mysys/my_atomic-t.c +++ b/unittest/mysys/my_atomic-t.c @@ -14,9 +14,6 @@ along with this program; if not, write to the Free Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA */ -//#define MY_ATOMIC_MODE_RWLOCKS -//#define MY_ATOMIC_MODE_DUMMY - #include <tap.h> #include <my_global.h> @@ -41,7 +38,7 @@ pthread_handler_t test_atomic_add_handler(void *arg) int32 x; for (x=((int)(intptr)(&m)); m ; m--) { - x=x*m+0x87654321; + x=(x*m+0x87654321) & INT_MAX32; my_atomic_rwlock_wrlock(&rwl); my_atomic_add32(&a32, x); my_atomic_rwlock_wrunlock(&rwl); @@ -111,7 +108,7 @@ pthread_handler_t test_atomic_cas_handler(void *arg) my_atomic_rwlock_wrlock(&rwl); y=my_atomic_load32(&a32); my_atomic_rwlock_wrunlock(&rwl); - x=x*m+0x87654321; + x=(x*m+0x87654321) & INT_MAX32; do { my_atomic_rwlock_wrlock(&rwl); ok=my_atomic_cas32(&a32, &y, y+x); @@ -171,7 +168,7 @@ pthread_handler_t test_lf_alloc(void *arg) for (x=((int)(intptr)(&m)); m ; m--) { TLA *node1, *node2; - x=x*m+0x87654321; + x=(x*m+0x87654321) & INT_MAX32; node1=(TLA *)lf_alloc_new(pins); node1->data=x; y+=node1->data; @@ -217,7 +214,7 @@ pthread_handler_t test_lf_hash(void *arg) y=x; for (i=0; i < N_TLH; i++) { - x=x*(m+i)+0x87654321; + x=(x*(m+i)+0x87654321) & INT_MAX32; z=(x<0) ? -x : x; if (lf_hash_insert(&lf_hash, pins, &z)) { @@ -227,7 +224,7 @@ pthread_handler_t test_lf_hash(void *arg) } for (i=0; i < N_TLH; i++) { - y=y*(m+i)+0x87654321; + y=(y*(m+i)+0x87654321) & INT_MAX32; z=(y<0) ? -y : y; if (lf_hash_delete(&lf_hash, pins, (uchar *)&z, sizeof(z))) sum-=z; @@ -307,8 +304,8 @@ int main() test_atomic("lf_alloc", test_lf_alloc, THREADS,CYCLES); test_atomic("lf_hash", test_lf_hash, THREADS,CYCLES); - lf_hash_end(&lf_hash); - lf_alloc_end(&lf_allocator); + lf_hash_destroy(&lf_hash); + lf_alloc_destroy(&lf_allocator); pthread_mutex_destroy(&mutex); pthread_cond_destroy(&cond); pthread_attr_destroy(&thr_attr); |