diff --git a/tests/cli-tests/compression/levels.sh b/tests/cli-tests/compression/levels.sh index b8230f2a346..bfe60c87c2a 100755 --- a/tests/cli-tests/compression/levels.sh +++ b/tests/cli-tests/compression/levels.sh @@ -9,6 +9,19 @@ datagen > file # Note: command echoing differs between macos and linux, so it's disabled below set +v version_info=$(zstd -V) +# --max needs about 8.5 GB of memory. On Linux, find how much this test can use: +# the physical RAM, or the cgroup (e.g. container) memory limit if it is lower. +mem_kib= +if [ -r /proc/meminfo ]; then + mem_kib=$(awk '$1 == "MemTotal:" { print $2 }' /proc/meminfo) + for limit_file in /sys/fs/cgroup/memory.max /sys/fs/cgroup/memory/memory.limit_in_bytes; do + limit=$(cat "$limit_file" 2>/dev/null) || continue + case "$limit" in + ''|*[!0-9]*) ;; # "max": no limit + *) if [ $((limit / 1024)) -lt "$mem_kib" ]; then mem_kib=$((limit / 1024)); fi ;; + esac + done +fi set -v # Compress with various levels and ensure that their sizes are ordered @@ -19,6 +32,9 @@ zstd -19 file -o file-19.zst -q if echo "$version_info" | grep -q '32-bit'; then # skip --max test: not enough address space cp file-19.zst file-max.zst +elif [ -n "$mem_kib" ] && [ "$mem_kib" -lt 9437184 ]; then + # skip --max test: not enough memory (less than 9 GiB) + cp file-19.zst file-max.zst else zstd --max file -o file-max.zst -q fi diff --git a/tests/cli-tests/compression/levels.sh.stderr.exact b/tests/cli-tests/compression/levels.sh.stderr.exact index fd7c076d277..52936ff2bd0 100644 --- a/tests/cli-tests/compression/levels.sh.stderr.exact +++ b/tests/cli-tests/compression/levels.sh.stderr.exact @@ -13,6 +13,9 @@ zstd -19 file -o file-19.zst -q if echo "$version_info" | grep -q '32-bit'; then # skip --max test: not enough address space cp file-19.zst file-max.zst +elif [ -n "$mem_kib" ] && [ "$mem_kib" -lt 9437184 ]; then + # skip --max test: not enough memory (less than 9 GiB) + cp file-19.zst file-max.zst else zstd --max file -o file-max.zst -q fi