blob: 7280f1d7044ed46085592d34ac7f06cdd8600166 [file] [log] [blame]
Gilles Peskineca144592021-11-04 12:52:14 +01001#!/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
Dave Rodgman16799db2023-11-02 19:47:20 +00007# SPDX-License-Identifier: Apache-2.0 OR GPL-2.0-or-later
Gilles Peskineca144592021-11-04 12:52:14 +01008
Gilles Peskinec25ae6f2023-07-25 19:53:04 +02009. "${0%/*}/../demo_common.sh"
Gilles Peskineca144592021-11-04 12:52:14 +010010
Gilles Peskinec25ae6f2023-07-25 19:53:04 +020011msg "Test the dynamic loading of libmbed*"
David Horstmann4dfa3682021-11-26 17:58:05 +000012
Gilles Peskinec25ae6f2023-07-25 19:53:04 +020013program="$programs_dir/test/dlopen"
14library_dir="$root_dir/library"
Gilles Peskineca144592021-11-04 12:52:14 +010015
Gilles Peskinef5d2d1c2023-07-25 20:13:53 +020016# Skip this test if we don't have a shared library build. Detect this
17# through the absence of the demo program.
18if [ ! -e "$program" ]; then
19 msg "$0: this demo requires a shared library build."
20 # Exit with a success status so that this counts as a pass for run_demos.py.
21 exit
22fi
23
Gilles Peskineca144592021-11-04 12:52:14 +010024# ELF-based Unix-like (Linux, *BSD, Solaris, ...)
25if [ -n "${LD_LIBRARY_PATH-}" ]; then
26 LD_LIBRARY_PATH="$library_dir:$LD_LIBRARY_PATH"
27else
28 LD_LIBRARY_PATH="$library_dir"
29fi
30export LD_LIBRARY_PATH
31
32# OSX/macOS
33if [ -n "${DYLD_LIBRARY_PATH-}" ]; then
34 DYLD_LIBRARY_PATH="$library_dir:$DYLD_LIBRARY_PATH"
35else
36 DYLD_LIBRARY_PATH="$library_dir"
37fi
38export DYLD_LIBRARY_PATH
39
Gilles Peskinec25ae6f2023-07-25 19:53:04 +020040msg "Running dynamic loading test program: $program"
41msg "Loading libraries from: $library_dir"
Gilles Peskineca144592021-11-04 12:52:14 +010042"$program"