Skip to content

Commit bd00908

Browse files
authored
Merge pull request #245 from padelsbach/wp_cmd_test_refactor
Update command line tests
2 parents 73aa5bf + d70f96c commit bd00908

File tree

9 files changed

+186
-277
lines changed

9 files changed

+186
-277
lines changed

.github/workflows/simple.yml

Lines changed: 28 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -13,25 +13,39 @@ concurrency:
1313
# END OF COMMON SECTION
1414

1515
jobs:
16+
build_wolfprovider:
17+
uses: ./.github/workflows/build-wolfprovider.yml
18+
with:
19+
wolfssl_ref: ${{ matrix.wolfssl_ref }}
20+
openssl_ref: ${{ matrix.openssl_ref }}
21+
strategy:
22+
matrix:
23+
wolfssl_ref: [ 'master', 'v5.8.0-stable' ]
24+
openssl_ref: [ 'master', 'openssl-3.5.0' ]
25+
debug: ['WOLFPROV_DEBUG=1', '']
26+
1627
simple_test:
1728
name: Simple Test
1829
runs-on: ubuntu-22.04
30+
needs: build_wolfprovider
1931
timeout-minutes: 20
2032
strategy:
2133
matrix:
22-
openssl_ref: [ 'master', 'openssl-3.5.0' ]
2334
wolfssl_ref: [ 'master', 'v5.8.0-stable' ]
35+
openssl_ref: [ 'master', 'openssl-3.5.0' ]
2436
force_fail: ['WOLFPROV_FORCE_FAIL=1', '']
25-
debug: ['WOLFPROV_DEBUG=1', '']
2637
steps:
2738
- name: Checkout wolfProvider
2839
uses: actions/checkout@v4
40+
with:
41+
fetch-depth: 1
2942

30-
# Check if this version of wolfssl/wolfprovider has already been built,
31-
# mark to cache these items on post if we do end up building
32-
- name: Checking wolfSSL/wolfProvider in cache
33-
uses: actions/cache@v4
34-
id: wolfprov-cache
43+
- name: Retrieving wolfProvider from cache
44+
# Debug builds are not currently supported by build-wolfprovider.yml
45+
# so those are manually built as a separate step.
46+
if: ${{ matrix.debug == '' }}
47+
uses: actions/cache/restore@v4
48+
id: wolfprov-cache-restore
3549
with:
3650
path: |
3751
wolfssl-install
@@ -41,21 +55,16 @@ jobs:
4155
openssl-install/bin
4256
4357
key: wolfprov-${{ matrix.wolfssl_ref }}-${{ matrix.openssl_ref }}-${{ github.sha }}
44-
lookup-only: true
58+
fail-on-cache-miss: true
4559

46-
# If not yet built this version, build it now
4760
- name: Build wolfProvider
48-
if: steps.wolfprov-${{ matrix.wolfssl_ref }}-cache.hit != 'true'
61+
if: ${{ matrix.debug != '' }}
4962
run: |
50-
${{ matrix.debug }} OPENSSL_TAG=${{ matrix.openssl_ref }} WOLFSSL_TAG=${{ matrix.wolfssl_ref }} ./scripts/build-wolfprovider.sh
63+
${{ matrix.debug }} \
64+
OPENSSL_TAG=${{ matrix.openssl_ref }} \
65+
WOLFSSL_TAG=${{ matrix.wolfssl_ref }} \
66+
./scripts/build-wolfprovider.sh
5167
5268
- name: Run simple tests
5369
run: |
54-
${{ matrix.force_fail }} ${{ matrix.debug }} ./scripts/cmd_test/do-cmd-tests.sh
55-
56-
- name: Print test logs
57-
if: always()
58-
run: |
59-
if [ -f test-suite.log ] ; then
60-
cat test-suite.log
61-
fi
70+
${{ matrix.force_fail }} ./scripts/cmd_test/do-cmd-tests.sh

scripts/cmd_test/aes-cmd-test.sh

Lines changed: 2 additions & 51 deletions
Original file line numberDiff line numberDiff line change
@@ -19,63 +19,14 @@
1919
# You should have received a copy of the GNU General Public License
2020
# along with wolfProvider. If not, see <http://www.gnu.org/licenses/>.
2121

22-
# Set up environment
2322
SCRIPT_DIR="$( cd "$( dirname "${BASH_SOURCE[0]}" )" &> /dev/null && pwd )"
24-
REPO_ROOT="$( cd "${SCRIPT_DIR}/../.." &> /dev/null && pwd )"
25-
UTILS_DIR="${REPO_ROOT}/scripts"
26-
export LOG_FILE="${SCRIPT_DIR}/aes-test.log"
27-
touch "$LOG_FILE"
28-
29-
# Source wolfProvider utilities
30-
source "${UTILS_DIR}/utils-general.sh"
31-
source "${UTILS_DIR}/utils-openssl.sh"
32-
source "${UTILS_DIR}/utils-wolfssl.sh"
33-
source "${UTILS_DIR}/utils-wolfprovider.sh"
34-
35-
# Initialize wolfProvider
36-
init_wolfprov
37-
38-
# Fail flags
39-
FAIL=0
40-
FORCE_FAIL_PASSED=0
41-
42-
# Check environment variables directly
43-
if [ "${WOLFPROV_FORCE_FAIL}" = "1" ]; then
44-
echo "Force fail mode enabled for AES tests"
45-
fi
46-
if [ "${WOLFSSL_ISFIPS}" = "1" ]; then
47-
echo "FIPS mode enabled for AES tests"
48-
fi
49-
50-
# Verify wolfProvider is properly loaded
51-
echo -e "\nVerifying wolfProvider configuration:"
52-
if ! $OPENSSL_BIN list -providers | grep -q "wolf"; then
53-
echo "[FAIL] wolfProvider not found in OpenSSL providers!"
54-
echo "Current provider list:"
55-
$OPENSSL_BIN list -providers
56-
FAIL=1
57-
else
58-
echo "wolfProvider is properly configured"
59-
fi
60-
61-
# Print environment for verification
62-
echo "Environment variables:"
63-
echo "OPENSSL_MODULES: ${OPENSSL_MODULES}"
64-
echo "LD_LIBRARY_PATH: ${LD_LIBRARY_PATH}"
65-
echo "OPENSSL_BIN: ${OPENSSL_BIN}"
23+
source "${SCRIPT_DIR}/cmd-test-common.sh"
24+
cmd_test_env_setup "aes-test.log"
6625

6726
# Create test data and output directories
6827
mkdir -p aes_outputs
6928
echo "This is test data for AES encryption testing." > test.txt
7029

71-
# Helper function to handle force fail checks
72-
check_force_fail() {
73-
if [ "${WOLFPROV_FORCE_FAIL}" = "1" ]; then
74-
echo "[PASS] Test passed when force fail was enabled"
75-
FORCE_FAIL_PASSED=1
76-
fi
77-
}
78-
7930
# Arrays for test configurations
8031
KEY_SIZES=("128" "192" "256")
8132
# Only include modes supported by wolfProvider

scripts/cmd_test/clean-cmd-test.sh

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
#!/bin/bash
2+
#
3+
# Copyright (C) 2006-2025 wolfSSL Inc.
4+
#
5+
# This file is part of wolfProvider.
6+
#
7+
# wolfProvider is free software; you can redistribute it and/or modify
8+
# it under the terms of the GNU General Public License as published by
9+
# the Free Software Foundation; either version 3 of the License, or
10+
# (at your option) any later version.
11+
#
12+
# wolfProvider is distributed in the hope that it will be useful,
13+
# but WITHOUT ANY WARRANTY; without even the implied warranty of
14+
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15+
# GNU General Public License for more details.
16+
#
17+
# You should have received a copy of the GNU General Public License
18+
# along with wolfProvider. If not, see <http://www.gnu.org/licenses/>.
19+
20+
# Clean up command test artifacts
21+
rm -rf ./scripts/cmd_test/*.log
22+
rm -rf ./aes_outputs
23+
rm -rf ./ecc_outputs
24+
rm -rf ./hash_outputs
25+
rm -rf ./rsa_outputs
26+
rm -rf ./test.txt
Lines changed: 83 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,83 @@
1+
#!/bin/bash
2+
#
3+
# Copyright (C) 2006-2025 wolfSSL Inc.
4+
#
5+
# This file is part of wolfProvider.
6+
#
7+
# wolfProvider is free software; you can redistribute it and/or modify
8+
# it under the terms of the GNU General Public License as published by
9+
# the Free Software Foundation; either version 3 of the License, or
10+
# (at your option) any later version.
11+
#
12+
# wolfProvider is distributed in the hope that it will be useful,
13+
# but WITHOUT ANY WARRANTY; without even the implied warranty of
14+
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15+
# GNU General Public License for more details.
16+
#
17+
# You should have received a copy of the GNU General Public License
18+
# along with wolfProvider. If not, see <http://www.gnu.org/licenses/>.
19+
20+
cmd_test_env_setup() {
21+
local log_file_name=$1
22+
SCRIPT_DIR="$( cd "$( dirname "${BASH_SOURCE[0]}" )" &> /dev/null && pwd )"
23+
# Set up environment
24+
export LOG_FILE="${SCRIPT_DIR}/${log_file_name}"
25+
touch "$LOG_FILE"
26+
27+
# OPENSSL_BIN must be set by the caller
28+
if [ -z "${OPENSSL_BIN:-}" ]; then
29+
echo "Error: OPENSSL_BIN environment variable is not set" | tee -a "$LOG_FILE"
30+
exit 1
31+
fi
32+
33+
# Fail flags
34+
FAIL=0
35+
FORCE_FAIL_PASSED=0
36+
37+
# Get the force fail parameter
38+
if [ "${WOLFPROV_FORCE_FAIL}" = "1" ]; then
39+
echo "Force fail mode enabled"
40+
fi
41+
if [ "${WOLFSSL_ISFIPS}" = "1" ]; then
42+
echo "FIPS mode enabled"
43+
fi
44+
45+
# Print environment for verification
46+
echo "Environment variables:"
47+
echo "OPENSSL_MODULES: ${OPENSSL_MODULES}"
48+
echo "OPENSSL_BIN: ${OPENSSL_BIN}"
49+
}
50+
51+
# Function to use default provider only
52+
use_default_provider() {
53+
unset OPENSSL_MODULES
54+
unset OPENSSL_CONF
55+
56+
# Verify that we are using the default provider
57+
if ${OPENSSL_BIN} list -providers | grep -q "wolfprov"; then
58+
echo "FAIL: unable to switch to default provider, wolfProvider is still active"
59+
exit 1
60+
fi
61+
echo "Switched to default provider"
62+
}
63+
64+
# Function to use wolf provider only
65+
use_wolf_provider() {
66+
export OPENSSL_MODULES=$WOLFPROV_PATH
67+
export OPENSSL_CONF=${WOLFPROV_CONFIG}
68+
69+
# Verify that we are using wolfProvider
70+
if ! ${OPENSSL_BIN} list -providers | grep -q "wolfprov"; then
71+
echo "FAIL: unable to switch to wolfProvider, default provider is still active"
72+
exit 1
73+
fi
74+
echo "Switched to wolfProvider"
75+
}
76+
77+
# Helper function to handle force fail checks
78+
check_force_fail() {
79+
if [ "${WOLFPROV_FORCE_FAIL}" = "1" ]; then
80+
echo "[PASS] Test passed when force fail was enabled"
81+
FORCE_FAIL_PASSED=1
82+
fi
83+
}

scripts/cmd_test/do-cmd-tests.sh

Lines changed: 35 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -19,42 +19,50 @@
1919
# You should have received a copy of the GNU General Public License
2020
# along with wolfProvider. If not, see <http://www.gnu.org/licenses/>.
2121

22-
# Get the force fail parameter
23-
if [ "${WOLFPROV_FORCE_FAIL}" = "1" ]; then
24-
echo "Force fail mode enabled for all tests"
25-
fi
26-
if [ "${WOLFSSL_ISFIPS}" = "1" ]; then
27-
echo "FIPS mode enabled for all tests"
28-
fi
29-
3022
# Get the directory where this script is located
3123
SCRIPT_DIR="$( cd "$( dirname "${BASH_SOURCE[0]}" )" &> /dev/null && pwd )"
3224
REPO_ROOT="$( cd "${SCRIPT_DIR}/../.." &> /dev/null && pwd )"
3325
UTILS_DIR="${REPO_ROOT}/scripts"
3426

35-
# Get the built versions
36-
if [ -d "${REPO_ROOT}/openssl-source" ] && [ -d "${REPO_ROOT}/wolfssl-source" ]; then
37-
# Get the actual versions that were built
38-
export OPENSSL_TAG=$(cd ${REPO_ROOT}/openssl-source &&
39-
(git describe --tags 2>/dev/null || git branch --show-current))
40-
export WOLFSSL_TAG=$(cd ${REPO_ROOT}/wolfssl-source &&
41-
(git describe --tags 2>/dev/null || git branch --show-current))
42-
else
43-
echo "[FAIL] OpenSSL or wolfSSL source directories not found"
44-
echo "Please run build-wolfprovider.sh first"
45-
exit 1
46-
fi
27+
source "${SCRIPT_DIR}/cmd-test-common.sh"
4728

48-
# Use the current version tags for testing
49-
export USE_CUR_TAG=1
29+
# If OPENSSL_BIN is not set, assume we are using a local build
30+
if [ -z "${OPENSSL_BIN:-}" ]; then
31+
# Check if the install directories exist
32+
if [ ! -d "${REPO_ROOT}/openssl-install" ] ||
33+
[ ! -d "${REPO_ROOT}/wolfssl-install" ]; then
34+
echo "[FAIL] OpenSSL or wolfSSL install directories not found"
35+
echo "Please set OPENSSL_BIN or run build-wolfprovider.sh first"
36+
exit 1
37+
fi
5038

51-
# Source OpenSSL utilities and initialize OpenSSL
52-
source "${UTILS_DIR}/utils-openssl.sh"
53-
init_openssl
39+
# Setup the environment for a local build
40+
source "${REPO_ROOT}/scripts/env-setup"
41+
else
42+
# We are using a user-provided OpenSSL binary, manually set the test
43+
# environment variables rather than using env-setup.
44+
# Find the location of the wolfProvider modules
45+
if [ -z "${WOLFPROV_PATH:-}" ]; then
46+
export WOLFPROV_PATH=$(find /usr/lib /usr/local/lib -type d -name ossl-modules 2>/dev/null | head -n 1)
47+
fi
48+
# Set the path to the wolfProvider config file
49+
if [ -z "${WOLFPROV_CONFIG:-}" ]; then
50+
if [ "${WOLFSSL_ISFIPS:-0}" = "1" ]; then
51+
export WOLFPROV_CONFIG="${REPO_ROOT}/provider-fips.conf"
52+
else
53+
export WOLFPROV_CONFIG="${REPO_ROOT}/provider.conf"
54+
fi
55+
fi
56+
fi
5457

5558
echo "=== Running wolfProvider Command-Line Tests ==="
56-
echo "Using OpenSSL version: ${OPENSSL_TAG}"
57-
echo "Using wolfSSL version: ${WOLFSSL_TAG}"
59+
echo "Using OPENSSL_BIN: ${OPENSSL_BIN}"
60+
echo "Using WOLFPROV_PATH: ${WOLFPROV_PATH}"
61+
echo "Using WOLFPROV_CONFIG: ${WOLFPROV_CONFIG}"
62+
63+
# Ensure we can switch providers before proceeding
64+
use_default_provider
65+
use_wolf_provider
5866

5967
# Run the hash comparison test
6068
echo -e "\n=== Running Hash Comparison Test ==="

0 commit comments

Comments
 (0)