1 /*
2  * Copyright (C) 2018 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_NDEBUG 0
18 #define LOG_TAG "codec2_hidl_hal_master_test"
19 
20 #include <android-base/logging.h>
21 #include <android-base/properties.h>
22 #include <gtest/gtest.h>
23 #include <hidl/GtestPrinter.h>
24 #include <hidl/ServiceManagement.h>
25 
26 #include <codec2/hidl/client.h>
27 
28 #include <VtsHalHidlTargetTestBase.h>
29 #include "media_c2_hidl_test_common.h"
30 
31 namespace {
32 
33 // google.codec2 Master test setup
34 class Codec2MasterHalTest : public ::testing::TestWithParam<std::string> {
35   public:
SetUp()36     virtual void SetUp() override {
37         mClient = android::Codec2Client::CreateFromService(GetParam().c_str());
38         ASSERT_NE(mClient, nullptr);
39     }
40 
41   protected:
description(const std::string & description)42     static void description(const std::string& description) {
43         RecordProperty("description", description);
44     }
45 
46     std::shared_ptr<android::Codec2Client> mClient;
47 };
48 
displayComponentInfo(const std::vector<C2Component::Traits> & compList)49 void displayComponentInfo(const std::vector<C2Component::Traits>& compList) {
50     for (size_t i = 0; i < compList.size(); i++) {
51         std::cout << compList[i].name << " | " << compList[i].domain;
52         std::cout << " | " << compList[i].kind << "\n";
53     }
54 }
55 
56 // List Components
TEST_P(Codec2MasterHalTest,ListComponents)57 TEST_P(Codec2MasterHalTest, ListComponents) {
58     ALOGV("ListComponents Test");
59 
60     C2String name = mClient->getName();
61     EXPECT_NE(name.empty(), true) << "Invalid Codec2Client Name";
62 
63     // Get List of components from all known services
64     const std::vector<C2Component::Traits> listTraits = mClient->ListComponents();
65 
66     if (listTraits.size() == 0)
67         ALOGE("Warning, ComponentInfo list empty");
68     else {
69         (void)displayComponentInfo;
70         for (size_t i = 0; i < listTraits.size(); i++) {
71             std::shared_ptr<android::Codec2Client::Listener> listener;
72             std::shared_ptr<android::Codec2Client::Component> component;
73             listener.reset(new CodecListener());
74             ASSERT_NE(listener, nullptr);
75 
76             // Create component from all known services
77             const c2_status_t status =
78                     android::Codec2Client::CreateComponentByName(
79                             listTraits[i].name.c_str(), listener, &component, &mClient);
80             ASSERT_EQ(status, C2_OK)
81                     << "Create component failed for " << listTraits[i].name.c_str();
82         }
83     }
84 }
85 
86 // @VsrTest = 3.2-001.003
TEST_P(Codec2MasterHalTest,MustUseAidlBeyond202404)87 TEST_P(Codec2MasterHalTest, MustUseAidlBeyond202404) {
88     static int sVendorApiLevel = android::base::GetIntProperty("ro.vendor.api_level", 0);
89     if (sVendorApiLevel < 202404) {
90         GTEST_SKIP() << "vendor api level less than 202404: " << sVendorApiLevel;
91     }
92     ALOGV("MustUseAidlBeyond202404 Test");
93 
94     EXPECT_NE(mClient->getAidlBase(), nullptr) << "android.hardware.media.c2 MUST use AIDL "
95                                                << "for chipsets launching at 202404 or above";
96 }
97 
98 }  // anonymous namespace
99 
100 INSTANTIATE_TEST_SUITE_P(PerInstance, Codec2MasterHalTest,
101                          testing::ValuesIn(android::Codec2Client::GetServiceNames()),
102                          android::hardware::PrintInstanceNameToString);
103