Skip to content

Fix tests in vhost-can-device#957

Open
MatiasVara wants to merge 4 commits into
rust-vmm:mainfrom
MatiasVara:can-fix-test
Open

Fix tests in vhost-can-device#957
MatiasVara wants to merge 4 commits into
rust-vmm:mainfrom
MatiasVara:can-fix-test

Conversation

@MatiasVara

@MatiasVara MatiasVara commented Apr 22, 2026

Copy link
Copy Markdown
Contributor

Summary of the PR

This PR includes some fixes for the test in vhost-user-can device. It also adds a mock interface to run the tests in an environment that does not have a can interface. It adds an option to set the name of the interface for tests so it can run on a real interface too. The PR also removes the name of the interface that is hardcoded in check_rx_frame() that is not required.

Requirements

Before submitting your PR, please make sure you addressed the following
requirements:

  • All commits in this PR have Signed-Off-By trailers (with
    git commit -s), and the commit message has max 60 characters for the
    summary and max 75 characters for each description line.
  • All added/changed functionality has a corresponding unit/integration
    test.
  • All added/changed public-facing functionality has entries in the "Upcoming
    Release" section of CHANGELOG.md (if no such section exists, please create one).
  • Any newly added unsafe code is properly documented.

length: 64.into(),
reserved: 0.into(),
flags: 0.into(),
flags: CAN_FRMF_TYPE_FD.into(),

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Shouldn't this be VIRTIO_CAN_FLAGS_FD?

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

In this case, the frame is sent directly to the host backend through can_out(), which expect CAN_FRMF_TYPE_FD. It seems that when we get something from the guest in the tx queue, the flag could be VIRTIO_CAN_FLAGS_FD but then it is processed by check_tx_frame() that convert it to CAN_FRMF_TYPE_FD. This test would sit after check_tx_frame(). I think, to use VIRTIO_CAN_FLAGS_FD, we would need to add check_tx_frame() to the test.

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ah, makes sense. This is not ideal modelling but this isn't this patch's fault. Is it easy to add check_tx_frame() here so that we are consistent?

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I will try it and let you know.

@MatiasVara MatiasVara Apr 22, 2026

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

check_tx_frame() is private in vhu_can.rs. I think if I want to use it in can.rs I would need to make it public. The other option is to move the test to vhu_can.rs and use check_tx_frame() with VIRTIO_CAN_FLAGS_FD.

@MatiasVara

MatiasVara commented Apr 23, 2026

Copy link
Copy Markdown
Contributor Author

@epilys if that's OK I will update the PR with other commits that fix tests so I do not open another PR.

@epilys

epilys commented Apr 23, 2026

Copy link
Copy Markdown
Member

Sure thing

@MatiasVara MatiasVara changed the title Set CAN_FRMF_TYPE_FD flag during test Fix tests in CAN Apr 23, 2026
@MatiasVara MatiasVara changed the title Fix tests in CAN Fix tests in vhost-can-device Apr 23, 2026
Fix test by using CAN_FRMF_TYPE_FD flag for 64 bytes packets and use
VIRTIO_CAN_TX as type.

Signed-off-by: Matias Ezequiel Vara Larsen <mvaralar@redhat.com>
Make the test finish when interface exists.

Signed-off-by: Matias Ezequiel Vara Larsen <mvaralar@redhat.com>
Add a mock interface for tests and an env variable for running the
tests with a real interface. To run with a real CAN interface named
`vcan0`, run:

TEST_CAN_INTERFACE=vcan0 cargo test --package vhost-device-can

Also, remove the name of the interfaces from tests since we use either
the mock interface or an existing interface. For those tests that do not
require an interface because they test a failing path, use
`nonexistent_can` interface.

Signed-off-by: Matias Ezequiel Vara Larsen <mvaralar@redhat.com>
The CAN-FD flag inference logic in check_rx_frame was gated on can_name
== "vcan0". This was added as a workaround for virtual CAN interfaces
(vcan), which do not distinguish between CAN and CAN-FD frames at the
socket level, i.e., all frames arrive as CanAnyFrame::Normal regardless of
their actual type.

However, the interface name check is unnecessary. Classic CAN frames can
never exceed 8 bytes, so the condition `res_len > 8` is already
sufficient to infer a CAN-FD frame when the feature has been negotiated.
This holds for all interface types:

- vcan: frames arrive without the FD flag, but res_len > 8 detects them
- Real CAN-FD hardware: the FD flag is already set by process_frame, so
  the additional |= is redundant but harmless
- Real classic CAN hardware: frames never exceed 8 bytes, so the
  condition is never triggered

Removing the name check also fixes the limitation of only supporting an
interface named exactly "vcan0", which excluded vcan1, vcan2, etc.

Signed-off-by: Matias Ezequiel Vara Larsen <mvaralar@redhat.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants