smbtorture: Move interactive shell into a separate file.
[gd/samba-autobuild/.git] / source4 / torture / shell.c
1 /*
2    Unix SMB/CIFS implementation.
3    SMB torture tester
4    Copyright (C) Andrew Tridgell 1997-2003
5    Copyright (C) Jelmer Vernooij 2006-2008
6
7    This program is free software; you can redistribute it and/or modify
8    it under the terms of the GNU General Public License as published by
9    the Free Software Foundation; either version 3 of the License, or
10    (at your option) any later version.
11
12    This program is distributed in the hope that it will be useful,
13    but WITHOUT ANY WARRANTY; without even the implied warranty of
14    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
15    GNU General Public License for more details.
16
17    You should have received a copy of the GNU General Public License
18    along with this program.  If not, see <http://www.gnu.org/licenses/>.
19 */
20
21 #include "includes.h"
22 #include "system/readline.h"
23 #include "lib/smbreadline/smbreadline.h"
24 #include "torture/smbtorture.h"
25
26 void torture_shell(struct torture_context *tctx)
27 {
28         char *cline;
29         int argc;
30         const char **argv;
31         int ret;
32
33         while (1) {
34                 cline = smb_readline("torture> ", NULL, NULL);
35
36                 if (cline == NULL)
37                         return;
38
39 #if HAVE_ADD_HISTORY
40                 add_history(cline);
41 #endif
42
43                 ret = poptParseArgvString(cline, &argc, &argv);
44                 if (ret != 0) {
45                         fprintf(stderr, "Error parsing line\n");
46                         continue;
47                 }
48
49                 if (!strcmp(argv[0], "quit")) {
50                         return;
51                 } else if (!strcmp(argv[0], "list")) {
52                         torture_print_tests(true);
53                 } else if (!strcmp(argv[0], "set")) {
54                         if (argc < 3) {
55                                 lp_dump(tctx->lp_ctx, stdout,
56                                         false /* show_defaults */,
57                                         0 /* skip services */);
58                         } else {
59                                 char *name = talloc_asprintf(NULL, "torture:%s", argv[1]);
60                                 lp_set_cmdline(tctx->lp_ctx, name, argv[2]);
61                                 talloc_free(name);
62                         }
63                 } else if (!strcmp(argv[0], "help")) {
64                         fprintf(stderr, "Available commands:\n"
65                                                         " help - This help command\n"
66                                                         " list - List the available\n"
67                                                         " run - Run test\n"
68                                                         " set - Change variables\n"
69                                                         "\n");
70                 } else if (!strcmp(argv[0], "run")) {
71                         if (argc < 2) {
72                                 fprintf(stderr, "Usage: run TEST-NAME [OPTIONS...]\n");
73                         } else {
74                                 torture_run_named_tests(tctx, argv[1]);
75                         }
76                 }
77                 free(cline);
78         }
79 }