mod test_utilities;
use async_rdma::{LocalMrReadAccess, LocalMrWriteAccess, Rdma};
use std::{alloc::Layout, io, time::Duration};
use test_utilities::test_server_client;
mod send_with_imm {
use super::*;
struct Data(String);
static IMM_NUM: u32 = 123;
static MSG: &str = "hello world";
async fn client(rdma: Rdma) -> io::Result<()> {
let mut lmr = rdma.alloc_local_mr(Layout::new::<Data>())?;
unsafe { std::ptr::write(lmr.as_mut_ptr() as *mut Data, Data(MSG.to_string())) };
rdma.send_with_imm(&lmr, IMM_NUM).await?;
rdma.send_with_imm(&lmr, IMM_NUM).await?;
rdma.send(&lmr).await?;
rdma.send(&lmr).await?;
Ok(())
}
async fn server(rdma: Rdma) -> io::Result<()> {
let (lmr, imm) = rdma.receive_with_imm().await?;
assert_eq!(imm, Some(IMM_NUM));
unsafe { assert_eq!(MSG.to_string(), *(*(lmr.as_ptr() as *const Data)).0) };
let lmr = rdma.receive().await?;
unsafe { assert_eq!(MSG.to_string(), *(*(lmr.as_ptr() as *const Data)).0) };
let (lmr, imm) = rdma.receive_with_imm().await?;
assert_eq!(imm, None);
unsafe { assert_eq!(MSG.to_string(), *(*(lmr.as_ptr() as *const Data)).0) };
let lmr = rdma.receive().await?;
unsafe { assert_eq!(MSG.to_string(), *(*(lmr.as_ptr() as *const Data)).0) };
tokio::time::sleep(Duration::from_secs(1)).await;
Ok(())
}
#[test]
fn main() {
test_server_client(server, client);
}
}
mod write_with_imm {
use super::*;
struct Data(String);
static IMM_NUM: u32 = 123;
static MSG: &str = "hello world";
async fn client(rdma: Rdma) -> io::Result<()> {
let mut lmr = rdma.alloc_local_mr(Layout::new::<Data>())?;
let mut rmr = rdma.request_remote_mr(Layout::new::<Data>()).await?;
unsafe { std::ptr::write(lmr.as_mut_ptr() as *mut Data, Data(MSG.to_string())) };
rdma.write_with_imm(&lmr, &mut rmr, IMM_NUM).await?;
rdma.send_remote_mr(rmr).await?;
Ok(())
}
async fn server(rdma: Rdma) -> io::Result<()> {
let imm = rdma.receive_write_imm().await?;
assert_eq!(imm, IMM_NUM);
let lmr = rdma.receive_local_mr().await?;
unsafe { assert_eq!(MSG.to_string(), *(*(lmr.as_ptr() as *const Data)).0) };
tokio::time::sleep(Duration::from_secs(1)).await;
Ok(())
}
#[test]
fn main() {
test_server_client(server, client);
}
}