gvisor.dev/gvisor@v0.0.0-20240520182842-f9d4d51c7e0f/test/util/save_util.h (about) 1 // Copyright 2018 The gVisor Authors. 2 // 3 // Licensed under the Apache License, Version 2.0 (the "License"); 4 // you may not use this file except in compliance with the License. 5 // You may obtain a copy of the License at 6 // 7 // http://www.apache.org/licenses/LICENSE-2.0 8 // 9 // Unless required by applicable law or agreed to in writing, software 10 // distributed under the License is distributed on an "AS IS" BASIS, 11 // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 // See the License for the specific language governing permissions and 13 // limitations under the License. 14 15 #ifndef GVISOR_TEST_UTIL_SAVE_UTIL_H_ 16 #define GVISOR_TEST_UTIL_SAVE_UTIL_H_ 17 18 namespace gvisor { 19 namespace testing { 20 21 // Returns true if the environment in which the calling process is executing 22 // allows the test to be checkpointed and restored during execution. 23 bool IsRunningWithSaveRestore(); 24 25 // May perform a co-operative save cycle. 26 // 27 // errno is guaranteed to be preserved. 28 void MaybeSave(); 29 30 // Causes MaybeSave to become a no-op until destroyed or reset. 31 class DisableSave { 32 public: 33 DisableSave(); 34 ~DisableSave(); 35 DisableSave(DisableSave const&) = delete; 36 DisableSave(DisableSave&&) = delete; 37 DisableSave& operator=(DisableSave const&) = delete; 38 DisableSave& operator=(DisableSave&&) = delete; 39 40 // reset allows saves to continue, and is called implicitly by the destructor. 41 // It may be called multiple times safely, but is not thread-safe. 42 void reset(); 43 44 private: 45 bool reset_ = false; 46 }; 47 48 namespace internal { 49 50 // Causes a co-operative save cycle to occur. 51 // 52 // errno is guaranteed to be preserved. 53 void DoCooperativeSave(); 54 55 } // namespace internal 56 57 } // namespace testing 58 } // namespace gvisor 59 60 #endif // GVISOR_TEST_UTIL_SAVE_UTIL_H_