1 /*
2 * Copyright (C) 2017 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 #define LOG_TAG "media_omx_hidl_master_test"
18 #ifdef __LP64__
19 #define OMX_ANDROID_COMPILE_AS_32BIT_ON_64BIT_PLATFORMS
20 #endif
21
22 #include <android-base/logging.h>
23
24 #include <android/hardware/media/omx/1.0/IOmx.h>
25 #include <android/hardware/media/omx/1.0/IOmxNode.h>
26 #include <android/hardware/media/omx/1.0/IOmxObserver.h>
27 #include <android/hardware/media/omx/1.0/IOmxStore.h>
28 #include <android/hardware/media/omx/1.0/types.h>
29 #include <android/hidl/allocator/1.0/IAllocator.h>
30 #include <android/hidl/memory/1.0/IMapper.h>
31 #include <android/hidl/memory/1.0/IMemory.h>
32
33 using ::android::hardware::media::omx::V1_0::IOmx;
34 using ::android::hardware::media::omx::V1_0::IOmxObserver;
35 using ::android::hardware::media::omx::V1_0::IOmxNode;
36 using ::android::hardware::media::omx::V1_0::IOmxStore;
37 using ::android::hardware::media::omx::V1_0::Message;
38 using ::android::hardware::media::omx::V1_0::CodecBuffer;
39 using ::android::hardware::media::omx::V1_0::PortMode;
40 using ::android::hidl::allocator::V1_0::IAllocator;
41 using ::android::hidl::memory::V1_0::IMemory;
42 using ::android::hidl::memory::V1_0::IMapper;
43 using ::android::hardware::Return;
44 using ::android::hardware::Void;
45 using ::android::hardware::hidl_vec;
46 using ::android::hardware::hidl_string;
47 using ::android::sp;
48
49 #include <VtsHalHidlTargetTestBase.h>
50 #include <getopt.h>
51 #include <media_hidl_test_common.h>
52
53 static ComponentTestEnvironment* gEnv = nullptr;
54
55 class MasterHidlTest : public ::testing::VtsHalHidlTargetTestBase {
56 private:
57 typedef ::testing::VtsHalHidlTargetTestBase Super;
58 public:
SetUp()59 virtual void SetUp() override {
60 Super::SetUp();
61 omxStore = nullptr;
62 omxStore = Super::getService<IOmxStore>();
63 ASSERT_NE(omxStore, nullptr);
64 omx = nullptr;
65 omx = omxStore->getOmx(gEnv->getInstance());
66 ASSERT_NE(omx, nullptr);
67 }
68
TearDown()69 virtual void TearDown() override {
70 Super::TearDown();
71 }
72
73 sp<IOmxStore> omxStore;
74 sp<IOmx> omx;
75
76 protected:
description(const std::string & description)77 static void description(const std::string& description) {
78 RecordProperty("description", description);
79 }
80 };
81
displayComponentInfo(hidl_vec<IOmx::ComponentInfo> & nodeList)82 void displayComponentInfo(hidl_vec<IOmx::ComponentInfo>& nodeList) {
83 for (size_t i = 0; i < nodeList.size(); i++) {
84 printf("%s | ", nodeList[i].mName.c_str());
85 for (size_t j = 0; j < ((nodeList[i]).mRoles).size(); j++) {
86 printf("%s ", nodeList[i].mRoles[j].c_str());
87 }
88 printf("\n");
89 }
90 }
91
92 // list service attributes
TEST_F(MasterHidlTest,ListServiceAttr)93 TEST_F(MasterHidlTest, ListServiceAttr) {
94 description("list service attributes");
95 android::hardware::media::omx::V1_0::Status status;
96 hidl_vec<IOmxStore::Attribute> attributes;
97 EXPECT_TRUE(omxStore
98 ->listServiceAttributes([&status, &attributes](
99 android::hardware::media::omx::V1_0::Status _s,
100 hidl_vec<IOmxStore::Attribute> const& _nl) {
101 status = _s;
102 attributes = _nl;
103 })
104 .isOk());
105 ASSERT_EQ(status, android::hardware::media::omx::V1_0::Status::OK);
106 if (attributes.size() == 0) ALOGV("Warning, Attribute list empty");
107 }
108
109 // get node prefix
TEST_F(MasterHidlTest,getNodePrefix)110 TEST_F(MasterHidlTest, getNodePrefix) {
111 description("get node prefix");
112 hidl_string prefix;
113 omxStore->getNodePrefix(
114 [&prefix](hidl_string const& _nl) { prefix = _nl; });
115 if (prefix.empty()) ALOGV("Warning, Node Prefix empty");
116 }
117
118 // list roles
TEST_F(MasterHidlTest,ListRoles)119 TEST_F(MasterHidlTest, ListRoles) {
120 description("list roles");
121 hidl_vec<IOmxStore::RoleInfo> roleList;
122 omxStore->listRoles([&roleList](hidl_vec<IOmxStore::RoleInfo> const& _nl) {
123 roleList = _nl;
124 });
125 if (roleList.size() == 0) ALOGV("Warning, RoleInfo list empty");
126 }
127
128 // list components and roles.
TEST_F(MasterHidlTest,ListNodes)129 TEST_F(MasterHidlTest, ListNodes) {
130 description("enumerate component and roles");
131 android::hardware::media::omx::V1_0::Status status;
132 hidl_vec<IOmx::ComponentInfo> nodeList;
133 bool isPass = true;
134 EXPECT_TRUE(
135 omx->listNodes([&status, &nodeList](
136 android::hardware::media::omx::V1_0::Status _s,
137 hidl_vec<IOmx::ComponentInfo> const& _nl) {
138 status = _s;
139 nodeList = _nl;
140 })
141 .isOk());
142 ASSERT_EQ(status, android::hardware::media::omx::V1_0::Status::OK);
143 if (nodeList.size() == 0)
144 ALOGV("Warning, ComponentInfo list empty");
145 else {
146 // displayComponentInfo(nodeList);
147 for (size_t i = 0; i < nodeList.size(); i++) {
148 sp<CodecObserver> observer = nullptr;
149 sp<IOmxNode> omxNode = nullptr;
150 observer = new CodecObserver(nullptr);
151 ASSERT_NE(observer, nullptr);
152 EXPECT_TRUE(
153 omx->allocateNode(
154 nodeList[i].mName, observer,
155 [&](android::hardware::media::omx::V1_0::Status _s,
156 sp<IOmxNode> const& _nl) {
157 status = _s;
158 omxNode = _nl;
159 })
160 .isOk());
161 ASSERT_EQ(status, android::hardware::media::omx::V1_0::Status::OK);
162 if (omxNode == nullptr) {
163 isPass = false;
164 std::cerr << "[ !OK ] " << nodeList[i].mName.c_str()
165 << "\n";
166 } else {
167 EXPECT_TRUE((omxNode->freeNode()).isOk());
168 omxNode = nullptr;
169 // std::cout << "[ OK ] " << nodeList[i].mName.c_str() <<
170 // "\n";
171 }
172 }
173 }
174 EXPECT_TRUE(isPass);
175 }
176
main(int argc,char ** argv)177 int main(int argc, char** argv) {
178 gEnv = new ComponentTestEnvironment();
179 ::testing::AddGlobalTestEnvironment(gEnv);
180 ::testing::InitGoogleTest(&argc, argv);
181 gEnv->init(&argc, argv);
182 int status = gEnv->initFromOptions(argc, argv);
183 if (status == 0) {
184 status = RUN_ALL_TESTS();
185 ALOGI("Test result = %d", status);
186 }
187 return status;
188 }
189