From d9ba8149a9dce1e0e01e043b291c3b6d7cd97420 Mon Sep 17 00:00:00 2001 From: Linwei Shang Date: Tue, 28 Nov 2023 23:17:40 +0000 Subject: [PATCH 1/5] ci: turn on tcp in examples * the tests can terminate gracefully * fix a bug in x86_64 tcp module which was not covered in CI --- examples/riscv/Makefile | 2 +- examples/riscv/src/tcp.rs | 1 + examples/x86_64/Makefile | 2 +- examples/x86_64/src/tcp.rs | 4 ++-- 4 files changed, 5 insertions(+), 4 deletions(-) diff --git a/examples/riscv/Makefile b/examples/riscv/Makefile index debb82f5..02f23601 100644 --- a/examples/riscv/Makefile +++ b/examples/riscv/Makefile @@ -4,7 +4,7 @@ mode := release kernel := target/$(target)/$(mode)/riscv img := target/$(target)/$(mode)/img -tcp ?= off +tcp ?= on sysroot := $(shell rustc --print sysroot) objdump := $(shell find $(sysroot) -name llvm-objdump) --arch-name=$(arch) diff --git a/examples/riscv/src/tcp.rs b/examples/riscv/src/tcp.rs index 5f6623c3..920fb4b6 100644 --- a/examples/riscv/src/tcp.rs +++ b/examples/riscv/src/tcp.rs @@ -175,6 +175,7 @@ pub fn test_echo_server(dev: DeviceImpl) { } else if socket.may_send() { info!("tcp:{} close", PORT); socket.close(); + break; } } } diff --git a/examples/x86_64/Makefile b/examples/x86_64/Makefile index bad89bae..01db00d5 100644 --- a/examples/x86_64/Makefile +++ b/examples/x86_64/Makefile @@ -4,7 +4,7 @@ mode := release kernel := target/$(target)/$(mode)/$(arch) img := target/$(target)/$(mode)/img accel ?= on -tcp ?= off +tcp ?= on sysroot := $(shell rustc --print sysroot) objdump := $(shell find $(sysroot) -name llvm-objdump) --arch-name=$(arch) diff --git a/examples/x86_64/src/tcp.rs b/examples/x86_64/src/tcp.rs index 07c2c3f6..275497fe 100644 --- a/examples/x86_64/src/tcp.rs +++ b/examples/x86_64/src/tcp.rs @@ -92,8 +92,7 @@ impl TxToken for VirtioTxToken { let mut dev = self.0.borrow_mut(); let mut tx_buf = dev.new_tx_buffer(len); let result = f(tx_buf.packet_mut()); - trace!("SEND {} bytes: {:02X?}", len, tx_buf.packet()); - dev.transmit(tx_buf).unwrap(); + dev.send(tx_buf).unwrap(); result } } @@ -176,6 +175,7 @@ pub fn test_echo_server(dev: DeviceImpl) { } else if socket.may_send() { info!("tcp:{} close", PORT); socket.close(); + break; } } } From e811b364562bf3b4fc2e609aecc2bb07e80eba6b Mon Sep 17 00:00:00 2001 From: Linwei Shang Date: Tue, 28 Nov 2023 23:22:28 +0000 Subject: [PATCH 2/5] add back trace --- examples/x86_64/src/tcp.rs | 1 + 1 file changed, 1 insertion(+) diff --git a/examples/x86_64/src/tcp.rs b/examples/x86_64/src/tcp.rs index 275497fe..71b4a52f 100644 --- a/examples/x86_64/src/tcp.rs +++ b/examples/x86_64/src/tcp.rs @@ -92,6 +92,7 @@ impl TxToken for VirtioTxToken { let mut dev = self.0.borrow_mut(); let mut tx_buf = dev.new_tx_buffer(len); let result = f(tx_buf.packet_mut()); + trace!("SEND {} bytes: {:02X?}", len, tx_buf.packet()); dev.send(tx_buf).unwrap(); result } From 76c4955af4e5541b9448efd6de5cc48bf50d4e8e Mon Sep 17 00:00:00 2001 From: Linwei Shang Date: Wed, 29 Nov 2023 01:56:54 +0000 Subject: [PATCH 3/5] fix riscv example tcp --- examples/riscv/rust-toolchain | 2 +- examples/riscv/src/tcp.rs | 4 ++-- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/examples/riscv/rust-toolchain b/examples/riscv/rust-toolchain index 762dae8c..07ade694 100644 --- a/examples/riscv/rust-toolchain +++ b/examples/riscv/rust-toolchain @@ -1 +1 @@ -nightly-2022-11-03 \ No newline at end of file +nightly \ No newline at end of file diff --git a/examples/riscv/src/tcp.rs b/examples/riscv/src/tcp.rs index 920fb4b6..b4fe7552 100644 --- a/examples/riscv/src/tcp.rs +++ b/examples/riscv/src/tcp.rs @@ -9,7 +9,7 @@ use smoltcp::iface::{Config, Interface, SocketSet}; use smoltcp::phy::{Device, DeviceCapabilities, Medium, RxToken, TxToken}; use smoltcp::wire::{EthernetAddress, IpAddress, IpCidr, Ipv4Address}; use smoltcp::{socket::tcp, time::Instant}; -use virtio_drivers::device::net::{NetBuffer, VirtIONet}; +use virtio_drivers::device::net::{RxBuffer, VirtIONet}; use virtio_drivers::{transport::Transport, Error}; use super::{HalImpl, NET_QUEUE_SIZE}; @@ -64,7 +64,7 @@ impl Device for DeviceWrapper { } } -struct VirtioRxToken(Rc>>, NetBuffer); +struct VirtioRxToken(Rc>>, RxBuffer); struct VirtioTxToken(Rc>>); impl RxToken for VirtioRxToken { From 172b19bdde6ac98200024180b80c6f7f2aadc6ce Mon Sep 17 00:00:00 2001 From: Linwei Shang Date: Thu, 30 Nov 2023 16:45:42 +0000 Subject: [PATCH 4/5] chore: set toolchain in toml & simplify CI config --- .github/workflows/main.yml | 27 +++------------------------ examples/aarch64/rust-toolchain.toml | 5 +++++ examples/riscv/rust-toolchain | 1 - examples/riscv/rust-toolchain.toml | 5 +++++ examples/x86_64/rust-toolchain | 1 - examples/x86_64/rust-toolchain.toml | 5 +++++ rust-toolchain.toml | 4 ++++ 7 files changed, 22 insertions(+), 26 deletions(-) create mode 100644 examples/aarch64/rust-toolchain.toml delete mode 100644 examples/riscv/rust-toolchain create mode 100644 examples/riscv/rust-toolchain.toml delete mode 100644 examples/x86_64/rust-toolchain create mode 100644 examples/x86_64/rust-toolchain.toml create mode 100644 rust-toolchain.toml diff --git a/.github/workflows/main.yml b/.github/workflows/main.yml index b991d6b9..0cc90111 100644 --- a/.github/workflows/main.yml +++ b/.github/workflows/main.yml @@ -9,12 +9,7 @@ jobs: check: runs-on: ubuntu-latest steps: - - uses: actions/checkout@v2 - - uses: actions-rs/toolchain@v1 - with: - profile: minimal - toolchain: stable - components: rustfmt, clippy + - uses: actions/checkout@v4 - name: Check code format uses: actions-rs/cargo@v1 with: @@ -28,11 +23,7 @@ jobs: build: runs-on: ubuntu-latest steps: - - uses: actions/checkout@v2 - - uses: actions-rs/toolchain@v1 - with: - profile: minimal - toolchain: stable + - uses: actions/checkout@v4 - name: Build with no features uses: actions-rs/cargo@v1 with: @@ -69,27 +60,15 @@ jobs: - x86_64 include: - example: aarch64 - toolchain: stable - target: aarch64-unknown-none packages: qemu-system-arm gcc-aarch64-linux-gnu - example: riscv - toolchain: nightly-2022-11-03 - target: riscv64imac-unknown-none-elf packages: qemu-system-misc - example: x86_64 - toolchain: nightly - target: x86_64-unknown-none packages: qemu-system-x86 steps: - - uses: actions/checkout@v2 + - uses: actions/checkout@v4 - name: Install QEMU run: sudo apt update && sudo apt install ${{ matrix.packages }} && sudo chmod 666 /dev/vhost-vsock - - uses: actions-rs/toolchain@v1 - with: - profile: minimal - toolchain: ${{ matrix.toolchain }} - target: ${{ matrix.target }} - components: llvm-tools-preview, rustfmt - name: Check code format working-directory: examples/${{ matrix.example }} run: cargo fmt --all -- --check diff --git a/examples/aarch64/rust-toolchain.toml b/examples/aarch64/rust-toolchain.toml new file mode 100644 index 00000000..cccdca67 --- /dev/null +++ b/examples/aarch64/rust-toolchain.toml @@ -0,0 +1,5 @@ +[toolchain] +channel = "nightly" +components = ["rustfmt", "llvm-tools"] +targets = ["aarch64-unknown-none"] +profile = "minimal" diff --git a/examples/riscv/rust-toolchain b/examples/riscv/rust-toolchain deleted file mode 100644 index 07ade694..00000000 --- a/examples/riscv/rust-toolchain +++ /dev/null @@ -1 +0,0 @@ -nightly \ No newline at end of file diff --git a/examples/riscv/rust-toolchain.toml b/examples/riscv/rust-toolchain.toml new file mode 100644 index 00000000..b88b0979 --- /dev/null +++ b/examples/riscv/rust-toolchain.toml @@ -0,0 +1,5 @@ +[toolchain] +channel = "nightly" +components = ["rustfmt", "llvm-tools"] +targets = ["riscv64imac-unknown-none-elf"] +profile = "minimal" diff --git a/examples/x86_64/rust-toolchain b/examples/x86_64/rust-toolchain deleted file mode 100644 index bf867e0a..00000000 --- a/examples/x86_64/rust-toolchain +++ /dev/null @@ -1 +0,0 @@ -nightly diff --git a/examples/x86_64/rust-toolchain.toml b/examples/x86_64/rust-toolchain.toml new file mode 100644 index 00000000..8389052f --- /dev/null +++ b/examples/x86_64/rust-toolchain.toml @@ -0,0 +1,5 @@ +[toolchain] +channel = "nightly" +components = ["rustfmt", "llvm-tools"] +targets = ["x86_64-unknown-none"] +profile = "minimal" diff --git a/rust-toolchain.toml b/rust-toolchain.toml new file mode 100644 index 00000000..85f36062 --- /dev/null +++ b/rust-toolchain.toml @@ -0,0 +1,4 @@ +[toolchain] +channel = "stable" +components = ["rustfmt", "clippy"] +profile = "minimal" From a4b236f55d02faf8876715ff184a709ab19fe159 Mon Sep 17 00:00:00 2001 From: Linwei Shang Date: Thu, 30 Nov 2023 16:55:50 +0000 Subject: [PATCH 5/5] fix: stable for aarch --- examples/aarch64/rust-toolchain.toml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/examples/aarch64/rust-toolchain.toml b/examples/aarch64/rust-toolchain.toml index cccdca67..b041d83b 100644 --- a/examples/aarch64/rust-toolchain.toml +++ b/examples/aarch64/rust-toolchain.toml @@ -1,5 +1,5 @@ [toolchain] -channel = "nightly" +channel = "stable" components = ["rustfmt", "llvm-tools"] targets = ["aarch64-unknown-none"] profile = "minimal"