smbtorture: Move interactive shell into a separate file.
authorJames Peach <jpeach@samba.org>
Sat, 20 Mar 2010 04:24:15 +0000 (21:24 -0700)
committerJames Peach <jpeach@apple.com>
Mon, 21 Jun 2010 15:58:10 +0000 (08:58 -0700)
lib/torture/torture.c
lib/torture/torture.h
source4/torture/config.mk
source4/torture/shell.c [new file with mode: 0644]
source4/torture/smbtorture.c
source4/torture/smbtorture.h
source4/torture/wscript_build

index dcb28eefb024a66ce63d0821350b695993ab3902..4333f98990dbd6ae20e227c0e9ea836566b81a53 100644 (file)
@@ -305,7 +305,7 @@ bool torture_run_suite(struct torture_context *context,
 }
 
 bool torture_run_suite_restricted(struct torture_context *context, 
-                      struct torture_suite *suite, char **restricted)
+                      struct torture_suite *suite, const char **restricted)
 {
        /* FIXME */
        return false;
index 931937c1182b7e27a2b4e92ca9a9679fdbc4607c..6482e89b94ff9a284a35e1417130c051e900ec5e 100644 (file)
@@ -221,7 +221,7 @@ bool torture_run_suite(struct torture_context *context,
 /* Run the specified testsuite recursively, but only the specified 
  * tests */
 bool torture_run_suite_restricted(struct torture_context *context, 
-                      struct torture_suite *suite, char **restricted);
+                      struct torture_suite *suite, const char **restricted);
 
 /* Run the specified testcase */
 bool torture_run_tcase(struct torture_context *context,
index 25e9b5377bfba031cf2956956afa121772ac02ec..09af078d800ea4768eda761c370f183b8170d927 100644 (file)
@@ -280,7 +280,10 @@ PRIVATE_DEPENDENCIES = \
 # End BINARY smbtorture
 #################################
 
-smbtorture_OBJ_FILES = $(torturesrcdir)/smbtorture.o $(torturesrcdir)/torture.o 
+smbtorture_OBJ_FILES = \
+               $(torturesrcdir)/smbtorture.o \
+               $(torturesrcdir)/torture.o  \
+               $(torturesrcdir)/shell.o
 
 PUBLIC_HEADERS += $(torturesrcdir)/smbtorture.h
 MANPAGES += $(torturesrcdir)/man/smbtorture.1
diff --git a/source4/torture/shell.c b/source4/torture/shell.c
new file mode 100644 (file)
index 0000000..1da4c59
--- /dev/null
@@ -0,0 +1,79 @@
+/*
+   Unix SMB/CIFS implementation.
+   SMB torture tester
+   Copyright (C) Andrew Tridgell 1997-2003
+   Copyright (C) Jelmer Vernooij 2006-2008
+
+   This program is free software; you can redistribute it and/or modify
+   it under the terms of the GNU General Public License as published by
+   the Free Software Foundation; either version 3 of the License, or
+   (at your option) any later version.
+
+   This program is distributed in the hope that it will be useful,
+   but WITHOUT ANY WARRANTY; without even the implied warranty of
+   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+   GNU General Public License for more details.
+
+   You should have received a copy of the GNU General Public License
+   along with this program.  If not, see <http://www.gnu.org/licenses/>.
+*/
+
+#include "includes.h"
+#include "system/readline.h"
+#include "lib/smbreadline/smbreadline.h"
+#include "torture/smbtorture.h"
+
+void torture_shell(struct torture_context *tctx)
+{
+       char *cline;
+       int argc;
+       const char **argv;
+       int ret;
+
+       while (1) {
+               cline = smb_readline("torture> ", NULL, NULL);
+
+               if (cline == NULL)
+                       return;
+
+#if HAVE_ADD_HISTORY
+               add_history(cline);
+#endif
+
+               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], "list")) {
+                       torture_print_tests(true);
+               } else if (!strcmp(argv[0], "set")) {
+                       if (argc < 3) {
+                               lp_dump(tctx->lp_ctx, stdout,
+                                       false /* show_defaults */,
+                                       0 /* skip services */);
+                       } else {
+                               char *name = talloc_asprintf(NULL, "torture:%s", argv[1]);
+                               lp_set_cmdline(tctx->lp_ctx, name, argv[2]);
+                               talloc_free(name);
+                       }
+               } else if (!strcmp(argv[0], "help")) {
+                       fprintf(stderr, "Available commands:\n"
+                                                       " help - This help command\n"
+                                                       " list - List the available\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 {
+                               torture_run_named_tests(tctx, argv[1]);
+                       }
+               }
+               free(cline);
+       }
+}
index 96014a22066560e741cdd64b767a0e2a170dfb60..b7140d70a5797169fed5f7b7f7f515d25553f853 100644 (file)
@@ -40,7 +40,7 @@
 static bool run_matching(struct torture_context *torture,
                                                 const char *prefix, 
                                                 const char *expr,
-                                                char **restricted,
+                                                const char **restricted,
                                                 struct torture_suite *suite,
                                                 bool *matched)
 {
@@ -94,8 +94,8 @@ static bool run_matching(struct torture_context *torture,
 /****************************************************************************
 run a specified test or "ALL"
 ****************************************************************************/
-static bool run_test(struct torture_context *torture, const char *name,
-                                        char **restricted)
+bool torture_run_named_tests(struct torture_context *torture, const char *name,
+                           const char **restricted)
 {
        bool ret = true;
        bool matched = false;
@@ -249,6 +249,15 @@ static void print_test_list(void)
        }
 }
 
+void torture_print_tests(bool structured)
+{
+       if (structured) {
+               print_structured_test_list();
+       } else {
+               print_test_list();
+       }
+}
+
 _NORETURN_ static void usage(poptContext pc)
 {
        poptPrintUsage(pc, stdout, 0);
@@ -377,61 +386,6 @@ const static struct torture_ui_ops std_ui_ops = {
        .progress = simple_progress,
 };
 
-static void run_shell(struct torture_context *tctx)
-{
-       char *cline;
-       int argc;
-       const char **argv;
-       int ret;
-
-       while (1) {
-               cline = smb_readline("torture> ", NULL, NULL);
-
-               if (cline == NULL)
-                       return;
-
-#if HAVE_ADD_HISTORY
-               add_history(cline);
-#endif
-
-               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], "list")) {
-                       print_structured_test_list();
-               } else if (!strcmp(argv[0], "set")) {
-                       if (argc < 3) {
-                               lp_dump(tctx->lp_ctx, stdout,
-                                       false /* show_defaults */,
-                                       0 /* skip services */);
-                       } else {
-                               char *name = talloc_asprintf(NULL, "torture:%s", argv[1]);
-                               lp_set_cmdline(tctx->lp_ctx, name, argv[2]);
-                               talloc_free(name);
-                       }
-               } else if (!strcmp(argv[0], "help")) {
-                       fprintf(stderr, "Available commands:\n"
-                                                       " help - This help command\n"
-                                                       " list - List the available\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]);
-                       }
-               }
-               free(cline);
-       }
-}
-
 /****************************************************************************
   main program
 ****************************************************************************/
@@ -448,6 +402,7 @@ int main(int argc,char *argv[])
        poptContext pc;
        static const char *target = "other";
        NTSTATUS status;
+       int shell = false;
        static const char *ui_ops_name = "subunit";
        const char *basedir = NULL;
        const char *extra_module = NULL;
@@ -477,6 +432,7 @@ int main(int argc,char *argv[])
                {"dangerous",   'X', POPT_ARG_NONE,     NULL,   OPT_DANGEROUS,
                 "run dangerous tests (eg. wiping out password database)", NULL},
                {"load-module",  0,  POPT_ARG_STRING, &extra_module,     0, "load tests from DSO file",    "SOFILE"},
+                {"shell",               0, 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},
@@ -695,9 +651,12 @@ int main(int argc,char *argv[])
 
        if (argc_new == 0) {
                printf("You must specify a testsuite to run, or 'ALL'\n");
+       } else if (shell) {
+               torture_shell(torture);
        } else {
                for (i=2;i<argc_new;i++) {
-                       if (!run_test(torture, argv_new[i], restricted)) {
+                       if (!torture_run_named_tests(torture, argv_new[i],
+                                   (const char **)restricted)) {
                                correct = false;
                        }
                }
index b45ce65f5087665c94342fa825c5cc3517bd6edf..8ad58bf71cf95d75645be3603904697c71ba7e69 100644 (file)
@@ -36,6 +36,11 @@ extern int torture_numasync;
 struct torture_test;
 int torture_init(void);
 bool torture_register_suite(struct torture_suite *suite);
+void torture_shell(struct torture_context *tctx);
+void torture_print_tests(bool structured);
+bool torture_run_named_tests(struct torture_context *torture, const char *name,
+                           const char **restricted);
+bool torture_parse_target(struct loadparm_context *lp_ctx, const char *target);
 
 /* Server Functionality Support */
 
index 798e8c7d723ad1f662e8e789ef0c453757245250..05b47e427a5f0638f4f6c9082cc03e739368dff6 100644 (file)
@@ -141,7 +141,7 @@ bld.SAMBA_MODULE('TORTURE_NTP',
 TORTURE_MODULES = 'TORTURE_BASIC TORTURE_RAW torture_rpc TORTURE_RAP TORTURE_AUTH TORTURE_NBENCH TORTURE_UNIX TORTURE_LDAP TORTURE_NBT TORTURE_NET TORTURE_NTP torture_registry'
 
 bld.SAMBA_SUBSYSTEM('torturemain',
-                    source='smbtorture.c torture.c',
+                    source='smbtorture.c torture.c shell.c',
                     subsystem_name='smbtorture',
                     deps='torture popt POPT_SAMBA POPT_CREDENTIALS dcerpc LIBCLI_SMB SMBREADLINE ' + TORTURE_MODULES,
                     needs_python=True