1 /*
2  * Copyright (C) 2021 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 /**
18  * Instantiate the set of test cases for each vendor module
19  */
20 
21 #define LOG_TAG "drm_hal_test@1.4"
22 
23 #include <android/hardware/drm/1.4/ICryptoFactory.h>
24 #include <android/hardware/drm/1.4/IDrmFactory.h>
25 #include <gtest/gtest.h>
26 #include <hidl/HidlSupport.h>
27 #include <hidl/ServiceManagement.h>
28 #include <log/log.h>
29 
30 #include <algorithm>
31 #include <iterator>
32 #include <string>
33 #include <utility>
34 #include <vector>
35 
36 #include "android/hardware/drm/1.4/vts/drm_hal_test.h"
37 
38 using drm_vts::DrmHalTestParam;
39 using drm_vts::PrintParamInstanceToString;
40 
41 using android::hardware::drm::V1_4::vts::DrmHalTest;
42 
__anona5d9ecfc0102null43 static const std::vector<DrmHalTestParam> kAllInstances = [] {
44     using ::android::hardware::hidl_array;
45     using ::android::hardware::hidl_vec;
46     using ::android::hardware::drm::V1_4::ICryptoFactory;
47     using ::android::hardware::drm::V1_4::IDrmFactory;
48 
49     std::vector<std::string> drmInstances =
50             android::hardware::getAllHalInstanceNames(IDrmFactory::descriptor);
51     std::vector<std::string> cryptoInstances =
52             android::hardware::getAllHalInstanceNames(ICryptoFactory::descriptor);
53     std::set<std::string> allInstances;
54     allInstances.insert(drmInstances.begin(), drmInstances.end());
55     allInstances.insert(cryptoInstances.begin(), cryptoInstances.end());
56 
57     std::vector<DrmHalTestParam> firstInstanceUuidCombos;
58     for (const auto &instance : allInstances) {
59         auto drmFactory = IDrmFactory::getService(instance);
60         if (drmFactory == nullptr) {
61             continue;
62         }
63         drmFactory->getSupportedCryptoSchemes(
64             [&](const hidl_vec<hidl_array<uint8_t, 16>>& schemes) {
65                 if (schemes.size() > 0) {
66                     firstInstanceUuidCombos.push_back(DrmHalTestParam(instance, schemes[0]));
67                 }
68             });
69     }
70     return firstInstanceUuidCombos;
71 }();
72 
73 GTEST_ALLOW_UNINSTANTIATED_PARAMETERIZED_TEST(DrmHalTest);
74 INSTANTIATE_TEST_SUITE_P(PerInstance, DrmHalTest,
75                          testing::ValuesIn(kAllInstances),
76                          PrintParamInstanceToString);
77 
main(int argc,char ** argv)78 int main(int argc, char** argv) {
79 #if defined(__LP64__)
80     const char* kModulePath = "/data/local/tmp/64/lib";
81 #else
82     const char* kModulePath = "/data/local/tmp/32/lib";
83 #endif
84     DrmHalTest::gVendorModules
85             = new drm_vts::VendorModules(kModulePath);
86     if (DrmHalTest::gVendorModules->getPathList().size() == 0) {
87         std::cerr << "WARNING: No vendor modules found in " << kModulePath <<
88                 ", all vendor tests will be skipped" << std::endl;
89     }
90     ::testing::InitGoogleTest(&argc, argv);
91     int status = RUN_ALL_TESTS();
92     ALOGI("Test result = %d", status);
93     return status;
94 }
95