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>
Copy the read data from the correct result buffer, otherwise
this results in incorrect data and/or memory overwrites in the
guest memory.
Signed-off-by: Vincent Whitchurch <vincent@whitchurch.se>
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>