r16333: Move more code out of the core smbtorture. It now no longer
[tprouty/samba.git] / source4 / torture / torture.c
1 /* 
2    Unix SMB/CIFS implementation.
3    SMB torture tester
4    Copyright (C) Andrew Tridgell 1997-2003
5    Copyright (C) Jelmer Vernooij 2006
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 2 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, write to the Free Software
19    Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
20 */
21
22 #include "includes.h"
23 #include "system/time.h"
24 #include "torture/torture.h"
25 #include "build.h"
26 #include "dlinklist.h"
27
28 _PUBLIC_ int torture_nprocs=4;
29 _PUBLIC_ int torture_numops=10;
30 _PUBLIC_ int torture_entries=1000;
31 _PUBLIC_ int torture_failures=1;
32 _PUBLIC_ int torture_seed=0;
33 _PUBLIC_ int torture_numasync=100;
34 _PUBLIC_ BOOL use_oplocks;
35 _PUBLIC_ BOOL use_level_II_oplocks;
36 _PUBLIC_ BOOL torture_showall = False;
37
38 struct torture_suite_list *torture_suites = NULL;
39
40 NTSTATUS torture_register_suite(struct torture_suite *suite)
41 {
42         struct torture_suite_list *p, *n;
43
44         n = talloc(talloc_autofree_context(), struct torture_suite_list);
45         n->suite = suite;
46
47         for (p = torture_suites; p; p = p->next) {
48                 if (strcmp(p->suite->name, suite->name) == 0) {
49                         /* Check for duplicates */
50                         DEBUG(0,("There already is a suite registered with the name %s!\n", suite->name));
51                         return NT_STATUS_OBJECT_NAME_COLLISION;
52                 }
53
54                 if (strcmp(p->suite->name, suite->name) < 0 && 
55                         (!p->next || strcmp(p->next->suite->name, suite->name) > 0)) {
56                         DLIST_ADD_AFTER(torture_suites, n, p);
57                         return NT_STATUS_OK;
58                 }
59         }
60
61         DLIST_ADD(torture_suites, n);
62
63         return NT_STATUS_OK;
64 }
65
66 static BOOL wrap_old_torture_fn(struct torture_context *torture,
67                                                                 const void *_fn)
68 {
69         BOOL (*fn)(struct torture_context *) = _fn;
70         return fn(torture);
71 }
72
73
74 /* Backwards compatibility wrapper */
75 _PUBLIC_ NTSTATUS register_torture_op(const char *name, BOOL (*fn)(struct torture_context *))
76 {
77         struct torture_suite *suite;
78         suite = torture_suite_create(talloc_autofree_context(), name);
79
80         torture_suite_add_simple_tcase(suite, name, 
81                                                                    wrap_old_torture_fn,
82                                                                    fn);
83         torture_register_suite(suite);
84
85         return NT_STATUS_OK;
86 }
87
88 int torture_init(void)
89 {
90         init_module_fn static_init[] = STATIC_torture_MODULES;
91         init_module_fn *shared_init = load_samba_modules(NULL, "torture");
92         
93         run_init_functions(static_init);
94         run_init_functions(shared_init);
95
96         talloc_free(shared_init);
97
98         return 0;
99 }