summaryrefslogtreecommitdiff
path: root/infrastructure/buildenv-testmain-template.cpp
diff options
context:
space:
mode:
Diffstat (limited to 'infrastructure/buildenv-testmain-template.cpp')
-rw-r--r--infrastructure/buildenv-testmain-template.cpp103
1 files changed, 80 insertions, 23 deletions
diff --git a/infrastructure/buildenv-testmain-template.cpp b/infrastructure/buildenv-testmain-template.cpp
index 45ad0933..b646a27b 100644
--- a/infrastructure/buildenv-testmain-template.cpp
+++ b/infrastructure/buildenv-testmain-template.cpp
@@ -18,26 +18,21 @@
#include "Box.h"
-#include "stdio.h"
-#include <exception>
-#include <sys/types.h>
-#include <unistd.h>
-#include <stdlib.h>
-#include <stdarg.h>
-#include <fcntl.h>
#include <errno.h>
-#include <string>
+#include <fcntl.h>
+#include <stdarg.h>
+#include <stdlib.h>
+#include <stdio.h>
+#include <unistd.h>
#ifdef HAVE_GETOPT_H
#include <getopt.h>
#endif
-#ifdef WIN32
- #include "emu.h"
-#else
- #include <syslog.h>
-#endif
+#include <sys/stat.h>
+#include <sys/types.h>
+#include <exception>
#include <string>
#include "Logging.h"
@@ -48,7 +43,7 @@
int test(int argc, const char *argv[]);
-#ifdef NDEBUG
+#ifdef BOX_RELEASE_BUILD
#define MODE_TEXT "release"
#else
#define MODE_TEXT "debug"
@@ -57,7 +52,17 @@ int test(int argc, const char *argv[]);
int failures = 0;
int first_fail_line;
std::string first_fail_file;
-std::string bbackupd_args, bbstored_args, bbackupquery_args, test_args;
+
+#ifdef WIN32
+ #define QUIET_PROCESS "-Q"
+#else
+ #define QUIET_PROCESS ""
+#endif
+
+std::string bbackupd_args = QUIET_PROCESS,
+ bbstored_args = QUIET_PROCESS,
+ bbackupquery_args,
+ test_args;
int filedes_open_at_beginning = -1;
@@ -159,7 +164,15 @@ int main(int argc, char * const * argv)
// Start memory leak testing
MEMLEAKFINDER_START
+ Logging::SetProgramName(BOX_MODULE);
+
#ifdef HAVE_GETOPT_H
+ #ifdef BOX_RELEASE_BUILD
+ int logLevel = Log::NOTICE; // need an int to do math with
+ #else
+ int logLevel = Log::INFO; // need an int to do math with
+ #endif
+
struct option longopts[] =
{
{ "bbackupd-args", required_argument, NULL, 'c' },
@@ -170,7 +183,7 @@ int main(int argc, char * const * argv)
int ch;
- while ((ch = getopt_long(argc, argv, "c:d:s:t:TUV", longopts, NULL))
+ while ((ch = getopt_long(argc, argv, "c:d:qs:t:vPTUV", longopts, NULL))
!= -1)
{
switch(ch)
@@ -202,9 +215,50 @@ int main(int argc, char * const * argv)
}
break;
+ #ifndef WIN32
+ case 'P':
+ {
+ Console::SetShowPID(true);
+ }
+ break;
+ #endif
+
+ case 'q':
+ {
+ if(logLevel == Log::NOTHING)
+ {
+ BOX_FATAL("Too many '-q': "
+ "Cannot reduce logging "
+ "level any more");
+ return 2;
+ }
+ logLevel--;
+ }
+ break;
+
+ case 'v':
+ {
+ if(logLevel == Log::EVERYTHING)
+ {
+ BOX_FATAL("Too many '-v': "
+ "Cannot increase logging "
+ "level any more");
+ return 2;
+ }
+ logLevel++;
+ }
+ break;
+
+ case 'V':
+ {
+ logLevel = Log::EVERYTHING;
+ }
+ break;
+
case 't':
{
- Console::SetTag(optarg);
+ Logging::SetProgramName(optarg);
+ Console::SetShowTag(true);
}
break;
@@ -221,12 +275,6 @@ int main(int argc, char * const * argv)
}
break;
- case 'V':
- {
- Logging::SetGlobalLevel(Log::EVERYTHING);
- }
- break;
-
case '?':
{
fprintf(stderr, "Unknown option: '%c'\n",
@@ -243,6 +291,8 @@ int main(int argc, char * const * argv)
}
}
+ Logging::SetGlobalLevel((Log::Level)logLevel);
+
argc -= optind - 1;
argv += optind - 1;
#endif // HAVE_GETOPT_H
@@ -276,6 +326,9 @@ int main(int argc, char * const * argv)
Timers::Init();
int returncode = test(argc, (const char **)argv);
Timers::Cleanup();
+
+ fflush(stdout);
+ fflush(stderr);
// check for memory leaks, if enabled
#ifdef BOX_MEMORY_LEAK_TESTING
@@ -292,6 +345,10 @@ int main(int argc, char * const * argv)
if(fulltestmode)
{
bool filesleftopen = checkfilesleftopen();
+
+ fflush(stdout);
+ fflush(stderr);
+
if(filesleftopen)
{
failures++;