LCOV - code coverage report
Current view: top level - lib/util/tests - test_logging.c (source / functions) Hit Total Coverage
Test: coverage report for vadcx-master-patch-75612 fe003de8 Lines: 36 48 75.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             :    A test server that only does logging.
       5             : 
       6             :    Copyright (C) Andrew Tridgell                1992-2005
       7             :    Copyright (C) Martin Pool                    2002
       8             :    Copyright (C) Jelmer Vernooij                2002
       9             :    Copyright (C) James J Myers                  2003 <myersjj@samba.org>
      10             :    Copyright (C) Douglas Bagnall                2022
      11             : 
      12             :    This program is free software; you can redistribute it and/or modify
      13             :    it under the terms of the GNU General Public License as published by
      14             :    the Free Software Foundation; either version 3 of the License, or
      15             :    (at your option) any later version.
      16             : 
      17             :    This program is distributed in the hope that it will be useful,
      18             :    but WITHOUT ANY WARRANTY; without even the implied warranty of
      19             :    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
      20             :    GNU General Public License for more details.
      21             : 
      22             :    You should have received a copy of the GNU General Public License
      23             :    along with this program.  If not, see <http://www.gnu.org/licenses/>.
      24             : */
      25             : 
      26             : #include "includes.h"
      27             : #include "lib/cmdline/cmdline.h"
      28             : 
      29             : #ifdef USING_CMDLINE_S3
      30             : #include "lib/util/debug_s3.h"
      31             : #endif
      32             : 
      33             : #define BINARY_NAME "test_s4_logging"
      34             : 
      35             : static int log_level = 1;
      36             : 
      37             : 
      38             : #include "lib/util/debug-classes/debug-classname-table.c"
      39             : 
      40          28 : static int log_all_classes(int level)
      41             : {
      42          28 :         size_t i;
      43          28 :         const char *name = NULL;
      44        1092 :         for (i = 0; i < ARRAY_SIZE(default_classname_table); i++) {
      45        1064 :                 name = default_classname_table[i];
      46        1064 :                 DEBUGC(i, level,
      47             :                        ("logging for '%s' [%zu], at level %d\n",
      48             :                         name, i, level));
      49             : 
      50             :                 /*
      51             :                  * That's it for the tests *here*. The invoker of this
      52             :                  * process will have set up an smb.conf that directs the
      53             :                  * output in particular ways, and will be looking to see that
      54             :                  * happens correctly.
      55             :                  */
      56             :         }
      57          28 :         return 0;
      58             : }
      59             : 
      60             : 
      61          28 : static int init_daemon(TALLOC_CTX *mem_ctx,
      62             :                        int argc,
      63             :                        const char *argv[],
      64             :                        const char **error)
      65             : {
      66          28 :         poptContext pc;
      67          28 :         int opt;
      68          28 :         bool ok;
      69         112 :         struct poptOption long_options[] = {
      70             :                 POPT_AUTOHELP
      71             :                 {
      72             :                         .longName   = "level",
      73             :                         .shortName  = 'L',
      74             :                         .argInfo    = POPT_ARG_INT,
      75             :                         .arg        = &log_level,
      76             :                         .descrip    = "log at this level",
      77             :                         .argDescrip = "LEVEL",
      78             :                 },
      79          28 :                 POPT_COMMON_SAMBA
      80          28 :                 POPT_COMMON_DAEMON
      81          28 :                 POPT_COMMON_VERSION
      82             :                 POPT_TABLEEND
      83             :         };
      84             : 
      85          28 :         setproctitle(BINARY_NAME);
      86             : 
      87          28 :         ok = samba_cmdline_init(mem_ctx,
      88             :                                 SAMBA_CMDLINE_CONFIG_SERVER,
      89             :                                 true /* require_smbconf */);
      90          28 :         if (!ok) {
      91           0 :                 *error = "Failed to init cmdline parser!\n";
      92           0 :                 return EINVAL;
      93             :         }
      94             : 
      95          28 :         pc = samba_popt_get_context(BINARY_NAME,
      96             :                                     argc,
      97             :                                     argv,
      98             :                                     long_options,
      99             :                                     0);
     100          28 :         if (pc == NULL) {
     101           0 :                 *error = "Failed to setup popt context!\n";
     102           0 :                 return ENOTRECOVERABLE;
     103             :         }
     104             : 
     105          28 :         while((opt = poptGetNextOpt(pc)) != -1) {
     106           0 :                 fprintf(stderr, "\nInvalid option %s: %s\n\n",
     107             :                         poptBadOption(pc, 0), poptStrerror(opt));
     108           0 :                 poptPrintUsage(pc, stderr, 0);
     109           0 :                 return 1;
     110             :         }
     111             : 
     112          28 :         poptFreeContext(pc);
     113             : 
     114             : #ifdef USING_CMDLINE_S3
     115          14 :         reopen_logs();
     116             : #endif
     117          28 :         return 0;
     118             : }
     119             : 
     120             : 
     121          28 : int main(int argc, const char *argv[])
     122             : {
     123          28 :         int rc;
     124          28 :         const char *error = NULL;
     125          28 :         TALLOC_CTX *mem_ctx = talloc_stackframe();
     126          28 :         if (mem_ctx == NULL) {
     127           0 :                 exit(ENOMEM);
     128             :         }
     129             : 
     130          28 :         setproctitle_init(argc, discard_const(argv), environ);
     131             : 
     132          28 :         rc = init_daemon(mem_ctx, argc, argv, &error);
     133          28 :         if (rc != 0) {
     134           0 :                 fprintf(stderr, "error [%d]: %s\n", rc, error);
     135           0 :                 exit_daemon(error, rc);
     136             :         }
     137             : 
     138          28 :         rc = log_all_classes(log_level);
     139          28 :         if (rc != 0) {
     140           0 :                 fprintf(stderr, "error in log_all_classes [%d]\n", rc);
     141           0 :                 exit_daemon("logging error", rc);
     142             :         }
     143             : 
     144          28 :         TALLOC_FREE(mem_ctx);
     145          28 :         return rc;
     146             : }

Generated by: LCOV version 1.14