Skip to content

Commit 058b3cc

Browse files
authored
Run unit tests with OpenMP in CI (#870)
1 parent d4cb5ee commit 058b3cc

File tree

5 files changed

+56
-20
lines changed

5 files changed

+56
-20
lines changed

.github/actions/linux-build/action.yml

Lines changed: 12 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
name: "Linux Build"
2-
description: "Build the C++ library on Linux."
2+
description: "Build the C++ library on Linux. Produces artifact build-cpp-linux-$compiler-$version-$config."
33
inputs:
44
config:
55
description: "Configuration to build (Release or Debug, see CMAKE_BUILD_TYPE)"
@@ -14,19 +14,19 @@ inputs:
1414
required: true
1515
default: "latest"
1616
optional-dependencies:
17-
description: "Build the library with optional dependencies (ON or OFF)"
17+
description: "Build the library with optional dependencies (ON or OFF, default ON). If OFF, adds `-nodep` to the artifact name"
1818
required: false
1919
default: "ON"
2020
coverage:
21-
description: "Turn coverage on (ON or OFF)"
21+
description: "Turn coverage on (ON or OFF, default OFF)"
2222
required: false
2323
default: "OFF"
2424
sanitize-ub:
25-
description: "Turn on UB sanitzer (ON or OFF)"
25+
description: "Turn on UB sanitzer (ON or OFF, default OFF)"
2626
required: false
2727
default: "OFF"
2828
sanitize-addr:
29-
description: "Turn on address sanitzer (ON or OFF)"
29+
description: "Turn on address sanitzer (ON or OFF, default OFF)"
3030
required: false
3131
default: "OFF"
3232
build-tests:
@@ -37,6 +37,10 @@ inputs:
3737
description: "Build benchmarks"
3838
required: false
3939
default: "OFF"
40+
openmp:
41+
description: "Enable Multithreading with OpenMP (ON or OFF, default OFF). If ON, adds `-omp` to the name of the artifact."
42+
required: false
43+
default: "OFF"
4044
runs:
4145
using: "composite"
4246
steps:
@@ -85,7 +89,7 @@ runs:
8589
exit 1
8690
fi
8791
mkdir -p build && cd build
88-
cmake -DCMAKE_BUILD_TYPE=${{ inputs.config }} -DMEMILIO_BUILD_TESTS=${{ inputs.build-tests }} -DMEMILIO_BUILD_BENCHMARKS=${{ inputs.build-benchmarks }} -DMEMILIO_TEST_COVERAGE=${{ inputs.coverage }} -DMEMILIO_SANITIZE_ADDRESS=${{ inputs.sanitize-addr }} -DMEMILIO_SANITIZE_UNDEFINED=${{ inputs.sanitize-ub }} -DMEMILIO_USE_BUNDLED_JSONCPP=${{ inputs.optional-dependencies }} ..
92+
cmake -DCMAKE_BUILD_TYPE=${{ inputs.config }} -DMEMILIO_BUILD_TESTS=${{ inputs.build-tests }} -DMEMILIO_BUILD_BENCHMARKS=${{ inputs.build-benchmarks }} -DMEMILIO_TEST_COVERAGE=${{ inputs.coverage }} -DMEMILIO_SANITIZE_ADDRESS=${{ inputs.sanitize-addr }} -DMEMILIO_SANITIZE_UNDEFINED=${{ inputs.sanitize-ub }} -DMEMILIO_USE_BUNDLED_JSONCPP=${{ inputs.optional-dependencies }} -DMEMILIO_ENABLE_OPENMP=${{ inputs.openmp }} ..
8993
make -j4
9094
- name: create build dir archive
9195
shell: bash
@@ -95,6 +99,7 @@ runs:
9599
- name: Upload built directory
96100
uses: actions/upload-artifact@v3
97101
with:
98-
name: build-cpp-linux-${{ inputs.compiler }}-${{ inputs.version }}-${{ inputs.config }}-${{ inputs.optional-dependencies == 'ON' && 'full' || 'part'}}
102+
#artifacts in one pipeline must have a different name, so options must add a suffix to the artifact name if different values are used in the same pipeline
103+
name: build-cpp-linux-${{ inputs.compiler }}-${{ inputs.version }}-${{ inputs.config }}${{ inputs.optional-dependencies == 'OFF' && '-nodep' || ''}}${{ inputs.openmp == 'ON' && '-omp' || ''}}
99104
path: cpp/build.tar.gz
100105
retention-days: 1

.github/actions/linux-test/action.yml

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,10 @@ inputs:
88
description: "Create coverage report (ON or OFF)"
99
required: false
1010
default: "OFF"
11+
num-repeat:
12+
description: "Repeat tests, e.g. to catch random failures like race conditions."
13+
required: false
14+
default: "1"
1115
runs:
1216
using: "composite"
1317
steps:
@@ -34,7 +38,7 @@ runs:
3438
run: |
3539
cd cpp/build/bin
3640
sudo chmod a+x memilio-test
37-
./memilio-test --gtest_output="xml:report.xml"
41+
./memilio-test --gtest_output="xml:report.xml" --gtest_repeat=${{ inputs.num-repeat }}
3842
- name: Compute code coverage
3943
shell: bash
4044
# compute code coverage

.github/actions/windows-build/action.yml

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
name: "Build MSVC"
2-
description: "Build memilio c++ library using MSVC on Windows"
2+
description: "Build memilio c++ library using MSVC on Windows. Creates artifact build-windows-msvc-$version-$config."
33
inputs:
44
config:
55
description: "Configuration to build (Release or Debug, see CMAKE_BUILD_TYPE)"
@@ -10,7 +10,7 @@ inputs:
1010
required: true
1111
default: "latest"
1212
optional-dependencies:
13-
description: "Build the library with optional dependencies (ON or OFF)"
13+
description: "Build the library with optional dependencies (ON or OFF). If OFF, adds `-nodep` to the artifact name"
1414
required: false
1515
default: "ON"
1616
runs:
@@ -53,6 +53,7 @@ runs:
5353
- name: Upload built binary files
5454
uses: actions/upload-artifact@v3
5555
with:
56-
name: build-cpp-windows-msvc-${{ inputs.version }}-${{ inputs.config }}-${{ inputs.optional-dependencies == 'ON' && 'full' || 'part'}}
56+
#artifacts in one pipeline must have a different name, so options must add a suffix to the artifact name if different values are used in the same pipeline
57+
name: build-cpp-windows-msvc-${{ inputs.version }}-${{ inputs.config }}${{ inputs.optional-dependencies == 'OFF' && '-nodep' || ''}}
5758
path: cpp/build-win/bin
5859
retention-days: 1

.github/pull_request_template.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@ Please check our [git workflow](https://github.com/SciCompMod/memilio/wiki/git-w
2121
- [ ] Every addressed issue is linked (use the "Closes #ISSUE" keyword below)
2222
- [ ] New code adheres to [coding guidelines](https://github.com/SciCompMod/memilio/wiki/Coding-guidelines)
2323
- [ ] No large data files have been added (files should in sum not exceed 100 KB, avoid PDFs, Word docs, etc.)
24-
- [ ] Tests are added for new functionality and a local test run was successful
24+
- [ ] Tests are added for new functionality and a local test run was successful (with and without OpenMP)
2525
- [ ] Appropriate **documentation** for new functionality has been added (Doxygen in the code and Markdown files if necessary)
2626
- [ ] Proper attention to licenses, especially no new third-party software with conflicting license has been added
2727
- [ ] (For ABM development) Checked [benchmark results](https://github.com/SciCompMod/memilio/wiki/Agent-Based-Model-Development) and ran and posted a local test above from before and after development to ensure performance is monitored.

.github/workflows/main.yml

Lines changed: 34 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -62,6 +62,18 @@ jobs:
6262
config: Release
6363
optional-dependencies: OFF
6464

65+
build-cpp-gcc-openmp:
66+
if: github.event.pull_request.draft == false
67+
runs-on: ubuntu-latest
68+
steps:
69+
- uses: actions/checkout@v3
70+
- uses: ./.github/actions/linux-build
71+
with:
72+
compiler: gcc
73+
version: latest
74+
config: Release
75+
openmp: ON
76+
6577
build-cpp-msvc:
6678
if: github.event.pull_request.draft == false
6779
strategy:
@@ -110,18 +122,32 @@ jobs:
110122
- uses: actions/checkout@v3
111123
- uses: ./.github/actions/linux-test
112124
with:
113-
build-artifact: build-cpp-linux-${{ matrix.compiler }}-${{ matrix.version }}-${{ matrix.config }}-full
125+
build-artifact: build-cpp-linux-${{ matrix.compiler }}-${{ matrix.version }}-${{ matrix.config }}
114126
coverage: ${{ (matrix.compiler == 'gcc' && matrix.version == 'latest' && matrix.config == 'Debug') && 'ON' || 'OFF' }}
115127

116-
test-linux-no-optional-deps:
128+
test-cpp-gcc-no-optional-deps:
117129
if: github.event.pull_request.draft == false
118130
needs: build-cpp-gcc-no-optional-deps
119131
runs-on: ubuntu-latest
120132
steps:
121133
- uses: actions/checkout@v3
122134
- uses: ./.github/actions/linux-test
123135
with:
124-
build-artifact: build-cpp-linux-gcc-latest-Release-part
136+
build-artifact: build-cpp-linux-gcc-latest-Release-nodep
137+
138+
test-cpp-gcc-openmp:
139+
if: github.event.pull_request.draft == false
140+
needs: build-cpp-gcc-openmp
141+
runs-on: ubuntu-latest
142+
timeout-minutes: 30
143+
env:
144+
OMP_NUM_THREADS: 4
145+
steps:
146+
- uses: actions/checkout@v3
147+
- uses: ./.github/actions/linux-test
148+
with:
149+
build-artifact: build-cpp-linux-gcc-latest-Release-omp
150+
num-repeat: 10
125151

126152
test-cpp-msvc:
127153
if: github.event.pull_request.draft == false
@@ -140,17 +166,17 @@ jobs:
140166
- uses: actions/checkout@v3
141167
- uses: ./.github/actions/windows-test
142168
with:
143-
build-artifact: build-cpp-windows-msvc-${{ matrix.version }}-${{ matrix.config }}-full
169+
build-artifact: build-cpp-windows-msvc-${{ matrix.version }}-${{ matrix.config }}
144170

145-
test-windows-no-optional-deps:
171+
test-cpp-msvc-no-optional-deps:
146172
if: github.event.pull_request.draft == false
147173
needs: build-cpp-msvc-no-optional-deps
148174
runs-on: windows-latest
149175
steps:
150176
- uses: actions/checkout@v3
151177
- uses: ./.github/actions/windows-test
152178
with:
153-
build-artifact: build-cpp-windows-msvc-latest-Release-part
179+
build-artifact: build-cpp-windows-msvc-latest-Release-nodep
154180

155181
run_examples-cpp-gcc_clang:
156182
if: github.event.pull_request.draft == false
@@ -170,7 +196,7 @@ jobs:
170196
- uses: actions/checkout@v3
171197
- uses: ./.github/actions/linux-run_examples
172198
with:
173-
build-artifact: build-cpp-linux-${{ matrix.compiler }}-${{ matrix.version }}-${{ matrix.config }}-full
199+
build-artifact: build-cpp-linux-${{ matrix.compiler }}-${{ matrix.version }}-${{ matrix.config }}
174200

175201
run_examples-cpp-msvc:
176202
if: github.event.pull_request.draft == false
@@ -189,7 +215,7 @@ jobs:
189215
- uses: actions/checkout@v3
190216
- uses: ./.github/actions/windows-run_examples
191217
with:
192-
build-artifact: build-cpp-windows-msvc-${{ matrix.version }}-${{ matrix.config }}-full
218+
build-artifact: build-cpp-windows-msvc-${{ matrix.version }}-${{ matrix.config }}
193219

194220
build-py-generation:
195221
if: github.event.pull_request.draft == false

0 commit comments

Comments
 (0)