]> git.ipfire.org Git - thirdparty/bacula.git/commitdiff
Add breaddir unittest
authorEric Bollengier <eric@baculasystems.com>
Thu, 24 Mar 2022 14:51:42 +0000 (15:51 +0100)
committerEric Bollengier <eric@baculasystems.com>
Thu, 24 Mar 2022 14:51:42 +0000 (15:51 +0100)
bacula/src/tools/breaddir.c [new file with mode: 0644]

diff --git a/bacula/src/tools/breaddir.c b/bacula/src/tools/breaddir.c
new file mode 100644 (file)
index 0000000..7267f7b
--- /dev/null
@@ -0,0 +1,65 @@
+/*
+   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.
+*/
+
+#include <sys/types.h>
+#include <dirent.h>
+#include "../bacula.h"
+#include "../lib/unittests.h"
+
+int breaddir(DIR *dirp, POOLMEM *&d_name);
+
+void *th1(void *)
+{
+   int nb=0;
+   intptr_t ret;
+   POOL_MEM p;
+   while (nb++ < 100) {
+      DIR *dir = opendir(".");
+      if (dir) {
+         while ((ret = breaddir(dir, p.addr())) == 0) {
+            /* nop */
+         }
+         if (ret > 0) {
+            berrno be;
+            Dmsg1(0, "errno=%s\n", be.bstrerror());
+         }
+         closedir(dir);
+      }
+   }
+   return (void *)ret;
+}
+
+
+int main()
+{
+   void *ret;
+   pthread_t t1[100];
+
+   Unittests t("breaddir_test", true, true);
+   t.configure(TEST_QUIET);
+
+   for (int i=0; i < 100; i++) {
+      pthread_create(&(t1[i]), NULL, th1, NULL);
+   }
+   for (int i=0; i < 100; i++) {
+      pthread_join(t1[i], &ret);
+      ok((intptr_t)ret == -1, "Check the readdir() value");
+   }
+   return report();
+}