summary refs log tree commit diff
path: root/pkgs/test
diff options
context:
space:
mode:
authorMatthew Bauer <matthew.bauer@obsidian.systems>2018-07-20 22:43:55 -0400
committerMatthew Bauer <matthew.bauer@obsidian.systems>2018-07-21 17:00:05 -0400
commitb98b4eac71cfb0ccedc6d909fd58058bc1cb85e7 (patch)
treebf88ca93914bf612c8a6e9657c0ed4fa01bde888 /pkgs/test
parent09fed91ec8e084c4cdfd9e2363d65e8bb7c48091 (diff)
downloadnixpkgs-b98b4eac71cfb0ccedc6d909fd58058bc1cb85e7.tar
nixpkgs-b98b4eac71cfb0ccedc6d909fd58058bc1cb85e7.tar.gz
nixpkgs-b98b4eac71cfb0ccedc6d909fd58058bc1cb85e7.tar.bz2
nixpkgs-b98b4eac71cfb0ccedc6d909fd58058bc1cb85e7.tar.lz
nixpkgs-b98b4eac71cfb0ccedc6d909fd58058bc1cb85e7.tar.xz
nixpkgs-b98b4eac71cfb0ccedc6d909fd58058bc1cb85e7.tar.zst
nixpkgs-b98b4eac71cfb0ccedc6d909fd58058bc1cb85e7.zip
tests: add some cross tests
Diffstat (limited to 'pkgs/test')
-rw-r--r--pkgs/test/cross/default.nix80
-rw-r--r--pkgs/test/default.nix2
2 files changed, 82 insertions, 0 deletions
diff --git a/pkgs/test/cross/default.nix b/pkgs/test/cross/default.nix
new file mode 100644
index 00000000000..6f41447ca76
--- /dev/null
+++ b/pkgs/test/cross/default.nix
@@ -0,0 +1,80 @@
+{ pkgs, pkgsCross, lib }:
+
+let
+
+  emulators = {
+    mingw32 = "WINEDEBUG=-all ${pkgs.winePackages.minimal}/bin/wine";
+    mingwW64 = "WINEDEBUG=-all ${pkgs.wineWowPackages.minimal}/bin/wine";
+    # TODO: add some qemu-based emulaltors here
+  };
+
+  getExecutable = pkgs: pkgFun: exec:
+    "${pkgFun pkgs}${exec}${pkgs.hostPlatform.extensions.executable}";
+
+  compareTest = { emulator, pkgFun, hostPkgs, crossPkgs, exec, args ? [] }: let
+    pkgName = (pkgFun hostPkgs).name;
+    args' = lib.concatStringsSep " " args;
+  in pkgs.runCommand "test-${pkgName}-${crossPkgs.hostPlatform.config}" {
+    nativeBuildInputs = [ pkgs.dos2unix ];
+  } ''
+    HOME=$(pwd)
+    mkdir -p $out
+
+    # We need to remove whitespace, unfortunately
+    # Windows programs use \r but Unix programs use \n
+
+    # find expected value natively
+    ${getExecutable hostPkgs pkgFun exec} ${args'} \
+      | dos2unix > $out/expected
+
+    # run emulator to get actual value
+    ${emulator} ${getExecutable crossPkgs pkgFun exec} ${args'} \
+      | dos2unix > $out/actual
+
+    if [ "$(cat $out/actual)" != "$(cat $out/expected)" ]; then
+      echo "${pkgName} did not output expected value:"
+      cat $out/expected
+      echo "instead it output:"
+      cat $out/actual
+      exit 1
+    else
+      echo "${pkgName} test passed"
+      echo "both produced output:"
+      cat $out/actual
+    fi
+  '';
+
+in
+
+lib.mapAttrs (name: emulator: let
+  crossPkgs = pkgsCross.${name};
+
+  # Apply some transformation on windows to get dlls in the right
+  # place. Unfortunately mingw doesn’t seem to be able to do linking
+  # properly.
+  platformFun = pkg: if crossPkgs.hostPlatform.isWindows then
+    pkgs.buildEnv {
+      name = "${pkg.name}-winlinks";
+      paths = [pkg] ++ pkg.buildInputs;
+    } else pkg;
+in {
+
+  hello = compareTest {
+    inherit emulator crossPkgs;
+    hostPkgs = pkgs;
+    exec = "/bin/hello";
+    pkgFun = pkgs: pkgs.hello;
+  };
+
+  file = compareTest {
+    inherit emulator crossPkgs;
+    hostPkgs = pkgs;
+    exec = "/bin/file";
+    args = [
+      "${pkgs.file}/share/man/man1/file.1.gz"
+      "${pkgs.dejavu_fonts}/share/fonts/truetype/DejaVuMathTeXGyre.ttf"
+    ];
+    pkgFun = pkgs: platformFun pkgs.file;
+  };
+
+}) emulators
diff --git a/pkgs/test/default.nix b/pkgs/test/default.nix
index 38f6cb8e564..d2e8e1c7314 100644
--- a/pkgs/test/default.nix
+++ b/pkgs/test/default.nix
@@ -23,4 +23,6 @@ with pkgs;
   cc-multilib-clang = callPackage ./cc-wrapper/multilib.nix { stdenv = clangMultiStdenv; };
 
   macOSSierraShared = callPackage ./macos-sierra-shared {};
+
+  cross = callPackage ./cross {};
 }