Skip to content

Commit

Permalink
Switch test coverage to use Clang.
Browse files Browse the repository at this point in the history
  • Loading branch information
tmadden committed Jul 12, 2018
1 parent 0ad9d78 commit 4f29591
Show file tree
Hide file tree
Showing 4 changed files with 31 additions and 137 deletions.
8 changes: 7 additions & 1 deletion .travis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,12 @@ before_script:
script:
- ./fips make test linux-make-debug
- ./fips make test linux-make-release
- export CC=`which clang-5.0`
- export CXX=`which clang-5.0`
- ./fips clean linux-make-debug
- ./fips clean linux-make-release
- ./fips make test linux-make-debug
- ./fips make test linux-make-release

before_cache:
- conan remove "*" -s -b -f
Expand All @@ -24,4 +30,4 @@ cache:
- $HOME/.conan/data

after_success:
- bash <(curl -s https://codecov.io/bash) -X gcov -f lcov.info
- bash <(curl -s https://codecov.io/bash) -X gcov
32 changes: 20 additions & 12 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -16,22 +16,31 @@ fips_project(alia)
# Conan and fips disagree on various build options, so we need to override
# some of Conan's defaults.
set(CONAN_OPTIONS)
if (FIPS_MSVC)
if (CMAKE_BUILD_TYPE STREQUAL "Debug")
if(FIPS_MSVC)
if(CMAKE_BUILD_TYPE STREQUAL "Debug")
set(CONAN_OPTIONS
-s compiler=Visual\ Studio -s build_type=Debug -s compiler.runtime=MTd)
else()
set(CONAN_OPTIONS
-s compiler=Visual\ Studio -s build_type=Release -s compiler.runtime=MT)
endif()
elseif(FIPS_GCC)
if (CMAKE_BUILD_TYPE STREQUAL "Debug")
if(CMAKE_BUILD_TYPE STREQUAL "Debug")
set(CONAN_OPTIONS
-s compiler=gcc -s compiler.libcxx=libstdc++11 -s build_type=Debug -o Boost:fPIC=True)
else()
set(CONAN_OPTIONS
-s compiler=gcc -s compiler.libcxx=libstdc++11 -s build_type=Release -o Boost:fPIC=True)
endif()
elseif(FIPS_CLANG)
string(REGEX REPLACE "([0-9]+\\.[0-9]+).*" "\\1" CLANG_MAJOR_MINOR_VERSION ${CMAKE_CXX_COMPILER_VERSION})
if (CMAKE_BUILD_TYPE STREQUAL "Debug")
set(CONAN_OPTIONS
-s compiler=clang -s compiler.version=${CLANG_MAJOR_MINOR_VERSION} -s compiler.libcxx=libstdc++11 -s build_type=Debug -o Boost:fPIC=True)
else()
set(CONAN_OPTIONS
-s compiler=clang -s compiler.version=${CLANG_MAJOR_MINOR_VERSION} -s compiler.libcxx=libstdc++11 -s build_type=Release -o Boost:fPIC=True)
endif()
endif()
execute_process(
COMMAND conan install ${PROJECT_SOURCE_DIR} ${CONAN_OPTIONS} -e CONAN_IMPORT_PATH=${FIPS_PROJECT_DEPLOY_DIR} --build missing
Expand Down Expand Up @@ -103,6 +112,8 @@ elseif(FIPS_MSVC)
add_definitions(/D_CRT_SECURE_NO_WARNINGS)
# Also suppress linker warnings about missing .pdb files that seem to inevitably creep in.
add_link_options(/ignore:4099)
elseif(FIPS_CLANG)
add_compile_options(-v)
endif()

# Enable "big objects" for Visual C++ and try to speed up builds.
Expand All @@ -112,10 +123,10 @@ if(FIPS_MSVC)
endif()

# Set build options for instrumenting test coverage.
if(FIPS_GCC AND CMAKE_BUILD_TYPE STREQUAL "Debug")
if(FIPS_CLANG AND CMAKE_BUILD_TYPE STREQUAL "Debug")
message(STATUS "Enabling gcov support")
add_compile_options(--coverage -fno-inline -fno-inline-small-functions -fno-default-inline -fprofile-arcs -ftest-coverage)
add_exe_link_options(--coverage)
add_compile_options(-DLLVM_USE_LINKER=gold -fprofile-instr-generate -fcoverage-mapping)
add_exe_link_options(-fprofile-instr-generate -fcoverage-mapping)
endif()

# Add the alia library.
Expand Down Expand Up @@ -186,15 +197,12 @@ add_custom_target(

# On Linux debug builds, the proper CMake test associated with the unit tests
# includes test coverage reporting.
if(FIPS_GCC AND CMAKE_BUILD_TYPE STREQUAL "Debug")
if(FIPS_CLANG AND CMAKE_BUILD_TYPE STREQUAL "Debug")
add_custom_target(
unit_test_coverage
COMMAND lcov -c -i -d . -o baseline.info
COMMAND ${CMAKE_COMMAND} --build . --target unit_tests
COMMAND lcov -c -d . -o raw.info
COMMAND lcov -a baseline.info -a raw.info -o ${PROJECT_BINARY_DIR}/combined.info
COMMAND lcov -e combined.info '${PROJECT_SOURCE_DIR}/src/alia/*' -o filtered.info
COMMAND ${CMAKE_COMMAND} -E copy filtered.info ${PROJECT_SOURCE_DIR}/lcov.info
COMMAND llvm-profdata-${CLANG_MAJOR_MINOR_VERSION} merge -sparse unit-testing/default.profraw -o default.profdata
COMMAND llvm-cov-4.0 show -instr-profile=default.profdata ${FIPS_PROJECT_DEPLOY_DIR}/unit_test_runner >${PROJECT_SOURCE_DIR}/coverage.txt
WORKING_DIRECTORY ${PROJECT_BINARY_DIR})
add_test(
NAME unit_test_coverage
Expand Down
2 changes: 1 addition & 1 deletion scripts/set-up-system.sh
Original file line number Diff line number Diff line change
Expand Up @@ -8,5 +8,5 @@ apt-get update -qy
apt-get install -y software-properties-common
add-apt-repository -y ppa:ubuntu-toolchain-r/test
apt-get update -qy
apt-get install -y --upgrade g++-5 gcc-5 lcov cmake git curl
apt-get install -y --upgrade g++-5 gcc-5 lcov cmake git curl clang-5.0
pip install virtualenv
126 changes: 3 additions & 123 deletions src/alia/common.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -179,9 +179,9 @@ struct noncopyable
}

private:
noncopyable(noncopyable const& other);
noncopyable(noncopyable const& other) = delete;
noncopyable&
operator=(noncopyable const& other);
operator=(noncopyable const& other) = delete;
};
} // namespace noncopyable_
} // namespace impl
Expand Down Expand Up @@ -215,130 +215,10 @@ struct exception : std::exception
std::shared_ptr<string> msg_;
};

// vector<N,T> represents an N-dimensional geometric vector with elements of
// type T.
template<unsigned N, class T>
struct vector
{
// allow external access to template parameters
typedef T value_type;
static const unsigned dimensionality = N;

// element accessors
T operator[](unsigned i) const
{
assert(i < N);
return elements[i];
}
T& operator[](unsigned i)
{
assert(i < N);
return elements[i];
}

vector()
{
}

// explicit conversion from vectors with other element types
template<class OtherT>
explicit vector(vector<N, OtherT> const& other)
{
for (unsigned i = 0; i < N; ++i)
(*this)[i] = static_cast<T>(other[i]);
}

private:
T elements[N];
};
// 2D constructor
template<class T>
vector<2, T>
make_vector(T x, T y)
{
vector<2, T> v;
v[0] = x;
v[1] = y;
return v;
}
// 3D constructor
template<class T>
vector<3, T>
make_vector(T x, T y, T z)
{
vector<3, T> v;
v[0] = x;
v[1] = y;
v[2] = z;
return v;
}
// equality operators
namespace impl {
template<unsigned N, class T, unsigned I>
struct vector_equality_test
{
static bool
apply(vector<N, T> const& a, vector<N, T> const& b)
{
return a[I - 1] == b[I - 1]
&& vector_equality_test<N, T, I - 1>::apply(a, b);
}
};
template<unsigned N, class T>
struct vector_equality_test<N, T, 0>
{
static bool
apply(vector<N, T> const& a, vector<N, T> const& b)
{
return true;
}
};
} // namespace impl
template<unsigned N, class T>
bool
operator==(vector<N, T> const& a, vector<N, T> const& b)
{
return impl::vector_equality_test<N, T, N>::apply(a, b);
}
template<unsigned N, class T>
bool
operator!=(vector<N, T> const& a, vector<N, T> const& b)
{
return !(a == b);
}
// < operator
template<unsigned N, class T>
bool
operator<(vector<N, T> const& a, vector<N, T> const& b)
{
for (unsigned i = 0; i < N; ++i)
{
if (a[i] < b[i])
return true;
if (b[i] < a[i])
return false;
}
return false;
}
// streaming
template<unsigned N, class T>
std::ostream&
operator<<(std::ostream& out, vector<N, T> const& v)
{
out << "(";
for (unsigned i = 0; i != N; ++i)
{
if (i != 0)
out << ", ";
out << v[i];
}
out << ")";
return out;
}

// optional<T> stores an optional value of type T (or no value).
struct none_type
{
none_type() {}
};
static none_type const none;
template<class T>
Expand Down

0 comments on commit 4f29591

Please sign in to comment.