1 /*
2  * Copyright (C) 2019 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 #include <android-base/logging.h>
18 #include <android-base/strings.h>
19 #include <android/hardware/automotive/can/1.0/ICanBus.h>
20 #include <android/hardware/automotive/can/1.0/ICanController.h>
21 #include <android/hardware/automotive/can/1.0/types.h>
22 #include <android/hidl/manager/1.2/IServiceManager.h>
23 #include <can-vts-utils/bus-enumerator.h>
24 #include <can-vts-utils/can-hal-printers.h>
25 #include <gmock/gmock.h>
26 #include <gtest/gtest.h>
27 #include <hidl-utils/hidl-utils.h>
28 #include <hidl/GtestPrinter.h>
29 #include <hidl/ServiceManagement.h>
30 #include <utils/Mutex.h>
31 #include <utils/SystemClock.h>
32 
33 #include <chrono>
34 #include <thread>
35 
36 namespace android::hardware::automotive::can::V1_0::vts {
37 
38 using namespace std::chrono_literals;
39 
40 using hardware::hidl_vec;
41 using InterfaceType = ICanController::InterfaceType;
42 
43 struct CanMessageListener : public can::V1_0::ICanMessageListener {
44     DISALLOW_COPY_AND_ASSIGN(CanMessageListener);
45 
CanMessageListenerandroid::hardware::automotive::can::V1_0::vts::CanMessageListener46     CanMessageListener() {}
47 
onReceiveandroid::hardware::automotive::can::V1_0::vts::CanMessageListener48     virtual Return<void> onReceive(const can::V1_0::CanMessage& msg) override {
49         std::unique_lock<std::mutex> lk(mMessagesGuard);
50         mMessages.push_back(msg);
51         mMessagesUpdated.notify_one();
52         return {};
53     }
54 
~CanMessageListenerandroid::hardware::automotive::can::V1_0::vts::CanMessageListener55     virtual ~CanMessageListener() { mCloseHandle->close(); }
56 
assignCloseHandleandroid::hardware::automotive::can::V1_0::vts::CanMessageListener57     void assignCloseHandle(sp<ICloseHandle> closeHandle) {
58         EXPECT_TRUE(closeHandle);
59         EXPECT_FALSE(mCloseHandle);
60         mCloseHandle = closeHandle;
61     }
62 
fetchMessagesandroid::hardware::automotive::can::V1_0::vts::CanMessageListener63     std::vector<can::V1_0::CanMessage> fetchMessages(std::chrono::milliseconds timeout,
64                                                      unsigned atLeast = 1) {
65         std::unique_lock<std::mutex> lk(mMessagesGuard);
66         mMessagesUpdated.wait_for(lk, timeout, [&] { return mMessages.size() >= atLeast; });
67         const auto messages = mMessages;
68         mMessages.clear();
69         return messages;
70     }
71 
72   private:
73     sp<ICloseHandle> mCloseHandle;
74 
75     std::mutex mMessagesGuard;
76     std::condition_variable mMessagesUpdated GUARDED_BY(mMessagesGuard);
77     std::vector<can::V1_0::CanMessage> mMessages GUARDED_BY(mMessagesGuard);
78 };
79 
80 struct Bus {
81     DISALLOW_COPY_AND_ASSIGN(Bus);
82 
Busandroid::hardware::automotive::can::V1_0::vts::Bus83     Bus(sp<ICanController> controller, const ICanController::BusConfig& config)
84         : mIfname(config.name), mController(controller) {
85         const auto result = controller->upInterface(config);
86         EXPECT_EQ(ICanController::Result::OK, result);
87 
88         /* Not using ICanBus::getService here, since it ignores interfaces not in the manifest
89          * file -- this is a test, so we don't want to add dummy services to a device manifest. */
90         auto manager = hidl::manager::V1_2::IServiceManager::getService();
91         auto service = manager->get(ICanBus::descriptor, config.name);
92         mBus = ICanBus::castFrom(service);
93         EXPECT_TRUE(mBus) << "ICanBus/" << config.name << " failed to register";
94     }
95 
~Busandroid::hardware::automotive::can::V1_0::vts::Bus96     virtual ~Bus() { reset(); }
97 
resetandroid::hardware::automotive::can::V1_0::vts::Bus98     void reset() {
99         mBus.clear();
100         if (mController) {
101             const auto res = mController->downInterface(mIfname);
102             EXPECT_TRUE(res);
103             mController.clear();
104         }
105     }
106 
operator ->android::hardware::automotive::can::V1_0::vts::Bus107     ICanBus* operator->() const { return mBus.get(); }
getandroid::hardware::automotive::can::V1_0::vts::Bus108     sp<ICanBus> get() { return mBus; }
109 
listenandroid::hardware::automotive::can::V1_0::vts::Bus110     sp<CanMessageListener> listen(const hidl_vec<CanMessageFilter>& filter) {
111         sp<CanMessageListener> listener = new CanMessageListener();
112 
113         Result result;
114         sp<ICloseHandle> closeHandle;
115         mBus->listen(filter, listener, hidl_utils::fill(&result, &closeHandle)).assertOk();
116         EXPECT_EQ(Result::OK, result);
117         listener->assignCloseHandle(closeHandle);
118 
119         return listener;
120     }
121 
sendandroid::hardware::automotive::can::V1_0::vts::Bus122     void send(const CanMessage& msg) {
123         EXPECT_NE(mBus, nullptr);
124         if (!mBus) return;
125         const auto result = mBus->send(msg);
126         EXPECT_EQ(Result::OK, result);
127     }
128 
129   private:
130     const std::string mIfname;
131     sp<ICanController> mController;
132     sp<ICanBus> mBus;
133 };
134 
135 class CanBusVirtualHalTest : public ::testing::TestWithParam<std::string> {
136   protected:
137     virtual void SetUp() override;
138     virtual void TearDown() override;
139     static void SetUpTestCase();
140 
141     Bus makeBus();
142 
143   protected:
144     static hidl_vec<hidl_string> mBusNames;
145 
146   private:
147     unsigned mLastIface = 0;
148     sp<ICanController> mCanController = nullptr;
149     static bool mTestCaseInitialized;
150 };
151 
152 hidl_vec<hidl_string> CanBusVirtualHalTest::mBusNames;
153 bool CanBusVirtualHalTest::mTestCaseInitialized = false;
154 
makeMessage(CanMessageId id,bool rtr,bool extended)155 static CanMessage makeMessage(CanMessageId id, bool rtr, bool extended) {
156     CanMessage msg = {};
157     msg.id = id;
158     msg.remoteTransmissionRequest = rtr;
159     msg.isExtendedId = extended;
160     return msg;
161 }
162 
clearTimestamps(std::vector<CanMessage> & messages)163 static void clearTimestamps(std::vector<CanMessage>& messages) {
164     std::for_each(messages.begin(), messages.end(), [](auto& msg) { msg.timestamp = 0; });
165 }
166 
SetUp()167 void CanBusVirtualHalTest::SetUp() {
168     ASSERT_TRUE(mTestCaseInitialized);
169 
170     mCanController = ICanController::getService(GetParam());
171     ASSERT_TRUE(mCanController) << "Couldn't open CAN Controller: " << GetParam();
172 
173     hidl_vec<InterfaceType> supported;
174     mCanController->getSupportedInterfaceTypes(hidl_utils::fill(&supported)).assertOk();
175     if (!supported.contains(InterfaceType::VIRTUAL)) GTEST_SKIP();
176 }
177 
TearDown()178 void CanBusVirtualHalTest::TearDown() {
179     mCanController.clear();
180 }
181 
SetUpTestCase()182 void CanBusVirtualHalTest::SetUpTestCase() {
183     mBusNames = utils::getBusNames();
184     ASSERT_NE(0u, mBusNames.size()) << "No ICanBus HALs defined in device manifest";
185 
186     mTestCaseInitialized = true;
187 }
188 
makeBus()189 Bus CanBusVirtualHalTest::makeBus() {
190     const auto idx = mLastIface++;
191     EXPECT_LT(idx, mBusNames.size());
192 
193     ICanController::BusConfig config = {};
194     config.name = mBusNames[idx];
195     config.interfaceId.virtualif({"vcan50"});
196 
197     return Bus(mCanController, config);
198 }
199 
TEST_P(CanBusVirtualHalTest,Send)200 TEST_P(CanBusVirtualHalTest, Send) {
201     auto bus = makeBus();
202 
203     CanMessage msg = {};
204     msg.id = 0x123;
205     msg.payload = {1, 2, 3};
206 
207     bus.send(msg);
208 }
209 
TEST_P(CanBusVirtualHalTest,SendAfterClose)210 TEST_P(CanBusVirtualHalTest, SendAfterClose) {
211     auto bus = makeBus();
212     auto zombie = bus.get();
213     bus.reset();
214 
215     const auto result = zombie->send({});
216     ASSERT_EQ(Result::INTERFACE_DOWN, result);
217 }
218 
TEST_P(CanBusVirtualHalTest,SendAndRecv)219 TEST_P(CanBusVirtualHalTest, SendAndRecv) {
220     if (mBusNames.size() < 2u) GTEST_SKIP() << "Not testable with less than two CAN buses.";
221     auto bus1 = makeBus();
222     auto bus2 = makeBus();
223 
224     auto listener = bus2.listen({});
225 
226     CanMessage msg = {};
227     msg.id = 0x123;
228     msg.payload = {1, 2, 3};
229     bus1.send(msg);
230 
231     auto messages = listener->fetchMessages(100ms);
232     ASSERT_EQ(1u, messages.size());
233     ASSERT_NEAR(uint64_t(elapsedRealtimeNano()), messages[0].timestamp,
234                 std::chrono::nanoseconds(100ms).count());
235     clearTimestamps(messages);
236     ASSERT_EQ(msg, messages[0]);
237 }
238 
TEST_P(CanBusVirtualHalTest,DownOneOfTwo)239 TEST_P(CanBusVirtualHalTest, DownOneOfTwo) {
240     if (mBusNames.size() < 2u) GTEST_SKIP() << "Not testable with less than two CAN buses.";
241 
242     auto bus1 = makeBus();
243     auto bus2 = makeBus();
244 
245     bus2.reset();
246 
247     bus1.send({});
248 }
249 
TEST_P(CanBusVirtualHalTest,FilterPositive)250 TEST_P(CanBusVirtualHalTest, FilterPositive) {
251     if (mBusNames.size() < 2u) GTEST_SKIP() << "Not testable with less than two CAN buses.";
252     auto bus1 = makeBus();
253     auto bus2 = makeBus();
254 
255     /* clang-format off */
256     /*        id,            mask,           rtr,                   eff,          exclude */
257     hidl_vec<CanMessageFilter> filterPositive = {
258             {0x334,           0x73F, FilterFlag::DONT_CARE, FilterFlag::DONT_CARE, false},
259             {0x49D,           0x700, FilterFlag::DONT_CARE, FilterFlag::DONT_CARE, false},
260             {0x325,           0x7FC, FilterFlag::DONT_CARE, FilterFlag::NOT_SET,   false},
261             {0x246,           0x7FF, FilterFlag::SET,       FilterFlag::DONT_CARE, false},
262             {0x1A2,           0x7FB, FilterFlag::SET,       FilterFlag::NOT_SET,   false},
263             {0x607,           0x7C9, FilterFlag::NOT_SET,   FilterFlag::DONT_CARE, false},
264             {0x7F4,           0x777, FilterFlag::NOT_SET,   FilterFlag::NOT_SET,   false},
265             {0x1BF19EAF, 0x10F0F0F0, FilterFlag::DONT_CARE, FilterFlag::DONT_CARE, false},
266             {0x12E99200, 0x1FFFFFFF, FilterFlag::DONT_CARE, FilterFlag::SET,       false},
267             {0x06B70270, 0x1FFFFFFF, FilterFlag::SET,       FilterFlag::DONT_CARE, false},
268             {0x096CFD2B, 0x1FFFFFFF, FilterFlag::SET,       FilterFlag::SET,       false},
269             {0x1BDCB008, 0x0F0F0F0F, FilterFlag::NOT_SET,   FilterFlag::DONT_CARE, false},
270             {0x08318B46, 0x10F0F0F0, FilterFlag::NOT_SET,   FilterFlag::SET,       false},
271             {0x06B,           0x70F, FilterFlag::DONT_CARE, FilterFlag::SET,       false},
272             {0x750,           0x70F, FilterFlag::SET,       FilterFlag::SET,       false},
273             {0x5CF,           0x70F, FilterFlag::NOT_SET,   FilterFlag::SET,       false},
274     };
275     /* clang-format on */
276     auto listenerPositive = bus2.listen(filterPositive);
277 
278     // 334:73F, DNC, DNC
279     bus1.send(makeMessage(0x3F4, false, false));
280     bus1.send(makeMessage(0x334, false, true));
281     bus1.send(makeMessage(0x374, true, false));
282     bus1.send(makeMessage(0x3F4, true, true));
283 
284     // 49D:700, DNC, DNC
285     bus1.send(makeMessage(0x404, false, false));
286     bus1.send(makeMessage(0x4A5, false, true));
287     bus1.send(makeMessage(0x4FF, true, false));
288     bus1.send(makeMessage(0x46B, true, true));
289 
290     // 325:7FC, DNC, NS
291     bus1.send(makeMessage(0x324, false, false));
292     bus1.send(makeMessage(0x325, false, true));  // filtered out
293     bus1.send(makeMessage(0x326, true, false));
294     bus1.send(makeMessage(0x327, true, true));  // filtered out
295 
296     // 246:7FF, SET, DNC
297     bus1.send(makeMessage(0x246, false, false));  // filtered out
298     bus1.send(makeMessage(0x246, false, true));   // filtered out
299     bus1.send(makeMessage(0x246, true, false));
300     bus1.send(makeMessage(0x246, true, true));
301 
302     // 1A2:7FB, SET, NS
303     bus1.send(makeMessage(0x1A2, false, false));  // filtered out
304     bus1.send(makeMessage(0x1A6, false, true));   // filtered out
305     bus1.send(makeMessage(0x1A2, true, false));
306     bus1.send(makeMessage(0x1A6, true, true));  // filtered out
307 
308     // 607:7C9, NS, DNC
309     bus1.send(makeMessage(0x607, false, false));
310     bus1.send(makeMessage(0x613, false, true));
311     bus1.send(makeMessage(0x625, true, false));  // filtered out
312     bus1.send(makeMessage(0x631, true, true));   // filtered out
313 
314     // 7F4:777, NS, NS
315     bus1.send(makeMessage(0x774, false, false));
316     bus1.send(makeMessage(0x7F4, false, true));  // filtered out
317     bus1.send(makeMessage(0x77C, true, false));  // filtered out
318     bus1.send(makeMessage(0x7FC, true, false));  // filtered out
319 
320     // 1BF19EAF:10F0F0F0, DNC, DNC
321     bus1.send(makeMessage(0x11F293A4, false, false));
322     bus1.send(makeMessage(0x15F697A8, false, true));
323     bus1.send(makeMessage(0x19FA9BAC, true, false));
324     bus1.send(makeMessage(0x1DFE9FA0, true, true));
325 
326     // 12E99200:1FFFFFFF, DNC, SET
327     bus1.send(makeMessage(0x12E99200, false, false));  // filtered out
328     bus1.send(makeMessage(0x12E99200, false, true));
329     bus1.send(makeMessage(0x12E99200, true, false));  // filtered out
330     bus1.send(makeMessage(0x12E99200, true, true));
331 
332     // 06B70270:1FFFFFFF, SET, DNC
333     bus1.send(makeMessage(0x06B70270, false, false));  // filtered out
334     bus1.send(makeMessage(0x06B70270, false, true));   // filtered out
335     bus1.send(makeMessage(0x06B70270, true, false));
336     bus1.send(makeMessage(0x06B70270, true, true));
337 
338     // 096CFD2B:1FFFFFFF, SET, SET
339     bus1.send(makeMessage(0x096CFD2B, false, false));  // filtered out
340     bus1.send(makeMessage(0x096CFD2B, false, true));   // filtered out
341     bus1.send(makeMessage(0x096CFD2B, true, false));   // filtered out
342     bus1.send(makeMessage(0x096CFD2B, true, true));
343 
344     // 1BDCB008:0F0F0F0F, NS, DNC
345     bus1.send(makeMessage(0x1B2C3048, false, false));
346     bus1.send(makeMessage(0x0B5C6078, false, true));
347     bus1.send(makeMessage(0x1B8C90A8, true, false));  // filtered out
348     bus1.send(makeMessage(0x0BBCC0D8, true, true));   // filtered out
349 
350     // 08318B46:10F0F0F0, NS, SET
351     bus1.send(makeMessage(0x0F3E8D4C, false, false));  // filtered out
352     bus1.send(makeMessage(0x0B3A8948, false, true));
353     bus1.send(makeMessage(0x07368544, true, false));  // filtered out
354     bus1.send(makeMessage(0x03328140, true, true));   // filtered out
355 
356     // 06B:70F, DNC, SET
357     bus1.send(makeMessage(0x00B, false, false));  // filtered out
358     bus1.send(makeMessage(0x04B, false, true));
359     bus1.send(makeMessage(0x08B, true, false));  // filtered out
360     bus1.send(makeMessage(0x0FB, true, true));
361 
362     // 750:70F, SET, SET
363     bus1.send(makeMessage(0x7F0, false, false));  // filtered out
364     bus1.send(makeMessage(0x780, false, true));   // filtered out
365     bus1.send(makeMessage(0x740, true, false));   // filtered out
366     bus1.send(makeMessage(0x700, true, true));
367 
368     // 5CF:70F, NS, SET
369     bus1.send(makeMessage(0x51F, false, false));  // filtered out
370     bus1.send(makeMessage(0x53F, false, true));
371     bus1.send(makeMessage(0x57F, true, false));  // filtered out
372     bus1.send(makeMessage(0x5FF, true, true));   // filtered out
373 
374     std::vector<can::V1_0::CanMessage> expectedPositive{
375             makeMessage(0x3F4, false, false),       // 334:73F, DNC, DNC
376             makeMessage(0x334, false, true),        // 334:73F, DNC, DNC
377             makeMessage(0x374, true, false),        // 334:73F, DNC, DNC
378             makeMessage(0x3F4, true, true),         // 334:73F, DNC, DNC
379             makeMessage(0x404, false, false),       // 49D:700, DNC, DNC
380             makeMessage(0x4A5, false, true),        // 49D:700, DNC, DNC
381             makeMessage(0x4FF, true, false),        // 49D:700, DNC, DNC
382             makeMessage(0x46B, true, true),         // 49D:700, DNC, DNC
383             makeMessage(0x324, false, false),       // 325:7FC, DNC, NS
384             makeMessage(0x326, true, false),        // 325:7FC, DNC, NS
385             makeMessage(0x246, true, false),        // 246:7FF, SET, DNC
386             makeMessage(0x246, true, true),         // 246:7FF, SET, DNC
387             makeMessage(0x1A2, true, false),        // 1A2:7FB, SET, NS
388             makeMessage(0x607, false, false),       // 607:7C9, NS, DNC
389             makeMessage(0x613, false, true),        // 607:7C9, NS, DNC
390             makeMessage(0x774, false, false),       // 7F4:777, NS, NS
391             makeMessage(0x11F293A4, false, false),  // 1BF19EAF:10F0F0F0, DNC, DNC
392             makeMessage(0x15F697A8, false, true),   // 1BF19EAF:10F0F0F0, DNC, DNC
393             makeMessage(0x19FA9BAC, true, false),   // 1BF19EAF:10F0F0F0, DNC, DNC
394             makeMessage(0x1DFE9FA0, true, true),    // 1BF19EAF:10F0F0F0, DNC, DNC
395             makeMessage(0x12E99200, false, true),   // 12E99200:1FFFFFFF, DNC, SET
396             makeMessage(0x12E99200, true, true),    // 12E99200:1FFFFFFF, DNC, SET
397             makeMessage(0x06B70270, true, false),   // 06B70270:1FFFFFFF, SET, DNC
398             makeMessage(0x06B70270, true, true),    // 06B70270:1FFFFFFF, SET, DNC
399             makeMessage(0x096CFD2B, true, true),    // 096CFD2B:1FFFFFFF, SET, SET
400             makeMessage(0x1B2C3048, false, false),  // 1BDCB008:0F0F0F0F, NS, DNC
401             makeMessage(0x0B5C6078, false, true),   // 1BDCB008:0F0F0F0F, NS, DNC
402             makeMessage(0x0B3A8948, false, true),   // 08318B46:10F0F0F0, NS, SET
403             makeMessage(0x04B, false, true),        // 06B:70F, DNC, SET
404             makeMessage(0x0FB, true, true),         // 06B:70F, DNC, SET
405             makeMessage(0x700, true, true),         // 750:70F, SET, SET
406             makeMessage(0x53F, false, true),        // 5CF:70F, NS, SET
407     };
408 
409     auto messagesPositive = listenerPositive->fetchMessages(100ms, expectedPositive.size());
410     clearTimestamps(messagesPositive);
411     ASSERT_EQ(expectedPositive, messagesPositive);
412 }
413 
TEST_P(CanBusVirtualHalTest,FilterNegative)414 TEST_P(CanBusVirtualHalTest, FilterNegative) {
415     if (mBusNames.size() < 2u) GTEST_SKIP() << "Not testable with less than two CAN buses.";
416     auto bus1 = makeBus();
417     auto bus2 = makeBus();
418 
419     /* clang-format off */
420     /*        id,             mask,           rtr,                   eff          exclude */
421     hidl_vec<CanMessageFilter> filterNegative = {
422             {0x063,           0x7F3, FilterFlag::DONT_CARE, FilterFlag::DONT_CARE, true},
423             {0x0A1,           0x78F, FilterFlag::DONT_CARE, FilterFlag::DONT_CARE, true},
424             {0x18B,           0x7E3, FilterFlag::DONT_CARE, FilterFlag::NOT_SET,   true},
425             {0x1EE,           0x7EC, FilterFlag::SET,       FilterFlag::DONT_CARE, true},
426             {0x23F,           0x7A5, FilterFlag::SET,       FilterFlag::NOT_SET,   true},
427             {0x31F,           0x77F, FilterFlag::NOT_SET,   FilterFlag::DONT_CARE, true},
428             {0x341,           0x77F, FilterFlag::NOT_SET,   FilterFlag::NOT_SET,   true},
429             {0x196573DB, 0x1FFFFF7F, FilterFlag::DONT_CARE, FilterFlag::DONT_CARE, true},
430             {0x1CFCB417, 0x1FFFFFEC, FilterFlag::DONT_CARE, FilterFlag::SET,       true},
431             {0x17CCC433, 0x1FFFFFEC, FilterFlag::SET,       FilterFlag::DONT_CARE, true},
432             {0x0BC2F508, 0x1FFFFFC3, FilterFlag::SET,       FilterFlag::SET,       true},
433             {0x1179B5D2, 0x1FFFFFC3, FilterFlag::NOT_SET,   FilterFlag::DONT_CARE, true},
434             {0x082AF63D, 0x1FFFFFFF, FilterFlag::NOT_SET,   FilterFlag::SET,       true},
435             {0x66D,           0x76F, FilterFlag::DONT_CARE, FilterFlag::SET,       true},
436             {0x748,           0x7CC, FilterFlag::SET,       FilterFlag::SET,       true},
437             {0x784,           0x7CC, FilterFlag::NOT_SET,   FilterFlag::SET,       true},
438     };
439     /* clang-format on */
440 
441     auto listenerNegative = bus2.listen(filterNegative);
442 
443     // 063:7F3, DNC, DNC: ~06[3,7,B,F]
444     bus1.send(makeMessage(0x063, false, false));  // filtered out
445     bus1.send(makeMessage(0x060, false, true));
446     bus1.send(makeMessage(0x05B, true, false));
447     bus1.send(makeMessage(0x06F, true, true));  // filtered out
448 
449     // 0A1:78F, DNC, DNC: ~0[8-F]1
450     bus1.send(makeMessage(0x081, false, false));  // filtered out
451     bus1.send(makeMessage(0x031, false, true));
452     bus1.send(makeMessage(0x061, true, false));
453     bus1.send(makeMessage(0x071, true, true));
454 
455     // 18B:7E3, DNC, NS: ~1[8-9][7,B,F]
456     bus1.send(makeMessage(0x18B, false, false));  // filtered out
457     bus1.send(makeMessage(0x188, false, true));
458     bus1.send(makeMessage(0x123, true, false));
459     bus1.send(makeMessage(0x1D5, true, true));
460 
461     // 1EE:7EC, SET, DNC: ~1[E-F][C-F]
462     bus1.send(makeMessage(0x17E, false, false));
463     bus1.send(makeMessage(0x138, false, true));
464     bus1.send(makeMessage(0x123, true, false));
465     bus1.send(makeMessage(0x1EC, true, true));  // filtered out
466 
467     // 23F:7A5, SET, NS: ~2[2,3,6,7][5,7,D,F]
468     bus1.send(makeMessage(0x222, false, false));
469     bus1.send(makeMessage(0x275, false, true));
470     bus1.send(makeMessage(0x23f, true, false));  // filtered out
471     bus1.send(makeMessage(0x241, true, false));
472     bus1.send(makeMessage(0x2FF, true, true));
473 
474     // 31F:77F, NS, DNC: ~3[1,9]F
475     bus1.send(makeMessage(0x32F, false, false));
476     bus1.send(makeMessage(0x31F, false, true));  // filtered out
477     bus1.send(makeMessage(0x36F, false, true));
478     bus1.send(makeMessage(0x31F, true, false));
479     bus1.send(makeMessage(0x3F3, true, true));
480 
481     // 341:77F, NS, NS: ~3[4,C]1
482     bus1.send(makeMessage(0x341, false, false));  // filtered out
483     bus1.send(makeMessage(0x352, false, false));
484     bus1.send(makeMessage(0x3AA, false, true));
485     bus1.send(makeMessage(0x3BC, true, false));
486     bus1.send(makeMessage(0x3FF, true, true));
487 
488     // 196573DB:1FFFFF7F, DNC, DNC: ~196573[5,D]B
489     bus1.send(makeMessage(0x1965733B, false, false));
490     bus1.send(makeMessage(0x1965734B, false, true));
491     bus1.send(makeMessage(0x1965735B, true, false));  // filtered out
492     bus1.send(makeMessage(0x1965736B, true, true));
493 
494     // 1CFCB417:1FFFFFEC, DNC, SET: ~1CFCB4[0-1][4-7]
495     bus1.send(makeMessage(0x1CFCB407, false, false));
496     bus1.send(makeMessage(0x1CFCB4FF, false, true));
497     bus1.send(makeMessage(0x1CFCB414, true, false));
498     bus1.send(makeMessage(0x1CFCB407, true, true));  // filtered out
499 
500     // 17CCC433:1FFFFFEC, SET, DNC: ~17CCC4[2-3][0-3]
501     bus1.send(makeMessage(0x17CCC430, false, false));
502     bus1.send(makeMessage(0x17CCC423, false, true));
503     bus1.send(makeMessage(0x17CCC420, true, false));  // filtered out
504     bus1.send(makeMessage(0x17CCC444, true, true));
505 
506     // 0BC2F508:1FFFFFC3, SET, SET: ~5[0-3][0,4,8,C]
507     bus1.send(makeMessage(0x0BC2F504, false, false));
508     bus1.send(makeMessage(0x0BC2F518, false, true));
509     bus1.send(makeMessage(0x0BC2F52C, true, false));
510     bus1.send(makeMessage(0x0BC2F500, true, true));  // filtered out
511     bus1.send(makeMessage(0x0BC2F543, true, true));
512 
513     // 1179B5D2:1FFFFFC3, NS, DNC: ~5[C-F][2,6,A,E]
514     bus1.send(makeMessage(0x1179B5BB, false, false));
515     bus1.send(makeMessage(0x1179B5EA, false, true));  // filtered out
516     bus1.send(makeMessage(0x1179B5C2, true, false));
517     bus1.send(makeMessage(0x1179B5DA, true, true));
518 
519     // 082AF63D:1FFFFF6F, NS, SET: ~6[2,3,A,B]D
520     bus1.send(makeMessage(0x082AF62D, false, false));
521     bus1.send(makeMessage(0x082AF63D, false, true));  // filtered out
522     bus1.send(makeMessage(0x082AF60D, false, true));
523     bus1.send(makeMessage(0x082AF6AD, true, false));
524     bus1.send(makeMessage(0x082AF6BD, true, true));
525 
526     // 66D:76F, DNC, SET: ~6[6,7,E,F]D
527     bus1.send(makeMessage(0x66D, false, false));
528     bus1.send(makeMessage(0x68D, false, true));
529     bus1.send(makeMessage(0x67D, true, false));
530     bus1.send(makeMessage(0x6ED, true, true));  // filtered out
531 
532     // 748:7CC, SET, SET: ~0x7[4-7][8-F]
533     bus1.send(makeMessage(0x749, false, false));
534     bus1.send(makeMessage(0x75A, false, true));
535     bus1.send(makeMessage(0x76B, true, false));
536     bus1.send(makeMessage(0x748, true, true));  // filtered out
537     bus1.send(makeMessage(0x788, true, true));
538 
539     // 784:7CC, NS, SET: ~0x7[8-F][4-7]
540     bus1.send(makeMessage(0x795, false, false));
541     bus1.send(makeMessage(0x784, false, true));  // filtered out
542     bus1.send(makeMessage(0x71B, false, true));
543     bus1.send(makeMessage(0x769, true, false));
544     bus1.send(makeMessage(0x784, true, true));
545 
546     std::vector<can::V1_0::CanMessage> expectedNegative{
547             makeMessage(0x060, false, true),        // 063:7F3, DNC, DNC
548             makeMessage(0x05B, true, false),        // 063:7F3, DNC, DNC
549             makeMessage(0x031, false, true),        // 0A1:78F, DNC, DNC
550             makeMessage(0x061, true, false),        // 0A1:78F, DNC, DNC
551             makeMessage(0x071, true, true),         // 0A1:78F, DNC, DNC
552             makeMessage(0x188, false, true),        // 18B:7E3, DNC, NS
553             makeMessage(0x123, true, false),        // 18B:7E3, DNC, NS
554             makeMessage(0x1D5, true, true),         // 18B:7E3, DNC, NS
555             makeMessage(0x17E, false, false),       // 1EE:7EC, SET, DNC
556             makeMessage(0x138, false, true),        // 1EE:7EC, SET, DNC
557             makeMessage(0x123, true, false),        // 1EE:7EC, SET, DNC
558             makeMessage(0x222, false, false),       // 23F:7A5, SET, NS
559             makeMessage(0x275, false, true),        // 23F:7A5, SET, NS
560             makeMessage(0x241, true, false),        // 23F:7A5, SET, NS
561             makeMessage(0x2FF, true, true),         // 23F:7A5, SET, NS
562             makeMessage(0x32F, false, false),       // 31F:77F, NS, DNC
563             makeMessage(0x36F, false, true),        // 31F:77F, NS, DNC
564             makeMessage(0x31F, true, false),        // 31F:77F, NS, DNC
565             makeMessage(0x3F3, true, true),         // 31F:77F, NS, DNC
566             makeMessage(0x352, false, false),       // 341:77F, NS, NS
567             makeMessage(0x3AA, false, true),        // 341:77F, NS, NS
568             makeMessage(0x3BC, true, false),        // 341:77F, NS, NS
569             makeMessage(0x3FF, true, true),         // 341:77F, NS, NS
570             makeMessage(0x1965733B, false, false),  // 196573DB:1FFFFF7F, DNC, DNC
571             makeMessage(0x1965734B, false, true),   // 196573DB:1FFFFF7F, DNC, DNC
572             makeMessage(0x1965736B, true, true),    // 196573DB:1FFFFF7F, DNC, DNC
573             makeMessage(0x1CFCB407, false, false),  // 1CFCB417:1FFFFFEC, DNC, SET
574             makeMessage(0x1CFCB4FF, false, true),   // 1CFCB417:1FFFFFEC, DNC, SET
575             makeMessage(0x1CFCB414, true, false),   // 1CFCB417:1FFFFFEC, DNC, SET
576             makeMessage(0x17CCC430, false, false),  // 17CCC433:1FFFFFEC, SET, DNC
577             makeMessage(0x17CCC423, false, true),   // 17CCC433:1FFFFFEC, SET, DNC
578             makeMessage(0x17CCC444, true, true),    // 17CCC433:1FFFFFEC, SET, DNC
579             makeMessage(0x0BC2F504, false, false),  // 0BC2F508:1FFFFFC3, SET, SET
580             makeMessage(0x0BC2F518, false, true),   // 0BC2F508:1FFFFFC3, SET, SET
581             makeMessage(0x0BC2F52C, true, false),   // 0BC2F508:1FFFFFC3, SET, SET
582             makeMessage(0x0BC2F543, true, true),    // 0BC2F508:1FFFFFC3, SET, SET
583             makeMessage(0x1179B5BB, false, false),  // 1179B5D2:1FFFFFC3, NS, DNC
584             makeMessage(0x1179B5C2, true, false),   // 1179B5D2:1FFFFFC3, NS, DNC
585             makeMessage(0x1179B5DA, true, true),    // 1179B5D2:1FFFFFC3, NS, DNC
586             makeMessage(0x082AF62D, false, false),  // 082AF63D:1FFFFF6F, NS, SET
587             makeMessage(0x082AF60D, false, true),   // 082AF63D:1FFFFF6F, NS, SET
588             makeMessage(0x082AF6AD, true, false),   // 082AF63D:1FFFFF6F, NS, SET
589             makeMessage(0x082AF6BD, true, true),    // 082AF63D:1FFFFF6F, NS, SET
590             makeMessage(0x66D, false, false),       // 66D:76F, DNC, SET
591             makeMessage(0x68D, false, true),        // 66D:76F, DNC, SET
592             makeMessage(0x67D, true, false),        // 66D:76F, DNC, SET
593             makeMessage(0x749, false, false),       // 748:7CC, SET, SET
594             makeMessage(0x75A, false, true),        // 748:7CC, SET, SET
595             makeMessage(0x76B, true, false),        // 748:7CC, SET, SET
596             makeMessage(0x788, true, true),         // 748:7CC, SET, SET
597             makeMessage(0x795, false, false),       // 784:7CC, NS, SET
598             makeMessage(0x71B, false, true),        // 784:7CC, NS, SET
599             makeMessage(0x769, true, false),        // 784:7CC, NS, SET
600             makeMessage(0x784, true, true),         // 784:7CC, NS, SET
601     };
602 
603     auto messagesNegative = listenerNegative->fetchMessages(100ms, expectedNegative.size());
604     clearTimestamps(messagesNegative);
605     ASSERT_EQ(expectedNegative, messagesNegative);
606 }
607 
TEST_P(CanBusVirtualHalTest,FilterMixed)608 TEST_P(CanBusVirtualHalTest, FilterMixed) {
609     if (mBusNames.size() < 2u) GTEST_SKIP() << "Not testable with less than two CAN buses.";
610     auto bus1 = makeBus();
611     auto bus2 = makeBus();
612 
613     /* clang-format off */
614     /*        id,           mask,             rtr,                   eff          exclude */
615     hidl_vec<CanMessageFilter> filterMixed = {
616             {0x000,      0x700,      FilterFlag::DONT_CARE, FilterFlag::DONT_CARE, false},
617             {0x0D5,      0x7FF,      FilterFlag::DONT_CARE, FilterFlag::DONT_CARE, true},
618             {0x046,      0x7FF,      FilterFlag::DONT_CARE, FilterFlag::NOT_SET,   true},
619             {0x11D89097, 0x1FFFFFFF, FilterFlag::DONT_CARE, FilterFlag::SET,       true},
620             {0x0AB,      0x7FF,      FilterFlag::NOT_SET,   FilterFlag::DONT_CARE, true},
621             {0x00D,      0x7FF,      FilterFlag::NOT_SET,   FilterFlag::NOT_SET,   true},
622             {0x0F82400E, 0x1FFFFFFF, FilterFlag::NOT_SET,   FilterFlag::SET,       true},
623             {0x08F,      0x7FF,      FilterFlag::SET,       FilterFlag::DONT_CARE, true},
624             {0x0BE,      0x7FF,      FilterFlag::SET,       FilterFlag::NOT_SET,   true},
625             {0x0A271011, 0x1FFFFFFF, FilterFlag::SET,       FilterFlag::SET,       true},
626             {0x0BE,      0x7FF,      FilterFlag::DONT_CARE, FilterFlag::DONT_CARE, false},
627 
628             {0x100,      0x700,      FilterFlag::DONT_CARE, FilterFlag::NOT_SET,   false},
629             {0x138,      0x7FF,      FilterFlag::DONT_CARE, FilterFlag::DONT_CARE, true},
630             {0x1BF,      0x7FF,      FilterFlag::DONT_CARE, FilterFlag::NOT_SET,   true},
631             {0x13AB6165, 0x1FFFFFFF, FilterFlag::DONT_CARE, FilterFlag::SET,       true},
632             {0x17A,      0x7FF,      FilterFlag::NOT_SET,   FilterFlag::DONT_CARE, true},
633             {0x13C,      0x7FF,      FilterFlag::NOT_SET,   FilterFlag::NOT_SET,   true},
634             {0x102C5197, 0x1FFFFFFF, FilterFlag::NOT_SET,   FilterFlag::SET,       true},
635             {0x19B,      0x7FF,      FilterFlag::SET,       FilterFlag::DONT_CARE, true},
636             {0x1B8,      0x7FF,      FilterFlag::SET,       FilterFlag::NOT_SET,   true},
637             {0x0D6D5185, 0x1FFFFFFF, FilterFlag::SET,       FilterFlag::SET,       true},
638             {0x1B8,      0x7FF,      FilterFlag::DONT_CARE, FilterFlag::DONT_CARE, false},
639 
640             {0x096A2200, 0x1FFFFF00, FilterFlag::DONT_CARE, FilterFlag::SET,       false},
641             {0x201,      0x7FF,      FilterFlag::DONT_CARE, FilterFlag::DONT_CARE, true},
642             {0x22A,      0x7FF,      FilterFlag::DONT_CARE, FilterFlag::NOT_SET,   true},
643             {0x1D1C3238, 0x1FFFFFFF, FilterFlag::DONT_CARE, FilterFlag::SET,       true},
644             {0x2C0,      0x7FF,      FilterFlag::NOT_SET,   FilterFlag::DONT_CARE, true},
645             {0x23C,      0x7FF,      FilterFlag::NOT_SET,   FilterFlag::NOT_SET,   true},
646             {0x016182C6, 0x1FFFFFFF, FilterFlag::NOT_SET,   FilterFlag::SET,       true},
647             {0x27B,      0x7FF,      FilterFlag::SET,       FilterFlag::DONT_CARE, true},
648             {0x2A5,      0x7FF,      FilterFlag::SET,       FilterFlag::NOT_SET,   true},
649             {0x160EB24B, 0x1FFFFFFF, FilterFlag::SET,       FilterFlag::SET,       true},
650             {0x2A5,      0x7FF,      FilterFlag::DONT_CARE, FilterFlag::DONT_CARE, false},
651 
652             {0x300,      0x700,      FilterFlag::NOT_SET,   FilterFlag::DONT_CARE, false},
653             {0x339,      0x7FF,      FilterFlag::DONT_CARE, FilterFlag::DONT_CARE, true},
654             {0x3D4,      0x7FF,      FilterFlag::DONT_CARE, FilterFlag::NOT_SET,   true},
655             {0x182263BE, 0x1FFFFFFF, FilterFlag::DONT_CARE, FilterFlag::SET,       true},
656             {0x327,      0x7FF,      FilterFlag::NOT_SET,   FilterFlag::DONT_CARE, true},
657             {0x36B,      0x7FF,      FilterFlag::NOT_SET,   FilterFlag::NOT_SET,   true},
658             {0x1A1D8374, 0x1FFFFFFF, FilterFlag::NOT_SET,   FilterFlag::SET,       true},
659             {0x319,      0x7FF,      FilterFlag::SET,       FilterFlag::DONT_CARE, true},
660             {0x39E,      0x7FF,      FilterFlag::SET,       FilterFlag::NOT_SET,   true},
661             {0x1B657332, 0x1FFFFFFF, FilterFlag::SET,       FilterFlag::SET,       true},
662             {0x39E,      0x7FF,      FilterFlag::DONT_CARE, FilterFlag::DONT_CARE, false},
663 
664             {0x06C5D400, 0x1FFFFF00, FilterFlag::NOT_SET,   FilterFlag::SET,       false},
665             {0x492,      0x7FF,      FilterFlag::DONT_CARE, FilterFlag::DONT_CARE, true},
666             {0x4EE,      0x7FF,      FilterFlag::DONT_CARE, FilterFlag::NOT_SET,   true},
667             {0x07725454, 0x1FFFFFFF, FilterFlag::DONT_CARE, FilterFlag::SET,       true},
668             {0x4D5,      0x7FF,      FilterFlag::NOT_SET,   FilterFlag::DONT_CARE, true},
669             {0x402,      0x7FF,      FilterFlag::NOT_SET,   FilterFlag::NOT_SET,   true},
670             {0x139714A7, 0x1FFFFFFF, FilterFlag::NOT_SET,   FilterFlag::SET,       true},
671             {0x464,      0x7FF,      FilterFlag::SET,       FilterFlag::DONT_CARE, true},
672             {0x454,      0x7FF,      FilterFlag::SET,       FilterFlag::NOT_SET,   true},
673             {0x0EF4B46F, 0x1FFFFFFF, FilterFlag::SET,       FilterFlag::SET,       true},
674             {0x454,      0x7FF,      FilterFlag::DONT_CARE, FilterFlag::DONT_CARE, false},
675 
676             {0x500,      0x700,      FilterFlag::SET,       FilterFlag::DONT_CARE, false},
677             {0x503,      0x7FF,      FilterFlag::DONT_CARE, FilterFlag::DONT_CARE, true},
678             {0x566,      0x7FF,      FilterFlag::DONT_CARE, FilterFlag::NOT_SET,   true},
679             {0x137605E7, 0x1FFFFFFF, FilterFlag::DONT_CARE, FilterFlag::SET,       true},
680             {0x564,      0x7FF,      FilterFlag::NOT_SET,   FilterFlag::DONT_CARE, true},
681             {0x58E,      0x7FF,      FilterFlag::NOT_SET,   FilterFlag::NOT_SET,   true},
682             {0x05F9052D, 0x1FFFFFFF, FilterFlag::NOT_SET,   FilterFlag::SET,       true},
683             {0x595,      0x7FF,      FilterFlag::SET,       FilterFlag::DONT_CARE, true},
684             {0x563,      0x7FF,      FilterFlag::SET,       FilterFlag::NOT_SET,   true},
685             {0x13358537, 0x1FFFFFFF, FilterFlag::SET,       FilterFlag::SET,       true},
686             {0x563,      0x7FF,      FilterFlag::DONT_CARE, FilterFlag::DONT_CARE, false},
687 
688             {0x600,      0x700,      FilterFlag::SET,       FilterFlag::NOT_SET,   false},
689             {0x64D,      0x7FF,      FilterFlag::DONT_CARE, FilterFlag::DONT_CARE, true},
690             {0x620,      0x7FF,      FilterFlag::DONT_CARE, FilterFlag::NOT_SET,   true},
691             {0x1069A676, 0x1FFFFFFF, FilterFlag::DONT_CARE, FilterFlag::SET,       true},
692             {0x62D,      0x7FF,      FilterFlag::NOT_SET,   FilterFlag::DONT_CARE, true},
693             {0x6C4,      0x7FF,      FilterFlag::NOT_SET,   FilterFlag::NOT_SET,   true},
694             {0x14C76629, 0x1FFFFFFF, FilterFlag::NOT_SET,   FilterFlag::SET,       true},
695             {0x689,      0x7FF,      FilterFlag::SET,       FilterFlag::DONT_CARE, true},
696             {0x6A4,      0x7FF,      FilterFlag::SET,       FilterFlag::NOT_SET,   true},
697             {0x0BCCA6C2, 0x1FFFFFFF, FilterFlag::SET,       FilterFlag::SET,       true},
698             {0x6A4,      0x7FF,      FilterFlag::DONT_CARE, FilterFlag::DONT_CARE, false},
699 
700             {0x04BB1700, 0x1FFFFF00, FilterFlag::SET,       FilterFlag::SET,       false},
701             {0x784,      0x7FF,      FilterFlag::DONT_CARE, FilterFlag::DONT_CARE, true},
702             {0x7F9,      0x7FF,      FilterFlag::DONT_CARE, FilterFlag::NOT_SET,   true},
703             {0x0200F77D, 0x1FFFFFFF, FilterFlag::DONT_CARE, FilterFlag::SET,       true},
704             {0x783,      0x7FF,      FilterFlag::NOT_SET,   FilterFlag::DONT_CARE, true},
705             {0x770,      0x7FF,      FilterFlag::NOT_SET,   FilterFlag::NOT_SET,   true},
706             {0x06602719, 0x1FFFFFFF, FilterFlag::NOT_SET,   FilterFlag::SET,       true},
707             {0x76B,      0x7FF,      FilterFlag::SET,       FilterFlag::DONT_CARE, true},
708             {0x7DF,      0x7FF,      FilterFlag::SET,       FilterFlag::NOT_SET,   true},
709             {0x1939E736, 0x1FFFFFFF, FilterFlag::SET,       FilterFlag::SET,       true},
710             {0x7DF,      0x7FF,      FilterFlag::DONT_CARE, FilterFlag::DONT_CARE, false},
711     };
712     /* clang-format on */
713 
714     auto listenerMixed = bus2.listen(filterMixed);
715 
716     bus1.send(makeMessage(0x000, true, true));  // positive filter
717     bus1.send(makeMessage(0x0D5, false, false));
718     bus1.send(makeMessage(0x046, true, false));
719     bus1.send(makeMessage(0x046, false, false));
720     bus1.send(makeMessage(0x11D89097, true, true));
721     bus1.send(makeMessage(0x11D89097, false, true));
722     bus1.send(makeMessage(0x0AB, false, false));
723     bus1.send(makeMessage(0x0AB, false, true));
724     bus1.send(makeMessage(0x00D, false, false));
725     bus1.send(makeMessage(0x0F82400E, false, true));
726     bus1.send(makeMessage(0x08F, true, false));
727     bus1.send(makeMessage(0x08F, true, true));
728     bus1.send(makeMessage(0x0BE, true, false));
729     bus1.send(makeMessage(0x0A271011, true, true));
730     bus1.send(makeMessage(0x0BE, false, true));   // not filtered
731     bus1.send(makeMessage(0x100, false, false));  // positive filter
732     bus1.send(makeMessage(0x138, false, true));
733     bus1.send(makeMessage(0x138, true, false));
734     bus1.send(makeMessage(0x1BF, false, false));
735     bus1.send(makeMessage(0x1BF, true, false));
736     bus1.send(makeMessage(0x13AB6165, false, true));
737     bus1.send(makeMessage(0x13AB6165, true, true));
738     bus1.send(makeMessage(0x17A, false, false));
739     bus1.send(makeMessage(0x17A, false, true));
740     bus1.send(makeMessage(0x13C, false, false));
741     bus1.send(makeMessage(0x102C5197, false, true));
742     bus1.send(makeMessage(0x19B, true, false));
743     bus1.send(makeMessage(0x19B, true, true));
744     bus1.send(makeMessage(0x1B8, true, false));
745     bus1.send(makeMessage(0x0D6D5185, true, true));
746     bus1.send(makeMessage(0x1B8, false, true));       // not filtered
747     bus1.send(makeMessage(0x096A2200, false, true));  // positive filter
748     bus1.send(makeMessage(0x201, false, true));
749     bus1.send(makeMessage(0x201, true, false));
750     bus1.send(makeMessage(0x22A, false, false));
751     bus1.send(makeMessage(0x22A, true, false));
752     bus1.send(makeMessage(0x1D1C3238, false, true));
753     bus1.send(makeMessage(0x1D1C3238, true, true));
754     bus1.send(makeMessage(0x2C0, false, false));
755     bus1.send(makeMessage(0x2C0, false, true));
756     bus1.send(makeMessage(0x23C, false, false));
757     bus1.send(makeMessage(0x016182C6, false, true));
758     bus1.send(makeMessage(0x27B, true, false));
759     bus1.send(makeMessage(0x27B, true, true));
760     bus1.send(makeMessage(0x2A5, true, false));
761     bus1.send(makeMessage(0x160EB24B, true, true));
762     bus1.send(makeMessage(0x2A5, false, true));   // not filtereed
763     bus1.send(makeMessage(0x300, false, false));  // positive filter
764     bus1.send(makeMessage(0x339, false, true));
765     bus1.send(makeMessage(0x339, false, false));
766     bus1.send(makeMessage(0x3D4, true, false));
767     bus1.send(makeMessage(0x182263BE, false, true));
768     bus1.send(makeMessage(0x182263BE, true, true));
769     bus1.send(makeMessage(0x327, false, false));
770     bus1.send(makeMessage(0x327, false, true));
771     bus1.send(makeMessage(0x36B, false, false));
772     bus1.send(makeMessage(0x1A1D8374, false, true));
773     bus1.send(makeMessage(0x319, true, false));
774     bus1.send(makeMessage(0x319, true, true));
775     bus1.send(makeMessage(0x39E, true, false));
776     bus1.send(makeMessage(0x1B657332, true, true));
777     bus1.send(makeMessage(0x39E, false, true));       // not filtered
778     bus1.send(makeMessage(0x06C5D400, false, true));  // positive filter
779     bus1.send(makeMessage(0x492, false, true));
780     bus1.send(makeMessage(0x492, true, false));
781     bus1.send(makeMessage(0x4EE, false, false));
782     bus1.send(makeMessage(0x4EE, true, false));
783     bus1.send(makeMessage(0x07725454, false, true));
784     bus1.send(makeMessage(0x07725454, true, true));
785     bus1.send(makeMessage(0x4D5, false, false));
786     bus1.send(makeMessage(0x4D5, false, true));
787     bus1.send(makeMessage(0x402, false, false));
788     bus1.send(makeMessage(0x139714A7, false, true));
789     bus1.send(makeMessage(0x464, true, false));
790     bus1.send(makeMessage(0x464, true, true));
791     bus1.send(makeMessage(0x454, true, false));
792     bus1.send(makeMessage(0x0EF4B46F, true, true));
793     bus1.send(makeMessage(0x454, false, true));  // not filtered
794     bus1.send(makeMessage(0x500, true, false));  // positive filter
795     bus1.send(makeMessage(0x503, false, true));
796     bus1.send(makeMessage(0x503, true, false));
797     bus1.send(makeMessage(0x566, false, false));
798     bus1.send(makeMessage(0x566, true, false));
799     bus1.send(makeMessage(0x137605E7, false, true));
800     bus1.send(makeMessage(0x137605E7, true, true));
801     bus1.send(makeMessage(0x564, false, false));
802     bus1.send(makeMessage(0x564, false, true));
803     bus1.send(makeMessage(0x58E, false, false));
804     bus1.send(makeMessage(0x05F9052D, false, true));
805     bus1.send(makeMessage(0x595, true, false));
806     bus1.send(makeMessage(0x595, true, true));
807     bus1.send(makeMessage(0x563, true, false));
808     bus1.send(makeMessage(0x13358537, true, true));
809     bus1.send(makeMessage(0x563, false, true));  // not filtered
810     bus1.send(makeMessage(0x600, true, false));  // positive filter
811     bus1.send(makeMessage(0x64D, false, true));
812     bus1.send(makeMessage(0x64D, true, false));
813     bus1.send(makeMessage(0x620, false, false));
814     bus1.send(makeMessage(0x620, true, false));
815     bus1.send(makeMessage(0x1069A676, false, true));
816     bus1.send(makeMessage(0x1069A676, true, true));
817     bus1.send(makeMessage(0x62D, false, false));
818     bus1.send(makeMessage(0x62D, false, true));
819     bus1.send(makeMessage(0x6C4, false, false));
820     bus1.send(makeMessage(0x14C76629, false, true));
821     bus1.send(makeMessage(0x689, true, false));
822     bus1.send(makeMessage(0x689, true, true));
823     bus1.send(makeMessage(0x6A4, true, false));
824     bus1.send(makeMessage(0x0BCCA6C2, true, true));
825     bus1.send(makeMessage(0x6A4, false, true));      // not filtered
826     bus1.send(makeMessage(0x04BB1700, true, true));  // positive filter
827     bus1.send(makeMessage(0x784, false, true));
828     bus1.send(makeMessage(0x784, true, false));
829     bus1.send(makeMessage(0x7F9, false, false));
830     bus1.send(makeMessage(0x7F9, true, false));
831     bus1.send(makeMessage(0x0200F77D, false, true));
832     bus1.send(makeMessage(0x0200F77D, true, true));
833     bus1.send(makeMessage(0x783, false, false));
834     bus1.send(makeMessage(0x783, false, true));
835     bus1.send(makeMessage(0x770, false, false));
836     bus1.send(makeMessage(0x06602719, false, true));
837     bus1.send(makeMessage(0x76B, true, false));
838     bus1.send(makeMessage(0x76B, true, true));
839     bus1.send(makeMessage(0x7DF, true, false));
840     bus1.send(makeMessage(0x1939E736, true, true));
841     bus1.send(makeMessage(0x7DF, false, true));  // not filtered
842 
843     std::vector<can::V1_0::CanMessage> expectedMixed{
844             makeMessage(0x000, true, true),  // 0x000:0x700, DONT_CARE, DONT_CARE
845             makeMessage(0x0BE, false, true),
846             makeMessage(0x100, false, false),  // 0x100:0x700, DONT_CARE, NOT_SET
847             makeMessage(0x1B8, false, true),
848             makeMessage(0x096A2200, false, true),  // 0x096A2200:0x1FFFFF00, DONT_CARE, SET
849             makeMessage(0x2A5, false, true),
850             makeMessage(0x300, false, false),  // 0x300:0x700, NOT_SET, DONT_CARE
851             makeMessage(0x39E, false, true),
852             makeMessage(0x06C5D400, false, true),  // 0x06C5D400:0x1FFFFF00, NOT_SET, SET
853             makeMessage(0x454, false, true),
854             makeMessage(0x500, true, false),  // 0x500:0x700, SET, DONT_CARE
855             makeMessage(0x563, false, true),
856             makeMessage(0x600, true, false),  // 0x600:0x700, SET, NOT_SET
857             makeMessage(0x6A4, false, true),
858             makeMessage(0x04BB1700, true, true),  // 0x04BB1700:0x1FFFFF00, SET, SET
859             makeMessage(0x7DF, false, true),
860     };
861 
862     auto messagesMixed = listenerMixed->fetchMessages(100ms, expectedMixed.size());
863     clearTimestamps(messagesMixed);
864     ASSERT_EQ(expectedMixed, messagesMixed);
865 }
866 
867 /**
868  * Example manual invocation:
869  * adb shell /data/nativetest64/VtsHalCanBusVirtualV1_0TargetTest/VtsHalCanBusVirtualV1_0TargetTest
870  */
871 INSTANTIATE_TEST_SUITE_P(  //
872         PerInstance, CanBusVirtualHalTest,
873         testing::ValuesIn(getAllHalInstanceNames(ICanController::descriptor)),
874         PrintInstanceNameToString);
875 
876 }  // namespace android::hardware::automotive::can::V1_0::vts
877