Skip to content

Commit

Permalink
New coverage build (LLNL#252)
Browse files Browse the repository at this point in the history
* add github actions for code coverage

* remove circle-ci coverage build

* [pre-commit.ci] auto fixes from pre-commit.com hooks

for more information, see https://pre-commit.ci

* fix circle ci config

* try to fix coverage builds

* try to fix some of the builds

* fix bug with 64 bit unit type, and C++17 or higher with unit string conversions

* fix clang-tidy issue

Co-authored-by: pre-commit-ci[bot] <66853113+pre-commit-ci[bot]@users.noreply.github.com>
  • Loading branch information
phlptp and pre-commit-ci[bot] authored Dec 12, 2022
1 parent 296dab0 commit 43d6658
Show file tree
Hide file tree
Showing 7 changed files with 148 additions and 32 deletions.
48 changes: 24 additions & 24 deletions .circleci/config.yml
Original file line number Diff line number Diff line change
Expand Up @@ -36,21 +36,21 @@ aliases:
make install
ctest -V -R find-package-tests
- &run_coverage
name: run_code_coverage
command: |
mkdir -p build
cd build
cmake ..
eval cmake .. -DCMAKE_BUILD_TYPE=Coverage ${CMAKE_FLAGS}
make -j 4
eval cmake --build . --target UNITS_coverage
ctest --output-on-failure
lcov --directory . --capture --output-file coverage.info # capture coverage info
lcov --remove coverage.info '*/tests/*' '*/examples/*' '*gtest*' '*gmock*' '/usr/*' --output-file coverage.info # filter out system
lcov --list coverage.info #debug info
# Uploading report to CodeCov
bash <(curl -s https://codecov.io/bash) || echo "Codecov did not collect coverage reports"
#- &run_coverage
# name: run_code_coverage
# command: |
# mkdir -p build
# cd build
# cmake ..
# eval cmake .. -DCMAKE_BUILD_TYPE=Coverage ${CMAKE_FLAGS}
# make -j 4
# eval cmake --build . --target UNITS_coverage
# ctest --output-on-failure
# lcov --directory . --capture --output-file coverage.info # capture coverage info
# lcov --remove coverage.info '*/tests/*' '*/examples/*' '*gtest*' '*gmock*' '/usr/*' --output-file coverage.info # filter out system
# lcov --list coverage.info #debug info
# Uploading report to CodeCov
# bash <(curl -s https://codecov.io/bash) || echo "Codecov did not collect coverage reports"

jobs:
unitsTSan:
Expand Down Expand Up @@ -111,14 +111,14 @@ jobs:
- checkout
- run: *setup_units
- run: *run_installer_tests
unitsCoverage:
docker:
- image: helics/buildenv:gcc7-coverage
environment:
CMAKE_FLAGS: '-DUNITS_ENABLE_TESTS=ON -DCMAKE_CXX_STANDARD=14'
steps:
- checkout
- run: *run_coverage
#unitsCoverage:
# docker:
# - image: helics/buildenv:gcc7-coverage
# environment:
# CMAKE_FLAGS: '-DUNITS_ENABLE_TESTS=ON -DCMAKE_CXX_STANDARD=14'
# steps:
# - checkout
# - run: *run_coverage

workflows:
version: 2
Expand All @@ -129,4 +129,4 @@ workflows:
- unitsTSan
- unitsInstall
- unitsFuzz
- unitsCoverage
# - unitsCoverage
65 changes: 65 additions & 0 deletions .github/workflows/coverage.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,65 @@
name: Tests
on:
push:
branches:
- main
- v*
pull_request:

concurrency:
group: ${{ github.workflow }}-${{ github.ref }}
cancel-in-progress: true

jobs:
coverage:
name: Coverage
runs-on: ubuntu-latest
strategy:
matrix:
std: ["11", "14", "17", "20"]
unitBase: ["uint64_t", "uint32_t"]
steps:
- uses: actions/checkout@v3
with:
fetch-depth: 0

- name: Get LCov
run: |
wget https://github.com/linux-test-project/lcov/releases/download/v1.16/lcov-1.16.tar.gz
tar -xzf lcov-1.16.tar.gz
cd lcov-1.16
sudo make install
- name: Configure
run: |
cmake -S . -B build \
-DCMAKE_CXX_STANDARD=${{matrix.std}} \
-DUNITS_ENABLE_TESTS=ON \
-DUNITS_BASE_TYPE=${{matrix.unitBase}} \
-DCMAKE_BUILD_TYPE=Coverage
- name: Build
run: cmake --build build -j4

- name: Test
run: |
cd build
ctest --output-on-failure
- name: Prepare coverage
run: |
lcov --directory . --capture --output-file coverage.info
lcov --remove coverage.info '*/tests/*' '*/examples/*' '*gtest*' '*gmock*' '/usr/*' --output-file coverage.info
lcov --list coverage.info
working-directory: build

- uses: codecov/codecov-action@v3
with:
files: build/coverage.info
fail_ci_if_error: true
functionalities: fixes





10 changes: 8 additions & 2 deletions .github/workflows/tests.yml
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ on:
jobs:
cmake-config:
name: CMake config check
runs-on: ubuntu-latest
runs-on: ubuntu-20.04
steps:
- uses: actions/checkout@v3

Expand Down Expand Up @@ -127,9 +127,15 @@ jobs:
with:
cmake-version: "3.22"
if: success() || failure()

- name: Check CMake 3.23 (full)
uses: ./.github/actions/quick_cmake
with:
cmake-version: "3.23"
if: success() || failure()

- name: Check CMake 3.24 (full)
uses: ./.github/actions/quick_cmake
with:
cmake-version: "3.24"
if: success() || failure()
3 changes: 2 additions & 1 deletion test/test_measurement_strings.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -121,7 +121,8 @@ TEST(MeasurementToString, case_sensitive)
precise_measurement case_sensitive_plural =
measurement_from_string(plural);
// true
EXPECT_TRUE(case_sensitive_plural.units().has_same_base(up.first));
EXPECT_TRUE(case_sensitive_plural.units().has_same_base(up.first))
<< "error with " << up.second;
precise_measurement case_sensitive_singular =
measurement_from_string(singular);
EXPECT_TRUE(case_sensitive_singular.units().has_same_base(up.first));
Expand Down
20 changes: 18 additions & 2 deletions units/unit_definitions.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -1632,11 +1632,21 @@ namespace detail {
template<typename UX, typename UX2>
double convertTemperature(double val, const UX& start, const UX2& result)
{
static constexpr std::array<double, 30> biasTable{
0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0,
0.0, 0.0, 0.0, 0.0, 121.0, 0.0, 0.0, 0.0, 0.0, 0.0,
0.0, 0.0, 0.0, 0.0, 0.0, 150.0, 0.0, 37.7778, 0.0, 0.0};

if (is_temperature(start)) {
if (units::degF == unit_cast(start)) {
val = (val - 32.0) * 5.0 / 9.0;
} else if (start.multiplier() != 1.0) {
val = val * start.multiplier();
if (start.multiplier() < 29.5 && start.multiplier() >= 0.0) {
val = val * start.multiplier() +
biasTable[static_cast<int>(start.multiplier())];
} else {
val = val * start.multiplier();
}
}
val += 273.15;
// convert to K
Expand All @@ -1649,7 +1659,13 @@ namespace detail {
val *= 9.0 / 5.0;
val += 32.0;
} else if (result.multiplier() != 1.0) {
val = val / result.multiplier();
if (result.multiplier() < 25.5 && result.multiplier() >= 0.0) {
val = (val -
biasTable[static_cast<int>(start.multiplier())]) /
result.multiplier();
} else {
val = val / result.multiplier();
}
}
return val;
}
Expand Down
10 changes: 8 additions & 2 deletions units/units.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -374,14 +374,14 @@ static std::string generateUnitSequence(double mux, std::string seq)
#ifdef UNITS_CONSTEXPR_IF_SUPPORTED
if constexpr (
detail::bitwidth::base_size == sizeof(std::uint32_t)) {
pw = seq[pwerloc + 1] - '0';
} else {
if (seq.size() <= pwerloc + 2 ||
!isDigitCharacter(seq[pwerloc + 2])) {
pw = seq[pwerloc + 1] - '0';
} else {
pw = 10;
}
} else {
pw = 10;
}
#else
if (detail::bitwidth::base_size == sizeof(std::uint32_t) ||
Expand Down Expand Up @@ -2832,7 +2832,13 @@ static const std::unordered_map<std::uint64_t, precise_unit> domainSpecificUnit{
{hashGen(domains::cooking, "C"), precise::us::cup},
{hashGen(domains::cooking, "T"), precise::us::tbsp},
{hashGen(domains::cooking, "c"), precise::us::cup},
{hashGen(domains::cooking, "smi"),
precise_unit(1.0 / 32.0, precise::us::tsp)},
{hashGen(domains::cooking, "scruple"),
precise_unit(1.0 / 4.0, precise::us::tsp)},
{hashGen(domains::cooking, "t"), precise::us::tsp},
{hashGen(domains::cooking, "ds"),
precise_unit(1.0 / 16.0, precise::us::tsp)},
{hashGen(domains::cooking, "TB"), precise::us::tbsp},
{hashGen(domains::surveying, "'"), precise::us::foot},
{hashGen(domains::surveying, "`"), precise::us::foot},
Expand Down
24 changes: 23 additions & 1 deletion units/units_conversion_maps.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -1426,7 +1426,7 @@ UNITS_CPP14_CONSTEXPR_OBJECT std::array<

UNITS_CPP14_CONSTEXPR_OBJECT std::array<
std::pair<const char*, precise_unit>,
995>
1016>
defined_unit_strings_customary{
{{"candle", precise::other::candle},
{"candlepower", precise::other::candle},
Expand Down Expand Up @@ -1721,6 +1721,14 @@ UNITS_CPP14_CONSTEXPR_OBJECT std::array<
{"degRankine", precise::temperature::degR},
{"degrankine", precise::temperature::degR},
{"rankine", precise::temperature::degR},
// gas oven temperature conversions
{"gasmark", {14.0, precise::temperature::degC}},
{"gas", {14.0, precise::temperature::degC}},
{"regulomark", {14.0, precise::temperature::degC}},
{"regulo", {14.0, precise::temperature::degC}},
{"stufe", {25.0, precise::temperature::degC}},
{"Thermostat", {27.77778, precise::temperature::degC}},
{"Th", {27.77778, precise::temperature::degC}},
{"oF", precise::degF},
// this is two strings since F could be interpreted as hex and I don't
// want it to be
Expand Down Expand Up @@ -2301,9 +2309,23 @@ UNITS_CPP14_CONSTEXPR_OBJECT std::array<
{"tablespoon", precise::us::tbsp},
{"tablespoon_us", precise::us::tbsp},
{"smidgen", precise_unit(1.0 / 32.0, precise::us::tsp)},
{"smdg", precise_unit(1.0 / 32.0, precise::us::tsp)},
{"pinch", precise_unit(1.0 / 24.0, precise::us::tsp)},
{"pn", precise_unit(1.0 / 24.0, precise::us::tsp)},
{"dash", precise_unit(1.0 / 16.0, precise::us::tsp)},
{"tad", precise_unit(1.0 / 8.0, precise::us::tsp)},
{"saltspoon", precise_unit(1.0 / 4.0, precise::us::tsp)},
{"ssp", precise_unit(1.0 / 4.0, precise::us::tsp)},
{"coffeespoon", precise_unit(1.0 / 2.0, precise::us::tsp)},
{"csp", precise_unit(1.0 / 2.0, precise::us::tsp)},
{"dessertspoon", precise_unit(2.0, precise::us::tsp)},
{"dsp", precise_unit(2.0, precise::us::tsp)},
{"dssp", precise_unit(2.0, precise::us::tsp)},
{"dstspn", precise_unit(2.0, precise::us::tsp)},
{"wineglass", precise_unit(1.0 / 4.0, precise::us::cup)},
{"wgf", precise_unit(1.0 / 4.0, precise::us::cup)},
{"teacup", precise_unit(1.0 / 2.0, precise::us::cup)},
{"tcf", precise_unit(1.0 / 2.0, precise::us::cup)},
{"cup_m", precise::metric::cup},
{"[CUP_M]", precise::metric::cup_uslegal},
{"[cup_m]", precise::metric::cup_uslegal}, // ucum definitions I think
Expand Down

0 comments on commit 43d6658

Please sign in to comment.