From: Eric Bollengier Date: Thu, 24 Mar 2022 14:51:42 +0000 (+0100) Subject: Add breaddir unittest X-Git-Tag: Release-11.3.2~8 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=6c349f81f749f0eedf2a6bc472e90a2694b28ec8;p=thirdparty%2Fbacula.git Add breaddir unittest --- diff --git a/bacula/src/tools/breaddir.c b/bacula/src/tools/breaddir.c new file mode 100644 index 000000000..7267f7b48 --- /dev/null +++ b/bacula/src/tools/breaddir.c @@ -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 +#include +#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(); +}