From db408c0d0dbe159146c637c97bbe9bbf41983586 Mon Sep 17 00:00:00 2001 From: Andrew Tridgell Date: Fri, 15 Feb 2008 15:53:11 +1100 Subject: convert gentest to use popt and the cmdline library (This used to be commit 681366b956a71aa7bd16b75263ccd73ddc680082) --- source4/torture/gentest.c | 166 +++++++++++++++++++++++----------------------- 1 file changed, 83 insertions(+), 83 deletions(-) diff --git a/source4/torture/gentest.c b/source4/torture/gentest.c index 8fa433a872..28cac81624 100644 --- a/source4/torture/gentest.c +++ b/source4/torture/gentest.c @@ -18,6 +18,7 @@ */ #include "includes.h" +#include "lib/cmdline/popt_common.h" #include "system/time.h" #include "system/filesys.h" #include "libcli/raw/request.h" @@ -1755,6 +1756,7 @@ static void gen_setfileinfo(int instance, union smb_setfileinfo *info) info->end_of_file_info.in.size = gen_offset(); break; case RAW_SFILEINFO_RENAME_INFORMATION: + case RAW_SFILEINFO_RENAME_INFORMATION_SMB2: info->rename_information.in.overwrite = gen_bool(); info->rename_information.in.root_fid = gen_root_fid(instance); info->rename_information.in.new_name = gen_fname_open(instance); @@ -2129,25 +2131,13 @@ static bool start_gentest(struct loadparm_context *lp_ctx) } -static void usage(void) +static void usage(poptContext pc) { printf( "Usage:\n\ - gentest2 //server1/share1 //server2/share2 [options..]\n\ - options:\n\ - -U user%%pass (can be specified twice)\n\ - -s seed\n\ - -o numops\n\ - -a (show all ops)\n\ - -A backtrack to find minimal ops\n\ - -i FILE add a list of wildcard exclusions\n\ - -O enable oplocks\n\ - -S FILE set preset seeds file\n\ - -L use preset seeds\n\ - -F fast reconnect (just close files)\n\ - -C continuous analysis mode\n\ - -X analyse even when test OK\n\ + gentest //server1/share1 //server2/share2 [options..]\n\ "); + poptPrintUsage(pc, stdout, 0); } /** @@ -2180,14 +2170,88 @@ static bool split_unc_name(const char *unc, char **server, char **share) int opt; int i, username_count=0; bool ret; + char *ignore_file=NULL; struct loadparm_context *lp_ctx; + poptContext pc; + int argc_new; + char **argv_new; + enum {OPT_UNCLIST=1000}; + struct poptOption long_options[] = { + POPT_AUTOHELP + {"seed", 0, POPT_ARG_INT, &options.seed, 0, "Seed to use for randomizer", NULL}, + {"num-ops", 0, POPT_ARG_INT, &options.numops, 0, "num ops", NULL}, + {"oplocks", 0, POPT_ARG_NONE, &options.use_oplocks,0, "use oplocks", NULL}, + {"showall", 0, POPT_ARG_NONE, &options.showall, 0, "display all operations", NULL}, + {"analyse", 0, POPT_ARG_NONE, &options.analyze, 0, "do backtrack analysis", NULL}, + {"analysealways", 0, POPT_ARG_NONE, &options.analyze_always, 0, "analysis always", NULL}, + {"analysecontinuous", 0, POPT_ARG_NONE, &options.analyze_continuous, 0, "analysis continuous", NULL}, + {"ignore", 0, POPT_ARG_STRING, &ignore_file, 0, "ignore from file", NULL}, + {"preset", 0, POPT_ARG_NONE, &options.use_preset_seeds, 0, "use preset seeds", NULL}, + {"fast", 0, POPT_ARG_NONE, &options.fast_reconnect, 0, "use fast reconnect", NULL}, + {"unclist", 0, POPT_ARG_STRING, NULL, OPT_UNCLIST, "unclist", NULL}, + {"seedsfile", 0, POPT_ARG_STRING, &options.seeds_file, 0, "seed file", NULL}, + { "user", 'U', POPT_ARG_STRING, NULL, 'U', "Set the network username", "[DOMAIN/]USERNAME[%PASSWORD]" }, + POPT_COMMON_SAMBA + POPT_COMMON_CONNECTION + POPT_COMMON_CREDENTIALS + POPT_COMMON_VERSION + { NULL } + }; + + setlinebuf(stdout); + options.seed = time(NULL); + + pc = poptGetContext("gentest", argc, (const char **) argv, long_options, + POPT_CONTEXT_KEEP_FIRST); + + poptSetOtherOptionHelp(pc, " "); + + lp_ctx = cmdline_lp_ctx; + servers[0].credentials = cli_credentials_init(talloc_autofree_context()); + servers[1].credentials = cli_credentials_init(talloc_autofree_context()); + cli_credentials_guess(servers[0].credentials, lp_ctx); + cli_credentials_guess(servers[1].credentials, lp_ctx); + + while((opt = poptGetNextOpt(pc)) != -1) { + switch (opt) { + case OPT_UNCLIST: + lp_set_cmdline(cmdline_lp_ctx, "torture:unclist", poptGetOptArg(pc)); + break; + case 'U': + if (username_count == 2) { + usage(pc); + exit(1); + } + cli_credentials_parse_string(servers[username_count].credentials, poptGetOptArg(pc), CRED_SPECIFIED); + username_count++; + break; + } + } + + if (ignore_file) { + options.ignore_patterns = file_lines_load(ignore_file, NULL, NULL); + } + + argv_new = discard_const_p(char *, poptGetArgs(pc)); + argc_new = argc; + for (i=0; i= 3)) { + usage(pc); + exit(1); + } setlinebuf(stdout); setup_logging("gentest", DEBUG_STDOUT); if (argc < 3 || argv[1][0] == '-') { - usage(); + usage(pc); exit(1); } @@ -2195,7 +2259,6 @@ static bool split_unc_name(const char *unc, char **server, char **share) for (i=0;i