Skip to content

Commit

Permalink
Merge pull request #868 from mull-project/dot-slash-binary
Browse files Browse the repository at this point in the history
mull-cxx and mull-runner: use real_path to expand relative paths
  • Loading branch information
stanislaw committed May 31, 2021
2 parents 673e2dd + 47f9bdb commit d4f63d2
Show file tree
Hide file tree
Showing 4 changed files with 64 additions and 14 deletions.
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
int test(int a, int b) {
return a + b;
}

int main(int argc, char **argv) {
return !( test(2, 3) == 5 );
}

// clang-format off

// RUN: %clang_cc %s -fembed-bitcode -g -o %s.exe

// RUN: cd %S

// RUN: %mull_cxx -linker=%clang_cc -ide-reporter-show-killed -keep-executable -mutators=cxx_add_to_sub -mutators=cxx_mul_to_div main.c.exe | %FILECHECK_EXEC %s --dump-input=fail --match-full-lines --check-prefix=CHECK-MULL-CXX
// CHECK-MULL-CXX: [info] Killed mutants (1/1):

// RUN: %mull_cxx -linker=%clang_cc -keep-executable -mutate-only -output=main.c.mutated.exe -mutators=cxx_add_to_sub -mutators=cxx_mul_to_div main.c.exe | %FILECHECK_EXEC %s --dump-input=fail --match-full-lines --check-prefix=CHECK-MUTATE
// CHECK-MUTATE: [info] Mutate-only mode on:{{.*}}

// RUN: %mull_runner main.c.mutated.exe -ide-reporter-show-killed | %FILECHECK_EXEC %s --dump-input=fail --match-full-lines --check-prefix=CHECK-RUNNER
// CHECK-RUNNER: [info] Killed mutants (1/1):
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
// clang-format off

/**
RUN: cd %CURRENT_DIR
RUN: (unset TERM; %MULL_EXEC -linker=%clang_cc this-file-does-not-exist 2>&1; test $? = 1) | %FILECHECK_EXEC %s --dump-input=fail --strict-whitespace --match-full-lines --check-prefix=CHECK-CXX
CHECK-CXX:[error] The provided path to an executable program is not valid: this-file-does-not-exist
CHECK-CXX:[error] Error messages are treated as fatal errors. Exiting now.
RUN: (%mull_runner this-file-does-not-exist 2>&1; test $? = 1) | %FILECHECK_EXEC %s --dump-input=fail --match-full-lines --check-prefix=CHECK-RUNNER
CHECK-RUNNER:[error] The provided path to an executable program is not valid: this-file-does-not-exist
CHECK-RUNNER:[error] Error messages are treated as fatal errors. Exiting now.
*/
22 changes: 15 additions & 7 deletions tools/mull-cxx/mull-cxx.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -33,11 +33,19 @@
#include <sstream>
#include <unistd.h>

static void validateInputFile() {
if (access(tool::InputFile.getValue().c_str(), R_OK) != 0) {
perror(tool::InputFile.getValue().c_str());
exit(1);
static std::string validateInputFile(const std::string &inputFile, mull::Diagnostics &diagnostics) {
if (access(inputFile.c_str(), R_OK) != 0) {
diagnostics.error(std::string("The provided path to an executable program is not valid: ") +
inputFile.c_str());
return "";
}
llvm::SmallString<256> inputRealPath;
if (llvm::sys::fs::real_path(inputFile, inputRealPath, false)) {
diagnostics.error(std::string("The provided path to an executable program is not valid: ") +
inputFile.c_str());
return "";
}
return inputRealPath.str().str();
}

static std::vector<std::string> splitFlags(const std::string &flags) {
Expand Down Expand Up @@ -77,7 +85,7 @@ int main(int argc, char **argv) {
"Diagnostics: Strict Mode enabled. Warning messages will be treated as fatal errors.");
}

validateInputFile();
const std::string inputFile = validateInputFile(tool::InputFile.getValue(), diagnostics);

mull::MetricsMeasure totalExecutionTime;
totalExecutionTime.start();
Expand All @@ -101,7 +109,7 @@ int main(int argc, char **argv) {
configuration.debugEnabled = tool::DebugEnabled;
configuration.timeout = tool::Timeout.getValue();

configuration.executable = tool::InputFile.getValue();
configuration.executable = inputFile;
configuration.outputFile = tool::OutputFile.getValue();
configuration.coverageInfo = tool::CoverageInfo.getValue();
configuration.includeNotCovered = tool::IncludeNotCovered.getValue();
Expand All @@ -128,7 +136,7 @@ int main(int argc, char **argv) {
std::vector<std::unique_ptr<ebc::EmbeddedFile>> embeddedFiles;
mull::SingleTaskExecutor extractBitcodeBuffers(diagnostics);
extractBitcodeBuffers.execute("Extracting bitcode from executable", [&] {
ebc::BitcodeRetriever bitcodeRetriever(tool::InputFile.getValue());
ebc::BitcodeRetriever bitcodeRetriever(inputFile);
for (auto &bitcodeInfo : bitcodeRetriever.GetBitcodeInfo()) {
auto &container = bitcodeInfo.bitcodeContainer;
if (container) {
Expand Down
22 changes: 15 additions & 7 deletions tools/mull-runner/mull-runner.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -11,11 +11,19 @@
#include <memory>
#include <unistd.h>

static void validateInputFile() {
if (access(tool::InputFile.getValue().c_str(), R_OK) != 0) {
perror(tool::InputFile.getValue().c_str());
exit(1);
static std::string validateInputFile(const std::string &inputFile, mull::Diagnostics &diagnostics) {
if (access(inputFile.c_str(), R_OK) != 0) {
diagnostics.error(std::string("The provided path to an executable program is not valid: ") +
inputFile.c_str());
return "";
}
llvm::SmallString<256> inputRealPath;
if (llvm::sys::fs::real_path(inputFile, inputRealPath, false)) {
diagnostics.error(std::string("The provided path to an executable program is not valid: ") +
inputFile.c_str());
return "";
}
return inputRealPath.str().str();
}

int main(int argc, char **argv) {
Expand Down Expand Up @@ -45,7 +53,7 @@ int main(int argc, char **argv) {
"Diagnostics: Strict Mode enabled. Warning messages will be treated as fatal errors.");
}

validateInputFile();
std::string inputFile = validateInputFile(tool::InputFile.getValue(), diagnostics);

mull::MetricsMeasure totalExecutionTime;
totalExecutionTime.start();
Expand All @@ -56,7 +64,7 @@ int main(int argc, char **argv) {
configuration.timeout = tool::Timeout.getValue();
configuration.includeNotCovered = tool::IncludeNotCovered.getValue();

configuration.executable = tool::InputFile.getValue();
configuration.executable = inputFile;

if (tool::Workers) {
mull::ParallelizationConfig parallelizationConfig;
Expand All @@ -82,7 +90,7 @@ int main(int argc, char **argv) {
.IDEReporterShowKilled = tool::IDEReporterShowKilled };
std::vector<std::unique_ptr<mull::Reporter>> reporters = reportersOption.reporters(params);

std::string executable = tool::InputFile.getValue();
std::string executable = inputFile;
std::string testProgram = executable;
if (!tool::TestProgram.empty()) {
testProgram = tool::TestProgram.getValue();
Expand Down

0 comments on commit d4f63d2

Please sign in to comment.