summaryrefslogtreecommitdiff
path: root/storage/maria/unittest
diff options
context:
space:
mode:
authorunknown <serg@janus.mylan>2006-10-19 12:21:30 +0200
committerunknown <serg@janus.mylan>2006-10-19 12:21:30 +0200
commitaea73116c14da8e946422de8e49c93acc85817d0 (patch)
tree252ce34b5fba783866d0c64615d1cd53164de88b /storage/maria/unittest
parent12a55aeabc353fdc1c3829ddd8baacb142160c80 (diff)
downloadmariadb-git-aea73116c14da8e946422de8e49c93acc85817d0.tar.gz
post-review fixes (style)
include/lf.h: comments
Diffstat (limited to 'storage/maria/unittest')
-rw-r--r--storage/maria/unittest/lockman-t.c97
-rw-r--r--storage/maria/unittest/trnman-t.c31
2 files changed, 66 insertions, 62 deletions
diff --git a/storage/maria/unittest/lockman-t.c b/storage/maria/unittest/lockman-t.c
index 638078fea65..ad382a360fb 100644
--- a/storage/maria/unittest/lockman-t.c
+++ b/storage/maria/unittest/lockman-t.c
@@ -42,16 +42,20 @@ LOCK_OWNER *loid2lo(uint16 loid)
return loarray+loid-1;
}
-#define unlock_all(O) diag("lo" #O "> release all locks"); \
+#define unlock_all(O) diag("lo" #O "> release all locks"); \
lockman_release_locks(&lockman, loid2lo(O));print_lockhash(&lockman)
-#define test_lock(O, R, L, S, RES) \
- ok(lockman_getlock(&lockman, loid2lo(O), R, L) == RES, \
- "lo" #O "> " S " lock resource " #R " with " #L "-lock"); \
+#define test_lock(O, R, L, S, RES) \
+ ok(lockman_getlock(&lockman, loid2lo(O), R, L) == RES, \
+ "lo" #O "> " S " lock resource " #R " with " #L "-lock"); \
print_lockhash(&lockman)
-#define lock_ok_a(O,R,L) test_lock(O,R,L,"",GOT_THE_LOCK)
-#define lock_ok_i(O,R,L) test_lock(O,R,L,"",GOT_THE_LOCK_NEED_TO_LOCK_A_SUBRESOURCE)
-#define lock_ok_l(O,R,L) test_lock(O,R,L,"",GOT_THE_LOCK_NEED_TO_INSTANT_LOCK_A_SUBRESOURCE)
-#define lock_conflict(O,R,L) test_lock(O,R,L,"cannot ",DIDNT_GET_THE_LOCK);
+#define lock_ok_a(O, R, L) \
+ test_lock(O, R, L, "", GOT_THE_LOCK)
+#define lock_ok_i(O, R, L) \
+ test_lock(O, R, L, "", GOT_THE_LOCK_NEED_TO_LOCK_A_SUBRESOURCE)
+#define lock_ok_l(O, R, L) \
+ test_lock(O, R, L, "", GOT_THE_LOCK_NEED_TO_INSTANT_LOCK_A_SUBRESOURCE)
+#define lock_conflict(O, R, L) \
+ test_lock(O, R, L, "cannot ", DIDNT_GET_THE_LOCK);
void test_lockman_simple()
{
@@ -63,41 +67,41 @@ void test_lockman_simple()
lock_ok_a(1, 1, X);
lock_ok_i(2, 2, IX);
/* failures */
- lock_conflict(2,1,X);
+ lock_conflict(2, 1, X);
unlock_all(2);
- lock_ok_a(1,2,S);
- lock_ok_a(1,2,IS);
- lock_ok_a(1,2,LS);
- lock_ok_i(1,3,IX);
- lock_ok_a(2,3,LS);
- lock_ok_i(1,3,IX);
- lock_ok_l(2,3,IS);
+ lock_ok_a(1, 2, S);
+ lock_ok_a(1, 2, IS);
+ lock_ok_a(1, 2, LS);
+ lock_ok_i(1, 3, IX);
+ lock_ok_a(2, 3, LS);
+ lock_ok_i(1, 3, IX);
+ lock_ok_l(2, 3, IS);
unlock_all(1);
unlock_all(2);
- lock_ok_i(1,1,IX);
- lock_conflict(2,1,S);
- lock_ok_a(1,1,LS);
+ lock_ok_i(1, 1, IX);
+ lock_conflict(2, 1, S);
+ lock_ok_a(1, 1, LS);
unlock_all(1);
unlock_all(2);
- lock_ok_i(1,1,IX);
- lock_ok_a(2,1,LS);
- lock_ok_a(1,1,LS);
- lock_ok_i(1,1,IX);
- lock_ok_i(3,1,IS);
+ lock_ok_i(1, 1, IX);
+ lock_ok_a(2, 1, LS);
+ lock_ok_a(1, 1, LS);
+ lock_ok_i(1, 1, IX);
+ lock_ok_i(3, 1, IS);
unlock_all(1);
unlock_all(2);
unlock_all(3);
- lock_ok_i(1,4,IS);
- lock_ok_i(2,4,IS);
- lock_ok_i(3,4,IS);
- lock_ok_a(3,4,LS);
- lock_ok_i(4,4,IS);
- lock_conflict(4,4,IX);
- lock_conflict(2,4,IX);
- lock_ok_a(1,4,LS);
+ lock_ok_i(1, 4, IS);
+ lock_ok_i(2, 4, IS);
+ lock_ok_i(3, 4, IS);
+ lock_ok_a(3, 4, LS);
+ lock_ok_i(4, 4, IS);
+ lock_conflict(4, 4, IX);
+ lock_conflict(2, 4, IX);
+ lock_ok_a(1, 4, LS);
unlock_all(1);
unlock_all(2);
unlock_all(3);
@@ -110,7 +114,7 @@ pthread_mutex_t rt_mutex;
pthread_cond_t rt_cond;
int rt_num_threads;
int litmus;
-int thread_number= 0, timeouts=0;
+int thread_number= 0, timeouts= 0;
void run_test(const char *test, pthread_handler handler, int n, int m)
{
pthread_t t;
@@ -121,7 +125,8 @@ void run_test(const char *test, pthread_handler handler, int n, int m)
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);
+ if (pthread_create(&t, &rt_attr, handler, &m))
+ abort();
pthread_mutex_lock(&rt_mutex);
while (rt_num_threads)
pthread_cond_wait(&rt_cond, &rt_mutex);
@@ -133,9 +138,9 @@ void run_test(const char *test, pthread_handler handler, int n, int m)
int Nrows= 100;
int Ntables= 10;
int table_lock_ratio= 10;
-enum lock_type lock_array[6]={S,X,LS,LX,IS,IX};
-char *lock2str[6]={"S","X","LS","LX","IS","IX"};
-char *res2str[4]={
+enum lock_type lock_array[6]= {S, X, LS, LX, IS, IX};
+char *lock2str[6]= {"S", "X", "LS", "LX", "IS", "IX"};
+char *res2str[4]= {
"DIDN'T GET THE LOCK",
"GOT THE LOCK",
"GOT THE LOCK NEED TO LOCK A SUBRESOURCE",
@@ -160,12 +165,12 @@ pthread_handler_t test_lockman(void *arg)
if (table_lock_ratio && (x/Nrows/4) % table_lock_ratio == 0)
{ /* table lock */
res= lockman_getlock(&lockman, lo, table, lock_array[locklevel]);
- DIAG(("loid=%2d, table %d lock %s, res=%s", loid, table,
+ DIAG(("loid %2d, table %d, lock %s, res %s", loid, table,
lock2str[locklevel], res2str[res]));
if (res == DIDNT_GET_THE_LOCK)
{
lockman_release_locks(&lockman, lo);
- DIAG(("loid=%2d, release all locks", loid));
+ DIAG(("loid %2d, release all locks", loid));
timeout++;
continue;
}
@@ -175,13 +180,13 @@ pthread_handler_t test_lockman(void *arg)
{ /* row lock */
locklevel&= 1;
res= lockman_getlock(&lockman, lo, table, lock_array[locklevel + 4]);
- DIAG(("loid=%2d, row %d lock %s, res=%s", loid, row,
+ DIAG(("loid %2d, row %d, lock %s, res %s", loid, row,
lock2str[locklevel+4], res2str[res]));
switch (res)
{
case DIDNT_GET_THE_LOCK:
lockman_release_locks(&lockman, lo);
- DIAG(("loid=%2d, release all locks", loid));
+ DIAG(("loid %2d, release all locks", loid));
timeout++;
continue;
case GOT_THE_LOCK:
@@ -190,12 +195,12 @@ pthread_handler_t test_lockman(void *arg)
/* not implemented, so take a regular lock */
case GOT_THE_LOCK_NEED_TO_LOCK_A_SUBRESOURCE:
res= lockman_getlock(&lockman, lo, row, lock_array[locklevel]);
- DIAG(("loid=%2d, ROW %d lock %s, res=%s", loid, row,
+ DIAG(("loid %2d, ROW %d, lock %s, res %s", loid, row,
lock2str[locklevel], res2str[res]));
if (res == DIDNT_GET_THE_LOCK)
{
lockman_release_locks(&lockman, lo);
- DIAG(("loid=%2d, release all locks", loid));
+ DIAG(("loid %2d, release all locks", loid));
timeout++;
continue;
}
@@ -234,7 +239,7 @@ int main()
return exit_status();
pthread_attr_init(&rt_attr);
- pthread_attr_setdetachstate(&rt_attr,PTHREAD_CREATE_DETACHED);
+ pthread_attr_setdetachstate(&rt_attr, PTHREAD_CREATE_DETACHED);
pthread_mutex_init(&rt_mutex, 0);
pthread_cond_init(&rt_cond, 0);
@@ -261,13 +266,13 @@ int main()
Nrows= 100;
Ntables= 10;
table_lock_ratio= 10;
- run_test("lockman", test_lockman, THREADS,CYCLES);
+ run_test("lockman", test_lockman, THREADS, CYCLES);
/* "real-life" simulation - many rows, no table locks */
Nrows= 1000000;
Ntables= 10;
table_lock_ratio= 0;
- run_test("lockman", test_lockman, THREADS,10000);
+ run_test("lockman", test_lockman, THREADS, 10000);
for (i= 0; i < Nlos; i++)
{
diff --git a/storage/maria/unittest/trnman-t.c b/storage/maria/unittest/trnman-t.c
index 6d4b48c6d3d..7bde9f5f720 100644
--- a/storage/maria/unittest/trnman-t.c
+++ b/storage/maria/unittest/trnman-t.c
@@ -41,7 +41,7 @@ pthread_handler_t test_trnman(void *arg)
pthread_mutex_t mutexes[MAX_ITER];
pthread_cond_t conds[MAX_ITER];
- for (i=0; i < MAX_ITER; i++)
+ for (i= 0; i < MAX_ITER; i++)
{
pthread_mutex_init(&mutexes[i], MY_MUTEX_INIT_FAST);
pthread_cond_init(&conds[i], 0);
@@ -60,7 +60,7 @@ pthread_handler_t test_trnman(void *arg)
}
}
- for (i=0; i < MAX_ITER; i++)
+ for (i= 0; i < MAX_ITER; i++)
{
pthread_mutex_destroy(&mutexes[i]);
pthread_cond_destroy(&conds[i]);
@@ -84,7 +84,8 @@ void run_test(const char *test, pthread_handler handler, int n, int m)
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);
+ if (pthread_create(&t, &rt_attr, handler, &m))
+ abort();
pthread_mutex_lock(&rt_mutex);
while (rt_num_threads)
pthread_cond_wait(&rt_cond, &rt_mutex);
@@ -94,11 +95,10 @@ void run_test(const char *test, pthread_handler handler, int n, int m)
}
#define ok_read_from(T1, T2, RES) \
- i=trnman_can_read_from(trn[T1], trid[T2]); \
+ i= trnman_can_read_from(trn[T1], trn[T2]->trid); \
ok(i == RES, "trn" #T1 " %s read from trn" #T2, i ? "can" : "cannot")
#define start_transaction(T) \
- trn[T]= trnman_new_trn(&mutexes[T], &conds[T]); \
- trid[T]= trn[T]->trid
+ trn[T]= trnman_new_trn(&mutexes[T], &conds[T])
#define commit(T) trnman_commit_trn(trn[T])
#define abort(T) trnman_abort_trn(trn[T])
@@ -106,12 +106,11 @@ void run_test(const char *test, pthread_handler handler, int n, int m)
void test_trnman_read_from()
{
TRN *trn[Ntrns];
- TrID trid[Ntrns];
pthread_mutex_t mutexes[Ntrns];
pthread_cond_t conds[Ntrns];
int i;
- for (i=0; i < Ntrns; i++)
+ for (i= 0; i < Ntrns; i++)
{
pthread_mutex_init(&mutexes[i], MY_MUTEX_INIT_FAST);
pthread_cond_init(&conds[i], 0);
@@ -119,19 +118,19 @@ void test_trnman_read_from()
start_transaction(0); /* start trn1 */
start_transaction(1); /* start trn2 */
- ok_read_from(1,0,0);
+ ok_read_from(1, 0, 0);
commit(0); /* commit trn1 */
start_transaction(2); /* start trn4 */
abort(2); /* abort trn4 */
start_transaction(3); /* start trn5 */
- ok_read_from(3,0,1);
- ok_read_from(3,1,0);
- ok_read_from(3,2,0);
+ ok_read_from(3, 0, 1);
+ ok_read_from(3, 1, 0);
+ ok_read_from(3, 2, 0);
commit(1); /* commit trn2 */
- ok_read_from(3,1,0);
+ ok_read_from(3, 1, 0);
commit(3); /* commit trn5 */
- for (i=0; i < Ntrns; i++)
+ for (i= 0; i < Ntrns; i++)
{
pthread_mutex_destroy(&mutexes[i]);
pthread_cond_destroy(&conds[i]);
@@ -148,7 +147,7 @@ int main()
return exit_status();
pthread_attr_init(&rt_attr);
- pthread_attr_setdetachstate(&rt_attr,PTHREAD_CREATE_DETACHED);
+ pthread_attr_setdetachstate(&rt_attr, PTHREAD_CREATE_DETACHED);
pthread_mutex_init(&rt_mutex, 0);
pthread_cond_init(&rt_cond, 0);
@@ -158,7 +157,7 @@ int main()
trnman_init();
test_trnman_read_from();
- run_test("trnman", test_trnman, THREADS,CYCLES);
+ run_test("trnman", test_trnman, THREADS, CYCLES);
diag("mallocs: %d", trnman_allocated_transactions);
{