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 |
| 7 | # SPDX-License-Identifier: Apache-2.0 |
| 8 | # |
| 9 | # Licensed under the Apache License, Version 2.0 (the "License"); you may |
| 10 | # not use this file except in compliance with the License. |
| 11 | # You may obtain a copy of the License at |
| 12 | # |
| 13 | # http://www.apache.org/licenses/LICENSE-2.0 |
| 14 | # |
| 15 | # Unless required by applicable law or agreed to in writing, software |
| 16 | # distributed under the License is distributed on an "AS IS" BASIS, WITHOUT |
| 17 | # WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
| 18 | # See the License for the specific language governing permissions and |
| 19 | # limitations under the License. |
| 20 | |
Gilles Peskine | c25ae6f | 2023-07-25 19:53:04 +0200 | [diff] [blame] | 21 | . "${0%/*}/../demo_common.sh" |
Gilles Peskine | ca14459 | 2021-11-04 12:52:14 +0100 | [diff] [blame] | 22 | |
Gilles Peskine | c25ae6f | 2023-07-25 19:53:04 +0200 | [diff] [blame] | 23 | msg "Test the dynamic loading of libmbed*" |
David Horstmann | 4dfa368 | 2021-11-26 17:58:05 +0000 | [diff] [blame] | 24 | |
Gilles Peskine | c25ae6f | 2023-07-25 19:53:04 +0200 | [diff] [blame] | 25 | program="$programs_dir/test/dlopen" |
| 26 | library_dir="$root_dir/library" |
Gilles Peskine | ca14459 | 2021-11-04 12:52:14 +0100 | [diff] [blame] | 27 | |
Gilles Peskine | f5d2d1c | 2023-07-25 20:13:53 +0200 | [diff] [blame] | 28 | # Skip this test if we don't have a shared library build. Detect this |
| 29 | # through the absence of the demo program. |
| 30 | if [ ! -e "$program" ]; then |
| 31 | msg "$0: this demo requires a shared library build." |
| 32 | # Exit with a success status so that this counts as a pass for run_demos.py. |
| 33 | exit |
| 34 | fi |
| 35 | |
Gilles Peskine | ca14459 | 2021-11-04 12:52:14 +0100 | [diff] [blame] | 36 | # ELF-based Unix-like (Linux, *BSD, Solaris, ...) |
| 37 | if [ -n "${LD_LIBRARY_PATH-}" ]; then |
| 38 | LD_LIBRARY_PATH="$library_dir:$LD_LIBRARY_PATH" |
| 39 | else |
| 40 | LD_LIBRARY_PATH="$library_dir" |
| 41 | fi |
| 42 | export LD_LIBRARY_PATH |
| 43 | |
| 44 | # OSX/macOS |
| 45 | if [ -n "${DYLD_LIBRARY_PATH-}" ]; then |
| 46 | DYLD_LIBRARY_PATH="$library_dir:$DYLD_LIBRARY_PATH" |
| 47 | else |
| 48 | DYLD_LIBRARY_PATH="$library_dir" |
| 49 | fi |
| 50 | export DYLD_LIBRARY_PATH |
| 51 | |
Gilles Peskine | c25ae6f | 2023-07-25 19:53:04 +0200 | [diff] [blame] | 52 | msg "Running dynamic loading test program: $program" |
| 53 | msg "Loading libraries from: $library_dir" |
Gilles Peskine | ca14459 | 2021-11-04 12:52:14 +0100 | [diff] [blame] | 54 | "$program" |