Skip to content

Commit 742b832

Browse files
authored
Ensure C++ user compatibility (#57)
* Initial use of clang for CI testing * Fixing some clang compatibility problems * Fixing C++ user compatibility problems * Disambiguate all testing from unit testing * Disambiguate coverage logging from testing * Found actual crash and OOM behavior with invalid bundle and EID inputs
1 parent d926f2a commit 742b832

38 files changed

Lines changed: 606 additions & 160 deletions

.github/workflows/build-test.yaml

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -82,9 +82,10 @@ jobs:
8282
- name: Dependencies
8383
run: ./build.sh deps
8484
- name: Prep
85-
run: |
86-
./build.sh prep \
87-
-DBUILD_DOCS_API=OFF -DBUILD_DOCS_MAN=OFF -DBUILD_TESTING=ON
85+
run: >
86+
./build.sh prep
87+
-DBUILD_DOCS_API=OFF -DBUILD_DOCS_MAN=OFF
88+
-DBUILD_UNITTEST=ON -DBUILD_COVERAGE=ON
8889
- name: Build
8990
run: ./build.sh
9091
- name: Install
@@ -153,7 +154,10 @@ jobs:
153154
- name: Dependencies
154155
run: ./build.sh deps
155156
- name: Prep
156-
run: ./build.sh prep -DBUILD_DOCS_API=OFF -DBUILD_DOCS_MAN=OFF -DBUILD_TESTING=ON
157+
run: >
158+
./build.sh prep
159+
-DBUILD_DOCS_API=OFF -DBUILD_DOCS_MAN=OFF
160+
-DBUILD_UNITTEST=OFF -DBUILD_COVERAGE=ON
157161
- name: Build
158162
run: ./build.sh
159163
- name: Install

.github/workflows/codeql.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -88,7 +88,7 @@ jobs:
8888
cmake ninja-build ruby build-essential \
8989
libssl-dev libjansson-dev
9090
./build.sh deps
91-
./build.sh prep -DTEST_MEMCHECK=OFF -DTEST_COVERAGE=OFF -DBUILD_DOCS_API=OFF -DBUILD_DOCS_MAN=OFF
91+
./build.sh prep -DTEST_MEMCHECK=OFF -DBUILD_COVERAGE=OFF -DBUILD_DOCS_API=OFF -DBUILD_DOCS_MAN=OFF
9292
9393
# Initializes the CodeQL tools for scanning.
9494
- name: Initialize CodeQL

.github/workflows/docs.yaml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -55,7 +55,7 @@ jobs:
5555
- name: Prep
5656
run: >
5757
./build.sh prep
58-
-DBUILD_TESTING=OFF -DTEST_MEMCHECK=OFF -DTEST_COVERAGE=OFF
58+
-DBUILD_TESTING=OFF -DTEST_MEMCHECK=OFF -DBUILD_COVERAGE=OFF
5959
-DBUILD_DOCS_API=ON
6060
- name: Build
6161
run: ./build.sh --target docs-api-html docs-api-pdf docs-api-misspelling

.github/workflows/fuzzing.yaml

Lines changed: 107 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,107 @@
1+
##
2+
## Copyright (c) 2025 The Johns Hopkins University Applied Physics
3+
## Laboratory LLC.
4+
##
5+
## This file is part of the Bundle Protocol Security Library (BSL).
6+
##
7+
## Licensed under the Apache License, Version 2.0 (the "License");
8+
## you may not use this file except in compliance with the License.
9+
## You may obtain a copy of the License at
10+
## http://www.apache.org/licenses/LICENSE-2.0
11+
## Unless required by applicable law or agreed to in writing, software
12+
## distributed under the License is distributed on an "AS IS" BASIS,
13+
## WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14+
## See the License for the specific language governing permissions and
15+
## limitations under the License.
16+
##
17+
## This work was performed for the Jet Propulsion Laboratory, California
18+
## Institute of Technology, sponsored by the United States Government under
19+
## the prime contract 80NM0018D0004 between the Caltech and NASA under
20+
## subcontract 1700763.
21+
##
22+
name: Build and run fuzzing
23+
on:
24+
schedule:
25+
- cron: '0 0 * * 0'
26+
push:
27+
branches:
28+
- main
29+
- 'apl-fy[0-9][0-9]'
30+
pull_request: {} # any target
31+
32+
jobs:
33+
fuzzing:
34+
strategy:
35+
fail-fast: false
36+
matrix:
37+
os: ['ubuntu-24.04', 'centos-9']
38+
compiler: ['clang']
39+
name: Fuzzing (${{matrix.os}} ${{matrix.compiler}})
40+
runs-on: ${{ matrix.os == 'centos-9' && 'ubuntu-24.04' || matrix.os }}
41+
container: ${{ matrix.os == 'centos-9' && 'quay.io/centos/centos:stream9' || null }}
42+
permissions:
43+
contents: read
44+
actions: write
45+
env:
46+
CC: ${{matrix.compiler=='clang' && 'clang' || 'gcc'}}
47+
CXX: ${{matrix.compiler=='clang' && 'clang++' || 'g++'}}
48+
steps:
49+
- name: Set up OS
50+
if: startsWith(matrix.os, 'ubuntu')
51+
run: |
52+
sudo rm /var/lib/man-db/auto-update
53+
sudo apt-get update
54+
sudo apt-get install -y \
55+
cmake ninja-build \
56+
ruby pkg-config ccache patch \
57+
${{matrix.compiler=='clang' && 'clang llvm' || 'gcc g++'}} \
58+
libssl-dev libjansson-dev \
59+
valgrind gcovr xmlstarlet
60+
sudo gem install cbor-diag
61+
- name: Set up OS
62+
if: startsWith(matrix.os, 'centos')
63+
run: |
64+
dnf install -y epel-release
65+
crb enable
66+
dnf install -y \
67+
git rsync \
68+
cmake ninja-build \
69+
ruby pkg-config ccache patch \
70+
${{matrix.compiler=='clang' && 'clang llvm' || 'gcc gcc-c++'}} \
71+
openssl-devel jansson-devel \
72+
valgrind xmlstarlet python3-pip
73+
pip3 install gcovr
74+
gem install cbor-diag
75+
- name: Checkout repository
76+
uses: actions/checkout@v4
77+
with:
78+
fetch-depth: 0
79+
submodules: recursive
80+
- name: ccache
81+
uses: hendrikmuhs/ccache-action@v1.2
82+
with:
83+
create-symlink: true
84+
- name: Dependencies
85+
run: ./build.sh deps
86+
- name: Prep
87+
run: >
88+
./build.sh prep
89+
-DBUILD_DOCS_API=OFF -DBUILD_DOCS_MAN=OFF
90+
-DBUILD_UNITTEST=OFF -DBUILD_FUZZING=ON -DBUILD_COVERAGE=ON
91+
- name: Build
92+
run: ./build.sh
93+
- name: Install
94+
run: ./build.sh install
95+
- name: Test
96+
run: ./build.sh check
97+
- name: Report corpus
98+
run: for FN in $(find test/*cbor*corpus -type f); do echo $FN; cborseq2diag.rb <$FN; done
99+
- name: Collect coverage
100+
run: ./build.sh coverage
101+
- name: Archive coverage
102+
uses: actions/upload-artifact@v4
103+
with:
104+
name: ${{github.job}}-${{matrix.os}}-${{matrix.compiler}}-coverage
105+
path: build/default/coverage*
106+
- name: Report coverage
107+
run: ./build.sh coverage-summary >> $GITHUB_STEP_SUMMARY

.github/workflows/packages.yaml

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -41,7 +41,7 @@ jobs:
4141
dnf config-manager --set-enabled crb
4242
dnf install -y epel-release
4343
dnf install -y \
44-
rsync cmake git ninja-build gcc ruby \
44+
rsync cmake git ninja-build gcc gcc-c++ ccache ruby \
4545
openssl-devel jansson-devel \
4646
doxygen graphviz plantuml texlive-bibtex \
4747
asciidoctor \
@@ -51,6 +51,10 @@ jobs:
5151
with:
5252
fetch-depth: 0
5353
submodules: recursive
54+
- name: ccache
55+
uses: hendrikmuhs/ccache-action@v1.2
56+
with:
57+
create-symlink: true
5458
- name: Prep
5559
run: ./build.sh rpm-prep
5660
- name: Build

CMakeLists.txt

Lines changed: 42 additions & 42 deletions
Original file line numberDiff line numberDiff line change
@@ -25,9 +25,10 @@ option(BUILD_LIB "Build the library itself" ON)
2525
option(BUILD_SHARED_LIBS "Build using shared libraries" ON)
2626
option(BUILD_DOCS_API "Enable API documentation building" OFF)
2727
option(BUILD_DOCS_MAN "Enable manpage building" OFF)
28-
option(BUILD_TESTING "Enable building unit tests" ON)
28+
option(BUILD_UNITTEST "Enable building unit tests" ON)
2929
option(TEST_MEMCHECK "Enable test runtime memory checking" ON)
30-
option(TEST_COVERAGE "Enable test runtime coverage logging" ON)
30+
option(BUILD_COVERAGE "Enable runtime coverage logging and reporting" OFF)
31+
option(BUILD_FUZZING "Enable building fuzzing executables" OFF)
3132
option(BUILD_PACKAGE "Enable building package outputs" OFF)
3233

3334
list(APPEND CMAKE_MODULE_PATH "${CMAKE_CURRENT_SOURCE_DIR}/cmake")
@@ -59,7 +60,7 @@ STRING(REPLACE "-" "." GIT_TAG_MOD ${GIT_TAG_MOD})
5960
message(STATUS "Using version marking ${GIT_TAG_VERS} - ${GIT_TAG_MOD}")
6061

6162
project(bsl
62-
LANGUAGES C
63+
LANGUAGES C CXX
6364
VERSION ${GIT_TAG_VERS}
6465
)
6566

@@ -75,21 +76,19 @@ add_definitions(
7576
# Generic warn/error options
7677
add_compile_options(
7778
-Wall
78-
-Wextra
79-
-Wpedantic
80-
-Werror
79+
$<$<COMPILE_LANGUAGE:C>:-Wextra>
80+
$<$<COMPILE_LANGUAGE:C>:-Wpedantic>
81+
$<$<COMPILE_LANGUAGE:C>:-Werror>
8182
-Wshadow -Wpointer-arith -Wstrict-prototypes
8283
-Wmissing-prototypes -Wredundant-decls -Wcast-align
83-
-Wformat=2 -Wswitch-enum
84+
-Wformat=2
8485
-fno-strict-aliasing -Werror=format-security -fno-common
8586
-Wstrict-aliasing=2
8687
# -Wconversion
87-
)
88-
add_compile_options(
8988
-ffunction-sections
9089
-fdata-sections
9190
-fno-omit-frame-pointer
92-
$<$<COMPILE_LANGUAGE:CXX>:-fno-exceptions>
91+
$<$<COMPILE_LANGUAGE:C>:-Wswitch-enum>
9392
)
9493
if(CMAKE_C_COMPILER_ID MATCHES "GNU")
9594
set(CMAKE_CXX_FLAGS_DEBUG "${CMAKE_CXX_FLAGS_DEBUG} -O0")
@@ -127,7 +126,7 @@ include(CheckTypeSize)
127126
check_type_size("int" SIZE_INT LANGUAGE C)
128127
check_type_size("size_t" SIZE_SIZET LANGUAGE C)
129128

130-
if(BUILD_TESTING)
129+
if(BUILD_UNITTEST)
131130
if(TEST_MEMCHECK)
132131
find_program(MEMCHECK_CMD valgrind)
133132
message(STATUS "Using valgrind memcheck for tests: ${MEMCHECK_CMD}")
@@ -142,45 +141,46 @@ if(BUILD_TESTING)
142141
# Arguments as list into global scope for Findunitytools.cmake
143142
set(TEST_EXEC_PREFIX "${MEMCHECK_CMD}" ${MEMCHECK_OPTIONS})
144143
endif(TEST_MEMCHECK)
145-
if(TEST_COVERAGE)
146-
include(CodeCoverage)
147-
append_coverage_compiler_flags()
148-
149-
set(COVERAGE_EXCLUDES
150-
"${CMAKE_CURRENT_SOURCE_DIR}/deps/*"
151-
"${CMAKE_CURRENT_SOURCE_DIR}/testroot/*"
152-
"${CMAKE_CURRENT_BINARY_DIR}/test/*"
153-
)
154-
set(GCOVR_ADDITIONAL_ARGS
155-
)
156-
setup_target_for_coverage_gcovr_xml(
157-
NAME coverage-xml
158-
BASE_DIRECTORY "${PROJECT_SOURCE_DIR}"
159-
)
160-
setup_target_for_coverage_gcovr_html(
161-
NAME coverage-html
162-
BASE_DIRECTORY "${PROJECT_SOURCE_DIR}"
163-
)
164-
endif(TEST_COVERAGE)
165-
166-
include(CTest)
167-
set(CMAKE_CTEST_ARGUMENTS
168-
--output-junit testresults.xml
169-
--output-on-failure
144+
endif(BUILD_UNITTEST)
145+
if(BUILD_FUZZING)
146+
find_package(libfuzzer)
147+
endif(BUILD_FUZZING)
148+
if(BUILD_COVERAGE)
149+
include(CodeCoverage)
150+
append_coverage_compiler_flags()
151+
152+
set(COVERAGE_EXCLUDES
153+
"${CMAKE_CURRENT_SOURCE_DIR}/deps/*"
154+
"${CMAKE_CURRENT_SOURCE_DIR}/testroot/*"
155+
"${CMAKE_CURRENT_BINARY_DIR}/test/*"
170156
)
171-
endif(BUILD_TESTING)
157+
set(GCOVR_ADDITIONAL_ARGS
158+
)
159+
setup_target_for_coverage_gcovr_xml(
160+
NAME coverage-xml
161+
BASE_DIRECTORY "${PROJECT_SOURCE_DIR}"
162+
)
163+
setup_target_for_coverage_gcovr_html(
164+
NAME coverage-html
165+
BASE_DIRECTORY "${PROJECT_SOURCE_DIR}"
166+
)
167+
endif(BUILD_COVERAGE)
168+
169+
include(CTest)
170+
set(CMAKE_CTEST_ARGUMENTS
171+
--output-junit testresults.xml
172+
--output-on-failure
173+
)
172174

173175
# Install config used by tall targets
174176
include(GNUInstallDirs)
175177

176178
if(BUILD_LIB)
177179
add_subdirectory(src)
178180
endif(BUILD_LIB)
179-
if(BUILD_TESTING)
180-
message(STATUS "Building tests")
181-
set(TEST_INSTALL_PREFIX "${CMAKE_INSTALL_LIBEXECDIR}/${PROJECT_NAME}")
182-
add_subdirectory(test)
183-
endif(BUILD_TESTING)
181+
182+
set(TEST_INSTALL_PREFIX "${CMAKE_INSTALL_LIBEXECDIR}/${PROJECT_NAME}")
183+
add_subdirectory(test)
184184
add_subdirectory(docs)
185185

186186
if(BUILD_PACKAGE)

build.sh

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -111,7 +111,7 @@ function cmd_rpm_prep {
111111
then
112112
git config --global --add safe.directory ${PWD}
113113
fi
114-
./resources/prep.sh -DBUILD_LIB=OFF -DBUILD_TESTING=OFF -DBUILD_DOCS_API=OFF -DBUILD_DOCS_MAN=OFF -DBUILD_PACKAGE=ON
114+
./resources/prep.sh -DBUILD_LIB=OFF -DBUILD_UNITTEST=OFF -DBUILD_DOCS_API=OFF -DBUILD_DOCS_MAN=OFF -DBUILD_PACKAGE=ON
115115
}
116116

117117
function cmd_rpm_build {

cmake/CodeCoverage.cmake

Lines changed: 10 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -164,8 +164,13 @@ foreach(LANG ${LANGUAGES})
164164
endif()
165165
endforeach()
166166

167-
set(COVERAGE_COMPILER_FLAGS "-g --coverage"
168-
CACHE INTERNAL "")
167+
if(CMAKE_C_COMPILER_ID MATCHES "GNU")
168+
set(COVERAGE_COMPILER_FLAGS "-g --coverage")
169+
set(GCOV_EXEC "--gcov-executable" "gcov")
170+
elseif(CMAKE_C_COMPILER_ID MATCHES "Clang")
171+
set(COVERAGE_COMPILER_FLAGS "-gdwarf-4 --coverage")
172+
set(GCOV_EXEC "--gcov-executable" "llvm-cov gcov")
173+
endif()
169174

170175
if(CMAKE_CXX_COMPILER_ID MATCHES "(GNU|Clang)")
171176
include(CheckCXXCompilerFlag)
@@ -309,7 +314,7 @@ function(setup_target_for_coverage_lcov)
309314
if(${Coverage_SONARQUBE})
310315
# Generate SonarQube output
311316
set(GCOVR_XML_CMD
312-
${GCOVR_PATH} --sonarqube ${Coverage_NAME}_sonarqube.xml -r ${BASEDIR} ${GCOVR_ADDITIONAL_ARGS}
317+
${GCOVR_PATH} ${GCOV_EXEC} --sonarqube ${Coverage_NAME}_sonarqube.xml -r ${BASEDIR} ${GCOVR_ADDITIONAL_ARGS}
313318
${GCOVR_EXCLUDE_ARGS} --object-directory=${PROJECT_BINARY_DIR}
314319
)
315320
set(GCOVR_XML_CMD_COMMAND
@@ -455,7 +460,7 @@ function(setup_target_for_coverage_gcovr_xml)
455460
)
456461
# Running gcovr
457462
set(GCOVR_XML_CMD
458-
${GCOVR_PATH} --xml ${Coverage_NAME}.xml -r ${BASEDIR} ${GCOVR_ADDITIONAL_ARGS}
463+
${GCOVR_PATH} ${GCOV_EXEC} --xml ${Coverage_NAME}.xml -r ${BASEDIR} ${GCOVR_ADDITIONAL_ARGS}
459464
${GCOVR_EXCLUDE_ARGS} --object-directory=${PROJECT_BINARY_DIR}
460465
)
461466

@@ -551,7 +556,7 @@ function(setup_target_for_coverage_gcovr_html)
551556
)
552557
# Running gcovr
553558
set(GCOVR_HTML_CMD
554-
${GCOVR_PATH} --html ${Coverage_NAME}/index.html --html-details -r ${BASEDIR} ${GCOVR_ADDITIONAL_ARGS}
559+
${GCOVR_PATH} ${GCOV_EXEC} --html ${Coverage_NAME}/index.html --html-details -r ${BASEDIR} ${GCOVR_ADDITIONAL_ARGS}
555560
${GCOVR_EXCLUDE_ARGS} --object-directory=${PROJECT_BINARY_DIR}
556561
)
557562

0 commit comments

Comments
 (0)