From de17bd9853d3ea2620e4a290ef1efe770085ef4f Mon Sep 17 00:00:00 2001 From: Stefan Lankes Date: Tue, 13 Feb 2024 18:52:06 +0100 Subject: [PATCH 1/3] add CI tests for MIO --- .github/workflows/ci.yml | 14 +++++++++++++- xtask/src/ci/qemu.rs | 35 ++++++++++++++++++++++++++++++++++- 2 files changed, 47 insertions(+), 2 deletions(-) diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index c3d0453135..93b04d6863 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -126,7 +126,7 @@ jobs: strategy: matrix: arch: [x86_64, aarch64, riscv64] - package: [rusty_demo, httpd, testudp, hello_world] + package: [rusty_demo, httpd, testudp, hello_world, miotcp, mioudp] netdev: [none, virtio-net-pci, rtl8139] profile: [dev, release] smp: [1, 4] @@ -135,6 +135,10 @@ jobs: package: httpd - arch: riscv64 package: testudp + - arch: riscv64 + package: mioudp + - arch: riscv64 + package: miotcp # microvm (Firecracker) test does not run on aarch64 or riscv64 - package: hello_world arch: aarch64 @@ -163,6 +167,10 @@ jobs: netdev: none - package: testudp netdev: none + - package: miotcp + netdev: none + - package: mioudp + netdev: none include: - arch: x86_64 packages: qemu-system-x86 libcap-ng-dev libseccomp-dev socat @@ -182,6 +190,10 @@ jobs: flags: --features ci,dhcpv4 - package: testudp flags: --features udp,dhcpv4 + - package: miotcp + flags: --features dhcpv4 + - package: mioudp + flags: --features udp,dhcpv4 - package: hello_world flags: --no-default-features --microvm diff --git a/xtask/src/ci/qemu.rs b/xtask/src/ci/qemu.rs index 0962112129..0b3175d081 100644 --- a/xtask/src/ci/qemu.rs +++ b/xtask/src/ci/qemu.rs @@ -1,4 +1,5 @@ -use std::net::UdpSocket; +use std::io::{Read, Write}; +use std::net::{TcpStream, UdpSocket}; use std::process::{Child, Command, ExitStatus}; use std::time::Duration; use std::{env, thread}; @@ -90,6 +91,8 @@ impl Qemu { match self.build.package.as_str() { "httpd" => test_httpd()?, "testudp" => test_testudp()?, + "miotcp" => test_miotcp()?, + "mioudp" => test_mioudp()?, _ => {} } @@ -279,6 +282,36 @@ fn test_testudp() -> Result<()> { let socket = UdpSocket::bind("127.0.0.1:0")?; socket.connect("127.0.0.1:9975")?; socket.send(buf.as_bytes())?; + + let mut buf = [0; 128]; + socket.recv(&mut buf)?; + eprintln!("[CI] receive: {buf:?}"); + + Ok(()) +} + +fn test_miotcp() -> Result<()> { + thread::sleep(Duration::from_secs(10)); + let buf = "exit"; + eprintln!("[CI] send {buf:?} via TCP to 127.0.0.1:9975"); + let mut stream = TcpStream::connect("127.0.0.1:9975")?; + stream.write_all(buf.as_bytes())?; + + let mut buf = vec![]; + stream.read_to_end(&mut buf)?; + eprintln!("[CI] receive: {buf:?}"); + + Ok(()) +} + +fn test_mioudp() -> Result<()> { + thread::sleep(Duration::from_secs(10)); + let buf = "exit"; + eprintln!("[CI] send {buf:?} via UDP to 127.0.0.1:9975"); + let socket = UdpSocket::bind("127.0.0.1:0")?; + socket.connect("127.0.0.1:9975")?; + socket.send(buf.as_bytes())?; + Ok(()) } From 3e5d957e801e61a485a849f9c25de08d02dd9b81 Mon Sep 17 00:00:00 2001 From: Stefan Lankes Date: Wed, 14 Feb 2024 07:29:32 +0100 Subject: [PATCH 2/3] convert received message to string improves the out messages of the CI tests --- xtask/src/ci/qemu.rs | 9 +++++---- 1 file changed, 5 insertions(+), 4 deletions(-) diff --git a/xtask/src/ci/qemu.rs b/xtask/src/ci/qemu.rs index 0b3175d081..5d77328f05 100644 --- a/xtask/src/ci/qemu.rs +++ b/xtask/src/ci/qemu.rs @@ -1,6 +1,7 @@ use std::io::{Read, Write}; use std::net::{TcpStream, UdpSocket}; use std::process::{Child, Command, ExitStatus}; +use std::str::from_utf8; use std::time::Duration; use std::{env, thread}; @@ -284,8 +285,8 @@ fn test_testudp() -> Result<()> { socket.send(buf.as_bytes())?; let mut buf = [0; 128]; - socket.recv(&mut buf)?; - eprintln!("[CI] receive: {buf:?}"); + let received = socket.recv(&mut buf)?; + eprintln!("[CI] receive: {}", from_utf8(&buf[..received])?); Ok(()) } @@ -298,8 +299,8 @@ fn test_miotcp() -> Result<()> { stream.write_all(buf.as_bytes())?; let mut buf = vec![]; - stream.read_to_end(&mut buf)?; - eprintln!("[CI] receive: {buf:?}"); + let received = stream.read_to_end(&mut buf)?; + eprintln!("[CI] receive: {}", from_utf8(&buf[..received])?); Ok(()) } From 6e2888ca48a370d6e58d449318c4624fea4642c4 Mon Sep 17 00:00:00 2001 From: Stefan Lankes Date: Wed, 14 Feb 2024 10:46:57 +0100 Subject: [PATCH 3/3] add check, if mioudp returns a valid string --- xtask/src/ci/qemu.rs | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/xtask/src/ci/qemu.rs b/xtask/src/ci/qemu.rs index 5d77328f05..8c774bf531 100644 --- a/xtask/src/ci/qemu.rs +++ b/xtask/src/ci/qemu.rs @@ -284,10 +284,6 @@ fn test_testudp() -> Result<()> { socket.connect("127.0.0.1:9975")?; socket.send(buf.as_bytes())?; - let mut buf = [0; 128]; - let received = socket.recv(&mut buf)?; - eprintln!("[CI] receive: {}", from_utf8(&buf[..received])?); - Ok(()) } @@ -313,6 +309,10 @@ fn test_mioudp() -> Result<()> { socket.connect("127.0.0.1:9975")?; socket.send(buf.as_bytes())?; + let mut buf = [0; 128]; + let received = socket.recv(&mut buf)?; + eprintln!("[CI] receive: {}", from_utf8(&buf[..received])?); + Ok(()) }