diff --git a/tests/Sanity/rpm-rebuild/runtest.sh b/tests/Sanity/rpm-rebuild/runtest.sh index f3537b0..261766f 100755 --- a/tests/Sanity/rpm-rebuild/runtest.sh +++ b/tests/Sanity/rpm-rebuild/runtest.sh @@ -2,6 +2,10 @@ # vim: dict+=/usr/share/beakerlib/dictionary.vim cpt=.,w,b,u,t,i,k . /usr/share/beakerlib/beakerlib.sh || exit 1 +# Available environment variables to configure +# PKG_TO_BUILD (mandatory): rpm packages to run rpmbuild on. +# MB_PER_CPU (optional): How many MB of ram per number of cpus should have. + # Analyze build failure and determine if it's a resource issue or real failure analyze_build_failure() { local logfile="$1" @@ -38,6 +42,25 @@ analyze_build_failure() { fi } +function get_memory_limited_cores() { + # Return the number of cores in a way that each core has access to at least + # the specified MB of physical RAM (default 1024MB). + # Swap is not counted to avoid severe performance degradation. + local mb_ram="$(free -m | awk '/Mem:/ {print $2}')" + local cores="$(nproc)" + local mb_per_core="${1:-1024}" + + local max_cores=$((mb_ram / mb_per_core)) + + if [ "$max_cores" -le "0" ]; then + echo "1" + elif [ "$max_cores" -lt "$cores" ]; then + echo "$max_cores" + else + echo "$cores" + fi +} + PACKAGE="$(rpm -qf "$(which rustc)")" rlJournalStart @@ -59,6 +82,12 @@ rlJournalStart rlDie "The package must be passed over PKG_TO_BUILD environment variable." fi + if [[ -n "${MB_PER_CPU}" ]]; then + MAX_CPUS=$(get_memory_limited_cores "$MB_PER_CPU") + rlLog "Running rpmbuild with max cores: $MAX_CPUS" + export RPM_BUILD_NCPUS="$MAX_CPUS" + fi + # Log basic system resources. If we start seeing failures due to disk # out of space, timeouts, or OOMs this will help identifying where # the issue might be. @@ -95,13 +124,13 @@ rlJournalStart rlPhaseStartTest set -o pipefail LOGFILE="${SRPM}_rpmbuild.log" - BUILD_CMD="rpmbuild -bb ${SPECDIR}/${SPECNAME}" + BUILD_CMD=(rpmbuild -bb "${SPECDIR}"/"${SPECNAME}") # Log the command being executed (for visibility in test output) - rlLog "Executing: $BUILD_CMD" + rlLog "Executing: ${BUILD_CMD[*]}" # Execute rpmbuild silently, saving complete log to file - if $BUILD_CMD &> "$LOGFILE"; then + if "${BUILD_CMD[@]}" &> "$LOGFILE"; then rlPass "rpmbuild succeeded" else # Analyze cause of failure diff --git a/tests/Sanity/rpm-rebuild/stratisd.fmf b/tests/Sanity/rpm-rebuild/stratisd.fmf index b3698fe..e01d5b4 100644 --- a/tests/Sanity/rpm-rebuild/stratisd.fmf +++ b/tests/Sanity/rpm-rebuild/stratisd.fmf @@ -3,7 +3,8 @@ require+: - stratisd environment+: PKG_TO_BUILD: "stratisd" -duration: 2h + MB_PER_CPU: "4096" +duration: 3h tier: 1 tag: @@ -15,3 +16,8 @@ adjust+: - enabled: false when: distro == rhel-8 and distro >= rhel-8.9 continue: false + + # Older stratisd packages (RHEL 9 and older) are much less RAM demanding + - environment+: + MB_PER_CPU: 2048 + when: distro < rhel-10