Skip to content
Draft
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
2 changes: 2 additions & 0 deletions bincompat-c-http/.gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
/workdir/
/initrd.cpio
48 changes: 48 additions & 0 deletions bincompat-c-http/.scripts/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,48 @@
# Scripts for Bincompat C HTTP server on Unikraft

These are companions instruction to the main instructions in the [`README`](README.md).

Use scripts as quick actions for building and running the bincompat C HTTP server on Unikraft:

**Note**: Run scripts from the application directory.

## Build for <plat> / <arch>:

```console
./.scripts/build/<plat>.<arch>
```

e.g.:

```console
./.scripts/build/qemu.x86_64
./.scripts/build/fc.x86_64
```

## Build for <plat> / <arch> using a different compiler

```console
CC=/path/to/compiler ./.scripts/build/<plat>.<arch>
```

e.g.

```console
CC=/usr/bin/gcc-12 ./.scripts/build/qemu.x86_64
CC=/usr/bin/clang ./.scripts/build/qemu.x86_64
CC=/usr/bin/gcc-12 ./.scripts/build/fc.x86_64
CC=/usr/bin/clang ./.scripts/build/fc.x86_64
```

## Run on <plat> / <arch>

```console
./.scripts/run/<plat>.<arch>
```

e.g.

```console
./.scripts/run/qemu.x86_64
./.scripts/run/fc.x86_64
```
4 changes: 4 additions & 0 deletions bincompat-c-http/.scripts/build/fc.x86_64
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
#!/bin/sh

./.scripts/build/rootfs.x86_64
./.scripts/build/kernel.fc.x86_64
4 changes: 4 additions & 0 deletions bincompat-c-http/.scripts/build/kernel.fc.x86_64
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
#!/bin/sh

. ./.scripts/common.sh
build_elfloader_base fc.x86_64
4 changes: 4 additions & 0 deletions bincompat-c-http/.scripts/build/kernel.qemu.x86_64
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
#!/bin/sh

. ./.scripts/common.sh
build_elfloader_base qemu.x86_64
4 changes: 4 additions & 0 deletions bincompat-c-http/.scripts/build/qemu.x86_64
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
#!/bin/sh

./.scripts/build/rootfs.x86_64
./.scripts/build/kernel.qemu.x86_64
6 changes: 6 additions & 0 deletions bincompat-c-http/.scripts/build/rootfs.x86_64
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
#!/bin/sh

rm -f initrd.cpio
make -C rootfs/ clean
make -C rootfs/
./workdir/unikraft/support/scripts/mkcpio initrd.cpio ./rootfs/
19 changes: 19 additions & 0 deletions bincompat-c-http/.scripts/common.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
#!/bin/sh

elfloader_base="elfloader-net"

if ! test -d workdir; then
mkdir workdir
fi

ln -sfn "../../$elfloader_base/workdir" workdir/base

build_elfloader_base()
{
(
cd "../$elfloader_base" &&
./setup.sh &&
make distclean &&
"./.scripts/build/$1"
) || exit 1
}
20 changes: 20 additions & 0 deletions bincompat-c-http/.scripts/run/fc.x86_64
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
#!/bin/sh

if test ! -f initrd.cpio; then
echo "No initrd.cpio file found." 1>&2
echo "Did you run the build script?" 1>&2
exit 1
fi

base_kernel="workdir/base/build/elfloader_fc-x86_64"
if test ! -f "$base_kernel"; then
echo "No kernel file $base_kernel." 1>&2
echo "Did you run the build script?" 1>&2
exit 1
fi

rm -f firecracker.socket

firecracker-x86_64 \
--api-sock firecracker.socket \
--config-file fc.x86_64.json
36 changes: 36 additions & 0 deletions bincompat-c-http/.scripts/run/qemu.x86_64
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
#!/bin/sh

if test ! -f initrd.cpio; then
echo "No initrd.cpio file found." 1>&2
echo "Did you run the build script?" 1>&2
exit 1
fi

base_kernel="workdir/base/build/elfloader_qemu-x86_64"
if test ! -f "$base_kernel"; then
echo "No kernel file $base_kernel." 1>&2
echo "Did you run the build script?" 1>&2
exit 1
fi

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

# Create bridge interface for QEMU networking.
sudo ip link add dev virbr0 type bridge
sudo ip address add 172.44.0.1/24 dev virbr0
sudo ip link set dev virbr0 up

sudo qemu-system-x86_64 \
-nographic \
-m 64 \
-cpu max \
-netdev bridge,id=en0,br=virbr0 -device virtio-net-pci,netdev=en0 \
-append "elfloader_qemu-x86_64 netdev.ip=172.44.0.2/24:172.44.0.1::: vfs.fstab=[ \"initrd0:/:extract::ramfs=1:\" ] -- /http_server" \
-kernel "$base_kernel" \
-initrd ./initrd.cpio
1 change: 1 addition & 0 deletions bincompat-c-http/.scripts/test/.gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
/log/
14 changes: 14 additions & 0 deletions bincompat-c-http/.scripts/test/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
# Testing C Hello on Unikraft

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).
Use these scripts to test C Hello on Unikraft.

**Note**: Run scripts from the application directory.

Use the `all.sh` script to test all builds and all available runs:

```console
./.scripts/test/all.sh
```

Logs are stored in the `./.scripts/test/log/` directory.
31 changes: 31 additions & 0 deletions bincompat-c-http/.scripts/test/all.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
#!/bin/sh

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

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

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

./setup.sh
test -d ./.scripts/test/log || mkdir ./.scripts/test/log
test_build_run qemu.x86_64
test_build_run fc.x86_64
134 changes: 134 additions & 0 deletions bincompat-c-http/.scripts/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"
24 changes: 24 additions & 0 deletions bincompat-c-http/.scripts/test/wrapper.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
#!/bin/sh

. ./.scripts/test/common.sh

if test $# -ne 1; then
echo "Unknown arguments." 1>&2
echo "Usage: $0 <start_command>" 1>&2
exit 1
fi

# Clean up previous instances.
clean_up

# Start instance.
start_instance 2>&1 | grep "Hello from Unikraft!" 1>&2
if test $? -ne 0; then
echo "Wrong message printed." 1>&2
echo "FAILED"
clean_up
exit 1
fi

# Stop instance.
end_with_success
Loading