Skip to content

Commit

Permalink
Diagnostics: enable debug-level logging (#669)
Browse files Browse the repository at this point in the history
  • Loading branch information
stanislaw authored Mar 8, 2020
1 parent 7d51cc8 commit 22c7d85
Show file tree
Hide file tree
Showing 7 changed files with 61 additions and 2 deletions.
2 changes: 2 additions & 0 deletions docs/generated/CLIOptions.rst
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,8 @@

--ide-reporter-show-killed Makes IDEReporter to also report killed mutations (disabled by default)

--debug Enables Debug Mode: more logs are printed

--compdb-path filename Path to a compilation database (compile_commands.json) for junk detection

--compilation-flags string Extra compilation flags for junk detection
Expand Down
4 changes: 4 additions & 0 deletions include/mull/Diagnostics/Diagnostics.h
Original file line number Diff line number Diff line change
Expand Up @@ -12,17 +12,21 @@ class Diagnostics {
Diagnostics();
~Diagnostics();

void enableDebugMode();

void info(const std::string& message);
void warning(const std::string& message);
void error(const std::string& message);
void progress(const std::string& message);
void debug(const std::string& message);

private:
void prepare();

DiagnosticsImpl *impl;
std::mutex mutex;
bool seenProgress;
bool debugModeEnabled;
};

}
22 changes: 20 additions & 2 deletions lib/Diagnostics/Diagnostics.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -15,17 +15,26 @@ class mull::DiagnosticsImpl {
spdlog::logger &log() {
return *logger;
}

void enableDebugMode() {
log().set_level(spdlog::level::level_enum::debug);
}
private:
std::unique_ptr<spdlog::logger> logger;
};

Diagnostics::Diagnostics() : impl(new DiagnosticsImpl()), seenProgress(false) {}
Diagnostics::Diagnostics()
: impl(new DiagnosticsImpl()), seenProgress(false), debugModeEnabled(false) {}

Diagnostics::~Diagnostics() {
delete impl;
}

void Diagnostics::enableDebugMode() {
std::lock_guard<std::mutex> guard(mutex);
debugModeEnabled = true;
impl->enableDebugMode();
}

void Diagnostics::info(const std::string &message) {
std::lock_guard<std::mutex> guard(mutex);
prepare();
Expand All @@ -51,6 +60,15 @@ void Diagnostics::progress(const std::string &message) {
fflush(stdout);
}

void Diagnostics::debug(const std::string &message) {
std::lock_guard<std::mutex> guard(mutex);
if (!debugModeEnabled) {
return;
}
prepare();
impl->log().debug(message);
}

void Diagnostics::prepare() {
if (seenProgress) {
fprintf(stdout, "\n");
Expand Down
20 changes: 20 additions & 0 deletions tests-lit/tests/options/-debug/01-debug-option/sample.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
int sum(int a, int b) {
return a + b;
}

int main() {
return sum(-2, 2);
}

/**
; RUN: cd / && %CLANG_EXEC -fembed-bitcode -g -O0 %s -o %s.exe
; RUN: cd %CURRENT_DIR
; RUN: %MULL_EXEC -test-framework CustomTest -mutators=cxx_add_to_sub -reporters=IDE -ide-reporter-show-killed %s.exe | %FILECHECK_EXEC %s --strict-whitespace --match-full-lines --check-prefix=WITHOUT-DEBUG
; RUN: %MULL_EXEC -test-framework CustomTest -mutators=cxx_add_to_sub -reporters=IDE -ide-reporter-show-killed %s.exe -debug | %FILECHECK_EXEC %s --strict-whitespace --match-full-lines --check-prefix=WITH-DEBUG
; WITHOUT-DEBUG-NOT:{{^.*\[debug\].*$}}
; WITHOUT-DEBUG:{{^.*}}sample.cpp:2:12: warning: Killed: Replaced + with - [cxx_add_to_sub]{{$}}
; WITH-DEBUG:[debug] Diagnostics: debug mode enabled
; WITH-DEBUG:{{^.*}}sample.cpp:2:12: warning: Killed: Replaced + with - [cxx_add_to_sub]{{$}}
**/
8 changes: 8 additions & 0 deletions tools/driver-cxx/CLIOptions.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -136,6 +136,13 @@ opt<bool> tool::IDEReporterShowKilled(
init(false),
cat(MullCXXCategory));

opt<bool> tool::DebugEnabled(
"debug",
desc("Enables Debug Mode: more logs are printed"),
Optional,
init(false),
cat(MullCXXCategory));

opt<bool> tool::DumpCLIInterface(
"dump-cli",
desc("Prints CLI options in the Sphinx/RST friendly format"),
Expand Down Expand Up @@ -301,6 +308,7 @@ void tool::dumpCLIInterface(Diagnostics &diagnostics) {
&ReportDirectory,
reporters,
&IDEReporterShowKilled,
&DebugEnabled,

&CompilationDatabasePath,
&CompilationFlags,
Expand Down
2 changes: 2 additions & 0 deletions tools/driver-cxx/CLIOptions.h
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,8 @@ extern opt<TestFrameworkOptionIndex> TestFrameworks;
extern list<ReporterKind> ReportersOption;
extern opt<bool> IDEReporterShowKilled;

extern opt<bool> DebugEnabled;

extern opt<SandboxKind> SandboxOption;

extern list<std::string> LDSearchPaths;
Expand Down
5 changes: 5 additions & 0 deletions tools/driver-cxx/driver-cxx.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -62,6 +62,11 @@ int main(int argc, char **argv) {
return 1;
}

if (tool::DebugEnabled) {
diagnostics.enableDebugMode();
diagnostics.debug("Diagnostics: debug mode enabled");
}

validateInputFile();

mull::MetricsMeasure totalExecutionTime;
Expand Down

0 comments on commit 22c7d85

Please sign in to comment.