Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

elfloader-net: Add test scripts #16

Open
wants to merge 1 commit into
base: test
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
29 changes: 29 additions & 0 deletions elfloader-net/test.all.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
#!/bin/sh

test_build()
{
printf "%-46s ... " build."$1"
./build."$1" > log.build."$1" 2>&1
if test $? -eq 0; then
echo "PASSED"
else
echo "FAILED"
fi
}

test_build_run()
{
printf "%-46s ... " build."$1"
./build."$1" > log.build."$1" 2>&1
if test $? -eq 0; then
echo "PASSED"
else
echo "FAILED"
fi

printf " %-42s ... " run."$1"
./test.wrapper.sh ./run."$1" 2> log.run."$1"
}

test_build_run qemu.x86_64
test_build_run fc.x86_64
134 changes: 134 additions & 0 deletions elfloader-net/test.common.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,134 @@
#!/bin/bash

if test -z "$log_file"; then
log_file="/dev/null"
fi

clean_up()
{
{
# Clean up any previous instances.
sudo pkill -9 qemu-system
sudo pkill -9 firecracker
kraft stop --all
kraft rm --all
sudo kraft stop --all
sudo kraft rm --all

# Remove previously created network interfaces.
sudo ip link set dev tap0 down
sudo ip link del dev tap0
sudo ip link set dev virbr0 down
sudo ip link del dev virbr0
} > /dev/null 2>&1
}

start_instance()
{
# Start instance.
setsid --fork "$start_command" 1>&2 &
if test $? -ne 0; then
echo "Cannot start instance" 1>&2
echo "FAILED"
clean_up
exit 1
fi
}

test_ping()
{
host="$1"

# Connect to instance.
ping -c 1 "$host" 1>&2
if test $? -ne 0; then
echo "Cannot ping $host" 1>&2
echo "FAILED"
clean_up
exit 1
fi
}

test_curl_connect()
{
host="$1"
port="$2"

# Query instance.
curl --retry 1 --connect-timeout 1 --max-time 10 "$host":"$port" 1>&2
if test $? -ne 0; then
echo "Cannot connect to $host:$port" 1>&2
echo "FAILED"
clean_up
exit 1
fi
}

test_curl_check_reply()
{
host="$1"
port="$2"
message="$3"

# Check server message contents.
curl --retry 1 --connect-timeout 1 --max-time 10 "$host":"$port" | grep "$message" 1>&2
if test $? -ne 0; then
echo "Wrong message from $host:$port" 1>&2
echo "FAILED"
clean_up
exit 1
fi
}

test_netcat_connect()
{
host="$1"
port="$2"

# Check connection.
netcat -w 3 "$host" "$port" < /dev/null 1>&2
if test $? -ne 0; then
echo "Cannot connect to $host:$port" 1>&2
echo "FAILED"
clean_up
exit 1
fi
}

test_redis_connect()
{
host="$1"
port="$2"

redis-cli -h "$host" -p "$port" < /dev/null 1>&2
if test $? -ne 0; then
echo "Cannot connect client to Redis server at $host:$port" 1>&2
echo "FAILED"
clean_up
exit 1
fi
}

test_redis_cli()
{
host="$1"
port="$2"

redis-cli -h "$host" -p "$port" set a 1 1>&2
redis-cli -h "$host" -p "$port" get a 1>&2
if test $? -eq 1; then
echo "FAILED"
echo "Cannot talk to Redis server at $host:$port" 1>&2
clean_up
exit 1
fi
}

end_with_success()
{
echo "PASSED"
clean_up
exit 0
}

start_command="$1"
31 changes: 31 additions & 0 deletions elfloader-net/test.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
#!/bin/sh

. ./test.common.sh

default_host=172.44.0.2
default_port=8080

if test $# -eq 0; then
echo "Host and port unspecified." 1>&2
host="$default_host"
port="$default_port"
elif test $# -eq 2; then
host="$1"
port="$2"
else
echo "Unknown arguments." 1>&2
echo "Usage: $0 [<hostname> <port>]" 1>&2
exit 1
fi
echo "Using as remote $host:$port" 1>&2

# Query non-localhost (NAT networking) instance.
if test ! "$host" = "localhost" -a ! "$host" = "127.0.0.1"; then
test_ping "$host"
fi

# Connect via HTTP.
test_curl_connect "$host" "$port"

# Connect via HTTP and check reply.
test_curl_check_reply "$host" "$port" "Hello from Unikraft!"
37 changes: 37 additions & 0 deletions elfloader-net/test.wrapper.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
#!/bin/sh

. ./test.common.sh

default_host=172.44.0.2
default_port=8080

if test $# -eq 1; then
echo "Host and port unspecified." 1>&2
host="$default_host"
port="$default_port"
elif test $# -eq 3; then
host="$2"
port="$3"
else
echo "Unknown arguments." 1>&2
echo "Usage: $0 <start_command> [<hostname> <port>]" 1>&2
exit 1
fi
echo "Using as remote $host:$port" 1>&2

# Clean up previous instances.
clean_up

# Start instance.
start_instance

# Wait for start.
sleep 3

./test.sh
if test $? -ne 0; then
exit 1
fi

# Stop instance.
end_with_success