r25554: Convert last instances of BOOL, True and False to the standard types.
[kai/samba-autobuild/.git] / source4 / torture / rpc / bench.c
1 /* 
2    Unix SMB/CIFS implementation.
3
4    simple RPC benchmark
5
6    Copyright (C) Andrew Tridgell 2005
7    
8    This program is free software; you can redistribute it and/or modify
9    it under the terms of the GNU General Public License as published by
10    the Free Software Foundation; either version 3 of the License, or
11    (at your option) any later version.
12    
13    This program is distributed in the hope that it will be useful,
14    but WITHOUT ANY WARRANTY; without even the implied warranty of
15    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
16    GNU General Public License for more details.
17    
18    You should have received a copy of the GNU General Public License
19    along with this program.  If not, see <http://www.gnu.org/licenses/>.
20 */
21
22 #include "includes.h"
23 #include "torture/torture.h"
24 #include "librpc/gen_ndr/ndr_srvsvc_c.h"
25 #include "torture/rpc/rpc.h"
26 #include "param/param.h"
27
28 /**************************/
29 /* srvsvc_NetShare        */
30 /**************************/
31 static bool test_NetShareEnumAll(struct dcerpc_pipe *p, TALLOC_CTX *mem_ctx)
32 {
33         NTSTATUS status;
34         struct srvsvc_NetShareEnumAll r;
35         struct srvsvc_NetShareCtr0 c0;
36         uint32_t levels[] = {0, 1, 2, 501, 502};
37         int i;
38         bool ret = true;
39         uint32_t resume_handle;
40
41         ZERO_STRUCT(c0);
42
43         r.in.server_unc = talloc_asprintf(mem_ctx,"\\\\%s",dcerpc_server_name(p));
44         r.in.ctr.ctr0 = &c0;
45         r.in.max_buffer = (uint32_t)-1;
46         r.in.resume_handle = &resume_handle;
47         r.out.resume_handle = &resume_handle;
48
49         for (i=0;i<ARRAY_SIZE(levels);i++) {
50                 ZERO_STRUCT(r.out);
51                 resume_handle = 0;
52                 r.in.level = levels[i];
53                 status = dcerpc_srvsvc_NetShareEnumAll(p, mem_ctx, &r);
54                 if (!NT_STATUS_IS_OK(status)) {
55                         printf("NetShareEnumAll level %u failed - %s\n", r.in.level, nt_errstr(status));
56                         ret = false;
57                         continue;
58                 }
59                 if (!W_ERROR_IS_OK(r.out.result)) {
60                         printf("NetShareEnumAll level %u failed - %s\n", r.in.level, win_errstr(r.out.result));
61                         continue;
62                 }
63         }
64
65         return ret;
66 }
67
68 /*
69   benchmark srvsvc netshareenumall queries
70 */
71 static bool bench_NetShareEnumAll(struct dcerpc_pipe *p, TALLOC_CTX *mem_ctx)
72 {
73         struct timeval tv = timeval_current();
74         bool ret = true;
75         int timelimit = lp_parm_int(global_loadparm, NULL, "torture", "timelimit", 10);
76         int count=0;
77
78         printf("Running for %d seconds\n", timelimit);
79         while (timeval_elapsed(&tv) < timelimit) {
80                 TALLOC_CTX *tmp_ctx = talloc_new(mem_ctx);
81                 if (!test_NetShareEnumAll(p, tmp_ctx)) break;
82                 talloc_free(tmp_ctx);
83                 count++;
84                 if (count % 50 == 0) {
85                         if (lp_parm_bool(global_loadparm, NULL, "torture", "progress", true)) {
86                                 printf("%.1f queries per second  \r", 
87                                        count / timeval_elapsed(&tv));
88                         }
89                 }
90         }
91
92         printf("%.1f queries per second  \n", count / timeval_elapsed(&tv));
93
94         return ret;
95 }
96
97
98 bool torture_bench_rpc(struct torture_context *torture)
99 {
100         NTSTATUS status;
101         struct dcerpc_pipe *p;
102         TALLOC_CTX *mem_ctx;
103         bool ret = true;
104
105         mem_ctx = talloc_init("torture_rpc_srvsvc");
106
107         status = torture_rpc_connection(torture, 
108                                         &p,
109                                         &ndr_table_srvsvc);
110         if (!NT_STATUS_IS_OK(status)) {
111                 talloc_free(mem_ctx);
112                 return false;
113         }
114
115         if (!bench_NetShareEnumAll(p, mem_ctx)) {
116                 ret = false;
117         }
118
119         talloc_free(mem_ctx);
120
121         return ret;
122 }