Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Update CommandReturn in preparation for the Command implementation. #299

Merged
merged 1 commit into from
May 19, 2021

Conversation

jrvanwhy
Copy link
Collaborator

This makes the following change to CommandReturn, which are needed by my implementation of the Command system call and its tests:

  1. Implements Debug. This is not a replacement for ufmt-based debugging, but rather to support unit tests (e.g. assert_eq!).
  2. Changes the register values from usize to u32, as RawSyscalls no longer returns its registers as usizes. I discovered that code that interacts with CommandReturn is cleaner if we store u32s in CommandReturn rather than Registers.
  3. new is now pub rather than pub(crate), as libtock_unittest needs to create CommandReturn values.
  4. I added CommandReturn::raw_values, which will be used by libtock_unittest to transform CommandReturns from fake drivers and expected syscalls into register values for RawSyscalls.
  5. I added safe CommandReturn constructors to libtock_unittest. libtock_platform intentionally does not expose safe constructors, as a process binary should only create a CommandReturn by calling the Command system call. However, libtock_unittest and unit tests based on it need to create CommandReturn values as well, so I added safe constructors.

The combination of 1 and 5 required me to add Debug to ErrorCode and ReturnVariant, so I did that as well.

@jrvanwhy jrvanwhy added the significant Indicates a PR is significant as defined by the code review policy. label May 13, 2021
`libtock_platform` does not provide safe constructors for `CommandReturn`, as in a process binary it is supposed to only be created by invocations of the Command system call. However, fake drivers for unit tests (as well as many unit tests) have a need to create their own `CommandReturn` values. To avoid a proliferation of `unsafe`, I added safe constructors for `CommandReturn` to `libtock_unittest`.

For testing purposes, I added unconditional `Debug` derives to some of the `libtock_platform` types. These are meant only for use in host-based tests: embedded code should use a lighter-weight solution (we're currently trying out `ufmt` for this).
@jrvanwhy
Copy link
Collaborator Author

bors r+

@bors
Copy link
Contributor

bors bot commented May 19, 2021

Build succeeded:

@bors bors bot merged commit 0fe6395 into tock:master May 19, 2021
@jrvanwhy jrvanwhy deleted the unittest-cmd-ret branch September 4, 2021 21:21
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
significant Indicates a PR is significant as defined by the code review policy.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants