Skip to content

Commit

Permalink
Implement coverage for all applicable metrics
Browse files Browse the repository at this point in the history
More metrics with modifiers support
Add simple test case
Fix SBCC subtractive coverage
  • Loading branch information
tom91136 committed Aug 1, 2024
1 parent 55e4989 commit 9cd510d
Show file tree
Hide file tree
Showing 41 changed files with 1,904 additions and 1,147 deletions.
31 changes: 20 additions & 11 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ CPMAddPackage("gh:ThePhD/[email protected]")
CPMAddPackage("gh:DatabaseGroup/tree-similarity#0.1.1")
CPMAddPackage(Aspartame
GITHUB_REPOSITORY tom91136/Aspartame
GIT_TAG 31a0e22298b0c89455f8edfbe48675c6858c2420)
GIT_TAG 8e87a5bb)
CPMAddPackage(
NAME zstd
GITHUB_REPOSITORY facebook/zstd
Expand Down Expand Up @@ -141,6 +141,7 @@ list(APPEND SV_COMPILE_FLAGS
-Wno-unused-function
-Wno-unused-variable
-Wno-unknown-warning-option
# -ftime-trace
)
list(APPEND SV_LINK_FLAGS "$<$<CONFIG:Debug>:${SV_LINK_DEBUG_FLAGS}>")

Expand Down Expand Up @@ -187,10 +188,12 @@ target_link_libraries(SilverVale
tree-sitter-rust
tree-sitter-fortran
clang-cpp
LLVM
)
LLVM)
target_compile_options(SilverVale PRIVATE ${SV_COMPILE_FLAGS})
target_link_options(SilverVale PRIVATE ${SV_LINK_FLAGS})
#set_property(TARGET SilverVale PROPERTY CXX_INCLUDE_WHAT_YOU_USE include-what-you-use)


if (CMAKE_BUILD_TYPE STREQUAL "Debug")
target_precompile_headers(SilverVale PRIVATE
[["clang/Tooling/Tooling.h"]]
Expand All @@ -212,11 +215,15 @@ if (CMAKE_BUILD_TYPE STREQUAL "Debug")
[["zstd.h"]]

[["aspartame/map.hpp"]]
[["aspartame/set.hpp"]]
[["aspartame/unordered_set.hpp"]]
[["aspartame/unordered_map.hpp"]]
[["aspartame/optional.hpp"]]
[["aspartame/string.hpp"]]
[["aspartame/vector.hpp"]]
[["aspartame/view.hpp"]]


<map>
<tuple>
<ctime>
Expand All @@ -228,14 +235,16 @@ if (CMAKE_BUILD_TYPE STREQUAL "Debug")
<utility>
<optional>
<iostream>
<fstream>
<type_traits>
<functional>
<filesystem>
<unordered_map>
)
endif ()

add_executable(driver src/driver.cpp)
add_executable(tests test/tree.cpp test/index.cpp test/structure.cpp test/preprocessor.cpp)
add_executable(tests test/tree.cpp test/ast.cpp test/index_microstream.cpp test/index_simple.cpp test/preprocessor.cpp)
target_link_libraries(tests PRIVATE Catch2::Catch2WithMain)
set_target_properties(driver PROPERTIES OUTPUT_NAME "sv")
foreach (target driver tests)
Expand All @@ -251,18 +260,17 @@ function(setup_fixture name cc cxx fc suffix)
message(STATUS "Adding fixture ${fixture_name}")
set(build_dir "${CMAKE_BINARY_DIR}/${fixture_name}_build")
set(FIXTURE_${fixture_name_upper}_EXPR "std::tuple{ \"${name}\", \"${cc}\", \"${suffix}\", \"${build_dir}\" }" PARENT_SCOPE)

add_custom_command(
TARGET tests
PRE_BUILD
TARGET tests POST_BUILD
COMMAND ${CMAKE_COMMAND} -E rm -rf "${build_dir}"
COMMAND ${CMAKE_COMMAND} -E env CCACHE_DISABLE=1 CC=${cc} CXX=${cxx} FC=${fc} ${CMAKE_COMMAND}
-S "${CMAKE_SOURCE_DIR}/test/fixture/${name}"
-B "${build_dir}"
${ARGN}
-DCMAKE_BUILD_TYPE=Release
-DCMAKE_EXPORT_COMPILE_COMMANDS=ON
-DCMAKE_VERBOSE_MAKEFILE=ON
COMMAND ${CMAKE_COMMAND} --build "${build_dir}"
BYPRODUCTS "${build_dir}/CMakeCache.txt"
WORKING_DIRECTORY "${CMAKE_CURRENT_BINARY_DIR}"
COMMENT "Configure fixture ${name} as ${fixture_name}"
)
Expand All @@ -272,11 +280,12 @@ add_library(processor_fixture OBJECT test/fixture/processor.cpp)
target_compile_options(processor_fixture PRIVATE -E)
set(FIXTURE_PROCESSOR_FILE "$<TARGET_OBJECTS:processor_fixture>")

set(GCC_COVERAGE_FLAGS "-fprofile-arcs;-ftest-coverage")
set(GCC_COVERAGE_FLAGS "-fprofile-arcs;-ftest-coverage;-g") # -g helps retain `return` in coverage (!?)
set(CLANG_COVERAGE_FLAGS "-fprofile-instr-generate;-fcoverage-mapping")

setup_fixture(dummy clang clang++ flang-new "" -DCMAKE_CXX_FLAGS="${CLANG_COVERAGE_FLAGS}")
setup_fixture(dummy gcc g++ gfortran "" -DCMAKE_CXX_FLAGS="${GCC_COVERAGE_FLAGS}")
setup_fixture(simple clang clang++ flang-new cxx -DCMAKE_CXX_FLAGS="${CLANG_COVERAGE_FLAGS}")
setup_fixture(simple gcc g++ gfortran cxx -DCMAKE_CXX_FLAGS="${GCC_COVERAGE_FLAGS}")
setup_fixture(simple gcc g++ gfortran f90 -DUSE_FORTRAN=ON -DCMAKE_Fortran_FLAGS="${GCC_COVERAGE_FLAGS}")

setup_fixture(microstream gcc g++ gfortran serial_f90 -DUSE_SERIAL=ON -DUSE_FORTRAN=ON -DCMAKE_Fortran_FLAGS="${GCC_COVERAGE_FLAGS}")
setup_fixture(microstream gcc g++ gfortran omp_f90 -DUSE_OMP=ON -DUSE_FORTRAN=ON -DCMAKE_Fortran_FLAGS="${GCC_COVERAGE_FLAGS}")
Expand Down
2 changes: 1 addition & 1 deletion include/sv/cli.h
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
#pragma once

#include <iosfwd>
#include <iostream>

#include "clang/Tooling/CommonOptionsParser.h"
#include "llvm/Support/CommandLine.h"
Expand Down
5 changes: 5 additions & 0 deletions include/sv/compress.h
Original file line number Diff line number Diff line change
@@ -1,6 +1,11 @@
#pragma once

#include <cstddef>
#include <cstdint>
#include <optional>
#include <string>
#include <system_error>
#include <vector>

#include "zstd.h"
#include "llvm/Support/raw_ostream.h"
Expand Down
47 changes: 24 additions & 23 deletions include/sv/database.h
Original file line number Diff line number Diff line change
Expand Up @@ -18,13 +18,12 @@ constexpr std::string_view EntryGCCGCovName = "coverage.gcc_gcov.sv.json";
struct GCCGCovProfile {

struct Line {
size_t line_number;
std::string function_name;
size_t count;
bool unexecuted_block;
size_t line_number{};
// XXX not all lines have a `function_name`
size_t count{};
bool unexecuted_block{};
// XXX `branches` not implemented

NLOHMANN_DEFINE_TYPE_INTRUSIVE(Line, line_number, function_name, count, unexecuted_block);
NLOHMANN_DEFINE_TYPE_INTRUSIVE(Line, line_number, count, unexecuted_block);
};

struct Function {
Expand All @@ -46,7 +45,7 @@ struct GCCGCovProfile {
std::string file{};
std::vector<Function> functions{};
std::vector<Line> lines{};
NLOHMANN_DEFINE_TYPE_INTRUSIVE(Entry, file, functions);
NLOHMANN_DEFINE_TYPE_INTRUSIVE(Entry, file, functions, lines);
};

std::string format_version{};
Expand Down Expand Up @@ -129,35 +128,38 @@ struct ClangSBCCProfile {
NLOHMANN_DEFINE_TYPE_INTRUSIVE(ClangSBCCProfile, type, version, data);
};

struct CountBasedCoverage {
struct Count {
size_t lineStart, lineEnd;
size_t colStart, colEnd;
size_t count;
struct PerFileCoverage {
struct Instance {
std::string function{};
size_t lineStart{}, lineEnd{};
size_t colStart{}, colEnd{};
size_t count{};

private:
DEF_SOL_UT_ACCESSOR(function);
DEF_SOL_UT_ACCESSOR(lineStart);
DEF_SOL_UT_ACCESSOR(lineEnd);
DEF_SOL_UT_ACCESSOR(colStart);
DEF_SOL_UT_ACCESSOR(colEnd);
DEF_SOL_UT_ACCESSOR(count);

public:
DEF_TEAL_SOL_UT(Count, //
SOL_UT_FN_ACC(Count, lineStart), //
SOL_UT_FN_ACC(Count, lineEnd), //
SOL_UT_FN_ACC(Count, colStart), //
SOL_UT_FN_ACC(Count, colEnd), //
SOL_UT_FN_ACC(Count, count));
DEF_TEAL_SOL_UT(Instance, //
SOL_UT_FN_ACC(Instance, function), //
SOL_UT_FN_ACC(Instance, lineStart), //
SOL_UT_FN_ACC(Instance, lineEnd), //
SOL_UT_FN_ACC(Instance, colStart), //
SOL_UT_FN_ACC(Instance, colEnd), //
SOL_UT_FN_ACC(Instance, count));
};

std::map<std::string, std::vector<Count>> functions{};
std::map<std::string, std::vector<Instance>> filenames{};

private:
DEF_SOL_UT_ACCESSOR(functions);
DEF_SOL_UT_ACCESSOR(filenames);

public:
DEF_TEAL_SOL_UT(CountBasedCoverage, SOL_UT_FN_ACC(CountBasedCoverage, functions));
DEF_TEAL_SOL_UT(PerFileCoverage, SOL_UT_FN_ACC(PerFileCoverage, filenames));
};

struct CompilationDatabase {
Expand Down Expand Up @@ -381,8 +383,7 @@ struct FlatEntry {
struct Database {
std::string root{};
std::vector<std::variant<std::shared_ptr<ClangEntry>, std::shared_ptr<FlatEntry>>> entries{};

std::shared_ptr<CountBasedCoverage> coverage{};
std::shared_ptr<PerFileCoverage> coverage{};

private:
DEF_SOL_UT_ACCESSOR(root);
Expand Down
1 change: 1 addition & 0 deletions include/sv/glob.h
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
#pragma once

#include <regex>
#include <string>

namespace sv {
std::regex globToRegex(const std::string &str, bool extended = true, bool globStar = false);
Expand Down
Loading

0 comments on commit 9cd510d

Please sign in to comment.