Skip to content

Commit

Permalink
tests: put test files in builddir/tests/ instead of srcdir/tests/
Browse files Browse the repository at this point in the history
To make folder structure cleaner.

Also change help message from .. termux-elf-cleaner .. to just
.. elf-cleaner .., to make the tool even more general.
  • Loading branch information
Grimler91 committed Dec 30, 2024
1 parent 99e14ec commit b29e7eb
Show file tree
Hide file tree
Showing 3 changed files with 33 additions and 26 deletions.
30 changes: 16 additions & 14 deletions tests/test-dynamic-section.sh
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
set -e

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

Expand All @@ -11,35 +11,37 @@ source_dir="$2"
binary_name="$3"
arch="$4"
api="$5"
test_dir="$(dirname $1)/tests"

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

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_VERNEED 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'"
expected_logs="$progname: Removing VERSYM section from '$test_dir/$testfile'
$progname: Removing VERNEED section from '$test_dir/$testfile'
$progname: Removing the DT_RUNPATH dynamic section entry from '$test_dir/$testfile'
$progname: Removing the DT_VERNEEDNUM dynamic section entry from '$test_dir/$testfile'
$progname: Removing the DT_VERNEED dynamic section entry from '$test_dir/$testfile'
$progname: Removing the DT_VERSYM dynamic section entry from '$test_dir/$testfile'
$progname: Replacing unsupported DF_1_* flags 134217737 with 1 in '$test_dir/$testfile'
$progname: Removing the DT_GNU_HASH dynamic section entry from '$test_dir/$testfile'"
elif [ "$api" = "24" ]; then
expected_logs="$progname: Replacing unsupported DF_1_* flags 134217737 with 9 in '$testfile'"
expected_logs="$progname: Replacing unsupported DF_1_* flags 134217737 with 9 in '$test_dir/$testfile'"
else
echo "Unknown API level $api"
exit 1
fi

cp "$origfile" "$testfile"
if [ "$("$elf_cleaner" --api-level "$api" "$testfile")" != "$expected_logs" ]; then
mkdir -p "$test_dir"
cp "$origfile" "$test_dir/"
if [ "$("$elf_cleaner" --api-level "$api" "$test_dir/$testfile")" != "$expected_logs" ]; then
echo "Logs do not match for $testfile"
exit 1
fi
if not cmp -s "$testfile" "$expectedfile"; then
if not cmp -s "$test_dir/$testfile" "$expectedfile"; then
echo "Expected and actual files differ for $testfile"
exit 1
fi
12 changes: 7 additions & 5 deletions tests/test-threads.sh
Original file line number Diff line number Diff line change
Expand Up @@ -2,30 +2,32 @@
set -e

if [ $# != 2 ]; then
echo "Usage path/to/test-threads.sh <termux-elf-cleaner> <source-dir>"
echo "Usage path/to/test-threads.sh <elf-cleaner> <source-dir>"
exit 1
fi

elf_cleaner="$1"
source_dir="$2"
test_dir="$(dirname $1)/tests"

mkdir -p "$test_dir"
for i in {1..100}; do
for arch in aarch64 arm i686 x86_64; do
for api in 21 24; do
cp "$source_dir/tests/curl-7.83.1-$arch-original" "$source_dir/tests/curl-8.83.1-$arch-api$api-threads-$i.test"
cp "$source_dir/tests/curl-7.83.1-$arch-original" "$test_dir/curl-7.83.1-$arch-api$api-threads-$i.test"
done
done
done

for api in 21 24; do
"$elf_cleaner" --api-level "$api" --quiet --jobs 4 "$source_dir/tests/curl-8.83.1-"*"-api$api-threads"*".test"
"$elf_cleaner" --api-level "$api" --quiet --jobs 4 "$test_dir/curl-7.83.1-"*"-api$api-threads"*".test"
done

for i in {1..100}; do
for arch in aarch64 arm i686 x86_64; do
for api in 21 24; do
if not cmp -s "$source_dir/tests/curl-7.83.1-$arch-api$api-cleaned" "$source_dir/tests/curl-8.83.1-$arch-api$api-threads-$i.test"; then
echo "Expected and actual files differ for $source_dir/tests/curl-8.83.1-$arch-threads-$i.test"
if not cmp -s "$source_dir/tests/curl-7.83.1-$arch-api$api-cleaned" "$test_dir/curl-7.83.1-$arch-api$api-threads-$i.test"; then
echo "Expected and actual files differ for curl-7.83.1-$arch"
exit 1
fi
done
Expand Down
17 changes: 10 additions & 7 deletions tests/test-tls-alignment.sh
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
set -e

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

Expand All @@ -14,24 +14,27 @@ arch="$4"
progname="$(basename "$elf_cleaner")"
basefile="$source_dir/tests/$binary_name-$arch"
origfile="$basefile-original"
testfile="$basefile.test"
testfile="$(basename $basefile).test"
expectedfile="$basefile-tls-aligned"
test_dir="$(dirname $1)/tests"

if [ "$arch" = "aarch64" ] || [ "$arch" = "x86_64" ]; then
expected_logs="$progname: Changing TLS alignment for '$testfile' to 64, instead of 8"
expected_logs="$progname: Changing TLS alignment for '$test_dir/$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"
expected_logs="$progname: Changing TLS alignment for '$test_dir/$testfile' to 32, instead of 8"
else
echo "Unknown architecture $arch"
exit 1
fi

cp "$origfile" "$testfile"
if [ "$("$elf_cleaner" "$testfile")" != "$expected_logs" ]; then
mkdir -p "$test_dir"
cp "$origfile" "$test_dir/$testfile"
# echo "$elf_cleaner" "$test_dir/$testfile"
if [ "$("$elf_cleaner" "$test_dir/$testfile")" != "$expected_logs" ]; then
echo "Logs do not match for $testfile"
exit 1
fi
if not cmp -s "$testfile" "$expectedfile"; then
if not cmp -s "$test_dir/$testfile" "$expectedfile"; then
echo "Expected and actual files differ for $testfile"
exit 1
fi

0 comments on commit b29e7eb

Please sign in to comment.