smbtorture: Add "target" command to interactive shell.
authorJames Peach <jpeach@samba.org>
Tue, 23 Mar 2010 04:55:49 +0000 (21:55 -0700)
committerJames Peach <jpeach@apple.com>
Mon, 21 Jun 2010 15:58:10 +0000 (08:58 -0700)
Add a "target" command to set the target server to test. Refactor
the command line argument processing a little so that you can run
--shell without any additional arguments.

source4/torture/shell.c
source4/torture/smbtorture.c

index 888097de7fa4657110ba6410bd8200e63588427f..2f58eb989bc28c9d9f4895a7610b2843a75dd760 100644 (file)
@@ -43,6 +43,8 @@ static void shell_list(const struct shell_command *,
        struct torture_context *, int, const char **);
 static void shell_auth(const struct shell_command *,
        struct torture_context *, int, const char **);
+static void shell_target(const struct shell_command *,
+       struct torture_context *, int, const char **);
 
 static void shell_usage(const struct shell_command *);
 static bool match_command(const char *, const struct shell_command *);
@@ -86,6 +88,11 @@ static const struct shell_command commands[] =
     {
        shell_set, "set", "[NAME VALUE]",
        "print or set test configuration parameters"
+    },
+
+    {
+       shell_target, "target", "[TARGET]",
+       "print or set the test target"
     }
 
 };
@@ -263,6 +270,28 @@ static void shell_auth(const struct shell_command * command,
 
 }
 
+static void shell_target(const struct shell_command *command,
+       struct torture_context *tctx, int argc, const char **argv)
+{
+       if (argc == 0) {
+               const char * host;
+               const char * share;
+               const char * binding;
+
+               host = torture_setting_string(tctx, "host", NULL);
+               share = torture_setting_string(tctx, "share", NULL);
+               binding = torture_setting_string(tctx, "binding", NULL);
+
+               printf("Target host: %s\n", host ? host : "");
+               printf("Target share: %s\n", share ? share : "");
+               printf("Target binding: %s\n", binding ? binding : "");
+       } else if (argc == 1) {
+               torture_parse_target(tctx->lp_ctx, argv[0]);
+       } else {
+               shell_usage(command);
+       }
+}
+
 static void shell_usage(const struct shell_command * command)
 {
     if (command->usage) {
@@ -287,4 +316,3 @@ static bool match_command(const char * name,
 
        return false;
 }
-
index b7140d70a5797169fed5f7b7f7f515d25553f853..f0da3f0e9e956513bc3345857eb4b1279a0d343d 100644 (file)
@@ -122,7 +122,7 @@ bool torture_run_named_tests(struct torture_context *torture, const char *name,
        return ret;
 }
 
-static bool parse_target(struct loadparm_context *lp_ctx, const char *target)
+bool torture_parse_target(struct loadparm_context *lp_ctx, const char *target)
 {
        char *host = NULL, *share = NULL;
        struct dcerpc_binding *binding_struct;
@@ -607,16 +607,6 @@ int main(int argc,char *argv[])
                }
        }
 
-       if (!(argc_new >= 3)) {
-               usage(pc);
-               exit(1);
-       }
-
-       if (!parse_target(cmdline_lp_ctx, argv_new[1])) {
-               usage(pc);
-               exit(1);
-       }
-
        if (!strcmp(ui_ops_name, "simple")) {
                ui_ops = &std_ui_ops;
        } else if (!strcmp(ui_ops_name, "subunit")) {
@@ -649,12 +639,29 @@ int main(int argc,char *argv[])
 
        gensec_init(cmdline_lp_ctx);
 
-       if (argc_new == 0) {
-               printf("You must specify a testsuite to run, or 'ALL'\n");
-       } else if (shell) {
+       // At this point, we should just have a target string,
+       // followed by a series of test names. Unless we are in
+       // shell mode, in which case we don't need anythig more.
+
+       if (argc_new > 1) {
+               // Take the target name or binding.
+               if (!torture_parse_target(cmdline_lp_ctx, argv_new[1])) {
+                       usage(pc);
+                       exit(1);
+               }
+
+               argc_new--;
+       }
+
+       if (shell) {
+               // In shell mode, just ignore any remaining test names.
                torture_shell(torture);
+       } else if (argc_new == 1) {
+               printf("You must specify a test to run, or 'ALL'\n");
+               usage(pc);
+               exit(1);
        } else {
-               for (i=2;i<argc_new;i++) {
+               for (i=1;i<argc_new;i++) {
                        if (!torture_run_named_tests(torture, argv_new[i],
                                    (const char **)restricted)) {
                                correct = false;