Skip to content

Commit d275e91

Browse files
committed
add shellHook to permit tests with capability requirements
1 parent 30f3dd2 commit d275e91

File tree

2 files changed

+81
-13
lines changed

2 files changed

+81
-13
lines changed

test.sh

Lines changed: 16 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -67,23 +67,23 @@ build_chainloader(){
6767
}
6868

6969
build_example(){
70-
nix-build $CCACHE_FLAG example.nix
70+
nix-build $CCACHE_FLAG unikernel.nix
7171
}
7272

7373
multicore_subset(){
74-
nix-shell --pure --arg smp true $CCACHE_FLAG --argstr unikernel ./test/kernel/integration/smp --run ./test.py
74+
nix-build ./unikernel.nix --arg smp true $CCACHE_FLAG --argstr unikernel ./test/kernel/integration/smp --arg doCheck true
7575

7676
# The following tests are not using multiple CPU's, but have been equippedd with some anyway
7777
# to make sure core functionality is not broken by missing locks etc. when waking up more cores.
78-
nix-shell --pure --arg smp true $CCACHE_FLAG --argstr unikernel ./test/net/integration/udp --run ./test.py
79-
nix-shell --pure --arg smp true $CCACHE_FLAG --argstr unikernel ./test/kernel/integration/paging --run ./test.py
78+
nix-shell ./unikernel.nix --arg smp true $CCACHE_FLAG --argstr unikernel ./test/net/integration/udp
79+
nix-build ./unikernel.nix --arg smp true $CCACHE_FLAG --argstr unikernel ./test/kernel/integration/paging --arg doCheck true
8080
}
8181

8282
smoke_tests(){
83-
nix-shell --pure $CCACHE_FLAG --argstr unikernel ./test/net/integration/udp --run ./test.py
84-
nix-shell --pure $CCACHE_FLAG --argstr unikernel ./test/net/integration/tcp --run ./test.py
85-
nix-shell --pure $CCACHE_FLAG --argstr unikernel ./test/kernel/integration/paging --run ./test.py
86-
nix-shell --pure $CCACHE_FLAG --argstr unikernel ./test/kernel/integration/smp --run ./test.py
83+
nix-build ./unikernel.nix $CCACHE_FLAG --argstr unikernel ./test/net/integration/udp
84+
nix-build ./unikernel.nix $CCACHE_FLAG --argstr unikernel ./test/net/integration/tcp
85+
nix-build ./unikernel.nix $CCACHE_FLAG --argstr unikernel ./test/kernel/integration/paging --arg doCheck true
86+
nix-build ./unikernel.nix $CCACHE_FLAG --argstr unikernel ./test/kernel/integration/smp --arg doCheck true
8787
}
8888

8989
run unittests "Build and run unit tests"
@@ -112,6 +112,7 @@ fi
112112

113113
# Continuing from here will run all integration tests.
114114

115+
sandboxed=true
115116
run_testsuite() {
116117
local base_folder="$1"
117118
shift
@@ -151,7 +152,11 @@ run_testsuite() {
151152

152153

153154
# The command to run, as string to be able to print the fully expanded command
154-
cmd="nix-shell --pure $CCACHE_FLAG --argstr unikernel $subfolder --run ./test.py"
155+
if $sandboxed; then
156+
cmd="nix-build ./unikernel.nix $CCACHE_FLAG --argstr unikernel ${subfolder%/} --arg doCheck true"
157+
else
158+
cmd="nix-shell ./unikernel.nix $CCACHE_FLAG --argstr unikernel ${subfolder%/}"
159+
fi
155160

156161
echo ""
157162
echo "🚧 Step $steps.$substeps"
@@ -223,7 +228,9 @@ exclusions=(
223228
"websocket" # Linking fails, undefined ref to http_parser_parse_url, http_parser_execute
224229
)
225230

231+
sandboxed=false
226232
run_testsuite "./test/net/integration" "${exclusions[@]}"
233+
sandboxed=true
227234

228235
echo -e "\n~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~"
229236

unikernel.nix

Lines changed: 65 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,12 @@
11
{
2-
32
# The unikernel to build
43
unikernel ? ./example,
54

5+
# The test file to run
6+
test ? "test.py",
7+
68
# Boot unikernel after building it
7-
doCheck ? true,
9+
doCheck ? false,
810

911
# Which architecture to build against
1012
arch ? "x86_64",
@@ -20,12 +22,27 @@
2022

2123
# The includeos library to build and link against
2224
includeos ? import ./default.nix { inherit withCcache; inherit smp; },
25+
26+
# vmrunner path, for vmrunner development
27+
vmrunner ? "",
2328
}:
29+
let
30+
absolutePathOf = base: p:
31+
if p == null then null else
32+
if builtins.isPath p then p
33+
else builtins.toPath (base + "/${p}");
2434

35+
unikernelPath = absolutePathOf ./. unikernel;
36+
vmrunnerPkg =
37+
if vmrunner == "" then
38+
includeos.vmrunner
39+
else
40+
includeos.pkgs.callPackage (builtins.toPath /. + vmrunner) {};
41+
in
2542
includeos.stdenv.mkDerivation rec {
2643
pname = "includeos_example";
2744
version = "dev";
28-
src = includeos.pkgs.lib.cleanSource "${unikernel}";
45+
src = includeos.pkgs.lib.cleanSource unikernelPath;
2946
dontStrip = true;
3047
inherit doCheck;
3148

@@ -46,14 +63,58 @@ includeos.stdenv.mkDerivation rec {
4663
"-DFOR_PRODUCTION=${if forProduction then "ON" else "OFF"}"
4764
];
4865

66+
installPhase = ''
67+
runHook preInstall
68+
find -mindepth 1 -maxdepth 1 -type f -exec install -v -D -t "$out/" {} \;
69+
find -mindepth 2 -name '*.elf.bin' -exec install -v -t "$out/" {} \;
70+
runHook postInstall
71+
'';
72+
73+
4974
nativeCheckInputs = [
5075
includeos.vmrunner
76+
includeos.pkgs.grub2
77+
includeos.pkgs.python3
5178
includeos.pkgs.qemu
79+
includeos.pkgs.iputils
80+
includeos.pkgs.xorriso
81+
];
82+
83+
checkInputs = [
84+
includeos.lest
5285
];
5386

87+
# use `nix-build --arg doCheck true` to run tests normally
5488
checkPhase = ''
5589
runHook preCheck
56-
boot *.elf.bin
90+
set -e
91+
if [ -e "${src}/${test}" ]; then
92+
echo "Running IncludeOS test: ${src}/${test}"
93+
python3 "${src}/${test}"
94+
else
95+
echo "Requested test, but no test was found 😟"
96+
exit 1
97+
fi
5798
runHook postCheck
5899
'';
100+
101+
# this is a hack
102+
# some tests need to be run through a shell because of net_cap_raw+ep and net_cap_admin+ep
103+
# replace nix-build with nix-shell to test without dropping capabilities
104+
packages = [
105+
(includeos.pkgs.python3.withPackages (p: [
106+
vmrunnerPkg
107+
]))
108+
];
109+
shellHook = ''
110+
set -eu
111+
pkg="$(nix-build ./unikernel.nix --arg doCheck false --arg unikernel ${unikernel})"
112+
113+
testPath="$(realpath "${unikernel}/${test}")"
114+
cd "$pkg"
115+
"$testPath" || exit 1
116+
117+
exit 0
118+
'';
119+
59120
}

0 commit comments

Comments
 (0)