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 <gtest/gtest.h>
18
19 #include <android/api-level.h>
20 #include <android-base/properties.h>
21 #include <meminfo/procmeminfo.h>
22 #include <meminfo/sysmeminfo.h>
23
24 namespace android {
25 namespace meminfo {
26
27 // /proc/<pid>/smaps_rollup support is required.
TEST(SmapsRollup,IsSupported)28 TEST(SmapsRollup, IsSupported) {
29 // Use init's pid for this test since it's the only known pid.
30 ASSERT_TRUE(IsSmapsRollupSupported(1));
31 }
32
33 // KReclaimable in /proc/meminfo is required.
TEST(SysMemInfo,TestKReclaimable)34 TEST(SysMemInfo, TestKReclaimable) {
35 SysMemInfo mi;
36
37 if (android::base::GetIntProperty("ro.product.first_api_level", 0) < __ANDROID_API_R__) {
38 GTEST_SKIP();
39 }
40 ASSERT_TRUE(mi.ReadMemInfo());
41 // KReclaimable includes SReclaimable, so they should be at least equal
42 ASSERT_TRUE(mi.mem_kreclaimable_kb() >= mi.mem_slab_reclaimable_kb());
43 }
44
45 // /sys/kernel/ion/total_heaps_kb support is required.
TEST(SysMemInfo,TestIonTotalHeapsKb)46 TEST(SysMemInfo, TestIonTotalHeapsKb) {
47 uint64_t size;
48
49 if (android::base::GetIntProperty("ro.product.first_api_level", 0) < __ANDROID_API_R__) {
50 GTEST_SKIP();
51 }
52 ASSERT_TRUE(ReadIonHeapsSizeKb(&size));
53 }
54
55 // /sys/kernel/ion/total_pools_kb support is required.
TEST(SysMemInfo,TestIonTotalPoolsKb)56 TEST(SysMemInfo, TestIonTotalPoolsKb) {
57 uint64_t size;
58
59 if (android::base::GetIntProperty("ro.product.first_api_level", 0) < __ANDROID_API_R__) {
60 GTEST_SKIP();
61 }
62 ASSERT_TRUE(ReadIonPoolsSizeKb(&size));
63 }
64
65 } // namespace meminfo
66 } // namespace android
67