Commit Graph

15 Commits

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