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>
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>
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>
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>
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>
While there may be some work to do on the testing framework to make
proper use of vm-virtio we should at least document the desire for
modularity.
Signed-off-by: Alex Bennée <alex.bennee@linaro.org>
This will help with review of incoming stuff although we may need to
lean on the wider community when it comes to more in depth Rust stuff.
Signed-off-by: Alex Bennée <alex.bennee@linaro.org>
The funcs() implementation is buggy as it doesn't take "func" by
reference and it only defaults to SMBUS and hence the I2C protocol is
never chosen as a function.
Since the value of "func" is never required to be set by the caller, it
shouldn't be passed as argument in the first place. Make the function
return Result<u64> instead.
The test test_funcs() was failing before this change and passes after
it.
Signed-off-by: Viresh Kumar <viresh.kumar@linaro.org>
The funcs() implementation is buggy as it doesn't take "func" by
reference and it only defaults to SMBUS and hence the I2C protocol is
never chosen as a function.
This test fails currently.
Suggested-by: Andreea Florescu <fandree@amazon.com>
Signed-off-by: Viresh Kumar <viresh.kumar@linaro.org>
Use hashmap instead of an array of size 1 << 7, as only a few entries of
the array are used here.
Signed-off-by: Viresh Kumar <viresh.kumar@linaro.org>
Be consistent with the use of expect() and unwrap() and use only one of
them, if required. Also add a comment on why usage of unwrap() is safe
in main().
Signed-off-by: Viresh Kumar <viresh.kumar@linaro.org>
The crate uses lots of ways to report errors, unify them and use a
separate Error enum type for each file. This will also help us improve
the test code later on.
Signed-off-by: Viresh Kumar <viresh.kumar@linaro.org>
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>