LCOV - code coverage report
Current view: top level - source4/torture/libnetapi - libnetapi_server.c (source / functions) Hit Total Coverage
Test: coverage report for master 2b515b7d Lines: 21 30 70.0 %
Date: 2024-02-28 12:06:22 Functions: 1 1 100.0 %

          Line data    Source code
       1             : /*
       2             :    Unix SMB/CIFS implementation.
       3             :    SMB torture tester
       4             :    Copyright (C) Guenther Deschner 2010
       5             : 
       6             :    This program is free software; you can redistribute it and/or modify
       7             :    it under the terms of the GNU General Public License as published by
       8             :    the Free Software Foundation; either version 3 of the License, or
       9             :    (at your option) any later version.
      10             : 
      11             :    This program is distributed in the hope that it will be useful,
      12             :    but WITHOUT ANY WARRANTY; without even the implied warranty of
      13             :    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
      14             :    GNU General Public License for more details.
      15             : 
      16             :    You should have received a copy of the GNU General Public License
      17             :    along with this program.  If not, see <http://www.gnu.org/licenses/>.
      18             : */
      19             : 
      20             : #include "includes.h"
      21             : #include "torture/smbtorture.h"
      22             : #include <netapi.h>
      23             : #include "torture/libnetapi/proto.h"
      24             : 
      25             : #define NETAPI_STATUS(tctx, x,y,fn) \
      26             :         torture_warning(tctx, "FAILURE: line %d: %s failed with status: %s (%d)\n", \
      27             :                 __LINE__, fn, libnetapi_get_error_string(x,y), y);
      28             : 
      29           1 : bool torture_libnetapi_server(struct torture_context *tctx)
      30             : {
      31           1 :         NET_API_STATUS status = 0;
      32           1 :         uint8_t *buffer = NULL;
      33           0 :         int i;
      34             : 
      35           1 :         const char *hostname = torture_setting_string(tctx, "host", NULL);
      36           0 :         struct libnetapi_ctx *ctx;
      37             : 
      38           1 :         torture_assert(tctx, torture_libnetapi_init_context(tctx, &ctx),
      39             :                        "failed to initialize libnetapi");
      40             : 
      41           1 :         torture_comment(tctx, "NetServer tests\n");
      42             : 
      43           1 :         torture_comment(tctx, "Testing NetRemoteTOD\n");
      44             : 
      45           1 :         status = NetRemoteTOD(hostname, &buffer);
      46           1 :         if (status) {
      47           0 :                 NETAPI_STATUS(tctx, ctx, status, "NetRemoteTOD");
      48           0 :                 goto out;
      49             :         }
      50           1 :         NetApiBufferFree(buffer);
      51             : 
      52           1 :         torture_comment(tctx, "Testing NetRemoteTOD 10 times\n");
      53             : 
      54          11 :         for (i=0; i<10; i++) {
      55          10 :                 status = NetRemoteTOD(hostname, &buffer);
      56          10 :                 if (status) {
      57           0 :                         NETAPI_STATUS(tctx, ctx, status, "NetRemoteTOD");
      58           0 :                         goto out;
      59             :                 }
      60          10 :                 NetApiBufferFree(buffer);
      61             :         }
      62             : 
      63           1 :         status = 0;
      64             : 
      65           1 :         torture_comment(tctx, "NetServer tests succeeded\n");
      66           1 :  out:
      67           1 :         if (status != 0) {
      68           0 :                 torture_comment(tctx, "NetServer testsuite failed with: %s\n",
      69             :                         libnetapi_get_error_string(ctx, status));
      70           0 :                 libnetapi_free(ctx);
      71           0 :                 return false;
      72             :         }
      73             : 
      74           1 :         libnetapi_free(ctx);
      75           1 :         return true;
      76             : }

Generated by: LCOV version 1.14