source: vendor/3.6.0/source4/libcli/resolve/testsuite.c

Last change on this file was 740, checked in by Silvan Scherrer, 13 years ago

Samba Server: update vendor to 3.6.0

File size: 2.8 KB
Line 
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 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 "system/network.h"
27#include "lib/util/util_net.h"
28
29static bool test_async_resolve(struct torture_context *tctx)
30{
31 struct nbt_name n;
32 struct tevent_context *ev;
33 int timelimit = torture_setting_int(tctx, "timelimit", 2);
34 const char *host = torture_setting_string(tctx, "host", NULL);
35 int count = 0;
36 struct timeval tv = timeval_current();
37 TALLOC_CTX *mem_ctx = tctx;
38
39 ev = tctx->ev;
40
41 ZERO_STRUCT(n);
42 n.name = host;
43
44 torture_comment(tctx, "Testing async resolve of '%s' for %d seconds\n",
45 host, timelimit);
46 while (timeval_elapsed(&tv) < timelimit) {
47 struct socket_address **s;
48 struct composite_context *c = resolve_name_host_send(mem_ctx, ev, NULL, 0, 0, &n);
49 torture_assert(tctx, c != NULL, "resolve_name_host_send");
50 torture_assert_ntstatus_ok(tctx, resolve_name_host_recv(c, mem_ctx, &s, NULL),
51 "async resolve failed");
52 count++;
53 }
54
55 torture_comment(tctx, "async rate of %.1f resolves/sec\n",
56 count/timeval_elapsed(&tv));
57 return true;
58}
59
60/*
61 test resolution using sync method
62*/
63static bool test_sync_resolve(struct torture_context *tctx)
64{
65 int timelimit = torture_setting_int(tctx, "timelimit", 2);
66 struct timeval tv = timeval_current();
67 int count = 0;
68 const char *host = torture_setting_string(tctx, "host", NULL);
69
70 torture_comment(tctx, "Testing sync resolve of '%s' for %d seconds\n",
71 host, timelimit);
72 while (timeval_elapsed(&tv) < timelimit) {
73 inet_ntoa(interpret_addr2(host));
74 count++;
75 }
76
77 torture_comment(tctx, "sync rate of %.1f resolves/sec\n",
78 count/timeval_elapsed(&tv));
79 return true;
80}
81
82
83struct torture_suite *torture_local_resolve(TALLOC_CTX *mem_ctx)
84{
85 struct torture_suite *suite = torture_suite_create(mem_ctx, "resolve");
86
87 torture_suite_add_simple_test(suite, "async", test_async_resolve);
88 torture_suite_add_simple_test(suite, "sync", test_sync_resolve);
89
90 return suite;
91}
Note: See TracBrowser for help on using the repository browser.