about summary refs log tree commit diff
path: root/nixos/tests
diff options
context:
space:
mode:
authorVladimír Čunát <vcunat@gmail.com>2016-04-07 14:35:03 +0200
committerVladimír Čunát <vcunat@gmail.com>2016-04-07 14:40:51 +0200
commitd1df28f8e5b98be01417ffc1032020415390f2a0 (patch)
tree0e2024acd74c6ce3fb4614eadb04abe632835f71 /nixos/tests
parent056b5a1a5f2a4096dd39db2265e5ca369c03ec15 (diff)
parentc55cfe0cb3425fb926219cf7dde8714f3d143744 (diff)
downloadnixlib-d1df28f8e5b98be01417ffc1032020415390f2a0.tar
nixlib-d1df28f8e5b98be01417ffc1032020415390f2a0.tar.gz
nixlib-d1df28f8e5b98be01417ffc1032020415390f2a0.tar.bz2
nixlib-d1df28f8e5b98be01417ffc1032020415390f2a0.tar.lz
nixlib-d1df28f8e5b98be01417ffc1032020415390f2a0.tar.xz
nixlib-d1df28f8e5b98be01417ffc1032020415390f2a0.tar.zst
nixlib-d1df28f8e5b98be01417ffc1032020415390f2a0.zip
Merge 'staging' into closure-size
This is mainly to get the update of bootstrap tools.
Otherwise there were mysterious segfaults:
https://github.com/NixOS/nixpkgs/pull/7701#issuecomment-203389817
Diffstat (limited to 'nixos/tests')
-rw-r--r--nixos/tests/ec2.nix19
-rw-r--r--nixos/tests/keymap.nix160
2 files changed, 173 insertions, 6 deletions
diff --git a/nixos/tests/ec2.nix b/nixos/tests/ec2.nix
index 0a95d6cfeff4..e1f7143e3a95 100644
--- a/nixos/tests/ec2.nix
+++ b/nixos/tests/ec2.nix
@@ -11,7 +11,6 @@ let
       modules = [
         ../maintainers/scripts/ec2/amazon-image.nix
         ../modules/testing/test-instrumentation.nix
-        ../modules/profiles/minimal.nix
         ../modules/profiles/qemu-guest.nix
         { ec2.hvm = true;
 
@@ -21,6 +20,14 @@ let
               ln -s vda /dev/xvda
               ln -s vda1 /dev/xvda1
             '';
+
+          # Needed by nixos-rebuild due to the lack of network
+          # access. Mostly copied from
+          # modules/profiles/installation-device.nix.
+          system.extraDependencies =
+            [ pkgs.stdenv pkgs.busybox pkgs.perlPackages.ArchiveCpio
+              pkgs.unionfs-fuse pkgs.mkinitcpio-nfs-utils
+            ];
         }
       ];
     }).config.system.build.amazonImage;
@@ -30,9 +37,8 @@ let
       metaData = pkgs.stdenv.mkDerivation {
         name = "metadata";
         buildCommand = ''
-          mkdir -p $out/2011-01-01
-          ln -s ${pkgs.writeText "userData" userData} $out/2011-01-01/user-data
           mkdir -p $out/1.0/meta-data
+          ln -s ${pkgs.writeText "userData" userData} $out/1.0/user-data
           echo "${hostname}" > $out/1.0/meta-data/hostname
           echo "(unknown)" > $out/1.0/meta-data/ami-manifest-path
         '' + optionalString (sshPublicKey != null) ''
@@ -48,7 +54,7 @@ let
           my $imageDir = ($ENV{'TMPDIR'} // "/tmp") . "/vm-state-machine";
           mkdir $imageDir, 0700;
           my $diskImage = "$imageDir/machine.qcow2";
-          system("qemu-img create -f qcow2 -o backing_file=${image}/nixos.img $diskImage") == 0 or die;
+          system("qemu-img create -f qcow2 -o backing_file=${image}/nixos.qcow2 $diskImage") == 0 or die;
           system("qemu-img resize $diskImage 10G") == 0 or die;
 
           # Note: we use net=169.0.0.0/8 rather than
@@ -91,7 +97,7 @@ in {
     '';
     script = ''
       $machine->start;
-      $machine->waitForFile("/root/user-data");
+      $machine->waitForFile("/etc/ec2-metadata/user-data");
       $machine->waitForUnit("sshd.service");
 
       $machine->succeed("grep unknown /etc/ec2-metadata/ami-manifest-path");
@@ -121,7 +127,7 @@ in {
       # Just to make sure resizing is idempotent.
       $machine->shutdown;
       $machine->start;
-      $machine->waitForFile("/root/user-data");
+      $machine->waitForFile("/etc/ec2-metadata/user-data");
     '';
   };
 
@@ -135,6 +141,7 @@ in {
         imports = [
           <nixpkgs/nixos/modules/virtualisation/amazon-image.nix>
           <nixpkgs/nixos/modules/testing/test-instrumentation.nix>
+          <nixpkgs/nixos/modules/profiles/qemu-guest.nix>
         ];
         environment.etc.testFile = {
           text = "whoa";
diff --git a/nixos/tests/keymap.nix b/nixos/tests/keymap.nix
new file mode 100644
index 000000000000..55a0e7603882
--- /dev/null
+++ b/nixos/tests/keymap.nix
@@ -0,0 +1,160 @@
+{ system ? builtins.currentSystem }:
+
+with import ../lib/testing.nix { inherit system; };
+
+let
+  testReader = pkgs.writeScript "test-input-reader" ''
+    #!${pkgs.stdenv.shell}
+    readInput() {
+      touch /tmp/reader.ready
+      echo "Waiting for '$1' to be typed"
+      read -r -n1 c
+      if [ "$c" = "$2" ]; then
+        echo "SUCCESS: Got back '$c' as expected."
+        echo 0 >&2
+      else
+        echo "FAIL: Expected '$2' but got '$c' instead."
+        echo 1 >&2
+      fi
+    }
+
+    main() {
+      error=0
+      while [ $# -gt 0 ]; do
+        ret="$((readInput "$2" "$3" | systemd-cat -t "$1") 2>&1)"
+        if [ $ret -ne 0 ]; then error=1; fi
+        shift 3
+      done
+      return $error
+    }
+
+    main "$@"; echo -n $? > /tmp/reader.exit
+  '';
+
+  mkReaderInput = testname: { qwerty, expect }: with pkgs.lib; let
+    lq = length qwerty;
+    le = length expect;
+    msg = "`qwerty' (${lq}) and `expect' (${le}) lists"
+        + " need to be of the same length!";
+    result = flatten (zipListsWith (a: b: [testname a b]) qwerty expect);
+  in if lq != le then throw msg else result;
+
+  mkKeyboardTest = layout: { extraConfig ? {}, tests }: with pkgs.lib; let
+    readerInput = flatten (mapAttrsToList mkReaderInput tests);
+    perlStr = val: "'${escape ["'" "\\"] val}'";
+    perlReaderInput = concatMapStringsSep ", " perlStr readerInput;
+  in makeTest {
+    name = "keymap-${layout}";
+
+    machine.i18n.consoleKeyMap = mkOverride 900 layout;
+    machine.services.xserver.layout = mkOverride 900 layout;
+    machine.imports = [ ./common/x11.nix extraConfig ];
+
+    testScript = ''
+      sub waitCatAndDelete ($) {
+        return $machine->succeed(
+          "for i in \$(seq 600); do if [ -e '$_[0]' ]; then ".
+          "cat '$_[0]' && rm -f '$_[0]' && exit 0; ".
+          "fi; sleep 0.1; done; echo timed out after 60 seconds >&2; exit 1"
+        );
+      };
+
+      sub mkTest ($$) {
+        my ($desc, $cmd) = @_;
+
+        my @testdata = (${perlReaderInput});
+        my $shellTestdata = join ' ', map { "'".s/'/'\\'''/gr."'" } @testdata;
+
+        subtest $desc, sub {
+          $machine->succeed("$cmd ${testReader} $shellTestdata &");
+          while (my ($testname, $qwerty, $expect) = splice(@testdata, 0, 3)) {
+            waitCatAndDelete "/tmp/reader.ready";
+            $machine->sendKeys($qwerty);
+          };
+          my $exitcode = waitCatAndDelete "/tmp/reader.exit";
+          die "tests for $desc failed" if $exitcode ne 0;
+        };
+      }
+
+      $machine->waitForX;
+
+      mkTest "VT keymap", "openvt -sw --";
+      mkTest "Xorg keymap", "DISPLAY=:0 xterm -fullscreen -e";
+    '';
+  };
+
+in pkgs.lib.mapAttrs mkKeyboardTest {
+  azerty = {
+    tests = {
+      azqw.qwerty = [ "q" "w" ];
+      azqw.expect = [ "a" "z" ];
+      altgr.qwerty = [ "alt_r-2" "alt_r-3" "alt_r-4" "alt_r-5" "alt_r-6" ];
+      altgr.expect = [ "~"       "#"       "{"       "["       "|"       ];
+    };
+
+    extraConfig.i18n.consoleKeyMap = "azerty/fr";
+    extraConfig.services.xserver.layout = "fr";
+  };
+
+  colemak = {
+    tests = {
+      homerow.qwerty = [ "a" "s" "d" "f" "j" "k" "l" "semicolon" ];
+      homerow.expect = [ "a" "r" "s" "t" "n" "e" "i" "o"         ];
+    };
+
+    extraConfig.i18n.consoleKeyMap = "en-latin9";
+    extraConfig.services.xserver.layout = "us";
+    extraConfig.services.xserver.xkbVariant = "colemak";
+  };
+
+  dvorak = {
+    tests = {
+      homerow.qwerty = [ "a" "s" "d" "f" "j" "k" "l" "semicolon" ];
+      homerow.expect = [ "a" "o" "e" "u" "h" "t" "n" "s"         ];
+      symbols.qwerty = [ "q" "w" "e" "minus" "equal" ];
+      symbols.expect = [ "'" "," "." "["     "]"     ];
+    };
+  };
+
+  dvp = {
+    tests = {
+      homerow.qwerty = [ "a" "s" "d" "f" "j" "k" "l" "semicolon" ];
+      homerow.expect = [ "a" "o" "e" "u" "h" "t" "n" "s"         ];
+      numbers.qwerty = map (x: "shift-${x}")
+                       [ "1" "2" "3" "4" "5" "6" "7" "8" "9" "0" "minus" ];
+      numbers.expect = [ "%" "7" "5" "3" "1" "9" "0" "2" "4" "6" "8" ];
+      symbols.qwerty = [ "1" "2" "3" "4" "5" "6" "7" "8" "9" "0" "minus" ];
+      symbols.expect = [ "&" "[" "{" "}" "(" "=" "*" ")" "+" "]" "!" ];
+    };
+
+    extraConfig.services.xserver.layout = "us";
+    extraConfig.services.xserver.xkbVariant = "dvp";
+  };
+
+  neo = {
+    tests = {
+      layer1.qwerty = [ "f"           "j"                     ];
+      layer1.expect = [ "e"           "n"                     ];
+      layer2.qwerty = [ "shift-f"     "shift-j"     "shift-6" ];
+      layer2.expect = [ "E"           "N"           "$"       ];
+      layer3.qwerty = [ "caps_lock-d" "caps_lock-f"           ];
+      layer3.expect = [ "{"           "}"                     ];
+    };
+
+    extraConfig.services.xserver.layout = "de";
+    extraConfig.services.xserver.xkbVariant = "neo";
+  };
+
+  qwertz = {
+    tests = {
+      zy.qwerty = [ "z" "y" ];
+      zy.expect = [ "y" "z" ];
+      altgr.qwerty = map (x: "alt_r-${x}")
+                     [ "q" "less" "7" "8" "9" "0" ];
+      altgr.expect = [ "@" "|"    "{" "[" "]" "}" ];
+    };
+
+    extraConfig.i18n.consoleKeyMap = "de";
+    extraConfig.services.xserver.layout = "de";
+  };
+}