Add shellcheck and a custom linter for test field

This commit is contained in:
Miloš Prchlík 2024-07-26 10:06:15 +02:00
commit 2a1c1558d3
22 changed files with 122 additions and 52 deletions

View file

@ -34,3 +34,25 @@ repos:
rev: "1.26.0"
hooks:
- id: tmt-lint
# - repo: https://github.com/koalaman/shellcheck-precommit
# rev: v0.7.2
# hooks:
# - id: shellcheck
# args: ["--severity=warning"] # Optionally only show errors and warnings
- repo: local
hooks:
- id: shellcheck
name: shellcheck
description: Test shell scripts with shellcheck
entry: shellcheck
language: python
types: [shell]
require_serial: true # shellcheck can detect sourcing this way
- id: custom-lint-checks
name: custom-lint-checks
entry: custom-lint-checks.sh
language: script
pass_filenames: false

37
custom-lint-checks.sh Executable file
View file

@ -0,0 +1,37 @@
#!/bin/bash
RETVAL=0
DELIMITER='=============================================================================='
echo -e "\n${DELIMITER}\nChecking WITH_SCL in tests' main.fmf\n"
# shellcheck disable=SC2044
for i in $(find . -name main.fmf); do
[ "$i" = "./tests/dts-probe-binaries/main.fmf" ] && continue
if grep -q '^test:.*test\.sh' "$i"; then
# shellcheck disable=SC2016
if ! grep -qF 'test: "$WITH_SCL ./test.sh"' "$i"; then
echo "$i does not use WITH_SCL in 'test:'"
RETVAL=1
fi
fi
done
echo "$DELIMITER"
echo -e "\n${DELIMITER}\nChecking for '!=' and ',' used together\n"
# shellcheck disable=SC2044
for i in $(find . -name '*.fmf' -type f); do
if grep -qE 'when:.*!=\s*[a-z0-9_]+,' "$i"; then
echo "$i uses '!=' and ',' together in 'when:'"
grep -E 'when:.*!=\s*[a-z0-9_]+,' "$i"
RETVAL=1
fi
done
echo "$DELIMITER"
echo -en "\nOVERALL RESULT: "
[[ "$RETVAL" -eq 0 ]] && echo PASS || echo FAIL
exit $RETVAL

View file

@ -43,7 +43,7 @@ rlJournalStart
rlAssertExists "tst-auditmod10a.o"
rlRun "objdump -d tst-auditmod10a.o > tst-auditmod10a.disas"
rlLog "Interesting instructions:"
rlLog "$(cat tst-auditmod10a.disas | grep zmm)"
rlLog "$(grep zmm tst-auditmod10a.disas)"
rlAssertGrep "vmovdqa64" tst-auditmod10a.disas
rlAssertGrep "vpbroadcastq" tst-auditmod10a.disas
rlAssertGrep "vpxord" tst-auditmod10a.disas

View file

@ -47,12 +47,12 @@ rlJournalStart
rlLogInfo 'x.o + y.o:'
rlRun "readelf -WS [xy].o"
rlRun "readelf -WS x"
rlLogInfo "$( readelf -WS [xy].o | grep $SECTION_NAME | grep PROGBITS )"
rlLogInfo "$( readelf -WS [xy].o | grep "$SECTION_NAME" | grep PROGBITS )"
rlLogInfo 'x:'
rlLogInfo "$( readelf -WS x | grep $SECTION_NAME )"
rlLogInfo "$( readelf -WS x | grep "$SECTION_NAME" )"
if [ $( readelf -WS [xy].o | grep $SECTION_NAME | grep PROGBITS | wc -l ) -eq 2 ] \
&& [ $( readelf -WS x | grep $SECTION_NAME | wc -l ) -eq 1 ]; then
if [ "$( readelf -WS [xy].o | grep "$SECTION_NAME" | grep -c PROGBITS )" -eq 2 ] \
&& [ "$( readelf -WS x | grep -c "$SECTION_NAME" )" -eq 1 ]; then
rlPass "Debug ranges sections were merged"
else
rlFail "Debug ranges sections were not merged"

View file

@ -46,7 +46,7 @@ rlJournalStart
rlPhaseStartTest
rlRun "gcc v.c -fPIC -shared -olibv.so"
rlRun "gcc u.c -fPIC -shared -olibu.so"
rlRun "gcc t.c -D_GNU_SOURCE -L. -lu -lv -ldl -Wl,-rpath,`pwd` &> out"
rlRun "gcc t.c -D_GNU_SOURCE -L. -lu -lv -ldl -Wl,-rpath,$(pwd) &> out"
rlLogInfo "$(cat out)"
rlAssertNotGrep "warning: hidden symbol .* is referenced" out
rlRun "./a.out"

View file

@ -4,3 +4,8 @@ duration: 10m
link+:
- verifies: https://issues.redhat.com/browse/RHEL-42954
adjust+:
- when: arch != aarch64
because: Test is relevant for aarch64 only
enabled: false

View file

@ -17,11 +17,11 @@ rlJournalStart
rlRun "gcc -O0 -o reproducer reproducer.c"
rlRun "readelf -lW ./reproducer |& tee output"
rlAssertEquals "only two LOAD sections are expected" "$(grep "LOAD" output | wc -l)" "2"
rlAssertEquals "only two LOAD sections are expected" "$(grep -c "LOAD" output)" "2"
rlRun "gcc -O0 -o reproducer -Wl,-z,separate-code reproducer.c"
rlRun "readelf -lW ./reproducer |& tee output"
rlAssertEquals "four LOAD sections are expected" "$(grep "LOAD" output | wc -l)" "4"
rlAssertEquals "four LOAD sections are expected" "$(grep -c "LOAD" output)" "4"
rlPhaseEnd
rlPhaseStartCleanup

View file

@ -6,5 +6,5 @@ link+:
duration: 15m
adjust+:
- when: arch != ppc64le,ppc64
- when: arch != ppc64le and arch != ppc64
enabled: false

View file

@ -40,13 +40,13 @@ rlJournalStart
rlPhaseEnd
for ld in $( ls {/emul/ia32-linux,}/lib*/ld-2* 2> /dev/null); do
rlPhaseStartTest "${ld} from $( rpmquery -f ${ld} )"
filename="$( basename ${ld} ).readline"
rlRun "readelf -S ${ld} > $filename" 0 "[$( basename ${ld} )] Write section headers of ${ld}"
rlPhaseStartTest "$ld from $( rpmquery -f "$ld" )"
filename="$( basename "$ld" ).readline"
rlRun "readelf -S $ld > $filename" 0 "[$( basename "$ld" )] Write section headers of $ld"
if ! [[ "$( rlGetArch )" == "ia64" && ! "${ld}" =~ "emul" ]]; then
rlAssertGrep ".stapsdt.base " $filename || rlLogError "This may be problem for SystemTap"
rlAssertGrep ".stapsdt.base " "$filename" || rlLogError "This may be problem for SystemTap"
fi
rlAssertNotGrep ".stapsdt.base.1" $filename || rlLogError "This may be problem for SystemTap"
rlAssertNotGrep ".stapsdt.base.1" "$filename" || rlLogError "This may be problem for SystemTap"
rlPhaseEnd
done

View file

@ -40,7 +40,7 @@ rlJournalStart
rlPhaseStartTest
rlRun "rpm -ql $PACKAGES | grep windmc > windmc.txt" 0,1
rlLogInfo "$(cat windmc.txt)"
rlRun "FILE_CNT=`cat windmc.txt | wc -l`"
rlRun "FILE_CNT=$(wc -l windmc.txt)"
if [ "$FILE_CNT" == "1" ]; then
rlFail "Either windmg manpage or binary is present - both options are wrong."
elif [ "$FILE_CNT" == "2" ]; then

View file

@ -36,7 +36,7 @@ rlJournalStart
rlPhaseEnd
rlPhaseStartTest
rpm -qd $PACKAGES | grep 'man' | while read -r m; do
rpm -qd "$PACKAGES" | grep 'man' | while read -r m; do
rlLog "$m"
man "$m" | col -b > man.txt
rlRun "[[ $(wc -c <man.txt) -ge 2000 ]]"

View file

@ -56,7 +56,7 @@ rlJournalStart
if [ $HAS_SUPPORT = 1 ]; then
rlPhaseStartTest
rlAssertExists $KO_FILE
rlAssertExists "$KO_FILE"
rlRun "set -o pipefail" 0 "Conserve the non-zero return value through the pipe"
# As suggested by nickc@redhat.com:

View file

@ -42,10 +42,10 @@ rlJournalStart
if [ "${EABI_file}" ]; then
rlLog "EABI_file = $EABI_file"
rlRun "cp -v $EABI_file $TmpDir" 0 "Copy file with GNU/Linux EABI"
local_binary="$(basename ${EABI_file})"
rlAssertExists ${local_binary}
rlRun "strip -R .comment ${local_binary}"
file $local_binary > out
local_binary="$(basename "$EABI_file")"
rlAssertExists "$local_binary"
rlRun "strip -R .comment $local_binary"
file "$local_binary" > out
rlAssertNotGrep "(SYSV)" out
else
rlDie "There's nothing to test."

View file

@ -47,7 +47,7 @@ rlJournalStart
rlLogInfo "$(cat out)"
rlAssertGrep "SONAME must not be empty string; ignored" out
rlRun "objdump -p libfoo.so | grep SONAME | awk '{print \$2}' > soname"
if [ "`stat -c '%s' soname`" != "0" ]; then
if [ "$(stat -c '%s' soname)" != "0" ]; then
rlLogInfo "SONAME='$(cat soname)'"
rlFail "Detected SONAME is empty"
fi

View file

@ -10,6 +10,6 @@ while read -r line; do
echo "Section $section alignment is not multiple of 512"
exit 1
fi
done < <(pe-inspect $1 | grep --text "section")
done < <(pe-inspect "$1" | grep --text "section")
echo "All OK"

View file

@ -35,11 +35,11 @@ __have_kernel_debuginfo () {
local RELEASE ARCH
rlRun "RELEASE=$(uname -r)"
rlRun "ARCH=$(uname -m)"
if ! rpm -q kernel-debuginfo-$RELEASE &>/dev/null; then
if ! rpm -q "kernel-debuginfo-$RELEASE" &>/dev/null; then
rlLogInfo 'kernel-debuginfo not present, trying to install it'
rlRun "dnf install -y --enablerepo=\*debuginfo kernel-debuginfo-$RELEASE"
fi
rlAssertRpm kernel-debuginfo-$RELEASE
rlAssertRpm "kernel-debuginfo-$RELEASE"
}
rlJournalStart

View file

@ -71,9 +71,9 @@ function buTestHeader () {
function buEnterTmpDir () {
rlRun "export TmpDir=$(mktemp -d -p $BU_TMPDIR_PARENT)" 0 "Creating tmp directory"
rlRun "export TmpDir=$(mktemp -d -p "$BU_TMPDIR_PARENT")" 0 "Creating tmp directory"
if [ ! -z "$BU_AS_TEST_USER" ]; then
if [ -n "$BU_AS_TEST_USER" ]; then
username="${1:-$BU_TEST_USER}"
buEnterTestUser "$username"
@ -92,7 +92,7 @@ function buExitTmpDir () {
rlRun "rm -r $TmpDir" 0 "Removing tmp directory"
fi
if [ ! -z "$BU_AS_TEST_USER" ]; then
if [ -n "$BU_AS_TEST_USER" ]; then
username="${1:-$BU_TEST_USER}"
buExitTestUser "$username"
@ -106,18 +106,18 @@ function buPrepareSRPM () {
rlFetchSrcForInstalled "$installed_rpm"
rlRun "export SRPM=`find . -name '*.src.rpm'`"
rlRun "export SRPM=$(find . -name '*.src.rpm')"
rlRun "rpm -ivh --define=\"_topdir $TmpDir\" $SRPM"
rlRun "export SPECDIR=`rpm --define=\"_topdir $TmpDir\" --eval=%_specdir`"
rlRun "export SPECFILE=`find $SPECDIR/ -name '*.spec'`"
rlRun "export SPECDIR=$(rpm --define=\"_topdir $TmpDir\" --eval=%_specdir)"
rlRun "export SPECFILE=$(find "$SPECDIR/" -name '*.spec')"
rlRun "yum-builddep -y --define=\"_topdir $TmpDir\" $builddep_options $SPECFILE"
}
function buBuildSRPM () {
if [ ! -z "$BU_AS_TEST_USER" ]; then
if [ -n "$BU_AS_TEST_USER" ]; then
username="${1:-$BU_TEST_USER}"
rlRun "su - $username -c 'rpmbuild -bc --define=\"_topdir $TmpDir\" $SPECFILE'"

View file

@ -130,7 +130,7 @@ adjust+:
# yamllint disable-line rule:line-length
COLLECTION_PACKAGES: gcc-toolset-13-binutils gcc-toolset-13-binutils-devel gcc-toolset-13-binutils-gold gcc-toolset-13-binutils-gprofng
- when: distro == rhel-9 and collection == gcc-toolset-13 and arch != x86_64,aarch64
- when: distro == rhel-9 and collection == gcc-toolset-13 and arch != x86_64 and arch != aarch64
require+:
- gcc-toolset-13-binutils
- gcc-toolset-13-binutils-devel
@ -203,7 +203,7 @@ adjust+:
# yamllint disable-line rule:line-length
COLLECTION_PACKAGES: gcc-toolset-13-binutils gcc-toolset-13-binutils-devel gcc-toolset-13-binutils-gold gcc-toolset-13-binutils-gprofng
- when: distro == rhel-8 and collection == gcc-toolset-13 and arch != x86_64,aarch64
- when: distro == rhel-8 and collection == gcc-toolset-13 and arch != x86_64 and arch != aarch64
require+:
- gcc-toolset-13-binutils
- gcc-toolset-13-binutils-devel
@ -369,7 +369,7 @@ adjust+:
GCC_PACKAGE: gcc-toolset-13-gcc
COLLECTION_PACKAGES: gcc-toolset-13-binutils gcc-toolset-13-binutils-devel gcc-toolset-13-binutils-gold
- when: distro == centos-stream-8 and collection == gcc-toolset-13 and arch != x86_64,aarch64
- when: distro == centos-stream-8 and collection == gcc-toolset-13 and arch != x86_64 and arch != aarch64
require+:
- gcc-toolset-13-binutils
- gcc-toolset-13-binutils-devel

View file

@ -89,7 +89,7 @@ rlJournalStart
rlLogInfo "REBOOTCOUNT=$REBOOTCOUNT"
rlLogInfo "RPM_BUILD_ID=$RPM_BUILD_ID"
rlRun "GCC=$(rpm -ql $GCC_PACKAGE | grep -E 'usr/bin/gcc$')"
rlRun "GCC=$(rpm -ql "$GCC_PACKAGE" | grep -E 'usr/bin/gcc$')"
rlLogInfo "GCC=$GCC"
rlRun "AFTER_REBOOT=no"
@ -125,7 +125,7 @@ rlJournalStart
rlRun "sed -i \"s/# define buildid .local/%define buildid $RPM_BUILD_ID/\" $SPECFILE"
fi
if [ "`rlGetPrimaryArch`" == "ppc64" ]; then
if [ "$(rlGetPrimaryArch)" == "ppc64" ]; then
TARGET="--target=ppc64"
else
TARGET="--target=$(uname -m)"
@ -158,7 +158,7 @@ rlJournalStart
if [ "$(arch)" = "s390x" ]; then
rlRun "grubby --info=ALL"
rlLogInfo "Default kernel is $(grubby --default-kernel), index $(grubby --default-index)"
rlRun "KERNEL_FILE=$(ls -1 /boot/vmlinuz-*${RPM_BUILD_ID}."$(arch)")"
rlRun "KERNEL_FILE=$(ls -1 "/boot/vmlinuz-*${RPM_BUILD_ID}.$(arch)")"
rlRun "ls -al $KERNEL_FILE"
rlRun "grubby --set-default $KERNEL_FILE"
rlLogInfo "Default kernel is $(grubby --default-kernel), index $(grubby --default-index)"

View file

@ -77,9 +77,9 @@ rlJournalStart
rlRun "objdump --help | grep 'supported architectures' | sed 's/objdump: supported architectures: //' | tr ' ' '\n' > actual_arch"
rlLog "expected targets:"
rlLog "$(cat $expected_tgt_file)"
rlLog "$(cat "$expected_tgt_file")"
rlLog "expected architectures:"
rlLog "$(cat $expected_arch_file)"
rlLog "$(cat "$expected_arch_file")"
rlLog "actual targets:"
rlLog "$(cat actual_tgt)"
rlLog "actual architectures:"

View file

@ -79,22 +79,22 @@ function verify_interesting_cases () {
"Aarch64: Fix DT_RELR with discarded sections" \
"https://issues.redhat.com/browse/RHEL-42765"
verify_test "ld/section-order-1a" \
verify_test "Text Section Ordering \(section-order-1a\)" \
"$tool_log" \
"Implement --section-ordering-file in the BFD linker" \
"https://issues.redhat.com/browse/RHEL-36305"
verify_test "ld/section-order-1b" \
verify_test "Text Section Ordering \(section-order-1b\)" \
"$tool_log" \
"Implement --section-ordering-file in the BFD linker" \
"https://issues.redhat.com/browse/RHEL-36305"
verify_test "ld/section-order-1c" \
verify_test "Data Section Ordering \(section-order-1c\)" \
"$tool_log" \
"Implement --section-ordering-file in the BFD linker" \
"https://issues.redhat.com/browse/RHEL-36305"
verify_test "ld/section-order-1d" \
verify_test "Data Section Ordering \(section-order-1d\)" \
"$tool_log" \
"Implement --section-ordering-file in the BFD linker" \
"https://issues.redhat.com/browse/RHEL-36305"

View file

@ -37,6 +37,12 @@ rlJournalStart
rlPhaseStartSetup
buTestHeader
ARCH="$(rlGetPrimaryArch)"
BUILD_ARCHS="$ARCH"
rlLogInfo "ARCH=$ARCH"
rlLogInfo "BUILD_ARCHS=$BUILD_ARCHS"
buEnterTmpDir
rlRun "LOGDIR=$TmpDir/LOGS"
@ -51,19 +57,19 @@ rlJournalStart
rlPhaseStartSetup "Rebuild binutils"
buBuildSRPM
rlRun "cp $CURRENT_BUILD/binutils/binutils.log $LOGDIR/binutils-$build_arch.log"
rlRun "cp $CURRENT_BUILD/binutils/binutils.sum $LOGDIR/binutils-$build_arch.sum"
rlRun "cp $CURRENT_BUILD/binutils/binutils.log $LOGDIR/binutils-$ARCH.log"
rlRun "cp $CURRENT_BUILD/binutils/binutils.sum $LOGDIR/binutils-$ARCH.sum"
rlRun "cp $CURRENT_BUILD/ld/ld.log $LOGDIR/ld-$build_arch.log"
rlRun "cp $CURRENT_BUILD/ld/ld.sum $LOGDIR/ld-$build_arch.sum"
rlRun "cp $CURRENT_BUILD/ld/ld.log $LOGDIR/ld-$ARCH.log"
rlRun "cp $CURRENT_BUILD/ld/ld.sum $LOGDIR/ld-$ARCH.sum"
rlRun "cp $CURRENT_BUILD/gas/testsuite/gas.log $LOGDIR/gas-$build_arch.log"
rlRun "cp $CURRENT_BUILD/gas/testsuite/gas.sum $LOGDIR/gas-$build_arch.sum"
rlRun "cp $CURRENT_BUILD/gas/testsuite/gas.log $LOGDIR/gas-$ARCH.log"
rlRun "cp $CURRENT_BUILD/gas/testsuite/gas.sum $LOGDIR/gas-$ARCH.sum"
rlPhaseEnd
for TOOL in binutils ld gas; do
tool_label="$TOOL / $build_arch"
tool_log="$LOGDIR/$TOOL-$build_arch"
tool_label="$TOOL / $ARCH"
tool_log="$LOGDIR/$TOOL-$ARCH"
rlPhaseStartTest "$tool_label"
rlLogInfo "$tool_label Summary"