Skip to content

Commit 46766ac

Browse files
committed
python3.10-http-server: Add test scripts
Add scripts/test/ for python3.10-http-server/: - README.md: instructions to run the tests - common.sh: common functions and variables for test scripts - single.sh: test an instance started beforehand - wrapper.sh: wrapper over single.sh that also starts an instance - all.sh: test all configurations Signed-off-by: Arghir Elisa-Elena <arghirelisaelena@gmail.com>
1 parent f3beec1 commit 46766ac

File tree

6 files changed

+229
-0
lines changed

6 files changed

+229
-0
lines changed
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
/log/
Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,31 @@
1+
# Testing Python3.10 Http Server on Unikraft
2+
3+
These are companion instructions to the main instructions in the [`README`](../../README.md) and to the scripted run instructions in the [`scripts/README`](../README.md).
4+
Use these scripts to test Python3.10 Http Server on Unikraft.
5+
6+
**Note**: Run scripts from the application directory.
7+
8+
Use the `all.sh` script to test all builds and all available runs:
9+
10+
```console
11+
./scripts/test/all.sh
12+
```
13+
14+
The command prints out a summary of the passed or failed tests.
15+
16+
Logs are stored in the `./scripts/test/log/` directory.
17+
18+
Use the `single.sh` script to only run a query test for a running instance.
19+
That is, first run the instance, e.g:
20+
21+
```console
22+
./scripts/run/qemu.x86_64
23+
```
24+
25+
And then query it with the `single.sh` script:
26+
27+
```console
28+
./single.sh
29+
```
30+
31+
The command prints out the output of the commands that query the instance.
Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,36 @@
1+
#!/bin/sh
2+
3+
test_build()
4+
{
5+
printf "%-46s ... " build."$1"
6+
./scripts/build/"$1" > ./scripts/test/log/build."$1" 2>&1
7+
if test $? -eq 0; then
8+
echo "PASSED"
9+
else
10+
echo "FAILED"
11+
fi
12+
}
13+
14+
test_build_run()
15+
{
16+
printf "%-46s ... " build."$1"
17+
./scripts/build/"$1" > ./scripts/test/log/build."$1" 2>&1
18+
if test $? -eq 0; then
19+
echo "PASSED"
20+
else
21+
echo "FAILED"
22+
fi
23+
24+
printf " %-42s ... " run."$1"
25+
./scripts/test/wrapper.sh ./scripts/run/"$1" "$2" "$3" 2> ./scripts/test/log/run."$1"
26+
}
27+
28+
./setup.sh
29+
test -d ./scripts/test/log || mkdir ./scripts/test/log
30+
31+
test_build_run qemu.x86_64 127.0.0.1 8080
32+
test_build_run qemu.arm64 127.0.0.1 18080
33+
test_build_run fc.x86_64 172.44.0.2 8080
34+
test_build fc.arm64
35+
test_build xen.x86_64
36+
test_build xen.arm64
Lines changed: 105 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,105 @@
1+
#!/bin/bash
2+
3+
if test -z "$log_file"; then
4+
log_file="/dev/null"
5+
fi
6+
7+
clean_up()
8+
{
9+
{
10+
# Clean up any previous instances.
11+
sudo pkill -9 qemu-system
12+
sudo pkill -9 firecracker
13+
kraft stop --all
14+
kraft rm --all
15+
sudo kraft stop --all
16+
sudo kraft rm --all
17+
18+
# Remove previously created network interfaces.
19+
sudo ip link set dev tap0 down
20+
sudo ip link del dev tap0
21+
sudo ip link set dev virbr0 down
22+
sudo ip link del dev virbr0
23+
} > /dev/null 2>&1
24+
}
25+
26+
start_instance()
27+
{
28+
# Start instance.
29+
setsid --fork "$start_command" 1>&2 &
30+
if test $? -ne 0; then
31+
echo "Cannot start instance" 1>&2
32+
echo "FAILED"
33+
clean_up
34+
exit 1
35+
fi
36+
}
37+
38+
test_ping()
39+
{
40+
host="$1"
41+
42+
# Connect to instance.
43+
ping -c 1 "$host" 1>&2
44+
if test $? -ne 0; then
45+
echo "Cannot ping $host" 1>&2
46+
echo "FAILED"
47+
clean_up
48+
exit 1
49+
fi
50+
}
51+
52+
test_curl_connect()
53+
{
54+
host="$1"
55+
port="$2"
56+
57+
# Query instance.
58+
curl --retry 1 --connect-timeout 1 --max-time 10 "$host":"$port" 1>&2
59+
if test $? -ne 0; then
60+
echo "Cannot connect to $host:$port" 1>&2
61+
echo "FAILED"
62+
clean_up
63+
exit 1
64+
fi
65+
}
66+
67+
test_curl_check_reply()
68+
{
69+
host="$1"
70+
port="$2"
71+
message="$3"
72+
73+
# Check server message contents.
74+
curl --retry 1 --connect-timeout 1 --max-time 10 "$host":"$port" | grep "$message" 1>&2
75+
if test $? -ne 0; then
76+
echo "Wrong message from $host:$port" 1>&2
77+
echo "FAILED"
78+
clean_up
79+
exit 1
80+
fi
81+
}
82+
83+
test_netcat_connect()
84+
{
85+
host="$1"
86+
port="$2"
87+
88+
# Check connection.
89+
netcat -w 3 "$host" "$port" < /dev/null 1>&2
90+
if test $? -ne 0; then
91+
echo "Cannot connect to $host:$port" 1>&2
92+
echo "FAILED"
93+
clean_up
94+
exit 1
95+
fi
96+
}
97+
98+
end_with_success()
99+
{
100+
echo "PASSED"
101+
clean_up
102+
exit 0
103+
}
104+
105+
start_command="$1"
Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
#!/bin/bash
2+
3+
. ./scripts/test/common.sh
4+
5+
default_host=127.0.0.1
6+
default_port=8080
7+
8+
if test $# -eq 0; then
9+
host="$default_host"
10+
port="$default_port"
11+
elif test $# -eq 2; then
12+
host="$1"
13+
port="$2"
14+
else
15+
echo "Usage: $0 [<hostname> <port>]" 1>&2
16+
exit 1
17+
fi
18+
19+
echo "Using as remote $host:$port" 1>&2
20+
21+
test_curl_connect "$host" "$port"
22+
test_curl_check_reply "$host" "$port" "Directory listing"
23+
24+
end_with_success
Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,32 @@
1+
#!/bin/bash
2+
3+
. ./scripts/test/common.sh
4+
5+
default_host=127.0.0.1
6+
default_port=8080
7+
8+
if test $# -eq 1; then
9+
host="$default_host"
10+
port="$default_port"
11+
elif test $# -eq 3; then
12+
host="$2"
13+
port="$3"
14+
else
15+
echo "Usage: $0 <start_command> [<hostname> <port>]" 1>&2
16+
exit 1
17+
fi
18+
19+
echo "Using as remote $host:$port" 1>&2
20+
21+
clean_up
22+
start_instance
23+
sleep 10
24+
25+
./scripts/test/single.sh "$host" "$port"
26+
if test $? -ne 0; then
27+
echo "Test failed for $host:$port" 1>&2
28+
clean_up
29+
exit 1
30+
fi
31+
32+
end_with_success

0 commit comments

Comments
 (0)