Commit Graph

41 Commits

Author SHA1 Message Date
Dorinda Bassey
9f72a8187f vhost-device-gpu: Refactor vhost-device-gpu
This commit refactors vhost-device-gpu by separating
virglrenderer from rutabaga, and using gfxstream via
rutabaga, Simplifying future backend development.

This commit introduces a significant refactor of the
virtio-gpu backend architecture:
- Transition `gfxstream` support to use `Rutabaga`
  abstraction.
- Decouple `virglrenderer` from `Rutabaga`, allowing
  it to be used as standalone.
- Unify backend handling using thread-local storage
  and macro-based runtime dispatch.

Key Changes:
VirglRenderer Backend:
   - `virgl.rs` is now a standalone backend that
     directly calls `libvirglrenderer` functions.
   - Removed reliance on `rutabaga` for virgl path.

Gfxstream Backend via Rutabaga:
   - Introduced `gfxstream.rs` backend using `rutabaga`
   - Thread-local `GfxstreamAdapter` manages its own
     `Rutabaga` instance, initialized lazily.
   - Preserved internal `GfxstreamResource` tracking
     with scanout support and memory handling.

Renderer Selection Logic:
   - In `device.rs`, `lazy_init_and_handle_event()` now:
     - Dispatches `VirglRendererAdapter` and
       `GfxstreamAdapter` using thread-local storage(TLS)
   - Introduced `extract_backend_and_vring()` helper for
     reusing backend setup logic.

Code Deduplication:
   - Abstracted common logic for both backends to common.rs.
   - Shared helpers reused between gfxstream and virgl.
   - Improved modularity with fewer duplicated error
     handling branches.

Testing and Validation:
   - Replaced `virtio_gpu.rs` testing paths with new unit
     tests for `gfxstream.rs` and `virgl.rs`.
   - Added code coverage for the new refactored crate.
   - Update coverage file to reflect the drop in coverage
     due to exclusion of some gfxstream tests from CI
     since they can't run in CI without GPU drivers.

Signed-off-by: Dorinda Bassey <dbassey@redhat.com>
2025-11-13 14:48:04 +01:00
Manos Pitsidianakis
4fd2add85c Adjust coverage for toolchain update
Signed-off-by: Manos Pitsidianakis <manos.pitsidianakis@linaro.org>
2025-11-10 10:39:03 +02:00
Manos Pitsidianakis
427ea9655e Add an xtask crate to generate manpages
For information about the cargo xtask workflow pattern see: <https://github.com/matklad/cargo-xtask>

This commit adds an xtask crate with only one task, "mangen", which
generates a ROFF manual page under `target/dist/man` directory for the
vhost-device-sound binary.

The xtask crate can be configured using cargo features, to help
packagers configure what manpages are generated.

This generates a manpage in target/dist/man/vhost-device-sound.1

The rendered ROFF output looks like:

  vhost-device-sound(1)        General Commands Manual       vhost-device-sound(1)

  NAME
         vhost-device-sound - A virtio-sound device using the vhost-user protocol.

  SYNOPSIS
         vhost-device-sound <--socket> <--backend> [-h|--help] [-V|--version]

  DESCRIPTION
         A virtio-sound device using the vhost-user protocol.

  OPTIONS
         --socket=SOCKET
                vhost-user Unix domain socket path

         --backend=BACKEND
                audio backend to be used

                [possible values: null, pipewire, alsa]

         -h, --help
                Print help

         -V, --version
                Print version

  VERSION
         v0.2.0

  REPORTING BUGS
         Report bugs to the project's issue tracker: https://github.com/rust-vmm/vhost-device

                        vhost-device-sound 0.2.0      vhost-device-sound(1)

Fixes #687 ("Add man page for vhost-device-sound")

Resolves: https://github.com/rust-vmm/vhost-device/issues/687
Signed-off-by: Manos Pitsidianakis <manos.pitsidianakis@linaro.org>
2025-04-15 14:25:32 +05:30
Matej Hrica
02409f0a09 Move vhost-user-gpu from staging to main directory
The CLI interface should be stable now and coverage is good. Support
for more backends as described in the README is comming later.

Note that this decreases the test coverage in the staging directory from
82.43% to 74.62%.

Signed-off-by: Matej Hrica <mhrica@redhat.com>
2025-02-14 10:15:52 +02:00
dependabot[bot]
fe02fcd89c build(deps): bump rust-vmm-ci from 2122417 to 1150c47
Bumps [rust-vmm-ci](https://github.com/rust-vmm/rust-vmm-ci) from `2122417` to `1150c47`.
- [Commits](212241789d...1150c47872)

---
updated-dependencies:
- dependency-name: rust-vmm-ci
  dependency-type: direct:production
...

Signed-off-by: dependabot[bot] <support@github.com>

[SG] Updated coverage score since we fixed its calculation, see
https://github.com/rust-vmm/rust-vmm-ci/pull/171

Signed-off-by: Stefano Garzarella <sgarzare@redhat.com>
2024-10-28 09:24:15 +01:00
Stefano Garzarella
057f3fefe5 chore: update code coverage score
The new CI update increased code coverage also in other repos.

Signed-off-by: Stefano Garzarella <sgarzare@redhat.com>
2024-09-25 10:27:44 +03:00
Haixu Cui
d12bf9886d vhost-device-spi: Add initial implementation
This program is a vhost-user backend that emulates a VirtIO SPI bus.
This program takes the layout of the spi bus and its devices on the host
OS and then talks to them via the /dev/spidevX.Y interface when a request
comes from the guest OS for a SPI device.

The implementation corresponds with the specification:
https://github.com/oasis-tcs/virtio-spec/tree/virtio-1.4/device-types/spi

Signed-off-by: Haixu Cui <quic_haixcui@quicinc.com>
2024-07-29 09:51:40 +02:00
Matias Ezequiel Vara Larsen
2f3b0b1f38 sound: Use Reader/Writer for tx/rx queue
This commit makes the handling of the tx/rx to rely on the Reader/Writer
modules. The commit also fixes the tests at streams.rs and replaces the
naming buffer for request. The coverage is also updated.

Signed-off-by: Matias Ezequiel Vara Larsen <mvaralar@redhat.com>
2024-07-22 13:50:40 +02:00
Stefano Garzarella
b113dc6b28 sound: promote to main workspace
The current implementation seems ready to be promoted to the
main workspace since the device supports both playback and recording,
and several audio backends.

Also, test coverage is good and aligned with the coverage of crates
in the main workspace.

Signed-off-by: Stefano Garzarella <sgarzare@redhat.com>
2024-01-03 11:16:07 +05:30
Viresh Kumar
fe1778a731 Add vhost-device-template crate
This adds a basic template crate, which will be useful for new
developers to understand how things work and layout all basic stuff they
are expected to write to make it work.

The current implementation just parses all the requests from the
virtqueue and prints the number of descriptor chains and size of each
descriptor buffer in there.

This adds basic sanity tests as well for the same, which can be run to
test the working of the crate.

Signed-off-by: Viresh Kumar <viresh.kumar@linaro.org>
2023-12-01 15:40:19 +05:30
Stefano Garzarella
5847489855 vsock: increase test coverage
Add more tests in vhost-device-vsock to increase the coverage.

Some of them are really simple and perhaps nonsensical (tests for
Debug, Clone, etc.), but for now we don't know how to disable this
in the tool, so let's cover these cases.

The vhost-device-vsock functions coverage increases from 70.73% to
90.45%:
    Filename             Functions  Missed Functions  Executed
    ----------------------------------------------------------
    main.rs                     51                12    76.47%
    rxops.rs                     8                 0   100.00%
    rxqueue.rs                  20                 0   100.00%
    thread_backend.rs           20                 3    85.00%
    txbuf.rs                    17                 0   100.00%
    vhu_vsock.rs                37                 1    97.30%
    vhu_vsock_thread.rs         40                 5    87.50%
    vsock_conn.rs               27                 0   100.00%
    ----------------------------------------------------------
    TOTAL                      220                21    90.45%

Closes #229

Signed-off-by: Stefano Garzarella <sgarzare@redhat.com>
2023-11-08 12:34:12 +02:00
Erik Schilling
2681d12435 tests: adjust code coverage after tool updates
CI was updated and now claims higher code coverage. Adjusting the values
to what the CI claims now.

Signed-off-by: Erik Schilling <erik.schilling@linaro.org>
2023-09-13 15:58:52 +01:00
Milan Zamazal
58650819ff Increase coverage score
CI complains not only when the score is too low but also when it is
too high.  Accommodate the increased average coverage caused by adding
vhost-device-scmi and its unit tests.

Signed-off-by: Milan Zamazal <mzamazal@redhat.com>
2023-09-04 16:15:33 +01:00
Erik Schilling
a9de87a1ce tree-wide: bubble up errors from daemon threads
There was a mix of just unwrapping (panicking) and catching and logging
errors. The unwrapping is not allowing for particulary pretty error
handling, so let's bubble the errors up by not crashing the thread,
but by just returning a Result<()> than is received when joining the
threads.

Not all .unwrap() uses were translated since a followup PR (#389) will
rework that code anyway (and get rid of the .unwrap() in the process).

Signed-off-by: Erik Schilling <erik.schilling@linaro.org>
2023-07-11 13:30:01 +05:30
Erik Schilling
9332a933f8 tree-wide: actually pretty-print error messages
We setup pretty-printing with all the thiserror-based Error structs, but
then only bubble the error up to the main, where it just gets printed
with the `Debug` trait.

This "catches" the error in the main and performs pretty printing using
the `Display` trait.

Before:

    Error: FailedCreatingListener(SocketError(Os { code: 98, kind:
        AddrInUse, message: "Address already in use" }))

After:

    [2023-07-06T17:20:47Z ERROR vhost_device_scsi] Failed creating
        listener: socket error: Address already in use (os error 98)

vhost-device-vsock is a bit special since it does not let error messages
bubble up to the main. It also does .unwrap() in most places, but it
_does_  pretty print errors during the main request handling part.

Had to slightly adjust the coverage since we have no tests for the main
functions.

Signed-off-by: Erik Schilling <erik.schilling@linaro.org>
2023-07-11 13:30:01 +05:30
Gaelan Steele
1de6d02fb8 scsi: Add tests for the emulated target
The vast majority of this work was done by Gaelan Steele as part of a
GSoC project [1][2].

[1] https://github.com/rust-vmm/vhost-device/pull/4
[2] https://gist.github.com/Gaelan/febec4e4606e1320026a0924c3bf74d0

Co-developed-by: Erik Schilling <erik.schilling@linaro.org>
Signed-off-by: Erik Schilling <erik.schilling@linaro.org>
Signed-off-by: Gaelan Steele <gbs@canishe.com>
2023-06-05 14:55:32 +05:30
Viresh Kumar
799073f17c gpio: Migrate to the upstream version of libgpiod
The upstream version doesn't compile the .c files locally and depends on
the package to be locally compiled and installed in advance.

It also doesn't provide pre-generated bindings, and requires bindgen
support.

Signed-off-by: Viresh Kumar <viresh.kumar@linaro.org>
2023-02-15 08:09:13 -07:00
Viresh Kumar
7c1d5ac57d gpiod: Migrate to upstreamed version of libgpiod
The libgpiod rust bindings got upstreamed recently. Migrate to the
upstreamed version.

Signed-off-by: Viresh Kumar <viresh.kumar@linaro.org>
2022-12-05 15:21:44 +05:30
Stefano Garzarella
a6d157f5e5 vsock: add more tests and update coverage_score
Add several tests to get good coverage. Unfortunately,
it's a lot of new code and not easy to test everything.
We may add more mocks and tests in the future.

Signed-off-by: Stefano Garzarella <sgarzare@redhat.com>
2022-10-12 15:17:45 +02:00
Viresh Kumar
a9678adfb9 gpio: Update Cargo.lock and coverage score
Update Cargo.lock and coverage score.

Signed-off-by: Viresh Kumar <viresh.kumar@linaro.org>
2022-04-04 12:38:51 +05:30
Mathieu Poirier
198fa54325 rng: Add testing module for vhost-device RNG
This patch adds testing modules for both main.rs and vu_rng.rs
in order to satisfy functional testing and code coverage.

Signed-off-by: Mathieu Poirier <mathieu.poirier@linaro.org>
2022-03-01 14:37:36 -07:00
Sergii Glushchenko
3cc37dada4 Adjust test coverage
Signed-off-by: Sergii Glushchenko <gsserge@amazon.com>
2022-01-25 10:13:02 +01:00
Viresh Kumar
33c40e5c06 Update cargo.lock and coverage
Update cargo.lock and coverage to match the latest code.

Signed-off-by: Viresh Kumar <viresh.kumar@linaro.org>
2022-01-20 14:50:25 +05:30
Sergii Glushchenko
c2e8d01cb9 Fix clippy warnings and adjust coverage
Signed-off-by: Sergii Glushchenko <gsserge@amazon.com>
2022-01-19 13:30:06 +01:00
Viresh Kumar
be99550269 i2c: Improve test coverage
Add more tests to increase coverage.

Signed-off-by: Viresh Kumar <viresh.kumar@linaro.org>
2022-01-10 12:50:52 +05:30
Viresh Kumar
8d8950b4cf i2c: Initialize env_logger
The i2c crate now uses log crate to publish error, info and warn
messages, but doesn't initialize a logger yet and these messages never
make it out.

Initialize the env_logger to see these messages.

Signed-off-by: Viresh Kumar <viresh.kumar@linaro.org>
2022-01-06 14:41:32 +05:30
Viresh Kumar
8c92046701 [i2c] Test descriptor processing
Add tests to validate processing of descriptors and read/write data.

The design is based on the virtio_queue::mock::MockSplitQueue
implementation, which is used to add a set of descriptors to the memory.
The same memory is then processed via DescriptorChain and the same set
of descriptors magically appear.

This patch adds various tests for success and failure and also validate
the data read or written.

Signed-off-by: Viresh Kumar <viresh.kumar@linaro.org>
2021-11-25 16:22:53 +05:30
Viresh Kumar
fbab2abc79 [i2c] Allow zero-length requests
Commands like SMBUS Quick don't require a buffer for the request and are
called as zero-length requests. The specification allows such requests
under the VIRTIO_I2C_F_ZERO_LENGTH_REQUEST feature, which is mandatory
to be implemented by the devices now.

Add support for zero-length requests.

Signed-off-by: Viresh Kumar <viresh.kumar@linaro.org>
2021-11-22 09:55:37 +05:30
Viresh Kumar
5af15e89bf [i2c] Add tests to validate data
Add tests to validate the data processed by rdwr() and smbus(). The
coverage score went up significantly as a result of all recent tests.

Signed-off-by: Viresh Kumar <viresh.kumar@linaro.org>
2021-11-17 08:57:28 +05:30
Viresh Kumar
b4e47f4994 [i2c] Send data for I2C_SMBUS_BYTE command
The data needs to be sent for I2C_SMBUS_BYTE command and we need to make
sure we don't access the same for I2C_SMBUS_QUICK command after the
command is processed.

Signed-off-by: Viresh Kumar <viresh.kumar@linaro.org>
2021-11-16 16:49:17 +05:30
Viresh Kumar
473e45ee0f [i2c] Reorganize SmbusMsg::new()
Reorganize SmbusMsg::new() to return Result<> from the match block
itself.

Suggested-by: Alex Bennée <alex.bennee@linaro.org>
Signed-off-by: Viresh Kumar <viresh.kumar@linaro.org>
2021-11-16 15:44:02 +05:30
Viresh Kumar
00bb1ebdfa [i2c] Improve unsafe blocks
Pointer access is inherently unsafe in Rust, change the layout of
structures to avoid using that.

Signed-off-by: Viresh Kumar <viresh.kumar@linaro.org>
2021-11-16 15:44:02 +05:30
Viresh Kumar
79a84972f5 [i2c] Update coverage score and Cargo.lock
Signed-off-by: Viresh Kumar <viresh.kumar@linaro.org>
2021-10-27 12:38:09 +05:30
Andreea Florescu
57b96aa3a3 update I2cAdapter to allow setting a mock device
Before the constructor of this function was opening the device
corresponding to the passed path. This did not allow for properly
mocking the device functionality. Now the device is passed as a
parameter instead, which allows us to tweak what the device returns for
ioctl calls, and we can thus test multiple scenarios.

Signed-off-by: Andreea Florescu <fandree@amazon.com>
2021-10-26 10:27:58 +03:00
Viresh Kumar
8028571d0a [i2c] Update coverage score
Signed-off-by: Viresh Kumar <viresh.kumar@linaro.org>
2021-10-08 14:29:15 +03:00
Viresh Kumar
bf59120d50 [i2c] update coverage score
Signed-off-by: Viresh Kumar <viresh.kumar@linaro.org>
2021-10-06 16:57:06 +05:30
Andreea Florescu
32b9d1a2a2 [i2c] update coverage score
Coverage is now increased by ~9%. Further tests should be relatively
straightforward to write by using the mock structure `DummyDevice`.

Signed-off-by: Andreea Florescu <fandree@amazon.com>
2021-09-23 18:31:39 +03:00
Viresh Kumar
c5e90cfee9 i2c: Add tests to cover basic backend operations
This still doesn't emulate the descriptors and descriptor chains over
the vrings. That will be added later.

Signed-off-by: Viresh Kumar <viresh.kumar@linaro.org>
2021-09-14 11:00:56 +03:00
Viresh Kumar
65da614d8b Update coverage to match with CI update
Signed-off-by: Viresh Kumar <viresh.kumar@linaro.org>
2021-08-20 10:08:45 +03:00
Viresh Kumar
019e755c61 i2c: Reduce test coverage score
Reduce the test coverage score as the files apart from i2c.rs are
mostly boilerplate code and it is difficult to test them as well as it
may not be worth it.

Signed-off-by: Viresh Kumar <viresh.kumar@linaro.org>
2021-08-19 09:52:14 +03:00
Andreea Florescu
72710f3a89 Initial commit 2021-05-26 10:18:40 +03:00