| Gilles Peskine | ca14459 | 2021-11-04 12:52:14 +0100 | [diff] [blame] | 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 | 
| Dave Rodgman | 16799db | 2023-11-02 19:47:20 +0000 | [diff] [blame] | 7 | # SPDX-License-Identifier: Apache-2.0 OR GPL-2.0-or-later | 
| Gilles Peskine | ca14459 | 2021-11-04 12:52:14 +0100 | [diff] [blame] | 8 |  | 
| Gilles Peskine | c25ae6f | 2023-07-25 19:53:04 +0200 | [diff] [blame] | 9 | . "${0%/*}/../demo_common.sh" | 
| Gilles Peskine | ca14459 | 2021-11-04 12:52:14 +0100 | [diff] [blame] | 10 |  | 
| Gilles Peskine | c25ae6f | 2023-07-25 19:53:04 +0200 | [diff] [blame] | 11 | msg "Test the dynamic loading of libmbed*" | 
| David Horstmann | 4dfa368 | 2021-11-26 17:58:05 +0000 | [diff] [blame] | 12 |  | 
| Gilles Peskine | c25ae6f | 2023-07-25 19:53:04 +0200 | [diff] [blame] | 13 | program="$programs_dir/test/dlopen" | 
|  | 14 | library_dir="$root_dir/library" | 
| Gilles Peskine | ca14459 | 2021-11-04 12:52:14 +0100 | [diff] [blame] | 15 |  | 
| Gilles Peskine | f5d2d1c | 2023-07-25 20:13:53 +0200 | [diff] [blame] | 16 | # Skip this test if we don't have a shared library build. Detect this | 
|  | 17 | # through the absence of the demo program. | 
|  | 18 | if [ ! -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 | 
|  | 22 | fi | 
|  | 23 |  | 
| Gilles Peskine | ca14459 | 2021-11-04 12:52:14 +0100 | [diff] [blame] | 24 | # ELF-based Unix-like (Linux, *BSD, Solaris, ...) | 
|  | 25 | if [ -n "${LD_LIBRARY_PATH-}" ]; then | 
|  | 26 | LD_LIBRARY_PATH="$library_dir:$LD_LIBRARY_PATH" | 
|  | 27 | else | 
|  | 28 | LD_LIBRARY_PATH="$library_dir" | 
|  | 29 | fi | 
|  | 30 | export LD_LIBRARY_PATH | 
|  | 31 |  | 
|  | 32 | # OSX/macOS | 
|  | 33 | if [ -n "${DYLD_LIBRARY_PATH-}" ]; then | 
|  | 34 | DYLD_LIBRARY_PATH="$library_dir:$DYLD_LIBRARY_PATH" | 
|  | 35 | else | 
|  | 36 | DYLD_LIBRARY_PATH="$library_dir" | 
|  | 37 | fi | 
|  | 38 | export DYLD_LIBRARY_PATH | 
|  | 39 |  | 
| Gilles Peskine | c25ae6f | 2023-07-25 19:53:04 +0200 | [diff] [blame] | 40 | msg "Running dynamic loading test program: $program" | 
|  | 41 | msg "Loading libraries from: $library_dir" | 
| Gilles Peskine | ca14459 | 2021-11-04 12:52:14 +0100 | [diff] [blame] | 42 | "$program" |