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

Generate config #1056

Draft
wants to merge 2 commits into
base: main
Choose a base branch
from
Draft
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
2 changes: 0 additions & 2 deletions docs/command-line/generated/mull-runner-cli-options.rst
Original file line number Diff line number Diff line change
Expand Up @@ -32,8 +32,6 @@

--mutation-score-threshold If mutation score falls under this threshold, and allow-surviving is not enabled, an error result code is returned

--no-test-output Does not capture output from test runs

--no-mutant-output Does not capture output from mutant runs

--no-output Combines -no-test-output and -no-mutant-output
Expand Down
30 changes: 3 additions & 27 deletions include/mull/Config/Configuration.h
Original file line number Diff line number Diff line change
Expand Up @@ -7,43 +7,19 @@

namespace mull {

#include "GeneratedConfiguration.h"

extern int MullDefaultTimeoutMilliseconds;

class Diagnostics;

struct Configuration {
struct Configuration : public GeneratedConfiguration {
std::string pathOnDisk;
bool debugEnabled;
bool quiet;
bool silent;
bool dryRunEnabled;
bool captureTestOutput;
bool captureMutantOutput;
bool includeNotCovered;
bool junkDetectionDisabled;

unsigned timeout;

IDEDiagnosticsKind diagnostics;

std::vector<std::string> mutators;
std::vector<std::string> ignoreMutators;

std::string executable;

std::string compilationDatabasePath;
std::vector<std::string> compilerFlags;

std::vector<std::string> includePaths;
std::vector<std::string> excludePaths;

ParallelizationConfig parallelization;

std::string gitDiffRef;
std::string gitProjectRoot;

DebugConfig debug{};

Configuration();

static std::string findConfig(Diagnostics &diagnostics);
Expand Down
20 changes: 4 additions & 16 deletions include/mull/Config/ConfigurationOptions.h
Original file line number Diff line number Diff line change
Expand Up @@ -2,27 +2,15 @@

namespace mull {

enum class IDEDiagnosticsKind { None, Survived, Killed, All };
#include "GeneratedDebugConfig.h"
#include "GeneratedParallelizationConfig.h"

struct ParallelizationConfig {
unsigned workers;
unsigned executionWorkers;
ParallelizationConfig();
struct ParallelizationConfig : public GeneratedParallelizationConfig {
static ParallelizationConfig defaultConfig();
void normalize();
bool exceedsHardware();
};

struct DebugConfig {
bool printIR = false;
bool printIRBefore = false;
bool printIRAfter = false;
bool printIRToFile = false;
bool traceMutants = false;
bool coverage = false;
bool gitDiff = false;
bool filters = false;
bool slowIRVerification = false;
};
struct DebugConfig : public GeneratedDebugConfig {};

} // namespace mull
153 changes: 153 additions & 0 deletions include/mull/Config/config.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,153 @@
[
{
"type": "struct",
"name": "ParallelizationConfig",
"description": "Controls parallelization",
"fields": [
{
"name": "workers",
"type": "unsigned",
"description": "How many threads to use for mutation and execution"
},
{
"name": "executionWorkers",
"type": "unsigned",
"description": "How many threads to use for execution"
}
]
},
{
"type": "struct",
"name": "DebugConfig",
"description": "Enables certain debug features",
"fields": [
{
"name": "printIR",
"type": "bool",
"description": "Prints LLVM IR before/after mutations into stderr"
},
{
"name": "printIRBefore",
"type": "bool",
"description": "Prints LLVM IR before mutations into stderr"
},
{
"name": "printIRAfter",
"type": "bool",
"description": "Prints LLVM IR after mutations into stderr"
},
{
"name": "printIRToFile",
"type": "bool",
"description": "Prints LLVM IR (before or after) into a file instead of stderr"
},
{
"name": "traceMutants",
"type": "bool",
"description": "Adds debug `printf`s into generated LLVM IR around mutations"
},
{
"name": "coverage",
"type": "bool",
"description": "Prints more debug output when `coverage` filter is enabled"
},
{
"name": "gitDiff",
"type": "bool",
"description": "Prints more debug output when `gitDiff` filter is enabled"
},
{
"name": "filters",
"type": "bool",
"description": "Prints more debug output for various filters"
},
{
"name": "slowIRVerification",
"type": "bool",
"description": "Turns on LLVM IR verification after each mutation is applied"
}
]
},
{
"type": "struct",
"name": "Configuration",
"description": "Mull config",
"fields": [
{
"name": "debugEnabled",
"type": "bool",
"description": "Turns on debug output"
},
{
"name": "quiet",
"type": "bool",
"description": "Turns off any output except of warnings and errors"
},
{
"name": "silent",
"type": "bool",
"description": "Turns off any output"
},
{
"name": "includeNotCovered",
"type": "bool",
"description": "Controls whether `coverage` filter should skip mutants that are not covered. Disabled by default."
},
{
"name": "junkDetectionDisabled",
"type": "bool",
"description": "Controls whether `junk detection` filter is enabled or not. Enabled by default."
},
{
"name": "mutators",
"type": "std::vector<std::string>",
"description": "Controls which mutators to turn on"
},
{
"name": "ignoreMutators",
"type": "std::vector<std::string>",
"description": "Controls which mutators to turn off"
},
{
"name": "compilationDatabasePath",
"type": "std::string",
"description": "Path to the compilation database (compile_commands.json)"
},
{
"name": "compilerFlags",
"type": "std::vector<std::string>",
"description": "Additional compiler flags used for junk detection"
},
{
"name": "includePaths",
"type": "std::vector<std::string>",
"description": "Controls behavior of `file path` filter"
},
{
"name": "excludePaths",
"type": "std::vector<std::string>",
"description": "Controls behavior of `file path` filter"
},
{
"name": "parallelization",
"type": "ParallelizationConfig",
"description": "Controls parallelization (both mutation and mutant execution)"
},
{
"name": "gitDiffRef",
"type": "std::string",
"description": "Controls the git ref for `git diff` filter"
},
{
"name": "gitProjectRoot",
"type": "std::string",
"description": "Controls the git repo location for `git diff` filter"
},
{
"name": "debug",
"type": "DebugConfig",
"description": "Controls various debug options"
}
]
}
]
20 changes: 19 additions & 1 deletion lib/Config/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -5,5 +5,23 @@ add_library(mull-configuration
)
target_include_directories(mull-configuration PUBLIC ${CMAKE_SOURCE_DIR}/include)
target_include_directories(mull-configuration PRIVATE ${LLVM_INCLUDE_DIRS})

# FIXME: replace with target_compile_options()
set_target_properties(mull-configuration PROPERTIES COMPILE_FLAGS ${MULL_CXX_FLAGS})
set_target_properties(mull-configuration PROPERTIES COMPILE_FLAGS ${MULL_CXX_FLAGS})

add_custom_command(
OUTPUT
${CMAKE_CURRENT_BINARY_DIR}/GeneratedYamlMapping.cpp
${CMAKE_CURRENT_BINARY_DIR}/GeneratedConfiguration.h
${CMAKE_CURRENT_BINARY_DIR}/GeneratedDebugConfig.h
${CMAKE_CURRENT_BINARY_DIR}/GeneratedParallelizationConfig.h
COMMAND
python3 ${CMAKE_CURRENT_SOURCE_DIR}/config_gen.py ${CMAKE_SOURCE_DIR}/include/mull/Config/config.json ${CMAKE_CURRENT_BINARY_DIR}
DEPENDS ${CMAKE_SOURCE_DIR}/include/mull/Config/config.json ${CMAKE_CURRENT_SOURCE_DIR}/config_gen.py
)
target_include_directories(mull-configuration PUBLIC ${CMAKE_CURRENT_BINARY_DIR})
add_custom_target(generate-config-sources DEPENDS ${CMAKE_CURRENT_BINARY_DIR}/GeneratedYamlMapping.cpp
${CMAKE_CURRENT_BINARY_DIR}/GeneratedConfiguration.h
${CMAKE_CURRENT_BINARY_DIR}/GeneratedDebugConfig.h
${CMAKE_CURRENT_BINARY_DIR}/GeneratedParallelizationConfig.h)
add_dependencies(mull-configuration generate-config-sources)
8 changes: 3 additions & 5 deletions lib/Config/Configuration.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -5,10 +5,8 @@ namespace mull {
int MullDefaultTimeoutMilliseconds = 3000;

Configuration::Configuration()
: pathOnDisk(), debugEnabled(false), quiet(true), silent(false), dryRunEnabled(false),
captureTestOutput(true), captureMutantOutput(true), includeNotCovered(false),
junkDetectionDisabled(false), timeout(MullDefaultTimeoutMilliseconds),
diagnostics(IDEDiagnosticsKind::None),
parallelization(ParallelizationConfig::defaultConfig()) {}
: pathOnDisk(), captureMutantOutput(true), timeout(MullDefaultTimeoutMilliseconds) {
this->parallelization = ParallelizationConfig::defaultConfig();
}

} // namespace mull
2 changes: 0 additions & 2 deletions lib/Config/ConfigurationOptions.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,6 @@

namespace mull {

ParallelizationConfig::ParallelizationConfig() : workers(0), executionWorkers(0) {}

void ParallelizationConfig::normalize() {
unsigned defaultWorkers = std::max(std::thread::hardware_concurrency(), unsigned(1));
if (workers == 0) {
Expand Down
53 changes: 1 addition & 52 deletions lib/Config/ConfigurationParser.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -8,58 +8,7 @@
using namespace mull;
using namespace std::string_literals;

template <> struct llvm::yaml::ScalarEnumerationTraits<IDEDiagnosticsKind> {
static void enumeration(llvm::yaml::IO &io, IDEDiagnosticsKind &value) {
io.enumCase(value, "none", IDEDiagnosticsKind::None);
io.enumCase(value, "killed", IDEDiagnosticsKind::Killed);
io.enumCase(value, "survived", IDEDiagnosticsKind::Survived);
io.enumCase(value, "all", IDEDiagnosticsKind::All);
}
};

template <> struct llvm::yaml::MappingTraits<ParallelizationConfig> {
static void mapping(llvm::yaml::IO &io, ParallelizationConfig &config) {
io.mapOptional("workers", config.workers);
io.mapOptional("executionWorkers", config.executionWorkers);
}
};

template <> struct llvm::yaml::MappingTraits<DebugConfig> {
static void mapping(llvm::yaml::IO &io, DebugConfig &config) {
io.mapOptional("printIR", config.printIR);
io.mapOptional("printIRAfter", config.printIRAfter);
io.mapOptional("printIRBefore", config.printIRBefore);
io.mapOptional("printIRToFile", config.printIRToFile);
io.mapOptional("traceMutants", config.traceMutants);
io.mapOptional("coverage", config.coverage);
io.mapOptional("gitDiff", config.gitDiff);
io.mapOptional("filters", config.filters);
io.mapOptional("slowIRVerification", config.slowIRVerification);
}
};

template <> struct llvm::yaml::MappingTraits<Configuration> {
static void mapping(llvm::yaml::IO &io, Configuration &config) {
io.mapOptional("debugEnabled", config.debugEnabled);
io.mapOptional("quiet", config.quiet);
io.mapOptional("silent", config.silent);
io.mapOptional("captureTestOutput", config.captureTestOutput);
io.mapOptional("captureMutantOutput", config.captureMutantOutput);
io.mapOptional("includeNotCovered", config.includeNotCovered);
io.mapOptional("timeout", config.timeout);
io.mapOptional("mutators", config.mutators);
io.mapOptional("ignoreMutators", config.ignoreMutators);
io.mapOptional("parallelization", config.parallelization);
io.mapOptional("compilationDatabasePath", config.compilationDatabasePath);
io.mapOptional("compilerFlags", config.compilerFlags);
io.mapOptional("junkDetectionDisabled", config.junkDetectionDisabled);
io.mapOptional("gitDiffRef", config.gitDiffRef);
io.mapOptional("gitProjectRoot", config.gitProjectRoot);
io.mapOptional("includePaths", config.includePaths);
io.mapOptional("excludePaths", config.excludePaths);
io.mapOptional("debug", config.debug);
}
};
#include "GeneratedYamlMapping.cpp"

std::string Configuration::findConfig(Diagnostics &diagnostics) {
if (getenv("MULL_CONFIG") != nullptr) {
Expand Down
Loading
Loading