Commit c4405b71 authored by Bradley C. Kuszmaul's avatar Bradley C. Kuszmaul Committed by Yoni Fogel

Make the ...dbufio tests better. Refs #2633. [t:2633]

git-svn-id: file:///svn/toku/tokudb@20534 c7de825b-a66e-492c-adef-691d508d4ae1
parent 2ef2752c
This diff is collapsed.
......@@ -15,6 +15,10 @@ C_BEGIN
static int event_count, event_count_trigger;
static void my_assert_hook (void) {
fprintf(stderr, "event_count=%d\n", event_count);
}
static void reset_event_counts(void) {
event_count = event_count_trigger = 0;
}
......@@ -76,19 +80,83 @@ static ssize_t bad_pwrite(int fd, const void * bp, size_t len, toku_off_t off) {
return r;
}
static int my_malloc_event = 0;
static FILE *
bad_fdopen(int fd, const char * mode) {
FILE * rval;
event_count++;
if (event_count_trigger == event_count) {
event_hit();
errno = EINVAL;
rval = NULL;
} else {
rval = fdopen(fd, mode);
}
return rval;
}
static FILE *
bad_fopen(const char *filename, const char *mode) {
FILE * rval;
event_count++;
if (event_count_trigger == event_count) {
event_hit();
errno = EINVAL;
rval = NULL;
} else {
rval = fopen(filename, mode);
}
return rval;
}
static int
bad_open(const char *path, int oflag, int mode) {
int rval;
event_count++;
if (event_count_trigger == event_count) {
event_hit();
errno = EINVAL;
rval = -1;
} else {
rval = open(path, oflag, mode);
}
return rval;
}
static int
bad_fclose(FILE * stream) {
int rval;
event_count++;
// Must close the stream even in the "error case" because otherwise there is no way to get the memory back.
rval = fclose(stream);
if (rval==0) {
if (event_count_trigger == event_count) {
errno = ENOSPC;
rval = -1;
}
}
return rval;
}
static int my_malloc_event = 1;
static int my_malloc_count = 0, my_big_malloc_count = 0;
static void reset_my_malloc_counts(void) {
my_malloc_count = my_big_malloc_count = 0;
}
size_t min_malloc_error_size = 0;
static void *my_malloc(size_t n) {
void *caller = __builtin_return_address(0);
if (!((void*)toku_malloc <= caller && caller <= (void*)toku_free))
goto skip;
my_malloc_count++;
if (n >= 64*1024) {
if (n >= min_malloc_error_size) {
my_big_malloc_count++;
if (my_malloc_event) {
caller = __builtin_return_address(1);
......@@ -194,11 +262,6 @@ static void test (const char *directory, BOOL is_error) {
assert(r==0);
}
toku_set_func_malloc(my_malloc);
brtloader_set_os_fwrite(bad_fwrite);
toku_set_func_write(bad_write);
toku_set_func_pwrite(bad_pwrite);
BRTLOADER bl;
DB **XMALLOC_N(N_DEST_DBS, dbs);
const struct descriptor **XMALLOC_N(N_DEST_DBS, descriptors);
......@@ -238,6 +301,7 @@ static void test (const char *directory, BOOL is_error) {
brt_loader_set_poll_function(&bl->poll_callback, loader_poll_callback, NULL);
QUEUE q;
{ int r = queue_create(&q, 1000); assert(r==0); }
DBUFIO_FILESET bfs;
......@@ -265,6 +329,17 @@ static void test (const char *directory, BOOL is_error) {
int r = toku_pthread_create(&consumer, NULL, consumer_thread, (void*)&cthunk);
assert(r==0);
}
toku_set_func_malloc(my_malloc);
brtloader_set_os_fwrite(bad_fwrite);
toku_set_func_write(bad_write);
toku_set_func_pwrite(bad_pwrite);
toku_set_func_fdopen(bad_fdopen);
toku_set_func_fopen(bad_fopen);
toku_set_func_open(bad_open);
toku_set_func_fclose(bad_fclose);
int result = 0;
{
int r = toku_merge_some_files_using_dbufio(TRUE, FIDX_NULL, q, N_SOURCES, bfs, src_fidxs, bl, 0, (DB*)NULL, compare_ints, 10000);
......@@ -279,6 +354,17 @@ static void test (const char *directory, BOOL is_error) {
int r = queue_eof(q);
assert(r==0);
}
toku_set_func_malloc(NULL);
brtloader_set_os_fwrite(NULL);
toku_set_func_write(NULL);
toku_set_func_pwrite(NULL);
toku_set_func_fdopen(NULL);
toku_set_func_fopen(NULL);
toku_set_func_open(NULL);
toku_set_func_fclose(NULL);
do_assert_hook = my_assert_hook;
{
void *vresult;
int r = toku_pthread_join(consumer, &vresult);
......@@ -323,16 +409,18 @@ static void test (const char *directory, BOOL is_error) {
static int usage(const char *progname, int n) {
fprintf(stderr, "Usage:\n %s [-v] [-q] [-r %d] [-s] [-m] directory\n", progname, n);
fprintf(stderr, "Usage:\n %s [-v] [-q] [-r %d] [-s] [-m] [-tend NEVENTS] directory\n", progname, n);
fprintf(stderr, "[-v] turn on verbose\n");
fprintf(stderr, "[-q] turn off verbose\n");
fprintf(stderr, "[-r %d] set the number of rows\n", n);
fprintf(stderr, "[-s] set the small loader size factor\n");
fprintf(stderr, "[-m] inject big malloc failures\n");
fprintf(stderr, "[-tend NEVENTS] stop testing after N events\n");
return 1;
}
int test_main (int argc, const char *argv[]) {
int tend = -1;
const char *progname=argv[0];
argc--; argv++;
while (argc>0) {
......@@ -349,6 +437,9 @@ int test_main (int argc, const char *argv[]) {
toku_brtloader_set_size_factor(1);
} else if (strcmp(argv[0],"-m") == 0) {
my_malloc_event = 1;
} else if (strcmp(argv[0],"-tend") == 0) {
argc--; argv++;
tend = atoi(argv[0]);
} else if (argc!=1) {
return usage(progname, N_RECORDS);
}
......@@ -381,7 +472,8 @@ int test_main (int argc, const char *argv[]) {
{
int event_limit = event_count;
if (verbose) printf("event_limit=%d\n", event_limit);
if (tend>0 && tend<event_limit) event_limit=tend;
if (verbose) printf("event_limit=%d\n", event_limit);
for (int i = 1; i <= event_limit; i++) {
reset_event_counts();
......
......@@ -681,4 +681,4 @@ loader-cleanup-test.tdbrun: $(patsubst %,loader-cleanup-test%.tdbrun, 1)
# ./loader-cleanup-test.tdb $(SUMMARIZE_CMD)
loader-cleanup-test1.tdbrun: loader-cleanup-test.tdb$(BINSUF)
$(VGRIND) ./loader-cleanup-test.tdb -r 1000 $(SUMMARIZE_CMD)
$(VGRIND) ./loader-cleanup-test.tdb -r 4000 -s $(SUMMARIZE_CMD)
......@@ -62,14 +62,15 @@ int abort_on_poll = 0; // set when test_loader() called with test_type of abort
DB_ENV *env;
enum {MAX_NAME=128};
enum {MAX_DBS=256};
int NUM_DBS=5;
int NUM_ROWS=100000;
#define default_NUM_DBS 5
int NUM_DBS=default_NUM_DBS;
#define default_NUM_ROWS 100000
int NUM_ROWS=default_NUM_ROWS;
//static int NUM_ROWS=50000000;
int CHECK_RESULTS=0;
int USE_PUTS=0;
int event_trigger_lo=0; // what event triggers to use?
int event_trigger_hi =0; // 0 and 0 mean none.
int assert_temp_files = 0;
enum {MAGIC=311};
......@@ -208,6 +209,7 @@ bad_fopen(const char *filename, const char *mode) {
fopen_count++;
event_count++;
if (fopen_count_trigger == fopen_count || event_count == event_count_trigger) {
printf("Doing fopen_count=%d event_count=%" PRId64 "\n", fopen_count, event_count);
errno = EINVAL;
rval = NULL;
} else {
......@@ -666,6 +668,7 @@ static void test_loader(enum test_type t, DB **dbs, int trigger)
printf(" done\n");
if (t == commit) {
event_count_nominal = event_count;
fwrite_count_nominal = fwrite_count; // capture how many fwrites were required for normal operation
write_count_nominal = write_count; // capture how many writes were required for normal operation
pwrite_count_nominal = pwrite_count; // capture how many pwrites were required for normal operation
......@@ -676,6 +679,7 @@ static void test_loader(enum test_type t, DB **dbs, int trigger)
if (verbose) {
printf("Nominal calls: function calls (number of calls for normal operation)\n");
printf(" events %" PRId64 "\n", event_count_nominal);
printf(" fwrite %d\n", fwrite_count_nominal);
printf(" write %d\n", write_count_nominal);
printf(" pwrite %d\n", pwrite_count_nominal);
......@@ -707,15 +711,20 @@ static void test_loader(enum test_type t, DB **dbs, int trigger)
}
int run_test_count = 0;
static void run_test(enum test_type t, int trigger)
{
run_test_count++;
int r;
if (verbose == 0) { // if no other ouput, give indication of progress
printf(".");
if (verbose>0) { // Don't print anything if verbose is 0. Use "+" to indicate progress if verbose is positive
printf("+");
fflush(stdout);
}
r = system("rm -rf " ENVDIR); CKERR(r);
r = toku_os_mkdir(ENVDIR, S_IRWXU+S_IRWXG+S_IRWXO); CKERR(r);
......@@ -826,43 +835,45 @@ static void run_all_tests(void) {
run_test(abort_txn, 0);
if (event_trigger_lo || event_trigger_hi) {
if (verbose) printf("\n\nDoing events %d-%d\n", event_trigger_lo, event_trigger_hi);
for (int i=event_trigger_lo; i<=event_trigger_hi; i++)
printf("\n\nDoing events %d-%d\n", event_trigger_lo, event_trigger_hi);
for (int i=event_trigger_lo; i<=event_trigger_hi; i++) {
run_test(event, i);
return;
}
enum test_type et[NUM_ERR_TYPES] = {enospc_f, enospc_w, enospc_p, einval_fdo, einval_fo, einval_o, enospc_fc};
int * nomp[NUM_ERR_TYPES] = {&fwrite_count_nominal, &write_count_nominal, &pwrite_count_nominal,
&fdopen_count_nominal, &fopen_count_nominal, &open_count_nominal, &fclose_count_nominal};
int limit = NUM_DBS * 5;
int j;
for (j = 0; j<NUM_ERR_TYPES; j++) {
enum test_type t = et[j];
const char * write_type = err_type_str(t);
int nominal = *(nomp[j]);
if (verbose)
printf("\nNow test with induced ENOSPC/EINVAL errors returned from %s, nominal = %d\n", write_type, nominal);
int i;
// induce write error at beginning of process
for (i = 1; i < limit && i < nominal+1; i++) {
trigger = i;
if (verbose) printf("\n\nTesting loader with enospc/einval induced at %s count %d (of %d)\n", write_type, trigger, nominal);
run_test(t, trigger);
}
if (nominal > limit) { // if we didn't already test every possible case
// induce write error sprinkled through process
for (i = 2; i < 5; i++) {
trigger = nominal / i;
} else {
enum test_type et[NUM_ERR_TYPES] = {enospc_f, enospc_w, enospc_p, einval_fdo, einval_fo, einval_o, enospc_fc};
int * nomp[NUM_ERR_TYPES] = {&fwrite_count_nominal, &write_count_nominal, &pwrite_count_nominal,
&fdopen_count_nominal, &fopen_count_nominal, &open_count_nominal, &fclose_count_nominal};
int limit = NUM_DBS * 5;
int j;
for (j = 0; j<NUM_ERR_TYPES; j++) {
enum test_type t = et[j];
const char * write_type = err_type_str(t);
int nominal = *(nomp[j]);
printf("Test %s %d\n", write_type, nominal);
if (verbose)
printf("\nNow test with induced ENOSPC/EINVAL errors returned from %s, nominal = %d\n", write_type, nominal);
int i;
// induce write error at beginning of process
for (i = 1; i < limit && i < nominal+1; i++) {
trigger = i;
if (verbose) printf("\n\nTesting loader with enospc/einval induced at %s count %d (of %d)\n", write_type, trigger, nominal);
run_test(t, trigger);
}
// induce write error at end of process
for (i = 0; i < limit; i++) {
trigger = nominal - i;
assert(trigger > 0);
if (verbose) printf("\n\nTesting loader with enospc/einval induced at %s count %d (of %d)\n", write_type, trigger, nominal);
run_test(t, trigger);
if (nominal > limit) { // if we didn't already test every possible case
// induce write error sprinkled through process
for (i = 2; i < 5; i++) {
trigger = nominal / i;
if (verbose) printf("\n\nTesting loader with enospc/einval induced at %s count %d (of %d)\n", write_type, trigger, nominal);
run_test(t, trigger);
}
// induce write error at end of process
for (i = 0; i < limit; i++) {
trigger = nominal - i;
assert(trigger > 0);
if (verbose) printf("\n\nTesting loader with enospc/einval induced at %s count %d (of %d)\n", write_type, trigger, nominal);
run_test(t, trigger);
}
}
}
}
......@@ -871,15 +882,9 @@ static void run_all_tests(void) {
int test_main(int argc, char * const *argv) {
do_args(argc, argv);
printf("\nTesting loader with default size_factor\n");
assert_temp_files = 0;
run_all_tests();
printf("\nTesting loader with size_factor=1\n");
db_env_set_loader_size_factor(1);
assert_temp_files = 1;
run_all_tests();
printf("\nTotal event_trigger count is %" PRId64 ". (Use with -t N M, where 1<=N<=M<=%" PRId64 "\n", event_count, event_count);
printf("run_test_count=%d\n", run_test_count);
return 0;
}
......@@ -897,7 +902,14 @@ static void do_args(int argc, char * const argv[]) {
} else if (strcmp(argv[0], "-h")==0) {
resultcode=0;
do_usage:
fprintf(stderr, "Usage: -h -c -s -p -d <num_dbs> -r <num_rows>\n%s\n", cmd);
fprintf(stderr, "Usage: -h -c -s -p -d <num_dbs> -r <num_rows> -t <elow> <ehi> \n%s\n", cmd);
fprintf(stderr, " where -h print this message.\n");
fprintf(stderr, " -c check the results.\n");
fprintf(stderr, " -p LOADER_USE_PUTS.\n");
fprintf(stderr, " -s size_factor=1.\n");
fprintf(stderr, " -d <num_dbs> Number of indexes to create (default=%d).\n", default_NUM_DBS);
fprintf(stderr, " -r <num_rows> Number of rows to put (default=%d).\n", default_NUM_ROWS);
fprintf(stderr, " -t <elo> <ehi> Instrument only events <elo> to <ehi> (default: instrument all).\n");
exit(resultcode);
} else if (strcmp(argv[0], "-d")==0) {
argc--; argv++;
......@@ -921,6 +933,8 @@ static void do_args(int argc, char * const argv[]) {
event_trigger_lo = atoi(argv[0]);
argc--; argv++;
event_trigger_hi = atoi(argv[0]);
} else if (strcmp(argv[0], "-s")==0) {
db_env_set_loader_size_factor(1);
} else {
fprintf(stderr, "Unknown arg: %s\n", argv[0]);
resultcode=1;
......
......@@ -4,10 +4,9 @@
/* This version will complain if NDEBUG is set. */
/* It evaluates the argument and then calls a function toku_do_assert() which takes all the hits for the branches not taken. */
#if defined(__cplusplus) || defined(__cilkplusplus)
extern "C" {
#endif
#include "c_dialects.h"
C_BEGIN
#ifdef NDEBUG
#error NDEBUG should not be set
......@@ -19,6 +18,8 @@ void toku_do_assert(int,const char*/*expr_as_string*/,const char */*fun*/,const
// Define GCOV if you want to get test-coverage information that ignores the assert statements.
// #define GCOV
extern void (*do_assert_hook)(void); // Set this to a function you want called after printing the assertion failure message but before calling abort(). By default this is NULL.
#if defined(GCOV) || TOKU_WINDOWS
#define assert(expr) toku_do_assert((expr) != 0, #expr, __FUNCTION__, __FILE__, __LINE__)
#else
......@@ -37,8 +38,6 @@ void toku_do_assert(int,const char*/*expr_as_string*/,const char */*fun*/,const
#define invariant(a) assert(a) // indicates a code invariant that must be true
#define resource_assert(a) assert(a) // indicates resource must be available, otherwise unrecoverable
#if defined(__cplusplus) || defined(__cilkplusplus)
}
#endif
C_END
#endif
......@@ -16,6 +16,8 @@
static void *backtrace_pointers[N_POINTERS];
#endif
void (*do_assert_hook)(void) = NULL;
void toku_do_assert_fail (const char* expr_as_string,const char *function,const char*file,int line)
{
fprintf(stderr, "%s:%d %s: Assertion `%s' failed\n", file,line,function,expr_as_string);
......@@ -44,6 +46,9 @@ void toku_do_assert_fail (const char* expr_as_string,const char *function,const
TerminateProcess(GetCurrentProcess(), 134); //Only way found so far to unconditionally
//Terminate the process
#endif
if (do_assert_hook) do_assert_hook();
abort();
}
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment