r19512: Add --shell option to smbtorture (first work towards support for 'recipes')
authorJelmer Vernooij <jelmer@samba.org>
Mon, 30 Oct 2006 01:19:31 +0000 (01:19 +0000)
committerGerald (Jerry) Carter <jerry@samba.org>
Wed, 10 Oct 2007 19:24:43 +0000 (14:24 -0500)
(This used to be commit 087a8e80a9e912b330178b8c647b83381635f8e9)

source4/torture/config.mk
source4/torture/smbtorture.c

index 630c557d28aa6119144804198503112d0cb08e00..b37a9c8bd94bed7bdb240e869523dfc0c61f6364 100644 (file)
@@ -279,7 +279,8 @@ PRIVATE_DEPENDENCIES = \
                POPT_CREDENTIALS \
                TORTURE_UI \
                dcerpc \
-               LIBCLI_SMB
+               LIBCLI_SMB \
+               SMBREADLINE
 MANPAGE = man/smbtorture.1
 # End BINARY smbtorture
 #################################
index 38f91454e65ebf18e002b0658502d8fc7df130f5..b615dd66adf429c79768bdde7d16a807b85cb28b 100644 (file)
@@ -24,6 +24,8 @@
 #include "system/time.h"
 #include "system/wait.h"
 #include "system/filesys.h"
+#include "system/readline.h"
+#include "lib/smbreadline/smbreadline.h"
 #include "libcli/libcli.h"
 #include "lib/ldb/include/ldb.h"
 #include "lib/events/events.h"
@@ -423,11 +425,55 @@ const static struct torture_ui_ops quiet_ui_ops = {
        .test_result = quiet_test_result
 };
 
+void run_shell(struct torture_context *tctx)
+{
+       char *cline;
+       int argc;
+       char **argv;
+       int ret;
+
+       while (1) {
+               cline = smb_readline("torture> ", NULL, NULL);
+
+               if (cline == NULL)
+                       return;
+       
+               ret = poptParseArgvString(cline, &argc, &argv);
+               if (ret != 0) {
+                       fprintf(stderr, "Error parsing line\n");
+                       continue;
+               }
+
+               if (!strcmp(argv[0], "quit")) {
+                       return;
+               } else if (!strcmp(argv[0], "set")) {
+                       if (argc < 3) {
+                               fprintf(stderr, "Usage: set <variable> <value>\n");
+                       } else {
+                               char *name = talloc_asprintf(NULL, "torture:%s", argv[1]);
+                               lp_set_cmdline(name, argv[2]);
+                               talloc_free(name);
+                       }
+               } else if (!strcmp(argv[0], "help")) {
+                       fprintf(stderr, "Available commands:\n"
+                                                       " help - This help command\n"
+                                                       " run - Run test\n"
+                                                       " set - Change variables\n"
+                                                       "\n");
+               } else if (!strcmp(argv[0], "run")) {
+                       if (argc < 2) {
+                               fprintf(stderr, "Usage: run TEST-NAME [OPTIONS...]\n");
+                       } else {
+                               run_test(tctx, argv[1]);
+                       }
+               }
+       }
+}
 
 /****************************************************************************
   main program
 ****************************************************************************/
- int main(int argc,char *argv[])
+int main(int argc,char *argv[])
 {
        int opt, i;
        bool correct = true;
@@ -439,6 +485,7 @@ const static struct torture_ui_ops quiet_ui_ops = {
        poptContext pc;
        static const char *target = "other";
        const char **subunit_dir;
+       int shell = False;
        static const char *ui_ops_name = "simple";
        enum {OPT_LOADFILE=1000,OPT_UNCLIST,OPT_TIMELIMIT,OPT_DNS,
              OPT_DANGEROUS,OPT_SMB_PORTS,OPT_ASYNC};
@@ -458,6 +505,7 @@ const static struct torture_ui_ops quiet_ui_ops = {
                {"parse-dns",   'D', POPT_ARG_STRING,   NULL,   OPT_DNS,        "parse-dns",    NULL},
                {"dangerous",   'X', POPT_ARG_NONE,     NULL,   OPT_DANGEROUS,
                 "run dangerous tests (eg. wiping out password database)", NULL},
+               {"shell",               's', POPT_ARG_NONE, &shell, True, "Run shell", NULL},
                {"target",              'T', POPT_ARG_STRING, &target, 0, "samba3|samba4|other", NULL},
                {"async",       'a', POPT_ARG_NONE,     NULL,   OPT_ASYNC,
                 "run async tests", NULL},
@@ -505,12 +553,6 @@ const static struct torture_ui_ops quiet_ui_ops = {
                case OPT_SMB_PORTS:
                        lp_set_cmdline("smb ports", poptGetOptArg(pc));
                        break;
-               default:
-                       d_printf("Invalid option %s: %s\n", 
-                                poptBadOption(pc, 0), poptStrerror(opt));
-                       torture_init();
-                       usage(pc);
-                       exit(1);
                }
        }
 
@@ -559,7 +601,7 @@ const static struct torture_ui_ops quiet_ui_ops = {
                }
        }
 
-       if (argc_new < 3) {
+       if (!(argc_new >= 3 || (shell && argc_new >= 2))) {
                usage(pc);
                exit(1);
        }
@@ -600,6 +642,8 @@ const static struct torture_ui_ops quiet_ui_ops = {
 
        if (argc_new == 0) {
                printf("You must specify a test to run, or 'ALL'\n");
+       } else if (shell) {
+               run_shell(torture);
        } else {
                int total;
                double rate;
@@ -610,7 +654,6 @@ const static struct torture_ui_ops quiet_ui_ops = {
                        }
                }
 
-
                unexpected_failures = str_list_length(torture->results.unexpected_failures);
 
                total = torture->results.skipped+torture->results.success+torture->results.failed+torture->results.errors;