Loading automotive/can/1.0/default/CanBus.cpp +16 −13 Original line number Diff line number Diff line Loading @@ -42,6 +42,8 @@ Return<Result> CanBus::send(const CanMessage& message) { struct canfd_frame frame = {}; frame.can_id = message.id; if (message.isExtendedId) frame.can_id |= CAN_EFF_FLAG; if (message.remoteTransmissionRequest) frame.can_id |= CAN_RTR_FLAG; frame.len = message.payload.size(); memcpy(frame.data, message.payload.data(), message.payload.size()); Loading Loading @@ -226,8 +228,8 @@ bool CanBus::down() { static bool satisfiesFilterFlag(FilterFlag filterFlag, bool flag) { // TODO(b/144458917) add testing for this to VTS tests if (filterFlag == FilterFlag::DONT_CARE) return true; if (filterFlag == FilterFlag::REQUIRE) return flag; if (filterFlag == FilterFlag::EXCLUDE) return !flag; if (filterFlag == FilterFlag::SET) return flag; if (filterFlag == FilterFlag::NOT_SET) return !flag; return false; } Loading @@ -241,25 +243,26 @@ static bool satisfiesFilterFlag(FilterFlag filterFlag, bool flag) { * \param id Message id to filter * \return true if the message id matches the filter, false otherwise */ static bool match(const hidl_vec<CanMessageFilter>& filter, CanMessageId id, bool isExtendedId, bool isRtr) { static bool match(const hidl_vec<CanMessageFilter>& filter, CanMessageId id, bool isRtr, bool isExtendedId) { if (filter.size() == 0) return true; bool anyNonInvertedPresent = false; bool anyNonInvertedSatisfied = false; bool anyNonExcludeRulePresent = false; bool anyNonExcludeRuleSatisfied = false; for (auto& rule : filter) { const bool satisfied = ((id & rule.mask) == rule.id) == !rule.inverted && const bool satisfied = ((id & rule.mask) == rule.id) && satisfiesFilterFlag(rule.rtr, isRtr) && satisfiesFilterFlag(rule.extendedFormat, isExtendedId); if (rule.inverted) { // Any inverted (blacklist) rule not being satisfied invalidates the whole filter set. if (!satisfied) return false; if (rule.exclude) { // Any excluded (blacklist) rule not being satisfied invalidates the whole filter set. if (satisfied) return false; } else { anyNonInvertedPresent = true; if (satisfied) anyNonInvertedSatisfied = true; anyNonExcludeRulePresent = true; if (satisfied) anyNonExcludeRuleSatisfied = true; } } return !anyNonInvertedPresent || anyNonInvertedSatisfied; return !anyNonExcludeRulePresent || anyNonExcludeRuleSatisfied; } void CanBus::notifyErrorListeners(ErrorEvent err, bool isFatal) { Loading automotive/can/1.0/types.hal +11 −12 Original line number Diff line number Diff line Loading @@ -73,23 +73,22 @@ struct CanMessage { * Single filter rule for CAN messages. * * A filter is satisfied if: * ((receivedId & mask) == (id & mask)) == !inverted * ((receivedId & mask) == (id & mask)) == !exclude * * In order for set of filters to match, at least one non-inverted filters must match (if there is * one) and all inverted filters must match. In other words: * - a single matching non-inverted filter makes the whole set matching; * - a single non-matching inverted filter makes the whole set non-matching. * * Additional less common options for filtering include: * rtr - Remote Transmission Request; another ECU requests DLC bytes of data on this message ID * extendedFormat - 29 bit message ID is used instead of 11 bits * In order for set of filters to match, at least one non-exclude filters must match (if there is * one) and all exclude filters must match. In other words: * - a single matching non-exclude filter makes the whole set matching; * - a single non-matching excluded filter makes the whole set non-matching. */ struct CanMessageFilter { CanMessageId id; uint32_t mask; bool inverted; /** Remote Transmission Request; another ECU requests <DLC> bytes of data on this message ID */ FilterFlag rtr; /** 29 bit message ID is used instead of 11 bits */ FilterFlag extendedFormat; /** 'exclude' *DOES* apply to rtr and extendedFormat! */ bool exclude; }; Loading @@ -100,9 +99,9 @@ enum FilterFlag : uint8_t { /** Default, FilterFlag doesn't effect what messages filtered */ DONT_CARE = 0, /** This FilterFlag MUST be present in received messages to pass though the filter */ REQUIRE, SET, /** This FilterFlag must NOT be present in received messages to pass though the filter */ EXCLUDE, NOT_SET, }; enum Result : uint8_t { Loading automotive/can/1.0/vts/functional/VtsHalCanBusV1_0TargetTest.cpp +11 −5 Original line number Diff line number Diff line Loading @@ -78,7 +78,7 @@ sp<ICloseHandle> CanBusHalTest::listenForErrors(const sp<ICanErrorListener>& lis TEST_F(CanBusHalTest, SendNoPayload) { CanMessage msg = {}; msg.id = 0x123; ASSERT_NE(mCanBus, nullptr); const auto result = mCanBus->send(msg); ASSERT_EQ(Result::OK, result); } Loading Loading @@ -118,9 +118,9 @@ TEST_F(CanBusHalTest, ListenNoFilter) { TEST_F(CanBusHalTest, ListenSomeFilter) { hidl_vec<CanMessageFilter> filters = { {0x123, 0x1FF, false, FilterFlag::DONT_CARE, FilterFlag::DONT_CARE}, {0x001, 0x00F, true, FilterFlag::DONT_CARE, FilterFlag::DONT_CARE}, {0x200, 0x100, false, FilterFlag::DONT_CARE, FilterFlag::DONT_CARE}, {0x123, 0x1FF, FilterFlag::DONT_CARE, FilterFlag::DONT_CARE, false}, {0x001, 0x00F, FilterFlag::DONT_CARE, FilterFlag::DONT_CARE, true}, {0x200, 0x100, FilterFlag::DONT_CARE, FilterFlag::DONT_CARE, false}, }; const auto [result, closeHandle] = listen(filters, new CanMessageListener()); Loading Loading @@ -171,14 +171,20 @@ TEST_F(CanBusHalTest, DontCloseErrorListener) { } // namespace android::hardware::automotive::can::V1_0::vts /** * This test requires that you bring up a valid bus first. * * Before running: * mma -j && adb root && adb remount && adb sync * * Example manual invocation: * adb shell /data/nativetest64/VtsHalCanBusV1_0TargetTest/VtsHalCanBusV1_0TargetTest \ * --hal_service_instance=android.hardware.automotive.can@1.0::ICanBus/test * --hal_service_instance=android.hardware.automotive.can@1.0::ICanBus/<NAME_OF_VALID_BUS> */ int main(int argc, char** argv) { using android::hardware::automotive::can::V1_0::ICanBus; using android::hardware::automotive::can::V1_0::vts::gEnv; using android::hardware::automotive::can::V1_0::vts::utils::SimpleHidlEnvironment; setenv("TREBLE_TESTING_OVERRIDE", "true", true); android::base::SetDefaultTag("CanBusVts"); android::base::SetMinimumLogSeverity(android::base::VERBOSE); gEnv = new SimpleHidlEnvironment<ICanBus>; Loading automotive/can/1.0/vts/functional/VtsHalCanBusVirtualV1_0TargetTest.cpp +600 −32 File changed.Preview size limit exceeded, changes collapsed. Show changes Loading
automotive/can/1.0/default/CanBus.cpp +16 −13 Original line number Diff line number Diff line Loading @@ -42,6 +42,8 @@ Return<Result> CanBus::send(const CanMessage& message) { struct canfd_frame frame = {}; frame.can_id = message.id; if (message.isExtendedId) frame.can_id |= CAN_EFF_FLAG; if (message.remoteTransmissionRequest) frame.can_id |= CAN_RTR_FLAG; frame.len = message.payload.size(); memcpy(frame.data, message.payload.data(), message.payload.size()); Loading Loading @@ -226,8 +228,8 @@ bool CanBus::down() { static bool satisfiesFilterFlag(FilterFlag filterFlag, bool flag) { // TODO(b/144458917) add testing for this to VTS tests if (filterFlag == FilterFlag::DONT_CARE) return true; if (filterFlag == FilterFlag::REQUIRE) return flag; if (filterFlag == FilterFlag::EXCLUDE) return !flag; if (filterFlag == FilterFlag::SET) return flag; if (filterFlag == FilterFlag::NOT_SET) return !flag; return false; } Loading @@ -241,25 +243,26 @@ static bool satisfiesFilterFlag(FilterFlag filterFlag, bool flag) { * \param id Message id to filter * \return true if the message id matches the filter, false otherwise */ static bool match(const hidl_vec<CanMessageFilter>& filter, CanMessageId id, bool isExtendedId, bool isRtr) { static bool match(const hidl_vec<CanMessageFilter>& filter, CanMessageId id, bool isRtr, bool isExtendedId) { if (filter.size() == 0) return true; bool anyNonInvertedPresent = false; bool anyNonInvertedSatisfied = false; bool anyNonExcludeRulePresent = false; bool anyNonExcludeRuleSatisfied = false; for (auto& rule : filter) { const bool satisfied = ((id & rule.mask) == rule.id) == !rule.inverted && const bool satisfied = ((id & rule.mask) == rule.id) && satisfiesFilterFlag(rule.rtr, isRtr) && satisfiesFilterFlag(rule.extendedFormat, isExtendedId); if (rule.inverted) { // Any inverted (blacklist) rule not being satisfied invalidates the whole filter set. if (!satisfied) return false; if (rule.exclude) { // Any excluded (blacklist) rule not being satisfied invalidates the whole filter set. if (satisfied) return false; } else { anyNonInvertedPresent = true; if (satisfied) anyNonInvertedSatisfied = true; anyNonExcludeRulePresent = true; if (satisfied) anyNonExcludeRuleSatisfied = true; } } return !anyNonInvertedPresent || anyNonInvertedSatisfied; return !anyNonExcludeRulePresent || anyNonExcludeRuleSatisfied; } void CanBus::notifyErrorListeners(ErrorEvent err, bool isFatal) { Loading
automotive/can/1.0/types.hal +11 −12 Original line number Diff line number Diff line Loading @@ -73,23 +73,22 @@ struct CanMessage { * Single filter rule for CAN messages. * * A filter is satisfied if: * ((receivedId & mask) == (id & mask)) == !inverted * ((receivedId & mask) == (id & mask)) == !exclude * * In order for set of filters to match, at least one non-inverted filters must match (if there is * one) and all inverted filters must match. In other words: * - a single matching non-inverted filter makes the whole set matching; * - a single non-matching inverted filter makes the whole set non-matching. * * Additional less common options for filtering include: * rtr - Remote Transmission Request; another ECU requests DLC bytes of data on this message ID * extendedFormat - 29 bit message ID is used instead of 11 bits * In order for set of filters to match, at least one non-exclude filters must match (if there is * one) and all exclude filters must match. In other words: * - a single matching non-exclude filter makes the whole set matching; * - a single non-matching excluded filter makes the whole set non-matching. */ struct CanMessageFilter { CanMessageId id; uint32_t mask; bool inverted; /** Remote Transmission Request; another ECU requests <DLC> bytes of data on this message ID */ FilterFlag rtr; /** 29 bit message ID is used instead of 11 bits */ FilterFlag extendedFormat; /** 'exclude' *DOES* apply to rtr and extendedFormat! */ bool exclude; }; Loading @@ -100,9 +99,9 @@ enum FilterFlag : uint8_t { /** Default, FilterFlag doesn't effect what messages filtered */ DONT_CARE = 0, /** This FilterFlag MUST be present in received messages to pass though the filter */ REQUIRE, SET, /** This FilterFlag must NOT be present in received messages to pass though the filter */ EXCLUDE, NOT_SET, }; enum Result : uint8_t { Loading
automotive/can/1.0/vts/functional/VtsHalCanBusV1_0TargetTest.cpp +11 −5 Original line number Diff line number Diff line Loading @@ -78,7 +78,7 @@ sp<ICloseHandle> CanBusHalTest::listenForErrors(const sp<ICanErrorListener>& lis TEST_F(CanBusHalTest, SendNoPayload) { CanMessage msg = {}; msg.id = 0x123; ASSERT_NE(mCanBus, nullptr); const auto result = mCanBus->send(msg); ASSERT_EQ(Result::OK, result); } Loading Loading @@ -118,9 +118,9 @@ TEST_F(CanBusHalTest, ListenNoFilter) { TEST_F(CanBusHalTest, ListenSomeFilter) { hidl_vec<CanMessageFilter> filters = { {0x123, 0x1FF, false, FilterFlag::DONT_CARE, FilterFlag::DONT_CARE}, {0x001, 0x00F, true, FilterFlag::DONT_CARE, FilterFlag::DONT_CARE}, {0x200, 0x100, false, FilterFlag::DONT_CARE, FilterFlag::DONT_CARE}, {0x123, 0x1FF, FilterFlag::DONT_CARE, FilterFlag::DONT_CARE, false}, {0x001, 0x00F, FilterFlag::DONT_CARE, FilterFlag::DONT_CARE, true}, {0x200, 0x100, FilterFlag::DONT_CARE, FilterFlag::DONT_CARE, false}, }; const auto [result, closeHandle] = listen(filters, new CanMessageListener()); Loading Loading @@ -171,14 +171,20 @@ TEST_F(CanBusHalTest, DontCloseErrorListener) { } // namespace android::hardware::automotive::can::V1_0::vts /** * This test requires that you bring up a valid bus first. * * Before running: * mma -j && adb root && adb remount && adb sync * * Example manual invocation: * adb shell /data/nativetest64/VtsHalCanBusV1_0TargetTest/VtsHalCanBusV1_0TargetTest \ * --hal_service_instance=android.hardware.automotive.can@1.0::ICanBus/test * --hal_service_instance=android.hardware.automotive.can@1.0::ICanBus/<NAME_OF_VALID_BUS> */ int main(int argc, char** argv) { using android::hardware::automotive::can::V1_0::ICanBus; using android::hardware::automotive::can::V1_0::vts::gEnv; using android::hardware::automotive::can::V1_0::vts::utils::SimpleHidlEnvironment; setenv("TREBLE_TESTING_OVERRIDE", "true", true); android::base::SetDefaultTag("CanBusVts"); android::base::SetMinimumLogSeverity(android::base::VERBOSE); gEnv = new SimpleHidlEnvironment<ICanBus>; Loading
automotive/can/1.0/vts/functional/VtsHalCanBusVirtualV1_0TargetTest.cpp +600 −32 File changed.Preview size limit exceeded, changes collapsed. Show changes