Skip to content

Commit

Permalink
split tests as requested by Grimler
Browse files Browse the repository at this point in the history
  • Loading branch information
thunder-coding committed Apr 3, 2024
1 parent b19916f commit 8a44b6f
Show file tree
Hide file tree
Showing 4 changed files with 110 additions and 58 deletions.
32 changes: 28 additions & 4 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -31,8 +31,32 @@ target_compile_definitions("${PACKAGE_NAME}"
PRIVATE "PACKAGE_NAME=\"${PACKAGE_NAME}\""
)


enable_testing()
add_test(
NAME "tests"
COMMAND bash -c "${CMAKE_CURRENT_SOURCE_DIR}/tests/test.sh ${CMAKE_CURRENT_BINARY_DIR}/${PACKAGE_NAME} ${CMAKE_CURRENT_SOURCE_DIR}"
)

# Dynamic section tests
foreach(arch ${ARCHES})
foreach(api ${APIS})
add_test(
NAME "dynamic-section-${arch}-api${api}"
COMMAND ${CMAKE_CURRENT_SOURCE_DIR}/tests/test-dynamic-section.sh
${CMAKE_CURRENT_BINARY_DIR}/${PACKAGE_NAME}
${CMAKE_CURRENT_SOURCE_DIR}
curl-7.83.1
${arch}
${api}
)
endforeach()
endforeach()

# TLS alignment tests
foreach(arch ${ARCHES})
add_test(
NAME "tls-alignment-${arch}-api${api}"
COMMAND ${CMAKE_CURRENT_SOURCE_DIR}/tests/test-tls-alignment.sh
${CMAKE_CURRENT_BINARY_DIR}/${PACKAGE_NAME}
${CMAKE_CURRENT_SOURCE_DIR}
valgrind-3.19.0
${arch}
)
endforeach()
45 changes: 45 additions & 0 deletions tests/test-dynamic-section.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,45 @@
#!/usr/bin/bash
set -e

if [ $# != 5 ]; then
echo "Usage path/to/test-dynamic-section.sh <termux-elf-cleaner> <source-dir> <binary-name> <arch> <api>"
exit 1
fi

elf_cleaner="$1"
source_dir="$2"
binary_name="$3"
arch="$4"
api="$5"

progname="$(basename "$elf_cleaner")"
basefile="$source_dir/tests/$binary_name-$arch"
origfile="$basefile-original"
testfile="$basefile-api$api.test"
expectedfile="$basefile-api$api-cleaned"

if [ "$api" = "21" ]; then
expected_logs="$progname: Removing version section from '$testfile'
$progname: Removing version section from '$testfile'
$progname: Removing the DT_RUNPATH dynamic section entry from '$testfile'
$progname: Removing the DT_VERNEEDNUM dynamic section entry from '$testfile'
$progname: Removing the DT_VERNEEDED dynamic section entry from '$testfile'
$progname: Removing the DT_VERSYM dynamic section entry from '$testfile'
$progname: Replacing unsupported DF_1_* flags 134217737 with 1 in '$testfile'
$progname: Removing the DT_GNU_HASH dynamic section entry from '$testfile'"
elif [ "$api" = "24" ]; then
expected_logs="$progname: Replacing unsupported DF_1_* flags 134217737 with 9 in '$testfile'"
else
echo "Unknown API level $api"
exit 1
fi

cp "$origfile" "$testfile"
if [ "$("$elf_cleaner" --api-level "$api" "$testfile")" != "$expected_logs" ]; then
echo "Logs do not match for $testfile"
exit 1
fi
if not cmp -s "$testfile" "$expectedfile"; then
echo "Expected and actual files differ for $testfile"
exit 1
fi
37 changes: 37 additions & 0 deletions tests/test-tls-alignment.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
#!/usr/bin/bash
set -e

if [ $# != 4 ]; then
echo "Usage path/to/test-dynamic-section.sh <termux-elf-cleaner> <source-dir> <binary-name> <arch>"
exit 1
fi

elf_cleaner="$1"
source_dir="$2"
binary_name="$3"
arch="$4"

progname="$(basename "$elf_cleaner")"
basefile="$source_dir/tests/$binary_name-$arch"
origfile="$basefile-original"
testfile="$basefile.test"
expectedfile="$basefile-tls-aligned"

if [ "$arch" = "aarch64" ] || [ "$arch" = "x86_64" ]; then
expected_logs="$progname: Changing TLS alignment for '$testfile' to 64, instead of 8"
elif [ "$arch" = "arm" ] || [ "$arch" = "i686" ]; then
expected_logs="$progname: Changing TLS alignment for '$testfile' to 32, instead of 8"
else
echo "Unknown architecture $arch"
exit 1
fi

cp "$origfile" "$testfile"
if [ "$("$elf_cleaner" "$testfile")" != "$expected_logs" ]; then
echo "Logs do not match for $testfile"
exit 1
fi
if not cmp -s "$testfile" "$expectedfile"; then
echo "Expected and actual files differ for $testfile"
exit 1
fi
54 changes: 0 additions & 54 deletions tests/test.sh

This file was deleted.

0 comments on commit 8a44b6f

Please sign in to comment.