Donate to e Foundation | Murena handsets with /e/OS | Own a part of Murena! Learn more

Commit f53a4e2f authored by chrisweir's avatar chrisweir
Browse files

Add VTS tests for EFF/RTR

Remote transmission request, and extended format id's require testing to
verify that the feature works correctly.

Also included is a fix which correctly sets the EFF and RTR flags of the
canfd_frame object based on the state of the CanMessage object.

A readability change is made to the types.hal which improves clarity of
the way filters are defined.

Bug: 146173498
Test: run the VTS tests in vts/functional - verify that they pass
Change-Id: I9892a2e2465b8c381774e7ee277bfa8660f25028
parent c6f6cc62
Loading
Loading
Loading
Loading
+16 −13
Original line number Diff line number Diff line
@@ -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());

@@ -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;
}

@@ -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) {
+11 −12
Original line number Diff line number Diff line
@@ -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;
};


@@ -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 {
+11 −5
Original line number Diff line number Diff line
@@ -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);
}
@@ -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());
@@ -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>;
+600 −32

File changed.

Preview size limit exceeded, changes collapsed.