LCOV - code coverage report
Current view: top level - source4/libcli/resolve - testsuite.c (source / functions) Hit Total Coverage
Test: coverage report for vadcx-master-patch-75612 fe003de8 Lines: 38 38 100.0 %
Date: 2024-02-29 22:57:05 Functions: 3 3 100.0 %

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

Generated by: LCOV version 1.14