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 "lib/events/events.h"
24 #include "libcli/resolve/resolve.h"
25 #include "torture/torture.h"
26 #include "torture/nbt/proto.h"
27 #include "param/param.h"
29 struct result_struct {
34 static void increment_handler(struct nbt_name_request *req)
36 struct result_struct *v = talloc_get_type(req->async.private, struct result_struct);
37 if (req->state != NBT_REQUEST_DONE) {
46 benchmark simple name queries
48 static bool bench_namequery(struct torture_context *tctx)
50 struct nbt_name_socket *nbtsock = nbt_name_socket_init(tctx, tctx->ev,
51 lp_iconv_convenience(tctx->lp_ctx));
53 struct result_struct *result;
54 struct nbt_name_query io;
55 struct timeval tv = timeval_current();
56 int timelimit = torture_setting_int(tctx, "timelimit", 5);
61 if (!torture_nbt_get_name(tctx, &name, &address))
65 io.in.dest_addr = address;
66 io.in.dest_port = lp_nbt_port(tctx->lp_ctx);
67 io.in.broadcast = false;
68 io.in.wins_lookup = false;
71 result = talloc_zero(tctx, struct result_struct);
73 torture_comment(tctx, "Running for %d seconds\n", timelimit);
74 while (timeval_elapsed(&tv) < timelimit) {
75 while (num_sent - (result->num_pass+result->num_fail) < 10) {
76 struct nbt_name_request *req;
77 req = nbt_name_query_send(nbtsock, &io);
78 torture_assert(tctx, req != NULL, "Failed to setup request!");
79 req->async.fn = increment_handler;
80 req->async.private = result;
82 if (num_sent % 1000 == 0) {
83 if (torture_setting_bool(tctx, "progress", true)) {
84 torture_comment(tctx, "%.1f queries per second (%d failures) \r",
85 result->num_pass / timeval_elapsed(&tv),
92 event_loop_once(nbtsock->event_ctx);
95 while (num_sent != (result->num_pass + result->num_fail)) {
96 event_loop_once(nbtsock->event_ctx);
99 torture_comment(tctx, "%.1f queries per second (%d failures) \n",
100 result->num_pass / timeval_elapsed(&tv),
108 benchmark how fast a server can respond to name queries
110 struct torture_suite *torture_bench_nbt(TALLOC_CTX *mem_ctx)
112 struct torture_suite *suite = torture_suite_create(mem_ctx, "BENCH");
113 torture_suite_add_simple_test(suite, "namequery", bench_namequery);