From 9992580ec57ad678e59a21a564389ba66e5594e9 Mon Sep 17 00:00:00 2001 From: Luke Chen Date: Mon, 26 Sep 2022 08:27:15 +1000 Subject: Import wiredtiger: 06926a917a9c92cc7407612d0638397a51cc8e44 from branch mongodb-master ref: 7739da50a2..06926a917a for: 6.2.0-rc0 WT-9739 test tiered: test_util command line parsing (#8285) --- src/third_party/wiredtiger/import.data | 2 +- src/third_party/wiredtiger/test/utility/misc.c | 8 ++ .../wiredtiger/test/utility/parse_opts.c | 85 +++++++++++++++++++++- .../wiredtiger/test/utility/test_util.h | 12 ++- 4 files changed, 98 insertions(+), 9 deletions(-) diff --git a/src/third_party/wiredtiger/import.data b/src/third_party/wiredtiger/import.data index 9da754bc186..042ed27ae7a 100644 --- a/src/third_party/wiredtiger/import.data +++ b/src/third_party/wiredtiger/import.data @@ -2,5 +2,5 @@ "vendor": "wiredtiger", "github": "wiredtiger/wiredtiger.git", "branch": "mongodb-master", - "commit": "7739da50a2c6a51a044915e01bf20cd33bc28eef" + "commit": "06926a917a9c92cc7407612d0638397a51cc8e44" } diff --git a/src/third_party/wiredtiger/test/utility/misc.c b/src/third_party/wiredtiger/test/utility/misc.c index ea808e14c41..ac7f2252540 100644 --- a/src/third_party/wiredtiger/test/utility/misc.c +++ b/src/third_party/wiredtiger/test/utility/misc.c @@ -207,6 +207,7 @@ testutil_progress(TEST_OPTS *opts, const char *message) void testutil_cleanup(TEST_OPTS *opts) { + int i; if (opts->conn != NULL) testutil_check(opts->conn->close(opts->conn, NULL)); @@ -220,6 +221,13 @@ testutil_cleanup(TEST_OPTS *opts) free(opts->progress_file_name); free(opts->home); free(opts->build_dir); + if (opts->tiered_storage) { + for (i = 0; i <= opts->nargc; ++i) + free(opts->nargv[i]); + free(opts->nargv); + } + if (opts->tiered_storage_source != NULL) + free(opts->tiered_storage_source); } /* diff --git a/src/third_party/wiredtiger/test/utility/parse_opts.c b/src/third_party/wiredtiger/test/utility/parse_opts.c index 98eabe89b7e..d87b89c7666 100644 --- a/src/third_party/wiredtiger/test/utility/parse_opts.c +++ b/src/third_party/wiredtiger/test/utility/parse_opts.c @@ -26,9 +26,79 @@ * OTHER DEALINGS IN THE SOFTWARE. */ #include "test_util.h" +#define DIR_STORE "dir_store" extern char *__wt_optarg; /* argument associated with option */ +/* + * parse_tiered_opts -- + * Parse command line options for the tiered storage configurations. + */ +static inline void +parse_tiered_opts(int argc, char *const *argv, TEST_OPTS *opts) +{ + int index, i; + int number_of_tiered_options; + + number_of_tiered_options = 0; + index = 0; + opts->tiered_storage = false; + opts->tiered_storage_source = NULL; + + for (i = 1; i < argc; i++) { + /* Tiered storage command line options starts with -P. */ + if (strstr(argv[i], "-P")) { + /* Many more options to come here. */ + if (argv[i][2] == 'o') { + if (argv[i + 1] == NULL) + testutil_die( + EINVAL, "%s option requires an argument %s", opts->progname, argv[i]); + number_of_tiered_options += 2; + } else if (argv[i][2] == 'T') { + /* This parsing is different because -PT does not accept any arguments. */ + ++number_of_tiered_options; + opts->tiered_storage = true; + } + } + } + + /* Return from here if tiered arguments are not passed. */ + if (!opts->tiered_storage) { + if (number_of_tiered_options == 0) + return; + else + testutil_die( + EINVAL, "Error - Tiered storage command line arguments are passed without -PT."); + } + + opts->nargc = argc - number_of_tiered_options; + + /* Allocate the memory for the new argv without tiered options. */ + opts->nargv = dmalloc(((size_t)opts->nargc + 1) * sizeof(char *)); + + /* Copy other command line arguments except tiered. */ + for (i = 0; i < argc; ++i) { + if (strcmp(argv[i], "-Po") == 0) { + opts->tiered_storage_source = dstrdup(argv[i + 1]); + /* Move the index because this option has an argument. */ + i++; + } else if (strcmp(argv[i], "-PT") == 0) + continue; + else + opts->nargv[index++] = dstrdup(argv[i]); + } + + testutil_assert(index == opts->nargc); + /* + * Allocating an extra empty space at the end of the new argv just to replicate the system argv + * implementation. + */ + opts->nargv[index++] = dstrdup(""); + + if (opts->tiered_storage_source == NULL) + opts->tiered_storage_source = dstrdup(DIR_STORE); +} + /* * testutil_parse_opts -- * Parse command line options for a test case. @@ -39,6 +109,8 @@ testutil_parse_opts(int argc, char *const *argv, TEST_OPTS *opts) size_t len; int ch; + opts->nargc = 0; + opts->nargv = NULL; opts->do_data_ops = false; opts->preserve = false; opts->running = true; @@ -49,14 +121,19 @@ testutil_parse_opts(int argc, char *const *argv, TEST_OPTS *opts) testutil_print_command_line(argc, argv); - while ((ch = __wt_getopt(opts->progname, argc, argv, "A:Bb:dh:n:o:pR:T:t:vW:")) != EOF) + parse_tiered_opts(argc, argv, opts); + + if (!opts->tiered_storage) { + opts->nargv = (char **)argv; + opts->nargc = argc; + } + + while ( + (ch = __wt_getopt(opts->progname, opts->nargc, opts->nargv, "A:b:dh:n:o:pR:T:t:vW:")) != EOF) switch (ch) { case 'A': /* Number of append threads */ opts->n_append_threads = (uint64_t)atoll(__wt_optarg); break; - case 'B': /* Use tiered storage objects and buckets. */ - opts->tiered = true; - break; case 'b': /* Build directory */ opts->build_dir = dstrdup(__wt_optarg); break; diff --git a/src/third_party/wiredtiger/test/utility/test_util.h b/src/third_party/wiredtiger/test/utility/test_util.h index c22770ce5e7..7b255d233d0 100644 --- a/src/third_party/wiredtiger/test/utility/test_util.h +++ b/src/third_party/wiredtiger/test/utility/test_util.h @@ -52,9 +52,13 @@ /* Generic option parsing structure shared by all test cases. */ typedef struct { char *home; - const char *argv0; /* Exec name */ - const char *progname; /* Truncated program name */ - char *build_dir; /* Build directory path */ + const char *argv0; /* Exec name */ + char **nargv; /* New argument vector */ + int nargc; /* New argument count */ + + const char *progname; /* Truncated program name */ + char *build_dir; /* Build directory path */ + char *tiered_storage_source; /* Tiered storage source */ enum { TABLE_COL = 1, /* Fixed-length column store */ @@ -67,7 +71,7 @@ typedef struct { bool do_data_ops; /* Have schema ops use data */ bool preserve; /* Don't remove files on exit */ - bool tiered; /* Configure tiered storage */ + bool tiered_storage; /* Configure tiered storage */ bool verbose; /* Run in verbose mode */ uint64_t nrecords; /* Number of records */ uint64_t nops; /* Number of operations */ -- cgit v1.2.1