From 6c4a482a0931ed1966e4ed85c8b5eaa10d396460 Mon Sep 17 00:00:00 2001 From: Andrei Popovici Date: Sat, 18 Oct 2025 11:53:51 +0300 Subject: [PATCH 1/3] Introduce c-bye program Signed-off-by: Andrei Popovici --- c-bye/.gitignore | 1 + c-bye/Makefile | 13 ++ c-bye/Makefile.uk | 3 + c-bye/README.md | 259 ++++++++++++++++++++++++++++++++++++ c-bye/README.scripts.md | 54 ++++++++ c-bye/build.fc.arm64 | 13 ++ c-bye/build.fc.x86_64 | 13 ++ c-bye/build.qemu.arm64 | 13 ++ c-bye/build.qemu.x86_64 | 13 ++ c-bye/build.xen.arm64 | 13 ++ c-bye/build.xen.x86_64 | 13 ++ c-bye/bye.c | 8 ++ c-bye/defconfig.fc.arm64 | 6 + c-bye/defconfig.fc.x86_64 | 3 + c-bye/defconfig.qemu.arm64 | 6 + c-bye/defconfig.qemu.x86_64 | 3 + c-bye/defconfig.xen.arm64 | 5 + c-bye/defconfig.xen.x86_64 | 2 + c-bye/fc.arm64.json | 12 ++ c-bye/fc.x86_64.json | 12 ++ c-bye/run.fc.arm64 | 12 ++ c-bye/run.fc.x86_64 | 12 ++ c-bye/run.qemu.arm64 | 14 ++ c-bye/run.qemu.x86_64 | 13 ++ c-bye/run.xen.arm64 | 9 ++ c-bye/run.xen.x86_64 | 9 ++ c-bye/test.all.sh | 33 +++++ c-bye/test.common.sh | 134 +++++++++++++++++++ c-bye/test.sh | 4 + c-bye/test.wrapper.sh | 24 ++++ c-bye/xen.arm64.cfg | 5 + c-bye/xen.x86_64.cfg | 5 + 32 files changed, 739 insertions(+) create mode 100644 c-bye/.gitignore create mode 100644 c-bye/Makefile create mode 100644 c-bye/Makefile.uk create mode 100644 c-bye/README.md create mode 100644 c-bye/README.scripts.md create mode 100755 c-bye/build.fc.arm64 create mode 100755 c-bye/build.fc.x86_64 create mode 100755 c-bye/build.qemu.arm64 create mode 100755 c-bye/build.qemu.x86_64 create mode 100755 c-bye/build.xen.arm64 create mode 100755 c-bye/build.xen.x86_64 create mode 100644 c-bye/bye.c create mode 100644 c-bye/defconfig.fc.arm64 create mode 100644 c-bye/defconfig.fc.x86_64 create mode 100644 c-bye/defconfig.qemu.arm64 create mode 100644 c-bye/defconfig.qemu.x86_64 create mode 100644 c-bye/defconfig.xen.arm64 create mode 100644 c-bye/defconfig.xen.x86_64 create mode 100644 c-bye/fc.arm64.json create mode 100644 c-bye/fc.x86_64.json create mode 100755 c-bye/run.fc.arm64 create mode 100755 c-bye/run.fc.x86_64 create mode 100755 c-bye/run.qemu.arm64 create mode 100755 c-bye/run.qemu.x86_64 create mode 100755 c-bye/run.xen.arm64 create mode 100755 c-bye/run.xen.x86_64 create mode 100755 c-bye/test.all.sh create mode 100644 c-bye/test.common.sh create mode 100755 c-bye/test.sh create mode 100755 c-bye/test.wrapper.sh create mode 100644 c-bye/xen.arm64.cfg create mode 100644 c-bye/xen.x86_64.cfg diff --git a/c-bye/.gitignore b/c-bye/.gitignore new file mode 100644 index 00000000..6a3417b8 --- /dev/null +++ b/c-bye/.gitignore @@ -0,0 +1 @@ +/out/ diff --git a/c-bye/Makefile b/c-bye/Makefile new file mode 100644 index 00000000..5fb0c984 --- /dev/null +++ b/c-bye/Makefile @@ -0,0 +1,13 @@ +UK_ROOT ?= $(PWD)/../repos/unikraft +UK_BUILD ?= $(PWD)/out +UK_APP ?= $(PWD) +LIBS_BASE = $(PWD)/../repos/libs +UK_LIBS ?= + +.PHONY: all + +all: + @$(MAKE) -C $(UK_ROOT) L=$(UK_LIBS) A=$(UK_APP) O=$(UK_BUILD) + +$(MAKECMDGOALS): + @$(MAKE) -C $(UK_ROOT) L=$(UK_LIBS) A=$(UK_APP) O=$(UK_BUILD) $(MAKECMDGOALS) diff --git a/c-bye/Makefile.uk b/c-bye/Makefile.uk new file mode 100644 index 00000000..28e8ff7b --- /dev/null +++ b/c-bye/Makefile.uk @@ -0,0 +1,3 @@ +$(eval $(call addlib,appcbye)) + +APPCHELLO_SRCS-y += $(APPCHELLO_BASE)/bye.c diff --git a/c-bye/README.md b/c-bye/README.md new file mode 100644 index 00000000..f63f5c38 --- /dev/null +++ b/c-bye/README.md @@ -0,0 +1,259 @@ +# C Hello on Unikraft + +Build and run a C Hello program on Unikraft. +Follow the instructions below to set up, configure, build and run C Hello. +Make sure you installed the [requirements](../README.md#requirements). + +## Quick Setup (aka TLDR) + +For a quick setup, run the commands below. +Note that you still need to install the [requirements](../README.md#requirements). + +To build and run the application for `x86_64`, use the commands below: + +```console +test -d ../repos/unikraft || git clone https://github.com/unikraft/unikraft ../repos/unikraft +make distclean +echo -e 'CONFIG_PLAT_KVM=y\nCONFIG_PLAT_KVM_VMM_QEMU=y\nCONFIG_ARCH_X86_64=y' > /tmp/defconfig +UK_DEFCONFIG=/tmp/defconfig make defconfig +make -j $(nproc) +qemu-system-x86_64 -nographic -m 8 -cpu max -kernel out/c-bye_qemu-x86_64 +``` + +This will configure, build and run the application, resulting in a `Hello from Unikraft!` message being printed. + +To do the same for `AArch64`, run the commands below: + +```console +test -d ../repos/unikraft || git clone https://github.com/unikraft/unikraft ../repos/unikraft +make distclean +echo -e 'CONFIG_PLAT_KVM=y\nCONFIG_PLAT_KVM_VMM_QEMU=y\nCONFIG_ARCH_ARM_64=y' > /tmp/defconfig +UK_DEFCONFIG=/tmp/defconfig make defconfig +make -j $(nproc) +qemu-system-aarch64 -nographic -machine virt -m 8 -cpu max -kernel out/c-bye_qemu-arm64 +``` + +Similar to the `x86_64` build, this will result in a `Hello from Unikraft!` message being printed. + +Information about every step and about other types of builds is detailed below. + +## Set Up + +Set up the [`unikraft` repository](https://github.com/unikraft/unikraft). +Clone it in `../repos/unikraft/` if not already cloned: + +```console +test -d ../repos/unikraft || git clone https://github.com/unikraft/unikraft ../repos/unikraft +``` +If you want use a custom variant of the repository (e.g. apply your own patch, make modifications), update it accordingly in the `../repos/` directory. + +## Clean + +While not strictly required, it is safest to clean the previous build artifacts: + +```console +make distclean +``` + +## Configure + +To configure the kernel, use: + +```console +make menuconfig +``` + +In the console menu interface, choose the target architecture (x86_64 or ARMv8 or ARMv7) and platform (Xen or KVM/QEMU or KVM/Firecracker). + +The end result will be the creation of the `.config` configuration file. + +## Build + +Build the application for the current configuration: + +```console +make -j $(nproc) +``` + +This results in the creation of the `out/` directory storing the build artifacts. +The unikernel application image file is `out/c-bye_-`, where `` is the platform name (`qemu`, `fc`, `xen`), and `` is the architecture (`x86_64` or `arm64`). + +### Use a Different Compiler + +If you want to use a different compiler, such as a Clang or a different GCC version, pass the `CC` variable to `make`. + +To build with Clang, use the commands below: + +```console +make properclean +make CC=clang -j $(nproc) +``` + +Note that Clang >= 14 is required to build Unikraft. + +To build with another GCC version, use the commands below: + +```console +make properclean +make CC=gcc- -j $(nproc) +``` + +where `` is the GCC version, such as `11`, `12`. + +Note that GCC >= 8 is required to build Unikraft. + +## Clean Up + +Doing a new configuration, or a new build may require cleaning up the configuration and build artifacts. + +In order to remove the build artifacts, use: + +```console +make clean +``` + +In order to remove fetched files also, that is the removal of the `out/` directory, use: + +```console +make properclean +``` + +In order to remove the generated `.config` file as well, use: + +```console +make distclean +``` + +## Run + +Run the resulting image using the corresponding platform tool. +Firecracker requires KVM support. +Xen requires a system with Xen installed. + +A successful run will show a message such as the one below: + +```text +Booting from ROM..Powered by +o. .o _ _ __ _ +Oo Oo ___ (_) | __ __ __ _ ' _) :_ +oO oO ' _ `| | |/ / _)' _` | |_| _) +oOo oOO| | | | | (| | | (_) | _) :_ + OoOoO ._, ._:_:_,\_._, .__,_:_, \___) + Calypso 0.17.0~5d38d108 +Hello from Unikraft! +``` + +### Run on QEMU/x86_64 + +```console +qemu-system-x86_64 -nographic -m 8 -cpu max -kernel out/c-bye_qemu-x86_64 +``` + +### Run on QEMU/ARM64 + +```console +qemu-system-aarch64 -nographic -machine virt -m 8 -cpu max -kernel out/c-bye_qemu-arm64 +``` + +### Run on Firecracker/x86_64 + +```console +rm -f firecracker.socket +firecracker-x86_64 --config-file fc.x86_64.json --api-sock firecracker.socket +``` + +The user running the above command must be able to use KVM. +Typically this means being part of the `kvm` group. +Otherwise, run the command above as root or prefixed by `sudo`. + +### Run on Firecracker/ARM64 + +```console +rm -f firecracker.socket +firecracker-aarch64 --config-file fc.arm64.json --api-sock firecracker.socket +``` + +The user running the above command must be able to use KVM. +Typically this means being part of the `kvm` group. +Otherwise, run the command above as the `root` account or prefixed by `sudo`. + +### Run on Xen/x86_64 + +```console +sudo xl create -c xen.x86_64.cfg +``` + +You need use `sudo` or the `root` account to run Xen. + +### Run on Xen/ARM64 + +```console +sudo xl create -c xen.arm64.cfg +``` + +You need use `sudo` or the `root` account to run Xen. + +## Customize + +C Hello is the simplest application to be run with Unikraft. +This makes it ideal as a minimal testing ground for new features: it builds fast, it doesn't have dependencies. + +### Update the Unikraft Core Code + +If updating the Unikraft core code in the `../repos/unikraft/` directory, you then go through the [configure](#configure), [build](#build) and [run](#run) steps. + +### Add Other Source Code Files + +The current configuration use a single source file: `bye.c`. +If looking to add another file to the build, update the [`Makefile.uk`](Makefile.uk) file. + +For example, to add a new file `support.c` to the build, update the [`Makefile.uk`](Makefile.uk) file to: + +```make +$(eval $(call addlib,appcbye)) + +APPCHELLO_SRCS-y += $(APPCHELLO_BASE)/bye.c +APPCHELLO_SRCS-y += $(APPCHELLO_BASE)/support.c +``` + +To add a new include directory, such as a local `include/` directory, update the [`Makefile.uk`](Makefile.uk) file to: + +```make +$(eval $(call addlib,appcbye)) + +APPCHELLO_SRCS-y += $(APPCHELLO_BASE)/bye.c +CINCLUDES-y += -I$(APPCHELLO_BASE)/include +``` + +Then go through the [configure](#configure), [build](#build) and [run](#run) steps. + +### Add Libraries + +It may be the case that you want to add a library to the build, in order to test the library or a certain feature. +If that is the case, update the `UK_LIBS` variable in the [`Makefile`](Makefile). + +For example, to add the Musl library to the build, clone the [`lib-musl` library repository](https://github.com/unikraft/lib-musl): + +```console +test -d ../repos/libs/musl || git clone https://github.com/unikraft/lib-musl ../repos/libs/musl +``` + +and update the `UK_LIBS` line the [`Makefile`](Makefile) to: + +```make +UK_LIBS ?= $(LIBS_BASE)/musl +``` + +To add another library, such as LWIP, clone the [corresponding `lib-lwip` repository](https://github.com/unikraft/lib-musl): + +```console +test -d ../repos/libs/lwip || git clone https://github.com/unikraft/lib-lwip ../repos/libs/lwip +``` + +and update the `UK_LIBS` line the [`Makefile`](Makefile) to: + +```make +UK_LIBS ?= $(LIBS_BASE)/musl:$(LIBS_BASE)/lwip +``` + +Then go through the [configure](#configure), [build](#build) and [run](#run) steps. diff --git a/c-bye/README.scripts.md b/c-bye/README.scripts.md new file mode 100644 index 00000000..dabf633f --- /dev/null +++ b/c-bye/README.scripts.md @@ -0,0 +1,54 @@ +# Scripts for C Hello on Unikraft + +These are companions instruction to the main instructions in the [`README`](README.md). + +Use scripts as quick actions for building and running C Hello on Unikraft. + +## Build for / : + +```console +./build.. +``` + +e.g.: + +```console +./build.qemu.x86_64 +./build.qemu.arm64 +./build.fc.x86_64 +./build.xen.arm64 +``` + +## Build for / using a different compiler + +```console +CC=/path/to/compiler ./build.. +``` + +e.g. + +```console +CC=/usr/bin/gcc-12 ./build.qemu.x86_64 +CC=/usr/bin/aarch64-linux-gnu-gcc-12 ./build.qemu.arm64 +CC=/usr/bin/clang ./build.qemu.x86_64 +CC=/usr/bin/clang ./build.qemu.arm64 +CC=/usr/bin/gcc-12 ./build.fc.x86_64 +CC=/usr/bin/aarch64-linux-gnu-gcc-12 ./build.fc.arm64 +CC=/usr/bin/clang ./build.fc.x86_64 +CC=/usr/bin/clang ./build.fc.arm64 +``` + +## Run on / + +```console +./run.. +``` + +e.g. + +```console +./run.qemu.x86_64 +./run.qemu.arm64 +./run.fc.x86_64 +./run.xen.arm64 +``` diff --git a/c-bye/build.fc.arm64 b/c-bye/build.fc.arm64 new file mode 100755 index 00000000..9bfb46a8 --- /dev/null +++ b/c-bye/build.fc.arm64 @@ -0,0 +1,13 @@ +#!/bin/sh + +test -d "../repos/unikraft" || git clone https://github.com/unikraft/unikraft ../repos/unikraft + +make distclean +UK_DEFCONFIG=$(pwd)/defconfig.fc.arm64 make defconfig +touch Makefile.uk +make prepare +if test -z "$CC"; then + make -j $(nproc) +else + make CC="$CC" -j $(nproc) +fi diff --git a/c-bye/build.fc.x86_64 b/c-bye/build.fc.x86_64 new file mode 100755 index 00000000..3e02206e --- /dev/null +++ b/c-bye/build.fc.x86_64 @@ -0,0 +1,13 @@ +#!/bin/sh + +test -d "../repos/unikraft" || git clone https://github.com/unikraft/unikraft ../repos/unikraft + +make distclean +UK_DEFCONFIG=$(pwd)/defconfig.fc.x86_64 make defconfig +touch Makefile.uk +make prepare +if test -z "$CC"; then + make -j $(nproc) +else + make CC="$CC" -j $(nproc) +fi diff --git a/c-bye/build.qemu.arm64 b/c-bye/build.qemu.arm64 new file mode 100755 index 00000000..c477734a --- /dev/null +++ b/c-bye/build.qemu.arm64 @@ -0,0 +1,13 @@ +#!/bin/sh + +test -d "../repos/unikraft" || git clone https://github.com/unikraft/unikraft ../repos/unikraft + +make distclean +UK_DEFCONFIG=$(pwd)/defconfig.qemu.arm64 make defconfig +touch Makefile.uk +make prepare +if test -z "$CC"; then + make -j $(nproc) +else + make CC="$CC" -j $(nproc) +fi diff --git a/c-bye/build.qemu.x86_64 b/c-bye/build.qemu.x86_64 new file mode 100755 index 00000000..a3e6598b --- /dev/null +++ b/c-bye/build.qemu.x86_64 @@ -0,0 +1,13 @@ +#!/bin/sh + +test -d "../repos/unikraft" || git clone https://github.com/unikraft/unikraft ../repos/unikraft + +make distclean +UK_DEFCONFIG=$(pwd)/defconfig.qemu.x86_64 make defconfig +touch Makefile.uk +make prepare +if test -z "$CC"; then + make -j $(nproc) +else + make CC="$CC" -j $(nproc) +fi diff --git a/c-bye/build.xen.arm64 b/c-bye/build.xen.arm64 new file mode 100755 index 00000000..ddb59ffe --- /dev/null +++ b/c-bye/build.xen.arm64 @@ -0,0 +1,13 @@ +#!/bin/sh + +test -d "../repos/unikraft" || git clone https://github.com/unikraft/unikraft ../repos/unikraft + +make distclean +UK_DEFCONFIG=$(pwd)/defconfig.xen.arm64 make defconfig +touch Makefile.uk +make prepare +if test -z "$CC"; then + make -j $(nproc) +else + make CC="$CC" -j $(nproc) +fi diff --git a/c-bye/build.xen.x86_64 b/c-bye/build.xen.x86_64 new file mode 100755 index 00000000..2ece342f --- /dev/null +++ b/c-bye/build.xen.x86_64 @@ -0,0 +1,13 @@ +#!/bin/sh + +test -d "../repos/unikraft" || git clone https://github.com/unikraft/unikraft ../repos/unikraft + +make distclean +UK_DEFCONFIG=$(pwd)/defconfig.xen.x86_64 make defconfig +touch Makefile.uk +make prepare +if test -z "$CC"; then + make -j $(nproc) +else + make CC="$CC" -j $(nproc) +fi diff --git a/c-bye/bye.c b/c-bye/bye.c new file mode 100644 index 00000000..346451fb --- /dev/null +++ b/c-bye/bye.c @@ -0,0 +1,8 @@ +#include + +int main(void) +{ + puts("Bye from Unikraft!"); + + return 0; +} diff --git a/c-bye/defconfig.fc.arm64 b/c-bye/defconfig.fc.arm64 new file mode 100644 index 00000000..a3308a52 --- /dev/null +++ b/c-bye/defconfig.fc.arm64 @@ -0,0 +1,6 @@ +CONFIG_PLAT_KVM=y +CONFIG_KVM_VMM_FIRECRACKER=y +CONFIG_ARCH_ARM_64=y +CONFIG_ARM64_ERRATUM_858921=n +CONFIG_ARM64_ERRATUM_835769=n +CONFIG_ARM64_ERRATUM_843419=n diff --git a/c-bye/defconfig.fc.x86_64 b/c-bye/defconfig.fc.x86_64 new file mode 100644 index 00000000..5ca23b22 --- /dev/null +++ b/c-bye/defconfig.fc.x86_64 @@ -0,0 +1,3 @@ +CONFIG_PLAT_KVM=y +CONFIG_KVM_VMM_FIRECRACKER=y +CONFIG_ARCH_X86_64=y diff --git a/c-bye/defconfig.qemu.arm64 b/c-bye/defconfig.qemu.arm64 new file mode 100644 index 00000000..15bcb1a2 --- /dev/null +++ b/c-bye/defconfig.qemu.arm64 @@ -0,0 +1,6 @@ +CONFIG_PLAT_KVM=y +CONFIG_KVM_VMM_QEMU=y +CONFIG_ARCH_ARM_64=y +CONFIG_ARM64_ERRATUM_858921=n +CONFIG_ARM64_ERRATUM_835769=n +CONFIG_ARM64_ERRATUM_843419=n diff --git a/c-bye/defconfig.qemu.x86_64 b/c-bye/defconfig.qemu.x86_64 new file mode 100644 index 00000000..2e0e290a --- /dev/null +++ b/c-bye/defconfig.qemu.x86_64 @@ -0,0 +1,3 @@ +CONFIG_PLAT_KVM=y +CONFIG_KVM_VMM_QEMU=y +CONFIG_ARCH_X86_64=y diff --git a/c-bye/defconfig.xen.arm64 b/c-bye/defconfig.xen.arm64 new file mode 100644 index 00000000..58623680 --- /dev/null +++ b/c-bye/defconfig.xen.arm64 @@ -0,0 +1,5 @@ +CONFIG_PLAT_XEN=y +CONFIG_ARCH_ARM_64=y +CONFIG_ARM64_ERRATUM_858921=n +CONFIG_ARM64_ERRATUM_835769=n +CONFIG_ARM64_ERRATUM_843419=n diff --git a/c-bye/defconfig.xen.x86_64 b/c-bye/defconfig.xen.x86_64 new file mode 100644 index 00000000..37586aad --- /dev/null +++ b/c-bye/defconfig.xen.x86_64 @@ -0,0 +1,2 @@ +CONFIG_PLAT_XEN=y +CONFIG_ARCH_X86_64=y diff --git a/c-bye/fc.arm64.json b/c-bye/fc.arm64.json new file mode 100644 index 00000000..e90885a8 --- /dev/null +++ b/c-bye/fc.arm64.json @@ -0,0 +1,12 @@ +{ + "boot-source": { + "kernel_image_path": "out/c-hello_fc-arm64" + }, + "drives": [], + "machine-config": { + "vcpu_count": 1, + "mem_size_mib": 8, + "smt": false, + "track_dirty_pages": false + } +} diff --git a/c-bye/fc.x86_64.json b/c-bye/fc.x86_64.json new file mode 100644 index 00000000..06abe165 --- /dev/null +++ b/c-bye/fc.x86_64.json @@ -0,0 +1,12 @@ +{ + "boot-source": { + "kernel_image_path": "out/c-hello_fc-x86_64" + }, + "drives": [], + "machine-config": { + "vcpu_count": 1, + "mem_size_mib": 8, + "smt": false, + "track_dirty_pages": false + } +} diff --git a/c-bye/run.fc.arm64 b/c-bye/run.fc.arm64 new file mode 100755 index 00000000..a85d5ded --- /dev/null +++ b/c-bye/run.fc.arm64 @@ -0,0 +1,12 @@ +#!/bin/sh + +if test ! -f "out/c-bye_fc-arm64"; then + echo "No kernel file out/c-bye_fc-arm64." 1>&2 + echo "Did you run ./build.fc.arm64 ?" 1>&2 + exit 1 +fi + +rm -f firecracker.socket +firecracker-aarch64 \ + --api-sock firecracker.socket \ + --config-file fc.arm64.json diff --git a/c-bye/run.fc.x86_64 b/c-bye/run.fc.x86_64 new file mode 100755 index 00000000..9c45f078 --- /dev/null +++ b/c-bye/run.fc.x86_64 @@ -0,0 +1,12 @@ +#!/bin/sh + +if test ! -f "out/c-bye_fc-x86_64"; then + echo "No kernel file out/c-bye_fc-x86_64." 1>&2 + echo "Did you run ./build.fc.x86_64 ?" 1>&2 + exit 1 +fi + +rm -f firecracker.socket +firecracker-x86_64 \ + --api-sock firecracker.socket \ + --config-file fc.x86_64.json diff --git a/c-bye/run.qemu.arm64 b/c-bye/run.qemu.arm64 new file mode 100755 index 00000000..1ed96946 --- /dev/null +++ b/c-bye/run.qemu.arm64 @@ -0,0 +1,14 @@ +#!/bin/sh + +if test ! -f "out/c-bye_qemu-arm64"; then + echo "No kernel file out/c-bye_qemu-arm64." 1>&2 + echo "Did you run ./build.qemu.arm64 ?" 1>&2 + exit 1 +fi + +qemu-system-aarch64 \ + -nographic \ + -machine virt \ + -m 8 \ + -cpu max \ + -kernel out/c-bye_qemu-arm64 diff --git a/c-bye/run.qemu.x86_64 b/c-bye/run.qemu.x86_64 new file mode 100755 index 00000000..9263b74a --- /dev/null +++ b/c-bye/run.qemu.x86_64 @@ -0,0 +1,13 @@ +#!/bin/sh + +if test ! -f "out/c-bye_qemu-x86_64"; then + echo "No kernel file out/c-bye_qemu-x86_64." 1>&2 + echo "Did you run ./build.qemu.x86_64 ?" 1>&2 + exit 1 +fi + +qemu-system-x86_64 \ + -nographic \ + -m 8 \ + -cpu max \ + -kernel out/c-bye_qemu-x86_64 diff --git a/c-bye/run.xen.arm64 b/c-bye/run.xen.arm64 new file mode 100755 index 00000000..a9bab98f --- /dev/null +++ b/c-bye/run.xen.arm64 @@ -0,0 +1,9 @@ +#!/bin/sh + +if test ! -f "out/c-bye_xen-arm64"; then + echo "No kernel file out/c-bye_xen-arm64." 1>&2 + echo "Did you run ./build.xen.arm64 ?" 1>&2 + exit 1 +fi + +sudo xl create -c xen.arm64.cfg diff --git a/c-bye/run.xen.x86_64 b/c-bye/run.xen.x86_64 new file mode 100755 index 00000000..e05c3b78 --- /dev/null +++ b/c-bye/run.xen.x86_64 @@ -0,0 +1,9 @@ +#!/bin/sh + +if test ! -f "out/c-bye_xen-x86_64"; then + echo "No kernel file out/c-bye_xen-x86_64." 1>&2 + echo "Did you run ./build.xen.x86_64 ?" 1>&2 + exit 1 +fi + +sudo xl create -c xen.x86_64.cfg diff --git a/c-bye/test.all.sh b/c-bye/test.all.sh new file mode 100755 index 00000000..70b746dc --- /dev/null +++ b/c-bye/test.all.sh @@ -0,0 +1,33 @@ +#!/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 qemu.arm64 +test_build_run fc.x86_64 +test_build fc.arm64 +test_build xen.x86_64 +test_build xen.arm64 diff --git a/c-bye/test.common.sh b/c-bye/test.common.sh new file mode 100644 index 00000000..897205bb --- /dev/null +++ b/c-bye/test.common.sh @@ -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" diff --git a/c-bye/test.sh b/c-bye/test.sh new file mode 100755 index 00000000..c18e81e9 --- /dev/null +++ b/c-bye/test.sh @@ -0,0 +1,4 @@ +#!/bin/sh + +. ./test.common.sh + diff --git a/c-bye/test.wrapper.sh b/c-bye/test.wrapper.sh new file mode 100755 index 00000000..7182d26c --- /dev/null +++ b/c-bye/test.wrapper.sh @@ -0,0 +1,24 @@ +#!/bin/sh + +. ./test.common.sh + +if test $# -ne 1; then + echo "Unknown arguments." 1>&2 + echo "Usage: $0 " 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 diff --git a/c-bye/xen.arm64.cfg b/c-bye/xen.arm64.cfg new file mode 100644 index 00000000..11a38f73 --- /dev/null +++ b/c-bye/xen.arm64.cfg @@ -0,0 +1,5 @@ +name = "c-bye" +vcpus = "1" +kernel = "./out/c-bye_xen-arm64" +memory = "8" +type = "pv" diff --git a/c-bye/xen.x86_64.cfg b/c-bye/xen.x86_64.cfg new file mode 100644 index 00000000..7386dd01 --- /dev/null +++ b/c-bye/xen.x86_64.cfg @@ -0,0 +1,5 @@ +name = "c-bye" +vcpus = "1" +kernel = "./out/c-bye_xen-x86_64" +memory = "8" +type = "pv" From e7c05b63cacb2d7e5520c7e994d26f217909b3a4 Mon Sep 17 00:00:00 2001 From: Andrei Popovici Date: Sat, 18 Oct 2025 11:57:43 +0300 Subject: [PATCH 2/3] Am adaugat --- salut/hello.c | 1 + 1 file changed, 1 insertion(+) create mode 100644 salut/hello.c diff --git a/salut/hello.c b/salut/hello.c new file mode 100644 index 00000000..5117f9f3 --- /dev/null +++ b/salut/hello.c @@ -0,0 +1 @@ +#inlcudopamksdnaijn From f3517b03103449112e29b00310658369942c78fa Mon Sep 17 00:00:00 2001 From: Andrei Popovici Date: Sat, 18 Oct 2025 12:17:36 +0300 Subject: [PATCH 3/3] Adaug touch Signed-off-by: Andrei Popovici --- c-bye/touch | 1 + 1 file changed, 1 insertion(+) create mode 100644 c-bye/touch diff --git a/c-bye/touch b/c-bye/touch new file mode 100644 index 00000000..f401a4cf --- /dev/null +++ b/c-bye/touch @@ -0,0 +1 @@ +HI hello.txt