1111# Exit: 0 = pass, 77 = skip, non-zero = fail
1212#
1313
14+ BUILD_DIR=" $( pwd) "
1415SCRIPT_DIR=" $( cd " $( dirname " $0 " ) " && pwd) "
15- TOP_DIR =" $( cd " $SCRIPT_DIR /.." && pwd) "
16+ SRC_DIR =" $( cd " $SCRIPT_DIR /.." && pwd) "
1617
17- FWTPM_SERVER=" $TOP_DIR /src/fwtpm/fwtpm_server"
18- UNIT_TEST=" $TOP_DIR /tests/unit.test"
19- RUN_EXAMPLES=" $TOP_DIR /examples/run_examples.sh"
18+ FWTPM_SERVER=" $BUILD_DIR /src/fwtpm/fwtpm_server"
19+ UNIT_TEST=" $BUILD_DIR /tests/unit.test"
20+ RUN_EXAMPLES=" $SRC_DIR /examples/run_examples.sh"
2021PID_FILE=" /tmp/fwtpm_check_$$ .pid"
2122
2223PASS=0
@@ -149,7 +150,7 @@ trap cleanup EXIT
149150IS_SWTPM_MODE=0
150151IS_FWTPM_MODE=0
151152HAS_GETENV=1
152- WOLFTPM_OPTIONS=" $TOP_DIR /wolftpm/options.h"
153+ WOLFTPM_OPTIONS=" $BUILD_DIR /wolftpm/options.h"
153154if [ -f " $WOLFTPM_OPTIONS " ]; then
154155 if grep -q " WOLFTPM_SWTPM" " $WOLFTPM_OPTIONS " ; then
155156 IS_SWTPM_MODE=1
@@ -205,6 +206,37 @@ if [ $HAS_RSA_NO_PAD -eq 0 ]; then
205206 SKIP_EXAMPLES=1
206207fi
207208
209+ # --- Auto-detect feature flags for run_examples.sh ---
210+
211+ # Defaults (match run_examples.sh defaults)
212+ WOLFCRYPT_ENABLE=${WOLFCRYPT_ENABLE:- 1}
213+ WOLFCRYPT_RSA=${WOLFCRYPT_RSA:- 1}
214+ WOLFCRYPT_ECC=${WOLFCRYPT_ECC:- 1}
215+ NO_FILESYSTEM=${NO_FILESYSTEM:- 0}
216+ NO_PUBASPRIV=${NO_PUBASPRIV:- 0}
217+ WOLFCRYPT_DEFAULT=${WOLFCRYPT_DEFAULT:- 0}
218+
219+ # Detect from wolftpm/options.h
220+ if [ -f " $WOLFTPM_OPTIONS " ] && grep -q " WOLFTPM2_NO_WOLFCRYPT" " $WOLFTPM_OPTIONS " ; then
221+ WOLFCRYPT_ENABLE=0
222+ fi
223+
224+ # Detect from wolfSSL options.h (system-installed or WOLFSSL_PATH)
225+ WOLFSSL_OPTS=" "
226+ for chk in /usr/local " $WOLFSSL_PATH " ; do
227+ [ -z " $chk " ] && continue
228+ found=$( find_wolfssl_options " $chk " 2> /dev/null)
229+ if [ -n " $found " ]; then WOLFSSL_OPTS=" $found " ; break ; fi
230+ done
231+
232+ if [ -n " $WOLFSSL_OPTS " ]; then
233+ grep -q " NO_RSA" " $WOLFSSL_OPTS " && WOLFCRYPT_RSA=0
234+ grep -q " HAVE_ECC" " $WOLFSSL_OPTS " || WOLFCRYPT_ECC=0
235+ grep -q " NO_FILESYSTEM" " $WOLFSSL_OPTS " && NO_FILESYSTEM=1
236+ grep -q " WOLFSSL_PUBLIC_ASN_PRIV_KEY" " $WOLFSSL_OPTS " || NO_PUBASPRIV=1
237+ grep -q " WOLFSSL_AES_CFB" " $WOLFSSL_OPTS " || WOLFCRYPT_DEFAULT=1
238+ fi
239+
208240# --- Determine port and start/detect server ---
209241
210242# Default port (honor env var override)
@@ -222,11 +254,11 @@ if [ $IS_FWTPM_MODE -eq 1 ]; then
222254 fi
223255 else
224256 # Clean stale artifacts and start our own server
225- rm -f " $TOP_DIR /fwtpm_nv.bin" /tmp/fwtpm.shm
226- rm -f " $TOP_DIR /rsa_test_blob.raw" " $TOP_DIR /ecc_test_blob.raw" \
227- " $TOP_DIR /keyblob.bin"
228- rm -f " $TOP_DIR " /certs/tpm-* -cert.pem " $TOP_DIR " /certs/tpm-* -cert.csr
229- rm -f " $TOP_DIR " /certs/server-* -cert.pem " $TOP_DIR " /certs/client-* -cert.pem
257+ rm -f " $BUILD_DIR /fwtpm_nv.bin" /tmp/fwtpm.shm
258+ rm -f " $BUILD_DIR /rsa_test_blob.raw" " $BUILD_DIR /ecc_test_blob.raw" \
259+ " $BUILD_DIR /keyblob.bin"
260+ rm -f " $BUILD_DIR " /certs/tpm-* -cert.pem " $BUILD_DIR " /certs/tpm-* -cert.csr
261+ rm -f " $BUILD_DIR " /certs/server-* -cert.pem " $BUILD_DIR " /certs/client-* -cert.pem
230262
231263 # Kill any orphaned servers from prior crashed runs (intentional pre-flight)
232264 killall fwtpm_server 2> /dev/null || true
@@ -287,18 +319,18 @@ else
287319 echo " Using external TPM server on port $FWTPM_PORT "
288320
289321 # Clean stale artifacts (NV state belongs to external server, don't touch it)
290- rm -f " $TOP_DIR /rsa_test_blob.raw" " $TOP_DIR /ecc_test_blob.raw" \
291- " $TOP_DIR /keyblob.bin"
292- rm -f " $TOP_DIR " /certs/tpm-* -cert.pem " $TOP_DIR " /certs/tpm-* -cert.csr
293- rm -f " $TOP_DIR " /certs/server-* -cert.pem " $TOP_DIR " /certs/client-* -cert.pem
322+ rm -f " $BUILD_DIR /rsa_test_blob.raw" " $BUILD_DIR /ecc_test_blob.raw" \
323+ " $BUILD_DIR /keyblob.bin"
324+ rm -f " $BUILD_DIR " /certs/tpm-* -cert.pem " $BUILD_DIR " /certs/tpm-* -cert.csr
325+ rm -f " $BUILD_DIR " /certs/server-* -cert.pem " $BUILD_DIR " /certs/client-* -cert.pem
294326fi
295327
296328# --- Run unit tests ---
297329
298330if [ -x " $UNIT_TEST " ]; then
299331 echo " "
300332 echo " === Running unit.test ==="
301- cd " $TOP_DIR "
333+ cd " $BUILD_DIR "
302334 if TPM2_SWTPM_PORT=" $FWTPM_PORT " " $UNIT_TEST " ; then
303335 PASS=$(( PASS + 1 ))
304336 echo " PASS: unit.test"
@@ -319,8 +351,14 @@ if [ $SKIP_EXAMPLES -eq 1 ]; then
319351elif [ -x " $RUN_EXAMPLES " ]; then
320352 echo " "
321353 echo " === Running run_examples.sh ==="
322- cd " $TOP_DIR "
354+ cd " $BUILD_DIR "
323355 if WOLFSSL_PATH=" $WOLFSSL_PATH " TPM2_SWTPM_PORT=" $FWTPM_PORT " \
356+ WOLFCRYPT_ENABLE=" $WOLFCRYPT_ENABLE " \
357+ WOLFCRYPT_RSA=" $WOLFCRYPT_RSA " \
358+ WOLFCRYPT_ECC=" $WOLFCRYPT_ECC " \
359+ NO_FILESYSTEM=" $NO_FILESYSTEM " \
360+ NO_PUBASPRIV=" $NO_PUBASPRIV " \
361+ WOLFCRYPT_DEFAULT=" $WOLFCRYPT_DEFAULT " \
324362 " $RUN_EXAMPLES " ; then
325363 PASS=$(( PASS + 1 ))
326364 echo " PASS: run_examples.sh"
0 commit comments