2004-06-24 21:10:31 +00:00
|
|
|
/*--- This software is copyrighted by the Regents of the University of
|
|
|
|
California, and other parties. The following terms apply to all files
|
|
|
|
associated with the software unless explicitly disclaimed in
|
|
|
|
individual files.
|
|
|
|
|
|
|
|
The authors hereby grant permission to use, copy, modify, distribute,
|
|
|
|
and license this software and its documentation for any purpose,
|
|
|
|
provided that existing copyright notices are retained in all copies
|
|
|
|
and that this notice is included verbatim in any distributions. No
|
|
|
|
written agreement, license, or royalty fee is required for any of the
|
|
|
|
authorized uses. Modifications to this software may be copyrighted by
|
|
|
|
their authors and need not follow the licensing terms described here,
|
|
|
|
provided that the new terms are clearly indicated on the first page of
|
|
|
|
each file where they apply.
|
|
|
|
|
|
|
|
IN NO EVENT SHALL THE AUTHORS OR DISTRIBUTORS BE LIABLE TO ANY PARTY
|
|
|
|
FOR DIRECT, INDIRECT, SPECIAL, INCIDENTAL, OR CONSEQUENTIAL DAMAGES
|
|
|
|
ARISING OUT OF THE USE OF THIS SOFTWARE, ITS DOCUMENTATION, OR ANY
|
|
|
|
DERIVATIVES THEREOF, EVEN IF THE AUTHORS HAVE BEEN ADVISED OF THE
|
|
|
|
POSSIBILITY OF SUCH DAMAGE.
|
|
|
|
|
|
|
|
THE AUTHORS AND DISTRIBUTORS SPECIFICALLY DISCLAIM ANY WARRANTIES,
|
|
|
|
INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
|
|
|
|
MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE, AND
|
|
|
|
NON-INFRINGEMENT. THIS SOFTWARE IS PROVIDED ON AN "AS IS" BASIS, AND
|
|
|
|
THE AUTHORS AND DISTRIBUTORS HAVE NO OBLIGATION TO PROVIDE
|
|
|
|
MAINTENANCE, SUPPORT, UPDATES, ENHANCEMENTS, OR MODIFICATIONS.
|
|
|
|
|
|
|
|
GOVERNMENT USE: If you are acquiring this software on behalf of the
|
|
|
|
U.S. government, the Government shall have only "Restricted Rights" in
|
|
|
|
the software and related documentation as defined in the Federal
|
|
|
|
Acquisition Regulations (FARs) in Clause 52.227.19 (c) (2). If you are
|
|
|
|
acquiring the software on behalf of the Department of Defense, the
|
|
|
|
software shall be classified as "Commercial Computer Software" and the
|
|
|
|
Government shall have only "Restricted Rights" as defined in Clause
|
|
|
|
252.227-7013 (c) (1) of DFARs. Notwithstanding the foregoing, the
|
|
|
|
authors grant the U.S. Government and others acting in its behalf
|
|
|
|
permission to use and distribute the software in accordance with the
|
|
|
|
terms specified in this license.
|
|
|
|
---*/
|
|
|
|
#include <config.h>
|
2004-07-20 03:40:57 +00:00
|
|
|
#include <lladd/common.h>
|
|
|
|
#include <../../src/lladd/latches.h>
|
2004-06-24 21:10:31 +00:00
|
|
|
#include <check.h>
|
|
|
|
#include <assert.h>
|
|
|
|
|
|
|
|
#include <lladd/transactional.h>
|
2004-06-28 21:10:10 +00:00
|
|
|
#include "../check_includes.h"
|
2004-06-24 21:10:31 +00:00
|
|
|
#define LOG_NAME "check_transactional2.log"
|
2004-07-30 01:28:39 +00:00
|
|
|
#define THREAD_COUNT 25
|
|
|
|
#define RECORDS_PER_THREAD 1000
|
2004-07-26 20:37:04 +00:00
|
|
|
|
|
|
|
void arraySet(int * array, int val) {
|
|
|
|
int i;
|
|
|
|
for(i = 0; i < 1024; i++) {
|
|
|
|
array[i] = val;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
int arrayCmp(int * array, int * array2) {
|
|
|
|
int i;
|
|
|
|
for(i = 0; i < 1024; i++) {
|
|
|
|
if(array[i] != array2[i]) {
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return 1;
|
|
|
|
}
|
|
|
|
|
|
|
|
/** Allocate a bunch of blobs, set them, read them, commit them, and read it again, chang them, abort, and read again. */
|
|
|
|
void * writingAbortingBlobWorkerThread ( void * v ) {
|
|
|
|
int offset = * (int *) v;
|
|
|
|
recordid * rids = malloc(RECORDS_PER_THREAD * sizeof(recordid));
|
|
|
|
int xid = Tbegin();
|
|
|
|
for(int i = 0; i < RECORDS_PER_THREAD; i++) {
|
|
|
|
rids[i] = /* ralloc(xid, sizeof(int)); */ Talloc(xid, 1024 * sizeof(int));
|
|
|
|
if(! (i %100)) {
|
|
|
|
printf("A%d", i/100);fflush(NULL);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
for(int i = 0; i < RECORDS_PER_THREAD; i++) {
|
|
|
|
int tmp[1024];/* = i + offset; */
|
|
|
|
arraySet(tmp, i+ offset);
|
|
|
|
Tset(xid, rids[i], tmp);
|
|
|
|
if(! (i %100)) {
|
|
|
|
printf("W%d", i/100); fflush(NULL);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
Tcommit(xid);
|
|
|
|
xid = Tbegin();
|
|
|
|
|
|
|
|
|
|
|
|
for(int i = 0; i < RECORDS_PER_THREAD; i++) {
|
|
|
|
int j[1024];
|
|
|
|
int k[1024];
|
|
|
|
arraySet(k, i+offset);
|
|
|
|
Tread(xid, rids[i], j);
|
|
|
|
assert(arrayCmp(j,k));/*i + offset == j); */
|
|
|
|
if(! (i %100)) {
|
|
|
|
printf("R%d", i/100);fflush(NULL);
|
|
|
|
}
|
|
|
|
arraySet(k, -1);
|
|
|
|
Tset(xid, rids[i], k);/*(void*)&minusOne); */
|
|
|
|
}
|
|
|
|
|
|
|
|
Tabort(xid);
|
|
|
|
|
|
|
|
xid = Tbegin();
|
|
|
|
|
|
|
|
for(int i = 0; i < RECORDS_PER_THREAD; i++) {
|
|
|
|
int j[1024];
|
|
|
|
int k[1024];
|
|
|
|
arraySet(k, i+offset);
|
|
|
|
Tread(xid, rids[i], j);
|
|
|
|
assert(arrayCmp(j,k));
|
|
|
|
if(! (i %100)) {
|
|
|
|
printf("S%d", i/100);fflush(NULL);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
Tcommit(xid);
|
2004-07-27 01:04:35 +00:00
|
|
|
free(rids);
|
2004-07-26 20:37:04 +00:00
|
|
|
return NULL;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
2004-07-20 03:40:57 +00:00
|
|
|
|
|
|
|
/** Allocate a bunch of stuff, set it, read it, commit it, and read it again. */
|
2004-07-26 20:37:04 +00:00
|
|
|
void * writingAbortingWorkerThread ( void * v ) {
|
2004-07-20 03:40:57 +00:00
|
|
|
int offset = * (int *) v;
|
|
|
|
recordid * rids = malloc(RECORDS_PER_THREAD * sizeof(recordid));
|
|
|
|
int xid = Tbegin();
|
|
|
|
for(int i = 0; i < RECORDS_PER_THREAD; i++) {
|
2004-07-23 20:21:44 +00:00
|
|
|
rids[i] = /* ralloc(xid, sizeof(int)); */ Talloc(xid, sizeof(int));
|
2004-07-26 20:37:04 +00:00
|
|
|
if(! (i %100)) {
|
|
|
|
printf("A%d", i/100);fflush(NULL);
|
2004-07-20 03:40:57 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
for(int i = 0; i < RECORDS_PER_THREAD; i++) {
|
|
|
|
int tmp = i + offset;
|
2004-07-23 20:21:44 +00:00
|
|
|
|
2004-07-20 03:40:57 +00:00
|
|
|
Tset(xid, rids[i], &tmp);
|
2004-07-26 20:37:04 +00:00
|
|
|
if(! (i %100)) {
|
|
|
|
printf("W%d", i/100); fflush(NULL);
|
2004-07-20 03:40:57 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2004-07-26 20:37:04 +00:00
|
|
|
Tcommit(xid);
|
|
|
|
xid = Tbegin();
|
|
|
|
|
|
|
|
|
2004-07-20 03:40:57 +00:00
|
|
|
for(int i = 0; i < RECORDS_PER_THREAD; i++) {
|
|
|
|
int j;
|
2004-07-26 20:37:04 +00:00
|
|
|
int minusOne = -1;
|
2004-07-23 20:21:44 +00:00
|
|
|
|
2004-07-26 20:37:04 +00:00
|
|
|
Tread(xid, rids[i], &j);
|
|
|
|
assert(i + offset == j);
|
|
|
|
if(! (i %100)) {
|
|
|
|
printf("R%d", i/100);fflush(NULL);
|
|
|
|
}
|
|
|
|
Tset(xid, rids[i], (void*)&minusOne);
|
|
|
|
}
|
|
|
|
|
|
|
|
Tabort(xid);
|
2004-07-23 20:21:44 +00:00
|
|
|
|
2004-07-26 20:37:04 +00:00
|
|
|
xid = Tbegin();
|
|
|
|
|
|
|
|
for(int i = 0; i < RECORDS_PER_THREAD; i++) {
|
|
|
|
int j;
|
|
|
|
Tread(xid, rids[i], &j);
|
|
|
|
assert(i + offset == j);
|
|
|
|
if(! (i %100)) {
|
|
|
|
printf("S%d", i/100);fflush(NULL);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
Tcommit(xid);
|
2004-07-27 01:04:35 +00:00
|
|
|
|
|
|
|
free (rids);
|
|
|
|
|
2004-07-26 20:37:04 +00:00
|
|
|
return NULL;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/** Allocate a bunch of stuff, set it, read it, commit it, and read it again. */
|
|
|
|
void * writingWorkerThread ( void * v ) {
|
|
|
|
int offset = * (int *) v;
|
|
|
|
recordid * rids = malloc(RECORDS_PER_THREAD * sizeof(recordid));
|
|
|
|
int xid = Tbegin();
|
|
|
|
for(int i = 0; i < RECORDS_PER_THREAD; i++) {
|
|
|
|
rids[i] = /* ralloc(xid, sizeof(int)); */ Talloc(xid, sizeof(int));
|
|
|
|
if(! (i %100)) {
|
|
|
|
printf("A%d", i/100);fflush(NULL);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
for(int i = 0; i < RECORDS_PER_THREAD; i++) {
|
|
|
|
int tmp = i + offset;
|
2004-07-23 20:21:44 +00:00
|
|
|
|
2004-07-26 20:37:04 +00:00
|
|
|
Tset(xid, rids[i], &tmp);
|
|
|
|
if(! (i %100)) {
|
|
|
|
printf("W%d", i/100); fflush(NULL);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
for(int i = 0; i < RECORDS_PER_THREAD; i++) {
|
|
|
|
int j;
|
2004-07-23 20:21:44 +00:00
|
|
|
|
|
|
|
Tread(xid, rids[i], &j);
|
2004-07-20 03:40:57 +00:00
|
|
|
assert(i + offset == j);
|
2004-07-26 20:37:04 +00:00
|
|
|
if(! (i %100)) {
|
|
|
|
printf("R%d", i/100);fflush(NULL);
|
2004-07-20 03:40:57 +00:00
|
|
|
}
|
|
|
|
}
|
2004-07-23 20:21:44 +00:00
|
|
|
|
2004-07-20 03:40:57 +00:00
|
|
|
Tcommit(xid);
|
2004-07-23 20:21:44 +00:00
|
|
|
|
2004-07-20 03:40:57 +00:00
|
|
|
xid = Tbegin();
|
|
|
|
|
|
|
|
for(int i = 0; i < RECORDS_PER_THREAD; i++) {
|
|
|
|
int j;
|
|
|
|
Tread(xid, rids[i], &j);
|
|
|
|
assert(i + offset == j);
|
2004-07-26 20:37:04 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
Tcommit(xid);
|
2004-07-27 01:04:35 +00:00
|
|
|
free(rids);
|
|
|
|
|
2004-07-20 03:40:57 +00:00
|
|
|
return NULL;
|
|
|
|
}
|
|
|
|
|
2004-06-24 21:10:31 +00:00
|
|
|
/**
|
2004-07-26 20:37:04 +00:00
|
|
|
@test
|
2004-06-24 21:10:31 +00:00
|
|
|
Assuming that the Tset() operation is implemented correctly, checks
|
|
|
|
that doUpdate, redoUpdate and undoUpdate are working correctly, for
|
|
|
|
operations that use physical logging.
|
|
|
|
*/
|
|
|
|
START_TEST(transactional_smokeTest) {
|
|
|
|
|
|
|
|
int xid;
|
|
|
|
recordid rid;
|
|
|
|
int foo = 2;
|
|
|
|
int bar;
|
|
|
|
|
|
|
|
Tinit();
|
|
|
|
|
|
|
|
xid = Tbegin();
|
|
|
|
|
|
|
|
rid = Talloc(xid, sizeof(int));
|
|
|
|
|
|
|
|
Tset(xid, rid, &foo);
|
|
|
|
|
|
|
|
bar = 4;
|
|
|
|
|
|
|
|
Tread(xid, rid, &bar);
|
|
|
|
|
|
|
|
fail_unless(bar == foo, NULL);
|
|
|
|
|
|
|
|
Tcommit(xid);
|
|
|
|
|
|
|
|
xid = Tbegin();
|
|
|
|
|
|
|
|
bar = 4;
|
|
|
|
Tread(xid, rid, &bar);
|
|
|
|
fail_unless(bar == foo, NULL);
|
|
|
|
|
|
|
|
|
|
|
|
Tabort(xid);
|
|
|
|
|
|
|
|
Tdeinit();
|
|
|
|
}
|
|
|
|
END_TEST
|
|
|
|
|
2004-06-28 21:10:10 +00:00
|
|
|
/**
|
2004-07-26 20:37:04 +00:00
|
|
|
@test
|
2004-06-28 21:10:10 +00:00
|
|
|
Just like transactional_smokeTest, but check blobs instead.
|
|
|
|
*/
|
|
|
|
START_TEST(transactional_blobSmokeTest) {
|
|
|
|
|
|
|
|
#define ARRAY_SIZE 10000
|
|
|
|
int xid;
|
|
|
|
recordid rid;
|
|
|
|
int foo[ARRAY_SIZE];
|
|
|
|
int bar[ARRAY_SIZE];
|
|
|
|
int i;
|
|
|
|
for(i = 0; i < ARRAY_SIZE; i++) {
|
|
|
|
foo[i] = i;
|
|
|
|
bar[i] = 2 * i;
|
|
|
|
}
|
|
|
|
|
|
|
|
Tinit();
|
|
|
|
|
|
|
|
xid = Tbegin();
|
|
|
|
|
|
|
|
rid = Talloc(xid, ARRAY_SIZE * sizeof(int));
|
|
|
|
|
|
|
|
fail_unless(rid.size == ARRAY_SIZE * sizeof(int), NULL);
|
|
|
|
|
|
|
|
Tset(xid, rid, &foo);
|
|
|
|
|
|
|
|
Tread(xid, rid, &bar);
|
|
|
|
|
|
|
|
for(i = 0 ; i < ARRAY_SIZE; i++) {
|
|
|
|
assert(bar[i] == foo[i]);
|
|
|
|
fail_unless(bar[i] == foo[i], NULL);
|
|
|
|
}
|
|
|
|
|
|
|
|
Tcommit(xid);
|
|
|
|
|
|
|
|
xid = Tbegin();
|
|
|
|
|
|
|
|
for(i = 0; i < ARRAY_SIZE; i++) {
|
|
|
|
bar[i] = 2 * i;
|
|
|
|
}
|
|
|
|
|
|
|
|
Tread(xid, rid, &bar);
|
|
|
|
|
|
|
|
|
|
|
|
for(i = 0 ; i < ARRAY_SIZE; i++) {
|
|
|
|
fail_unless(bar[i] == foo[i], NULL);
|
|
|
|
}
|
|
|
|
|
|
|
|
Tabort(xid);
|
|
|
|
|
|
|
|
Tdeinit();
|
|
|
|
}
|
|
|
|
END_TEST
|
|
|
|
|
2004-07-26 20:37:04 +00:00
|
|
|
/**
|
|
|
|
@test
|
|
|
|
Make sure that the single threaded version of transactional_threads_commit passes.
|
|
|
|
*/
|
2004-07-20 03:40:57 +00:00
|
|
|
START_TEST(transactional_nothreads_commit) {
|
|
|
|
int five = 5;
|
|
|
|
Tinit();
|
|
|
|
writingWorkerThread(&five);
|
|
|
|
Tdeinit();
|
|
|
|
} END_TEST
|
|
|
|
|
2004-07-26 20:37:04 +00:00
|
|
|
/**
|
|
|
|
@test
|
|
|
|
Test LLADD in a multi-threaded envrionment, where every transaction commits.
|
|
|
|
*/
|
2004-07-20 03:40:57 +00:00
|
|
|
START_TEST(transactional_threads_commit) {
|
|
|
|
pthread_t workers[THREAD_COUNT];
|
|
|
|
int i;
|
|
|
|
|
|
|
|
Tinit();
|
|
|
|
|
|
|
|
for(i = 0; i < THREAD_COUNT; i++) {
|
|
|
|
int arg = i + 100;
|
|
|
|
pthread_create(&workers[i], NULL, writingWorkerThread, &arg);
|
|
|
|
|
|
|
|
}
|
|
|
|
for(i = 0; i < THREAD_COUNT; i++) {
|
|
|
|
pthread_join(workers[i], NULL);
|
|
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
Tdeinit();
|
|
|
|
} END_TEST
|
|
|
|
|
2004-07-26 20:37:04 +00:00
|
|
|
/**
|
|
|
|
@test
|
|
|
|
Make sure that the single threaded version of transactional_threads_abort passes.
|
|
|
|
*/
|
|
|
|
START_TEST(transactional_nothreads_abort) {
|
|
|
|
int five = 5;
|
|
|
|
Tinit();
|
|
|
|
writingAbortingWorkerThread(&five);
|
|
|
|
Tdeinit();
|
|
|
|
} END_TEST
|
|
|
|
|
|
|
|
/**
|
|
|
|
@test
|
|
|
|
Test LLADD in a multi-threaded envrionment, with a mix of transaction commits and aborts.
|
|
|
|
*/
|
|
|
|
START_TEST(transactional_threads_abort) {
|
|
|
|
pthread_t workers[THREAD_COUNT];
|
|
|
|
int i;
|
|
|
|
|
|
|
|
Tinit();
|
|
|
|
|
|
|
|
for(i = 0; i < THREAD_COUNT; i++) {
|
|
|
|
int arg = i + 100;
|
|
|
|
pthread_create(&workers[i], NULL, writingAbortingWorkerThread, &arg);
|
|
|
|
|
|
|
|
}
|
|
|
|
for(i = 0; i < THREAD_COUNT; i++) {
|
|
|
|
pthread_join(workers[i], NULL);
|
|
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
Tdeinit();
|
|
|
|
} END_TEST
|
|
|
|
|
|
|
|
/**
|
|
|
|
@test
|
|
|
|
Make sure that the single threaded version of transactional_threads_abort passes.
|
|
|
|
*/
|
|
|
|
START_TEST(transactional_blobs_nothreads_abort) {
|
|
|
|
int five = 5;
|
|
|
|
Tinit();
|
|
|
|
writingAbortingBlobWorkerThread(&five);
|
|
|
|
Tdeinit();
|
|
|
|
} END_TEST
|
|
|
|
|
|
|
|
/**
|
|
|
|
@test
|
|
|
|
Test LLADD in a multi-threaded envrionment, with a mix of transaction commits and aborts.
|
|
|
|
*/
|
|
|
|
START_TEST(transactional_blobs_threads_abort) {
|
|
|
|
pthread_t workers[THREAD_COUNT];
|
|
|
|
int i;
|
|
|
|
|
|
|
|
Tinit();
|
|
|
|
|
|
|
|
for(i = 0; i < THREAD_COUNT; i++) {
|
|
|
|
int arg = i + 100;
|
|
|
|
pthread_create(&workers[i], NULL, writingAbortingBlobWorkerThread, &arg);
|
|
|
|
|
|
|
|
}
|
|
|
|
for(i = 0; i < THREAD_COUNT; i++) {
|
|
|
|
pthread_join(workers[i], NULL);
|
|
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
Tdeinit();
|
|
|
|
} END_TEST
|
|
|
|
|
2004-06-24 21:10:31 +00:00
|
|
|
/**
|
|
|
|
Add suite declarations here
|
|
|
|
*/
|
|
|
|
Suite * check_suite(void) {
|
|
|
|
Suite *s = suite_create("transactional");
|
|
|
|
/* Begin a new test */
|
|
|
|
TCase *tc = tcase_create("transactional_smokeTest");
|
|
|
|
|
|
|
|
/* Sub tests are added, one per line, here */
|
2004-07-30 01:28:39 +00:00
|
|
|
tcase_add_test(tc, transactional_smokeTest);
|
|
|
|
tcase_add_test(tc, transactional_blobSmokeTest);
|
|
|
|
tcase_add_test(tc, transactional_nothreads_commit);
|
|
|
|
tcase_add_test(tc, transactional_threads_commit);
|
|
|
|
tcase_add_test(tc, transactional_nothreads_abort);
|
2004-07-26 20:37:59 +00:00
|
|
|
tcase_add_test(tc, transactional_threads_abort);
|
2004-07-26 20:37:04 +00:00
|
|
|
tcase_add_test(tc, transactional_blobs_nothreads_abort);
|
2004-07-27 21:30:54 +00:00
|
|
|
/* tcase_add_test(tc, transactional_blobs_threads_abort); */
|
2004-06-24 21:10:31 +00:00
|
|
|
/* --------------------------------------------- */
|
2004-06-28 21:10:10 +00:00
|
|
|
tcase_add_checked_fixture(tc, setup, teardown);
|
2004-06-24 21:10:31 +00:00
|
|
|
suite_add_tcase(s, tc);
|
|
|
|
|
|
|
|
|
|
|
|
return s;
|
|
|
|
}
|
|
|
|
|
|
|
|
#include "../check_setup.h"
|