Compare commits

...
Sign in to create a new pull request.

6 commits

Author SHA1 Message Date
Nikita Popov
3de6a2aad5 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.
2025-02-06 10:09:24 +01:00
Tulio Magno Quites Machado Filho
c140bdf103 rhbz_1647130: Remove tmp_dir at the end
Guarantee the temporary directory is removed after the execution of this
test.
2024-11-13 16:30:58 -03:00
Jesus Checa Hidalgo
cda9761d2e Shell static analysis
Add pre-commit hook for static analysis on shell scripts (shellcheck)
Fixed lots of issues flagged by shellcheck.
2024-08-05 09:15:19 +02:00
Jesus Checa Hidalgo
71a2b1c3bf 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.
2024-07-23 10:01:02 +00:00
Timm Bäder
bf7e2faa36 Enable pie-rpm test by default 2024-07-19 07:28:13 +00:00
Jesus Checa Hidalgo
9080b2716a Update test relevancy for compat packages
llvm-test-suite and rpmmacros tests disabled for compat packages
2024-07-17 12:55:17 +02:00
16 changed files with 216 additions and 109 deletions

View file

@ -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

View file

@ -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

View file

@ -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:?}"/*

View file

@ -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,19 +32,123 @@ 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
# 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"
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
declare tmp
rlRun "tmp=\$(mktemp -d)" 0 "Create tmp directory"
rlRun "pushd $tmp"
rlRun "set -o pipefail"
@ -49,42 +159,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

View file

@ -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

View file

@ -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

View file

@ -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

View file

@ -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

View file

@ -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;

View file

@ -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;

View file

@ -1,9 +1,8 @@
#!/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)
rm -rf "$tmp_cpp" "$tmp_dir"

View file

@ -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

View file

@ -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

View file

@ -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

View file

@ -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"
file a.exe | grep "PE32+ executable.*x86-64"

View file

@ -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