• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*
2  * Copyright (C) 2019 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 "src/profiling/memory/page_idle_checker.h"
18 
19 #include "perfetto/ext/base/utils.h"
20 #include "test/gtest_and_gmock.h"
21 
22 namespace perfetto {
23 namespace profiling {
24 namespace {
25 
TEST(PageIdleCheckerTest,AllOnFirstPageAligned)26 TEST(PageIdleCheckerTest, AllOnFirstPageAligned) {
27   EXPECT_EQ(GetFirstPageShare(0, 10), 10u);
28 }
29 
TEST(PageIdleCheckerTest,AllOnFirstPageUnAligned)30 TEST(PageIdleCheckerTest, AllOnFirstPageUnAligned) {
31   EXPECT_EQ(GetFirstPageShare(10, 10), 10u);
32 }
33 
TEST(PageIdleCheckerTest,WholeFirstPageAligned)34 TEST(PageIdleCheckerTest, WholeFirstPageAligned) {
35   EXPECT_EQ(GetFirstPageShare(0, base::kPageSize + 10), base::kPageSize);
36   EXPECT_EQ(GetLastPageShare(0, base::kPageSize + 10), 10u);
37 }
38 
TEST(PageIdleCheckerTest,WholeLastPageAligned)39 TEST(PageIdleCheckerTest, WholeLastPageAligned) {
40   EXPECT_EQ(GetFirstPageShare(0, 3 * base::kPageSize), base::kPageSize);
41   EXPECT_EQ(GetLastPageShare(0, 3 * base::kPageSize), base::kPageSize);
42 }
43 
TEST(PageIdleCheckerTest,SomeFirstAndLast)44 TEST(PageIdleCheckerTest, SomeFirstAndLast) {
45   EXPECT_EQ(GetFirstPageShare(10, 3 * base::kPageSize + 10),
46             base::kPageSize - 10);
47   EXPECT_EQ(GetLastPageShare(10, 3 * base::kPageSize + 10), 20u);
48 }
49 
50 }  // namespace
51 }  // namespace profiling
52 }  // namespace perfetto
53