2 Unix SMB/CIFS implementation.
4 local test for async resolve code
6 Copyright (C) Andrew Tridgell 2004
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.
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, write to the Free Software
20 Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
24 #include "lib/events/events.h"
25 #include "libcli/resolve/resolve.h"
27 static BOOL test_async_resolve(TALLOC_CTX *mem_ctx)
30 struct event_context *ev = event_context_find(mem_ctx);
31 int timelimit = lp_parm_int(-1, "torture", "timelimit", 10);
32 const char *host = lp_parm_string(-1, "torture", "host");
34 struct timeval tv = timeval_current();
39 printf("Testing async resolve of localhost for %d seconds\n", timelimit);
40 while (timeval_elapsed(&tv) < timelimit) {
42 struct composite_context *c = resolve_name_host_send(&n, ev);
43 NTSTATUS status = resolve_name_host_recv(c, mem_ctx, &s);
44 if (!NT_STATUS_IS_OK(status)) {
45 printf("async resolve failed - %s\n", nt_errstr(status));
51 printf("async rate of %.1f resolves/sec\n", count/timeval_elapsed(&tv));
56 test resolution using sync method
58 static BOOL test_sync_resolve(TALLOC_CTX *mem_ctx)
60 int timelimit = lp_parm_int(-1, "torture", "timelimit", 10);
61 struct timeval tv = timeval_current();
63 const char *host = lp_parm_string(-1, "torture", "host");
65 printf("Testing sync resolve of localhost for %d seconds\n", timelimit);
66 while (timeval_elapsed(&tv) < timelimit) {
67 sys_inet_ntoa(interpret_addr2(host));
71 printf("sync rate of %.1f resolves/sec\n", count/timeval_elapsed(&tv));
76 BOOL torture_local_resolve(void)
78 TALLOC_CTX *mem_ctx = talloc_init("torture_local_irpc");
81 ret &= test_sync_resolve(mem_ctx);
82 ret &= test_async_resolve(mem_ctx);