Line data Source code
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 "librpc/gen_ndr/ndr_srvsvc_c.h"
24 : #include "torture/rpc/torture_rpc.h"
25 :
26 : /**************************/
27 : /* srvsvc_NetShare */
28 : /**************************/
29 0 : static bool test_NetShareEnumAll(struct dcerpc_pipe *p, TALLOC_CTX *mem_ctx)
30 : {
31 : NTSTATUS status;
32 : struct srvsvc_NetShareEnumAll r;
33 : struct srvsvc_NetShareInfoCtr info_ctr;
34 : struct srvsvc_NetShareCtr0 c0;
35 : struct srvsvc_NetShareCtr1 c1;
36 : struct srvsvc_NetShareCtr2 c2;
37 : struct srvsvc_NetShareCtr501 c501;
38 : struct srvsvc_NetShareCtr502 c502;
39 0 : uint32_t totalentries = 0;
40 0 : uint32_t levels[] = {0, 1, 2, 501, 502};
41 : int i;
42 0 : bool ret = true;
43 : uint32_t resume_handle;
44 0 : struct dcerpc_binding_handle *b = p->binding_handle;
45 :
46 0 : ZERO_STRUCT(info_ctr);
47 :
48 0 : r.in.server_unc = talloc_asprintf(mem_ctx,"\\\\%s",dcerpc_server_name(p));
49 0 : r.in.info_ctr = &info_ctr;
50 0 : r.in.max_buffer = (uint32_t)-1;
51 0 : r.in.resume_handle = &resume_handle;
52 0 : r.out.resume_handle = &resume_handle;
53 0 : r.out.totalentries = &totalentries;
54 0 : r.out.info_ctr = &info_ctr;
55 :
56 0 : for (i=0;i<ARRAY_SIZE(levels);i++) {
57 0 : resume_handle = 0;
58 0 : info_ctr.level = levels[i];
59 :
60 0 : switch (info_ctr.level) {
61 0 : case 0:
62 0 : ZERO_STRUCT(c0);
63 0 : info_ctr.ctr.ctr0 = &c0;
64 0 : break;
65 0 : case 1:
66 0 : ZERO_STRUCT(c1);
67 0 : info_ctr.ctr.ctr1 = &c1;
68 0 : break;
69 0 : case 2:
70 0 : ZERO_STRUCT(c2);
71 0 : info_ctr.ctr.ctr2 = &c2;
72 0 : break;
73 0 : case 501:
74 0 : ZERO_STRUCT(c501);
75 0 : info_ctr.ctr.ctr501 = &c501;
76 0 : break;
77 0 : case 502:
78 0 : ZERO_STRUCT(c502);
79 0 : info_ctr.ctr.ctr502 = &c502;
80 0 : break;
81 : }
82 :
83 0 : status = dcerpc_srvsvc_NetShareEnumAll_r(b, mem_ctx, &r);
84 0 : if (!NT_STATUS_IS_OK(status)) {
85 0 : printf("NetShareEnumAll level %u failed - %s\n", info_ctr.level, nt_errstr(status));
86 0 : ret = false;
87 0 : continue;
88 : }
89 0 : if (!W_ERROR_IS_OK(r.out.result)) {
90 0 : printf("NetShareEnumAll level %u failed - %s\n", info_ctr.level, win_errstr(r.out.result));
91 0 : continue;
92 : }
93 : }
94 :
95 0 : return ret;
96 : }
97 :
98 : /*
99 : benchmark srvsvc netshareenumall queries
100 : */
101 0 : static bool bench_NetShareEnumAll(struct torture_context *tctx, struct dcerpc_pipe *p, TALLOC_CTX *mem_ctx)
102 : {
103 0 : struct timeval tv = timeval_current();
104 0 : bool ret = true;
105 0 : int timelimit = torture_setting_int(tctx, "timelimit", 10);
106 0 : int count=0;
107 :
108 0 : printf("Running for %d seconds\n", timelimit);
109 0 : while (timeval_elapsed(&tv) < timelimit) {
110 0 : TALLOC_CTX *tmp_ctx = talloc_new(mem_ctx);
111 0 : if (!test_NetShareEnumAll(p, tmp_ctx)) break;
112 0 : talloc_free(tmp_ctx);
113 0 : count++;
114 0 : if (count % 50 == 0) {
115 0 : if (torture_setting_bool(tctx, "progress", true)) {
116 0 : printf("%.1f queries per second \r",
117 0 : count / timeval_elapsed(&tv));
118 : }
119 : }
120 : }
121 :
122 0 : printf("%.1f queries per second \n", count / timeval_elapsed(&tv));
123 :
124 0 : return ret;
125 : }
126 :
127 :
128 0 : bool torture_bench_rpc(struct torture_context *torture)
129 : {
130 : NTSTATUS status;
131 : struct dcerpc_pipe *p;
132 : TALLOC_CTX *mem_ctx;
133 0 : bool ret = true;
134 :
135 0 : mem_ctx = talloc_init("torture_rpc_srvsvc");
136 :
137 0 : status = torture_rpc_connection(torture,
138 : &p,
139 : &ndr_table_srvsvc);
140 0 : if (!NT_STATUS_IS_OK(status)) {
141 0 : talloc_free(mem_ctx);
142 0 : return false;
143 : }
144 :
145 0 : if (!bench_NetShareEnumAll(torture, p, mem_ctx)) {
146 0 : ret = false;
147 : }
148 :
149 0 : talloc_free(mem_ctx);
150 :
151 0 : return ret;
152 : }
|