From 9080b2716a6da5641db5150f5641c2e94f26e844 Mon Sep 17 00:00:00 2001 From: Jesus Checa Hidalgo Date: Wed, 17 Jul 2024 12:55:17 +0200 Subject: [PATCH 1/6] Update test relevancy for compat packages llvm-test-suite and rpmmacros tests disabled for compat packages --- tests/llvm-test-suite/main.fmf | 4 ++++ tests/rpmmacros/main.fmf | 9 +++++++++ 2 files changed, 13 insertions(+) diff --git a/tests/llvm-test-suite/main.fmf b/tests/llvm-test-suite/main.fmf index e084bd1..9deb601 100644 --- a/tests/llvm-test-suite/main.fmf +++ b/tests/llvm-test-suite/main.fmf @@ -8,6 +8,10 @@ adjust+: or distro == centos enabled: false + - because: "llvm test suite not built for compat packages" + enabled: false + when: compat is defined + require+: - git - clang diff --git a/tests/rpmmacros/main.fmf b/tests/rpmmacros/main.fmf index 05c3245..45e3ded 100644 --- a/tests/rpmmacros/main.fmf +++ b/tests/rpmmacros/main.fmf @@ -4,3 +4,12 @@ require+: - clang-devel extra-summary: /tools/clang/rpmmacros extra-task: /tools/clang/rpmmacros + +adjust+: + # From spec file: + # File in the macros file for other packages to use. We are not doing this + # in the compat package, because the version macros would conflict with + # eachother if both clang and the clang compat package were installed together. + - because: "macros.clang is not added to compat packages" + enabled: false + when: compat is defined From bf7e2faa36dfe6e15e5e0bbdb3ebbc92eed2d6b9 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Timm=20B=C3=A4der?= Date: Wed, 22 May 2024 12:05:09 +0200 Subject: [PATCH 2/6] Enable pie-rpm test by default --- tests/pie-rpm/main.fmf | 4 ---- 1 file changed, 4 deletions(-) diff --git a/tests/pie-rpm/main.fmf b/tests/pie-rpm/main.fmf index 0a35fb6..1b276b9 100644 --- a/tests/pie-rpm/main.fmf +++ b/tests/pie-rpm/main.fmf @@ -6,10 +6,6 @@ require+: - rpm-build - glibc-static -# TODO: Untag this test when redhat-rpm-config is modified. -# See: https://src.fedoraproject.org/rpms/redhat-rpm-config/pull-request/291 -tag: not-in-default - adjust+: - enabled: false when: distro != fedora or distro < fedora-40 From 71a2b1c3bfc0b1908f057783c2c0f98849be6f37 Mon Sep 17 00:00:00 2001 From: Jesus Checa Hidalgo Date: Tue, 16 Jul 2024 08:36:56 +0200 Subject: [PATCH 3/6] Refactor kernel-ark build test for caching and git clone retry This commit mitigates test failures due to git unreliability and improves test time over test reruns using cached SRPMs. - Added CACHE_DIR_BASE, KERNEL_SRPM_PATTERN and KERNEL SRPM variables. - Implemented checkCache() to look for an existing SRPM in the cache and install its build dependencies. - Implemented cloneKernelTree() for cloning the kernel-ark repo with retries. - Implemented generateSRPM() to handle all operations required to generate an SRPM and cache it. - Updated main test phase to utilize caching and SRPM generation functions. --- tests/kernel-ark-build/runtest.sh | 162 +++++++++++++++++++++++------- 1 file changed, 124 insertions(+), 38 deletions(-) diff --git a/tests/kernel-ark-build/runtest.sh b/tests/kernel-ark-build/runtest.sh index 7342048..f9b217f 100755 --- a/tests/kernel-ark-build/runtest.sh +++ b/tests/kernel-ark-build/runtest.sh @@ -2,11 +2,17 @@ # vim: dict+=/usr/share/beakerlib/dictionary.vim cpt=.,w,b,u,t,i,k . /usr/share/beakerlib/beakerlib.sh || exit 1 -## General configuration variables. Can be overriden via environment +## General configuration variables. Can be overridden via environment # Kernel branch to build. Typically ark-latest or os-build. KERNEL_BRANCH=${KERNEL_BRANCH:-"ark-latest"} KERNEL_GIT_URL=${KERNEL_GIT_URL:-"https://gitlab.com/cki-project/kernel-ark.git"} +## Helper variables to handle cached/generated SRPM +CACHE_DIR_BASE="/var/tmp/kernel-" +KERNEL_SRPM_PATTERN="kernel-*.src.rpm" +# Path to the kernel SRPM to build. +KERNEL_SRPM="" + # Environment variables to configure the kernel build: # * ENABLE_LTO: If set, it will build kernel-ark with clang_lto. # * ENABLE_DEBUG: If set, it will build kernel-ark in debug mode. @@ -16,8 +22,8 @@ CLANG_MODE=${CLANG_MODE:-"--with clang"} BUILD_MODE=${ENABLE_DEBUG:+"--with debug --without base"} BUILD_MODE=${BUILD_MODE:-"--with base --without debug"} -function logTmtRequiredPackages(){ - # Get the expected packages from TMT metadata requires +# Log installed packages required by TMT +logTmtRequiredPackages() { if [[ ! -e $TMT_TEST_METADATA ]]; then rlLogWarning "${FUNCNAME[0]}: No TMT_TEST_METADATA file found. Run the test from tmt" return @@ -26,15 +32,109 @@ function logTmtRequiredPackages(){ rlLog "# Installed packages:" rlLog "#----------------------------#" for pkg in $TMT_REQUIRES; do - rlAssertRpm $pkg - done; + rlAssertRpm "$pkg" + done rlLog "#----------------------------#" +} +# Check if a previous test run created a kernel SRPM for the latest commit +# If found, the abspath is stored in KERNEL_SRPM global variable +# Returns 0 if srpm found, 1 otherwise. +checkCache() { + local commit_hash + local cache_dir + local cached_srpm + + commit_hash=$(git ls-remote "${KERNEL_GIT_URL}" "${KERNEL_BRANCH}" | awk '{print $1}') + rlLog "Latest commit for ${KERNEL_BRANCH} branch: $commit_hash" + + cache_dir="${CACHE_DIR_BASE}${commit_hash}/" + if [[ -d "$cache_dir" ]]; then + cached_srpm=$(find "$cache_dir" -name "${KERNEL_SRPM_PATTERN}") + if [[ -n "$cached_srpm" ]]; then + rlLog "Found cached SRPM: $cached_srpm" + rlRun "dnf builddep -y $cached_srpm > install-buildreqs.log 2>&1" + rlFileSubmit install-buildreqs.log + KERNEL_SRPM="$cached_srpm" + return 0 + fi + fi + rlLog "Cached kernel SRPM not found" + return 1 +} + +# Attempts to clone the kernel-ark tree in the CWD, at most 3 times. +# Returns 0 on success, 1 otherwise +cloneKernelTree() { + local retries=3 + local delay=10 + + rlLog "Cloning kernel" + while [[ $retries -gt 0 ]]; do + rlRun "git clone -q --branch ${KERNEL_BRANCH} ${KERNEL_GIT_URL}" 0-255 + retcode=$? + if [[ $retcode -eq 0 ]]; then + return 0 + else + retries=$((retries - 1)) + rlLog "Clone failed, wait ${delay}s and retry ($retries retries left)" + sleep $delay + fi + done + return $retcode +} + +# In a kernel-ark repository, do all the operations needed to generate an SRPM +# If the kernel is generated return the abspath in KERNEL_SRPM global variable +# Returns 0 on success, 1 otherwise +generateSRPM() { + local generated_srpm + local commit_hash + local cache_dir + + if ! cloneKernelTree; then + rlFail "Failed to clone kernel tree" + return 1 + fi + + rlRun "pushd kernel-ark" + rlLog "Gathering and installing missing build requirements" + rlRun "make dist-get-buildreqs > make-buildreqs.log 2>&1" + rlFileSubmit make-buildreqs.log + if grep -q 'Missing dependencies:' make-buildreqs.log; then + rlRun "KERNEL_BUILDREQS=\"$(sed -n 's/Missing dependencies://p' make-buildreqs.log)\"" + rlRun 'dnf install -y ${KERNEL_BUILDREQS} > install-buildreqs.log 2>&1' + rlFileSubmit install-buildreqs.log + elif grep 'PASS:' make-buildreqs.log; then + rlLog "All dependencies were already installed" + else + rlLogWarning "Error getting dependencies, the build might fail" + rlRun "cat make-buildreqs.log" + fi + + rlLog "Generating SRPM" + rlRun "make dist-srpm > dist-srpm.log 2>&1" + rlFileSubmit dist-srpm.log + + generated_srpm=$(find "$(pwd)" -name "$KERNEL_SRPM_PATTERN") + if [[ -e "$generated_srpm" ]]; then + rlLog "Caching generated SRPM" + commit_hash=$(git rev-parse HEAD) + cache_dir="${CACHE_DIR_BASE}${commit_hash}/" + rlRun "mkdir -p $cache_dir" + rlRun "cp $generated_srpm $cache_dir" + KERNEL_SRPM="$generated_srpm" + rlRun "popd" + return 0 + else + rlLogWarning "Failed to generate SRPM" + rlRun "popd" + return 1 + fi } rlJournalStart rlPhaseStartSetup - # Log system mem/cpus and packages installed by tmt rlRun "nproc" rlRun "free -h" logTmtRequiredPackages @@ -49,42 +149,28 @@ rlJournalStart rlPhaseEnd rlPhaseStartTest - # TODO It would be fantastic to find out a way to shallow clone without - # breaking the dist-get-buildreqs and dist-srpm make targets, because - # a complete clone takes about 5GiB and a LOT of time... - rlLog "Cloning kernel" - rlRun "git clone --branch ${KERNEL_BRANCH} ${KERNEL_GIT_URL}" - rlRun 'cd kernel-ark' - - rlLog "Gathering and installing missing build requirements" - rlRun "make dist-get-buildreqs > make-buildreqs.log" - rlFileSubmit make-buildreqs.log - if grep 'Missing dependencies:' make-buildreqs.log; then - rlRun "KERNEL_BUILDREQS=\"$(sed -n 's/Missing dependencies://p' make-buildreqs.log)\"" - rlRun 'dnf install -y ${KERNEL_BUILDREQS} > install-buildreqs.log 2>&1' - rlFileSubmit install-buildreqs.log - elif grep 'PASS:' make-buildreqs.log; then - rlLog "All dependencies were already installed" + # Check if kernel package was generated by a previous test run + # and generate a new one if it wasn't + checkCache + if [[ -e "$KERNEL_SRPM" ]]; then + rlLog "Using cached kernel SRPM: $KERNEL_SRPM" else - rlLogWarning "Error getting dependencies, the build might fail" - rlRun "cat make-buildreqs.log" + rlLog "No kernel SRPM found, generating new SRPM" + generateSRPM fi - rlLog "Generating srpm" - rlRun 'make dist-srpm > dist-srpm.log 2>&1' - rlRun 'KERNEL_SRPM=$(find . -name kernel-*.src.rpm)' - rlFileSubmit dist-srpm.log - - # Prepare the flags to be passed to rpmbuild depending on the configuration - BUILD_FLAGS="--target $(uname -m) --with up --with toolchain_clang " - BUILD_FLAGS+="--without trace --without arm64_16k --without arm64_64k " - BUILD_FLAGS+="--without realtime --without zfcpdump " - BUILD_FLAGS+="${CLANG_MODE} ${BUILD_MODE}" - - rlLog "Building kernel (branch $KERNEL_BRANCH)" - rlRun "rpmbuild ${BUILD_FLAGS} --rebuild ${KERNEL_SRPM} > build.log 2>&1" - rlFileSubmit build.log + if [[ -e "$KERNEL_SRPM" ]]; then + BUILD_FLAGS="--target $(uname -m) --with up --with toolchain_clang " + BUILD_FLAGS+="--without trace --without arm64_16k --without arm64_64k " + BUILD_FLAGS+="--without realtime --without zfcpdump " + BUILD_FLAGS+="${CLANG_MODE} ${BUILD_MODE}" + rlLog "Building kernel (branch $KERNEL_BRANCH)" + rlRun "rpmbuild ${BUILD_FLAGS} --rebuild ${KERNEL_SRPM} > build.log 2>&1" + rlFileSubmit build.log + else + rlFail "Kernel SRPM not found, finishing test" + fi rlPhaseEnd rlPhaseStartCleanup From cda9761d2e9853bf34aa566dfb028e31fc2d0226 Mon Sep 17 00:00:00 2001 From: Jesus Checa Hidalgo Date: Mon, 5 Aug 2024 09:15:19 +0200 Subject: [PATCH 4/6] Shell static analysis Add pre-commit hook for static analysis on shell scripts (shellcheck) Fixed lots of issues flagged by shellcheck. --- .pre-commit-config.yaml | 7 +++++ tests/fedora-flags/runtest.sh | 7 +++-- tests/gcc-clang-compatibility/runtest.sh | 20 ++++++------ tests/kernel-ark-build/runtest.sh | 16 ++++++++-- tests/libomp/runtest.sh | 12 +++---- tests/long-double/runtest.sh | 2 +- tests/ppc64le-long-double/runtest-fedora.sh | 9 +++--- tests/ppc64le-long-double/runtest.sh | 9 ++---- tests/rhbz_1647130/runtest.sh | 14 ++++----- tests/rpmmacros/runtest.sh | 8 ++--- tests/toolchains/runtest.sh | 35 ++++++++++----------- tests/ucrt64-toolchain/runtest.sh | 2 +- tests/use-correct-dwarf-default/runtest.sh | 8 ++--- 13 files changed, 80 insertions(+), 69 deletions(-) diff --git a/.pre-commit-config.yaml b/.pre-commit-config.yaml index e5388a6..2e27e78 100644 --- a/.pre-commit-config.yaml +++ b/.pre-commit-config.yaml @@ -12,3 +12,10 @@ repos: rev: 1.32.2 hooks: - id: tmt-lint + +- repo: https://github.com/koalaman/shellcheck-precommit + rev: v0.10.0 + hooks: + - id: shellcheck + require_serial: true # Podman has trouble running concurrently + args: ["--exclude=SC1091"] # Ignore "Not following" sourced scripts diff --git a/tests/fedora-flags/runtest.sh b/tests/fedora-flags/runtest.sh index 96d1cc8..04698e7 100755 --- a/tests/fedora-flags/runtest.sh +++ b/tests/fedora-flags/runtest.sh @@ -1,10 +1,11 @@ #!/bin/bash +# shellcheck disable=SC2086 set -ex pipefail -cflags=`rpm -D '%toolchain clang' -E %{build_cflags}` -cxxflags=`rpm -D '%toolchain clang' -E %{build_cxxflags}` -ldflags=`rpm -D '%toolchain clang' -E %{build_ldflags}` +cflags=$(rpm -D '%toolchain clang' -E '%{build_cflags}') +cxxflags=$(rpm -D '%toolchain clang' -E '%{build_cxxflags}') +ldflags=$(rpm -D '%toolchain clang' -E '%{build_ldflags}') # Test a c program diff --git a/tests/gcc-clang-compatibility/runtest.sh b/tests/gcc-clang-compatibility/runtest.sh index 3480309..504713d 100755 --- a/tests/gcc-clang-compatibility/runtest.sh +++ b/tests/gcc-clang-compatibility/runtest.sh @@ -1,4 +1,4 @@ -#!/bin/sh -eux +#!/bin/bash -eux tmp=$(mktemp -d) @@ -6,7 +6,7 @@ tmp=$(mktemp -d) # gcc-toolset-XX, in such case we need to test the compatibility with that one. # We can get that from `clang -v` output. TOOLSET=$(clang -v |& grep "Selected GCC installation" | grep -P -o '(dev|gcc-)toolset-[0-9]*') ||: -if [[ "x" = "x${TOOLSET}" ]]; then +if [[ "" = "${TOOLSET}" ]]; then GCC="g++" else GCC="scl enable ${TOOLSET} -- g++" @@ -14,13 +14,13 @@ else fi # Build the source with GCC, link it with clang -${GCC} -c hello.cpp -o ${tmp}/hello.o -clang++ -o ${tmp}/hello ${tmp}/hello.o -${tmp}/hello | grep "Hello world" -rm -rf ${tmp}/* +${GCC} -c hello.cpp -o "${tmp}/hello.o" +clang++ -o "${tmp}"/hello "${tmp}/hello.o" +"${tmp}/hello" | grep "Hello world" +rm -rf "${tmp:?}"/* # Build the source with clang, link it with GCC -clang++ -c hello.cpp -o ${tmp}/hello.o -${GCC} -o ${tmp}/hello ${tmp}/hello.o -${tmp}/hello | grep "Hello world" -rm -rf ${tmp}/* +clang++ -c hello.cpp -o "${tmp}/hello.o" +${GCC} -o "${tmp}"/hello "${tmp}/hello.o" +"${tmp}/hello" | grep "Hello world" +rm -rf "${tmp:?}"/* diff --git a/tests/kernel-ark-build/runtest.sh b/tests/kernel-ark-build/runtest.sh index f9b217f..db04d4a 100755 --- a/tests/kernel-ark-build/runtest.sh +++ b/tests/kernel-ark-build/runtest.sh @@ -81,7 +81,7 @@ cloneKernelTree() { sleep $delay fi done - return $retcode + return "$retcode" } # In a kernel-ark repository, do all the operations needed to generate an SRPM @@ -102,8 +102,17 @@ generateSRPM() { rlRun "make dist-get-buildreqs > make-buildreqs.log 2>&1" rlFileSubmit make-buildreqs.log if grep -q 'Missing dependencies:' make-buildreqs.log; then - rlRun "KERNEL_BUILDREQS=\"$(sed -n 's/Missing dependencies://p' make-buildreqs.log)\"" - rlRun 'dnf install -y ${KERNEL_BUILDREQS} > install-buildreqs.log 2>&1' + # Getting the build requirements is quite tricky as it might contain + # not only package names but also "provides" perl(ExtUtils::Embed) which + # can break the dnf command if not escaped properly. The safest way is + # to create an array which contains each req as argument, then pass the + # array to dnf. Bash will later pass each element properly quoted. + # rlRun can also easily break the command due to special characters + # so we don't use it here. + read -ra KERNEL_BUILDREQS <<< "$(sed -n 's/Missing dependencies://p' make-buildreqs.log)" + rlLog "Installing dependencies: ${KERNEL_BUILDREQS[*]}" + dnf install -y "${KERNEL_BUILDREQS[@]}" > install-buildreqs.log 2>&1 || \ + rlFail "$(cat install-buildreqs.log)" rlFileSubmit install-buildreqs.log elif grep 'PASS:' make-buildreqs.log; then rlLog "All dependencies were already installed" @@ -139,6 +148,7 @@ rlJournalStart rlRun "free -h" logTmtRequiredPackages + declare tmp rlRun "tmp=\$(mktemp -d)" 0 "Create tmp directory" rlRun "pushd $tmp" rlRun "set -o pipefail" diff --git a/tests/libomp/runtest.sh b/tests/libomp/runtest.sh index dfe811f..934b96b 100755 --- a/tests/libomp/runtest.sh +++ b/tests/libomp/runtest.sh @@ -2,23 +2,23 @@ set -exo pipefail -CLANG_PKG=$(rpm -qf --queryformat '%{name}' $(readlink -f $(type -p clang))) +CLANG_PKG=$(rpm -qf --queryformat '%{name}' "$(readlink -f "$(type -p clang)")") # For compat packages, we want to check if there's a package suffix: clang17 instead clang for example PKG_SUFFIX=${CLANG_PKG#clang} -CLANG_NVR=$(rpm -q $CLANG_PKG) -CLANG_VERSION=$(rpm --queryformat="%{version}" -q $CLANG_NVR) +CLANG_NVR=$(rpm -q "$CLANG_PKG") +CLANG_VERSION=$(rpm --queryformat="%{version}" -q "$CLANG_NVR") LIBOMP_DEPENDENCIES="libomp${PKG_SUFFIX} libomp${PKG_SUFFIX}-devel" # Ensure clang depends on the correct clang-libs version -rpm -q --requires ${CLANG_NVR} | grep "${CLANG_PKG}-libs.* = ${CLANG_VERSION}" +rpm -q --requires "$CLANG_NVR" | grep "${CLANG_PKG}-libs.* = ${CLANG_VERSION}" # Check that weak dependencies are correct. The versions of these should be the same # as clang's to guarantee the ABI compatibility, and that version should be actually # installed as well. for lomp_dep in $LIBOMP_DEPENDENCIES; do - rpm -q --recommends clang${PKG_SUFFIX}-libs | grep "${lomp_dep}.* = ${CLANG_VERSION}" - [[ "$(rpm --queryformat="%{version}" -q ${lomp_dep}.$(uname -m))" == "${CLANG_VERSION}" ]] + rpm -q --recommends "clang${PKG_SUFFIX}-libs" | grep "${lomp_dep}.* = ${CLANG_VERSION}" + [[ "$(rpm --queryformat="%{version}" -q "${lomp_dep}"."$(uname -m)")" == "${CLANG_VERSION}" ]] done # Perform a sanity test to ensure everything works as expected diff --git a/tests/long-double/runtest.sh b/tests/long-double/runtest.sh index d69e2c3..68b6aaa 100755 --- a/tests/long-double/runtest.sh +++ b/tests/long-double/runtest.sh @@ -1,4 +1,4 @@ -set -e +#!/bin/bash -e # Use __LDBL_MANT_DIG__ as a way to distinguish between long double formats. # While this is not guaranteed to change for all formats, it provides a diff --git a/tests/ppc64le-long-double/runtest-fedora.sh b/tests/ppc64le-long-double/runtest-fedora.sh index 3cfb081..84dbee7 100755 --- a/tests/ppc64le-long-double/runtest-fedora.sh +++ b/tests/ppc64le-long-double/runtest-fedora.sh @@ -1,8 +1,7 @@ -set -e +#!/bin/bash -e -fedora_release=`rpm -E %{fedora}` +fedora_release=$(rpm -E "%{fedora}") mock_root=fedora-$fedora_release-ppc64le -triple=ppc64le-redhat-linux mock_cmd="mock -r $mock_root --isolation=simple" @@ -12,10 +11,10 @@ run_test () { echo "Running $test_name" echo "Expected output: $expected" - actual=$($mock_cmd -q --shell ./$test_name) + actual=$($mock_cmd -q --shell "./$test_name") echo "Actual output: $actual" - if [[ x$expected == x$actual ]]; then + if [[ "$expected" == "$actual" ]]; then return 0; else return 1; diff --git a/tests/ppc64le-long-double/runtest.sh b/tests/ppc64le-long-double/runtest.sh index be357d5..ec3a1c6 100755 --- a/tests/ppc64le-long-double/runtest.sh +++ b/tests/ppc64le-long-double/runtest.sh @@ -1,7 +1,4 @@ -set -e - -triple=ppc64le-redhat-linux - +#!/bin/bash -e run_test () { test_name=$1 @@ -9,10 +6,10 @@ run_test () { echo "Running $test_name" echo "Expected output: $expected" - actual=$(./$test_name) + actual=$("./$test_name") echo "Actual output: $actual" - if [[ x$expected == x$actual ]]; then + if [[ "$expected" == "$actual" ]]; then return 0; else return 1; diff --git a/tests/rhbz_1647130/runtest.sh b/tests/rhbz_1647130/runtest.sh index 6898f78..1b8b6db 100755 --- a/tests/rhbz_1647130/runtest.sh +++ b/tests/rhbz_1647130/runtest.sh @@ -1,9 +1,7 @@ -#!/bin/sh -set -e -set -x +#!/bin/bash -ex -tmp_cpp=`mktemp -t XXXXX.cpp` -tmp_dir=`mktemp -d` -echo 'int main(int argc, char*argv[]) { while(argc--) new int(); return 0; }' > $tmp_cpp -scan-build -o $tmp_dir clang++ -c $tmp_cpp -o /dev/null -(scan-view --no-browser $tmp_dir/* & WPID=$! && sleep 10s && kill $WPID) +tmp_cpp=$(mktemp -t XXXXX.cpp) +tmp_dir=$(mktemp -d) +echo 'int main(int argc, char*argv[]) { while(argc--) new int(); return 0; }' > "$tmp_cpp" +scan-build -o "$tmp_dir" clang++ -c "$tmp_cpp" -o /dev/null +(scan-view --no-browser "$tmp_dir"/* & WPID=$! && sleep 10s && kill $WPID) diff --git a/tests/rpmmacros/runtest.sh b/tests/rpmmacros/runtest.sh index 99295c3..02cd4a5 100755 --- a/tests/rpmmacros/runtest.sh +++ b/tests/rpmmacros/runtest.sh @@ -1,11 +1,11 @@ -#!/bin/sh -eux +#!/bin/bash -eux -clang_pkg=${1:-"$(rpm -qf --queryformat '%{name}' $(readlink -f $(type -p clang)))"} +clang_pkg=${1:-"$(rpm -qf --queryformat '%{name}' "$(readlink -f "$(type -p clang)")")"} macros_path="/usr/lib/rpm/macros.d/macros.clang" set pipefail -if ! rpm -q $clang_pkg > /dev/null; then +if ! rpm -q "$clang_pkg" > /dev/null; then echo "Could not find package $clang_pkg" exit 1 fi @@ -23,7 +23,7 @@ echo # suffix ~rcN. Meanwhile, the macro won't include it in order to allow packages # built with an RC package to be fully supported later. # In that case, we need to remove that prefix. -rpm_version=$(rpm -q $clang_pkg --qf "%{version}" | sed 's/~.*//') +rpm_version=$(rpm -q "$clang_pkg" --qf "%{version}" | sed 's/~.*//') macro_version=$(rpm --eval "%{clang_version}") if [[ "$rpm_version" != "$macro_version" ]]; then diff --git a/tests/toolchains/runtest.sh b/tests/toolchains/runtest.sh index 0d1a3e5..d1d9298 100755 --- a/tests/toolchains/runtest.sh +++ b/tests/toolchains/runtest.sh @@ -1,4 +1,4 @@ -#!/bin/sh -eux +#!/bin/bash -eu set pipefail @@ -12,41 +12,40 @@ status=0 test_toolchain() { - toolchain=$@ + toolchain=("$@") args="" - while [ $# -gt 0 ]; do - case $1 in + for arg in "${toolchain[@]}"; do + case "$arg" in clang) - compiler=$1 + compiler=$arg src=hello.c ;; clang++) - compiler=$1 + compiler=$arg src=hello.cpp ;; compiler-rt) - args="$args -rtlib=$1" + args="$args -rtlib=$arg" ;; libc++) - args="$args -stdlib=$1" + args="$args -stdlib=$arg" ;; libstdc++) - args="$args -stdlib=$1" + args="$args -stdlib=$arg" ;; lld) - args="$args -fuse-ld=$1" + args="$args -fuse-ld=$arg" ;; *) - args="$args $1" + args="$args $arg" ;; esac - shift done cmd="$compiler $args $src" rm -f a.out - echo "* $toolchain" + echo "* ${toolchain[*]}" echo " command: $cmd" if $cmd && ./a.out | grep -q 'Hello World'; then echo " PASS" @@ -57,17 +56,17 @@ test_toolchain() { } clang --version -CLANG_PKG=$(rpm -qf --queryformat '%{name}' $(readlink -f $(type -p clang))) +CLANG_PKG=$(rpm -qf --queryformat '%{name}' "$(readlink -f "$(type -p clang)")") # Repoquery is needed instead yum info for compatibility with RHEL-7 -repoquery -i --installed $CLANG_PKG | grep ^Source -clang_version=$(rpm -q --queryformat "%{version}" $CLANG_PKG | grep -ioP "^[0-9]+") +repoquery -i --installed "$CLANG_PKG" | grep ^Source +clang_version=$(rpm -q --queryformat "%{version}" "$CLANG_PKG" | grep -ioP "^[0-9]+") echo "" for compiler in clang clang++; do for rtlib in "" compiler-rt; do for linker in "" lld; do for cxxlib in "" $CXXLIBS; do - if [ "$compiler" = "clang" -a -n "$cxxlib" ]; then + if [[ "$compiler" = "clang" && -n "$cxxlib" ]]; then continue fi for args in "" -static; do @@ -100,7 +99,7 @@ for compiler in clang clang++; do continue fi - test_toolchain $compiler $rtlib $linker $cxxlib $args + test_toolchain "$compiler" "$rtlib" "$linker" "$cxxlib" "$args" done done done diff --git a/tests/ucrt64-toolchain/runtest.sh b/tests/ucrt64-toolchain/runtest.sh index 2b3f166..9c8d5fe 100755 --- a/tests/ucrt64-toolchain/runtest.sh +++ b/tests/ucrt64-toolchain/runtest.sh @@ -1,4 +1,4 @@ -set -eux +#!/bin/bash -eux clang++ --target=x86_64-windows-gnu test.cpp file a.exe | grep "PE32+ executable (console) x86-64, for MS Windows" diff --git a/tests/use-correct-dwarf-default/runtest.sh b/tests/use-correct-dwarf-default/runtest.sh index 926658e..47e5a30 100755 --- a/tests/use-correct-dwarf-default/runtest.sh +++ b/tests/use-correct-dwarf-default/runtest.sh @@ -1,4 +1,4 @@ -#!/bin/sh -eux +#!/bin/bash -eux # Determine correct DWARF version to use. Defaults to version 5, but older # distros might need to use version 4, which can be configured using the @@ -6,9 +6,9 @@ required_dwarf_version=${DWARF_VERSION:-5} # Get clang version -CLANG_PKG=$(rpm -qf --queryformat '%{name}' $(readlink -f $(type -p clang))) -clang_version=$(rpm -q --queryformat "%{version}" $CLANG_PKG | grep -ioP "^[0-9]+") -if [ $clang_version -lt 18 ]; then +CLANG_PKG=$(rpm -qf --queryformat '%{name}' "$(readlink -f "$(type -p clang)")") +clang_version=$(rpm -q --queryformat "%{version}" "$CLANG_PKG" | grep -ioP "^[0-9]+") +if [ "$clang_version" -lt 18 ]; then >&2 echo "clang is older than version 18"; required_dwarf_version=4 fi From c140bdf103ff140adc3efca43d5a0fa19bf649b1 Mon Sep 17 00:00:00 2001 From: Tulio Magno Quites Machado Filho Date: Wed, 13 Nov 2024 16:30:58 -0300 Subject: [PATCH 5/6] rhbz_1647130: Remove tmp_dir at the end Guarantee the temporary directory is removed after the execution of this test. --- tests/rhbz_1647130/runtest.sh | 1 + 1 file changed, 1 insertion(+) diff --git a/tests/rhbz_1647130/runtest.sh b/tests/rhbz_1647130/runtest.sh index 1b8b6db..39f8a90 100755 --- a/tests/rhbz_1647130/runtest.sh +++ b/tests/rhbz_1647130/runtest.sh @@ -5,3 +5,4 @@ tmp_dir=$(mktemp -d) echo 'int main(int argc, char*argv[]) { while(argc--) new int(); return 0; }' > "$tmp_cpp" scan-build -o "$tmp_dir" clang++ -c "$tmp_cpp" -o /dev/null (scan-view --no-browser "$tmp_dir"/* & WPID=$! && sleep 10s && kill $WPID) +rm -rf "$tmp_cpp" "$tmp_dir" From 3de6a2aad533cdf90fcccc21ba1d8207c4568714 Mon Sep 17 00:00:00 2001 From: Nikita Popov Date: Thu, 6 Feb 2025 10:09:24 +0100 Subject: [PATCH 6/6] Update ucrt test for new file output After a recent file update, the output is now: > a.exe: PE32+ executable for MS Windows 5.02 (console), x86-64, 18 sections Adjust the grep to match both the old and new output. I think the key parts are that it's a "PE32+ executable" for x86-64. --- tests/ucrt64-toolchain/runtest.sh | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/tests/ucrt64-toolchain/runtest.sh b/tests/ucrt64-toolchain/runtest.sh index 9c8d5fe..c9d0946 100755 --- a/tests/ucrt64-toolchain/runtest.sh +++ b/tests/ucrt64-toolchain/runtest.sh @@ -1,4 +1,4 @@ #!/bin/bash -eux clang++ --target=x86_64-windows-gnu test.cpp -file a.exe | grep "PE32+ executable (console) x86-64, for MS Windows" +file a.exe | grep "PE32+ executable.*x86-64"