Skip to content

Commit

Permalink
Add test to set interpreter of same name
Browse files Browse the repository at this point in the history
  • Loading branch information
yuta-hayama authored and Mic92 committed Nov 18, 2024
1 parent 0a64a88 commit 5017be7
Show file tree
Hide file tree
Showing 2 changed files with 58 additions and 1 deletion.
3 changes: 2 additions & 1 deletion tests/Makefile.am
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,8 @@ src_TESTS = \
overlapping-segments-after-rounding.sh \
shared-rpath.sh \
short-first-segment.sh \
empty-note.sh
empty-note.sh \
set-interpreter-same.sh

build_TESTS = \
$(no_rpath_arch_TESTS)
Expand Down
56 changes: 56 additions & 0 deletions tests/set-interpreter-same.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,56 @@
#! /bin/sh -e
SCRATCH=scratch/$(basename "$0" .sh)

./simple

curInterpreter=$(../src/patchelf --print-interpreter ./simple)
echo "current interpreter is $curInterpreter"

rm -rf "${SCRATCH}"
mkdir -p "${SCRATCH}"

cp simple "${SCRATCH}"/

echo "set the same interpreter as the current one"
before_checksum=$(sha256sum ${SCRATCH}/simple)
../src/patchelf --set-interpreter "${curInterpreter}" "${SCRATCH}/simple"
after_checksum=$(sha256sum ${SCRATCH}/simple)

if [ "$before_checksum" != "$after_checksum" ]; then
echo "--set-interpreter should be NOP, but the file has been changed."
exit 1
fi

${SCRATCH}/simple

dummyInterpreter="aaaaaaaaaaaaaaaaaaaaaaaaaaaaaa"

echo "set the dummy interpreter"
before_checksum=$(sha256sum ${SCRATCH}/simple)
../src/patchelf --set-interpreter "${dummyInterpreter}" "${SCRATCH}/simple"
after_checksum=$(sha256sum ${SCRATCH}/simple)

if [ "$before_checksum" = "$after_checksum" ]; then
echo "--set-interpreter should be run, but the file has not been changed."
exit 1
fi

if "${SCRATCH}/simple"; then
echo "simple works, but it shouldn't"
exit 1
fi

echo "set the same interpreter as the current one"
before_checksum=$(sha256sum ${SCRATCH}/simple)
../src/patchelf --set-interpreter "${dummyInterpreter}" "${SCRATCH}/simple"
after_checksum=$(sha256sum ${SCRATCH}/simple)

if [ "$before_checksum" != "$after_checksum" ]; then
echo "--set-interpreter should be NOP, but the file has been changed."
exit 1
fi

if "${SCRATCH}/simple"; then
echo "simple works, but it shouldn't"
exit 1
fi

0 comments on commit 5017be7

Please sign in to comment.