Skip to content

Commit

Permalink
Add tests for OpenMP variant
Browse files Browse the repository at this point in the history
  • Loading branch information
GabTux committed Mar 27, 2024
1 parent 60333f3 commit 9037fb5
Show file tree
Hide file tree
Showing 4 changed files with 70 additions and 7 deletions.
42 changes: 36 additions & 6 deletions .github/workflows/tests.yml
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ on:
- main

env:
CTEST_OUTPUT_ON_FAILURE: 1
CTEST_OUTPUT_ON_ FAILURE: 1
CODECOV_TOKEN: ${{ secrets.CODECOV_TOKEN }}
CPM_SOURCE_CACHE: ${{ github.workspace }}/cpm_modules

Expand All @@ -27,16 +27,46 @@ jobs:
path: "**/cpm_modules"
key: ${{ github.workflow }}-cpm-modules-${{ hashFiles('**/CMakeLists.txt', '**/*.cmake') }}

- name: configure
- name: configure (cpp variant)
run: cmake -Stest -Bbuild -DENABLE_TEST_COVERAGE=1 -DCMAKE_BUILD_TYPE=Debug

- name: build
- name: build (cpp variant)
run: cmake --build build -j4

- name: test
- name: test (cpp variant)
run: |
cd build
ctest --build-config Debug
- name: collect code coverage
run: bash <(curl -s https://codecov.io/bash) || echo "Codecov did not collect coverage reports"
- name: collect code coverage (cpp variant)
run: bash <(curl -s https://codecov.io/bash) || echo "Codecov did not collect coverage reports"

build_openmp:
runs-on: ubuntu-latest

steps:
- uses: actions/checkout@v2

- uses: actions/cache@v2
with:
path: "**/cpm_modules"
key: ${{ github.workflow }}-cpm-modules-${{ hashFiles('**/CMakeLists.txt', '**/*.cmake') }}

- name: configure (OpenMP variant)
run: cmake -Stest -Bbuild_openmp -DENABLE_TEST_COVERAGE=1 -DCMAKE_BUILD_TYPE=Debug -DOPENMP_VARIANT=ON

- name: build (OpenMP variant)
run: cmake --build build_openmp -j4

- name: test (OpenMP variant)
run: |
cd build_openmp
ctest --build-config Debug
- name: collect code coverage (OpenMP variant)
run: bash <(curl -s https://codecov.io/bash) || echo "Codecov did not collect coverage reports"

- name: collect code coverage (combined)
run: |
coverage combine build/coverage.xml build_openmp/coverage.xml -o coverage.merged.xml
bash <(curl -s https://codecov.io/bash -f coverage.merged.xml) || echo "Codecov did not collect coverage reports"
15 changes: 15 additions & 0 deletions test/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,21 @@ if(NOT TEST_INSTALLED_VERSION)
endif()
endif()

option(OPENMP_VARIANT "Use OpenMP variant" OFF)

if(OPENMP_VARIANT)
find_package(OpenMP)
if(OpenMP_CXX_FOUND)
target_link_libraries(${PROJECT_NAME} OpenMP::OpenMP_CXX)
target_compile_definitions(${PROJECT_NAME} PRIVATE PPQSORT_OPENMP)
message("Using OpenMP version")
else()
message(WARNING "OpenMP not found, using C++ version")
endif()
else()
message("Using C++ version")
endif()

# ---- Add PPQSortTests ----

enable_testing()
Expand Down
16 changes: 16 additions & 0 deletions test/source/ppqsort.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -87,6 +87,21 @@ TEST(StaticInputs, EmptyContainer) {
ASSERT_THAT(in, ::testing::ContainerEq(std::vector<int>{}));
}

#ifdef _OPENMP

TEST(StaticInputs, TriggerSeqPartition) {
std::vector<int> in = {52, 0, 5, 1, 2, 3, 45, 8, 1, 10,
52, 0, 5, 1, 2, 3, 45, 8, 1, 10};
std::vector ref(in);
auto res = ppqsort::impl::openmp::partition_right_branchless_par(in.begin(), in.end(), std::less<>(), 4);
auto pivot = *res.first;
ASSERT_TRUE(std::is_partitioned(in.begin(), in.end(), [&](const int & i){ return i < pivot;}));
res = ppqsort::impl::openmp::partition_to_right_par(in.begin(), in.end(), std::less<>(), 4);
pivot = *res.first;
ASSERT_TRUE(std::is_partitioned(in.begin(), in.end(), [&](const int & i){ return i < pivot;}));
}

#else
TEST(StaticInputs, TriggerSeqPartition) {
std::vector<int> in = {52, 0, 5, 1, 2, 3, 45, 8, 1, 10,
52, 0, 5, 1, 2, 3, 45, 8, 1, 10};
Expand All @@ -99,6 +114,7 @@ TEST(StaticInputs, TriggerSeqPartition) {
pivot = *res.first;
ASSERT_TRUE(std::is_partitioned(in.begin(), in.end(), [&](const int & i){ return i < pivot;}));
}
#endif


TEST(Patterns, Ascending) {
Expand Down
4 changes: 3 additions & 1 deletion test/source/thread_pool.cpp
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
#ifndef _OPENMP

/****************************************************
* ThreadPool Tests
Expand Down Expand Up @@ -167,4 +168,5 @@ namespace ppqsort::impl::cpp {
ASSERT_EQ(stack.try_pop().value(), 2);
ASSERT_EQ(stack.try_pop().value(), 1);
}
}
}
#endif

0 comments on commit 9037fb5

Please sign in to comment.