r12510: Change the DCE/RPC interfaces to take a pointer to a
[bbaumbach/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 2 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, write to the Free Software
20    Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
21 */
22
23 #include "includes.h"
24 #include "librpc/gen_ndr/ndr_srvsvc.h"
25
26 /**************************/
27 /* srvsvc_NetShare        */
28 /**************************/
29 static BOOL test_NetShareEnumAll(struct dcerpc_pipe *p, TALLOC_CTX *mem_ctx)
30 {
31         NTSTATUS status;
32         struct srvsvc_NetShareEnumAll r;
33         struct srvsvc_NetShareCtr0 c0;
34         uint32_t levels[] = {0, 1, 2, 501, 502};
35         int i;
36         BOOL ret = True;
37         uint32_t resume_handle;
38
39         ZERO_STRUCT(c0);
40
41         r.in.server_unc = talloc_asprintf(mem_ctx,"\\\\%s",dcerpc_server_name(p));
42         r.in.ctr.ctr0 = &c0;
43         r.in.max_buffer = (uint32_t)-1;
44         r.in.resume_handle = &resume_handle;
45         r.out.resume_handle = &resume_handle;
46
47         for (i=0;i<ARRAY_SIZE(levels);i++) {
48                 ZERO_STRUCT(r.out);
49                 resume_handle = 0;
50                 r.in.level = levels[i];
51                 status = dcerpc_srvsvc_NetShareEnumAll(p, mem_ctx, &r);
52                 if (!NT_STATUS_IS_OK(status)) {
53                         printf("NetShareEnumAll level %u failed - %s\n", r.in.level, nt_errstr(status));
54                         ret = False;
55                         continue;
56                 }
57                 if (!W_ERROR_IS_OK(r.out.result)) {
58                         printf("NetShareEnumAll level %u failed - %s\n", r.in.level, win_errstr(r.out.result));
59                         continue;
60                 }
61         }
62
63         return ret;
64 }
65
66 /*
67   benchmark srvsvc netshareenumall queries
68 */
69 static BOOL bench_NetShareEnumAll(struct dcerpc_pipe *p, TALLOC_CTX *mem_ctx)
70 {
71         struct timeval tv = timeval_current();
72         BOOL ret = True;
73         int timelimit = lp_parm_int(-1, "torture", "timelimit", 10);
74         int count=0;
75
76         printf("Running for %d seconds\n", timelimit);
77         while (timeval_elapsed(&tv) < timelimit) {
78                 TALLOC_CTX *tmp_ctx = talloc_new(mem_ctx);
79                 if (!test_NetShareEnumAll(p, tmp_ctx)) break;
80                 talloc_free(tmp_ctx);
81                 count++;
82                 if (count % 50 == 0) {
83                         printf("%.1f queries per second  \r", 
84                                count / timeval_elapsed(&tv));
85                 }
86         }
87
88         printf("%.1f queries per second  \n", count / timeval_elapsed(&tv));
89
90         return ret;
91 }
92
93
94 BOOL torture_bench_rpc(void)
95 {
96         NTSTATUS status;
97         struct dcerpc_pipe *p;
98         TALLOC_CTX *mem_ctx;
99         BOOL ret = True;
100
101         mem_ctx = talloc_init("torture_rpc_srvsvc");
102
103         status = torture_rpc_connection(mem_ctx, 
104                                         &p,
105                                         &dcerpc_table_srvsvc);
106         if (!NT_STATUS_IS_OK(status)) {
107                 talloc_free(mem_ctx);
108                 return False;
109         }
110
111         if (!bench_NetShareEnumAll(p, mem_ctx)) {
112                 ret = False;
113         }
114
115         talloc_free(mem_ctx);
116
117         return ret;
118 }