Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add slow verification for debugging #1000

Merged
merged 2 commits into from
May 5, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions include/mull/Config/Configuration.h
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ extern int MullDefaultTimeoutMilliseconds;
class Diagnostics;

struct Configuration {
std::string pathOnDisk;
bool debugEnabled;
bool quiet;
bool silent;
Expand Down
1 change: 1 addition & 0 deletions include/mull/Config/ConfigurationOptions.h
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@ struct DebugConfig {
bool coverage = false;
bool gitDiff = false;
bool filters = false;
bool slowIRVerification = false;
};

} // namespace mull
9 changes: 7 additions & 2 deletions include/mull/Parallelization/Tasks/ApplyMutationTask.h
Original file line number Diff line number Diff line change
Expand Up @@ -7,16 +7,21 @@
namespace mull {
class progress_counter;
class MutationPoint;
struct Configuration;
class Diagnostics;

class ApplyMutationTask {
public:
explicit ApplyMutationTask(const Configuration &config, Diagnostics &diagnostics);
using In = const std::vector<MutationPoint *>;
using Out = std::vector<int>;
using iterator = In::const_iterator;

ApplyMutationTask() = default;

void operator()(iterator begin, iterator end, Out &storage,
progress_counter &counter);

private:
const Configuration &config;
Diagnostics &diagnostics;
};
} // namespace mull
2 changes: 1 addition & 1 deletion lib/Config/Configuration.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ namespace mull {
int MullDefaultTimeoutMilliseconds = 3000;

Configuration::Configuration()
: debugEnabled(false), quiet(true), silent(false), dryRunEnabled(false),
: pathOnDisk(), debugEnabled(false), quiet(true), silent(false), dryRunEnabled(false),
captureTestOutput(true), captureMutantOutput(true), includeNotCovered(false),
junkDetectionDisabled(false), timeout(MullDefaultTimeoutMilliseconds),
diagnostics(IDEDiagnosticsKind::None),
Expand Down
2 changes: 2 additions & 0 deletions lib/Config/ConfigurationParser.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,7 @@ template <> struct llvm::yaml::MappingTraits<DebugConfig> {
io.mapOptional("coverage", config.coverage);
io.mapOptional("gitDiff", config.gitDiff);
io.mapOptional("filters", config.filters);
io.mapOptional("slowIRVerification", config.slowIRVerification);
}
};

Expand Down Expand Up @@ -94,5 +95,6 @@ Configuration Configuration::loadFromDisk(Diagnostics &diagnostics, const std::s
llvm::yaml::Input input(bufferOrError.get()->getMemBufferRef());
Configuration configuration;
input >> configuration;
configuration.pathOnDisk = path;
return configuration;
}
17 changes: 14 additions & 3 deletions lib/Driver.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -210,8 +210,11 @@ void mull::mutateBitcode(llvm::Module &module) {
InsertMutationTrampolinesTask::insertTrampolines(bitcode, configuration);
});

TaskExecutor<ApplyMutationTask> applyMutations(
diagnostics, "Applying mutations", mutations, Nothing, { ApplyMutationTask() });
TaskExecutor<ApplyMutationTask> applyMutations(diagnostics,
"Applying mutations",
mutations,
Nothing,
{ ApplyMutationTask(configuration, diagnostics) });
applyMutations.execute();

if (configuration.debug.printIR || configuration.debug.printIRAfter) {
Expand All @@ -224,7 +227,15 @@ void mull::mutateBitcode(llvm::Module &module) {
if (llvm::verifyModule(module, &errorStream)) {
std::stringstream message;
message << "Uh oh! Mull corrupted LLVM module.\n"
<< "Please, report the following error message here "
<< "Please, add the following lines:\n"
<< "debug:\n"
<< " slowIRVerification: true\n"
<< "to the config file ";
if (!configuration.pathOnDisk.empty()) {
message << "(" << configuration.pathOnDisk << ") ";
}
message << "and re-run the failing command.\n\n";
message << "Otherwise, report the following error message here "
"https://github.com/mull-project/mull/issues\n"
<< "Underlying error message:\n"
<< errorStream.str();
Expand Down
31 changes: 31 additions & 0 deletions lib/Parallelization/Tasks/ApplyMutationTask.cpp
Original file line number Diff line number Diff line change
@@ -1,15 +1,46 @@
#include "mull/Parallelization/Tasks/ApplyMutationTask.h"

#include "mull/Config/Configuration.h"
#include "mull/Diagnostics/Diagnostics.h"
#include "mull/MutationPoint.h"
#include "mull/Parallelization/Progress.h"
#include <llvm/IR/Verifier.h>
#include <sstream>

using namespace mull;

ApplyMutationTask::ApplyMutationTask(const Configuration &config, Diagnostics &diagnostics)
: config(config), diagnostics(diagnostics) {}

void ApplyMutationTask::operator()(iterator begin, iterator end, Out &storage,
progress_counter &counter) {
for (auto it = begin; it != end; ++it, counter.increment()) {
auto point = *it;
point->recordMutation();
point->applyMutation();
if (config.debug.slowIRVerification) {
auto module = point->getBitcode()->getModule();
std::string error;
llvm::raw_string_ostream errorStream(error);
if (llvm::verifyModule(*module, &errorStream)) {
std::stringstream message;
std::string mutator = point->getMutatorIdentifier();
message << "Uh oh! Mull corrupted LLVM module.\n"
<< "Please, report the following error message here "
"https://github.com/mull-project/mull/issues\n"
<< "Underlying error message:\n"
<< errorStream.str() << "\n"
<< "The module was corrupted by '" << mutator << "' mutator.\n"
<< "To disable it, add the following:\n"
"ignoreMutators:\n"
<< " - " << mutator << "\n"
<< "to the config file";
if (!config.pathOnDisk.empty()) {
message << " (" << config.pathOnDisk << ")";
}
message << "\n";
diagnostics.error(message.str());
}
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,6 @@ int main(int argc, char **argv) {

// clang-format off

// RUN: %clang_cc %pass_mull_ir_frontend %s -g -o %s.exe
// RUN: %clang_cc %sysroot %pass_mull_ir_frontend %s -g -o %s.exe
// RUN: %mull_runner main.c.exe -ide-reporter-show-killed | %filecheck %s --dump-input=fail --match-full-lines
// CHECK: [info] Killed mutants (1/1):
2 changes: 1 addition & 1 deletion tests-lit/tests/debug/printIRAfter/main.c
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,6 @@ int main() {
return sum(0, 0);
}

// RUN: %clang_cc %pass_mull_ir_frontend -g %s -o %s.exe 2>&1 | %filecheck %s --dump-input=fail --strict-whitespace --match-full-lines
// RUN: %clang_cc %sysroot %pass_mull_ir_frontend -g %s -o %s.exe 2>&1 | %filecheck %s --dump-input=fail --strict-whitespace --match-full-lines
// CHECK:define{{.*}}@sum{{.*}}
// CHECK:define{{.*}}cxx_add_to_sub{{.*}}
2 changes: 1 addition & 1 deletion tests-lit/tests/debug/printIRBefore/main.c
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,6 @@ int main() {
return sum(0, 0);
}

// RUN: %clang_cc %pass_mull_ir_frontend -g %s -o %s.exe 2>&1 | %filecheck %s --dump-input=fail --strict-whitespace --match-full-lines
// RUN: %clang_cc %sysroot %pass_mull_ir_frontend -g %s -o %s.exe 2>&1 | %filecheck %s --dump-input=fail --strict-whitespace --match-full-lines
// CHECK:define{{.*}}@sum{{.*}}
// CHECK-NOT:define{{.*}}cxx_add_to_sub{{.*}}
2 changes: 1 addition & 1 deletion tests-lit/tests/debug/traceMutants/main.c
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ int main() {
return sum(0, 0);
}

// RUN: %clang_cc %pass_mull_ir_frontend -g %s -o %s.exe
// RUN: %clang_cc %sysroot %pass_mull_ir_frontend -g %s -o %s.exe
// RUN: %s.exe | %filecheck %s --dump-input=fail --strict-whitespace --match-full-lines --check-prefix=CHECK
// RUN: env "cxx_add_to_sub:%s:4:12=1" %s.exe | %filecheck %s --dump-input=fail --strict-whitespace --match-full-lines --check-prefix=CHECK-MUTANT

Expand Down
2 changes: 1 addition & 1 deletion tests-lit/tests/filters/blockaddress/main.c
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ int main(int argc, char **argv) {
return 0;
}

// RUN: %clang_cc %pass_mull_ir_frontend -g %s -o %s.exe
// RUN: %clang_cc %sysroot %pass_mull_ir_frontend -g %s -o %s.exe
// RUN: %s.exe | %filecheck %s --dump-input=fail --strict-whitespace --match-full-lines --check-prefix=CHECK1
// CHECK1:label1
// RUN: %s.exe x | %filecheck %s --dump-input=fail --strict-whitespace --match-full-lines --check-prefix=CHECK2
Expand Down
2 changes: 1 addition & 1 deletion tests-lit/tests/filters/variadic-functions/main.c
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@ int main() {
return 0;
}

// RUN: %clang_cc %pass_mull_ir_frontend -g %s -o %s.exe
// RUN: %clang_cc %sysroot %pass_mull_ir_frontend -g %s -o %s.exe
// RUN: %s.exe | %filecheck %s --dump-input=fail --strict-whitespace --match-full-lines
// CHECK:_est
// CHECK-NEXT:t_st
Expand Down