Commit ee6a3082 authored by RILLING Louis's avatar RILLING Louis
Browse files

fake-vm/tests: Introduce macros to use correct local and remote addresses

parent 53769283
#[cfg(test)]
#[macro_use(local_vsg_address_str, local_vsg_address, remote_vsg_address)]
extern crate fake_vm;
use fake_vm::{Context, VsgAddress, Error, Result};
use libc;
#[allow(unused_imports)]
......@@ -183,12 +187,12 @@ mod test {
macro_rules! valid_args {
() => {
os_args!("-atiti", "-n10.0.0.1", "-t1970-01-01T00:00:00")
os_args!("-atiti", "-n", local_vsg_address_str!(), "-t1970-01-01T00:00:00")
}
}
macro_rules! invalid_args {
() => {
os_args!("-btiti", "-n10.0.0.1", "-t1970-01-01T00:00:00")
os_args!("-btiti", "-n", local_vsg_address_str!(), "-t1970-01-01T00:00:00")
}
}
......@@ -390,8 +394,8 @@ mod test {
assert_eq!(0, res);
let buffer = b"Foo msg";
let src = 0;
let dest = 0;
let src = local_vsg_address!();
let dest = remote_vsg_address!();
let res: c_int = unsafe { vsg_send(context, src, dest, buffer.len() as u32, buffer.as_ref().as_ptr()) };
assert_eq!(0, res);
......@@ -414,8 +418,8 @@ mod test {
let res: c_int = unsafe { vsg_start(context) };
assert_eq!(0, res);
let src = 0;
let dest = 0;
let src = local_vsg_address!();
let dest = remote_vsg_address!();
let res: c_int = unsafe { vsg_send(context, src, dest, 0, std::ptr::null()) };
assert_eq!(0, res);
......@@ -438,8 +442,8 @@ mod test {
let res: c_int = unsafe { vsg_start(context) };
assert_eq!(0, res);
let src = 0;
let dest = 0;
let src = local_vsg_address!();
let dest = remote_vsg_address!();
let res: c_int = unsafe { vsg_send(context, src, dest, 1, std::ptr::null()) };
assert_eq!(libc::EINVAL, res);
......@@ -468,8 +472,8 @@ mod test {
assert_eq!(0, res);
let buffer = [0u8; fake_vm::MAX_PACKET_SIZE + 1];
let src = 0;
let dest = 0;
let src = local_vsg_address!();
let dest = remote_vsg_address!();
let res: c_int = unsafe { vsg_send(context, src, dest, buffer.len() as u32, (&buffer).as_ptr()) };
assert_eq!(libc::EMSGSIZE, res);
......@@ -490,8 +494,8 @@ mod test {
init();
let buffer = b"Foo msg";
let src = 0;
let dest = 1;
let src = local_vsg_address!();
let dest = remote_vsg_address!();
let res: c_int = unsafe { vsg_send(std::ptr::null(), src, dest, buffer.len() as u32, buffer.as_ref().as_ptr()) };
assert_eq!(libc::EINVAL, res);
}
......@@ -515,8 +519,8 @@ mod test {
assert_ne!(TIMEVAL_POISON.tv_usec, tv.tv_usec);
let buffer = b"This is the end";
let src = 0;
let dest = 1;
let src = local_vsg_address!();
let dest = remote_vsg_address!();
let res: c_int = unsafe { vsg_send(context, src, dest, buffer.len() as u32, buffer.as_ref().as_ptr()) };
assert_eq!(0, res);
......@@ -543,8 +547,8 @@ mod test {
assert_eq!(0, res);
let buffer = b"This is the end";
let src = 0;
let dest = 0;
let src = local_vsg_address!();
let dest = remote_vsg_address!();
let res: c_int = unsafe { vsg_send(context, src, dest, buffer.len() as u32, buffer.as_ref().as_ptr()) };
assert_eq!(0, res);
......
......@@ -306,24 +306,47 @@ pub mod test_helpers {
#[cfg(feature = "test-helpers")]
pub use super::connector::test_helpers::*;
#[macro_export]
macro_rules! local_vsg_address_str {
() => {
"10.0.0.1"
}
}
#[macro_export]
macro_rules! local_vsg_address {
() => {{
use std::str::FromStr;
u32::from(std::net::Ipv4Addr::from_str(local_vsg_address_str!()).unwrap()).to_be()
}}
}
#[macro_export]
macro_rules! remote_vsg_address {
() => {
u32::from(std::net::Ipv4Addr::new(10, 0, 1, 1)).to_be()
}
}
#[macro_export]
macro_rules! valid_args {
() => {
&["-atiti", "-n10.0.0.1", "-t1970-01-01T00:00:00"]
&["-atiti", "-n", local_vsg_address_str!(), "-t1970-01-01T00:00:00"]
}
}
#[macro_export]
macro_rules! valid_args_h1 {
() => {
&["-atiti", "-n10.0.0.1", "-t1970-01-01T01:00:00"]
&["-atiti", "-n", local_vsg_address_str!(), "-t1970-01-01T01:00:00"]
}
}
#[macro_export]
macro_rules! invalid_args {
() => {
&["-btiti", "-n10.0.0.1", "-t1970-01-01T00:00:00"]
&["-btiti", "-n", local_vsg_address_str!(), "-t1970-01-01T00:00:00"]
}
}
......@@ -439,8 +462,8 @@ mod test {
context.start()
.expect("start failed");
let src = 0;
let dest = 1;
let src = local_vsg_address!();
let dest = remote_vsg_address!();
context.send(src, dest, b"Foo msg")
.expect("send failed");
......@@ -465,8 +488,8 @@ mod test {
assert!(tv.tv_sec >= 0 && tv.tv_sec < 10);
assert!(tv.tv_usec >= 0 && tv.tv_usec < 999999);
let src = 0;
let dest = 1;
let src = local_vsg_address!();
let dest = remote_vsg_address!();
context.send(src, dest, b"This is the end")
.expect("send failed");
......@@ -491,8 +514,8 @@ mod test {
assert!(tv.tv_sec >= 3600 && tv.tv_sec < 3610);
assert!(tv.tv_usec >= 0 && tv.tv_usec < 999999);
let src = 0;
let dest = 1;
let src = local_vsg_address!();
let dest = remote_vsg_address!();
context.send(src, dest, b"This is the end")
.expect("send failed");
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment