Skip to content

Commit d81f133

Browse files
committed
New test framework for standlone binary testing, including tests validating the default swap works as expected.
1 parent cf77626 commit d81f133

File tree

17 files changed

+836
-11
lines changed

17 files changed

+836
-11
lines changed

Makefile.am

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,15 @@ if BUILD_REPLACE_DEFAULT
1919
lib_LTLIBRARIES += libdefault.la
2020
libdefault_la_SOURCES = src/wp_default_replace.c
2121
libdefault_la_LIBADD = libwolfprov.la
22+
23+
# Install libdefault.so to OpenSSL lib directory for replace-default builds
24+
install-exec-hook:
25+
@echo "Installing libdefault.so to OpenSSL lib directory..."
26+
$(INSTALL) -m 755 "$(DESTDIR)$(libdir)/libdefault.so" "$(OPENSSL_LIB_DIR)/libdefault.so"
27+
28+
uninstall-hook:
29+
@echo "Removing libdefault.so from OpenSSL lib directory..."
30+
rm -f "$(OPENSSL_LIB_DIR)/libdefault.so"
2231
endif
2332

2433
EXTRA_DIST+=ChangeLog.md

configure.ac

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -132,6 +132,18 @@ AC_ARG_ENABLE([replace-default],
132132

133133
AM_CONDITIONAL([BUILD_REPLACE_DEFAULT], [test "x$ENABLED_REPLACE_DEFAULT" = "xyes"])
134134

135+
# Set OpenSSL lib directory for installing libdefault.so
136+
if test "x$ENABLED_REPLACE_DEFAULT" = "xyes"; then
137+
if test -d "$OPENSSL_INSTALL_DIR/lib64"; then
138+
OPENSSL_LIB_DIR="$OPENSSL_INSTALL_DIR/lib64"
139+
elif test -d "$OPENSSL_INSTALL_DIR/lib"; then
140+
OPENSSL_LIB_DIR="$OPENSSL_INSTALL_DIR/lib"
141+
else
142+
OPENSSL_LIB_DIR="$OPENSSL_INSTALL_DIR/lib"
143+
fi
144+
fi
145+
AC_SUBST([OPENSSL_LIB_DIR])
146+
135147

136148
AX_HARDEN_CC_COMPILER_FLAGS
137149

scripts/build-wolfprovider.sh

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ show_help() {
88
echo "Script Arguments:"
99
echo " --help, -help, -h Display this help menu and exit"
1010
echo " --clean Run make clean in OpenSSL, wolfSSL, and wolfProvider"
11-
echo " --distclean Remove source directories of OpenSSL and wolfSSL"
11+
echo " --distclean Remove source and install directories of OpenSSL, wolfSSL, and wolfProvider"
1212
echo " --debug Builds OpenSSL, wolfSSL, and WolfProvider with debugging enabled. This is the same as setting WOLFPROV_DEBUG=1"
1313
echo " --debug-asn-template Enable debug information for asn within wolfSSL"
1414
echo " --disable-err-trace No debug trace messages from library errors in wolfSSL"
@@ -30,7 +30,7 @@ show_help() {
3030
echo " WOLFSSL_FIPS_VERSION Version of wolfSSL FIPS bundle (v5, v6, ready), used as an argument for --enable-fips when configuring wolfSSL"
3131
echo " WOLFSSL_FIPS_CHECK_TAG Tag for wolfSSL FIPS bundle (linuxv5.2.1, v6.0.0, etc), used as an argument for fips-check.sh when cloning a wolfSSL FIPS version"
3232
echo " WOLFPROV_CLEAN If set to 1, run make clean in OpenSSL, wolfSSL, and wolfProvider"
33-
echo " WOLFPROV_DISTCLEAN If set to 1, remove the source directories of OpenSSL and wolfSSL"
33+
echo " WOLFPROV_DISTCLEAN If set to 1, remove the source and install directories of OpenSSL, wolfSSL, and wolfProvider"
3434
echo " WOLFPROV_DEBUG If set to 1, builds OpenSSL, wolfSSL, and wolfProvider with debug options enabled"
3535
echo " WOLFPROV_QUICKTEST If set to 1, disables some tests in the test suite to increase test speed"
3636
echo " WOLFPROV_DISABLE_ERR_TRACE If set to 1, wolfSSL will not be configured with --enable-debug-trace-errcodes=backtrace"

scripts/env-setup

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -33,9 +33,9 @@ echo "PWD: $PWD"
3333

3434
# Detect the openssl library path
3535
if [ -d $REPO_ROOT/openssl-install/lib ]; then
36-
OPENSSL_LIB_PATH=$REPO_ROOT/openssl-install/lib
36+
export OPENSSL_LIB_PATH=$REPO_ROOT/openssl-install/lib
3737
elif [ -d $REPO_ROOT/openssl-install/lib64 ]; then
38-
OPENSSL_LIB_PATH=$REPO_ROOT/openssl-install/lib64
38+
export OPENSSL_LIB_PATH=$REPO_ROOT/openssl-install/lib64
3939
else
4040
echo "Error: Could not find OpenSSL lib directory in $REPO_ROOT/openssl-install"
4141
exit 1

scripts/utils-openssl.sh

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -50,6 +50,8 @@ clean_openssl() {
5050
if [ "$WOLFPROV_DISTCLEAN" -eq "1" ]; then
5151
printf "Removing OpenSSL source ...\n"
5252
rm -rf "${OPENSSL_SOURCE_DIR}"
53+
printf "Removing OpenSSL install ...\n"
54+
rm -rf "${OPENSSL_INSTALL_DIR}"
5355
fi
5456
}
5557

scripts/utils-wolfprovider.sh

Lines changed: 15 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -106,17 +106,32 @@ clean_wolfprov() {
106106
fi
107107
rm -rf ${WOLFPROV_INSTALL_DIR}
108108
fi
109+
if [ "$WOLFPROV_DISTCLEAN" -eq "1" ]; then
110+
printf "Removing wolfProvider install ...\n"
111+
rm -rf ${WOLFPROV_INSTALL_DIR}
112+
rm -rf ${LIBDEFAULT_STUB_INSTALL_DIR}
113+
fi
109114
}
110115

111116
install_wolfprov() {
112117
cd ${WOLFPROV_SOURCE_DIR}
113118

119+
# Add stub library path for replace-default functionality after dependencies are installed
120+
if [ "$WOLFPROV_REPLACE_DEFAULT" = "1" ]; then
121+
if [ -z "$LD_LIBRARY_PATH" ]; then
122+
export LD_LIBRARY_PATH="${LIBDEFAULT_STUB_INSTALL_DIR}/lib"
123+
else
124+
export LD_LIBRARY_PATH="${LIBDEFAULT_STUB_INSTALL_DIR}/lib:$LD_LIBRARY_PATH"
125+
fi
126+
fi
127+
114128
init_openssl
115129
init_wolfssl
116130

117131
printf "\nConsolidating wolfProvider ...\n"
118132
unset OPENSSL_MODULES
119133
unset OPENSSL_CONF
134+
120135
printf "LD_LIBRARY_PATH: $LD_LIBRARY_PATH\n"
121136

122137
printf "\tConfigure wolfProvider ... "
@@ -130,12 +145,6 @@ install_wolfprov() {
130145

131146
if [ "$WOLFPROV_REPLACE_DEFAULT" = "1" ]; then
132147
WOLFPROV_CONFIG_OPTS+=" --enable-replace-default"
133-
# Add stub library path for replace-default functionality
134-
if [ -z "$LD_LIBRARY_PATH" ]; then
135-
export LD_LIBRARY_PATH="${LIBDEFAULT_STUB_INSTALL_DIR}/lib"
136-
else
137-
export LD_LIBRARY_PATH="${LIBDEFAULT_STUB_INSTALL_DIR}/lib:$LD_LIBRARY_PATH"
138-
fi
139148
fi
140149

141150
./configure ${WOLFPROV_CONFIG_OPTS} CFLAGS="${WOLFPROV_CONFIG_CFLAGS}" >>$LOG_FILE 2>&1

scripts/utils-wolfssl.sh

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -49,6 +49,8 @@ clean_wolfssl() {
4949
if [ "$WOLFPROV_DISTCLEAN" -eq "1" ]; then
5050
printf "Removing wolfSSL source ...\n"
5151
rm -rf "${WOLFSSL_SOURCE_DIR}"
52+
printf "Removing wolfSSL install ...\n"
53+
rm -rf "${WOLFSSL_INSTALL_DIR}"
5254
fi
5355
}
5456

@@ -72,7 +74,10 @@ clone_wolfssl() {
7274
DEPTH_ARG=${WOLFPROV_DEBUG:+""}
7375
DEPTH_ARG=${DEPTH_ARG:---depth=1}
7476

75-
git clone ${DEPTH_ARG} -b ${CLONE_TAG} ${WOLFSSL_GIT} ${WOLFSSL_SOURCE_DIR} >>$LOG_FILE 2>&1
77+
# If we are replacing default provider, our current built openssl still
78+
# links to the default stub and is non-functional. Run the clone with
79+
# no explicitly LD_LIBRARY_PATH to ensure use of global openssl for clone
80+
LD_LIBRARY_PATH="" git clone ${DEPTH_ARG} -b ${CLONE_TAG} ${WOLFSSL_GIT} ${WOLFSSL_SOURCE_DIR} >>$LOG_FILE 2>&1
7681
RET=$?
7782

7883
if [ $RET != 0 ]; then

test/include.am

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -35,3 +35,5 @@ test_unit_test_SOURCES = \
3535
test_unit_test_LDADD = libwolfprov.la
3636
noinst_HEADERS += test/unit.h
3737

38+
# Include standalone binary tests
39+
include test/standalone/include.am

test/standalone/include.am

Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,36 @@
1+
# vim:ft=automake
2+
# included from test/include.am
3+
# All paths should be given relative to the root
4+
5+
# Standalone test programs use no extension - simple and clean!
6+
7+
# Common standalone test headers
8+
noinst_HEADERS += test/standalone/test_common.h
9+
10+
# Standalone test programs
11+
# Each test compiles to its own binary for isolated execution
12+
check_PROGRAMS += test/sha256_simple.test test/hardload.test
13+
noinst_PROGRAMS += test/sha256_simple.test test/hardload.test
14+
DISTCLEANFILES += test/.libs/sha256_simple.test test/.libs/hardload.test
15+
16+
# Common flags for all standalone tests
17+
STANDALONE_COMMON_CPPFLAGS = -DCERTS_DIR='"$(abs_top_srcdir)/certs"' \
18+
-I$(srcdir)/test/standalone
19+
STANDALONE_COMMON_LDADD = libwolfprov.la
20+
21+
# Individual test configurations
22+
test_sha256_simple_test_CPPFLAGS = $(STANDALONE_COMMON_CPPFLAGS)
23+
test_sha256_simple_test_SOURCES = test/standalone/tests/sha256_simple/test_sha256_simple.c
24+
test_sha256_simple_test_LDADD = $(STANDALONE_COMMON_LDADD)
25+
26+
test_hardload_test_CPPFLAGS = $(STANDALONE_COMMON_CPPFLAGS)
27+
test_hardload_test_SOURCES = test/standalone/tests/hardload/test_hardload.c
28+
test_hardload_test_LDADD = $(STANDALONE_COMMON_LDADD)
29+
30+
# Common test utilities are built automatically by automake
31+
32+
# Add standalone tests to the test suite
33+
# We'll run these through our multi-environment runner manually
34+
# TESTS += test/sha256_simple.test
35+
36+
# Note: test results are cleaned by the test runner automatically
Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
openssl_conf = openssl_init
2+
3+
[openssl_init]
4+
providers = provider_sect
5+
6+
[provider_sect]
7+
default = default_sect
8+
9+
[default_sect]
10+
activate = 1

0 commit comments

Comments
 (0)