1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
|
# Teach the kernel how to run armv7l and aarch64-linux binaries,
# and run GNU Hello for these architectures.
{
system ? builtins.currentSystem,
config ? { },
pkgs ? import ../.. { inherit system config; },
}:
with import ../lib/testing-python.nix { inherit system pkgs; };
let
expectArgv0 =
xpkgs:
xpkgs.runCommandCC "expect-argv0"
{
src = pkgs.writeText "expect-argv0.c" ''
#include <stdio.h>
#include <string.h>
int main(int argc, char **argv) {
fprintf(stderr, "Our argv[0] is %s\n", argv[0]);
if (strcmp(argv[0], argv[1])) {
fprintf(stderr, "ERROR: argv[0] is %s, should be %s\n", argv[0], argv[1]);
return 1;
}
return 0;
}
'';
}
''
$CC -o $out $src
'';
in
{
basic = makeTest {
name = "systemd-binfmt";
nodes.machine = {
boot.binfmt.emulatedSystems = [
"armv7l-linux"
"aarch64-linux"
];
};
testScript =
let
helloArmv7l = pkgs.pkgsCross.armv7l-hf-multiplatform.hello;
helloAarch64 = pkgs.pkgsCross.aarch64-multiplatform.hello;
in
''
machine.start()
assert "world" in machine.succeed(
"${helloArmv7l}/bin/hello"
)
assert "world" in machine.succeed(
"${helloAarch64}/bin/hello"
)
'';
};
preserveArgvZero = makeTest {
name = "systemd-binfmt-preserve-argv0";
nodes.machine = {
boot.binfmt.emulatedSystems = [
"aarch64-linux"
];
};
testScript =
let
testAarch64 = expectArgv0 pkgs.pkgsCross.aarch64-multiplatform;
in
''
machine.start()
machine.succeed("exec -a meow ${testAarch64} meow")
'';
};
ldPreload = makeTest {
name = "systemd-binfmt-ld-preload";
nodes.machine = {
boot.binfmt.emulatedSystems = [
"aarch64-linux"
];
};
testScript =
let
helloAarch64 = pkgs.pkgsCross.aarch64-multiplatform.hello;
libredirectAarch64 = pkgs.pkgsCross.aarch64-multiplatform.libredirect;
in
''
machine.start()
assert "error" not in machine.succeed(
"LD_PRELOAD='${libredirectAarch64}/lib/libredirect.so' ${helloAarch64}/bin/hello 2>&1"
).lower()
'';
};
chroot = makeTest {
name = "systemd-binfmt-chroot";
nodes.machine =
{
pkgs,
lib,
config,
...
}:
{
boot.binfmt.emulatedSystems = [
"aarch64-linux"
"wasm32-wasip1"
];
boot.binfmt.preferStaticEmulators = true;
environment.systemPackages = [
(pkgs.writeShellScriptBin "test-chroot" ''
set -euo pipefail
mkdir -p /tmp/chroot
cp ${lib.getExe' pkgs.pkgsCross.aarch64-multiplatform.pkgsStatic.busybox "busybox"} /tmp/chroot/busybox
cp ${lib.getExe pkgs.pkgsCross.wasm32-wasip1.yaml2json} /tmp/chroot/yaml2json # wasi binaries that build are hard to come by
chroot /tmp/chroot /busybox uname -m | grep aarch64
echo 42 | chroot /tmp/chroot /yaml2json | grep 42
'')
];
assertions = [
{
assertion = config.nix.settings.extra-sandbox-paths == [ ];
message = "Using binfmt_misc with static emulators, nix.settings.extra-sandbox-paths should be empty";
}
];
};
testScript = ''
machine.start()
machine.succeed("test-chroot")
'';
};
}
|