Add tests for random_get
@@ -126,6 +126,8 @@ impl OakABITestServiceNode for FrontendNode {
tests.insert("ChannelWrite", FrontendNode::test_channel_write);
tests.insert("WaitOnChannelsRaw", FrontendNode::test_channel_wait_raw);
tests.insert("WaitOnChannels", FrontendNode::test_channel_wait);
+ tests.insert("RandomGetRaw", FrontendNode::test_random_get_raw);
+ tests.insert("RandomGet", FrontendNode::test_random_get);
tests.insert(
"ChannelHandleReuse",
FrontendNode::test_channel_handle_reuse,
@@ -699,6 +701,25 @@ impl FrontendNode {
Ok(())
}
+ fn test_random_get_raw(&self) -> std::io::Result<()> {
+ unsafe {
+ expect_eq!(
+ OakStatus::ERR_INVALID_ARGS.value(),
+ oak::wasm::random_get(invalid_raw_offset() as *mut u8, 1)
+ );
+ }
+ Ok(())
+ }
+
+ fn test_random_get(&self) -> std::io::Result<()> {
+ let original = vec![0x01, 0x02, 0x03, 0x04];
+ let mut data = original.clone();
+ expect_eq!(OakStatus::OK, oak::random_get(&mut data));
+ // 1 in 2^32 chance of getting back original value
+ expect!(data != original);
+ Ok(())
+ }
+
fn test_channel_handle_reuse(&self) -> std::io::Result<()> {
// Set up a fresh channel with a pending message so wait_on_channels
// doesn't block.
