Skip to content

Commit

Permalink
Merge #478
Browse files Browse the repository at this point in the history
478: Run shellcheck on all tests r=Mic92 a=brenoguim



Co-authored-by: Breno Rodrigues Guimaraes <[email protected]>
  • Loading branch information
bors[bot] and brenoguim authored Mar 18, 2023
2 parents 27cbc89 + 3710a70 commit 265b31a
Show file tree
Hide file tree
Showing 9 changed files with 46 additions and 41 deletions.
5 changes: 5 additions & 0 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,11 @@ on:
pull_request:
push:
jobs:
shellcheck:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v3
- run: shellcheck tests/*.sh
nix:
runs-on: ubuntu-latest
steps:
Expand Down
2 changes: 1 addition & 1 deletion tests/endianness.sh
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ for arch in ppc64 ppc64le; do
rm -rf "${SCRATCH}"
mkdir -p "${SCRATCH}"

cp "${srcdir}/endianness/${arch}/main" "${srcdir}/endianness/${arch}/libtest.so" "${SCRATCH}/"
cp "${srcdir:?}/endianness/${arch}/main" "${srcdir}/endianness/${arch}/libtest.so" "${SCRATCH}/"

rpath="${PWD}/${SCRATCH}"

Expand Down
16 changes: 8 additions & 8 deletions tests/modify-execstack.sh
Original file line number Diff line number Diff line change
@@ -1,16 +1,16 @@
#! /bin/sh -e
SCRATCH=scratch/$(basename $0 .sh)
SCRATCH=scratch/$(basename "$0" .sh)
PATCHELF=$(readlink -f "../src/patchelf")

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

cp simple ${SCRATCH}/
cp simple-execstack ${SCRATCH}/
cp libsimple.so ${SCRATCH}/
cp libsimple-execstack.so ${SCRATCH}/
cp simple "${SCRATCH}"/
cp simple-execstack "${SCRATCH}"/
cp libsimple.so "${SCRATCH}"/
cp libsimple-execstack.so "${SCRATCH}"/

cd ${SCRATCH}
cd "${SCRATCH}"


## simple
Expand Down
10 changes: 5 additions & 5 deletions tests/no-rpath-pie-powerpc.sh
Original file line number Diff line number Diff line change
Expand Up @@ -3,17 +3,17 @@ set -x
SCRATCH=scratch/no-rpath-pie-powerpc
READELF=${READELF:-readelf}

no_rpath_bin="${srcdir}/no-rpath-prebuild/no-rpath-pie-powerpc"
no_rpath_bin="${srcdir:?}/no-rpath-prebuild/no-rpath-pie-powerpc"

if [ ! -f $no_rpath_bin ]; then
echo "no 'no-rpath' binary for '$ARCH' in '${srcdir}/no-rpath-prebuild'"
if [ ! -f "$no_rpath_bin" ]; then
echo "no 'no-rpath' binary for '$ARCH' in '${srcdir:?}/no-rpath-prebuild'"
exit 1
fi

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

cp $no_rpath_bin ${SCRATCH}/no-rpath
cp "$no_rpath_bin" ${SCRATCH}/no-rpath

oldRPath=$(../src/patchelf --print-rpath ${SCRATCH}/no-rpath)
if test -n "$oldRPath"; then exit 1; fi
Expand All @@ -30,7 +30,7 @@ fi
# Tests for powerpc PIE endianness regressions
readelfData=$(${READELF} -l ${SCRATCH}/no-rpath 2>&1)

if [ $(echo "$readelfData" | grep "PHDR" | wc -l) != 1 ]; then
if [ "$(echo "$readelfData" | grep -c "PHDR")" != 1 ]; then
# Triggered if PHDR errors appear on stderr
echo "Unexpected number of occurences of PHDR in readelf results"
exit 1
Expand Down
4 changes: 2 additions & 2 deletions tests/no-rpath-prebuild.sh
Original file line number Diff line number Diff line change
Expand Up @@ -14,10 +14,10 @@ if [ -z "$ARCH" ] || [ "$ARCH" = prebuild ] ; then
exit 1
fi

no_rpath_bin="${srcdir}/no-rpath-prebuild/no-rpath-$ARCH"
no_rpath_bin="${srcdir:?}/no-rpath-prebuild/no-rpath-$ARCH"

if [ ! -f "$no_rpath_bin" ]; then
echo "no 'no-rpath' binary for '$ARCH' in '${srcdir}/no-rpath-prebuild'"
echo "no 'no-rpath' binary for '$ARCH' in '${srcdir:?}/no-rpath-prebuild'"
exit 1
fi

Expand Down
2 changes: 1 addition & 1 deletion tests/overlapping-segments-after-rounding.sh
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ if test "$(uname -i)" = x86_64 && test "$(uname)" = Linux; then
rm -rf "${SCRATCH}"
mkdir -p "${SCRATCH}"

cp "${srcdir}/${EXEC_NAME}" "${SCRATCH}/"
cp "${srcdir:?}/${EXEC_NAME}" "${SCRATCH}/"
cd "${SCRATCH}"

${PATCHELF} --force-rpath --remove-rpath --output modified1 "${EXEC_NAME}"
Expand Down
2 changes: 1 addition & 1 deletion tests/phdr-corruption.sh
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ cp "${SONAME}" "${SCRATCH}"
# Check for PT_PHDR entry VirtAddr corruption
readelfData=$(${READELF} -l "${SCRATCH_SO}" 2>&1)

if [ "$(echo "$readelfData" | grep "PHDR" | wc -l)" != 1 ]; then
if [ "$(echo "$readelfData" | grep -c "PHDR")" != 1 ]; then
# Triggered if PHDR errors appear on stderr
echo "ERROR: Unexpected number of occurences of PHDR in readelf results!"
exit 1
Expand Down
12 changes: 6 additions & 6 deletions tests/print-execstack.sh
Original file line number Diff line number Diff line change
@@ -1,14 +1,14 @@
#! /bin/sh -e
SCRATCH=scratch/$(basename $0 .sh)
SCRATCH=scratch/$(basename "$0" .sh)
PATCHELF=$(readlink -f "../src/patchelf")

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

cp simple ${SCRATCH}/
cp simple-execstack ${SCRATCH}/
cp simple "${SCRATCH}"/
cp simple-execstack "${SCRATCH}"/

cd ${SCRATCH}
cd "${SCRATCH}"

if ! ${PATCHELF} --print-execstack simple | grep -q 'execstack: -'; then
echo "wrong execstack detection"
Expand Down
34 changes: 17 additions & 17 deletions tests/rename-dynamic-symbols.sh
Original file line number Diff line number Diff line change
@@ -1,17 +1,17 @@
#!/bin/sh -e
SCRATCH=scratch/$(basename $0 .sh)
SCRATCH=scratch/$(basename "$0" .sh)
PATCHELF=$(readlink -f "../src/patchelf")

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

full_main_name="${PWD}/many-syms-main"
full_lib_name="${PWD}/libmany-syms.so"
chmod -w $full_lib_name $full_main_name
chmod -w "$full_lib_name" "$full_main_name"

suffix="_special_suffix"

cd ${SCRATCH}
cd "${SCRATCH}"

###############################################################################
# Test that all symbols in the dynamic symbol table will have the expected
Expand All @@ -20,16 +20,16 @@ cd ${SCRATCH}
###############################################################################

list_symbols() {
nm -D $@ | awk '{ print $NF }' | sed '/^ *$/d'
nm -D "$@" | awk '{ print $NF }' | sed '/^ *$/d'
}

list_symbols $full_lib_name | cut -d@ -f1 | sort -u | awk "{printf \"%s %s${suffix}\n\",\$1,\$1}" > map
list_symbols $full_lib_name | cut -d@ -f1 | sort -u | awk "{printf \"%s${suffix} %s\n\",\$1,\$1}" > rmap
list_symbols "$full_lib_name" | cut -d@ -f1 | sort -u | awk "{printf \"%s %s${suffix}\n\",\$1,\$1}" > map
list_symbols "$full_lib_name" | cut -d@ -f1 | sort -u | awk "{printf \"%s${suffix} %s\n\",\$1,\$1}" > rmap

${PATCHELF} --rename-dynamic-symbols map --output libmapped.so $full_lib_name
${PATCHELF} --rename-dynamic-symbols map --output libmapped.so "$full_lib_name"
${PATCHELF} --rename-dynamic-symbols rmap --output libreversed.so libmapped.so

list_symbols $full_lib_name | sort > orig_syms
list_symbols "$full_lib_name" | sort > orig_syms
list_symbols libmapped.so | sort > map_syms
list_symbols libreversed.so | sort > rev_syms

Expand All @@ -47,10 +47,10 @@ diff orig_syms map_syms_r > diff_orig_syms_map_syms_r || exit 1
###############################################################################

print_relocation_table() {
readelf -W -r $1 | awk '{ printf "%s\n",$5 }' | cut -f1 -d@
readelf -W -r "$1" | awk '{ printf "%s\n",$5 }' | cut -f1 -d@
}

print_relocation_table $full_lib_name > orig_rel
print_relocation_table "$full_lib_name" > orig_rel
print_relocation_table libmapped.so > map_rel
print_relocation_table libreversed.so > rev_rel

Expand All @@ -69,19 +69,19 @@ diff orig_rel map_rel_r > diff_orig_rel_map_rel_r || exit 1
###############################################################################

echo "# Create the map"
list_symbols --defined-only $full_lib_name | cut -d@ -f1 | sort -u | awk "{printf \"%s %s${suffix}\n\",\$1,\$1}" > map
list_symbols --defined-only "$full_lib_name" | cut -d@ -f1 | sort -u | awk "{printf \"%s %s${suffix}\n\",\$1,\$1}" > map

echo "# Copy all dependencies"
mkdir env
cd env
cp $full_lib_name $full_main_name .
cp "$full_lib_name" "$full_main_name" .

echo "# Apply renaming"
chmod +w *
${PATCHELF} --rename-dynamic-symbols ../map *
chmod +w ./*
${PATCHELF} --rename-dynamic-symbols ../map ./*

echo "# Run the patched tool and libraries"
env LD_BIND_NOW=1 LD_LIBRARY_PATH=${PWD} ./many-syms-main
env LD_BIND_NOW=1 LD_LIBRARY_PATH="${PWD}" ./many-syms-main

# Test that other switches still work when --rename-dynamic-symbols has no effect
echo "SYMBOL_THAT_DOESNT_EXIST ANOTHER_NAME" > map
Expand Down

0 comments on commit 265b31a

Please sign in to comment.