2 Unix SMB/CIFS implementation.
6 Copyright (C) Andrew Tridgell 2005
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.
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.
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/>.
23 #include "libcli/cldap/cldap.h"
24 #include "libcli/resolve/resolve.h"
25 #include "torture/torture.h"
26 #include "param/param.h"
27 #include "../lib/tsocket/tsocket.h"
29 #define CHECK_VAL(v, correct) torture_assert_int_equal(tctx, (v), (correct), "incorrect value");
32 struct torture_context *tctx;
33 int pass_count, fail_count;
36 static void request_netlogon_handler(struct tevent_req *req)
38 struct cldap_netlogon io;
39 struct bench_state *state = tevent_req_callback_data(req, struct bench_state);
41 TALLOC_CTX *tmp_ctx = talloc_new(NULL);
43 status = cldap_netlogon_recv(req, tmp_ctx, &io);
45 if (NT_STATUS_IS_OK(status)) {
54 benchmark cldap netlogon calls
56 static bool bench_cldap_netlogon(struct torture_context *tctx, const char *address)
58 struct cldap_socket *cldap;
60 struct timeval tv = timeval_current();
61 int timelimit = torture_setting_int(tctx, "timelimit", 10);
62 struct cldap_netlogon search;
63 struct bench_state *state;
65 struct tsocket_address *dest_addr;
68 ret = tsocket_address_inet_from_strings(tctx, "ip",
70 lp_cldap_port(tctx->lp_ctx),
74 status = cldap_socket_init(tctx, tctx->ev, NULL, dest_addr, &cldap);
75 torture_assert_ntstatus_ok(tctx, status, "cldap_socket_init");
77 state = talloc_zero(tctx, struct bench_state);
81 search.in.dest_address = NULL;
82 search.in.dest_port = 0;
83 search.in.acct_control = -1;
84 search.in.version = 6;
86 printf("Running CLDAP/netlogon for %d seconds\n", timelimit);
87 while (timeval_elapsed(&tv) < timelimit) {
88 while (num_sent - (state->pass_count+state->fail_count) < 10) {
89 struct tevent_req *req;
90 req = cldap_netlogon_send(state, cldap, &search);
92 tevent_req_set_callback(req, request_netlogon_handler, state);
95 if (num_sent % 50 == 0) {
96 if (torture_setting_bool(tctx, "progress", true)) {
97 printf("%.1f queries per second (%d failures) \r",
98 state->pass_count / timeval_elapsed(&tv),
105 tevent_loop_once(tctx->ev);
108 while (num_sent != (state->pass_count + state->fail_count)) {
109 tevent_loop_once(tctx->ev);
112 printf("%.1f queries per second (%d failures) \n",
113 state->pass_count / timeval_elapsed(&tv),
120 static void request_rootdse_handler(struct tevent_req *req)
122 struct cldap_search io;
123 struct bench_state *state = tevent_req_callback_data(req, struct bench_state);
125 TALLOC_CTX *tmp_ctx = talloc_new(NULL);
126 status = cldap_search_recv(req, tmp_ctx, &io);
128 if (NT_STATUS_IS_OK(status)) {
133 talloc_free(tmp_ctx);
137 benchmark cldap netlogon calls
139 static bool bench_cldap_rootdse(struct torture_context *tctx, const char *address)
141 struct cldap_socket *cldap;
143 struct timeval tv = timeval_current();
144 int timelimit = torture_setting_int(tctx, "timelimit", 10);
145 struct cldap_search search;
146 struct bench_state *state;
148 struct tsocket_address *dest_addr;
151 ret = tsocket_address_inet_from_strings(tctx, "ip",
153 lp_cldap_port(tctx->lp_ctx),
157 /* cldap_socket_init should now know about the dest. address */
158 status = cldap_socket_init(tctx, tctx->ev, NULL, dest_addr, &cldap);
159 torture_assert_ntstatus_ok(tctx, status, "cldap_socket_init");
161 state = talloc_zero(tctx, struct bench_state);
164 search.in.dest_address = NULL;
165 search.in.dest_port = 0;
166 search.in.filter = "(objectClass=*)";
167 search.in.timeout = 2;
168 search.in.retries = 1;
170 printf("Running CLDAP/rootdse for %d seconds\n", timelimit);
171 while (timeval_elapsed(&tv) < timelimit) {
172 while (num_sent - (state->pass_count+state->fail_count) < 10) {
173 struct tevent_req *req;
174 req = cldap_search_send(state, cldap, &search);
176 tevent_req_set_callback(req, request_rootdse_handler, state);
179 if (num_sent % 50 == 0) {
180 if (torture_setting_bool(tctx, "progress", true)) {
181 printf("%.1f queries per second (%d failures) \r",
182 state->pass_count / timeval_elapsed(&tv),
189 tevent_loop_once(tctx->ev);
192 while (num_sent != (state->pass_count + state->fail_count)) {
193 tevent_loop_once(tctx->ev);
196 printf("%.1f queries per second (%d failures) \n",
197 state->pass_count / timeval_elapsed(&tv),
205 benchmark how fast a CLDAP server can respond to a series of parallel
208 bool torture_bench_cldap(struct torture_context *torture)
211 struct nbt_name name;
215 make_nbt_name_server(&name, torture_setting_string(torture, "host", NULL));
217 /* do an initial name resolution to find its IP */
218 status = resolve_name(lp_resolve_context(torture->lp_ctx), &name, torture, &address, torture->ev);
219 if (!NT_STATUS_IS_OK(status)) {
220 printf("Failed to resolve %s - %s\n",
221 name.name, nt_errstr(status));
225 ret &= bench_cldap_netlogon(torture, address);
226 ret &= bench_cldap_rootdse(torture, address);