util/debug: share classname table with tests
authorDouglas Bagnall <douglas.bagnall@catalyst.net.nz>
Thu, 16 Jun 2022 05:26:08 +0000 (17:26 +1200)
committerAndrew Bartlett <abartlet@samba.org>
Fri, 17 Jun 2022 01:28:30 +0000 (01:28 +0000)
The executables generated from lib/util/tests/test_logging.c are used
by the samba.tests.logfiles tests to test logging with various
smb.confs that assign classes to various files at different levels
etc.

Previously test_logging.c had its own version of the table; now it
shares one with debug.c

We put the table in a sub-directory (lib/util/debug-classes/), because
adding local_include=True to the wscript_build stanza causes the
compiler confusion between <time.h> and lib/util/time.h.

Note: there are still two other lists of the class names, in
python/samba/tests/logfiles.py and
docs-xml/smbdotconf/logging/loglevel.xml.

Signed-off-by: Douglas Bagnall <douglas.bagnall@catalyst.net.nz>
Reviewed-by: Andrew Bartlett <abartlet@samba.org>
lib/util/debug-classes/debug-classname-table.c [new file with mode: 0644]
lib/util/debug.c
lib/util/tests/test_logging.c
lib/util/wscript_build

diff --git a/lib/util/debug-classes/debug-classname-table.c b/lib/util/debug-classes/debug-classname-table.c
new file mode 100644 (file)
index 0000000..9062078
--- /dev/null
@@ -0,0 +1,62 @@
+/*
+   Unix SMB/CIFS implementation.
+   Samba utility functions
+   Copyright (C) Andrew Tridgell 1992-1998
+   Copyright (C) Elrond               2002
+   Copyright (C) Simo Sorce           2002
+
+   This program is free software; you can redistribute it and/or modify
+   it under the terms of the GNU General Public License as published by
+   the Free Software Foundation; either version 3 of the License, or
+   (at your option) any later version.
+
+   This program is distributed in the hope that it will be useful,
+   but WITHOUT ANY WARRANTY; without even the implied warranty of
+   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+   GNU General Public License for more details.
+
+   You should have received a copy of the GNU General Public License
+   along with this program.  If not, see <http://www.gnu.org/licenses/>.
+*/
+
+
+static const char *default_classname_table[] = {       
+       [DBGC_ALL] =                    "all",
+       [DBGC_TDB] =                    "tdb",
+       [DBGC_PRINTDRIVERS] =           "printdrivers",
+       [DBGC_LANMAN] =                 "lanman",
+       [DBGC_SMB] =                    "smb",
+       [DBGC_RPC_PARSE] =              "rpc_parse",
+       [DBGC_RPC_SRV] =                "rpc_srv",
+       [DBGC_RPC_CLI] =                "rpc_cli",
+       [DBGC_PASSDB] =                 "passdb",
+       [DBGC_SAM] =                    "sam",
+       [DBGC_AUTH] =                   "auth",
+       [DBGC_WINBIND] =                "winbind",
+       [DBGC_VFS] =                    "vfs",
+       [DBGC_IDMAP] =                  "idmap",
+       [DBGC_QUOTA] =                  "quota",
+       [DBGC_ACLS] =                   "acls",
+       [DBGC_LOCKING] =                "locking",
+       [DBGC_MSDFS] =                  "msdfs",
+       [DBGC_DMAPI] =                  "dmapi",
+       [DBGC_REGISTRY] =               "registry",
+       [DBGC_SCAVENGER] =              "scavenger",
+       [DBGC_DNS] =                    "dns",
+       [DBGC_LDB] =                    "ldb",
+       [DBGC_TEVENT] =                 "tevent",
+       [DBGC_AUTH_AUDIT] =             "auth_audit",
+       [DBGC_AUTH_AUDIT_JSON] =        "auth_json_audit",
+       [DBGC_KERBEROS] =               "kerberos",
+       [DBGC_DRS_REPL] =               "drs_repl",
+       [DBGC_SMB2] =                   "smb2",
+       [DBGC_SMB2_CREDITS] =           "smb2_credits",
+       [DBGC_DSDB_AUDIT] =             "dsdb_audit",
+       [DBGC_DSDB_AUDIT_JSON] =        "dsdb_json_audit",
+       [DBGC_DSDB_PWD_AUDIT]  =        "dsdb_password_audit",
+       [DBGC_DSDB_PWD_AUDIT_JSON] =    "dsdb_password_json_audit",
+       [DBGC_DSDB_TXN_AUDIT]  =        "dsdb_transaction_audit",
+       [DBGC_DSDB_TXN_AUDIT_JSON] =    "dsdb_transaction_json_audit",
+       [DBGC_DSDB_GROUP_AUDIT] =       "dsdb_group_audit",
+       [DBGC_DSDB_GROUP_AUDIT_JSON] =  "dsdb_group_json_audit",
+};
index 4ec5766a292e03ee213b965835f95286461ac530..24d8281d27f85c16c9d279ad11fe4b7193f37e6e 100644 (file)
@@ -124,46 +124,11 @@ struct debug_class {
        ino_t ino;
 };
 
-static const char *default_classname_table[] = {
-       [DBGC_ALL] =                    "all",
-       [DBGC_TDB] =                    "tdb",
-       [DBGC_PRINTDRIVERS] =           "printdrivers",
-       [DBGC_LANMAN] =                 "lanman",
-       [DBGC_SMB] =                    "smb",
-       [DBGC_RPC_PARSE] =              "rpc_parse",
-       [DBGC_RPC_SRV] =                "rpc_srv",
-       [DBGC_RPC_CLI] =                "rpc_cli",
-       [DBGC_PASSDB] =                 "passdb",
-       [DBGC_SAM] =                    "sam",
-       [DBGC_AUTH] =                   "auth",
-       [DBGC_WINBIND] =                "winbind",
-       [DBGC_VFS] =                    "vfs",
-       [DBGC_IDMAP] =                  "idmap",
-       [DBGC_QUOTA] =                  "quota",
-       [DBGC_ACLS] =                   "acls",
-       [DBGC_LOCKING] =                "locking",
-       [DBGC_MSDFS] =                  "msdfs",
-       [DBGC_DMAPI] =                  "dmapi",
-       [DBGC_REGISTRY] =               "registry",
-       [DBGC_SCAVENGER] =              "scavenger",
-       [DBGC_DNS] =                    "dns",
-       [DBGC_LDB] =                    "ldb",
-       [DBGC_TEVENT] =                 "tevent",
-       [DBGC_AUTH_AUDIT] =             "auth_audit",
-       [DBGC_AUTH_AUDIT_JSON] =        "auth_json_audit",
-       [DBGC_KERBEROS] =               "kerberos",
-       [DBGC_DRS_REPL] =               "drs_repl",
-       [DBGC_SMB2] =                   "smb2",
-       [DBGC_SMB2_CREDITS] =           "smb2_credits",
-       [DBGC_DSDB_AUDIT] =             "dsdb_audit",
-       [DBGC_DSDB_AUDIT_JSON] =        "dsdb_json_audit",
-       [DBGC_DSDB_PWD_AUDIT]  =        "dsdb_password_audit",
-       [DBGC_DSDB_PWD_AUDIT_JSON] =    "dsdb_password_json_audit",
-       [DBGC_DSDB_TXN_AUDIT]  =        "dsdb_transaction_audit",
-       [DBGC_DSDB_TXN_AUDIT_JSON] =    "dsdb_transaction_json_audit",
-       [DBGC_DSDB_GROUP_AUDIT] =       "dsdb_group_audit",
-       [DBGC_DSDB_GROUP_AUDIT_JSON] =  "dsdb_group_json_audit",
-};
+/*
+ * default_classname_table[] is read in from debug-classname-table.c
+ * so that test_logging.c can use it too.
+ */
+#include "lib/util/debug-classes/debug-classname-table.c"
 
 /*
  * This is to allow reading of dbgc_config before the debug
index f7c6585e8914e636b38c93b76d53c1def9577c44..9b13b052f25435914ea769e7db5d1da08b095c22 100644 (file)
 static int log_level = 1;
 
 
-struct debug_class {
-       int dclass;
-       const char *name;
-};
-
-struct debug_class classes_table[] = {
-       {DBGC_ALL, "all"},
-       {DBGC_TDB, "tdb"},
-       {DBGC_PRINTDRIVERS, "printdrivers"},
-       {DBGC_LANMAN, "lanman"},
-       {DBGC_SMB, "smb"},
-       {DBGC_RPC_PARSE, "rpc_parse"},
-       {DBGC_RPC_SRV, "rpc_srv"},
-       {DBGC_RPC_CLI, "rpc_cli"},
-       {DBGC_PASSDB, "passdb"},
-       {DBGC_SAM, "sam"},
-       {DBGC_AUTH, "auth"},
-       {DBGC_WINBIND, "winbind"},
-       {DBGC_VFS, "vfs"},
-       {DBGC_IDMAP, "idmap"},
-       {DBGC_QUOTA, "quota"},
-       {DBGC_ACLS, "acls"},
-       {DBGC_LOCKING, "locking"},
-       {DBGC_MSDFS, "msdfs"},
-       {DBGC_DMAPI, "dmapi"},
-       {DBGC_REGISTRY, "registry"},
-       {DBGC_SCAVENGER, "scavenger"},
-       {DBGC_DNS, "dns"},
-       {DBGC_LDB, "ldb"},
-       {DBGC_TEVENT, "tevent"},
-       {DBGC_AUTH_AUDIT, "auth_audit"},
-       {DBGC_AUTH_AUDIT_JSON, "auth_json_audit"},
-       {DBGC_KERBEROS, "kerberos"},
-       {DBGC_DRS_REPL, "drs_repl"},
-       {DBGC_SMB2, "smb2"},
-       {DBGC_SMB2_CREDITS, "smb2_credits"},
-       {DBGC_DSDB_AUDIT, "dsdb_audit"},
-       {DBGC_DSDB_AUDIT_JSON, "dsdb_json_audit"},
-       {DBGC_DSDB_PWD_AUDIT, "dsdb_password_audit"},
-       {DBGC_DSDB_PWD_AUDIT_JSON, "dsdb_password_json_audit"},
-       {DBGC_DSDB_TXN_AUDIT, "dsdb_transaction_audit"},
-       {DBGC_DSDB_TXN_AUDIT_JSON, "dsdb_transaction_json_audit"},
-       {DBGC_DSDB_GROUP_AUDIT, "dsdb_group_audit"},
-       {DBGC_DSDB_GROUP_AUDIT_JSON, "dsdb_group_json_audit"},
-};
-
+#include "lib/util/debug-classes/debug-classname-table.c"
 
 static int log_all_classes(int level)
 {
        size_t i;
-       struct debug_class c;
-       for (i = 0; i < ARRAY_SIZE(classes_table); i++) {
-               c = classes_table[i];
-               if (i != c.dclass) {
-                       /*
-                        * we implicitly rely on these values staying in the
-                        * right order.
-                        */
-                       fprintf(stderr,
-                               "expected '%s' class to have value %zu\n",
-                               c.name, i);
-                       return 1;
-               }
-
-               DEBUGC(c.dclass, level,
-                      ("logging for '%s' [%d], at level %d\n",
-                       c.name, c.dclass, level));
+       const char *name = NULL;
+       for (i = 0; i < ARRAY_SIZE(default_classname_table); i++) {
+               name = default_classname_table[i];
+               DEBUGC(i, level,
+                      ("logging for '%s' [%zu], at level %d\n",
+                       name, i, level));
 
                /*
                 * That's it for the tests *here*. The invoker of this
index 5b5a3d23906a57159e7fc69e005630601455cefe..e2194e68e3ed475890d4ca6f35d2a5f471f63c11 100644 (file)
@@ -53,7 +53,7 @@ bld.SAMBA_LIBRARY('samba-debug',
                   deps='replace time-basic close-low-fd talloc socket-blocking' + samba_debug_add_deps,
                   public_deps='systemd systemd-journal lttng-ust',
                   local_include=False,
-                  includes=samba_debug_add_inc,
+                  includes='lib/util/debug-classes ' + samba_debug_add_inc,
                   private_library=True)
 
 bld.SAMBA_LIBRARY('socket-blocking',