From 7349f261aa4c3e7d2553579bd253c76cf0bb6215 Mon Sep 17 00:00:00 2001 From: Eric Bollengier Date: Wed, 4 Aug 2021 16:01:55 +0200 Subject: [PATCH] regress: Add test for debug-tags functions --- bacula/src/tools/Makefile.in | 4 +++ bacula/src/tools/debug-tags.c | 51 +++++++++++++++++++++++++++++++++++ regress/tests/debug-tags-test | 13 +++++++++ 3 files changed, 68 insertions(+) create mode 100644 bacula/src/tools/debug-tags.c create mode 100755 regress/tests/debug-tags-test diff --git a/bacula/src/tools/Makefile.in b/bacula/src/tools/Makefile.in index 30b396abe..0326bca00 100644 --- a/bacula/src/tools/Makefile.in +++ b/bacula/src/tools/Makefile.in @@ -67,6 +67,10 @@ all: Makefile $(TOOLS) gigaslam grow test-cpp: test-cpp.o ../lib/unittests.o $(LIBTOOL_LINK) $(CXX) $(LDFLAGS) -L../lib -o $@ test-cpp.o ../lib/unittests.o -lbac $(DLIB) $(LIBS) $(GETTEXT_LIBS) $(OPENSSL_LIBS) +debug-tags_test: debug-tags.o ../lib/unittests.o + $(LIBTOOL_LINK) $(CXX) $(LDFLAGS) -L../lib -o $@ debug-tags.o ../lib/unittests.o -lbac $(DLIB) $(LIBS) $(GETTEXT_LIBS) $(OPENSSL_LIBS) + $(INSTALL_PROGRAM) $@ $(DESTDIR)$(sbindir)/ + fs-io-error: fs-io-error.c $(CXX) -Wall fs-io-error.c -D_FILE_OFFSET_BITS=64 -lfuse -o fs-io-error diff --git a/bacula/src/tools/debug-tags.c b/bacula/src/tools/debug-tags.c new file mode 100644 index 000000000..158b56471 --- /dev/null +++ b/bacula/src/tools/debug-tags.c @@ -0,0 +1,51 @@ +/* + Bacula(R) - The Network Backup Solution + + Copyright (C) 2000-2022 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. +*/ + +/* Written by Eric Bollengier */ + +#include "bacula.h" +#include "lib/unittests.h" + + +void test_list(int64_t tags, int nb, const char *format) +{ + alist tlist(10, not_owned_by_alist); + debug_get_tags_list(&tlist, tags); + is(tlist.size(), nb, "Parse simple tags back"); + + POOL_MEM tmp; + debug_get_tags(tmp.handle(), tags); + is(tmp.c_str(), format, "Check tags format"); +} + +int main(int argc, char **argv) +{ + int64_t tags=0; + Unittests alist_test("debug-tags"); + log("Test debug tags feature"); + + ok(debug_parse_tags("network,snapshot", &tags), "Parse simple tags"); + is(tags, DT_NETWORK|DT_SNAPSHOT, "Check simple parsing"); + test_list(tags, 2, "network,snapshot"); + + ok(debug_parse_tags("network,!snapshot", &tags), "Parse tag deletion"); + is(tags, DT_NETWORK, "Check tag deletion"); + test_list(tags, 1, "network"); + return report(); +} diff --git a/regress/tests/debug-tags-test b/regress/tests/debug-tags-test new file mode 100755 index 000000000..f603ecc31 --- /dev/null +++ b/regress/tests/debug-tags-test @@ -0,0 +1,13 @@ +#!/bin/sh +# +# Copyright (C) 2000-2015 Kern Sibbald +# License: BSD 2-Clause; see file LICENSE-FOSS +# +# This is an alist unit test +# +TestName="debug-tags_test" +. scripts/functions +make -C $src/src/tools $TestName + +$bin/$TestName +exit $? -- 2.47.3