From d3ab56ab32896b33f9c8d5edf23390355baa65d2 Mon Sep 17 00:00:00 2001 From: Philipp Storz Date: Fri, 14 Sep 2018 11:24:20 +0200 Subject: [PATCH] cleanup core/src/tests directory - moved "testls" to tools and renamed to "btestls" adapted all regression tests using testls - remove other core/src/tests binaries and replaced them with standard tools --- core/src/tests/CMakeLists.txt | 31 - core/src/tests/bbatch.cc | 379 ---------- core/src/tests/bregtest.cc | 155 ---- core/src/tests/cats_test.cc | 709 ------------------ core/src/tests/gigaslam.cc | 53 -- core/src/tests/grow.cc | 59 -- core/src/tools/CMakeLists.txt | 5 +- .../src/{tests/testls.cc => tools/btestls.cc} | 0 regress/tests/big-vol-test | 6 +- regress/tests/dev-test-root | 4 +- regress/tests/etc-test-root | 4 +- regress/tests/lib-tape-root | 4 +- regress/tests/lib-test-root | 4 +- regress/tests/regexwhere-test | 319 -------- regress/tests/speed-test | 143 ---- regress/tests/usr-tape-root | 4 +- regress/tests/weird-files2-test | 4 +- 17 files changed, 19 insertions(+), 1864 deletions(-) delete mode 100644 core/src/tests/bbatch.cc delete mode 100644 core/src/tests/bregtest.cc delete mode 100644 core/src/tests/cats_test.cc delete mode 100644 core/src/tests/gigaslam.cc delete mode 100644 core/src/tests/grow.cc rename core/src/{tests/testls.cc => tools/btestls.cc} (100%) delete mode 100755 regress/tests/regexwhere-test delete mode 100755 regress/tests/speed-test diff --git a/core/src/tests/CMakeLists.txt b/core/src/tests/CMakeLists.txt index ba0f6395fc9..cf758068eed 100644 --- a/core/src/tests/CMakeLists.txt +++ b/core/src/tests/CMakeLists.txt @@ -18,34 +18,3 @@ # 02110-1301, USA. -add_executable(bregtest bregtest.cc ) -target_link_libraries(bregtest bareos ${JANSSON_LIBRARIES}) - -add_executable(testls testls.cc) -target_link_libraries(testls bareosfind bareos ${JANSSON_LIBRARIES}) - -IF(NOT HAVE_WIN32) - add_executable(bbatch bbatch.cc) - target_link_libraries(bbatch bareoscats bareossql bareos ${JANSSON_LIBRARIES}) -ENDIF() - -#add_executable(bvfs_test bvfs_test.cc) -#target_link_libraries(bvfs_test bareoscats bareossql) - -#add_executable(cats_test cats_test.cc) -#target_link_libraries(cats_test bareoscats bareossql) - -add_executable(gigaslam gigaslam.cc) -target_link_libraries(gigaslam) - -add_executable(grow grow.cc) -target_link_libraries(grow bareos ${JANSSON_LIBRARIES}) - -set (TESTS_SBIN - bregtest grow testls - ) -IF(NOT HAVE_WIN32) - LIST(APPEND TESTS_SBIN bbatch) -ENDIF() - -INSTALL(TARGETS ${TESTS_SBIN} DESTINATION "${sbindir}") diff --git a/core/src/tests/bbatch.cc b/core/src/tests/bbatch.cc deleted file mode 100644 index be5e703e872..00000000000 --- a/core/src/tests/bbatch.cc +++ /dev/null @@ -1,379 +0,0 @@ -/* - BAREOS® - Backup Archiving REcovery Open Sourced - - Copyright (C) 2001-2006 Free Software Foundation Europe e.V. - - This program is Free Software; you can redistribute it and/or - modify it under the terms of version three of the GNU Affero General Public - License as published by the Free Software Foundation and included - in the file LICENSE. - - This program is distributed in the hope that it will be useful, but - WITHOUT ANY WARRANTY; without even the implied warranty of - MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU - Affero General Public License for more details. - - You should have received a copy of the GNU Affero General Public License - along with this program; if not, write to the Free Software - Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA - 02110-1301, USA. -*/ -/* - * Program to test batch mode - * - * Eric Bollengier, March 2007 - */ - -/* - to create datafile - - for i in $(seq 10000 99999) ; do - j=$((($i % 1000) + 555)) - echo "$i;/tmp/totabofds$j/fiddddle${j}$i;xxxLSTATxxxx;xxxxxxxMD5xxxxxx" - done > dat1 - - or - - j=0 - find / | while read a; do - j=$(($j+1)) - echo "$j;$a;xxxLSTATxxxx;xxxxxxxMD5xxxxxx" - done > dat1 - */ - -#include "include/bareos.h" -#include "stored/stored.h" -#include "findlib/find.h" -#include "cats/cats.h" -#include "cats/cats_backends.h" -#include "cats/sql.h" -#include "lib/edit.h" -#include "lib/bsignal.h" - -/* Forward referenced functions */ -static void *do_batch(void *); - - -/* Local variables */ -static BareosDb *db; - -#if defined(HAVE_DYNAMIC_CATS_BACKENDS) -static const char *backend_directory = _PATH_BAREOS_BACKENDDIR; -#endif -static const char *db_name = "bareos"; -static const char *db_user = "bareos"; -static const char *db_password = ""; -static const char *db_host = NULL; -static const char *db_driver = NULL; - -static pthread_mutex_t mutex = PTHREAD_MUTEX_INITIALIZER; - -static void usage() -{ - fprintf(stderr, _( -PROG_COPYRIGHT -"\nVersion: %s (%s)\n" -"Example : bbatch -w /path/to/workdir -h localhost -f dat1 -f dat -f datx\n" -" will start 3 thread and load dat1, dat and datx in your catalog\n" -"See bbatch.c to generate datafile\n\n" -"Usage: bbatch [ options ] -w working/dir -f datafile\n" -" -b with batch mode\n" -" -B without batch mode\n" -" -d set debug level to \n" -" -dt print timestamp in debug output\n" -" -D specify the driver database name (default NULL)\n" -" -n specify the database name (default bareos)\n" -" -u specify database user name (default bareos)\n" -" -P specify database host (default NULL)\n" -" -w specify working directory\n" -" -r call restore code with given jobids\n" -" -v verbose\n" -" -f specify data file\n" -" -? print this message\n\n"), 2001, VERSION, BDATE); - exit(1); -} - -/* number of thread started */ -int nb=0; - -static int ListHandler(void *ctx, int num_fields, char **row) -{ - uint64_t *a = (uint64_t*) ctx; - (*a)++; - return 0; -} - -int main (int argc, char *argv[]) -{ - int ch; -#if defined(HAVE_DYNAMIC_CATS_BACKENDS) - alist *backend_directories = NULL; -#endif - bool disable_batch = false; - char *restore_list=NULL; - setlocale(LC_ALL, ""); - bindtextdomain("bareos", LOCALEDIR); - textdomain("bareos"); - InitStackDump(); - LmgrInitThread(); - - char **files = (char **) malloc (10 * sizeof(char *)); - int i; - MyNameIs(argc, argv, "bbatch"); - InitMsg(NULL, NULL); - - OSDependentInit(); - - while ((ch = getopt(argc, argv, "bBh:c:d:D:n:P:Su:vf:w:r:?")) != -1) { - switch (ch) { - case 'r': - restore_list=bstrdup(optarg); - break; - - case 'B': - disable_batch = true; - break; - - case 'b': - disable_batch = false; - break; - - case 'd': /* debug level */ - if (*optarg == 't') { - dbg_timestamp = true; - } else { - debug_level = atoi(optarg); - if (debug_level <= 0) { - debug_level = 1; - } - } - break; - - case 'D': - db_driver = optarg; - break; - - case 'h': - db_host = optarg; - break; - - case 'n': - db_name = optarg; - break; - - case 'w': - working_directory = optarg; - break; - - case 'u': - db_user = optarg; - break; - - case 'P': - db_password = optarg; - break; - - case 'v': - verbose++; - break; - - case 'f': - if (nb < 10 ) { - files[nb++] = optarg; - } - break; - - case '?': - default: - usage(); - - } - } - argc -= optind; - argv += optind; - - if (argc != 0) { - Pmsg0(0, _("Wrong number of arguments: \n")); - usage(); - } - - if (restore_list) { - uint64_t nb_file=0; - btime_t start, end; - - /* - * To use the -r option, the catalog should already contains records - */ - -#if defined(HAVE_DYNAMIC_CATS_BACKENDS) - backend_directories = New(alist(10, owned_by_alist)); - backend_directories->append((char *)backend_directory); - - DbSetBackendDirs(backend_directories); -#endif - - if ((db = db_init_database(NULL, - db_driver, - db_name, - db_user, - db_password, - db_host, - 0, - NULL, - false, - disable_batch, - false, - false)) == NULL) { - Emsg0(M_ERROR_TERM, 0, _("Could not init Bareos database\n")); - } - if (!db->OpenDatabase(NULL)) { - Emsg0(M_ERROR_TERM, 0, db->strerror()); - } - - start = GetCurrentBtime(); - db->GetFileList(NULL, restore_list, false, false, ListHandler, &nb_file); - end = GetCurrentBtime(); - - Pmsg3(0, _("Computing file list for jobid=%s files=%lld secs=%d\n"), - restore_list, nb_file, (uint32_t)BtimeToUnix(end-start)); - - free(restore_list); - return 0; - } - - if (disable_batch) { - printf("Without new Batch mode\n"); - } else { - printf("With new Batch mode\n"); - } - - i = nb; - while (--i >= 0) { - pthread_t thid; - JobControlRecord *bjcr = new_jcr(sizeof(JobControlRecord), NULL); - bjcr->bsr = NULL; - bjcr->VolSessionId = 1; - bjcr->VolSessionTime = (uint32_t)time(NULL); - bjcr->NumReadVolumes = 0; - bjcr->NumWriteVolumes = 0; - bjcr->JobId = getpid(); - bjcr->setJobType(JT_CONSOLE); - bjcr->setJobLevel(L_FULL); - bjcr->JobStatus = JS_Running; - bjcr->where = bstrdup(files[i]); - bjcr->job_name = GetPoolMemory(PM_FNAME); - PmStrcpy(bjcr->job_name, "Dummy.Job.Name"); - bjcr->client_name = GetPoolMemory(PM_FNAME); - PmStrcpy(bjcr->client_name, "Dummy.Client.Name"); - bstrncpy(bjcr->Job, "bbatch", sizeof(bjcr->Job)); - bjcr->fileset_name = GetPoolMemory(PM_FNAME); - PmStrcpy(bjcr->fileset_name, "Dummy.fileset.name"); - bjcr->fileset_md5 = GetPoolMemory(PM_FNAME); - PmStrcpy(bjcr->fileset_md5, "Dummy.fileset.md5"); - - if ((db = db_init_database(NULL, - db_driver, - db_name, - db_user, - db_password, - db_host, - 0, - NULL, - false, - false, - false, - false)) == NULL) { - Emsg0(M_ERROR_TERM, 0, _("Could not init Bareos database\n")); - } - if (!db->OpenDatabase(NULL)) { - Emsg0(M_ERROR_TERM, 0, db->strerror()); - } - Dmsg0(200, "Database opened\n"); - if (verbose) { - Pmsg2(000, _("Using Database: %s, User: %s\n"), db_name, db_user); - } - - bjcr->db = db; - - pthread_create(&thid, NULL, do_batch, bjcr); - } - - while (nb > 0) { - Bmicrosleep(1,0); - } - - return 0; -} - -static void FillAttr(AttributesDbRecord *ar, char *data) -{ - char *p; - char *b; - int index=0; - ar->Stream = STREAM_UNIX_ATTRIBUTES; - ar->JobId = getpid(); - - for(p = b = data; *p; p++) { - if (*p == ';') { - *p = '\0'; - switch (index) { - case 0: - ar->FileIndex = str_to_int64(b); - break; - case 1: - ar->fname = b; - break; - case 2: - ar->attr = b; - break; - case 3: - ar->Digest = b; - break; - } - index++; - b = ++p; - } - } -} - -static void *do_batch(void *jcr) -{ - JobControlRecord *bjcr = (JobControlRecord *)jcr; - char data[1024]; - int lineno = 0; - struct AttributesDbRecord ar; - memset(&ar, 0, sizeof(ar)); - btime_t begin = GetCurrentBtime(); - char *datafile = bjcr->where; - - FILE *fd = fopen(datafile, "r"); - if (!fd) { - Emsg1(M_ERROR_TERM, 0, _("Error opening datafile %s\n"), datafile); - } - while (fgets(data, sizeof(data)-1, fd)) { - StripTrailingNewline(data); - lineno++; - if (verbose && ((lineno % 5000) == 1)) { - printf("\r%i", lineno); - } - FillAttr(&ar, data); - if (!bjcr->db->CreateAttributesRecord(bjcr, &ar)) { - Emsg0(M_ERROR_TERM, 0, _("Error while inserting file\n")); - } - } - fclose(fd); - bjcr->db->WriteBatchFileRecords(bjcr); - btime_t end = GetCurrentBtime(); - - P(mutex); - char ed1[200], ed2[200]; - printf("\rbegin = %s, end = %s\n", edit_int64(begin, ed1),edit_int64(end, ed2)); - printf("Insert time = %sms\n", edit_int64((end - begin) / 10000, ed1)); - printf("Create %u files at %.2f/s\n", lineno, - (lineno / ((float)((end - begin) / 1000000)))); - nb--; - V(mutex); - pthread_exit(NULL); - return NULL; -} diff --git a/core/src/tests/bregtest.cc b/core/src/tests/bregtest.cc deleted file mode 100644 index 49bf71bd052..00000000000 --- a/core/src/tests/bregtest.cc +++ /dev/null @@ -1,155 +0,0 @@ -/* - BAREOS® - Backup Archiving REcovery Open Sourced - - Copyright (C) 2006-2008 Free Software Foundation Europe e.V. - - This program is Free Software; you can redistribute it and/or - modify it under the terms of version three of the GNU Affero General Public - License as published by the Free Software Foundation, which is - listed in the file LICENSE. - - This program is distributed in the hope that it will be useful, but - WITHOUT ANY WARRANTY; without even the implied warranty of - MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU - Affero General Public License for more details. - - You should have received a copy of the GNU Affero General Public License - along with this program; if not, write to the Free Software - Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA - 02110-1301, USA. -*/ -/* - * Test program for testing regular expressions. - * - * Kern Sibbald, MMVI - */ - -/* - * If you define BAREOS_REGEX, bregex will be built with the - * Bareos bregex library, which is the same code that we - * use on Win32, thus using Linux, you can test your Win32 - * expressions. Otherwise, this program will link with the - * system library routines. - */ -//#define BAREOS_REGEX - -#include "include/bareos.h" -#include -#include "lib/breg.h" - -static void usage() -{ - fprintf(stderr, -"\n" -"Usage: bregtest [-d debug_level] [-s] -f -e /test/test2/\n" -" -f specify file of data to be matched\n" -" -e specify expression\n" -" -s sed output\n" -" -d set debug level to \n" -" -dt print timestamp in debug output\n" -" -? print this message.\n" -"\n"); - - exit(1); -} - - -int main(int argc, char *const *argv) -{ - char *fname = NULL; - char *expr = NULL; - int ch; - bool sed=false; - char data[1000]; - FILE *fd; - - setlocale(LC_ALL, ""); - bindtextdomain("bareos", LOCALEDIR); - textdomain("bareos"); - - while ((ch = getopt(argc, argv, "sd:f:e:")) != -1) { - switch (ch) { - case 'd': /* set debug level */ - if (*optarg == 't') { - dbg_timestamp = true; - } else { - debug_level = atoi(optarg); - if (debug_level <= 0) { - debug_level = 1; - } - } - break; - - case 'f': /* data */ - fname = optarg; - break; - - case 'e': - expr = optarg; - break; - - case 's': - sed=true; - break; - - case '?': - default: - usage(); - - } - } - argc -= optind; - argv += optind; - - if (!fname) { - printf("A data file must be specified.\n"); - usage(); - } - - if (!expr) { - printf("An expression must be specified.\n"); - usage(); - } - - OSDependentInit(); - - alist *list; - char *p; - - list = get_bregexps(expr); - - if (!list) { - printf("Can't use %s as 'sed' expression\n", expr); - exit (1); - } - - fd = fopen(fname, "r"); - if (!fd) { - printf(_("Could not open data file: %s\n"), fname); - exit(1); - } - - while (fgets(data, sizeof(data)-1, fd)) { - StripTrailingNewline(data); - ApplyBregexps(data, list, &p); - if (sed) { - printf("%s\n", p); - } else { - printf("%s => %s\n", data, p); - } - } - fclose(fd); - FreeBregexps(list); - delete list; - exit(0); -} -/* - TODO: - - ajout /g - - - tests - * test avec /i - * test avec un sed et faire un diff - * test avec une boucle pour voir les fuites - -*/ diff --git a/core/src/tests/cats_test.cc b/core/src/tests/cats_test.cc deleted file mode 100644 index 5fc864dca60..00000000000 --- a/core/src/tests/cats_test.cc +++ /dev/null @@ -1,709 +0,0 @@ -/* - BAREOS® - Backup Archiving REcovery Open Sourced - - Copyright (C) 2011-2011 Free Software Foundation Europe e.V. - - This program is Free Software; you can redistribute it and/or - modify it under the terms of version three of the GNU Affero General Public - License as published by the Free Software Foundation and included - in the file LICENSE. - - This program is distributed in the hope that it will be useful, but - WITHOUT ANY WARRANTY; without even the implied warranty of - MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU - Affero General Public License for more details. - - You should have received a copy of the GNU Affero General Public License - along with this program; if not, write to the Free Software - Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA - 02110-1301, USA. -*/ -/* - * Program to test CATS DB routines - */ -#define _BDB_PRIV_INTERFACE_ - -#include "include/bareos.h" -#include "jcr.h" -#include "cats/cats.h" -#include "cats/bdb_priv.h" - -/* Local variables */ -static BareosDb *db; -static const char *file = "COPYRIGHT"; -#if defined(HAVE_DYNAMIC_CATS_BACKENDS) -static const char *backend_directory = _PATH_BAREOS_BACKENDDIR; -#endif -static const char *db_name = "bareos"; -static const char *db_user = "bareos"; -static const char *db_password = ""; -static const char *db_host = NULL; -static const char *db_address = NULL; -static const char *db_driver = NULL; -static int db_port = 0; -static int64_t pid = 0; -static JobControlRecord *jcr=NULL; - -#define PLINE "\n============================================================\n" -static void usage() -{ - fprintf(stderr, _( -PROG_COPYRIGHT -"\nVersion: %s (%s)\n" -" -d set debug level to \n" -" -dt print timestamp in debug output\n" -" -D specify the driver database name (default NULL)\n" -" -n specify the database name (default bareos)\n" -" -u specify database user name (default bareos)\n" -" -P specify database host (default NULL)\n" -" -w specify working directory\n" -" -p specify path\n" -" -f specify file\n" -" -l maximum tuple to fetch\n" -" -q print only errors\n" -" -v verbose\n" -" -? print this message\n\n"), 2011, VERSION, BDATE); - exit(1); -} - -bool print_ok=true; -int _err=0; -int _wrn=0; -int _nb=0; - -bool _warn(const char *file, int l, const char *op, int value, const char *label) -{ - bool ret=false; - _nb++; - if (!value) { - _wrn++; - printf("WRN %.30s %s:%i on %s\n", label, file, l, op); - } else { - ret=true; - printf("OK %.30s\n", label); - } - return ret; -} - -#define warn(x, label) _warn(__FILE__, __LINE__, #x, (x), label) - -bool _ok(const char *file, int l, const char *op, int value, const char *label) -{ - bool ret=false; - _nb++; - if (!value) { - _err++; - printf("ERR %.30s %s:%i on %s\n", label, file, l, op); - } else { - ret=true; - if (print_ok) { - printf("OK %.30s\n", label); - } - } - return ret; -} - -#define ok(x, label) _ok(__FILE__, __LINE__, #x, (x), label) - -bool _nok(const char *file, int l, const char *op, int value, const char *label) -{ - bool ret=false; - _nb++; - if (value) { - _err++; - printf("ERR %.30s %s:%i on !%s\n", label, file, l, op); - } else { - ret = true; - if (print_ok) { - printf("OK %.30s\n", label); - } - } - return ret; -} - -#define nok(x, label) _nok(__FILE__, __LINE__, #x, (x), label) - -int report() -{ - printf("Result %i/%i OK\n", _nb - _err, _nb); - return _err>0; -} - -static void cmp_pool(PoolDbRecord &pr, PoolDbRecord &pr2) -{ - ok(pr.MaxVols == pr2.MaxVols, " Check Pool MaxVols"); - ok(pr.UseOnce == pr2.UseOnce, " Check Pool UseOnce"); - ok(pr.UseCatalog == pr2.UseCatalog, " Check Pool UseCatalog"); - ok(pr.AcceptAnyVolume == pr2.AcceptAnyVolume," Check Pool AcceptAnyVolume"); - ok(pr.AutoPrune == pr2.AutoPrune, " Check Pool AutoPrune"); - ok(pr.Recycle == pr2.Recycle, " Check Pool Recycle"); - ok(pr.VolRetention == pr2.VolRetention , " Check Pool VolRetention"); - ok(pr.VolUseDuration == pr2.VolUseDuration, " Check Pool VolUseDuration"); - ok(pr.MaxVolJobs == pr2.MaxVolJobs, " Check Pool MaxVolJobs"); - ok(pr.MaxVolFiles == pr2.MaxVolFiles, " Check Pool MaxVolFiles"); - ok(pr.MaxVolBytes == pr2.MaxVolBytes, " Check Pool MaxVolBytes"); - ok(bstrcmp(pr.PoolType, pr2.PoolType), " Check Pool PoolType"); - ok(pr.LabelType == pr2.LabelType, " Check Pool LabelType"); - ok(bstrcmp(pr.LabelFormat, pr2.LabelFormat), " Check Pool LabelFormat"); - ok(pr.RecyclePoolId == pr2.RecyclePoolId, " Check Pool RecyclePoolId"); - ok(pr.ScratchPoolId == pr2.ScratchPoolId, " Check Pool ScratchPoolId"); - ok(pr.ActionOnPurge == pr2.ActionOnPurge, " Check Pool ActionOnPurge"); -} - -static void CmpClient(ClientDbRecord &cr, ClientDbRecord &cr2) -{ - ok(bstrcmp(cr2.Name, cr.Name), " Check Client Name"); - ok(bstrcmp(cr2.Uname, cr.Uname), " Check Client Uname"); - ok(cr.AutoPrune == cr2.AutoPrune, " Check Client Autoprune"); - ok(cr.JobRetention == cr2.JobRetention, " Check Client JobRetention"); - ok(cr.FileRetention == cr2.FileRetention," Check Client FileRetention"); -} - -static void cmp_job(JobDbRecord &jr, JobDbRecord &jr2) -{ - ok(jr.VolSessionId == jr2.VolSessionId, " Check VolSessionId"); - ok(jr.VolSessionTime == jr2.VolSessionTime, " Check VolSessionTime"); - ok(jr.PoolId == jr2.PoolId, " Check PoolId"); - ok(jr.StartTime == jr2.StartTime, " Check StartTime"); - ok(jr.EndTime == jr2.EndTime, " Check EndTime"); - ok(jr.JobFiles == jr2.JobFiles, " Check JobFiles"); - ok(jr.JobBytes == jr2.JobBytes, " Check JobBytes"); - ok(jr.JobTDate == jr2.JobTDate, " Check JobTDate"); - ok(bstrcmp(jr.Job, jr2.Job), " Check Job"); - ok(jr.JobStatus == jr2.JobStatus, " Check JobStatus"); - ok(jr.JobType == jr2.JobType, " Check Type"); - ok(jr.JobLevel == jr2.JobLevel, " Check Level"); - ok(jr.ClientId == jr2.ClientId, " Check ClientId"); - ok(bstrcmp(jr.Name, jr2.Name), " Check Name"); - ok(jr.PriorJobId == jr2.PriorJobId, " Check PriorJobId"); - ok(jr.RealEndTime == jr2.RealEndTime, " Check RealEndTime"); - ok(jr.JobId == jr2.JobId, " Check JobId"); - ok(jr.FileSetId == jr2.FileSetId, " Check FileSetId"); - ok(jr.SchedTime == jr2.SchedTime, " Check SchedTime"); - ok(jr.RealEndTime == jr2.RealEndTime, " Check RealEndTime"); - ok(jr.ReadBytes == jr2.ReadBytes, " Check ReadBytes"); - ok(jr.HasBase == jr2.HasBase, " Check HasBase"); - ok(jr.PurgedFiles == jr2.PurgedFiles, " Check PurgedFiles"); -} - - -#define aPATH "/aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa" -#define aFILE "aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa" - -static int ListFiles(void *ctx, int nb_col, char **row) -{ - uint32_t *k = (uint32_t*) ctx; - (*k)++; - ok(nb_col > 4, "Check result columns"); - ok(bstrcmp(row[0], aPATH aPATH aPATH aPATH "/"), "Check path"); - ok(bstrcmp(row[1], aFILE aFILE ".txt"), "Check filename"); - ok(str_to_int64(row[2]) == 10, "Check FileIndex"); - ok(str_to_int64(row[3]) == jcr->JobId, "Check JobId"); - return 1; -} - -static int CountCol(void *ctx, int nb_col, char **row) -{ - *((int32_t*) ctx) = nb_col; - return 1; -} - -/* number of thread started */ - -int main (int argc, char *argv[]) -{ - int ch; - alist* backend_directories = NULL; - char *path=NULL, *client=NULL; - uint64_t limit=0; - bool clean=false; - bool full_test=false; - int dbtype; - uint32_t j; - char temp[20]; - POOLMEM *buf = GetPoolMemory(PM_FNAME); - POOLMEM *buf2 = GetPoolMemory(PM_FNAME); - POOLMEM *buf3 = GetPoolMemory(PM_FNAME); - - setlocale(LC_ALL, ""); - bindtextdomain("bareos", LOCALEDIR); - textdomain("bareos"); - InitStackDump(); - pid = getpid(); - - Pmsg0(0, "Starting cats_test tool" PLINE); - - MyNameIs(argc, argv, ""); - InitMsg(NULL, NULL); - - OSDependentInit(); - - while ((ch = getopt(argc, argv, "qh:c:l:d:D:n:P:Su:vFw:?p:f:T")) != -1) { - switch (ch) { - case 'q': - print_ok = false; - break; - - case 'd': /* debug level */ - if (*optarg == 't') { - dbg_timestamp = true; - } else { - debug_level = atoi(optarg); - if (debug_level <= 0) { - debug_level = 1; - } - } - break; - - case 'D': - db_driver = optarg; - break; - - case 'l': - limit = str_to_int64(optarg); - break; - - case 'c': - client = optarg; - break; - - case 'h': - db_host = optarg; - break; - - case 'n': - db_name = optarg; - break; - - case 'w': - working_directory = optarg; - break; - - case 'u': - db_user = optarg; - break; - - case 'P': - db_password = optarg; - break; - - case 'v': - verbose++; - break; - - case 'p': - path = optarg; - break; - - case 'F': - full_test = true; - break; - - case 'f': - file = optarg; - break; - - case 'T': - clean = true; - break; - - case '?': - default: - usage(); - - } - } - argc -= optind; - argv += optind; - - if (argc != 0) { - Pmsg0(0, _("Wrong number of arguments: \n")); - usage(); - } - - /* TODO: - * - Open DB - * - With errors - * - With good info - * - With multiple thread in // - * - Test cats.h - * - Test all sql_cmds.c - * - Test all sql.c (db_) - * - Test all sql_create.c - * - Test db_handler - */ - - jcr = new_jcr(sizeof(JobControlRecord), NULL); - jcr->setJobType(JT_CONSOLE); - jcr->setJobLevel(L_NONE); - jcr->JobStatus = JS_Running; - bstrncpy(jcr->Job, "**dummy**", sizeof(jcr->Job)); - jcr->JobId = pid; /* this is JobId on tape */ - jcr->start_time = jcr->sched_time = time(NULL); - - /* Test DB connexion */ - Pmsg1(0, PLINE "Test DB connection \"%s\"" PLINE, db_name); - -#if defined(HAVE_DYNAMIC_CATS_BACKENDS) - backend_directories = New(alist(10, owned_by_alist)); - backend_directories->append((char *)backend_directory); - - DbSetBackendDirs(backend_directories); -#endif - - if (full_test) { - db = db_init_database(jcr, db_driver, db_name, db_user, db_password, db_address, db_port + 100, NULL); - ok(db != NULL, "Test bad connection"); - if (!db) { - report(); - exit (1); - } - nok(db_open_database(jcr, db), "Open bad Database"); - db_close_database(jcr, db); - } - - db = db_init_database(jcr, db_driver, db_name, db_user, db_password, db_address, db_port, NULL); - - ok(db != NULL, "Test db connection"); - if (!db) { - report(); - exit (1); - } - if (!ok(db_open_database(jcr, db), "Open Database")) { - Pmsg1(000, _("Could not open database \"%s\".\n"), db_name); - Jmsg(jcr, M_FATAL, 0, _("Could not open, database \"%s\".\n"), db_name); - Jmsg(jcr, M_FATAL, 0, _("%s"), db_strerror(db)); - Pmsg1(000, "%s", db_strerror(db)); - db_close_database(jcr, db); - report(); - exit (1); - } - dbtype = db_get_type_index(db); - - - /* Check if the SQL library is thread-safe */ - //db_check_backend_thread_safe(); - ok(CheckTablesVersion(jcr, db), "Check table version"); - ok(db_sql_query(db, "SELECT VersionId FROM Version", - DbIntHandler, &j), "SELECT VersionId"); - - ok(UPDATE_DB(jcr, db, (char*)"UPDATE Version SET VersionId = 1"), - "Update VersionId"); - nok(CheckTablesVersion(jcr, db), "Check table version"); - Mmsg(buf, "UPDATE Version SET VersionId = %d", j); - ok(UPDATE_DB(jcr, db, buf), "Restore VersionId"); - - if (dbtype != SQL_TYPE_SQLITE3) { - ok(db_check_max_connections(jcr, db, 1), "Test min Max Connexion"); - nok(db_check_max_connections(jcr, db, 10000), "Test max Max Connexion"); - } - - ok(db_open_batch_connexion(jcr, db), "Opening batch connection"); - db_close_database(jcr, jcr->db_batch); - jcr->db_batch = NULL; - - /* ---------------------------------------------------------------- */ - - uint32_t storageid=0; - ok(db_sql_query(db, "SELECT MIN(StorageId) FROM Storage", - DbIntHandler, &storageid), "Get StorageId"); - ok(storageid > 0, "Check StorageId"); - if (!storageid) { - Pmsg0(0, "Please, run REGRESS_DEBUG=1 tests/bareos-backup-test before this test"); - exit (1); - } - - /* ---------------------------------------------------------------- */ - Pmsg0(0, PLINE "Doing Basic SQL tests" PLINE); - ok(db_sql_query(db, "SELECT 1,2,3,4,5", CountCol, &j), "Count 5 rows"); - ok(j == 5, "Check number of columns"); - ok(db_sql_query(db, "SELECT 1,2,3,4,5,'a','b','c','d','e'", - CountCol, &j), "Count 10 rows"); - ok(j == 10, "Check number of columns"); - - Bsnprintf(temp, sizeof(temp), "t%lld", pid); - ok(db_sql_query(db, "SELECT 2", DbIntHandler, &j), "Good SELECT query"); - ok(db_sql_query(db, "SELECT 1 FROM Media WHERE VolumeName='missing'", - DbIntHandler, &j), "Good empty SELECT query"); - - db_int64_ctx i64; - i64.value = 0; i64.count = 0; - ok(db_sql_query(db, "SELECT 1",db_int64_handler, &i64),"db_int64_handler"); - ok(i64.value == 1, "Check db_int64_handler return"); - - db_list_ctx lctx; - ok(db_sql_query(db, "SELECT FileId FROM File ORDER By FileId LIMIT 10", - DbListHandler, &lctx), "db_list_ctx"); - ok(lctx.count == 10, "Check db_list_ctx count "); - ok(bstrcmp(lctx.list, "1,2,3,4,5,6,7,8,9,10"), "Check db_list_ctx list"); - - nok(db_sql_query(db, "blabla", DbIntHandler, &j), "Bad query"); - - Mmsg(buf, "CREATE Table %s (a int)", temp); - ok(db_sql_query(db, buf, NULL, NULL), "CREATE query"); - - Mmsg(buf, "INSERT INTO %s (a) VALUES (1)", temp); - ok(INSERT_DB(jcr, db, buf), "INSERT query"); - ok(INSERT_DB(jcr, db, buf), "INSERT query"); - ok(SqlAffectedRows(db) == 1, "Check SqlAffectedRows"); - - Mmsg(buf, "INSERT INTO aaa%s (a) VALUES (1)", temp); - nok(INSERT_DB(jcr, db, buf), "Bad INSERT query"); - ok(SqlAffectedRows(db) == 0, "Check SqlAffectedRows"); - - Mmsg(buf, "UPDATE %s SET a = 2", temp); - ok(UPDATE_DB(jcr, db, buf), "UPDATE query"); - ok(SqlAffectedRows(db) == 2, "Check SqlAffectedRows"); - - Mmsg(buf, "UPDATE %s SET a = 2 WHERE a = 1", temp); - nok(UPDATE_DB(jcr, db, buf), "Empty UPDATE query"); - - Mmsg(buf, "UPDATE aaa%s SET a = 2", temp); - nok(UPDATE_DB(jcr, db, buf), "Bad UPDATE query"); - - Mmsg(buf, "DELETE FROM %s", temp); - ok(DELETE_DB(jcr, db, buf), "DELETE query"); - nok(DELETE_DB(jcr, db, buf), "Empty DELETE query"); /* TODO bug ? */ - - Mmsg(buf, "DELETE FROM aaa%s", temp); - ok(DELETE_DB(jcr, db, buf), "Bad DELETE query"); /* TODO bug ? */ - - Mmsg(buf, "DROP TABLE %s", temp); - ok(QUERY_DB(jcr, db, buf), "DROP query"); - nok(QUERY_DB(jcr, db, buf), "Empty DROP query"); - - /* ---------------------------------------------------------------- */ - - strcpy(buf, "This string should be 'escaped'"); - db_escape_string(jcr, db, buf2, buf, strlen(buf)); - ok((strlen(buf) + 2) == strlen(buf2),"Quoted string should be longer"); - Mmsg(buf, "INSERT INTO Path (Path) VALUES ('%lld-%s')", pid, buf2); - ok(db_sql_query(db, buf, NULL, NULL), "Inserting quoted string"); - - /* ---------------------------------------------------------------- */ - Pmsg0(0, PLINE "Doing Job tests" PLINE); - - JobDbRecord jr, jr2; - memset(&jr, 0, sizeof(jr)); - memset(&jr2, 0, sizeof(jr2)); - jr.JobId = 1; - ok(db_get_job_record(jcr, db, &jr), "Get Job record for JobId=1"); - ok(jr.JobFiles > 10, "Check number of files"); - - jr.JobId = (JobId_t)pid; - Mmsg(buf, "%s-%lld", jr.Job, pid); - strcpy(jr.Job, buf); - ok(db_create_job_record(jcr, db, &jr), "Create Job record"); - ok(db_update_job_start_record(jcr, db, &jr), "Update Start Record"); - ok(db_update_job_end_record(jcr, db, &jr), "Update End Record"); - jr2.JobId = jr.JobId; - ok(db_get_job_record(jcr, db, &jr2), "Get Job record by JobId"); - cmp_job(jr, jr2); - - memset(&jr2, 0, sizeof(jr2)); - strcpy(jr2.Job, jr.Job); - ok(db_get_job_record(jcr, db, &jr2), "Get Job record by Job name"); - cmp_job(jr, jr2); - - memset(&jr2, 0, sizeof(jr2)); - jr2.JobId = 99999; - nok(db_get_job_record(jcr, db, &jr2), "Get non existing Job record (JobId)"); - - memset(&jr2, 0, sizeof(jr2)); - strcpy(jr2.Job, "test"); - nok(db_get_job_record(jcr, db, &jr2), "Get non existing Job record (Job)"); - - /* ---------------------------------------------------------------- */ - - AttributesDbRecord ar; - memset(&ar, 0, sizeof(ar)); - Mmsg(buf2, aPATH aPATH aPATH aPATH "/" aFILE aFILE ".txt"); - ar.fname = buf2; - Mmsg(buf3, "gD ImIZ IGk B Po Po A A A JY BNNvf5 BNKzS7 BNNuwC A A C"); - ar.attr = buf3; - ar.FileIndex = 10; - ar.Stream = STREAM_UNIX_ATTRIBUTES; - ar.FileType = FT_REG; - jcr->JobId = ar.JobId = jr.JobId; - jcr->JobStatus = JS_Running; - ok(db_create_attributes_record(jcr, db, &ar), "Inserting Filename"); - ok(db_write_batch_file_records(jcr), "Commit batch session"); - Mmsg(buf, "SELECT FileIndex FROM File WHERE JobId=%lld",(int64_t)jcr->JobId); - ok(db_sql_query(db, buf, DbIntHandler, &j), "Get Inserted record"); - ok(j == ar.FileIndex, "Check FileIndex"); - Mmsg(buf, "SELECT COUNT(1) FROM File WHERE JobId=%lld",(int64_t)jcr->JobId); - ok(db_sql_query(db, buf, DbIntHandler, &j), "List records"); - ok(j == 1, "Check batch session records"); - j = 0; - Mmsg(buf, "%lld", (uint64_t)jcr->JobId); - ok(db_get_file_list(jcr, jcr->db_batch, buf, false, false, ListFiles, &j), - "List files with db_get_file_list()"); - ok(j == 1, "Check db_get_file_list results"); - /* ---------------------------------------------------------------- */ - - Pmsg0(0, PLINE "Doing Client tests" PLINE); - ClientDbRecord cr, cr2; - memset(&cr, 0, sizeof(cr)); - memset(&cr2, 0, sizeof(cr2)); - - cr.AutoPrune = 1; - cr.FileRetention = 10; - cr.JobRetention = 15; - Bsnprintf(cr.Name, sizeof(cr.Name), "client-%lld-fd", pid); - Bsnprintf(cr.Uname, sizeof(cr.Uname), "uname-%lld", pid); - - ok(db_create_client_record(jcr, db, &cr), "db_create_client_record()"); - ok(cr.ClientId > 0, "Check ClientId"); - - cr2.ClientId = cr.ClientId; /* Save it */ - cr.ClientId = 0; - - Pmsg0(0, "Search client by ClientId\n"); - ok(db_create_client_record(jcr, db, &cr),"Should get the client record"); - ok(cr.ClientId == cr2.ClientId, "Check if ClientId is the same"); - - ok(db_get_client_record(jcr, db, &cr2), "Search client by ClientId"); - CmpClient(cr, cr2); - - Pmsg0(0, "Search client by Name\n"); - memset(&cr2, 0, sizeof(cr2)); - strcpy(cr2.Name, cr.Name); - ok(db_get_client_record(jcr, db, &cr2),"Search client by Name"); - CmpClient(cr, cr2); - - Pmsg0(0, "Search non existing client by Name\n"); - memset(&cr2, 0, sizeof(cr2)); - Bsnprintf(cr2.Name, sizeof(cr2.Name), "hollow-client-%lld-fd", pid); - nok(db_get_client_record(jcr, db, &cr2), "Search non existing client"); - ok(cr2.ClientId == 0, "Check ClientId after failed search"); - - cr.AutoPrune = 0; - strcpy(cr.Uname, "NewUname"); - ok(db_update_client_record(jcr, db, &cr), "Update Client record"); - memset(&cr2, 0, sizeof(cr2)); - cr2.ClientId = cr.ClientId; - ok(db_get_client_record(jcr, db, &cr2),"Search client by ClientId"); - CmpClient(cr, cr2); - - int nb, i; - uint32_t *ret_ids; - ok(db_get_client_ids(jcr, db, &nb, &ret_ids), "Get Client Ids"); - ok(nb > 0, "Should find at least 1 Id"); - for (i = 0; i < nb; i++) { - if (ret_ids[i] == cr2.ClientId) { - break; - } - } - ok(i < nb, "Check if ClientId was found"); - - /* ---------------------------------------------------------------- */ - Pmsg0(0, PLINE "Doing Pool tests" PLINE); - PoolDbRecord pr, pr2; - memset(&pr, 0, sizeof(pr)); - memset(&pr2, 0, sizeof(pr2)); - - Bsnprintf(pr.Name, sizeof(pr.Name), "pool-%lld", pid); - pr.MaxVols = 10; - pr.UseOnce = 0; - pr.UseCatalog = true; - pr.AcceptAnyVolume = true; - pr.AutoPrune = true; - pr.Recycle = true; - pr.VolRetention = 1000; - pr.VolUseDuration = 1000; - pr.MaxVolJobs = 100; - pr.MaxVolFiles = 1000; - pr.MaxVolBytes = 1000000; - strcpy(pr.PoolType, "Backup"); - pr.LabelType = 0; - pr.LabelFormat[0] = 0; - pr.RecyclePoolId = 0; - pr.ScratchPoolId = 0; - pr.ActionOnPurge = 1; - - ok(db_create_pool_record(jcr, db, &pr), "db_create_pool_record()"); - ok(pr.PoolId > 0, "Check PoolId"); - - pr2.PoolId = pr.PoolId; - pr.PoolId = 0; - - Pmsg0(0, "Search pool by PoolId\n"); - nok(db_create_pool_record(jcr, db, &pr),"Can't create pool twice"); - ok(DbGetPoolRecord(jcr, db, &pr2), "Search pool by PoolId"); - cmp_pool(pr, pr2); - - pr2.MaxVols++; - pr2.AutoPrune = false; - pr2.Recycle = false; - pr2.VolRetention++; - pr2.VolUseDuration++; - pr2.MaxVolJobs++; - pr2.MaxVolFiles++; - pr2.MaxVolBytes++; - strcpy(pr2.PoolType, "Restore"); - strcpy(pr2.LabelFormat, "VolFormat"); - pr2.RecyclePoolId = 0; - pr2.ScratchPoolId = 0; - pr2.ActionOnPurge = 2; - - ok(db_update_pool_record(jcr, db, &pr2), "Update Pool record"); - memset(&pr, 0, sizeof(pr)); - pr.PoolId = pr2.PoolId; - ok(DbGetPoolRecord(jcr, db, &pr), "Search pool by PoolId"); - cmp_pool(pr, pr2); - - ok(db_delete_pool_record(jcr, db, &pr), "Delete Pool"); - nok(db_delete_pool_record(jcr, db, &pr), "Delete non existing Pool"); - nok(db_update_pool_record(jcr, db, &pr), "Update non existing Pool"); - ok(db_create_pool_record(jcr, db, &pr), "Recreate Pool"); - - /* ---------------------------------------------------------------- */ - Pmsg0(0, PLINE "Doing Media tests" PLINE); - - MediaDbRecord mr, mr2; - memset(&mr, 0, sizeof(mr)); - memset(&mr2, 0, sizeof(mr2)); - - Bsnprintf(mr.VolumeName, sizeof(mr.VolumeName), "media-%lld", pid); - Bsnprintf(mr.MediaType, sizeof(mr.MediaType), "type-%lld", pid); - - /* from SetPoolDbrDefaultsInMediaDbr(&mr, &pr); */ - mr.PoolId = pr.PoolId; - bstrncpy(mr.VolStatus, NT_("Append"), sizeof(mr.VolStatus)); - mr.Recycle = pr.Recycle; - mr.VolRetention = pr.VolRetention; - mr.VolUseDuration = pr.VolUseDuration; - mr.ActionOnPurge = pr.ActionOnPurge; - mr.RecyclePoolId = pr.RecyclePoolId; - mr.MaxVolJobs = pr.MaxVolJobs; - mr.MaxVolFiles = pr.MaxVolFiles; - mr.MaxVolBytes = pr.MaxVolBytes; - mr.LabelType = pr.LabelType; - mr.Enabled = 1; - - mr.VolCapacityBytes = 1000; - mr.Slot = 1; - mr.VolBytes = 1000; - mr.InChanger = 1; - mr.VolReadTime = 10000; - mr.VolWriteTime = 99999; - mr.StorageId = 0; - mr.DeviceId = 0; - mr.LocationId = 0; - mr.ScratchPoolId = 0; - mr.RecyclePoolId = 0; - - ok(db_create_media_record(jcr, db, &mr), "Create Media"); - nok(db_create_media_record(jcr, db, &mr), "Create Media twice"); - - /* ---------------------------------------------------------------- */ - Pmsg0(0, PLINE "Doing ... tests" PLINE); - - db_close_database(jcr, db); - report(); - FreePoolMemory(buf); - FreePoolMemory(buf2); - FreePoolMemory(buf3); - return 0; -} diff --git a/core/src/tests/gigaslam.cc b/core/src/tests/gigaslam.cc deleted file mode 100644 index fbdcefbd9ed..00000000000 --- a/core/src/tests/gigaslam.cc +++ /dev/null @@ -1,53 +0,0 @@ -/* - By John Walker written ages ago. - - Create a sparse file. - - Beat denial of service floggers to death by persuading - them to download a HOW_BIG pseudo GIF file which is actually - a holey file occupying trivial space on our server. - - Make: make gigaslam - Run: ./gigaslam - Output: a file named gigaslam.gif that contains something like - 16K bytes (i.e. 2-8K blocks), but appears to be 1GB in - length because the second block is written at a 1GB - address. - - Be careful what you do with this file as not all programs know - how to deal with sparse files. - -*/ - -/* Define to make fseeko etc. visible, on some hosts e.g. HP-UX */ -#define _LARGEFILE_SOURCE 1 - -#define HOW_BIG 1000000000ll - -#ifdef __GNUC__ -#ifndef _GNU_SOURCE -#define _GNU_SOURCE -#endif -#ifndef _FILE_OFFSET_BITS -#define _FILE_OFFSET_BITS 64 -#endif -#endif - -#include -#include -#include - -int main(int argc, char *const *argv) -{ - FILE *fp = fopen("gigaslam.gif", "w"); - char header[] = "\n\n
\n"; - char trailer[] = "\n"; - off_t howBig = HOW_BIG; - - fwrite(header, sizeof header, 1, fp); - fseeko(fp, howBig - strlen(trailer), 0); - fwrite(trailer, strlen(trailer), 1, fp); - fclose(fp); - return 0; - -} diff --git a/core/src/tests/grow.cc b/core/src/tests/grow.cc deleted file mode 100644 index ab220c8eb98..00000000000 --- a/core/src/tests/grow.cc +++ /dev/null @@ -1,59 +0,0 @@ -/* - By John Walker written ages ago. - - Create a sparse file. - - Beat denial of service floggers to death by persuading - them to download a HOW_BIG pseudo GIF file which is actually - a holey file occupying trivial space on our server. - - Make: make gigaslam - Run: ./gigaslam - Output: a file named gigaslam.gif that contains something like - 16K bytes (i.e. 2-8K blocks), but appears to be 1GB in - length because the second block is written at a 1GB - address. - - Be careful what you do with this file as not all programs know - how to deal with sparse files. - - Tweaked by Kern Sibbald, July 2007 to grow a file to a specified - size. - -*/ - -#ifdef __GNUC__ -#ifndef _GNU_SOURCE -#define _GNU_SOURCE -#endif -#ifndef _FILE_OFFSET_BITS -#define _FILE_OFFSET_BITS 64 -#endif -#endif - -#include "include/bareos.h" -#include "lib/edit.h" - -int main(int argc, char *argv[]) -{ - off_t howBig; - FILE *fp; - - if (argc != 3) { - Pmsg0(0, "Calling sequence: grow \n"); - exit(1); - } - howBig = str_to_int64(argv[2]); - fp = fopen(argv[1], "r+"); - if (!fp) { - BErrNo be; - Pmsg2(0, "Could not open %s for write. ERR=%s\n", argv[1], be.bstrerror()); - exit(1); - } - char trailer[] = "xxxxxxx\n"; - - fseeko(fp, howBig - strlen(trailer), SEEK_SET); - fwrite(trailer, strlen(trailer), 1, fp); - fclose(fp); - return 0; -} diff --git a/core/src/tools/CMakeLists.txt b/core/src/tools/CMakeLists.txt index bed9abd8aef..b5d97373770 100644 --- a/core/src/tools/CMakeLists.txt +++ b/core/src/tools/CMakeLists.txt @@ -47,6 +47,9 @@ target_link_libraries(bwild bareos ${JANSSON_LIBRARIES}) add_executable(bscrypto bscrypto.cc) target_link_libraries(bscrypto bareos ${JANSSON_LIBRARIES}) +add_executable(btestls btestls.cc) +target_link_libraries(btestls bareosfind bareos ${JANSSON_LIBRARIES}) + IF(NOT HAVE_WIN32) add_executable(bpluginfo bpluginfo.cc) target_link_libraries(bpluginfo bareos ${DL_LIBRARIES} ${JANSSON_LIBRARIES}) @@ -55,7 +58,7 @@ IF(NOT HAVE_WIN32) ENDIF() set (TOOLS_BIN - bsmtp bwild bregex + bsmtp bwild bregex btestls ) set (TOOLS_SBIN diff --git a/core/src/tests/testls.cc b/core/src/tools/btestls.cc similarity index 100% rename from core/src/tests/testls.cc rename to core/src/tools/btestls.cc diff --git a/regress/tests/big-vol-test b/regress/tests/big-vol-test index 9ffa9990867..cac4680fd7b 100755 --- a/regress/tests/big-vol-test +++ b/regress/tests/big-vol-test @@ -1,7 +1,7 @@ #!/bin/sh # # Create a big Volume > 5 GB and backup to it to test disk -# seeking on big volumes. We cheat and artifically grow +# seeking on big volumes. We cheat and artificially grow # the volume. # TestName="big-vol-test" @@ -44,9 +44,9 @@ check_for_zombie_jobs storage=File # # make big file size=5200000000 -${bin}/grow ${tmp}/TestVolume001 ${size} +truncate ${tmp}/TestVolume001 --size=${size} if [ $? != 0 ]; then - echo "Execute of ${bin}/grow failed." + echo "Execute of truncate failed." exit 1 fi diff --git a/regress/tests/dev-test-root b/regress/tests/dev-test-root index a41412351f1..8faf0e7ba97 100755 --- a/regress/tests/dev-test-root +++ b/regress/tests/dev-test-root @@ -41,9 +41,9 @@ stop_bareos # More cleanup needed below cd / -${cwd}/bin/testls -e ${cwd}/scripts/exclude-etc-test dev >${cwd}/tmp/original +${cwd}/bin/btestls -e ${cwd}/scripts/exclude-etc-test dev >${cwd}/tmp/original cd ${cwd}/tmp/bareos-restores -${cwd}/bin/testls -e ${cwd}/scripts/exclude-etc-test dev >${cwd}/tmp/restored +${cwd}/bin/btestls -e ${cwd}/scripts/exclude-etc-test dev >${cwd}/tmp/restored cd ${cwd}/tmp # # Use sed to cut out parts that *always* change diff --git a/regress/tests/etc-test-root b/regress/tests/etc-test-root index c61fafcc2e2..e125c07c99a 100755 --- a/regress/tests/etc-test-root +++ b/regress/tests/etc-test-root @@ -43,9 +43,9 @@ stop_bareos # more cleanup needed below cd / -${cwd}/bin/testls -e ${cwd}/scripts/exclude-etc-test etc >${cwd}/tmp/1 +${cwd}/bin/btestls -e ${cwd}/scripts/exclude-etc-test etc >${cwd}/tmp/1 cd ${cwd}/tmp/bareos-restores -${cwd}/bin/testls -e ${cwd}/scripts/exclude-etc-test etc >${cwd}/tmp/2 +${cwd}/bin/btestls -e ${cwd}/scripts/exclude-etc-test etc >${cwd}/tmp/2 sort <${cwd}/tmp/1 >${cwd}/tmp/original sort <${cwd}/tmp/2 >${cwd}/tmp/restored rm -f ${cwd}/tmp/1 ${cwd}/tmp/2 diff --git a/regress/tests/lib-tape-root b/regress/tests/lib-tape-root index fdb95f6e700..5a3756f2dfe 100755 --- a/regress/tests/lib-tape-root +++ b/regress/tests/lib-tape-root @@ -38,9 +38,9 @@ run_bareos stop_bareos cd / -${cwd}/bin/testls -e ${cwd}/scripts/exclude-usr-test lib >${cwd}/tmp/original +${cwd}/bin/btestls -e ${cwd}/scripts/exclude-usr-test lib >${cwd}/tmp/original cd ${cwd}/tmp/bareos-restores -${cwd}/bin/testls -e ${cwd}/scripts/exclude-usr-test lib >${cwd}/tmp/restored +${cwd}/bin/btestls -e ${cwd}/scripts/exclude-usr-test lib >${cwd}/tmp/restored cd ${cwd}/tmp sed s%.*lib/kbd/consolefonts$%lib/kbd/consolefonts% original >1 sort <1 >original diff --git a/regress/tests/lib-test-root b/regress/tests/lib-test-root index bcb70d492bc..a313ea89d44 100755 --- a/regress/tests/lib-test-root +++ b/regress/tests/lib-test-root @@ -46,9 +46,9 @@ stop_bareos # more cleanup to be done below cd / -${cwd}/bin/testls -e ${cwd}/scripts/exclude-lib-test lib >${cwd}/tmp/original +${cwd}/bin/btestls -e ${cwd}/scripts/exclude-lib-test lib >${cwd}/tmp/original cd ${cwd}/tmp/bareos-restores -${cwd}/bin/testls -e ${cwd}/scripts/exclude-lib-test lib >${cwd}/tmp/restored +${cwd}/bin/btestls -e ${cwd}/scripts/exclude-lib-test lib >${cwd}/tmp/restored cd ${cwd}/tmp sed s%.*lib/kbd/consolefonts$%lib/kbd/consolefonts% original >1 sort <1 >original diff --git a/regress/tests/regexwhere-test b/regress/tests/regexwhere-test deleted file mode 100755 index cd22489da5b..00000000000 --- a/regress/tests/regexwhere-test +++ /dev/null @@ -1,319 +0,0 @@ -#!/bin/sh -# -# Test file relocation feature -# - -TestName="regexwhere-test" -JobName=backup - -. scripts/functions - -scripts/cleanup -scripts/copy-test-confs - -/bin/cp -f scripts/bareos-dir.conf.regexwhere bin/bareos-dir.conf - -# -# Remove the !restored from the messages resource because -# this test needs the restored listing to verify the -# restore results -# -outf="${cwd}/tmp/sed_tmp" -echo "s%, \!restored%%g" >${outf} -cp ${cwd}/bin/bareos-fd.conf ${cwd}/tmp/1 -sed -f ${outf} ${cwd}/tmp/1 >${cwd}/bin/bareos-fd.conf - -# Directory to backup. -# This directory will be created by setup_data(). -BackupDirectory="${tmp}/data" - -# Use a tgz to setup data to be backuped. -# Data will be placed at "${tmp}/data". -# po.tgz: build/po/* -setup_data data/po.tgz -echo "test" > ${BackupDirectory}/README.txt - -# the default fileset FS_TESTJOB backups all file and directories defined in "${tmp}/file-list". -echo "${BackupDirectory}" >${tmp}/file-list - - -start_test - -cat <tmp/bconcmds -@$out tmp/RUN_backup -messages -label volume=TestVolume001 -run job=backup yes -wait -messages -@################################## -@$out tmp/RUN_JobA -restore -5 -cd ${BackupDirectory}/build/po -m *.po -done -1 -yes -wait -messages -@################################## -@$out tmp/RUN_JobB -restore -@# Select the most recent backup for a client -5 -cd ${BackupDirectory}/build/po -m *.po -done -@# Restore Job: 2: JobB -2 -yes -wait -messages -@################################## -@$out tmp/RUN_JobC -restore -5 -cd ${BackupDirectory}/build/po -m *.po -done -3 -yes -wait -messages -@################################## -@$out tmp/RUN_JobD -restore -5 -cd ${BackupDirectory}/build/po -m *.po -done -4 -yes -wait -messages -@################################## -@$out tmp/RUN_JobE -restore -5 -cd ${BackupDirectory}/build/po -m *.po -done -5 -yes -wait -messages -@################################## -@$out tmp/RUN_JobF -restore -5 -cd ${BackupDirectory}/build/po -m *.po -done -6 -yes -wait -messages -@################################## -@$out tmp/RUN_JobG -restore strip_prefix="${cwd}" add_prefix="${tmp}/bareos-restore.$$" -5 -cd ${BackupDirectory}/build/po -m *.po -done -7 -yes -wait -messages -@################################## -@$out tmp/RUN_JobH -restore add_suffix=.old -5 -cd ${BackupDirectory}/build/po -m *.po -done -7 -yes -wait -messages -@################################## -@$out tmp/RUN_JobI -restore regexwhere="!Po!old!i,!old!po!,!\$!.old!" -5 -cd ${BackupDirectory}/build/po -m *.po -done -7 -yes -wait -messages -@################################## -@$out tmp/RUN_JobJ -restore -5 -cd ${BackupDirectory}/build/po -m *.po -done -7 -mod -@## File Relocation -> add suffix -> test -> accept -11 -3 -.old -5 -/etc/passwd -. -6 -@## Where -m -10 -tmp/bareos-restore-it -m -@## use add suffix -11 -3 -.old -6 -yes -wait -messages -@sleep 1 -quit -END_OF_DATA - -run_bareos - -stop_bareos - - -dstat=0 -bstat=0 -rstat=0 -export dstat -export bstat -export rstat - -J=JobA -grep "Restore OK" tmp/RUN_$J > /dev/null && \ -grep "${BackupDirectory}/build/po/fr.old.po" tmp/RUN_$J > /dev/null - -if [ $? = 0 ]; then - [ "$debug" = 1 ] && echo $J ok -else - echo "$J in error" - rstat=1 -fi - -J=JobB -grep "Restore OK" tmp/RUN_$J > /dev/null && \ -# $cwd begins with / -FILE="${tmp}/bareos-restore${BackupDirectory}/po/fr.po.old" -grep "$FILE" tmp/RUN_$J > /dev/null -if [ $? = 0 ]; then - [ "$debug" = 1 ] && echo $J ok -else - echo "$J in error (file $FILE not found)" - rstat=1 -fi - -J=JobC -grep "Restore OK" tmp/RUN_$J > /dev/null && \ -grep "tmp/bareos-restore${BackupDirectory}/build/po/fr.po" tmp/RUN_$J > /dev/null -if [ $? = 0 ]; then - [ "$debug" = 1 ] && echo $J ok -else - echo "$J in error" - rstat=1 -fi - -J=JobD -grep "Restore Error" tmp/RUN_$J > /dev/null -if [ $? = 0 ]; then - [ "$debug" = 1 ] && echo $J ok -else - echo "$J in error" - rstat=1 -fi - -J=JobE -grep "Restore OK" tmp/RUN_$J > /dev/null && \ -FILE="${BackupDirectory}/tmp/fr.po" -grep "${FILE}" tmp/RUN_$J > /dev/null -if [ $? = 0 ]; then - [ "$debug" = 1 ] && echo $J ok -else - echo "$J in error (file $FILE not found)" - rstat=1 -fi - -J=JobF -grep "Restore OK" tmp/RUN_$J > /dev/null && \ -grep "${BackupDirectory}/build/po/fr.po" tmp/RUN_$J > /dev/null -if [ $? = 0 ]; then - [ "$debug" = 1 ] && echo $J ok -else - echo "$J in error" - rstat=1 -fi - -J=JobG -grep "Restore OK" tmp/RUN_$J > /dev/null && \ -FILE="tmp/bareos-restore.$$/tmp/data/build/po/fr.po" -grep "${FILE}" tmp/RUN_$J > /dev/null -if [ $? = 0 ]; then - [ "$debug" = 1 ] && echo $J ok -else - echo "$J in error (file $FILE not found)" - rstat=1 -fi - -J=JobH -grep "Restore OK" tmp/RUN_$J > /dev/null && \ -grep "${BackupDirectory}/build/po/fr.po.old" tmp/RUN_$J > /dev/null -if [ $? = 0 ]; then - [ "$debug" = 1 ] && echo $J ok -else - echo "$J in error" - rstat=1 -fi - -J=JobI -grep "Restore OK" tmp/RUN_$J > /dev/null && \ -grep "${BackupDirectory}/build/po/fr.po.old" tmp/RUN_$J > /dev/null -if [ $? = 0 ]; then - [ "$debug" = 1 ] && echo $J ok -else - echo "$J in error" - rstat=1 -fi - - -J=JobJ -grep "Restore OK" tmp/RUN_$J > /dev/null && \ -grep "/etc/passwd.old" tmp/RUN_$J > /dev/null && \ -grep "Where: *tmp/bareos-restore-it" tmp/RUN_$J > /dev/null && \ -grep "${BackupDirectory}/build/po/fr.po.old" tmp/RUN_$J > /dev/null -if [ $? = 0 ]; then - [ "$debug" = 1 ] && echo $J ok -else - echo "$J in error" - rstat=1 -fi - -# test with bregtest - -find ${BackupDirectory} > tmp/list -# thanks to BSD like system for that... -sed -e 's/[Rr][Ee][Aa][Dd][Mm][Ee]/readme/' -e 's/\([ch]\)$/.old.\1/' tmp/list > tmp/list.sed -${bin}/bregtest -s -f tmp/list -e '/readme/readme/i,/([ch])$/.old.$1/' > tmp/list.bsed - -diff tmp/list.bsed tmp/list.sed >/dev/null 2>&1 -if [ $? = 0 ]; then - [ "$debug" = 1 ] && echo bregtest ok -else - echo "bregtest test in error" - rstat=1 - -fi - -end_test diff --git a/regress/tests/speed-test b/regress/tests/speed-test deleted file mode 100755 index 1908b310d35..00000000000 --- a/regress/tests/speed-test +++ /dev/null @@ -1,143 +0,0 @@ -#!/bin/sh - -. scripts/functions - -# -# Run a big test with backup of millions of files then run 100 incremental -# modifying 10% each time -# -# Can use following env variables -# ACCURATE=yes -# BASEJOB=yes -# NB_CONCURENT=4 -# NB_FULL=25 -# NB_INCR=25 -# NB_FILES=750000 -# -# TODO: this test is not enabled. -# - -TestName="speed-test" -JobName=speed - -${rscripts}/cleanup - -# Directory to backup. -BackupDirectory="${tmp}/data" -mkdir -p $cwd/files -echo "$BackupDirectory" >${tmp}/file-list - -${rscripts}/copy-test-confs -sed 's/Max Run Time/#Max Run Time/' $conf/bareos-dir.conf > $tmp/1 -sed 's/SpoolData/#SpoolData/' $tmp/1 > $conf/bareos-dir.conf - -change_jobname CompressedTest $JobName -if [ a$ACCURATE != a ]; then - sed 's/Name = "speed"/Name = "speed"; accurate=yes/' $conf/bareos-dir.conf > $tmp/1 - mv $tmp/1 $conf/bareos-dir.conf -fi - -if [ a$BASEJOB != a ]; then - sed 's/Name = "speed"/Name = "speed"; accurate=yes;basejob=speed/' $conf/bareos-dir.conf > $tmp/1 - mv $tmp/1 $conf/bareos-dir.conf - basejob="level=base" -fi - -NB_CONCURENT=${NB_CONCURENT:-1} -NB_FULL=${NB_FULL:-20} -NB_INCR=${NB_INCR:-25} -NB_FILES=${NB_FILES:-100000} - -start_test - -echo "Creating $NB_FILES files" -perl -Mscripts::functions -e "create_many_files('$BackupDirectory', $NB_FILES);" - -cat <${tmp}/bconcmds -@$out /dev/null -messages -@$out ${tmp}/log1.out -label storage=File volume=TestVolume001 -run job=$JobName $basejob yes -wait -messages -quit -END_OF_DATA - -run_bareos -check_for_zombie_jobs storage=File - -cat <${tmp}/bconcmds -@$out /dev/null -messages -@$out ${tmp}/log1.out -END_OF_DATA - -for j in $(seq 1 $NB_CONCURENT); do - cat <>${tmp}/bconcmds -@sleep 5 -run job=$JobName level=Full yes -EOF -done - -cat <>${tmp}/bconcmds -wait -messages -quit -EOF - -# insert X million files into File table -for i in $(seq 0 $NB_FULL); do - run_bconsole -done - -# Now, run many incremental -sed 's/Full/Incremental/' ${tmp}/bconcmds > $tmp/1 -mv $tmp/1 ${tmp}/bconcmds - -for i in $(seq 0 $NB_INCR); do - perl -Mscripts::functions -e "update_some_files('$BackupDirectory/'.chr($i+65));" - run_bconsole -done - -cat <${tmp}/bconcmds -@$out /dev/null -messages -@# -@# now do a restore -@# -@$out ${tmp}/log2.out -time -restore where=${tmp}/bareos-restores storage=File select all done yes -time -wait -time -status storage=File -messages -quit -END_OF_DATA - -run_bconsole -check_for_zombie_jobs storage=File -stop_bareos - -check_two_logs -#rm -rf ${tmp}/files - -find ${tmp}/bareos-restores | wc -l | tee $tmp/bareos-restore-list -rm -rf ${tmp}/bareos-restores - -# check the time needed to compute restore list -if [ x$db_password != x ]; then - p="-P $db_password" -fi - -# Disabled, as it is not sure, what bbatch does. -# Also, this test is the only one, using it. -# Without this test, there is no need to compile it at all. -#(time $bin/bbatch -r 1 -n $db_name -u $db_user $p -w $tmp) >> $working/log 2>&1 - -cp $working/log files/log-${DBTYPE}-$(date +%F_%H-%M).log -cp $tmp/log2.out files/log2-${DBTYPE}-$(date +%F_%H-%M).log - -end_test diff --git a/regress/tests/usr-tape-root b/regress/tests/usr-tape-root index c7283ca5da2..d12195bf12e 100755 --- a/regress/tests/usr-tape-root +++ b/regress/tests/usr-tape-root @@ -37,9 +37,9 @@ END_OF_DATA run_bareos stop_bareos cd / -${cwd}/bin/testls -e ${cwd}/scripts/exclude-usr-test lib >${cwd}/tmp/original +${cwd}/bin/btestls -e ${cwd}/scripts/exclude-usr-test lib >${cwd}/tmp/original cd ${cwd}/tmp/bareos-restores -${cwd}/bin/testls -e ${cwd}/scripts/exclude-usr-test lib >${cwd}/tmp/restored +${cwd}/bin/btestls -e ${cwd}/scripts/exclude-usr-test lib >${cwd}/tmp/restored cd ${cwd}/tmp sed s%.*lib/kbd/consolefonts$%lib/kbd/consolefonts% original >1 sort <1 >original diff --git a/regress/tests/weird-files2-test b/regress/tests/weird-files2-test index 9a96830e312..8da24ac7a3c 100755 --- a/regress/tests/weird-files2-test +++ b/regress/tests/weird-files2-test @@ -25,7 +25,7 @@ cd .. start_test -${bin}/testls weird-files2 | sort >${cwd}/tmp/original +${bin}/btestls weird-files2 | sort >${cwd}/tmp/original cat <tmp/bconcmds @$out /dev/null @@ -72,7 +72,7 @@ run_bconsole check_for_zombie_jobs storage=File stop_bareos -${bin}/testls weird-files2 | sort >${cwd}/tmp/restored +${bin}/btestls weird-files2 | sort >${cwd}/tmp/restored check_two_logs diff -u ${cwd}/tmp/original ${cwd}/tmp/restored 2>&1 >/dev/null