summaryrefslogtreecommitdiff
path: root/tests
diff options
context:
space:
mode:
authorFarid Zakaria <farid.m.zakaria@gmail.com>2021-12-20 17:28:34 -0800
committerFarid Zakaria <farid.m.zakaria@gmail.com>2021-12-20 17:34:26 -0800
commite268662c32464f3a09d3aecf069f906a562ab350 (patch)
tree835e514a4e01b312a36e4f84744dd2971a8972dc /tests
parentd306abeb3549a574408fe8de490415f67f2a486e (diff)
downloadpatchelf-e268662c32464f3a09d3aecf069f906a562ab350.tar.gz
Add a unit test
Diffstat (limited to 'tests')
-rw-r--r--tests/Makefile.am3
-rwxr-xr-xtests/replace-add-needed.sh34
2 files changed, 36 insertions, 1 deletions
diff --git a/tests/Makefile.am b/tests/Makefile.am
index 404f159..b280e62 100644
--- a/tests/Makefile.am
+++ b/tests/Makefile.am
@@ -39,7 +39,8 @@ src_TESTS = \
basic-flags.sh \
set-empty-rpath.sh \
phdr-corruption.sh \
- replace-needed.sh
+ replace-needed.sh \
+ replace-add-needed.sh
build_TESTS = \
$(no_rpath_arch_TESTS)
diff --git a/tests/replace-add-needed.sh b/tests/replace-add-needed.sh
new file mode 100755
index 0000000..b486897
--- /dev/null
+++ b/tests/replace-add-needed.sh
@@ -0,0 +1,34 @@
+#! /bin/sh -e
+SCRATCH=scratch/$(basename $0 .sh)
+PATCHELF=$(readlink -f "../src/patchelf")
+
+rm -rf ${SCRATCH}
+mkdir -p ${SCRATCH}
+
+cp simple ${SCRATCH}/
+cp libfoo.so ${SCRATCH}/
+cp libbar.so ${SCRATCH}/
+
+
+cd ${SCRATCH}
+
+libcldd=$(ldd ./simple | grep -oP "(?<=libc.so.6 => )[^ ]+")
+
+# We have to set the soname on these libraries
+${PATCHELF} --set-soname libbar.so ./libbar.so
+
+# Add a libbar.so so we can rewrite it later
+${PATCHELF} --add-needed libbar.so ./simple
+
+${PATCHELF} --replace-needed libc.so.6 ${libcldd} \
+ --replace-needed libbar.so $(readlink -f ./libbar.so) \
+ --add-needed $(readlink -f ./libfoo.so) \
+ ./simple
+
+exitCode=0
+./simple || exitCode=$?
+
+if test "$exitCode" != 0; then
+ ldd ./simple
+ exit 1
+fi