Skip to content

Commit

Permalink
[testing] Enhancement: Update error codes
Browse files Browse the repository at this point in the history
  • Loading branch information
iyzhang committed Dec 1, 2023
1 parent a33ea7e commit 1176ac8
Show file tree
Hide file tree
Showing 7 changed files with 51 additions and 16 deletions.
13 changes: 12 additions & 1 deletion examples/tcp-echo/client.rs
Original file line number Diff line number Diff line change
Expand Up @@ -349,7 +349,7 @@ impl TcpEchoClient {
let errno: i64 = qr.qr_ret;

// Check if client has reset the connection.
if errno == libc::ECONNRESET as i64 {
if is_closed(errno) {
println!("INFO: server reset connection (qd={:?})", qd);
self.handle_close(qd)?;
} else {
Expand Down Expand Up @@ -404,6 +404,17 @@ impl TcpEchoClient {
}
}

//======================================================================================================================
// Standalone functions
//======================================================================================================================

fn is_closed(ret: i64) -> bool {
match ret as i32 {
libc::ECONNRESET | libc::ENOTCONN | libc::ECANCELED | libc::EBADF => true,
_ => false,
}
}

//======================================================================================================================
// Trait Implementations
//======================================================================================================================
Expand Down
24 changes: 12 additions & 12 deletions examples/tcp-echo/server.rs
Original file line number Diff line number Diff line change
Expand Up @@ -172,18 +172,7 @@ impl TcpEchoServer {
let errno: i64 = qr.qr_ret;

// Check if client has reset the connection.
if errno == libc::ECONNRESET as i64 || errno == libc::ECANCELED as i64 || errno == libc::EBADF as i64 {
if errno == libc::ECONNRESET as i64 {
println!("INFO: client reset connection (qd={:?})", qd);
}
if errno == libc::EBADF as i64 {
println!("INFO: client terminated connection (qd={:?})", qd);
} else {
println!(
"INFO: operation cancelled, resetting connection (qd={:?}, qt={:?})",
qd, qt
);
}
if is_closed(errno) {
self.handle_close(qd)?;
} else {
println!(
Expand Down Expand Up @@ -275,6 +264,17 @@ impl TcpEchoServer {
}
}

//======================================================================================================================
// Standalone functions
//======================================================================================================================

fn is_closed(ret: i64) -> bool {
match ret as i32 {
libc::ECONNRESET | libc::ENOTCONN | libc::ECANCELED | libc::EBADF => true,
_ => false,
}
}

//======================================================================================================================
// Trait Implementations
//======================================================================================================================
Expand Down
14 changes: 12 additions & 2 deletions examples/tcp-wait/client.rs
Original file line number Diff line number Diff line change
Expand Up @@ -249,8 +249,7 @@ impl TcpClient {
anyhow::bail!("pop() should not sucessfully receive any data");
}
},
Ok(qr) if qr.qr_opcode == demi_opcode_t::DEMI_OPC_FAILED && qr.qr_ret == libc::ECANCELED as i64 => {},
Ok(qr) if qr.qr_opcode == demi_opcode_t::DEMI_OPC_FAILED && qr.qr_ret == libc::EBADF as i64 => {},
Ok(qr) if qr.qr_opcode == demi_opcode_t::DEMI_OPC_FAILED && is_closed(qr.qr_ret) => {},
Ok(_) => anyhow::bail!("wait() should not succeed with pop() after close()"),
Err(_) => anyhow::bail!("wait() should not fail"),
}
Expand Down Expand Up @@ -311,6 +310,17 @@ impl TcpClient {
}
}

//======================================================================================================================
// Standalone functions
//======================================================================================================================

fn is_closed(ret: i64) -> bool {
match ret as i32 {
libc::ECONNRESET | libc::ENOTCONN | libc::ECANCELED | libc::EBADF => true,
_ => false,
}
}

//======================================================================================================================
// Trait Implementations
//======================================================================================================================
Expand Down
13 changes: 12 additions & 1 deletion examples/tcp-wait/server.rs
Original file line number Diff line number Diff line change
Expand Up @@ -140,7 +140,7 @@ impl TcpServer {
"client should not have any pending operations, but it has"
);
},
demi_opcode_t::DEMI_OPC_FAILED if qr.qr_ret == libc::ECONNRESET as i64 => {
demi_opcode_t::DEMI_OPC_FAILED if is_closed(qr.qr_ret) => {
let qd: QDesc = qr.qr_qd.into();
let _: Vec<QToken> = self.terminate_connection(qd)?;
},
Expand Down Expand Up @@ -233,6 +233,17 @@ impl TcpServer {
}
}

//======================================================================================================================
// Standalone functions
//======================================================================================================================

fn is_closed(ret: i64) -> bool {
match ret as i32 {
libc::ECONNRESET | libc::ENOTCONN | libc::ECANCELED | libc::EBADF => true,
_ => false,
}
}

//======================================================================================================================
// Trait Implementations
//======================================================================================================================
Expand Down
1 change: 1 addition & 0 deletions tests/rust/tcp-test/accept/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -171,6 +171,7 @@ fn accept_connecting_socket(libos: &mut LibOS, remote: &SocketAddr) -> Result<()
match libos.wait(qt, Some(Duration::from_micros(0))) {
Ok(qr) if qr.qr_opcode == demi_opcode_t::DEMI_OPC_FAILED && qr.qr_ret == libc::ECANCELED as i64 => {},
Ok(qr) if qr.qr_opcode == demi_opcode_t::DEMI_OPC_FAILED && qr.qr_ret == libc::ECONNREFUSED as i64 => {},
Ok(qr) if qr.qr_opcode == demi_opcode_t::DEMI_OPC_FAILED && qr.qr_ret == libc::ECONNABORTED as i64 => {},
// If connect() completes successfully, something has gone wrong.
Ok(qr) if qr.qr_opcode == demi_opcode_t::DEMI_OPC_CONNECT && qr.qr_ret == 0 => {
anyhow::bail!("connect() should not succeed because remote does not exist")
Expand Down
1 change: 1 addition & 0 deletions tests/rust/tcp-test/connect/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -134,6 +134,7 @@ fn connect_to_bad_remote(libos: &mut LibOS) -> Result<()> {
// Poll for enough time to get the connection refused.
match libos.wait(qt, Some(Duration::from_secs(75))) {
Ok(qr) if qr.qr_ret == libc::ECONNREFUSED as i64 => {},
Ok(qr) if qr.qr_ret == libc::ECONNABORTED as i64 => {},
// If completes successfully, something has gone wrong.
Ok(qr) if qr.qr_opcode == demi_opcode_t::DEMI_OPC_CONNECT && qr.qr_ret == 0 => {
anyhow::bail!("connect() should not succeed because remote does not exist")
Expand Down
1 change: 1 addition & 0 deletions tests/rust/tcp-test/wait/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -224,6 +224,7 @@ fn wait_after_async_close_connecting_socket(libos: &mut LibOS, remote: &SocketAd
Ok(qr) if qr.qr_opcode == demi_opcode_t::DEMI_OPC_FAILED && qr.qr_ret == libc::ECONNREFUSED as i64 => {},
Ok(qr) if qr.qr_opcode == demi_opcode_t::DEMI_OPC_FAILED && qr.qr_ret == libc::ECANCELED as i64 => {},
Ok(qr) if qr.qr_opcode == demi_opcode_t::DEMI_OPC_FAILED && qr.qr_ret == libc::EBADF as i64 => {},
Ok(qr) if qr.qr_opcode == demi_opcode_t::DEMI_OPC_FAILED && qr.qr_ret == libc::ECONNABORTED as i64 => {},
// If connect() completes successfully, something has gone wrong.
Ok(qr) if qr.qr_opcode == demi_opcode_t::DEMI_OPC_CONNECT && qr.qr_ret == 0 => {
anyhow::bail!("connect() should not succeed because remote does not exist")
Expand Down

0 comments on commit 1176ac8

Please sign in to comment.