Skip to content

Commit f3ee625

Browse files
committed
Improve ./configure defaults and expand make check
1 parent 1619b04 commit f3ee625

4 files changed

Lines changed: 96 additions & 78 deletions

File tree

.github/workflows/fwtpm-test.yml

Lines changed: 12 additions & 66 deletions
Original file line numberDiff line numberDiff line change
@@ -166,6 +166,12 @@ jobs:
166166
repository: wolfssl/wolfssl
167167
path: wolfssl
168168

169+
- name: Install tpm2-tools
170+
if: ${{ !matrix.build_only }}
171+
run: |
172+
sudo apt-get update
173+
sudo apt-get install -y tpm2-tools libtss2-tcti-mssim0
174+
169175
- name: ASLR workaround (sanitizers)
170176
if: ${{ matrix.sanitizer }}
171177
run: sudo sysctl vm.mmap_rnd_bits=28
@@ -227,74 +233,14 @@ jobs:
227233
/tmp/fwtpm_check_*.log
228234
retention-days: 5
229235

230-
# ----------------------------------------------------------------
231-
# tpm2-tools compatibility (socket transport)
232-
# ----------------------------------------------------------------
233-
fwtpm-tpm2tools:
234-
runs-on: ubuntu-latest
235-
steps:
236-
- name: Checkout wolfTPM
237-
uses: actions/checkout@v4
238-
239-
- name: Checkout wolfSSL
240-
uses: actions/checkout@v4
241-
with:
242-
repository: wolfssl/wolfssl
243-
path: wolfssl
244-
245-
- name: Build wolfSSL
246-
working-directory: ./wolfssl
247-
run: |
248-
./autogen.sh
249-
./configure --enable-wolftpm --enable-pkcallbacks --enable-keygen \
250-
CFLAGS="-DWC_RSA_NO_PADDING"
251-
make
252-
sudo make install
253-
sudo ldconfig
254-
255-
- name: Install tpm2-tools
256-
run: |
257-
sudo apt-get update
258-
sudo apt-get install -y tpm2-tools libtss2-tcti-mssim0
259-
260-
- name: Build wolfTPM
261-
run: |
262-
./autogen.sh
263-
./configure --enable-fwtpm --enable-swtpm --enable-debug
264-
make
265-
266-
- name: Start fwtpm_server
267-
run: |
268-
rm -f fwtpm_nv.bin
269-
src/fwtpm/fwtpm_server \
270-
> /tmp/fwtpm_srv.log 2>&1 &
271-
echo $! > /tmp/fwtpm_server.pid
272-
sleep 0.5
273-
kill -0 $(cat /tmp/fwtpm_server.pid)
274-
275-
- name: Run tpm2-tools tests
276-
run: scripts/tpm2_tools_test.sh --no-start
277-
278-
- name: Stop fwtpm_server
279-
if: always()
280-
run: |
281-
if [ -f /tmp/fwtpm_server.pid ]; then
282-
kill $(cat /tmp/fwtpm_server.pid) 2>/dev/null || true
283-
fi
284-
285-
- name: Upload failure logs
286-
if: failure()
287-
uses: actions/upload-artifact@v4
288-
with:
289-
name: fwtpm-tpm2tools-logs
290-
path: |
291-
/tmp/fwtpm_srv.log
292-
/tmp/fwtpm_tpm2tools_srv.log
293-
retention-days: 5
294-
295236
# ----------------------------------------------------------------
296237
# tpm2-tools compatibility test against IBM SW TPM
297-
# Validates that tpm2_tools_test.sh works on a reference TPM
238+
# Validates that tpm2_tools_test.sh works on a reference TPM.
239+
#
240+
# NOTE: tpm2-tools compatibility against fwtpm_server is now exercised
241+
# by the fwtpm-examples matrix entries (fwtpm-socket, fwtpm-asan,
242+
# fwtpm-ubsan) via `make check` — the standalone fwtpm-tpm2tools job
243+
# was removed to eliminate duplication.
298244
# ----------------------------------------------------------------
299245
ibmswtpm-tpm2tools:
300246
runs-on: ubuntu-latest

configure.ac

Lines changed: 24 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -225,11 +225,31 @@ then
225225
AM_CFLAGS="$AM_CFLAGS -DWOLFTPM_LINUX_DEV"
226226
fi
227227

228+
# Native host defaults — auto-enable fwTPM and swTPM on Linux/BSD x86_64 / aarch64
229+
# so `make check` provides full coverage out of the box. Users can still
230+
# explicitly disable with --disable-fwtpm / --disable-swtpm.
231+
WOLFTPM_DEFAULT_FWTPM=no
232+
WOLFTPM_DEFAULT_SWTPM=no
233+
case $host_cpu in
234+
x86_64|amd64|aarch64)
235+
# Defensive exclusion: fwtpm_server uses POSIX sockets and is not
236+
# currently portable to Windows / Darwin. Auto-enable on Linux/BSD only.
237+
case $host_os in
238+
*mingw*|*cygwin*|*msys*|*darwin*|*win32*)
239+
;;
240+
*)
241+
WOLFTPM_DEFAULT_FWTPM=yes
242+
WOLFTPM_DEFAULT_SWTPM=yes
243+
;;
244+
esac
245+
;;
246+
esac
247+
228248
# SW TPM device Support
229249
AC_ARG_ENABLE([swtpm],
230-
[AS_HELP_STRING([--enable-swtpm],[Enable use of TPM through the SW socket driver (default: disabled)])],
250+
[AS_HELP_STRING([--enable-swtpm],[Enable use of TPM through the SW socket driver (default: enabled on Linux x86_64/aarch64, disabled elsewhere)])],
231251
[ ENABLED_SWTPM=$enableval ],
232-
[ ENABLED_SWTPM=no ]
252+
[ ENABLED_SWTPM=$WOLFTPM_DEFAULT_SWTPM ]
233253
)
234254

235255
# SWTPM port configuration
@@ -279,9 +299,9 @@ AC_SUBST([DISTCHECK_SWTPM_PORT_FLAG])
279299

280300
# Firmware TPM (fwTPM) - software TPM 2.0 simulator
281301
AC_ARG_ENABLE([fwtpm],
282-
[AS_HELP_STRING([--enable-fwtpm],[Enable firmware TPM (fwTPM) server (default: disabled)])],
302+
[AS_HELP_STRING([--enable-fwtpm],[Enable firmware TPM (fwTPM) server (default: enabled on Linux x86_64/aarch64, disabled elsewhere)])],
283303
[ ENABLED_FWTPM=$enableval ],
284-
[ ENABLED_FWTPM=no ]
304+
[ ENABLED_FWTPM=$WOLFTPM_DEFAULT_FWTPM ]
285305
)
286306

287307
if test "x$ENABLED_FWTPM" = "xyes"

scripts/tpm2_tools_test.sh

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,11 @@
66
# Usage:
77
# scripts/tpm2_tools_test.sh [--no-start] [--verbose] [--tcti=mssim|swtpm]
88
#
9+
# Environment:
10+
# TPM2_SWTPM_PORT TCP port the running TPM server listens on (default: 2321).
11+
# Used when this script is invoked from `make check` to
12+
# target the random port picked by tests/fwtpm_check.sh.
13+
#
914
# Requirements: tpm2-tools >= 5.0, libtss2-tcti-mssim (or libtss2-tcti-swtpm)
1015
#
1116
# Exit: 0 if all tests pass, 77 if tpm2-tools not installed (SKIP), 1 on failure
@@ -19,7 +24,7 @@ WOLFTPM_ROOT="$(cd "$SCRIPT_DIR/.." && pwd)"
1924
# wolfTPM fwtpm_server auto-detects the TCTI protocol (mssim or swtpm).
2025
# Both are supported. Default to mssim for backward compatibility.
2126
TCTI_TYPE="${TCTI_TYPE:-mssim}"
22-
export TPM2TOOLS_TCTI="${TCTI_TYPE}:host=localhost,port=2321"
27+
export TPM2TOOLS_TCTI="${TCTI_TYPE}:host=localhost,port=${TPM2_SWTPM_PORT:-2321}"
2328
TEST_TMPDIR=/tmp/fwtpm_tpm2tools
2429
VERBOSE=0
2530
NO_START=0
@@ -38,7 +43,7 @@ for arg in "$@"; do
3843
--no-start) NO_START=1 ;;
3944
--tcti=*)
4045
TCTI_TYPE="${arg#--tcti=}"
41-
export TPM2TOOLS_TCTI="${TCTI_TYPE}:host=localhost,port=2321"
46+
export TPM2TOOLS_TCTI="${TCTI_TYPE}:host=localhost,port=${TPM2_SWTPM_PORT:-2321}"
4247
;;
4348
--help|-h)
4449
grep '^#' "$0" | sed 's/^# \{0,1\}//' | head -12; exit 0 ;;
@@ -160,7 +165,7 @@ server_stop() {
160165
server_restart() {
161166
# Send tpm2_shutdown to flush volatile state before stopping server.
162167
# Use explicit TCTI in case environment is not set.
163-
TPM2TOOLS_TCTI="${TCTI_TYPE}:host=localhost,port=2321" \
168+
TPM2TOOLS_TCTI="${TCTI_TYPE}:host=localhost,port=${TPM2_SWTPM_PORT:-2321}" \
164169
tpm2_shutdown 2>/dev/null || true
165170
sleep 0.2
166171

tests/fwtpm_check.sh

Lines changed: 52 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -390,11 +390,58 @@ fi
390390

391391
# --- Run tpm2-tools tests if available ---
392392

393-
# tpm2-tools tests are handled by their own CI job (fwtpm-tpm2tools)
394-
# and scripts/tpm2_tools_test.sh. Not included in make check because
395-
# the test script hardcodes port 2321 and we use random ports here.
396-
echo "SKIP: tpm2-tools (run separately via scripts/tpm2_tools_test.sh)"
397-
SKIP=$((SKIP + 1))
393+
# tpm2-tools speaks TCP TCTI (mssim/swtpm) only — TIS/SHM-only builds have no
394+
# socket and must skip. Otherwise reuse our fwtpm_server on $FWTPM_PORT and
395+
# call the script with --no-start. The script honors TPM2_SWTPM_PORT.
396+
TPM2_TOOLS_SCRIPT="$SRC_DIR/scripts/tpm2_tools_test.sh"
397+
if [ $IS_SWTPM_MODE -ne 1 ]; then
398+
echo "SKIP: tpm2-tools (requires --enable-swtpm for TCP socket transport)"
399+
SKIP=$((SKIP + 1))
400+
elif [ -x "$TPM2_TOOLS_SCRIPT" ]; then
401+
echo ""
402+
echo "=== Running tpm2_tools_test.sh ==="
403+
cd "$BUILD_DIR"
404+
405+
# Restart fwtpm_server with a clean NV file so the tpm2-tools tests get
406+
# isolated state. tpm2_clear is not enough — example NV indices created
407+
# in run_examples.sh (e.g. 0x1500001) are not always cleared by it.
408+
# Only restart if we actually started the server ourselves.
409+
if [ $STARTED_SERVER -eq 1 ]; then
410+
if [ -f "$PID_FILE" ]; then
411+
kill "$(cat "$PID_FILE")" 2>/dev/null || true
412+
sleep 0.3
413+
fi
414+
rm -f "$BUILD_DIR/fwtpm_nv.bin"
415+
"$FWTPM_SERVER" --port "$FWTPM_PORT" \
416+
--platform-port "$FWTPM_PLAT_PORT" \
417+
> /tmp/fwtpm_check_$$.log 2>&1 &
418+
echo $! > "$PID_FILE"
419+
if ! wait_for_port "$FWTPM_PORT" 500; then
420+
echo "FAIL: fwtpm_server restart failed before tpm2-tools tests"
421+
cat /tmp/fwtpm_check_$$.log
422+
FAIL=$((FAIL + 1))
423+
echo ""
424+
echo "=== fwTPM Integration Results: $PASS passed, $FAIL failed, $SKIP skipped ==="
425+
exit 1
426+
fi
427+
fi
428+
429+
TPM2_SWTPM_PORT="$FWTPM_PORT" "$TPM2_TOOLS_SCRIPT" --no-start
430+
rc=$?
431+
if [ $rc -eq 0 ]; then
432+
PASS=$((PASS + 1))
433+
echo "PASS: tpm2_tools_test.sh"
434+
elif [ $rc -eq 77 ]; then
435+
SKIP=$((SKIP + 1))
436+
echo "SKIP: tpm2_tools_test.sh (tpm2-tools not installed)"
437+
else
438+
FAIL=$((FAIL + 1))
439+
echo "FAIL: tpm2_tools_test.sh (exit $rc)"
440+
fi
441+
else
442+
echo "SKIP: tpm2_tools_test.sh not found"
443+
SKIP=$((SKIP + 1))
444+
fi
398445

399446
echo ""
400447
echo "=== fwTPM Integration Results: $PASS passed, $FAIL failed, $SKIP skipped ==="

0 commit comments

Comments
 (0)