1 /*
2 * Copyright (C) 2021 The Android Open Source Project
3 *
4 * Licensed under the Apache License, Version 2.0 (the "License");
5 * you may not use this file except in compliance with the License.
6 * You may obtain a copy of the License at
7 *
8 * http://www.apache.org/licenses/LICENSE-2.0
9 *
10 * Unless required by applicable law or agreed to in writing, software
11 * distributed under the License is distributed on an "AS IS" BASIS,
12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 * See the License for the specific language governing permissions and
14 * limitations under the License.
15 */
16
17 #include "gtest/gtest.h"
18
19 #include "berberis/base/large_mmap.h"
20 #include "berberis/base/mmap.h"
21
22 namespace berberis {
23
24 namespace {
25
TEST(LargeMmap,Smoke)26 TEST(LargeMmap, Smoke) {
27 InitLargeMmap();
28
29 auto large_p1 = static_cast<uint8_t*>(LargeMmapOrDie(kPageSize));
30 auto p1 = static_cast<uint8_t*>(MmapOrDie(kPageSize));
31 auto p2 = static_cast<uint8_t*>(MmapOrDie(kPageSize));
32 auto large_p2 = static_cast<uint8_t*>(LargeMmapOrDie(kPageSize));
33
34 #if defined(__LP64__)
35 // We can only guarantee small mmaps are not in between of large mmaps.
36 EXPECT_LT(large_p1, large_p2);
37 EXPECT_TRUE(p1 < large_p1 || p1 > large_p2);
38 EXPECT_TRUE(p2 < large_p1 || p2 > large_p2);
39 #endif
40
41 MunmapOrDie(large_p1, kPageSize);
42 MunmapOrDie(large_p2, kPageSize);
43 MunmapOrDie(p1, kPageSize);
44 MunmapOrDie(p2, kPageSize);
45 }
46
47 } // namespace
48
49 } // namespace berberis
50