blob: a3bd29318dad7eaa16a16ab7c430aa7adfd1a1c7 [file] [log] [blame]
Kalesh Singhf4ab0182020-12-01 11:47:01 -05001/*
2 * Copyright (C) 2020 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#include <aidl/Gtest.h>
17#include <aidl/Vintf.h>
18
19#include <aidl/android/hardware/memtrack/DeviceInfo.h>
20#include <aidl/android/hardware/memtrack/IMemtrack.h>
21#include <aidl/android/hardware/memtrack/MemtrackType.h>
22#include <android/binder_manager.h>
23#include <android/binder_process.h>
24
25using aidl::android::hardware::memtrack::DeviceInfo;
26using aidl::android::hardware::memtrack::IMemtrack;
27using aidl::android::hardware::memtrack::MemtrackRecord;
28using aidl::android::hardware::memtrack::MemtrackType;
29
30class MemtrackAidlTest : public testing::TestWithParam<std::string> {
31 public:
32 virtual void SetUp() override {
33 const auto instance = std::string() + IMemtrack::descriptor + "/default";
34 auto memtrackBinder = ndk::SpAIBinder(AServiceManager_getService(instance.c_str()));
35 memtrack_ = IMemtrack::fromBinder(memtrackBinder);
36 ASSERT_NE(memtrack_, nullptr);
37 }
38
39 std::shared_ptr<IMemtrack> memtrack_;
40};
41
42TEST_P(MemtrackAidlTest, GetMemoryInvalidPid) {
43 int pid = -1;
44 MemtrackType type = MemtrackType::OTHER;
45 std::vector<MemtrackRecord> records;
46
47 auto status = memtrack_->getMemory(pid, type, &records);
48
49 EXPECT_EQ(status.getExceptionCode(), EX_ILLEGAL_ARGUMENT);
50}
51
52TEST_P(MemtrackAidlTest, GetMemoryInvalidType) {
53 int pid = 1;
54 MemtrackType type = MemtrackType::NUM_TYPES;
55 std::vector<MemtrackRecord> records;
56
57 auto status = memtrack_->getMemory(pid, type, &records);
58
59 EXPECT_EQ(status.getExceptionCode(), EX_UNSUPPORTED_OPERATION);
60}
61
62TEST_P(MemtrackAidlTest, GetMemory) {
63 int pid = 1;
64 MemtrackType type = MemtrackType::OTHER;
65 std::vector<MemtrackRecord> records;
66
67 auto status = memtrack_->getMemory(pid, type, &records);
68
69 EXPECT_TRUE(status.isOk());
70}
71
72TEST_P(MemtrackAidlTest, GetGpuDeviceInfo) {
73 std::vector<DeviceInfo> device_info;
74
75 auto status = memtrack_->getGpuDeviceInfo(&device_info);
76
77 EXPECT_TRUE(status.isOk());
78}
79
80GTEST_ALLOW_UNINSTANTIATED_PARAMETERIZED_TEST(MemtrackAidlTest);
81INSTANTIATE_TEST_SUITE_P(PerInstance, MemtrackAidlTest,
82 testing::ValuesIn(android::getAidlHalInstanceNames(IMemtrack::descriptor)),
83 android::PrintInstanceNameToString);
84
85int main(int argc, char** argv) {
86 ::testing::InitGoogleTest(&argc, argv);
87 ABinderProcess_setThreadPoolMaxThreadCount(1);
88 ABinderProcess_startThreadPool();
89 return RUN_ALL_TESTS();
90}