/* * wt_connect -- * Configure the WiredTiger connection. */ static void wt_connect(SHARED_CONFIG *cfg, char *config_open) { static WT_EVENT_HANDLER event_handler = { handle_error, handle_message, NULL, NULL /* Close handler. */ }; int ret; char config[512]; size_t print_count; testutil_clean_work_dir(home); testutil_make_work_dir(home); print_count = (size_t)snprintf(config, sizeof(config), "create,statistics=(all),error_prefix=\"%s\",%s%s", progname, config_open == NULL ? "" : ",", config_open == NULL ? "" : config_open); if (print_count >= sizeof(config)) testutil_die(EINVAL, "Config string too long"); if ((ret = wiredtiger_open( home, &event_handler, config, &cfg->conn)) != 0) testutil_die(ret, "wiredtiger_open"); }
/* * cleanup -- * Clean up from previous runs. */ static int cleanup(void) { g.running = 0; g.ntables_created = 0; testutil_clean_work_dir(g.home); return (0); }
int main(int argc, char *argv[]) { CONFIG *cp; size_t len, *lp; int ch, small; char *working_dir; if ((progname = strrchr(argv[0], DIR_DELIM)) == NULL) progname = argv[0]; else ++progname; small = 0; working_dir = NULL; while ((ch = __wt_getopt(progname, argc, argv, "h:s")) != EOF) switch (ch) { case 'h': working_dir = __wt_optarg; break; case 's': /* Gigabytes */ small = 1; break; default: usage(); } argc -= __wt_optind; argv += __wt_optind; if (argc != 0) usage(); testutil_work_dir_from_path(home, 512, working_dir); /* Allocate a buffer to use. */ len = small ? ((size_t)SMALL_MAX) : ((size_t)4 * GIGABYTE); if ((big = malloc(len)) == NULL) testutil_die(errno, ""); memset(big, 'a', len); /* Make sure the configurations all work. */ for (lp = lengths; *lp != 0; ++lp) { if (small && *lp > SMALL_MAX) break; for (cp = config; cp->uri != NULL; ++cp) { if (!cp->recno) /* Big key on row-store */ run(cp, 1, *lp); run(cp, 0, *lp); /* Big value */ } } free(big); testutil_clean_work_dir(home); return (EXIT_SUCCESS); }
/* * main -- * The main program for the test. When invoked with "subtest" * argument, run the subtest. Otherwise, run a separate process * for each needed subtest, and check the results. */ int main(int argc, char *argv[]) { TEST_OPTS *opts, _opts; uint64_t nresults; const char *debugger; /* Ignore unless requested */ if (!testutil_is_flag_set("TESTUTIL_ENABLE_LONG_TESTS")) return (EXIT_SUCCESS); opts = &_opts; memset(opts, 0, sizeof(*opts)); debugger = NULL; testutil_check(testutil_parse_opts(argc, argv, opts)); argc -= __wt_optind; argv += __wt_optind; if (opts->nrecords == 0) opts->nrecords = 50000; while (argc > 0) { if (strcmp(argv[0], "subtest") == 0) { subtest_main(argc, argv, false); return (0); } else if (strcmp(argv[0], "subtest_close") == 0) { subtest_main(argc, argv, true); return (0); } else if (strcmp(argv[0], "gdb") == 0) debugger = "/usr/bin/gdb"; else testutil_assert(false); argc--; argv++; } if (opts->verbose) { printf("Number of operations until failure: %" PRIu64 " (change with -o N)\n", opts->nops); printf("Number of records: %" PRIu64 " (change with -n N)\n", opts->nrecords); } if (opts->nops == 0) { run_check_subtest_range(opts, debugger, false); run_check_subtest_range(opts, debugger, true); } else run_check_subtest(opts, debugger, opts->nops, opts->nrecords, &nresults); testutil_clean_work_dir(opts->home); testutil_cleanup(opts); return (0); }
/* * testutil_cleanup -- * Delete the existing work directory and free the options structure. */ void testutil_cleanup(TEST_OPTS *opts) { if (opts->conn != NULL) testutil_check(opts->conn->close(opts->conn, NULL)); if (!opts->preserve) testutil_clean_work_dir(opts->home); free(opts->conn_config); free(opts->table_config); free(opts->uri); free(opts->home); }
/* * run_check_subtest -- * Run the subtest with the given parameters and check the results. */ static void run_check_subtest(TEST_OPTS *opts, const char *debugger, uint64_t nops, bool close_test, uint64_t *nresultsp) { int estatus, narg; char rarg[20], sarg[20], *subtest_args[MAX_ARGS]; narg = 0; if (debugger != NULL) { subtest_args[narg++] = (char *)debugger; subtest_args[narg++] = (char *)"--"; } subtest_args[narg++] = (char *)opts->progname; /* "subtest" must appear before arguments */ if (close_test) subtest_args[narg++] = (char *)"subtest_close"; else subtest_args[narg++] = (char *)"subtest"; subtest_args[narg++] = (char *)"-h"; subtest_args[narg++] = opts->home; subtest_args[narg++] = (char *)"-v"; /* subtest is always verbose */ subtest_args[narg++] = (char *)"-p"; subtest_args[narg++] = (char *)"-o"; testutil_check(__wt_snprintf(sarg, sizeof(sarg), "%" PRIu64, nops)); subtest_args[narg++] = sarg; /* number of operations */ subtest_args[narg++] = (char *)"-n"; testutil_check(__wt_snprintf( rarg, sizeof(rarg), "%" PRIu64, opts->nrecords)); subtest_args[narg++] = rarg; /* number of records */ subtest_args[narg++] = NULL; testutil_assert(narg <= MAX_ARGS); if (opts->verbose) printf("running a separate process with %" PRIu64 " operations until fail...\n", nops); testutil_clean_work_dir(opts->home); testutil_check(run_process( opts, debugger != NULL ? debugger : opts->progname, subtest_args, &estatus)); if (opts->verbose) printf("process exited %d\n", estatus); /* * Verify results in parent process. */ testutil_check(check_results(opts, nresultsp)); }
/* * testutil_make_work_dir -- * Delete the existing work directory, then create a new one. */ void testutil_make_work_dir(char *dir) { size_t len; int ret; char *buf; testutil_clean_work_dir(dir); /* Additional bytes for the mkdir command */ len = strlen(dir) + strlen(MKDIR_COMMAND) + 1; if ((buf = malloc(len)) == NULL) testutil_die(ENOMEM, "Failed to allocate memory"); /* mkdir shares syntax between Windows and Linux */ snprintf(buf, len, "%s%s", MKDIR_COMMAND, dir); if ((ret = system(buf)) != 0) testutil_die(ret, "%s", buf); free(buf); }
/* * shutdown -- * Clean up from previous runs. */ static void shutdown(void) { testutil_clean_work_dir(home); }