Skip to content

Commit 261f674

Browse files
committed
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.
1 parent 08e218e commit 261f674

File tree

2 files changed

+14
-8
lines changed

2 files changed

+14
-8
lines changed

src/libutil/current-process.cc

Lines changed: 11 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@
77
#include "nix/util/file-system.hh"
88
#include "nix/util/processes.hh"
99
#include "nix/util/signals.hh"
10+
#include "nix/util/environment-variables.hh"
1011
#include <math.h>
1112

1213
#ifdef __APPLE__
@@ -66,14 +67,16 @@ void setStackSize(size_t stackSize)
6667
if (getrlimit(RLIMIT_STACK, &limit) == 0 && static_cast<size_t>(limit.rlim_cur) < stackSize) {
6768
savedStackSize = limit.rlim_cur;
6869
if (limit.rlim_max < static_cast<rlim_t>(stackSize)) {
69-
logger->log(
70-
lvlWarn,
71-
HintFmt(
72-
"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%'.",
73-
limit.rlim_max,
74-
stackSize,
75-
stackSize / 1024)
76-
.str());
70+
if (getEnv("_NIX_TEST_NO_ENVIRONMENT_WARNINGS") != "1") {
71+
logger->log(
72+
lvlWarn,
73+
HintFmt(
74+
"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%'.",
75+
limit.rlim_max,
76+
stackSize,
77+
stackSize / 1024)
78+
.str());
79+
}
7780
}
7881
auto requestedSize = std::min(static_cast<rlim_t>(stackSize), limit.rlim_max);
7982
limit.rlim_cur = requestedSize;

tests/functional/common/vars.sh

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -49,6 +49,9 @@ if ! isTestOnNixOS; then
4949
fi
5050
export _NIX_IN_TEST=$TEST_ROOT/shared
5151
export _NIX_TEST_NO_LSOF=1
52+
# Suppress warnings that depend on the test environment (e.g., ulimit warnings)
53+
# to avoid non-deterministic test failures in golden tests
54+
export _NIX_TEST_NO_ENVIRONMENT_WARNINGS=1
5255
export NIX_REMOTE=${NIX_REMOTE_-}
5356

5457
fi # ! isTestOnNixOS

0 commit comments

Comments
 (0)