]> git.ipfire.org Git - thirdparty/bacula.git/commitdiff
Add little bpipe_test in tools/
authorEric Bollengier <eric@baculasystems.com>
Mon, 9 Mar 2020 09:23:15 +0000 (10:23 +0100)
committerEric Bollengier <eric@baculasystems.com>
Mon, 22 Jun 2020 08:49:24 +0000 (10:49 +0200)
bacula/src/tools/Makefile.in
bacula/src/tools/bpipe_test.c [new file with mode: 0644]

index abd66199df4d3dd1c2af96286d133fc831dfaa92..35faddc09305533e75d0107b92478444995e3ecd 100644 (file)
@@ -94,6 +94,11 @@ timelimit: timelimit.o
        ${CC} ${DEFS} ${DEBUG} -pipe -DHAVE_ERRNO_H -DHAVE_SETITIMER -DHAVE_SIGACTION -c timelimit.c 
        ${CC} -o timelimit timelimit.o
 
+bpipe_test: bpipe_test.o ../lib/libbac$(DEFAULT_ARCHIVE_TYPE)
+       $(MAKE) -C ../lib alist_test
+       $(LIBTOOL_LINK) $(CXX) -g $(LDFLAGS) -L. -L../lib -L../findlib -o $@ bpipe_test.o ../lib/unittests.o \
+               $(DLIB) -lbac -lm $(LIBS) $(GETTEXT_LIBS) $(OPENSSL_LIBS)
+
 testfind: Makefile ../lib/libbac$(DEFAULT_ARCHIVE_TYPE) ../lib/libbaccfg$(DEFAULT_ARCHIVE_TYPE) \
          ../findlib/libbacfind$(DEFAULT_ARCHIVE_TYPE) $(FINDOBJS)
        $(LIBTOOL_LINK) $(CXX) -g $(LDFLAGS) -o $@ $(FINDOBJS) -L. -L../lib -L../findlib \
diff --git a/bacula/src/tools/bpipe_test.c b/bacula/src/tools/bpipe_test.c
new file mode 100644 (file)
index 0000000..2238fbb
--- /dev/null
@@ -0,0 +1,48 @@
+/*
+   Bacula® - The Network Backup Solution
+
+   Copyright (C) 2000-2020 Bacula Systems SA
+   All rights reserved.
+
+   The main author of Bacula is Kern Sibbald, with contributions from many
+   others, a complete list can be found in the file AUTHORS.
+
+   Licensees holding a valid Bacula Systems SA license may use this file
+   and others of this release in accordance with the proprietary license
+   agreement provided in the LICENSE file.  Redistribution of any part of
+   this release is not permitted.
+
+   Bacula® is a registered trademark of Kern Sibbald.
+*/
+
+#include "bacula.h"
+#include "../lib/unittests.h"
+
+int main(int argc, char **argv)
+{
+   Unittests u("t");
+   char buf[512] = {0};
+   BPIPE *bp;
+   FILE *fp;
+   fp = fopen("toto.sh", "w");
+   fprintf(fp, "#!/bin/sh\necho hello\nread a\necho $a\n");
+   fclose(fp);
+   chmod("toto.sh", 0755);
+   
+   bp = open_bpipe("./toto.sh", 0, "rw");
+   ok(bp != NULL, "open_bpipe");
+
+   fgets(buf, sizeof(buf), bp->rfd);
+   ok(strcmp(buf, "hello\n") == 0, "fgets on bpipe");
+   printf("%s", buf);
+
+   fprintf(bp->wfd, "titi\n");
+   fflush(bp->wfd);
+
+   fgets(buf, sizeof(buf), bp->rfd);
+   ok(strcmp(buf, "titi\n") == 0, "fgets on bpipe");
+   printf("%s", buf);
+   
+   ok(close_bpipe(bp) == 0, "closing bpipe");
+   return report();
+}