The socket count argument is optional and defaults to 1, but the tests
written for it were more C like and weren't so clean. Use Option to
improve upon that.
While at it, fix socket names as well. Socket name is name of a socket
and shouldn't be used as test-name. Fix the TODOs as well.
Signed-off-by: Viresh Kumar <viresh.kumar@linaro.org>
This moves the code around to keep structures together with their
implementations, and also keep all configuration stuff to main.c itself.
Signed-off-by: Viresh Kumar <viresh.kumar@linaro.org>
It still doesn't look correct to keep a separate routine for this, which
can be called by others.
Merge it with new() itself.
Signed-off-by: Viresh Kumar <viresh.kumar@linaro.org>
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>
Remove the dry run related functionality. The main function now just
having boilerplate code that we should test via integration tests. We
can test the parsing by validating the `TryFrom` implementation.
Everything else is not possible to test with unit tests because they
need I/O (such as working with sockets), and thus are more appropriate
for integration tests.
Added more tests for validating the expected behavior of parsing.
Signed-off-by: Andreea Florescu <fandree@amazon.com>
Without the dependency fixed, the build is failing. Also, considering
that this crate exports a binary, `Cargo.lock` must be committed to the
repository. Added the `Cargo.lock` file.
Signed-off-by: Andreea Florescu <fandree@amazon.com>
Updated the existing unit tests to map to the new implemented
abstraction.
In the process of updating the tests, a few other worth mentioning
changes are implemented:
- when initializing a resource needed for the test, it is a best
practice to keep any updates that change the test result in the same
function. This was not followed as the requests vector was initialized
in the test, and was cleared in a function that was asserting results.
This is an unexpected behavior, and is now removed. The requests are
always initialized in the test before using them (and clear is no longer
used).
- `assert_results` is deleted because it was hard to read which results
where asserted. It is also not necessary to mock functions in that way
because now we can mock only the parts we need from the device
implementation.
The tests are incomplete though because we also need to check the error
returned. This should be implemented in a future commit to keep things
separated.
Signed-off-by: Andreea Florescu <fandree@amazon.com>
This helps with simplifying the code by keeping all checks at init time.
In practice it means that invalid objects can no longer be created,
which simplifies the testing.
All objects are created through either new, or `TryFrom`, and they can
only be updated (outside of test functions) via functions that are
checking the validity of the resulting object.
Signed-off-by: Andreea Florescu <fandree@amazon.com>
This separation is needed so we can easily write unit tests for parsing
without needing to create full blown objects. (as a side note, before
this is possible, we also need to get rid of errno, and replace it with
custom Errors, so that we can also write the much needed negative
tests).
This separation is achieved through creating configuration structures
that can be either programatically initialized, or initialized through
parsing the command line parameters.
This commit is still WIP because we also need to make sure that
configuration objects can only be created valid (to reduce some risks
for future extensions where parameters might be passed some other way
rather than yaml). Also, we need to move the check for uniquness of
device addresses in the DeviceConfig instead of the `I2cMap`.
Signed-off-by: Andreea Florescu <fandree@amazon.com>
The I2cAdapterTrait was introduced because of a need to test the i2c
implementation without having access to a physical device on the host
running the tests. This abstraction though still made the tests pretty
hard to write, so it is now replaced by another abstractions: I2cDevice.
This abstraction is written working backwards from what we DO NOT have
access to on the host where we want to run the tests. This is the i2c
device. So, this abstraction is just abstracting the way all the ioctl
calls that need to be handled by an i2c device. This way, we can test
all the other wrappers that are implemented in this crate.
The abstraction is implemented for a physical device to keep backwards
compatibility with existing code.
This abstraction still needs improvements such as marking the functions
as unsafe. For now the tests are commented out because they need to be
re-written with this abstraction. Since we still have refactoring work
to do (i.e. separate the parsing from the device operation), writing
tests is postponed so that it does not involve duplicated work.
Signed-off-by: Andreea Florescu <fandree@amazon.com>
This function does not need to be in the trait. Having it as a public
function also makes the code hard to use because the return of the
`is_smbus` function is only valid after an initial call to `get_func`.
To get rid of this behavior, we can make the `get_func` a private
function in the `I2cAdapter` implementation, and call this function on
`new`.
The function was renamed to `read_func` to make the name more "mutable"
compatible (the function needs a mutable reference, but it was called
`get`; get functions don't typically need mutable references).
Signed-off-by: Andreea Florescu <fandree@amazon.com>
We've typically separated imports in 3 categories:
- Rust standard library
- external crates
- project internal imports (such as imports from user defined modules)
Signed-off-by: Andreea Florescu <fandree@amazon.com>
This is a first change in a series meant for moving all the parsing of
strings in a single place, with the goal of separating parsing from the
device operation. This helps with separating concerns, mocking, and
writing unit tests.
Signed-off-by: Andreea Florescu <fandree@amazon.com>
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>
Remove the incorrect file dependabot.yaml and edit the correct one to
allow crate updates on weekly basis.
Signed-off-by: Viresh Kumar <viresh.kumar@linaro.org>
To avoid breaking the crate with a newer version of the
vhost-user-backend crate, fix the dependency to a known good version of
the crate.
Signed-off-by: Viresh Kumar <viresh.kumar@linaro.org>
vhost-user-backend repository received few updates recently, which
caused this one to break.
Update the code here to fix the breakage.
Signed-off-by: Viresh Kumar <viresh.kumar@linaro.org>
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>