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