From c28358201597a713ff59b9f51cbbadfd529ce11a Mon Sep 17 00:00:00 2001 From: Yi Wu Date: Thu, 5 Mar 2026 17:32:51 +0000 Subject: [PATCH 1/8] tests: add cmake DESTDIR install test Signed-off-by: Yi Wu --- tests/scripts/components-build-system.sh | 26 ++++++++++++++++++++++++ 1 file changed, 26 insertions(+) diff --git a/tests/scripts/components-build-system.sh b/tests/scripts/components-build-system.sh index c6f29d6ec1..d76a699ce7 100644 --- a/tests/scripts/components-build-system.sh +++ b/tests/scripts/components-build-system.sh @@ -203,6 +203,32 @@ support_test_cmake_as_package_install () { support_test_cmake_out_of_source } +component_test_cmake_install_with_destdir () { + # Remove existing generated files so that we use the ones CMake + # generates + $MAKE_COMMAND neat + + msg "install: cmake with DESTDIR staging" + MBEDTLS_ROOT_DIR="$PWD" + mkdir "$OUT_OF_SOURCE_DIR" + cd "$OUT_OF_SOURCE_DIR" + cmake -DGEN_FILES=ON -DENABLE_PROGRAMS=OFF -DENABLE_TESTING=OFF -DUSE_SHARED_MBEDTLS_LIBRARY=ON -DCMAKE_INSTALL_PREFIX:PATH=/usr "$MBEDTLS_ROOT_DIR" + make + + DESTDIR="$OUT_OF_SOURCE_DIR/stage" make install + + install_libdir="$(sed -n 's/^CMAKE_INSTALL_LIBDIR:PATH=//p' CMakeCache.txt)" + test -n "$install_libdir" + test -L "$OUT_OF_SOURCE_DIR/stage/usr/${install_libdir}/libmbedcrypto.so" + + cd "$MBEDTLS_ROOT_DIR" + rm -rf "$OUT_OF_SOURCE_DIR" +} + +support_test_cmake_install_with_destdir () { + support_test_cmake_out_of_source +} + component_build_cmake_custom_config_file () { # Make a copy of config file to use for the in-tree test cp "$CONFIG_H" include/mbedtls_config_in_tree_copy.h From 909ba268435aa06f1fac440bc0e86cde99341980 Mon Sep 17 00:00:00 2001 From: Yi Wu Date: Thu, 26 Mar 2026 09:23:44 +0000 Subject: [PATCH 2/8] Test: add symlinks and dangling link check Signed-off-by: Yi Wu --- tests/scripts/components-build-system.sh | 34 +++++++++++++++++++++--- 1 file changed, 31 insertions(+), 3 deletions(-) diff --git a/tests/scripts/components-build-system.sh b/tests/scripts/components-build-system.sh index d76a699ce7..0ea52899ae 100644 --- a/tests/scripts/components-build-system.sh +++ b/tests/scripts/components-build-system.sh @@ -217,9 +217,37 @@ component_test_cmake_install_with_destdir () { DESTDIR="$OUT_OF_SOURCE_DIR/stage" make install - install_libdir="$(sed -n 's/^CMAKE_INSTALL_LIBDIR:PATH=//p' CMakeCache.txt)" - test -n "$install_libdir" - test -L "$OUT_OF_SOURCE_DIR/stage/usr/${install_libdir}/libmbedcrypto.so" + install_lib_subdir="$(sed -n 's/^CMAKE_INSTALL_LIBDIR:PATH=//p' CMakeCache.txt)" + if [ -z "$install_lib_subdir" ]; then + echo "Error: Failed to read CMAKE_INSTALL_LIBDIR from CMakeCache.txt" >&2 + exit 1 + fi + + install_lib_path="$OUT_OF_SOURCE_DIR/stage/usr/${install_lib_subdir}" + + if [ ! -L "$install_lib_path/libmbedcrypto.so" ]; then + echo "Error: Expected symlink missing: $install_lib_path/libmbedcrypto.so" >&2 + ls -l "$install_lib_path" >&2 || true + exit 1 + fi + + # Match the install(CODE) logic in library/CMakeLists.txt: + # libmbedcrypto.so.${MBEDTLS_CRYPTO_SOVERSION} -> libmbedcrypto.so.${MBEDTLS_VERSION} + # libmbedcrypto.so -> libmbedcrypto.so.${MBEDTLS_CRYPTO_SOVERSION} + symlink_count="$(find "$install_lib_path" -maxdepth 1 -type l -name 'libmbedcrypto.so*' | wc -l)" + if [ "$symlink_count" -lt 2 ]; then + echo "Error: Expected at least 2 libmbedcrypto.so* symlinks, got $symlink_count" >&2 + ls -l "$install_lib_path"/libmbedcrypto.so* >&2 || true + exit 1 + fi + + for symlink in "$install_lib_path"/libmbedcrypto.so*; do + if [ -L "$symlink" ] && [ ! -e "$symlink" ]; then + echo "Error: Dangling symlink found: $symlink -> $(readlink "$symlink")" >&2 + ls -l "$install_lib_path"/libmbedcrypto.so* >&2 || true + exit 1 + fi + done cd "$MBEDTLS_ROOT_DIR" rm -rf "$OUT_OF_SOURCE_DIR" From a51dc8201cb3f37be4c5e972303a297a91ebbb84 Mon Sep 17 00:00:00 2001 From: Yi Wu Date: Mon, 13 Apr 2026 12:48:01 +0100 Subject: [PATCH 3/8] tests: fix DESTDIR install checks and add macOS compatibility Signed-off-by: Yi Wu --- tests/scripts/components-build-system.sh | 50 ++++++++++-------------- 1 file changed, 21 insertions(+), 29 deletions(-) diff --git a/tests/scripts/components-build-system.sh b/tests/scripts/components-build-system.sh index 0ea52899ae..9c8d794527 100644 --- a/tests/scripts/components-build-system.sh +++ b/tests/scripts/components-build-system.sh @@ -218,39 +218,31 @@ component_test_cmake_install_with_destdir () { DESTDIR="$OUT_OF_SOURCE_DIR/stage" make install install_lib_subdir="$(sed -n 's/^CMAKE_INSTALL_LIBDIR:PATH=//p' CMakeCache.txt)" - if [ -z "$install_lib_subdir" ]; then - echo "Error: Failed to read CMAKE_INSTALL_LIBDIR from CMakeCache.txt" >&2 - exit 1 - fi + [ -n "$install_lib_subdir" ] # Failed to read CMAKE_INSTALL_LIBDIR from CMakeCache.txt install_lib_path="$OUT_OF_SOURCE_DIR/stage/usr/${install_lib_subdir}" - if [ ! -L "$install_lib_path/libmbedcrypto.so" ]; then - echo "Error: Expected symlink missing: $install_lib_path/libmbedcrypto.so" >&2 - ls -l "$install_lib_path" >&2 || true - exit 1 + if [[ "$OSTYPE" == linux* ]]; then + # library/CMakeLists.txt installs libmbedcrypto.so with a versioned + # symlink chain on Linux. + for lib in tfpsacrypto mbedcrypto mbedx509 mbedtls; do + [ -f "$install_lib_path/lib${lib}.a" ] + [ -L "$install_lib_path/lib${lib}.so" ] + [ -e "$install_lib_path/lib${lib}.so" ] + versioned=( "$install_lib_path/lib${lib}.so".* ) + [ -L "${versioned[0]}" ] + [ -e "${versioned[0]}" ] + done + elif [[ "$OSTYPE" == darwin* ]]; then + # On macOS the custom install logic installs libmbedcrypto.dylib + # directly without a versioned symlink chain. + for lib in tfpsacrypto mbedcrypto mbedx509 mbedtls; do + [ -f "$install_lib_path/lib${lib}.a" ] + [ -e "$install_lib_path/lib${lib}.dylib" ] + done + else + echo "Unsupported platform for DESTDIR shared library checks" fi - - # Match the install(CODE) logic in library/CMakeLists.txt: - # libmbedcrypto.so.${MBEDTLS_CRYPTO_SOVERSION} -> libmbedcrypto.so.${MBEDTLS_VERSION} - # libmbedcrypto.so -> libmbedcrypto.so.${MBEDTLS_CRYPTO_SOVERSION} - symlink_count="$(find "$install_lib_path" -maxdepth 1 -type l -name 'libmbedcrypto.so*' | wc -l)" - if [ "$symlink_count" -lt 2 ]; then - echo "Error: Expected at least 2 libmbedcrypto.so* symlinks, got $symlink_count" >&2 - ls -l "$install_lib_path"/libmbedcrypto.so* >&2 || true - exit 1 - fi - - for symlink in "$install_lib_path"/libmbedcrypto.so*; do - if [ -L "$symlink" ] && [ ! -e "$symlink" ]; then - echo "Error: Dangling symlink found: $symlink -> $(readlink "$symlink")" >&2 - ls -l "$install_lib_path"/libmbedcrypto.so* >&2 || true - exit 1 - fi - done - - cd "$MBEDTLS_ROOT_DIR" - rm -rf "$OUT_OF_SOURCE_DIR" } support_test_cmake_install_with_destdir () { From 033e44b4c49011ff9eecc6995ba29b259697ff9f Mon Sep 17 00:00:00 2001 From: Yi Wu Date: Mon, 13 Apr 2026 15:13:52 +0100 Subject: [PATCH 4/8] test: add debug output and fix for win config Signed-off-by: Yi Wu --- tests/scripts/components-build-system.sh | 11 +++++++++-- 1 file changed, 9 insertions(+), 2 deletions(-) diff --git a/tests/scripts/components-build-system.sh b/tests/scripts/components-build-system.sh index 9c8d794527..63a708675e 100644 --- a/tests/scripts/components-build-system.sh +++ b/tests/scripts/components-build-system.sh @@ -222,15 +222,22 @@ component_test_cmake_install_with_destdir () { install_lib_path="$OUT_OF_SOURCE_DIR/stage/usr/${install_lib_subdir}" - if [[ "$OSTYPE" == linux* ]]; then + if [[ "$OSTYPE" != darwin* ]]; then # library/CMakeLists.txt installs libmbedcrypto.so with a versioned # symlink chain on Linux. for lib in tfpsacrypto mbedcrypto mbedx509 mbedtls; do + if [ "$QUIET" -eq 0 ]; then + echo "Checking lib=$lib" + fi [ -f "$install_lib_path/lib${lib}.a" ] [ -L "$install_lib_path/lib${lib}.so" ] [ -e "$install_lib_path/lib${lib}.so" ] versioned=( "$install_lib_path/lib${lib}.so".* ) - [ -L "${versioned[0]}" ] + if [ "$QUIET" -eq 0 ]; then + declare -p versioned + fi + [ "${#versioned[@]}" -ge 1 ] + # [ -L "${versioned[0]}" ] [ -e "${versioned[0]}" ] done elif [[ "$OSTYPE" == darwin* ]]; then From e7e329e70b93147ea918e48bd3fc16cbaa665e5d Mon Sep 17 00:00:00 2001 From: Yi Wu Date: Tue, 14 Apr 2026 10:12:44 +0100 Subject: [PATCH 5/8] test: reorder if-else structure Signed-off-by: Yi Wu --- tests/scripts/components-build-system.sh | 22 ++++++++++------------ 1 file changed, 10 insertions(+), 12 deletions(-) diff --git a/tests/scripts/components-build-system.sh b/tests/scripts/components-build-system.sh index 63a708675e..26aa70a770 100644 --- a/tests/scripts/components-build-system.sh +++ b/tests/scripts/components-build-system.sh @@ -222,7 +222,14 @@ component_test_cmake_install_with_destdir () { install_lib_path="$OUT_OF_SOURCE_DIR/stage/usr/${install_lib_subdir}" - if [[ "$OSTYPE" != darwin* ]]; then + if [[ "$OSTYPE" == darwin* ]]; then + # On macOS the custom install logic installs libmbedcrypto.dylib + # directly without a versioned symlink chain. + for lib in tfpsacrypto mbedcrypto mbedx509 mbedtls; do + [ -f "$install_lib_path/lib${lib}.a" ] + [ -e "$install_lib_path/lib${lib}.dylib" ] + done + else # library/CMakeLists.txt installs libmbedcrypto.so with a versioned # symlink chain on Linux. for lib in tfpsacrypto mbedcrypto mbedx509 mbedtls; do @@ -236,19 +243,10 @@ component_test_cmake_install_with_destdir () { if [ "$QUIET" -eq 0 ]; then declare -p versioned fi - [ "${#versioned[@]}" -ge 1 ] - # [ -L "${versioned[0]}" ] + # [ "${#versioned[@]}" -ge 1 ] + [ -L "${versioned[0]}" ] [ -e "${versioned[0]}" ] done - elif [[ "$OSTYPE" == darwin* ]]; then - # On macOS the custom install logic installs libmbedcrypto.dylib - # directly without a versioned symlink chain. - for lib in tfpsacrypto mbedcrypto mbedx509 mbedtls; do - [ -f "$install_lib_path/lib${lib}.a" ] - [ -e "$install_lib_path/lib${lib}.dylib" ] - done - else - echo "Unsupported platform for DESTDIR shared library checks" fi } From 50d85c11c5b284167c59b4d01d3c3fafd60c8003 Mon Sep 17 00:00:00 2001 From: Yi Wu Date: Tue, 14 Apr 2026 11:06:16 +0100 Subject: [PATCH 6/8] test: versioned symlink order fix Signed-off-by: Yi Wu --- tests/scripts/components-build-system.sh | 14 +++++++++++--- 1 file changed, 11 insertions(+), 3 deletions(-) diff --git a/tests/scripts/components-build-system.sh b/tests/scripts/components-build-system.sh index 26aa70a770..3333b51e5d 100644 --- a/tests/scripts/components-build-system.sh +++ b/tests/scripts/components-build-system.sh @@ -239,13 +239,21 @@ component_test_cmake_install_with_destdir () { [ -f "$install_lib_path/lib${lib}.a" ] [ -L "$install_lib_path/lib${lib}.so" ] [ -e "$install_lib_path/lib${lib}.so" ] + + # do not assume a fixed match ordering. versioned=( "$install_lib_path/lib${lib}.so".* ) if [ "$QUIET" -eq 0 ]; then declare -p versioned fi - # [ "${#versioned[@]}" -ge 1 ] - [ -L "${versioned[0]}" ] - [ -e "${versioned[0]}" ] + versioned_symlink= + for candidate in "${versioned[@]}"; do + if [ -L "$candidate" ]; then + versioned_symlink="$candidate" + break + fi + done + [ -n "$versioned_symlink" ] + [ -e "$versioned_symlink" ] done fi } From 3e8625c396932983566ad7d70dc73ec7d1aa1617 Mon Sep 17 00:00:00 2001 From: Yi Wu Date: Wed, 15 Apr 2026 11:58:23 +0100 Subject: [PATCH 7/8] test: improve symlink checks Signed-off-by: Yi Wu --- tests/scripts/components-build-system.sh | 17 ++++++----------- 1 file changed, 6 insertions(+), 11 deletions(-) diff --git a/tests/scripts/components-build-system.sh b/tests/scripts/components-build-system.sh index 3333b51e5d..2074952ac2 100644 --- a/tests/scripts/components-build-system.sh +++ b/tests/scripts/components-build-system.sh @@ -240,20 +240,15 @@ component_test_cmake_install_with_destdir () { [ -L "$install_lib_path/lib${lib}.so" ] [ -e "$install_lib_path/lib${lib}.so" ] - # do not assume a fixed match ordering. - versioned=( "$install_lib_path/lib${lib}.so".* ) + # Match ABI-version names such as libxxx.so.17 + # and check that symlink. + versioned=( "$install_lib_path/lib${lib}.so".+([0-9]) ) if [ "$QUIET" -eq 0 ]; then declare -p versioned fi - versioned_symlink= - for candidate in "${versioned[@]}"; do - if [ -L "$candidate" ]; then - versioned_symlink="$candidate" - break - fi - done - [ -n "$versioned_symlink" ] - [ -e "$versioned_symlink" ] + [ "${#versioned[@]}" -eq 1 ] + [ -L "${versioned[0]}" ] + [ -e "${versioned[0]}" ] done fi } From 800e7f79284173385355520cccefc08afe471367 Mon Sep 17 00:00:00 2001 From: Yi Wu Date: Mon, 20 Apr 2026 16:54:33 +0100 Subject: [PATCH 8/8] test: remove tfpsacrypto checks in 3.6 DESTDIR install test Signed-off-by: Yi Wu --- tests/scripts/components-build-system.sh | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/tests/scripts/components-build-system.sh b/tests/scripts/components-build-system.sh index 2074952ac2..0cdc51a625 100644 --- a/tests/scripts/components-build-system.sh +++ b/tests/scripts/components-build-system.sh @@ -225,14 +225,14 @@ component_test_cmake_install_with_destdir () { if [[ "$OSTYPE" == darwin* ]]; then # On macOS the custom install logic installs libmbedcrypto.dylib # directly without a versioned symlink chain. - for lib in tfpsacrypto mbedcrypto mbedx509 mbedtls; do + for lib in mbedcrypto mbedx509 mbedtls; do [ -f "$install_lib_path/lib${lib}.a" ] [ -e "$install_lib_path/lib${lib}.dylib" ] done else # library/CMakeLists.txt installs libmbedcrypto.so with a versioned # symlink chain on Linux. - for lib in tfpsacrypto mbedcrypto mbedx509 mbedtls; do + for lib in mbedcrypto mbedx509 mbedtls; do if [ "$QUIET" -eq 0 ]; then echo "Checking lib=$lib" fi