diff options
Diffstat (limited to 'test/util')
-rw-r--r-- | test/util/save_util.cc | 18 |
1 files changed, 16 insertions, 2 deletions
diff --git a/test/util/save_util.cc b/test/util/save_util.cc index 71f4078a7..5540e2146 100644 --- a/test/util/save_util.cc +++ b/test/util/save_util.cc @@ -27,9 +27,23 @@ namespace gvisor { namespace testing { namespace { +enum class CooperativeSaveMode { + kUnknown = 0, // cooperative_save_mode is statically-initialized to 0 + kAvailable, + kNotAvailable, +}; + +std::atomic<CooperativeSaveMode> cooperative_save_mode; + bool CooperativeSaveEnabled() { - static bool enabled = getenv(GVISOR_COOPERATIVE_SAVE_TEST) != nullptr; - return enabled; + auto mode = cooperative_save_mode.load(); + if (mode == CooperativeSaveMode::kUnknown) { + mode = (getenv(GVISOR_COOPERATIVE_SAVE_TEST) != nullptr) + ? CooperativeSaveMode::kAvailable + : CooperativeSaveMode::kNotAvailable; + cooperative_save_mode.store(mode); + } + return mode == CooperativeSaveMode::kAvailable; } std::atomic<int> save_disable; |