Skip to content

Commit 21ff605

Browse files
committed
Testing incoming connections
1 parent c502e1f commit 21ff605

File tree

8 files changed

+55
-2
lines changed

8 files changed

+55
-2
lines changed

Cargo.lock

Lines changed: 4 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

Cargo.toml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@ members = [
33
"fortanix-vme/fortanix-vme-abi",
44
"fortanix-vme/fortanix-vme-runner",
55
"fortanix-vme/tests/outgoing_connection",
6+
"fortanix-vme/tests/incoming_connection",
67
"intel-sgx/aesm-client",
78
"intel-sgx/dcap-provider",
89
"intel-sgx/dcap-ql-sys",

fortanix-vme/ci-common.sh

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -100,7 +100,6 @@ function cargo_test {
100100
echo "Success"
101101
fi
102102
else
103-
${elf} -- --nocapture
104103
${elf} -- --nocapture > ${out} 2> ${err}
105104

106105
out=$(cat ${out} | grep -v "#" || true)

fortanix-vme/ci-fortanixvme.sh

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@ source ./ci-common.sh
66

77
function cleanup {
88
stop_runner
9+
killall test_interaction
910
}
1011

1112
function setup_environment {
@@ -50,7 +51,7 @@ function run_tests {
5051
fi
5152
}
5253

53-
run_tests outgoing_connection
54+
run_tests outgoing_connection incoming_connection
5455

5556
echo "********************************"
5657
echo "** All tests succeeded! **"
Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
[package]
2+
name = "incoming_connection"
3+
version = "0.1.0"
4+
edition = "2021"
5+
6+
# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html
7+
8+
[dependencies]
Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
Bind to socket to 3400
2+
Listening for incoming connections...
3+
Waiting for connection 1
4+
Connection 1: Connected
5+
Waiting for connection 2
6+
Connection 2: Connected
Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
use std::net::{Shutdown, TcpListener};
2+
use std::io::{Read, Write};
3+
4+
fn main() {
5+
println!("Bind to socket to 3400");
6+
let listener = TcpListener::bind("127.0.0.1:3400").expect("Bind failed");
7+
// println!("# Listening on: {}", listener.local_addr().unwrap().port());
8+
9+
println!("Listening for incoming connections...");
10+
for id in 1..3 {
11+
println!("Waiting for connection {}", id);
12+
match listener.accept() {
13+
Ok((mut stream, addr)) => {
14+
println!("# addr = {:?}", addr);
15+
println!("Connection {}: Connected", id);
16+
let mut buff_in = [0u8; 4192];
17+
let n = stream.read(&mut buff_in).unwrap();
18+
println!("# read: {} bytes", n);
19+
let out = "HTTP/1.0 200 OK\r\nContent-Type: text/html; charset=ISO-8859-1\r\n\r\n<html><body>Hello World!</body></html>\r\n";
20+
stream.write(out.as_bytes()).unwrap();
21+
stream.shutdown(Shutdown::Both).unwrap();
22+
},
23+
Err(e) => println!("Connection {}: Accept failed: {:?}", id, e),
24+
}
25+
}
26+
}
Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
#!/bin/bash -ex
2+
3+
while [ true ]
4+
do
5+
echo "Interacting with test"
6+
timeout 1s curl -k localhost:3400 || true
7+
sleep 20s
8+
done

0 commit comments

Comments
 (0)