Skip to content
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
2 changes: 2 additions & 0 deletions bincompat-django6.0-python3.12/.gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
/__pycache__/
/workdir/
48 changes: 48 additions & 0 deletions bincompat-django6.0-python3.12/.scripts/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,48 @@
# Scripts for Bincompat Django 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-django6.0-python3.12/.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
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
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-django6.0-python3.12/.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-django6.0-python3.12/.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/
117 changes: 117 additions & 0 deletions bincompat-django6.0-python3.12/.scripts/common.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,117 @@
#!/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
}

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"
20 changes: 20 additions & 0 deletions bincompat-django6.0-python3.12/.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-django6.0-python3.12/.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:\" ] -- /usr/local/bin/python3 /app/server.py" \
-kernel "$base_kernel" \
-initrd ./initrd.cpio
1 change: 1 addition & 0 deletions bincompat-django6.0-python3.12/.scripts/test/.gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
/log/
14 changes: 14 additions & 0 deletions bincompat-django6.0-python3.12/.scripts/test/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
# Testing Django-Python 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-django6.0-python3.12/.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
Loading