Skip to content

Commit

Permalink
Merge pull request #844 from mull-project/mutate-diffs
Browse files Browse the repository at this point in the history
GitDiffFilter: expand -git-project-root argument to absolute path
  • Loading branch information
stanislaw committed Mar 22, 2021
2 parents 296ee8e + 3eeb0f3 commit eed5960
Show file tree
Hide file tree
Showing 5 changed files with 131 additions and 10 deletions.
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
[
{
"arguments": [
"cc",
"-c",
"-fembed-bitcode",
"-g",
"-O0",
"-o",
"%PWD/sample.cpp.exe",
"%PWD/sample.cpp"
],
"directory": "/",
"file": "%PWD/sample.cpp"
}
]
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
// clang-format off

bool valid_age(int age) {
if (age >= 21) { /// This comment line creates a diff with mutations!
return true;
}
if (age >= 21) {
(void)0; /// This comment line creates a diff with no mutations on the line.
}
return false;
}

int main() {
bool test1 = valid_age(25) == true;
if (!test1) {
/// test failed
return 1;
}

bool test2 = valid_age(20) == false;
if (!test2) {
/// test failed
return 1;
}

bool test3 = valid_age(21) == true;
if (!test3) {
/// test failed
return 1;
}

/// success
return 0;
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
// clang-format off

bool valid_age(int age) {
if (age >= 21) {
return true;
}
if (age >= 21) {
return true;
}
return false;
}

int main() {
bool test1 = valid_age(25) == true;
if (!test1) {
/// test failed
return 1;
}

bool test2 = valid_age(20) == false;
if (!test2) {
/// test failed
return 1;
}

bool test3 = valid_age(21) == true;
if (!test3) {
/// test failed
return 1;
}

/// success
return 0;
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
RUN: cd %S
RUN: mkdir -p %S/Output/sandbox
RUN: cp %S/sample.cpp.original %S/Output/sandbox/sample.cpp
RUN: cd %S/Output/sandbox
RUN: git init .
RUN: git add sample.cpp
RUN: git -c user.name='Mull' -c user.email=alex@lowlevelbits.org commit -m "Impersonation is evil."
RUN: cp %S/sample.cpp.modified %S/Output/sandbox/sample.cpp
RUN: cd / && %CLANG_EXEC -fembed-bitcode -g -O0 %S/Output/sandbox/sample.cpp -o %S/Output/sample.cpp.exe

/// The important part relevant to this test is -git-project-root=. (relative path is passed)
RUN: cd %S/Output/sandbox && (unset TERM; %MULL_EXEC -debug -git-diff-ref=master -git-project-root=. -linker=%clang_cxx -mutators=cxx_ge_to_lt -mutators=cxx_ge_to_gt -ide-reporter-show-killed %S/Output/sample.cpp.exe 2>&1; test $? = 0) | %FILECHECK_EXEC %s --dump-input=fail --strict-whitespace --match-full-lines

CHECK:[info] Incremental testing using Git Diff is enabled.
CHECK:- Git ref: master
CHECK:- Git project root: {{.*}}/Output/sandbox

CHECK:[debug] GitDiffFilter: whitelisting instruction: {{.*}}/sample.cpp:4:7
CHECK:[debug] GitDiffFilter: whitelisting instruction: {{.*}}/sample.cpp:4:11
CHECK:[debug] GitDiffFilter: skipping instruction: {{.*}}/sample.cpp:7:7
CHECK:[debug] GitDiffFilter: skipping instruction: {{.*}}/sample.cpp:7:11

CHECK:[info] Killed mutants (2/2):
CHECK:{{^.*}}sample.cpp:4:11: warning: Killed: Replaced >= with > [cxx_ge_to_gt]{{$}}
CHECK:{{^.*}}sample.cpp:4:11: warning: Killed: Replaced >= with < [cxx_ge_to_lt]{{$}}
CHECK:[info] All mutations have been killed
CHECK:[info] Mutation score: 100%
30 changes: 20 additions & 10 deletions tools/mull-cxx/mull-cxx.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
#include <ebc/BitcodeRetriever.h>
#include <ebc/EmbeddedFile.h>

#include <llvm/Support/Path.h>
#include <llvm/Support/TargetSelect.h>

#include "CLIOptions.h"
Expand Down Expand Up @@ -226,16 +227,25 @@ int main(int argc, char **argv) {
diagnostics.warning(debugMessage.str());
} else {
std::string gitProjectRoot = tool::GitProjectRoot.getValue();
std::string gitDiffBranch = tool::GitDiffRef.getValue();
diagnostics.info(std::string("Incremental testing using Git Diff is enabled.\n")
+ "- Git ref: " + gitDiffBranch + "\n"
+ "- Git project root: " + gitProjectRoot);
mull::GitDiffFilter *gitDiffFilter =
mull::GitDiffFilter::createFromGitDiff(diagnostics, gitProjectRoot, gitDiffBranch);

if (gitDiffFilter) {
filterStorage.emplace_back(gitDiffFilter);
filters.instructionFilters.push_back(gitDiffFilter);
llvm::SmallString<256> tmpGitProjectRoot;
if (!llvm::sys::fs::real_path(gitProjectRoot, tmpGitProjectRoot)) {
gitProjectRoot = tmpGitProjectRoot.str();

std::string gitDiffBranch = tool::GitDiffRef.getValue();
diagnostics.info(std::string("Incremental testing using Git Diff is enabled.\n") +
"- Git ref: " + gitDiffBranch + "\n" +
"- Git project root: " + gitProjectRoot);
mull::GitDiffFilter *gitDiffFilter =
mull::GitDiffFilter::createFromGitDiff(diagnostics, gitProjectRoot, gitDiffBranch);

if (gitDiffFilter) {
filterStorage.emplace_back(gitDiffFilter);
filters.instructionFilters.push_back(gitDiffFilter);
}
} else {
diagnostics.warning(
std::string("could not expand -git-project-root to an absolute path: ") +
gitProjectRoot);
}
}
}
Expand Down

0 comments on commit eed5960

Please sign in to comment.