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 #include "base/test/scoped_amount_of_physical_memory_override.h" 6 7 #include "base/check_op.h" 8 #include "base/system/sys_info.h" 9 10 namespace base::test { 11 ScopedAmountOfPhysicalMemoryOverride(uint64_t amount_of_memory_mb)12ScopedAmountOfPhysicalMemoryOverride::ScopedAmountOfPhysicalMemoryOverride( 13 uint64_t amount_of_memory_mb) { 14 CHECK_GT(amount_of_memory_mb, 0u); 15 old_amount_of_physical_memory_mb_ = 16 base::SysInfo::SetAmountOfPhysicalMemoryMbForTesting(amount_of_memory_mb); 17 } 18 ~ScopedAmountOfPhysicalMemoryOverride()19ScopedAmountOfPhysicalMemoryOverride::~ScopedAmountOfPhysicalMemoryOverride() { 20 if (old_amount_of_physical_memory_mb_) { 21 base::SysInfo::SetAmountOfPhysicalMemoryMbForTesting( 22 *old_amount_of_physical_memory_mb_); 23 } else { 24 base::SysInfo::ClearAmountOfPhysicalMemoryMbForTesting(); 25 } 26 } 27 28 } // namespace base::test 29