dlopen_demo.sh (1540B)
1 #!/bin/sh 2 3 # Run the shared library dynamic loading demo program. 4 # This is only expected to work when Mbed TLS is built as a shared library. 5 6 # Copyright The Mbed TLS Contributors 7 # SPDX-License-Identifier: Apache-2.0 OR GPL-2.0-or-later 8 9 SCRIPT_DIR=$(dirname "$0") 10 . "${SCRIPT_DIR}/../../scripts/demo_common.sh" 11 12 msg "Test the dynamic loading of libmbed*" 13 14 # Once demo_common.sh is sourced we'll have $root_dir pointing to the root 15 # path of Mbed TLS or TF-PSA-Crypto. 16 if is_mbedtls_root $root_dir; then 17 msg "Running in Mbed TLS repo" 18 program="$root_dir/programs/test/dlopen" 19 library_dir="$root_dir/library" 20 else 21 msg "Running in TF-PSA-Crypto repo" 22 program="$root_dir/programs/test/tfpsacrypto_dlopen" 23 library_dir="$root_dir/core" 24 fi 25 26 # Skip this test if we don't have a shared library build. Detect this 27 # through the absence of the demo program. 28 if [ ! -e "$program" ]; then 29 msg "Error: demo program $program not found." 30 # Exit with a success status so that this counts as a pass for run_demos.py. 31 exit 32 fi 33 34 # ELF-based Unix-like (Linux, *BSD, Solaris, ...) 35 if [ -n "${LD_LIBRARY_PATH-}" ]; then 36 LD_LIBRARY_PATH="$library_dir:$LD_LIBRARY_PATH" 37 else 38 LD_LIBRARY_PATH="$library_dir" 39 fi 40 export LD_LIBRARY_PATH 41 42 # OSX/macOS 43 if [ -n "${DYLD_LIBRARY_PATH-}" ]; then 44 DYLD_LIBRARY_PATH="$library_dir:$DYLD_LIBRARY_PATH" 45 else 46 DYLD_LIBRARY_PATH="$library_dir" 47 fi 48 export DYLD_LIBRARY_PATH 49 50 msg "Running dynamic loading test program: $program" 51 msg "Loading libraries from: $library_dir" 52 "$program"