| 1 |
/* |
| 2 |
Unix SMB/CIFS implementation. |
| 3 |
|
| 4 |
NBT name query testing |
| 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 "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" |
| 28 |
|
| 29 |
struct result_struct { |
| 30 |
int num_pass; |
| 31 |
int num_fail; |
| 32 |
}; |
| 33 |
|
| 34 |
static void increment_handler(struct nbt_name_request *req) |
| 35 |
{ |
| 36 |
struct result_struct *v = talloc_get_type(req->async.private_data, struct result_struct); |
| 37 |
if (req->state != NBT_REQUEST_DONE) { |
| 38 |
v->num_fail++; |
| 39 |
} else { |
| 40 |
v->num_pass++; |
| 41 |
} |
| 42 |
talloc_free(req); |
| 43 |
} |
| 44 |
|
| 45 |
/* |
| 46 |
benchmark simple name queries |
| 47 |
*/ |
| 48 |
static bool bench_namequery(struct torture_context *tctx) |
| 49 |
{ |
| 50 |
struct nbt_name_socket *nbtsock = torture_init_nbt_socket(tctx); |
| 51 |
int num_sent=0; |
| 52 |
struct result_struct *result; |
| 53 |
struct nbt_name_query io = { |
| 54 |
.in = { |
| 55 |
.retries = 0, |
| 56 |
} |
| 57 |
}; |
| 58 |
struct timeval tv = timeval_current(); |
| 59 |
int timelimit = torture_setting_int(tctx, "timelimit", 5); |
| 60 |
|
| 61 |
const char *address; |
| 62 |
struct nbt_name name; |
| 63 |
|
| 64 |
if (!torture_nbt_get_name(tctx, &name, &address)) |
| 65 |
return false; |
| 66 |
|
| 67 |
io.in.name = name; |
| 68 |
io.in.dest_addr = address; |
| 69 |
io.in.dest_port = lpcfg_nbt_port(tctx->lp_ctx); |
| 70 |
io.in.broadcast = false; |
| 71 |
io.in.wins_lookup = false; |
| 72 |
io.in.timeout = 1; |
| 73 |
|
| 74 |
result = talloc_zero(tctx, struct result_struct); |
| 75 |
|
| 76 |
torture_comment(tctx, "Running for %d seconds\n", timelimit); |
| 77 |
while (timeval_elapsed(&tv) < timelimit) { |
| 78 |
while (num_sent - (result->num_pass+result->num_fail) < 10) { |
| 79 |
struct nbt_name_request *req; |
| 80 |
req = nbt_name_query_send(nbtsock, &io); |
| 81 |
torture_assert(tctx, req != NULL, "Failed to setup request!"); |
| 82 |
req->async.fn = increment_handler; |
| 83 |
req->async.private_data = result; |
| 84 |
num_sent++; |
| 85 |
if (num_sent % 1000 == 0) { |
| 86 |
if (torture_setting_bool(tctx, "progress", true)) { |
| 87 |
torture_comment(tctx, "%.1f queries per second (%d failures) \r", |
| 88 |
result->num_pass / timeval_elapsed(&tv), |
| 89 |
result->num_fail); |
| 90 |
fflush(stdout); |
| 91 |
} |
| 92 |
} |
| 93 |
} |
| 94 |
|
| 95 |
tevent_loop_once(nbtsock->event_ctx); |
| 96 |
} |
| 97 |
|
| 98 |
while (num_sent != (result->num_pass + result->num_fail)) { |
| 99 |
tevent_loop_once(nbtsock->event_ctx); |
| 100 |
} |
| 101 |
|
| 102 |
torture_comment(tctx, "%.1f queries per second (%d failures) \n", |
| 103 |
result->num_pass / timeval_elapsed(&tv), |
| 104 |
result->num_fail); |
| 105 |
|
| 106 |
return true; |
| 107 |
} |
| 108 |
|
| 109 |
|
| 110 |
/* |
| 111 |
benchmark how fast a server can respond to name queries |
| 112 |
*/ |
| 113 |
struct torture_suite *torture_bench_nbt(TALLOC_CTX *mem_ctx) |
| 114 |
{ |
| 115 |
struct torture_suite *suite = torture_suite_create(mem_ctx, "bench"); |
| 116 |
torture_suite_add_simple_test(suite, "namequery", bench_namequery); |
| 117 |
|
| 118 |
return suite; |
| 119 |
} |