vsock: add handshake regression test

This patch has been cherry-picked from the Firecracker tree. The
reference commit is 6dbe8e021a64ba3742081741a7538cdfd93a102e.

Signed-off-by: Gabriel Ionescu <gbi@amazon.com>
Signed-off-by: Stefano Garzarella <sgarzare@redhat.com>
This commit is contained in:
Stefano Garzarella 2020-06-16 12:17:55 +02:00 committed by Sebastien Boeuf
parent 6ab4e247e6
commit bb3cf7c30c
2 changed files with 32 additions and 0 deletions

View File

@ -764,6 +764,16 @@ mod tests {
}
}
impl<S> VsockConnection<S>
where
S: Read + Write + AsRawFd,
{
/// Get the fwd_cnt value from the connection.
pub(crate) fn fwd_cnt(&self) -> Wrapping<u32> {
self.fwd_cnt
}
}
fn init_pkt(pkt: &mut VsockPacket, op: u16, len: u32) -> &mut VsockPacket {
for b in pkt.hdr_mut() {
*b = 0;

View File

@ -1356,4 +1356,26 @@ mod tests {
assert!(!ctx.muxer.has_pending_rx());
}
#[test]
fn test_regression_handshake() {
// Address one of the issues found while fixing the following issue:
// https://github.com/firecracker-microvm/firecracker/issues/1751
// This test checks that the handshake message is not accounted for
let mut ctx = MuxerTestContext::new("regression_handshake");
let peer_port = 1025;
// Create a local connection.
let (_, local_port) = ctx.local_connect(peer_port);
// Get the connection from the connection map.
let key = ConnMapKey {
local_port,
peer_port,
};
let conn = ctx.muxer.conn_map.get_mut(&key).unwrap();
// Check that fwd_cnt is 0 - "OK ..." was not accounted for.
assert_eq!(conn.fwd_cnt().0, 0);
}
}