1 : // Copyright 2015 Google Inc. All Rights Reserved.
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 : #include "syzygy/testing/laa.h"
16 :
17 : #include <windows.h>
18 : #include "base/logging.h"
19 : #include "gtest/gtest.h"
20 : #include "syzygy/common/align.h"
21 :
22 : namespace testing {
23 :
24 E : size_t GetAddressSpaceSize() {
25 E : MEMORYSTATUSEX mem_status = {};
26 E : mem_status.dwLength = sizeof(mem_status);
27 E : CHECK(::GlobalMemoryStatusEx(&mem_status));
28 :
29 : // Because of the way the interceptors work we only support 2GB or 4GB
30 : // virtual memory sizes, even if the actual is 3GB (32-bit windows, LAA,
31 : // and 4GT kernel option enabled).
32 : static const uint64 k1GB = 1UL << 30;
33 E : uint64 mem_size = ::common::AlignUp64(mem_status.ullTotalVirtual, 2 * k1GB);
34 E : mem_size /= k1GB;
35 E : return static_cast<size_t>(mem_size);
36 E : }
37 :
38 E : bool ShouldSkipTest(size_t required_address_space_size) {
39 E : if (GetAddressSpaceSize() == required_address_space_size)
40 i : return false;
41 : const ::testing::TestInfo* const test_info =
42 E : ::testing::UnitTest::GetInstance()->current_test_info();
43 : fprintf(stderr, "WARNING: %s.%s requires %d GB memory model, skipping.\n",
44 : test_info->test_case_name(), test_info->name(),
45 E : required_address_space_size);
46 E : return true;
47 E : }
48 :
49 : } // namespace testing
|