#include "test.h" #include #include #include #include #include "brtloader-internal.h" #include "memory.h" static int qsort_compare_ints (const void *a, const void *b) { int avalue = *(int*)a; int bvalue = *(int*)b; if (avaluebvalue) return +1; return 0; } static int compare_ints (DB *dest_db, const DBT *akey, const DBT *bkey) { assert(dest_db==NULL); assert(akey->size==sizeof(int)); assert(bkey->size==sizeof(int)); return qsort_compare_ints(akey->data, bkey->data); } static void test_merge_internal (int a[], int na, int b[], int nb) { struct row *MALLOC_N(na, ar); struct row *MALLOC_N(nb, br); for (int i=0; ib[j]); j++; } else { assert(0); } } } toku_free(cr); toku_free(ar); toku_free(br); } /* Test the basic merger. */ static void test_merge (void) { { int avals[]={1,2,3,4,5}; int *bvals = NULL; //icc won't let us use a zero-sized array explicitly or by [] = {} construction. test_merge_internal(avals, 5, bvals, 0); test_merge_internal(bvals, 0, avals, 5); } { int avals[]={1,3,5,7}; int bvals[]={2,4}; test_merge_internal(avals, 4, bvals, 2); test_merge_internal(bvals, 2, avals, 4); } { int avals[]={1,2,3,5,6,7}; int bvals[]={2,4,5,6,8}; test_merge_internal(avals, 6, bvals, 5); test_merge_internal(bvals, 5, avals, 6); } } static void test_internal_mergesort_row_array (int a[], int n) { struct row *MALLOC_N(n, ar); for (int i=0; i= fs.n_temp_files); destroy_rowset(&aset); destroy_rowset(&bset); for (int i=0; i<2; i++) assert(fs.temp_data_names[i] != NULL && fs.temp_idx_names[i] != NULL); r = merge_files(&fs, &bl, dest_db, compare_ints); CKERR(r); assert(fs.n_temp_files==1); FILE *inf = fopen(fs.temp_data_names[0], "r"); char *name = toku_strdup(template); int fd = mkstemp(name); fprintf(stderr, "Final data in %s\n", name); assert(r>=0); struct descriptor desc = {.version = 1, .dbt = (DBT){.size = 4, .data="abcd"}}; r = write_file_to_dbfile(fd, inf, &bl, &desc); CKERR(r); r = fclose(inf); CKERR(r); r = unlink(fs.temp_data_names[0]); CKERR(r); r = unlink(fs.temp_idx_names[0]); CKERR(r); toku_free(fs.temp_data_names[0]); toku_free(fs.temp_idx_names[0]); toku_free(fs.temp_data_names); toku_free(fs.temp_idx_names); toku_free(name); } /* Test to see if we can open temporary files. */ int test_main (int argc, const char *argv[]) { const char *progname=argv[0]; argc--; argv++; while (argc>0) { if (strcmp(argv[0],"-v")==0) { verbose=1; } else if (strcmp(argv[0],"-q")==0) { verbose=0; } else if (argc!=1) { fprintf(stderr, "Usage:\n %s [-v] [-q] directory\n", progname); exit(1); } else { break; } argc--; argv++; } assert(argc==1); // argv[1] is the directory in which to do the test. const char* directory = argv[0]; int r = toku_os_mkdir(directory, 0755); if (r!=0) CKERR2(errno, EEXIST); int templen = strlen(directory)+15; char template[templen]; int n = snprintf(template, templen, "%s/tempXXXXXX", directory); assert (n>0 && n