1 # Teach the kernel how to run armv7l and aarch64-linux binaries,
2 # and run GNU Hello for these architectures.
4 { system ? builtins.currentSystem,
6 pkgs ? import ../.. { inherit system config; }
9 with import ../lib/testing-python.nix { inherit system pkgs; };
12 expectArgv0 = xpkgs: xpkgs.runCommandCC "expect-argv0" {
13 src = pkgs.writeText "expect-argv0.c" ''
17 int main(int argc, char **argv) {
18 fprintf(stderr, "Our argv[0] is %s\n", argv[0]);
20 if (strcmp(argv[0], argv[1])) {
21 fprintf(stderr, "ERROR: argv[0] is %s, should be %s\n", argv[0], argv[1]);
33 name = "systemd-binfmt";
35 boot.binfmt.emulatedSystems = [
42 helloArmv7l = pkgs.pkgsCross.armv7l-hf-multiplatform.hello;
43 helloAarch64 = pkgs.pkgsCross.aarch64-multiplatform.hello;
47 assert "world" in machine.succeed(
48 "${helloArmv7l}/bin/hello"
51 assert "world" in machine.succeed(
52 "${helloAarch64}/bin/hello"
57 preserveArgvZero = makeTest {
58 name = "systemd-binfmt-preserve-argv0";
60 boot.binfmt.emulatedSystems = [
65 testAarch64 = expectArgv0 pkgs.pkgsCross.aarch64-multiplatform;
68 machine.succeed("exec -a meow ${testAarch64} meow")
72 ldPreload = makeTest {
73 name = "systemd-binfmt-ld-preload";
75 boot.binfmt.emulatedSystems = [
80 helloAarch64 = pkgs.pkgsCross.aarch64-multiplatform.hello;
81 libredirectAarch64 = pkgs.pkgsCross.aarch64-multiplatform.libredirect;
85 assert "error" not in machine.succeed(
86 "LD_PRELOAD='${libredirectAarch64}/lib/libredirect.so' ${helloAarch64}/bin/hello 2>&1"
92 name = "systemd-binfmt-chroot";
93 nodes.machine = { pkgs, lib, ... }: {
94 boot.binfmt.emulatedSystems = [
95 "aarch64-linux" "wasm32-wasi"
97 boot.binfmt.preferStaticEmulators = true;
99 environment.systemPackages = [
100 (pkgs.writeShellScriptBin "test-chroot" ''
103 cp ${lib.getExe' pkgs.pkgsCross.aarch64-multiplatform.pkgsStatic.busybox "busybox"} /tmp/chroot/busybox
104 cp ${lib.getExe pkgs.pkgsCross.wasi32.yaml2json} /tmp/chroot/yaml2json # wasi binaries that build are hard to come by
105 chroot /tmp/chroot /busybox uname -m | grep aarch64
106 echo 42 | chroot /tmp/chroot /yaml2json | grep 42
112 machine.succeed("test-chroot")