Merge "Setup tests for libtrusty-rs"
This commit is contained in:
commit
3153efa864
3 changed files with 41 additions and 6 deletions
|
|
@ -26,3 +26,12 @@ rust_library {
|
||||||
"libnix",
|
"libnix",
|
||||||
],
|
],
|
||||||
}
|
}
|
||||||
|
|
||||||
|
rust_test {
|
||||||
|
name: "libtrusty-rs-tests",
|
||||||
|
crate_name: "trusty_test",
|
||||||
|
srcs: ["tests/test.rs"],
|
||||||
|
rustlibs: [
|
||||||
|
"libtrusty-rs",
|
||||||
|
]
|
||||||
|
}
|
||||||
|
|
|
||||||
|
|
@ -128,15 +128,15 @@ impl TipcChannel {
|
||||||
/// Receives a message from the connected service.
|
/// Receives a message from the connected service.
|
||||||
///
|
///
|
||||||
/// Returns the number of bytes in the received message, or any error that
|
/// Returns the number of bytes in the received message, or any error that
|
||||||
/// occurred when reading the message. A return value of 0 indicates that
|
/// occurred when reading the message. Blocks until there is a message to
|
||||||
/// there were no incoming messages to receive.
|
/// receive if none is already ready to read.
|
||||||
///
|
///
|
||||||
/// # Errors
|
/// # Errors
|
||||||
///
|
///
|
||||||
/// Returns an error with native error code 90 (`EMSGSIZE`) if `buf` isn't
|
/// Returns an error with native error code 90 (`EMSGSIZE`) if `buf` isn't large
|
||||||
/// large enough to contain the incoming message. Use
|
/// enough to contain the incoming message. Use
|
||||||
/// [`raw_os_error`][std::io::Error::raw_os_error] to check the error code
|
/// [`raw_os_error`][std::io::Error::raw_os_error] to check the error code to
|
||||||
/// to determine if you need to increase the size of `buf`.
|
/// determine if you need to increase the size of `buf`.
|
||||||
pub fn recv(&mut self, buf: &mut [u8]) -> io::Result<usize> {
|
pub fn recv(&mut self, buf: &mut [u8]) -> io::Result<usize> {
|
||||||
self.0.read(buf)
|
self.0.read(buf)
|
||||||
}
|
}
|
||||||
|
|
|
||||||
26
trusty/libtrusty-rs/tests/test.rs
Normal file
26
trusty/libtrusty-rs/tests/test.rs
Normal file
|
|
@ -0,0 +1,26 @@
|
||||||
|
use trusty::{TipcChannel, DEFAULT_DEVICE};
|
||||||
|
|
||||||
|
const ECHO_NAME: &str = "com.android.ipc-unittest.srv.echo";
|
||||||
|
|
||||||
|
#[test]
|
||||||
|
fn echo() {
|
||||||
|
let mut connection = TipcChannel::connect(DEFAULT_DEVICE, ECHO_NAME)
|
||||||
|
.expect("Failed to connect to Trusty service");
|
||||||
|
|
||||||
|
// Send a message to the echo TA.
|
||||||
|
let send_buf = [7u8; 32];
|
||||||
|
connection.send(send_buf.as_slice()).unwrap();
|
||||||
|
|
||||||
|
// Receive the response message from the TA.
|
||||||
|
let mut recv_buf = [0u8; 32];
|
||||||
|
let read_len = connection.recv(&mut recv_buf).expect("Failed to read from connection");
|
||||||
|
|
||||||
|
assert_eq!(
|
||||||
|
send_buf.len(),
|
||||||
|
read_len,
|
||||||
|
"Received data was wrong size (expected {} bytes, received {})",
|
||||||
|
send_buf.len(),
|
||||||
|
read_len,
|
||||||
|
);
|
||||||
|
assert_eq!(send_buf, recv_buf, "Received data does not match sent data");
|
||||||
|
}
|
||||||
Loading…
Add table
Reference in a new issue