Skip to content

Commit 47b8fdd

Browse files
Adding code coverage (#2148)
* First stab at adding coverage tests Signed-off-by: Spencer Wilson <[email protected]> * Install dependencies for coveralls action Signed-off-by: Spencer Wilson <[email protected]> * Integrate code coverage into CI Signed-off-by: Spencer Wilson <[email protected]> * Properly parallelize Signed-off-by: Spencer Wilson <[email protected]> * Refine test coverage Signed-off-by: Spencer Wilson <[email protected]> * Ignore unused exclude path error Signed-off-by: Spencer Wilson <[email protected]> * Update exclude path Signed-off-by: Spencer Wilson <[email protected]> * Fix Markdown formatting Signed-off-by: Spencer Wilson <[email protected]> * Pin dependencies Signed-off-by: Spencer Wilson <[email protected]> * Update workflow badge path Signed-off-by: Aiden Fox Ivey <[email protected]> * Fix path in CI.md Signed-off-by: Aiden Fox Ivey <[email protected]> * Remove unnecessary call to install curl Signed-off-by: Aiden Fox Ivey <[email protected]> --------- Signed-off-by: Spencer Wilson <[email protected]> Signed-off-by: Aiden Fox Ivey <[email protected]> Co-authored-by: Spencer Wilson <[email protected]>
1 parent 6218d54 commit 47b8fdd

File tree

9 files changed

+99
-3
lines changed

9 files changed

+99
-3
lines changed

.CMake/compiler_opts.cmake

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -113,6 +113,10 @@ if(CMAKE_C_COMPILER_ID MATCHES "Clang")
113113
if(${OQS_DEBUG_BUILD})
114114
add_compile_options(-g3)
115115
add_compile_options(-fno-omit-frame-pointer)
116+
if(${USE_COVERAGE})
117+
add_compile_options(-coverage)
118+
add_link_options(-coverage)
119+
endif()
116120
if(USE_SANITIZER STREQUAL "Address")
117121
add_compile_options(-fno-optimize-sibling-calls)
118122
add_compile_options(-fsanitize-address-use-after-scope)
@@ -175,6 +179,10 @@ elseif(CMAKE_C_COMPILER_ID STREQUAL "GNU")
175179
if(${OQS_DEBUG_BUILD})
176180
add_compile_options (-Wstrict-overflow)
177181
add_compile_options(-ggdb3)
182+
if(${USE_COVERAGE})
183+
add_compile_options(-coverage)
184+
add_link_options(-coverage)
185+
endif()
178186
else()
179187
add_compile_options(-O3)
180188
add_compile_options(-fomit-frame-pointer)

.github/workflows/code-coverage.yml

Lines changed: 60 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,60 @@
1+
name: Code coverage tests
2+
3+
permissions:
4+
contents: read
5+
6+
on: [workflow_call, workflow_dispatch]
7+
8+
jobs:
9+
coverage:
10+
name: Run code coverage testing
11+
strategy:
12+
matrix:
13+
# The 'id' value for each job should be added to the 'carry-forward' string in the 'finish' job.
14+
include:
15+
- id: x64-generic
16+
runner: ubuntu-latest
17+
CMAKE_ARGS: -DOQS_DIST_BUILD=OFF -DOQS_OPT_TARGET=generic
18+
- id: x64-distbuild
19+
runner: ubuntu-latest
20+
CMAKE_ARGS: -DOQS_DIST_BUILD=ON
21+
- id: arm64-distbuild
22+
runner: ubuntu-24.04-arm
23+
CMAKE_ARGS: -DOQS_DIST_BUILD=ON
24+
runs-on: ${{ matrix.runner }}
25+
container: openquantumsafe/ci-ubuntu-latest:latest
26+
steps:
27+
- name: Checkout code
28+
uses: actions/checkout@692973e3d937129bcbf40652eb9f2f61becf3332 # pin@v4
29+
- name: Configure
30+
run: |
31+
mkdir build && cd build && \
32+
cmake -GNinja -DCMAKE_BUILD_TYPE=Debug -DUSE_COVERAGE=ON ${{ matrix.CMAKE_ARGS }} .. && \
33+
cmake -LA -N ..
34+
- name: Build
35+
run: ninja
36+
working-directory: build
37+
- name: Run tests
38+
run: |
39+
python3 -m pytest --verbose --numprocesses=auto \
40+
tests/test_acvp_vectors.py \
41+
tests/test_cmdline.py \
42+
tests/test_kat.py
43+
- name: Run lcov
44+
run: lcov -d . -c -o lcov.info --exclude /usr/lib,/usr/include --ignore-errors unused
45+
- name: Upload to coveralls.io
46+
uses: coverallsapp/github-action@648a8eb78e6d50909eff900e4ec85cab4524a45b # [email protected]
47+
with:
48+
flag-name: ${{ matrix.id }}
49+
parallel: true
50+
51+
finish:
52+
needs: coverage
53+
if: ${{ always() }}
54+
runs-on: ubuntu-latest
55+
steps:
56+
- name: Finish coveralls.io
57+
uses: coverallsapp/github-action@648a8eb78e6d50909eff900e4ec85cab4524a45b # [email protected]
58+
with:
59+
parallel-finished: true
60+
carry-forward: "x64-generic,x64-distbuild,arm64-distbuild"

.github/workflows/commit-to-main.yml

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,10 @@ jobs:
1212
platform-tests:
1313
uses: ./.github/workflows/platforms.yml
1414

15+
code-coverage:
16+
uses: ./.github/workflows/code-coverage.yml
17+
secrets: inherit
18+
1519
scorecard:
1620
uses: ./.github/workflows/scorecard.yml
1721
secrets: inherit

.github/workflows/pr.yml

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,11 @@ jobs:
1818
needs: basic-checks
1919
uses: ./.github/workflows/platforms.yml
2020

21+
code-coverage:
22+
needs: basic-checks
23+
uses: ./.github/workflows/code-coverage.yml
24+
secrets: inherit
25+
2126
scorecard:
2227
needs: basic-checks
2328
uses: ./.github/workflows/scorecard.yml

CI.md

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -26,12 +26,12 @@ For example, "[full tests] [trigger downstream]" will trigger both the platform
2626
#### <a name="pr.yml"></a> Pull request workflow (`pr.yml`)
2727

2828
This workflow runs on pull requests.
29-
It calls [basic checks](#basic.yml), [platform tests](#platforms.yml) and [scorecard analysis](#scorecard.yml).
29+
It calls [basic checks](#basic.yml), [code coverage tests](#code-coverage.yml), [platform tests](#platforms.yml) and [scorecard analysis](#scorecard.yml).
3030

3131
#### <a name="commit-to-main.yml"></a> Commit-to-main workflow (`commit-to-main.yml`)
3232

3333
This workflow runs on pushes to the `main` branch (typically done automatically when a pull request is merged).
34-
It calls [platform tests](#platforms.yml), [scorecard analysis](#scorecard.yml), and [basic downstream tests](#downstream-basic.yml).
34+
It calls [platform tests](#platforms.yml), [code coverage tests](#code-coverage.yml), [scorecard analysis](#scorecard.yml), and [basic downstream tests](#downstream-basic.yml).
3535

3636
#### <a name="weekly.yml"></a> Weekly workflow (`weekly.yml`)
3737

@@ -53,6 +53,10 @@ Users with "write" permissions can also trigger them manually via the GitHub web
5353

5454
This workflow runs a minimal set of tests that should pass before heavier tests are triggered.
5555

56+
#### <a name="code-coverage.yml"></a> Code coverage tests (`code-coverage.yml`)
57+
58+
This workflow runs code coverage tests and uploads the results to [Coveralls.io](https://coveralls.io/github/open-quantum-safe/liboqs).
59+
5660
#### <a name="<platform>.yml"></a> Individual platform tests (`<platform>.yml`)
5761

5862
These workflows contain tests for the individual [platforms supported by liboqs](PLATFORMS.md).

CONFIGURE.md

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@ The following options can be passed to CMake before the build file generation pr
1616
- [OQS_USE_CUPQC](#OQS_USE_CUPQC)
1717
- [OQS_OPT_TARGET](#OQS_OPT_TARGET)
1818
- [OQS_SPEED_USE_ARM_PMU](#OQS_SPEED_USE_ARM_PMU)
19+
- [USE_COVERAGE](#USE_COVERAGE)
1920
- [USE_SANITIZER](#USE_SANITIZER)
2021
- [OQS_ENABLE_TEST_CONSTANT_TIME](#OQS_ENABLE_TEST_CONSTANT_TIME)
2122
- [OQS_STRICT_WARNINGS](#OQS_STRICT_WARNINGS)
@@ -36,7 +37,9 @@ This means liboqs is built as a static library by default.
3637

3738
Can be set to the following values:
3839

39-
- `Debug`: This turns off all compiler optimizations and produces debugging information. When the compiler is Clang, the [USE_SANITIZER](#USE_SANITIZER) option can also be specified to enable a Clang sanitizer. **This value only has effect when the compiler is GCC or Clang**
40+
- `Debug`: This turns off all compiler optimizations and produces debugging information. **This value only has effect when the compiler is GCC or Clang**
41+
- The [USE_COVERAGE](#USE_COVERAGE) option can also be specified to enable code coverage testing.
42+
- When the compiler is Clang, the [USE_SANITIZER](#USE_SANITIZER) option can also be specified to enable a Clang sanitizer.
4043

4144
- `Release`: This compiles code at the `O3` optimization level, and sets other compiler flags that reduce the size of the binary.
4245

@@ -173,6 +176,12 @@ Note that this option is not known to work on Apple M1 chips.
173176

174177
**Default**: `OFF`.
175178

179+
## USE_COVERAGE
180+
181+
This has an effect when the compiler is GCC or Clang and when [CMAKE_BUILD_TYPE](#CMAKE_BUILD_TYPE) is `Debug`. Can be `ON` or `OFF`. When `ON`, code coverage testing will be enabled.
182+
183+
**Default**: Unset.
184+
176185
## USE_SANITIZER
177186

178187
This has an effect when the compiler is Clang and when [CMAKE_BUILD_TYPE](#CMAKE_BUILD_TYPE) is `Debug`. Then, it can be set to:

README.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@ liboqs
44
[![Main Branch Tests](https://github.com/open-quantum-safe/liboqs/actions/workflows/commit-to-main.yml/badge.svg)](https://github.com/open-quantum-safe/liboqs/actions/workflows/commit-to-main.yml)
55
[![Weekly Tests](https://github.com/open-quantum-safe/liboqs/actions/workflows/weekly.yml/badge.svg)](https://github.com/open-quantum-safe/liboqs/actions/workflows/weekly.yml)
66
![Travis Build Status](https://img.shields.io/travis/com/open-quantum-safe/liboqs?logo=travis&label=Travis%20CI&labelColor=%23343B42&color=%232EBB4E)
7+
[![Coverage Status](https://coveralls.io/repos/github/open-quantum-safe/liboqs/badge.svg?branch=main)](https://coveralls.io/github/open-quantum-safe/liboqs?branch=main)
78

89
liboqs is an open source C library for quantum-safe cryptographic algorithms.
910

src/oqsconfig.h.cmake

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,7 @@
3030
#cmakedefine BUILD_SHARED_LIBS 1
3131
#cmakedefine OQS_BUILD_ONLY_LIB 1
3232
#cmakedefine OQS_OPT_TARGET "@OQS_OPT_TARGET@"
33+
#cmakedefine USE_COVERAGE 1
3334
#cmakedefine USE_SANITIZER "@USE_SANITIZER@"
3435
#cmakedefine CMAKE_BUILD_TYPE "@CMAKE_BUILD_TYPE@"
3536

tests/system_info.c

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -216,6 +216,7 @@ static void print_oqs_configuration(void) {
216216
* OQS_OPT_TARGET: Visible by looking at compile options (-march or -mcpu):
217217
* 'auto' -> "-march|cpu=native"
218218
* OQS_SPEED_USE_ARM_PMU: Output with Target platform
219+
* USE_COVERAGE: --coverage option present in compile options
219220
* USE_SANITIZER: -fsanitize= option present in compile options
220221
* OQS_ENABLE_TEST_CONSTANT_TIME: only shown below
221222
*/
@@ -273,6 +274,9 @@ static void print_oqs_configuration(void) {
273274
#ifdef OQS_BUILD_ONLY_LIB
274275
printf("OQS_BUILD_ONLY_LIB "); // pretty much impossible to appear but added for completeness
275276
#endif
277+
#ifdef USE_COVERAGE
278+
printf("USE_COVERAGE " );
279+
#endif
276280
#ifdef USE_SANITIZER
277281
printf("USE_SANITIZER=%s ", USE_SANITIZER);
278282
#endif

0 commit comments

Comments
 (0)