blob: faa84169fe0de51a6773907f5128031f3c627e7d [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 }
Eric Biggers649c20e2024-09-30 23:39:28 +0000223
224 // We should assert !used_slots.empty() here, but that can't be done yet due to
225 // config_disableWeaverOnUnsecuredUsers being supported. The value of that option is not
226 // accessible from here, so we have to assume it might be set to true.
Eric Biggers31380e72023-07-18 02:34:00 +0000227
228 // Find the first free slot.
229 int found = 0;
230 for (uint32_t i = 0; i < config_.slots; i++) {
231 if (used_slots.find(i) == used_slots.end()) {
232 first_free_slot_ = i;
233 found++;
234 break;
235 }
236 }
237 // Find the last free slot.
238 for (uint32_t i = config_.slots; i > 0; i--) {
239 if (used_slots.find(i - 1) == used_slots.end()) {
240 last_free_slot_ = i - 1;
241 found++;
242 break;
243 }
244 }
245 ASSERT_EQ(found, 2) << "All Weaver slots are already in use by the system";
Eric Biggersb59654f2023-07-18 02:33:59 +0000246}
247
ChengYou Ho10f8a482021-01-02 22:45:32 +0800248/*
249 * Checks config values are suitably large
250 */
Eric Biggersb59654f2023-07-18 02:33:59 +0000251TEST_P(WeaverTest, GetConfig) {
Eric Biggers961a1382023-07-18 02:34:00 +0000252 EXPECT_GE(config_.slots, 16u);
253 EXPECT_GE(config_.keySize, 16u);
254 EXPECT_GE(config_.valueSize, 16u);
ChengYou Ho10f8a482021-01-02 22:45:32 +0800255}
256
257/*
258 * Gets the config twice and checks they are the same
259 */
Eric Biggersb59654f2023-07-18 02:33:59 +0000260TEST_P(WeaverTest, GettingConfigMultipleTimesGivesSameResult) {
ChengYou Ho10f8a482021-01-02 22:45:32 +0800261 WeaverConfig config2;
262
Eric Biggers961a1382023-07-18 02:34:00 +0000263 auto ret = weaver_->getConfig(&config2);
ChengYou Ho10f8a482021-01-02 22:45:32 +0800264 ASSERT_TRUE(ret.isOk());
265
Eric Biggers961a1382023-07-18 02:34:00 +0000266 EXPECT_EQ(config_, config2);
ChengYou Ho10f8a482021-01-02 22:45:32 +0800267}
268
269/*
Eric Biggers31380e72023-07-18 02:34:00 +0000270 * Writes a key and value to the last free slot
ChengYou Ho10f8a482021-01-02 22:45:32 +0800271 */
Eric Biggersb59654f2023-07-18 02:33:59 +0000272TEST_P(WeaverTest, WriteToLastSlot) {
Eric Biggers31380e72023-07-18 02:34:00 +0000273 const auto writeRet = weaver_->write(last_free_slot_, KEY, VALUE);
ChengYou Ho10f8a482021-01-02 22:45:32 +0800274 ASSERT_TRUE(writeRet.isOk());
275}
276
277/*
278 * Writes a key and value to a slot
279 * Reads the slot with the same key and receives the value that was previously written
280 */
Eric Biggersb59654f2023-07-18 02:33:59 +0000281TEST_P(WeaverTest, WriteFollowedByReadGivesTheSameValue) {
Eric Biggers31380e72023-07-18 02:34:00 +0000282 const uint32_t slotId = first_free_slot_;
Eric Biggers961a1382023-07-18 02:34:00 +0000283 const auto ret = weaver_->write(slotId, KEY, VALUE);
ChengYou Ho10f8a482021-01-02 22:45:32 +0800284 ASSERT_TRUE(ret.isOk());
285
286 WeaverReadResponse response;
Eric Biggers961a1382023-07-18 02:34:00 +0000287 const auto readRet = weaver_->read(slotId, KEY, &response);
ChengYou Ho10f8a482021-01-02 22:45:32 +0800288 ASSERT_TRUE(readRet.isOk());
Eric Biggers961a1382023-07-18 02:34:00 +0000289 EXPECT_EQ(response.value, VALUE);
290 EXPECT_EQ(response.timeout, 0u);
291 EXPECT_EQ(response.status, WeaverReadStatus::OK);
ChengYou Ho10f8a482021-01-02 22:45:32 +0800292}
293
294/*
295 * Writes a key and value to a slot
296 * Overwrites the slot with a new key and value
297 * Reads the slot with the new key and receives the new value
298 */
Eric Biggersb59654f2023-07-18 02:33:59 +0000299TEST_P(WeaverTest, OverwritingSlotUpdatesTheValue) {
Eric Biggers31380e72023-07-18 02:34:00 +0000300 const uint32_t slotId = first_free_slot_;
Eric Biggers961a1382023-07-18 02:34:00 +0000301 const auto initialWriteRet = weaver_->write(slotId, WRONG_KEY, VALUE);
ChengYou Ho10f8a482021-01-02 22:45:32 +0800302 ASSERT_TRUE(initialWriteRet.isOk());
303
Eric Biggers961a1382023-07-18 02:34:00 +0000304 const auto overwriteRet = weaver_->write(slotId, KEY, OTHER_VALUE);
ChengYou Ho10f8a482021-01-02 22:45:32 +0800305 ASSERT_TRUE(overwriteRet.isOk());
306
307 WeaverReadResponse response;
Eric Biggers961a1382023-07-18 02:34:00 +0000308 const auto readRet = weaver_->read(slotId, KEY, &response);
ChengYou Ho10f8a482021-01-02 22:45:32 +0800309 ASSERT_TRUE(readRet.isOk());
Eric Biggers961a1382023-07-18 02:34:00 +0000310 EXPECT_EQ(response.value, OTHER_VALUE);
311 EXPECT_EQ(response.timeout, 0u);
312 EXPECT_EQ(response.status, WeaverReadStatus::OK);
ChengYou Ho10f8a482021-01-02 22:45:32 +0800313}
314
315/*
316 * Writes a key and value to a slot
317 * Reads the slot with a different key so does not receive the value
318 */
Eric Biggersb59654f2023-07-18 02:33:59 +0000319TEST_P(WeaverTest, WriteFollowedByReadWithWrongKeyDoesNotGiveTheValue) {
Eric Biggers31380e72023-07-18 02:34:00 +0000320 const uint32_t slotId = first_free_slot_;
Eric Biggers961a1382023-07-18 02:34:00 +0000321 const auto writeRet = weaver_->write(slotId, KEY, VALUE);
322 ASSERT_TRUE(writeRet.isOk());
ChengYou Ho10f8a482021-01-02 22:45:32 +0800323
324 WeaverReadResponse response;
Eric Biggers961a1382023-07-18 02:34:00 +0000325 const auto readRet = weaver_->read(slotId, WRONG_KEY, &response);
ChengYou Ho20c47b42022-11-30 17:51:17 +0000326 ASSERT_TRUE(readRet.isOk());
Eric Biggers961a1382023-07-18 02:34:00 +0000327 EXPECT_TRUE(response.value.empty());
328 EXPECT_EQ(response.status, WeaverReadStatus::INCORRECT_KEY);
ChengYou Ho10f8a482021-01-02 22:45:32 +0800329}
330
331/*
332 * Writing to an invalid slot fails
333 */
Eric Biggersb59654f2023-07-18 02:33:59 +0000334TEST_P(WeaverTest, WritingToInvalidSlotFails) {
Eric Biggers961a1382023-07-18 02:34:00 +0000335 if (config_.slots == std::numeric_limits<uint32_t>::max()) {
ChengYou Ho10f8a482021-01-02 22:45:32 +0800336 // If there are no invalid slots then pass
337 return;
338 }
339
Eric Biggers961a1382023-07-18 02:34:00 +0000340 const auto writeRet = weaver_->write(config_.slots, KEY, VALUE);
ChengYou Ho10f8a482021-01-02 22:45:32 +0800341 ASSERT_FALSE(writeRet.isOk());
342}
343
344/*
345 * Reading from an invalid slot fails rather than incorrect key
346 */
Eric Biggersb59654f2023-07-18 02:33:59 +0000347TEST_P(WeaverTest, ReadingFromInvalidSlotFails) {
Eric Biggers961a1382023-07-18 02:34:00 +0000348 if (config_.slots == std::numeric_limits<uint32_t>::max()) {
ChengYou Ho10f8a482021-01-02 22:45:32 +0800349 // If there are no invalid slots then pass
350 return;
351 }
352
353 WeaverReadResponse response;
Eric Biggers961a1382023-07-18 02:34:00 +0000354 const auto readRet = weaver_->read(config_.slots, KEY, &response);
ChengYou Ho20c47b42022-11-30 17:51:17 +0000355 ASSERT_TRUE(readRet.isOk());
Eric Biggers961a1382023-07-18 02:34:00 +0000356 EXPECT_TRUE(response.value.empty());
357 EXPECT_EQ(response.timeout, 0u);
358 EXPECT_EQ(response.status, WeaverReadStatus::FAILED);
ChengYou Ho10f8a482021-01-02 22:45:32 +0800359}
360
361/*
362 * Writing a key that is too large fails
363 */
Eric Biggersb59654f2023-07-18 02:33:59 +0000364TEST_P(WeaverTest, WriteWithTooLargeKeyFails) {
Eric Biggers961a1382023-07-18 02:34:00 +0000365 std::vector<uint8_t> bigKey(config_.keySize + 1);
ChengYou Ho10f8a482021-01-02 22:45:32 +0800366
Eric Biggers31380e72023-07-18 02:34:00 +0000367 const auto writeRet = weaver_->write(first_free_slot_, bigKey, VALUE);
ChengYou Ho10f8a482021-01-02 22:45:32 +0800368 ASSERT_FALSE(writeRet.isOk());
369}
370
371/*
372 * Writing a value that is too large fails
373 */
Eric Biggersb59654f2023-07-18 02:33:59 +0000374TEST_P(WeaverTest, WriteWithTooLargeValueFails) {
Eric Biggers961a1382023-07-18 02:34:00 +0000375 std::vector<uint8_t> bigValue(config_.valueSize + 1);
ChengYou Ho10f8a482021-01-02 22:45:32 +0800376
Eric Biggers31380e72023-07-18 02:34:00 +0000377 const auto writeRet = weaver_->write(first_free_slot_, KEY, bigValue);
ChengYou Ho10f8a482021-01-02 22:45:32 +0800378 ASSERT_FALSE(writeRet.isOk());
379}
380
381/*
Eric Biggers961a1382023-07-18 02:34:00 +0000382 * Reading with a key that is too large fails
ChengYou Ho10f8a482021-01-02 22:45:32 +0800383 */
Eric Biggersb59654f2023-07-18 02:33:59 +0000384TEST_P(WeaverTest, ReadWithTooLargeKeyFails) {
Eric Biggers961a1382023-07-18 02:34:00 +0000385 std::vector<uint8_t> bigKey(config_.keySize + 1);
ChengYou Ho10f8a482021-01-02 22:45:32 +0800386
ChengYou Ho10f8a482021-01-02 22:45:32 +0800387 WeaverReadResponse response;
Eric Biggers31380e72023-07-18 02:34:00 +0000388 const auto readRet = weaver_->read(first_free_slot_, bigKey, &response);
ChengYou Ho20c47b42022-11-30 17:51:17 +0000389 ASSERT_TRUE(readRet.isOk());
Eric Biggers961a1382023-07-18 02:34:00 +0000390 EXPECT_TRUE(response.value.empty());
391 EXPECT_EQ(response.timeout, 0u);
392 EXPECT_EQ(response.status, WeaverReadStatus::FAILED);
ChengYou Ho10f8a482021-01-02 22:45:32 +0800393}
394
Eric Biggers47b145a2023-07-24 17:21:28 +0000395GTEST_ALLOW_UNINSTANTIATED_PARAMETERIZED_TEST(WeaverTest);
396
Eric Biggersb59654f2023-07-18 02:33:59 +0000397// Instantiate the test for each HIDL Weaver service.
ChengYou Ho10f8a482021-01-02 22:45:32 +0800398INSTANTIATE_TEST_SUITE_P(
Eric Biggersb59654f2023-07-18 02:33:59 +0000399 PerHidlInstance, WeaverTest,
400 testing::Combine(testing::Values("hidl"),
401 testing::ValuesIn(android::hardware::getAllHalInstanceNames(
402 HidlIWeaver::descriptor))),
403 [](const testing::TestParamInfo<std::tuple<std::string, std::string>>& info) {
404 return android::hardware::PrintInstanceNameToString(
405 testing::TestParamInfo<std::string>{std::get<1>(info.param), info.index});
406 });
407
408// Instantiate the test for each AIDL Weaver service.
409INSTANTIATE_TEST_SUITE_P(
410 PerAidlInstance, WeaverTest,
411 testing::Combine(testing::Values("aidl"),
412 testing::ValuesIn(android::getAidlHalInstanceNames(IWeaver::descriptor))),
413 [](const testing::TestParamInfo<std::tuple<std::string, std::string>>& info) {
414 // This name_generator makes the instance name be included in the test case names, e.g.
415 // "PerAidlInstance/WeaverTest#GetConfig/0_android_hardware_weaver_IWeaver_default"
416 // instead of "PerAidlInstance/WeaverTest#GetConfig/0".
417 return android::PrintInstanceNameToString(
418 testing::TestParamInfo<std::string>{std::get<1>(info.param), info.index});
419 });
ChengYou Ho10f8a482021-01-02 22:45:32 +0800420
421int main(int argc, char** argv) {
422 ::testing::InitGoogleTest(&argc, argv);
423 ABinderProcess_setThreadPoolMaxThreadCount(1);
424 ABinderProcess_startThreadPool();
425 return RUN_ALL_TESTS();
426}