blob: fd55b80fde823e5ddef8b4f54975eb58945b1587 [file] [log] [blame]
Arthur Ishiguro4e916c32021-08-12 12:47:03 -07001/*
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#include <aidl/Gtest.h>
17#include <aidl/Vintf.h>
18
19#include "VtsHalContexthubUtilsCommon.h"
20
21#include <android/hardware/contexthub/BnContextHub.h>
22#include <android/hardware/contexthub/BnContextHubCallback.h>
23#include <android/hardware/contexthub/IContextHub.h>
24#include <android/hardware/contexthub/IContextHubCallback.h>
25#include <binder/IServiceManager.h>
26#include <binder/ProcessState.h>
27#include <log/log.h>
28
29#include <cinttypes>
30#include <future>
31
32using ::android::ProcessState;
33using ::android::sp;
34using ::android::String16;
35using ::android::binder::Status;
36using ::android::hardware::contexthub::AsyncEventType;
37using ::android::hardware::contexthub::ContextHubInfo;
38using ::android::hardware::contexthub::ContextHubMessage;
Matthew Sedamadfd5572023-11-21 05:53:00 -080039using ::android::hardware::contexthub::ErrorCode;
Arthur Ishiguro065a9a52021-11-19 00:24:45 +000040using ::android::hardware::contexthub::HostEndpointInfo;
Arthur Ishiguro4e916c32021-08-12 12:47:03 -070041using ::android::hardware::contexthub::IContextHub;
42using ::android::hardware::contexthub::IContextHubCallbackDefault;
Matthew Sedamadfd5572023-11-21 05:53:00 -080043using ::android::hardware::contexthub::MessageDeliveryStatus;
Arthur Ishiguro4e916c32021-08-12 12:47:03 -070044using ::android::hardware::contexthub::NanoappBinary;
45using ::android::hardware::contexthub::NanoappInfo;
Arthur Ishiguro08103072021-12-09 18:30:49 +000046using ::android::hardware::contexthub::NanoappRpcService;
Anthony Stange7fba1002023-03-02 21:45:20 +000047using ::android::hardware::contexthub::NanSessionRequest;
48using ::android::hardware::contexthub::NanSessionStateUpdate;
Arthur Ishiguro4e916c32021-08-12 12:47:03 -070049using ::android::hardware::contexthub::Setting;
50using ::android::hardware::contexthub::vts_utils::kNonExistentAppId;
51using ::android::hardware::contexthub::vts_utils::waitForCallback;
52
Lei Ju8787afa2023-06-28 09:36:19 -070053// 6612b522-b717-41c8-b48d-c0b1cc64e142
Lei Ju5b2ded42023-12-05 15:08:21 -080054constexpr std::array<uint8_t, 16> kUuid = {0x66, 0x12, 0xb5, 0x22, 0xb7, 0x17, 0x41, 0xc8,
55 0xb4, 0x8d, 0xc0, 0xb1, 0xcc, 0x64, 0xe1, 0x42};
56const String16 kName{"VtsAidlHalContextHubTargetTest"};
Lei Ju8787afa2023-06-28 09:36:19 -070057
Arthur Ishiguro4e916c32021-08-12 12:47:03 -070058class ContextHubAidl : public testing::TestWithParam<std::tuple<std::string, int32_t>> {
59 public:
60 virtual void SetUp() override {
61 contextHub = android::waitForDeclaredService<IContextHub>(
62 String16(std::get<0>(GetParam()).c_str()));
63 ASSERT_NE(contextHub, nullptr);
64 }
65
66 uint32_t getHubId() { return std::get<1>(GetParam()); }
67
68 void testSettingChanged(Setting setting);
69
70 sp<IContextHub> contextHub;
71};
72
73TEST_P(ContextHubAidl, TestGetHubs) {
74 std::vector<ContextHubInfo> hubs;
75 ASSERT_TRUE(contextHub->getContextHubs(&hubs).isOk());
76
77 ALOGD("System reports %zu hubs", hubs.size());
78
79 for (const ContextHubInfo& hub : hubs) {
80 ALOGD("Checking hub ID %" PRIu32, hub.id);
81
82 EXPECT_GT(hub.name.size(), 0);
83 EXPECT_GT(hub.vendor.size(), 0);
84 EXPECT_GT(hub.toolchain.size(), 0);
85 EXPECT_GT(hub.peakMips, 0);
86 EXPECT_GT(hub.chrePlatformId, 0);
87 EXPECT_GT(hub.chreApiMajorVersion, 0);
Arthur Ishiguro6471f612021-10-28 21:59:55 +000088 EXPECT_GE(hub.chreApiMinorVersion, 0);
89 EXPECT_GE(hub.chrePatchVersion, 0);
Arthur Ishiguro4e916c32021-08-12 12:47:03 -070090
91 // Minimum 128 byte MTU as required by CHRE API v1.0
92 EXPECT_GE(hub.maxSupportedMessageLengthBytes, UINT32_C(128));
93 }
94}
95
Matthew Sedamc8ce4d52023-01-09 20:18:21 +000096TEST_P(ContextHubAidl, TestEnableTestMode) {
97 Status status = contextHub->setTestMode(true);
98 if (status.exceptionCode() == Status::EX_UNSUPPORTED_OPERATION ||
99 status.transactionError() == android::UNKNOWN_TRANSACTION) {
Matthew Sedam121b6d62023-01-19 19:04:53 +0000100 GTEST_SKIP() << "Not supported -> old API; or not implemented";
101 } else {
102 ASSERT_TRUE(status.isOk());
Matthew Sedamc8ce4d52023-01-09 20:18:21 +0000103 }
Matthew Sedamc8ce4d52023-01-09 20:18:21 +0000104}
105
106TEST_P(ContextHubAidl, TestDisableTestMode) {
107 Status status = contextHub->setTestMode(false);
108 if (status.exceptionCode() == Status::EX_UNSUPPORTED_OPERATION ||
109 status.transactionError() == android::UNKNOWN_TRANSACTION) {
Matthew Sedam121b6d62023-01-19 19:04:53 +0000110 GTEST_SKIP() << "Not supported -> old API; or not implemented";
111 } else {
112 ASSERT_TRUE(status.isOk());
Matthew Sedamc8ce4d52023-01-09 20:18:21 +0000113 }
Matthew Sedamc8ce4d52023-01-09 20:18:21 +0000114}
115
Arthur Ishiguroe6b540d2021-10-29 16:01:35 +0000116class EmptyContextHubCallback : public android::hardware::contexthub::BnContextHubCallback {
117 public:
118 Status handleNanoappInfo(const std::vector<NanoappInfo>& /* appInfo */) override {
119 return Status::ok();
120 }
121
122 Status handleContextHubMessage(const ContextHubMessage& /* msg */,
123 const std::vector<String16>& /* msgContentPerms */) override {
124 return Status::ok();
125 }
126
127 Status handleContextHubAsyncEvent(AsyncEventType /* evt */) override { return Status::ok(); }
128
129 Status handleTransactionResult(int32_t /* transactionId */, bool /* success */) override {
130 return Status::ok();
131 }
Anthony Stange7344af92022-12-22 14:21:31 +0000132
Anthony Stange7fba1002023-03-02 21:45:20 +0000133 Status handleNanSessionRequest(const NanSessionRequest& /* request */) override {
134 return Status::ok();
135 }
Lei Ju8787afa2023-06-28 09:36:19 -0700136
Matthew Sedamadfd5572023-11-21 05:53:00 -0800137 Status handleMessageDeliveryStatus(
138 char16_t /* hostEndPointId */,
139 const MessageDeliveryStatus& /* messageDeliveryStatus */) override {
140 return Status::ok();
141 }
142
Lei Ju8787afa2023-06-28 09:36:19 -0700143 Status getUuid(std::array<uint8_t, 16>* out_uuid) override {
144 *out_uuid = kUuid;
145 return Status::ok();
146 }
Lei Ju5b2ded42023-12-05 15:08:21 -0800147
148 Status getName(::android::String16* out_name) override {
149 *out_name = kName;
150 return Status::ok();
151 }
Arthur Ishiguroe6b540d2021-10-29 16:01:35 +0000152};
153
Arthur Ishiguro4e916c32021-08-12 12:47:03 -0700154TEST_P(ContextHubAidl, TestRegisterCallback) {
Arthur Ishiguroe6b540d2021-10-29 16:01:35 +0000155 sp<EmptyContextHubCallback> cb = sp<EmptyContextHubCallback>::make();
Arthur Ishiguro070f47d2022-01-06 22:42:10 +0000156 ASSERT_TRUE(contextHub->registerCallback(getHubId(), cb).isOk());
Arthur Ishiguro4e916c32021-08-12 12:47:03 -0700157}
158
Arthur Ishiguro4e916c32021-08-12 12:47:03 -0700159// Helper callback that puts the async appInfo callback data into a promise
160class QueryAppsCallback : public android::hardware::contexthub::BnContextHubCallback {
161 public:
162 Status handleNanoappInfo(const std::vector<NanoappInfo>& appInfo) override {
163 ALOGD("Got app info callback with %zu apps", appInfo.size());
164 promise.set_value(appInfo);
165 return Status::ok();
166 }
167
168 Status handleContextHubMessage(const ContextHubMessage& /* msg */,
169 const std::vector<String16>& /* msgContentPerms */) override {
170 return Status::ok();
171 }
172
173 Status handleContextHubAsyncEvent(AsyncEventType /* evt */) override { return Status::ok(); }
174
175 Status handleTransactionResult(int32_t /* transactionId */, bool /* success */) override {
176 return Status::ok();
177 }
178
Anthony Stange7fba1002023-03-02 21:45:20 +0000179 Status handleNanSessionRequest(const NanSessionRequest& /* request */) override {
180 return Status::ok();
181 }
Anthony Stange7344af92022-12-22 14:21:31 +0000182
Matthew Sedamadfd5572023-11-21 05:53:00 -0800183 Status handleMessageDeliveryStatus(
184 char16_t /* hostEndPointId */,
185 const MessageDeliveryStatus& /* messageDeliveryStatus */) override {
186 return Status::ok();
187 }
188
Lei Ju8787afa2023-06-28 09:36:19 -0700189 Status getUuid(std::array<uint8_t, 16>* out_uuid) override {
190 *out_uuid = kUuid;
191 return Status::ok();
192 }
193
Lei Ju5b2ded42023-12-05 15:08:21 -0800194 Status getName(::android::String16* out_name) override {
195 *out_name = kName;
196 return Status::ok();
197 }
198
Arthur Ishiguro4e916c32021-08-12 12:47:03 -0700199 std::promise<std::vector<NanoappInfo>> promise;
200};
201
202// Calls queryApps() and checks the returned metadata
203TEST_P(ContextHubAidl, TestQueryApps) {
204 sp<QueryAppsCallback> cb = sp<QueryAppsCallback>::make();
Arthur Ishiguro070f47d2022-01-06 22:42:10 +0000205 ASSERT_TRUE(contextHub->registerCallback(getHubId(), cb).isOk());
206 ASSERT_TRUE(contextHub->queryNanoapps(getHubId()).isOk());
Arthur Ishiguro4e916c32021-08-12 12:47:03 -0700207
208 std::vector<NanoappInfo> appInfoList;
209 ASSERT_TRUE(waitForCallback(cb->promise.get_future(), &appInfoList));
210 for (const NanoappInfo& appInfo : appInfoList) {
211 EXPECT_NE(appInfo.nanoappId, UINT64_C(0));
212 EXPECT_NE(appInfo.nanoappId, kNonExistentAppId);
Arthur Ishiguro08103072021-12-09 18:30:49 +0000213
214 // Verify services are unique.
215 std::set<uint64_t> existingServiceIds;
216 for (const NanoappRpcService& rpcService : appInfo.rpcServices) {
217 EXPECT_NE(rpcService.id, UINT64_C(0));
218 EXPECT_EQ(existingServiceIds.count(rpcService.id), 0);
219 existingServiceIds.insert(rpcService.id);
220 }
Arthur Ishiguro4e916c32021-08-12 12:47:03 -0700221 }
222}
223
Matthew Sedamd70f84d2023-03-06 18:34:24 +0000224// Calls getPreloadedNanoappsIds() and verifies there are preloaded nanoapps
225TEST_P(ContextHubAidl, TestGetPreloadedNanoappIds) {
Arthur Ishigurofd5e65c2022-11-08 16:49:47 +0000226 std::vector<int64_t> preloadedNanoappIds;
Matthew Sedamd70f84d2023-03-06 18:34:24 +0000227 Status status = contextHub->getPreloadedNanoappIds(getHubId(), &preloadedNanoappIds);
Arthur Ishigurofd5e65c2022-11-08 16:49:47 +0000228 if (status.exceptionCode() == Status::EX_UNSUPPORTED_OPERATION ||
229 status.transactionError() == android::UNKNOWN_TRANSACTION) {
Matthew Sedam121b6d62023-01-19 19:04:53 +0000230 GTEST_SKIP() << "Not supported -> old API; or not implemented";
231 } else {
232 ASSERT_TRUE(status.isOk());
Arthur Ishigurofd5e65c2022-11-08 16:49:47 +0000233 }
Arthur Ishigurofd5e65c2022-11-08 16:49:47 +0000234}
235
Arthur Ishiguro4e916c32021-08-12 12:47:03 -0700236// Helper callback that puts the TransactionResult for the expectedTransactionId into a
237// promise
238class TransactionResultCallback : public android::hardware::contexthub::BnContextHubCallback {
239 public:
240 Status handleNanoappInfo(const std::vector<NanoappInfo>& /* appInfo */) override {
241 return Status::ok();
242 }
243
244 Status handleContextHubMessage(const ContextHubMessage& /* msg */,
245 const std::vector<String16>& /* msgContentPerms */) override {
246 return Status::ok();
247 }
248
249 Status handleContextHubAsyncEvent(AsyncEventType /* evt */) override { return Status::ok(); }
250
251 Status handleTransactionResult(int32_t transactionId, bool success) override {
252 ALOGD("Got transaction result callback for transactionId %" PRIu32 " (expecting %" PRIu32
253 ") with success %d",
254 transactionId, expectedTransactionId, success);
255 if (transactionId == expectedTransactionId) {
256 promise.set_value(success);
257 }
258 return Status::ok();
259 }
260
Anthony Stange7fba1002023-03-02 21:45:20 +0000261 Status handleNanSessionRequest(const NanSessionRequest& /* request */) override {
262 return Status::ok();
263 }
Anthony Stange7344af92022-12-22 14:21:31 +0000264
Matthew Sedamadfd5572023-11-21 05:53:00 -0800265 Status handleMessageDeliveryStatus(
266 char16_t /* hostEndPointId */,
267 const MessageDeliveryStatus& /* messageDeliveryStatus */) override {
268 return Status::ok();
269 }
270
Lei Ju8787afa2023-06-28 09:36:19 -0700271 Status getUuid(std::array<uint8_t, 16>* out_uuid) override {
272 *out_uuid = kUuid;
273 return Status::ok();
274 }
275
Lei Ju5b2ded42023-12-05 15:08:21 -0800276 Status getName(::android::String16* out_name) override {
277 *out_name = kName;
278 return Status::ok();
279 }
280
Arthur Ishiguro4e916c32021-08-12 12:47:03 -0700281 uint32_t expectedTransactionId = 0;
282 std::promise<bool> promise;
283};
284
285// Parameterized fixture that sets the callback to TransactionResultCallback
286class ContextHubTransactionTest : public ContextHubAidl {
287 public:
288 virtual void SetUp() override {
289 ContextHubAidl::SetUp();
Arthur Ishiguro070f47d2022-01-06 22:42:10 +0000290 ASSERT_TRUE(contextHub->registerCallback(getHubId(), cb).isOk());
Arthur Ishiguro4e916c32021-08-12 12:47:03 -0700291 }
292
293 sp<TransactionResultCallback> cb = sp<TransactionResultCallback>::make();
294};
295
296TEST_P(ContextHubTransactionTest, TestSendMessageToNonExistentNanoapp) {
297 ContextHubMessage message;
298 message.nanoappId = kNonExistentAppId;
299 message.messageType = 1;
300 message.messageBody.resize(4);
301 std::fill(message.messageBody.begin(), message.messageBody.end(), 0);
302
303 ALOGD("Sending message to non-existent nanoapp");
Arthur Ishiguro070f47d2022-01-06 22:42:10 +0000304 ASSERT_TRUE(contextHub->sendMessageToHub(getHubId(), message).isOk());
Arthur Ishiguro4e916c32021-08-12 12:47:03 -0700305}
306
307TEST_P(ContextHubTransactionTest, TestLoadEmptyNanoapp) {
308 cb->expectedTransactionId = 0123;
309 NanoappBinary emptyApp;
310
311 emptyApp.nanoappId = kNonExistentAppId;
312 emptyApp.nanoappVersion = 1;
313 emptyApp.flags = 0;
314 emptyApp.targetChreApiMajorVersion = 1;
315 emptyApp.targetChreApiMinorVersion = 0;
316
317 ALOGD("Loading empty nanoapp");
Arthur Ishiguro070f47d2022-01-06 22:42:10 +0000318 bool success = contextHub->loadNanoapp(getHubId(), emptyApp, cb->expectedTransactionId).isOk();
Arthur Ishiguro4e916c32021-08-12 12:47:03 -0700319 if (success) {
320 bool transactionSuccess;
321 ASSERT_TRUE(waitForCallback(cb->promise.get_future(), &transactionSuccess));
322 ASSERT_FALSE(transactionSuccess);
323 }
324}
325
326TEST_P(ContextHubTransactionTest, TestUnloadNonexistentNanoapp) {
327 cb->expectedTransactionId = 1234;
328
329 ALOGD("Unloading nonexistent nanoapp");
Arthur Ishiguro070f47d2022-01-06 22:42:10 +0000330 bool success =
331 contextHub->unloadNanoapp(getHubId(), kNonExistentAppId, cb->expectedTransactionId)
332 .isOk();
Arthur Ishiguro4e916c32021-08-12 12:47:03 -0700333 if (success) {
334 bool transactionSuccess;
335 ASSERT_TRUE(waitForCallback(cb->promise.get_future(), &transactionSuccess));
336 ASSERT_FALSE(transactionSuccess);
337 }
338}
339
340TEST_P(ContextHubTransactionTest, TestEnableNonexistentNanoapp) {
341 cb->expectedTransactionId = 2345;
342
343 ALOGD("Enabling nonexistent nanoapp");
Arthur Ishiguro070f47d2022-01-06 22:42:10 +0000344 bool success =
345 contextHub->enableNanoapp(getHubId(), kNonExistentAppId, cb->expectedTransactionId)
346 .isOk();
Arthur Ishiguro4e916c32021-08-12 12:47:03 -0700347 if (success) {
348 bool transactionSuccess;
349 ASSERT_TRUE(waitForCallback(cb->promise.get_future(), &transactionSuccess));
350 ASSERT_FALSE(transactionSuccess);
351 }
352}
353
354TEST_P(ContextHubTransactionTest, TestDisableNonexistentNanoapp) {
355 cb->expectedTransactionId = 3456;
356
357 ALOGD("Disabling nonexistent nanoapp");
Arthur Ishiguro070f47d2022-01-06 22:42:10 +0000358 bool success =
359 contextHub->disableNanoapp(getHubId(), kNonExistentAppId, cb->expectedTransactionId)
360 .isOk();
Arthur Ishiguro4e916c32021-08-12 12:47:03 -0700361 if (success) {
362 bool transactionSuccess;
363 ASSERT_TRUE(waitForCallback(cb->promise.get_future(), &transactionSuccess));
364 ASSERT_FALSE(transactionSuccess);
365 }
366}
367
368void ContextHubAidl::testSettingChanged(Setting setting) {
369 // In VTS, we only test that sending the values doesn't cause things to blow up - GTS tests
370 // verify the expected E2E behavior in CHRE
Arthur Ishiguroe6b540d2021-10-29 16:01:35 +0000371 sp<EmptyContextHubCallback> cb = sp<EmptyContextHubCallback>::make();
Arthur Ishiguro070f47d2022-01-06 22:42:10 +0000372 ASSERT_TRUE(contextHub->registerCallback(getHubId(), cb).isOk());
Arthur Ishiguro4e916c32021-08-12 12:47:03 -0700373
374 ASSERT_TRUE(contextHub->onSettingChanged(setting, true /* enabled */).isOk());
375 ASSERT_TRUE(contextHub->onSettingChanged(setting, false /* enabled */).isOk());
Arthur Ishiguro4e916c32021-08-12 12:47:03 -0700376}
377
378TEST_P(ContextHubAidl, TestOnLocationSettingChanged) {
379 testSettingChanged(Setting::LOCATION);
380}
381
382TEST_P(ContextHubAidl, TestOnWifiMainSettingChanged) {
383 testSettingChanged(Setting::WIFI_MAIN);
384}
385
386TEST_P(ContextHubAidl, TestOnWifiScanningSettingChanged) {
387 testSettingChanged(Setting::WIFI_SCANNING);
388}
389
390TEST_P(ContextHubAidl, TestOnAirplaneModeSettingChanged) {
391 testSettingChanged(Setting::AIRPLANE_MODE);
392}
393
394TEST_P(ContextHubAidl, TestOnMicrophoneSettingChanged) {
395 testSettingChanged(Setting::MICROPHONE);
396}
397
Anthonya6b65002022-01-20 20:49:10 +0000398TEST_P(ContextHubAidl, TestOnBtMainSettingChanged) {
399 testSettingChanged(Setting::BT_MAIN);
400}
401
402TEST_P(ContextHubAidl, TestOnBtScanningSettingChanged) {
403 testSettingChanged(Setting::BT_SCANNING);
404}
405
Arthur Ishiguro4e916c32021-08-12 12:47:03 -0700406std::vector<std::tuple<std::string, int32_t>> generateContextHubMapping() {
407 std::vector<std::tuple<std::string, int32_t>> tuples;
408 auto contextHubAidlNames = android::getAidlHalInstanceNames(IContextHub::descriptor);
409 std::vector<ContextHubInfo> contextHubInfos;
410
411 for (int i = 0; i < contextHubAidlNames.size(); i++) {
412 auto contextHubName = contextHubAidlNames[i].c_str();
413 auto contextHub = android::waitForDeclaredService<IContextHub>(String16(contextHubName));
414 if (contextHub->getContextHubs(&contextHubInfos).isOk()) {
415 for (auto& info : contextHubInfos) {
416 tuples.push_back(std::make_tuple(contextHubName, info.id));
417 }
418 }
419 }
420
421 return tuples;
422}
423
Arthur Ishiguro065a9a52021-11-19 00:24:45 +0000424TEST_P(ContextHubAidl, TestHostConnection) {
425 constexpr char16_t kHostEndpointId = 1;
426 HostEndpointInfo hostEndpointInfo;
Arthur Ishiguro16f40622023-02-10 18:11:12 +0000427 hostEndpointInfo.type = HostEndpointInfo::Type::NATIVE;
Arthur Ishiguro065a9a52021-11-19 00:24:45 +0000428 hostEndpointInfo.hostEndpointId = kHostEndpointId;
429
430 ASSERT_TRUE(contextHub->onHostEndpointConnected(hostEndpointInfo).isOk());
431 ASSERT_TRUE(contextHub->onHostEndpointDisconnected(kHostEndpointId).isOk());
432}
433
434TEST_P(ContextHubAidl, TestInvalidHostConnection) {
435 constexpr char16_t kHostEndpointId = 1;
436
Arthur Ishiguro5dba9212022-02-01 17:03:32 +0000437 ASSERT_TRUE(contextHub->onHostEndpointDisconnected(kHostEndpointId).isOk());
Arthur Ishiguro065a9a52021-11-19 00:24:45 +0000438}
439
Anthony Stange7344af92022-12-22 14:21:31 +0000440TEST_P(ContextHubAidl, TestNanSessionStateChange) {
Anthony Stange7fba1002023-03-02 21:45:20 +0000441 NanSessionStateUpdate update;
442 update.state = true;
Rocky Fang78140982023-06-16 00:42:41 +0000443 Status status = contextHub->onNanSessionStateChanged(update);
444 if (status.exceptionCode() == Status::EX_UNSUPPORTED_OPERATION ||
445 status.transactionError() == android::UNKNOWN_TRANSACTION) {
446 GTEST_SKIP() << "Not supported -> old API; or not implemented";
447 } else {
448 ASSERT_TRUE(status.isOk());
449 update.state = false;
450 ASSERT_TRUE(contextHub->onNanSessionStateChanged(update).isOk());
451 }
Anthony Stange7344af92022-12-22 14:21:31 +0000452}
453
Matthew Sedamadfd5572023-11-21 05:53:00 -0800454TEST_P(ContextHubAidl, TestSendMessageDeliveryStatusToHub) {
455 MessageDeliveryStatus messageDeliveryStatus;
456 messageDeliveryStatus.messageSequenceNumber = 123;
457 messageDeliveryStatus.errorCode = ErrorCode::OK;
458
459 Status status = contextHub->sendMessageDeliveryStatusToHub(getHubId(), messageDeliveryStatus);
460 if (status.exceptionCode() == Status::EX_UNSUPPORTED_OPERATION ||
461 status.transactionError() == android::UNKNOWN_TRANSACTION) {
462 GTEST_SKIP() << "Not supported -> old API; or not implemented";
463 } else {
464 EXPECT_TRUE(status.isOk());
465 }
466}
467
Arthur Ishiguro4e916c32021-08-12 12:47:03 -0700468std::string PrintGeneratedTest(const testing::TestParamInfo<ContextHubAidl::ParamType>& info) {
469 return std::string("CONTEXT_HUB_ID_") + std::to_string(std::get<1>(info.param));
470}
471
472GTEST_ALLOW_UNINSTANTIATED_PARAMETERIZED_TEST(ContextHubAidl);
473INSTANTIATE_TEST_SUITE_P(ContextHub, ContextHubAidl, testing::ValuesIn(generateContextHubMapping()),
474 PrintGeneratedTest);
475
476GTEST_ALLOW_UNINSTANTIATED_PARAMETERIZED_TEST(ContextHubTransactionTest);
477INSTANTIATE_TEST_SUITE_P(ContextHub, ContextHubTransactionTest,
478 testing::ValuesIn(generateContextHubMapping()), PrintGeneratedTest);
479
480int main(int argc, char** argv) {
481 ::testing::InitGoogleTest(&argc, argv);
482 ProcessState::self()->setThreadPoolMaxThreadCount(1);
483 ProcessState::self()->startThreadPool();
484 return RUN_ALL_TESTS();
485}