1
1
Fork 0
mirror of https://github.com/NixOS/nix.git synced 2025-11-08 19:46:02 +01:00

tests: Suppress environment-dependent warnings

... via _NIX_TEST_NO_ENVIRONMENT_WARNINGS

This environment variable suppresses warnings that depend on the test
environment (such as ulimit warnings in builds on systems with lower
limits, which may well succeed if it weren't for the warning).

This prevents non-deterministic test failures in golden/characterization
tests.

Alternative considered: filtering stderr in test scripts, but that approach
is fragile with binary test output, and potentially multiple call sites.
This commit is contained in:
Robert Hensing 2025-11-04 23:14:21 +01:00
parent 08e218eb0b
commit 261f674a25
2 changed files with 14 additions and 8 deletions

View file

@ -7,6 +7,7 @@
#include "nix/util/file-system.hh"
#include "nix/util/processes.hh"
#include "nix/util/signals.hh"
#include "nix/util/environment-variables.hh"
#include <math.h>
#ifdef __APPLE__
@ -66,14 +67,16 @@ void setStackSize(size_t stackSize)
if (getrlimit(RLIMIT_STACK, &limit) == 0 && static_cast<size_t>(limit.rlim_cur) < stackSize) {
savedStackSize = limit.rlim_cur;
if (limit.rlim_max < static_cast<rlim_t>(stackSize)) {
logger->log(
lvlWarn,
HintFmt(
"Stack size hard limit is %1%, which is less than the desired %2%. If possible, increase the hard limit, e.g. with 'ulimit -Hs %3%'.",
limit.rlim_max,
stackSize,
stackSize / 1024)
.str());
if (getEnv("_NIX_TEST_NO_ENVIRONMENT_WARNINGS") != "1") {
logger->log(
lvlWarn,
HintFmt(
"Stack size hard limit is %1%, which is less than the desired %2%. If possible, increase the hard limit, e.g. with 'ulimit -Hs %3%'.",
limit.rlim_max,
stackSize,
stackSize / 1024)
.str());
}
}
auto requestedSize = std::min(static_cast<rlim_t>(stackSize), limit.rlim_max);
limit.rlim_cur = requestedSize;

View file

@ -49,6 +49,9 @@ if ! isTestOnNixOS; then
fi
export _NIX_IN_TEST=$TEST_ROOT/shared
export _NIX_TEST_NO_LSOF=1
# Suppress warnings that depend on the test environment (e.g., ulimit warnings)
# to avoid non-deterministic test failures in golden tests
export _NIX_TEST_NO_ENVIRONMENT_WARNINGS=1
export NIX_REMOTE=${NIX_REMOTE_-}
fi # ! isTestOnNixOS