Skip to content

Commit

Permalink
WIP Added Network test
Browse files Browse the repository at this point in the history
  • Loading branch information
jounathaen committed Mar 20, 2024
1 parent abe8633 commit 45f5778
Show file tree
Hide file tree
Showing 4 changed files with 53 additions and 3 deletions.
15 changes: 15 additions & 0 deletions tests/network-test.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
mod common;

use std::{
fs::{read, remove_file},
path::PathBuf,
};

use common::{build_hermit_bin, run_simple_vm};

#[test]
fn network_test() {
let bin_path = build_hermit_bin("network_test");
run_simple_vm(bin_path);
panic!();
}
4 changes: 2 additions & 2 deletions tests/test-kernels/Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion tests/test-kernels/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -6,4 +6,4 @@ edition = "2021"
publish = false

[target.'cfg(target_os = "hermit")'.dependencies]
hermit = "0.8"
hermit = {version="0.8.2", features=["pci", "pci-ids", "acpi", "tcp", "udp"] }
35 changes: 35 additions & 0 deletions tests/test-kernels/src/bin/network_test.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
#![allow(dead_code)]
#![allow(unused_imports)]

use std::{
fs::File,
io::{Error, Read},
net::{Ipv4Addr, SocketAddrV4, TcpListener},
};

#[cfg(target_os = "hermit")]
use hermit as _;

fn main() -> Result<(), Error> {
println!("Network Test - ");
// let loopback = Ipv4Addr::new(10, 8, 8, 11);
// println!("1");
// let socket = SocketAddrV4::new(loopback, 0);
// println!("2");
// let listener = TcpListener::bind(socket)?;
// println!("3");

let listener = TcpListener::bind("127.0.0.1:9975").unwrap();
let (mut socket, _) = listener.accept().unwrap();
let mut buf = [0u8; 1000];
println!("about to read");
match socket.read(&mut buf) {
Err(e) => {
println!("read err {e:?}");
}
Ok(received) => {
print!("read {}", std::str::from_utf8(&buf[..received]).unwrap());
}
}
Ok(())
}

0 comments on commit 45f5778

Please sign in to comment.