From: Eric Bollengier Date: Tue, 12 May 2020 08:47:49 +0000 (+0200) Subject: BEE Backport bacula/src/tools/test_tags.c X-Git-Tag: Release-11.3.2~1685 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=ebd97e897b9dfb554b7b8fcddad06a584bb4b29a;p=thirdparty%2Fbacula.git BEE Backport bacula/src/tools/test_tags.c This commit is the result of the squash of the following main commits: Author: Eric Bollengier Date: Mon Jan 28 10:40:15 2019 +0100 Update copyright year Author: Eric Bollengier Date: Thu Sep 6 15:17:45 2018 +0200 regress: Add unittests for tags, bpipe and breaddir Author: Eric Bollengier Date: Sat Aug 30 07:57:09 2014 +0200 regress: Add small tool to test debug tags --- diff --git a/bacula/src/tools/test_tags.c b/bacula/src/tools/test_tags.c new file mode 100644 index 0000000000..9907c9d759 --- /dev/null +++ b/bacula/src/tools/test_tags.c @@ -0,0 +1,98 @@ +/* + Bacula(R) - The Network Backup Solution + + Copyright (C) 2000-2020 Kern Sibbald + + The original author of Bacula is Kern Sibbald, with contributions + from many others, a complete list can be found in the file AUTHORS. + + You may use this file and others of this release according to the + license defined in the LICENSE file, which includes the Affero General + Public License, v3.0 ("AGPLv3") and some additional permissions and + terms pursuant to its AGPLv3 Section 7. + + This notice must be preserved when any source code is + conveyed and/or propagated. + + Bacula(R) is a registered trademark of Kern Sibbald. +*/ +/* Simple tool to test chk_dbglvl() macro */ + +#include "bacula.h" +#include "lib/unittests.h" + +void *start_heap; + +int main (int argc, char *argv[]) +{ + Unittests t("tags_test", true, true); + start_heap = sbrk(0); + setlocale(LC_ALL, ""); + bindtextdomain("bacula", LOCALEDIR); + textdomain("bacula"); + init_stack_dump(); + my_name_is(argc, argv, "dmsg"); + init_msg(NULL, NULL); + daemon_start_time = time(NULL); + set_working_directory("/tmp/"); + set_thread_concurrency(150); + + debug_level = 0; + debug_level_tags = 0; + + nok(chk_dbglvl(10), "debug_level < 10"); + ok(chk_dbglvl(0), "lvl 0"); + nok(chk_dbglvl(DT_NETWORK), "no tag defined"); + nok(chk_dbglvl(DT_NETWORK|10), "no tag, debug_level < 10"); + + debug_level = 10; + debug_level_tags = 0; + + ok(chk_dbglvl(10), "debug_level = 10"); + ok(chk_dbglvl(0), "lvl 0"); + nok(chk_dbglvl(DT_NETWORK), "no tag defined"); + nok(chk_dbglvl(DT_NETWORK|10), "no tag, debug_level = 10"); + + debug_level = 20; + debug_level_tags = 0; + + ok(chk_dbglvl(10), "debug_level > 10"); + ok(chk_dbglvl(0), "lvl 0"); + nok(chk_dbglvl(DT_NETWORK), "no tag defined"); + nok(chk_dbglvl(DT_NETWORK|10), "no tag, debug_level = 20"); + + debug_level = 20; + debug_level_tags = DT_NETWORK; + + ok(chk_dbglvl(10), "debug_level > 10"); + ok(chk_dbglvl(0), "lvl 0"); + ok(chk_dbglvl(DT_NETWORK), "network tag defined"); + ok(chk_dbglvl(DT_NETWORK|10), "tag defined, debug_level > lvl"); + nok(chk_dbglvl(DT_NETWORK|30), "tag defined, debug_level < lvl"); + + debug_level = 0; + debug_level_tags = 0; + ok(debug_parse_tags("network,volume", &debug_level_tags), "parse tags"); + + nok(chk_dbglvl(10), "debug_level > 10"); + ok(chk_dbglvl(0), "lvl 0"); + ok(chk_dbglvl(DT_NETWORK), "network tag defined"); + nok(chk_dbglvl(DT_NETWORK|10), "tag defined, debug_level > lvl"); + + ok(debug_parse_tags("!network,!volume", &debug_level_tags), "parse tags"); + + nok(chk_dbglvl(10), "debug_level > 10"); + ok(chk_dbglvl(0), "lvl 0"); + nok(chk_dbglvl(DT_NETWORK), "network tag not defined"); + nok(chk_dbglvl(DT_NETWORK|10), "no tag, debug_level > lvl"); + + ok(debug_parse_tags("all,!network", &debug_level_tags), "parse tags"); + nok(chk_dbglvl(DT_NETWORK), "network not defined"); + ok(chk_dbglvl(DT_VOLUME), "volume tag defined"); + ok(chk_dbglvl(DT_SQL), "sql tag defined"); + + nok(debug_parse_tags("blabla", &debug_level_tags), "bad tags"); + ok(debug_parse_tags("", &debug_level_tags), "empty tags"); + term_msg(); + return report(); +}