Skip to content

Commit

Permalink
abitest: test handle renumbering (#771)
Browse files Browse the repository at this point in the history
  • Loading branch information
daviddrysdale committed Mar 26, 2020
1 parent 8069863 commit 6a6ec36
Showing 1 changed file with 30 additions and 0 deletions.
30 changes: 30 additions & 0 deletions examples/abitest/module_0/rust/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -125,6 +125,10 @@ impl OakABITestService for FrontendNode {
tests.insert("ChannelReadOrphan", FrontendNode::test_channel_read_orphan);
tests.insert("ChannelWriteRaw", FrontendNode::test_channel_write_raw);
tests.insert("ChannelWrite", FrontendNode::test_channel_write);
tests.insert(
"ChannelWriteHandle",
FrontendNode::test_channel_write_handle,
);
tests.insert(
"ChannelWriteOrphan",
FrontendNode::test_channel_write_orphan,
Expand Down Expand Up @@ -645,6 +649,32 @@ impl FrontendNode {
Ok(())
}

fn test_channel_write_handle(&mut self) -> TestResult {
let (out_channel, in_channel) = oak::channel_create().unwrap();

// Send a single handle.
let empty = vec![];
expect_eq!(
Ok(()),
oak::channel_write(out_channel, &empty, &[in_channel.handle])
);

let mut buffer = Vec::<u8>::with_capacity(5);
let mut handles = Vec::with_capacity(1);
expect_eq!(
Ok(()),
oak::channel_read(in_channel, &mut buffer, &mut handles)
);
expect_eq!(0, buffer.len());
expect_eq!(1, handles.len());
// The transferred handle has a new value.
expect!(handles[0] != in_channel.handle);

expect_eq!(Ok(()), oak::channel_close(in_channel.handle));
expect_eq!(Ok(()), oak::channel_close(out_channel.handle));
Ok(())
}

fn test_channel_write_orphan(&mut self) -> TestResult {
let (out_channel, in_channel) = oak::channel_create().unwrap();

Expand Down

0 comments on commit 6a6ec36

Please sign in to comment.