1 // Copyright 2023 The Chromium Authors 2 // Use of this source code is governed by a BSD-style license that can be 3 // found in the LICENSE file. 4 5 #ifndef BASE_TEST_SCOPED_AMOUNT_OF_PHYSICAL_MEMORY_OVERRIDE_H_ 6 #define BASE_TEST_SCOPED_AMOUNT_OF_PHYSICAL_MEMORY_OVERRIDE_H_ 7 8 #include <stdint.h> 9 10 #include <optional> 11 12 namespace base::test { 13 14 // Sets the amount of physical memory in MB override on construction, and 15 // removes it when the object goes out of scope. This class is intended to be 16 // used by tests that need to override the amount of physical memory on the 17 // system to validate different system conditions. 18 class ScopedAmountOfPhysicalMemoryOverride { 19 public: 20 // Constructor that initializes the amount of memory override. Memory is 21 // specified in MB. 22 explicit ScopedAmountOfPhysicalMemoryOverride(uint64_t amount_of_memory_mb); 23 24 ScopedAmountOfPhysicalMemoryOverride( 25 const ScopedAmountOfPhysicalMemoryOverride&) = delete; 26 ScopedAmountOfPhysicalMemoryOverride& operator=( 27 const ScopedAmountOfPhysicalMemoryOverride&) = delete; 28 29 ~ScopedAmountOfPhysicalMemoryOverride(); 30 31 private: 32 std::optional<uint64_t> old_amount_of_physical_memory_mb_; 33 }; 34 35 } // namespace base::test 36 37 #endif // BASE_TEST_SCOPED_AMOUNT_OF_PHYSICAL_MEMORY_OVERRIDE_H_ 38