Browse Source

Merge pull request #119 from lwshang/tcp_on

ci: turn on tcp feature in examples
Andrew Walbran 1 year ago
parent
commit
501d3594a5

+ 3 - 24
.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

+ 5 - 0
examples/aarch64/rust-toolchain.toml

@@ -0,0 +1,5 @@
+[toolchain]
+channel = "stable"
+components = ["rustfmt", "llvm-tools"]
+targets = ["aarch64-unknown-none"]
+profile = "minimal"

+ 1 - 1
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)

+ 0 - 1
examples/riscv/rust-toolchain

@@ -1 +0,0 @@
-nightly-2022-11-03

+ 5 - 0
examples/riscv/rust-toolchain.toml

@@ -0,0 +1,5 @@
+[toolchain]
+channel = "nightly"
+components = ["rustfmt", "llvm-tools"]
+targets = ["riscv64imac-unknown-none-elf"]
+profile = "minimal"

+ 3 - 2
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<T: Transport> Device for DeviceWrapper<T> {
     }
 }
 
-struct VirtioRxToken<T: Transport>(Rc<RefCell<DeviceImpl<T>>>, NetBuffer);
+struct VirtioRxToken<T: Transport>(Rc<RefCell<DeviceImpl<T>>>, RxBuffer);
 struct VirtioTxToken<T: Transport>(Rc<RefCell<DeviceImpl<T>>>);
 
 impl<T: Transport> RxToken for VirtioRxToken<T> {
@@ -175,6 +175,7 @@ pub fn test_echo_server<T: Transport>(dev: DeviceImpl<T>) {
         } else if socket.may_send() {
             info!("tcp:{} close", PORT);
             socket.close();
+            break;
         }
     }
 }

+ 1 - 1
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)

+ 0 - 1
examples/x86_64/rust-toolchain

@@ -1 +0,0 @@
-nightly

+ 5 - 0
examples/x86_64/rust-toolchain.toml

@@ -0,0 +1,5 @@
+[toolchain]
+channel = "nightly"
+components = ["rustfmt", "llvm-tools"]
+targets = ["x86_64-unknown-none"]
+profile = "minimal"

+ 2 - 1
examples/x86_64/src/tcp.rs

@@ -93,7 +93,7 @@ impl<T: Transport> TxToken for VirtioTxToken<T> {
         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 +176,7 @@ pub fn test_echo_server<T: Transport>(dev: DeviceImpl<T>) {
         } else if socket.may_send() {
             info!("tcp:{} close", PORT);
             socket.close();
+            break;
         }
     }
 }

+ 4 - 0
rust-toolchain.toml

@@ -0,0 +1,4 @@
+[toolchain]
+channel = "stable"
+components = ["rustfmt", "clippy"]
+profile = "minimal"