Skip to content

Commit 4a9fc76

Browse files
Add CLang to CI unit tests (#119)
* init clang ci * update build & ci * update jobs * Making valgrind build optional * more cleanup --------- Co-authored-by: Brian Sipos <brian.sipos@jhuapl.edu>
1 parent 2d941c1 commit 4a9fc76

7 files changed

Lines changed: 29 additions & 7 deletions

File tree

.github/workflows/build-test.yaml

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,7 @@ jobs:
3535
fail-fast: false
3636
matrix:
3737
os: ['ubuntu-24.04', 'centos-9']
38-
compiler: ['gcc']
38+
compiler: ['gcc', 'clang']
3939
name: Unit Test (${{matrix.os}} ${{matrix.compiler}})
4040
runs-on: ${{ matrix.os == 'centos-9' && 'ubuntu-24.04' || matrix.os }}
4141
container: ${{ matrix.os == 'centos-9' && 'quay.io/centos/centos:stream9' || null }}
@@ -70,7 +70,7 @@ jobs:
7070
ruby pkg-config ccache patch \
7171
${{matrix.compiler=='clang' && 'clang llvm' || 'gcc gcc-c++'}} \
7272
openssl-devel jansson-devel \
73-
valgrind xmlstarlet \
73+
valgrind valgrind-devel xmlstarlet \
7474
python3 python3-pip python3-wheel
7575
pip3 install gcovr
7676
- name: Checkout repository
@@ -145,7 +145,7 @@ jobs:
145145
cmake ninja-build \
146146
ruby pkg-config gcc gcc-c++ ccache patch \
147147
openssl-devel jansson-devel \
148-
valgrind xmlstarlet \
148+
valgrind valgrind-devel xmlstarlet \
149149
python3 python3-pip python3-wheel
150150
pip3 install gcovr
151151
- name: Checkout repository

.github/workflows/fuzzing.yaml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -56,7 +56,7 @@ jobs:
5656
ruby pkg-config ccache patch \
5757
${{matrix.compiler=='clang' && 'clang llvm' || 'gcc g++'}} \
5858
libssl-dev libjansson-dev \
59-
valgrind gcovr xmlstarlet
59+
gcovr xmlstarlet
6060
sudo gem install cbor-diag
6161
- name: Set up OS
6262
if: startsWith(matrix.os, 'centos')
@@ -69,7 +69,7 @@ jobs:
6969
ruby pkg-config ccache patch \
7070
${{matrix.compiler=='clang' && 'clang llvm' || 'gcc gcc-c++'}} \
7171
openssl-devel jansson-devel \
72-
valgrind xmlstarlet python3-pip
72+
xmlstarlet python3-pip
7373
pip3 install gcovr
7474
gem install cbor-diag
7575
- name: Checkout repository

CMakeLists.txt

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -116,7 +116,7 @@ if(BUILD_LIB)
116116
find_package(QCBOR REQUIRED)
117117
find_package(OpenSSL REQUIRED)
118118
find_package(Threads REQUIRED)
119-
find_package(jansson REQUIRED)
119+
find_package(Jansson REQUIRED)
120120
endif(BUILD_LIB)
121121

122122
include(CheckSymbolExists)
@@ -130,7 +130,9 @@ check_type_size("size_t" SIZE_SIZET LANGUAGE C)
130130

131131
if(BUILD_UNITTEST)
132132
if(TEST_MEMCHECK)
133-
find_program(MEMCHECK_CMD valgrind)
133+
find_package(valgrind REQUIRED)
134+
135+
find_program(MEMCHECK_CMD valgrind REQUIRED)
134136
message(STATUS "Using valgrind memcheck for tests: ${MEMCHECK_CMD}")
135137
set(MEMCHECK_OPTIONS
136138
"--tool=memcheck"
Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,6 @@
1+
# Imports targets for using Jansson libraries:
2+
# Jansson::Jansson
3+
#
14

25
# Try pkg-config first
36
pkg_search_module(JANSSON jansson IMPORTED_TARGET)

cmake/Findvalgrind.cmake

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
# Imports targets for using valgrind libraries:
2+
# valgrind::valgrind
3+
#
4+
pkg_search_module(VALGRIND valgrind IMPORTED_TARGET)
5+
if(VALGRIND_FOUND)
6+
add_library(valgrind::valgrind ALIAS PkgConfig::VALGRIND)
7+
endif(VALGRIND_FOUND)

src/CMakeLists.txt

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -68,6 +68,9 @@ set_target_properties(bsl_crypto
6868
target_link_libraries(bsl_crypto PUBLIC bsl_front)
6969
target_link_libraries(bsl_crypto PUBLIC MLIB::mlib)
7070
target_link_libraries(bsl_crypto INTERFACE OpenSSL::Crypto)
71+
if(TARGET valgrind::valgrind)
72+
target_compile_definitions(bsl_crypto PRIVATE HAVE_VALGRIND)
73+
endif(TARGET valgrind::valgrind)
7174

7275
# Default Security Context library
7376
set(BSL_DEFAULT_SC_H

src/crypto/CryptoInterface.c

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,10 @@
3131
#include <openssl/err.h>
3232
#include <openssl/rand.h>
3333

34+
#if defined(HAVE_VALGRIND)
35+
#include <valgrind/memcheck.h>
36+
#endif /* defined(HAVE_VALGRIND) */
37+
3438
/**
3539
* Struct to hold private key information
3640
*/
@@ -545,6 +549,9 @@ int BSL_Cipher_GetTag(BSL_Cipher_t *cipher_ctx, void **tag)
545549
{
546550
int res = EVP_CIPHER_CTX_ctrl(cipher_ctx->libhandle, EVP_CTRL_GCM_GET_TAG, BSL_CRYPTO_AESGCM_AUTH_TAG_LEN, *tag);
547551
CHK_PROPERTY(res == 1);
552+
#if defined(HAVE_VALGRIND)
553+
VALGRIND_MAKE_MEM_DEFINED(*tag, BSL_CRYPTO_AESGCM_AUTH_TAG_LEN);
554+
#endif /* defined(HAVE_VALGRIND) */
548555
return 0;
549556
}
550557

0 commit comments

Comments
 (0)