r13924: Split more prototypes out of include/proto.h + initial work on header
[bbaumbach/samba-autobuild/.git] / source / torture / local / resolve.c
1 /* 
2    Unix SMB/CIFS implementation.
3
4    local test for async resolve code
5
6    Copyright (C) Andrew Tridgell 2004
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 2 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, write to the Free Software
20    Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
21 */
22
23 #include "includes.h"
24 #include "lib/events/events.h"
25 #include "libcli/resolve/resolve.h"
26
27 static BOOL test_async_resolve(TALLOC_CTX *mem_ctx)
28 {
29         struct nbt_name n;
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");
33         int count = 0;
34         struct timeval tv = timeval_current();
35
36         ZERO_STRUCT(n);
37         n.name = host;
38
39         printf("Testing async resolve of localhost for %d seconds\n", timelimit);
40         while (timeval_elapsed(&tv) < timelimit) {
41                 const char *s;
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));
46                         return False;
47                 }
48                 count++;
49         }
50
51         printf("async rate of %.1f resolves/sec\n", count/timeval_elapsed(&tv));
52         return True;
53 }
54
55 /*
56   test resolution using sync method
57 */
58 static BOOL test_sync_resolve(TALLOC_CTX *mem_ctx)
59 {
60         int timelimit = lp_parm_int(-1, "torture", "timelimit", 10);
61         struct timeval tv = timeval_current();
62         int count = 0;
63         const char *host = lp_parm_string(-1, "torture", "host");
64
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));
68                 count++;
69         }
70         
71         printf("sync rate of %.1f resolves/sec\n", count/timeval_elapsed(&tv));
72         return True;
73 }
74
75
76 BOOL torture_local_resolve(void) 
77 {
78         TALLOC_CTX *mem_ctx = talloc_init("torture_local_irpc");
79         BOOL ret = True;
80
81         ret &= test_sync_resolve(mem_ctx);
82         ret &= test_async_resolve(mem_ctx);
83
84         talloc_free(mem_ctx);
85
86         return ret;
87 }