Commit Graph

30 Commits

Author SHA1 Message Date
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