blob: 8952dfcb19c1a73f70be5c43286232f54559d4ac [file] [log] [blame]
ChengYou Ho10f8a482021-01-02 22:45:32 +08001/*
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/weaver/IWeaver.h>
Eric Biggers31380e72023-07-18 02:34:00 +000020#include <android-base/file.h>
21#include <android-base/parseint.h>
22#include <android-base/strings.h>
ChengYou Ho10f8a482021-01-02 22:45:32 +080023#include <android/binder_manager.h>
24#include <android/binder_process.h>
Eric Biggersb59654f2023-07-18 02:33:59 +000025#include <android/hardware/weaver/1.0/IWeaver.h>
26#include <hidl/GtestPrinter.h>
27#include <hidl/ServiceManagement.h>
ChengYou Ho10f8a482021-01-02 22:45:32 +080028
29#include <limits>
30
31using ::aidl::android::hardware::weaver::IWeaver;
32using ::aidl::android::hardware::weaver::WeaverConfig;
33using ::aidl::android::hardware::weaver::WeaverReadResponse;
ChengYou Ho20c47b42022-11-30 17:51:17 +000034using ::aidl::android::hardware::weaver::WeaverReadStatus;
ChengYou Ho10f8a482021-01-02 22:45:32 +080035
Eric Biggersb59654f2023-07-18 02:33:59 +000036using HidlIWeaver = ::android::hardware::weaver::V1_0::IWeaver;
37using HidlWeaverConfig = ::android::hardware::weaver::V1_0::WeaverConfig;
38using HidlWeaverReadStatus = ::android::hardware::weaver::V1_0::WeaverReadStatus;
39using HidlWeaverReadResponse = ::android::hardware::weaver::V1_0::WeaverReadResponse;
40using HidlWeaverStatus = ::android::hardware::weaver::V1_0::WeaverStatus;
ChengYou Ho10f8a482021-01-02 22:45:32 +080041
Eric Biggers31380e72023-07-18 02:34:00 +000042const std::string kSlotMapFile = "/metadata/password_slots/slot_map";
ChengYou Ho10f8a482021-01-02 22:45:32 +080043const std::vector<uint8_t> KEY{1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16};
44const std::vector<uint8_t> WRONG_KEY{0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0};
45const std::vector<uint8_t> VALUE{16, 15, 14, 13, 12, 11, 10, 9, 8, 7, 6, 5, 4, 3, 2, 1};
46const std::vector<uint8_t> OTHER_VALUE{0, 1, 1, 2, 3, 5, 8, 13, 21, 34, 55, 89, 144, 233, 255, 255};
47
Eric Biggersb59654f2023-07-18 02:33:59 +000048class WeaverAdapter {
49 public:
50 virtual ~WeaverAdapter() {}
51 virtual bool isReady() = 0;
52 virtual ::ndk::ScopedAStatus getConfig(WeaverConfig* _aidl_return) = 0;
53 virtual ::ndk::ScopedAStatus read(int32_t in_slotId, const std::vector<uint8_t>& in_key,
54 WeaverReadResponse* _aidl_return) = 0;
55 virtual ::ndk::ScopedAStatus write(int32_t in_slotId, const std::vector<uint8_t>& in_key,
56 const std::vector<uint8_t>& in_value) = 0;
57};
58
59class WeaverAidlAdapter : public WeaverAdapter {
60 public:
61 WeaverAidlAdapter(const std::string& param)
62 : aidl_weaver_(IWeaver::fromBinder(
63 ::ndk::SpAIBinder(AServiceManager_waitForService(param.c_str())))) {}
64 ~WeaverAidlAdapter() {}
65
66 bool isReady() { return aidl_weaver_ != nullptr; }
67
68 ::ndk::ScopedAStatus getConfig(WeaverConfig* _aidl_return) {
69 return aidl_weaver_->getConfig(_aidl_return);
ChengYou Ho10f8a482021-01-02 22:45:32 +080070 }
71
Eric Biggersb59654f2023-07-18 02:33:59 +000072 ::ndk::ScopedAStatus read(int32_t in_slotId, const std::vector<uint8_t>& in_key,
73 WeaverReadResponse* _aidl_return) {
74 return aidl_weaver_->read(in_slotId, in_key, _aidl_return);
75 }
ChengYou Ho10f8a482021-01-02 22:45:32 +080076
Eric Biggersb59654f2023-07-18 02:33:59 +000077 ::ndk::ScopedAStatus write(int32_t in_slotId, const std::vector<uint8_t>& in_key,
78 const std::vector<uint8_t>& in_value) {
79 return aidl_weaver_->write(in_slotId, in_key, in_value);
80 }
81
82 private:
83 std::shared_ptr<IWeaver> aidl_weaver_;
ChengYou Ho10f8a482021-01-02 22:45:32 +080084};
85
Eric Biggersb59654f2023-07-18 02:33:59 +000086class WeaverHidlAdapter : public WeaverAdapter {
87 public:
88 WeaverHidlAdapter(const std::string& param) : hidl_weaver_(HidlIWeaver::getService(param)) {}
89 ~WeaverHidlAdapter() {}
90
91 bool isReady() { return hidl_weaver_ != nullptr; }
92
93 ::ndk::ScopedAStatus getConfig(WeaverConfig* _aidl_return) {
94 bool callbackCalled = false;
95 HidlWeaverStatus status;
96 HidlWeaverConfig config;
97 auto ret = hidl_weaver_->getConfig([&](HidlWeaverStatus s, HidlWeaverConfig c) {
98 callbackCalled = true;
99 status = s;
100 config = c;
101 });
102 if (!ret.isOk() || !callbackCalled || status != HidlWeaverStatus::OK) {
103 return ::ndk::ScopedAStatus::fromStatus(STATUS_FAILED_TRANSACTION);
104 }
105 _aidl_return->slots = config.slots;
106 _aidl_return->keySize = config.keySize;
107 _aidl_return->valueSize = config.valueSize;
108 return ::ndk::ScopedAStatus::ok();
109 }
110
111 ::ndk::ScopedAStatus read(int32_t in_slotId, const std::vector<uint8_t>& in_key,
112 WeaverReadResponse* _aidl_return) {
113 bool callbackCalled = false;
114 HidlWeaverReadStatus status;
115 std::vector<uint8_t> value;
116 uint32_t timeout;
117 auto ret = hidl_weaver_->read(in_slotId, in_key,
118 [&](HidlWeaverReadStatus s, HidlWeaverReadResponse r) {
119 callbackCalled = true;
120 status = s;
121 value = r.value;
122 timeout = r.timeout;
123 });
124 if (!ret.isOk() || !callbackCalled) {
125 return ::ndk::ScopedAStatus::fromStatus(STATUS_FAILED_TRANSACTION);
126 }
127 switch (status) {
128 case HidlWeaverReadStatus::OK:
129 _aidl_return->status = WeaverReadStatus::OK;
130 break;
131 case HidlWeaverReadStatus::FAILED:
132 _aidl_return->status = WeaverReadStatus::FAILED;
133 break;
134 case HidlWeaverReadStatus::INCORRECT_KEY:
135 _aidl_return->status = WeaverReadStatus::INCORRECT_KEY;
136 break;
137 case HidlWeaverReadStatus::THROTTLE:
138 _aidl_return->status = WeaverReadStatus::THROTTLE;
139 break;
140 default:
141 ADD_FAILURE() << "Unknown HIDL read status: " << static_cast<uint32_t>(status);
142 _aidl_return->status = WeaverReadStatus::FAILED;
143 break;
144 }
145 _aidl_return->value = value;
146 _aidl_return->timeout = timeout;
147 return ::ndk::ScopedAStatus::ok();
148 }
149
150 ::ndk::ScopedAStatus write(int32_t in_slotId, const std::vector<uint8_t>& in_key,
151 const std::vector<uint8_t>& in_value) {
152 auto status = hidl_weaver_->write(in_slotId, in_key, in_value);
153 switch (status) {
154 case HidlWeaverStatus::OK:
155 return ::ndk::ScopedAStatus::ok();
156 case HidlWeaverStatus::FAILED:
157 return ::ndk::ScopedAStatus::fromStatus(STATUS_FAILED_TRANSACTION);
158 default:
159 ADD_FAILURE() << "Unknown HIDL write status: " << status.description();
160 return ::ndk::ScopedAStatus::fromStatus(STATUS_FAILED_TRANSACTION);
161 }
162 }
163
164 private:
165 android::sp<HidlIWeaver> hidl_weaver_;
166};
167
168class WeaverTest : public ::testing::TestWithParam<std::tuple<std::string, std::string>> {
169 protected:
170 void SetUp() override;
171 void TearDown() override {}
Eric Biggers31380e72023-07-18 02:34:00 +0000172 void FindFreeSlots();
Eric Biggersb59654f2023-07-18 02:33:59 +0000173
Eric Biggers961a1382023-07-18 02:34:00 +0000174 std::unique_ptr<WeaverAdapter> weaver_;
175 WeaverConfig config_;
Eric Biggers31380e72023-07-18 02:34:00 +0000176 uint32_t first_free_slot_;
177 uint32_t last_free_slot_;
Eric Biggersb59654f2023-07-18 02:33:59 +0000178};
179
180void WeaverTest::SetUp() {
181 std::string api, instance_name;
182 std::tie(api, instance_name) = GetParam();
183 if (api == "hidl") {
Eric Biggers961a1382023-07-18 02:34:00 +0000184 weaver_.reset(new WeaverHidlAdapter(instance_name));
Eric Biggersb59654f2023-07-18 02:33:59 +0000185 } else if (api == "aidl") {
Eric Biggers961a1382023-07-18 02:34:00 +0000186 weaver_.reset(new WeaverAidlAdapter(instance_name));
Eric Biggersb59654f2023-07-18 02:33:59 +0000187 } else {
188 FAIL() << "Bad test parameterization";
189 }
Eric Biggers961a1382023-07-18 02:34:00 +0000190 ASSERT_TRUE(weaver_->isReady());
191
192 auto ret = weaver_->getConfig(&config_);
193 ASSERT_TRUE(ret.isOk());
194 ASSERT_GT(config_.slots, 0);
195 GTEST_LOG_(INFO) << "WeaverConfig: slots=" << config_.slots << ", keySize=" << config_.keySize
196 << ", valueSize=" << config_.valueSize;
Eric Biggers31380e72023-07-18 02:34:00 +0000197
198 FindFreeSlots();
199 GTEST_LOG_(INFO) << "First free slot is " << first_free_slot_ << ", last free slot is "
200 << last_free_slot_;
201}
202
203void WeaverTest::FindFreeSlots() {
204 // Determine which Weaver slots are in use by the system. These slots can't be used by the test.
205 std::set<uint32_t> used_slots;
206 if (access(kSlotMapFile.c_str(), F_OK) == 0) {
207 std::string contents;
208 ASSERT_TRUE(android::base::ReadFileToString(kSlotMapFile, &contents))
209 << "Failed to read " << kSlotMapFile;
210 for (const auto& line : android::base::Split(contents, "\n")) {
211 auto trimmed_line = android::base::Trim(line);
212 if (trimmed_line[0] == '#' || trimmed_line[0] == '\0') continue;
213 auto slot_and_user = android::base::Split(trimmed_line, "=");
214 uint32_t slot;
215 ASSERT_TRUE(slot_and_user.size() == 2 &&
216 android::base::ParseUint(slot_and_user[0], &slot))
217 << "Error parsing " << kSlotMapFile << " at \"" << line << "\"";
218 GTEST_LOG_(INFO) << "Slot " << slot << " is in use by " << slot_and_user[1];
219 ASSERT_LT(slot, config_.slots);
220 used_slots.insert(slot);
221 }
222 }
223 // Starting in Android 14, the system will always use at least one Weaver slot if Weaver is
Eric Biggersb267fcc2024-08-28 00:06:01 +0000224 // supported at all. This is true even if an LSKF hasn't been set yet, since Weaver is used to
225 // protect the initial binding of each user's synthetic password to ensure that binding can be
226 // securely deleted if an LSKF is set later. Make sure we saw at least one slot, as otherwise
227 // the Weaver implementation must have a bug that makes it not fully usable by Android.
Eric Biggerse1d4bc52024-01-25 23:46:51 +0000228 ASSERT_FALSE(used_slots.empty())
229 << "Could not determine which Weaver slots are in use by the system";
Eric Biggers31380e72023-07-18 02:34:00 +0000230
231 // Find the first free slot.
232 int found = 0;
233 for (uint32_t i = 0; i < config_.slots; i++) {
234 if (used_slots.find(i) == used_slots.end()) {
235 first_free_slot_ = i;
236 found++;
237 break;
238 }
239 }
240 // Find the last free slot.
241 for (uint32_t i = config_.slots; i > 0; i--) {
242 if (used_slots.find(i - 1) == used_slots.end()) {
243 last_free_slot_ = i - 1;
244 found++;
245 break;
246 }
247 }
248 ASSERT_EQ(found, 2) << "All Weaver slots are already in use by the system";
Eric Biggersb59654f2023-07-18 02:33:59 +0000249}
250
ChengYou Ho10f8a482021-01-02 22:45:32 +0800251/*
252 * Checks config values are suitably large
253 */
Eric Biggersb59654f2023-07-18 02:33:59 +0000254TEST_P(WeaverTest, GetConfig) {
Eric Biggers961a1382023-07-18 02:34:00 +0000255 EXPECT_GE(config_.slots, 16u);
256 EXPECT_GE(config_.keySize, 16u);
257 EXPECT_GE(config_.valueSize, 16u);
ChengYou Ho10f8a482021-01-02 22:45:32 +0800258}
259
260/*
261 * Gets the config twice and checks they are the same
262 */
Eric Biggersb59654f2023-07-18 02:33:59 +0000263TEST_P(WeaverTest, GettingConfigMultipleTimesGivesSameResult) {
ChengYou Ho10f8a482021-01-02 22:45:32 +0800264 WeaverConfig config2;
265
Eric Biggers961a1382023-07-18 02:34:00 +0000266 auto ret = weaver_->getConfig(&config2);
ChengYou Ho10f8a482021-01-02 22:45:32 +0800267 ASSERT_TRUE(ret.isOk());
268
Eric Biggers961a1382023-07-18 02:34:00 +0000269 EXPECT_EQ(config_, config2);
ChengYou Ho10f8a482021-01-02 22:45:32 +0800270}
271
272/*
Eric Biggers31380e72023-07-18 02:34:00 +0000273 * Writes a key and value to the last free slot
ChengYou Ho10f8a482021-01-02 22:45:32 +0800274 */
Eric Biggersb59654f2023-07-18 02:33:59 +0000275TEST_P(WeaverTest, WriteToLastSlot) {
Eric Biggers31380e72023-07-18 02:34:00 +0000276 const auto writeRet = weaver_->write(last_free_slot_, KEY, VALUE);
ChengYou Ho10f8a482021-01-02 22:45:32 +0800277 ASSERT_TRUE(writeRet.isOk());
278}
279
280/*
281 * Writes a key and value to a slot
282 * Reads the slot with the same key and receives the value that was previously written
283 */
Eric Biggersb59654f2023-07-18 02:33:59 +0000284TEST_P(WeaverTest, WriteFollowedByReadGivesTheSameValue) {
Eric Biggers31380e72023-07-18 02:34:00 +0000285 const uint32_t slotId = first_free_slot_;
Eric Biggers961a1382023-07-18 02:34:00 +0000286 const auto ret = weaver_->write(slotId, KEY, VALUE);
ChengYou Ho10f8a482021-01-02 22:45:32 +0800287 ASSERT_TRUE(ret.isOk());
288
289 WeaverReadResponse response;
Eric Biggers961a1382023-07-18 02:34:00 +0000290 const auto readRet = weaver_->read(slotId, KEY, &response);
ChengYou Ho10f8a482021-01-02 22:45:32 +0800291 ASSERT_TRUE(readRet.isOk());
Eric Biggers961a1382023-07-18 02:34:00 +0000292 EXPECT_EQ(response.value, VALUE);
293 EXPECT_EQ(response.timeout, 0u);
294 EXPECT_EQ(response.status, WeaverReadStatus::OK);
ChengYou Ho10f8a482021-01-02 22:45:32 +0800295}
296
297/*
298 * Writes a key and value to a slot
299 * Overwrites the slot with a new key and value
300 * Reads the slot with the new key and receives the new value
301 */
Eric Biggersb59654f2023-07-18 02:33:59 +0000302TEST_P(WeaverTest, OverwritingSlotUpdatesTheValue) {
Eric Biggers31380e72023-07-18 02:34:00 +0000303 const uint32_t slotId = first_free_slot_;
Eric Biggers961a1382023-07-18 02:34:00 +0000304 const auto initialWriteRet = weaver_->write(slotId, WRONG_KEY, VALUE);
ChengYou Ho10f8a482021-01-02 22:45:32 +0800305 ASSERT_TRUE(initialWriteRet.isOk());
306
Eric Biggers961a1382023-07-18 02:34:00 +0000307 const auto overwriteRet = weaver_->write(slotId, KEY, OTHER_VALUE);
ChengYou Ho10f8a482021-01-02 22:45:32 +0800308 ASSERT_TRUE(overwriteRet.isOk());
309
310 WeaverReadResponse response;
Eric Biggers961a1382023-07-18 02:34:00 +0000311 const auto readRet = weaver_->read(slotId, KEY, &response);
ChengYou Ho10f8a482021-01-02 22:45:32 +0800312 ASSERT_TRUE(readRet.isOk());
Eric Biggers961a1382023-07-18 02:34:00 +0000313 EXPECT_EQ(response.value, OTHER_VALUE);
314 EXPECT_EQ(response.timeout, 0u);
315 EXPECT_EQ(response.status, WeaverReadStatus::OK);
ChengYou Ho10f8a482021-01-02 22:45:32 +0800316}
317
318/*
319 * Writes a key and value to a slot
320 * Reads the slot with a different key so does not receive the value
321 */
Eric Biggersb59654f2023-07-18 02:33:59 +0000322TEST_P(WeaverTest, WriteFollowedByReadWithWrongKeyDoesNotGiveTheValue) {
Eric Biggers31380e72023-07-18 02:34:00 +0000323 const uint32_t slotId = first_free_slot_;
Eric Biggers961a1382023-07-18 02:34:00 +0000324 const auto writeRet = weaver_->write(slotId, KEY, VALUE);
325 ASSERT_TRUE(writeRet.isOk());
ChengYou Ho10f8a482021-01-02 22:45:32 +0800326
327 WeaverReadResponse response;
Eric Biggers961a1382023-07-18 02:34:00 +0000328 const auto readRet = weaver_->read(slotId, WRONG_KEY, &response);
ChengYou Ho20c47b42022-11-30 17:51:17 +0000329 ASSERT_TRUE(readRet.isOk());
Eric Biggers961a1382023-07-18 02:34:00 +0000330 EXPECT_TRUE(response.value.empty());
331 EXPECT_EQ(response.status, WeaverReadStatus::INCORRECT_KEY);
ChengYou Ho10f8a482021-01-02 22:45:32 +0800332}
333
334/*
335 * Writing to an invalid slot fails
336 */
Eric Biggersb59654f2023-07-18 02:33:59 +0000337TEST_P(WeaverTest, WritingToInvalidSlotFails) {
Eric Biggers961a1382023-07-18 02:34:00 +0000338 if (config_.slots == std::numeric_limits<uint32_t>::max()) {
ChengYou Ho10f8a482021-01-02 22:45:32 +0800339 // If there are no invalid slots then pass
340 return;
341 }
342
Eric Biggers961a1382023-07-18 02:34:00 +0000343 const auto writeRet = weaver_->write(config_.slots, KEY, VALUE);
ChengYou Ho10f8a482021-01-02 22:45:32 +0800344 ASSERT_FALSE(writeRet.isOk());
345}
346
347/*
348 * Reading from an invalid slot fails rather than incorrect key
349 */
Eric Biggersb59654f2023-07-18 02:33:59 +0000350TEST_P(WeaverTest, ReadingFromInvalidSlotFails) {
Eric Biggers961a1382023-07-18 02:34:00 +0000351 if (config_.slots == std::numeric_limits<uint32_t>::max()) {
ChengYou Ho10f8a482021-01-02 22:45:32 +0800352 // If there are no invalid slots then pass
353 return;
354 }
355
356 WeaverReadResponse response;
Eric Biggers961a1382023-07-18 02:34:00 +0000357 const auto readRet = weaver_->read(config_.slots, KEY, &response);
ChengYou Ho20c47b42022-11-30 17:51:17 +0000358 ASSERT_TRUE(readRet.isOk());
Eric Biggers961a1382023-07-18 02:34:00 +0000359 EXPECT_TRUE(response.value.empty());
360 EXPECT_EQ(response.timeout, 0u);
361 EXPECT_EQ(response.status, WeaverReadStatus::FAILED);
ChengYou Ho10f8a482021-01-02 22:45:32 +0800362}
363
364/*
365 * Writing a key that is too large fails
366 */
Eric Biggersb59654f2023-07-18 02:33:59 +0000367TEST_P(WeaverTest, WriteWithTooLargeKeyFails) {
Eric Biggers961a1382023-07-18 02:34:00 +0000368 std::vector<uint8_t> bigKey(config_.keySize + 1);
ChengYou Ho10f8a482021-01-02 22:45:32 +0800369
Eric Biggers31380e72023-07-18 02:34:00 +0000370 const auto writeRet = weaver_->write(first_free_slot_, bigKey, VALUE);
ChengYou Ho10f8a482021-01-02 22:45:32 +0800371 ASSERT_FALSE(writeRet.isOk());
372}
373
374/*
375 * Writing a value that is too large fails
376 */
Eric Biggersb59654f2023-07-18 02:33:59 +0000377TEST_P(WeaverTest, WriteWithTooLargeValueFails) {
Eric Biggers961a1382023-07-18 02:34:00 +0000378 std::vector<uint8_t> bigValue(config_.valueSize + 1);
ChengYou Ho10f8a482021-01-02 22:45:32 +0800379
Eric Biggers31380e72023-07-18 02:34:00 +0000380 const auto writeRet = weaver_->write(first_free_slot_, KEY, bigValue);
ChengYou Ho10f8a482021-01-02 22:45:32 +0800381 ASSERT_FALSE(writeRet.isOk());
382}
383
384/*
Eric Biggers961a1382023-07-18 02:34:00 +0000385 * Reading with a key that is too large fails
ChengYou Ho10f8a482021-01-02 22:45:32 +0800386 */
Eric Biggersb59654f2023-07-18 02:33:59 +0000387TEST_P(WeaverTest, ReadWithTooLargeKeyFails) {
Eric Biggers961a1382023-07-18 02:34:00 +0000388 std::vector<uint8_t> bigKey(config_.keySize + 1);
ChengYou Ho10f8a482021-01-02 22:45:32 +0800389
ChengYou Ho10f8a482021-01-02 22:45:32 +0800390 WeaverReadResponse response;
Eric Biggers31380e72023-07-18 02:34:00 +0000391 const auto readRet = weaver_->read(first_free_slot_, bigKey, &response);
ChengYou Ho20c47b42022-11-30 17:51:17 +0000392 ASSERT_TRUE(readRet.isOk());
Eric Biggers961a1382023-07-18 02:34:00 +0000393 EXPECT_TRUE(response.value.empty());
394 EXPECT_EQ(response.timeout, 0u);
395 EXPECT_EQ(response.status, WeaverReadStatus::FAILED);
ChengYou Ho10f8a482021-01-02 22:45:32 +0800396}
397
Eric Biggers47b145a2023-07-24 17:21:28 +0000398GTEST_ALLOW_UNINSTANTIATED_PARAMETERIZED_TEST(WeaverTest);
399
Eric Biggersb59654f2023-07-18 02:33:59 +0000400// Instantiate the test for each HIDL Weaver service.
ChengYou Ho10f8a482021-01-02 22:45:32 +0800401INSTANTIATE_TEST_SUITE_P(
Eric Biggersb59654f2023-07-18 02:33:59 +0000402 PerHidlInstance, WeaverTest,
403 testing::Combine(testing::Values("hidl"),
404 testing::ValuesIn(android::hardware::getAllHalInstanceNames(
405 HidlIWeaver::descriptor))),
406 [](const testing::TestParamInfo<std::tuple<std::string, std::string>>& info) {
407 return android::hardware::PrintInstanceNameToString(
408 testing::TestParamInfo<std::string>{std::get<1>(info.param), info.index});
409 });
410
411// Instantiate the test for each AIDL Weaver service.
412INSTANTIATE_TEST_SUITE_P(
413 PerAidlInstance, WeaverTest,
414 testing::Combine(testing::Values("aidl"),
415 testing::ValuesIn(android::getAidlHalInstanceNames(IWeaver::descriptor))),
416 [](const testing::TestParamInfo<std::tuple<std::string, std::string>>& info) {
417 // This name_generator makes the instance name be included in the test case names, e.g.
418 // "PerAidlInstance/WeaverTest#GetConfig/0_android_hardware_weaver_IWeaver_default"
419 // instead of "PerAidlInstance/WeaverTest#GetConfig/0".
420 return android::PrintInstanceNameToString(
421 testing::TestParamInfo<std::string>{std::get<1>(info.param), info.index});
422 });
ChengYou Ho10f8a482021-01-02 22:45:32 +0800423
424int main(int argc, char** argv) {
425 ::testing::InitGoogleTest(&argc, argv);
426 ABinderProcess_setThreadPoolMaxThreadCount(1);
427 ABinderProcess_startThreadPool();
428 return RUN_ALL_TESTS();
429}