]> git.proxmox.com Git - systemd.git/commitdiff
logind autopkgtest: Add test for suspending on lid switch close
authorMartin Pitt <martin.pitt@ubuntu.com>
Sat, 18 Apr 2015 08:10:01 +0000 (09:10 +0100)
committerMartin Pitt <martin.pitt@ubuntu.com>
Sat, 18 Apr 2015 15:57:51 +0000 (16:57 +0100)
This reproduces LP #1444166 (lid switch not working in the first few minutes
after boot).

debian/changelog
debian/tests/control
debian/tests/lidswitch.evemu [new file with mode: 0644]
debian/tests/logind

index 2ebbdc50be47e2c9236867fa12fe4faa2fbc6f59..d619aa7c63c9d4f61a884d25aad66f6ba1f2c14f 100644 (file)
@@ -11,6 +11,9 @@ systemd (219-8) UNRELEASED; urgency=medium
   [ Martin Pitt ]
   * cryptsetup: Implement offset and skip options. (Closes: #751707,
     LP: #953875)
+  * logind autopkgtest: Add test for suspending on lid switch close.
+    This reproduces LP #1444166 (lid switch not working in the first few
+    minutes after boot).
 
  -- Michael Biebl <biebl@debian.org>  Mon, 13 Apr 2015 20:46:34 +0200
 
index 1ced344eab862894993255757579565ea426f5bd..09c7b7b5bcb783df13c0560eb0cff9170cba6b05 100644 (file)
@@ -1,7 +1,11 @@
-Tests: timedated, hostnamed, localed-locale, localed-x11-keymap, logind
+Tests: timedated, hostnamed, localed-locale, localed-x11-keymap
 Depends: systemd, libpam-systemd, acl, locales
 Restrictions: needs-root, isolation-container
 
+Tests: logind
+Depends: systemd, libpam-systemd, acl, locales, evemu-tools
+Restrictions: needs-root, isolation-machine
+
 Tests: bootchart
 Depends: systemd, libpam-systemd, acl, locales
 Restrictions: needs-root, isolation-machine, breaks-testbed
diff --git a/debian/tests/lidswitch.evemu b/debian/tests/lidswitch.evemu
new file mode 100644 (file)
index 0000000..de1d590
--- /dev/null
@@ -0,0 +1,34 @@
+# EVEMU 1.2
+# Input device name: "Lid Switch"
+# Input device ID: bus 0x19 vendor 0000 product 0x05 version 0000
+# Supported events:
+#   Event type 0 (EV_SYN)
+#     Event code 0 (SYN_REPORT)
+#     Event code 5 (FF_STATUS_MAX)
+#   Event type 5 (EV_SW)
+#     Event code 0 (SW_LID)
+# Properties:
+N: Fake Lid Switch
+I: 0019 0000 0005 0000
+P: 00 00 00 00 00 00 00 00
+B: 00 21 00 00 00 00 00 00 00
+B: 01 00 00 00 00 00 00 00 00
+B: 01 00 00 00 00 00 00 00 00
+B: 01 00 00 00 00 00 00 00 00
+B: 01 00 00 00 00 00 00 00 00
+B: 01 00 00 00 00 00 00 00 00
+B: 01 00 00 00 00 00 00 00 00
+B: 01 00 00 00 00 00 00 00 00
+B: 01 00 00 00 00 00 00 00 00
+B: 01 00 00 00 00 00 00 00 00
+B: 01 00 00 00 00 00 00 00 00
+B: 01 00 00 00 00 00 00 00 00
+B: 01 00 00 00 00 00 00 00 00
+B: 02 00 00 00 00 00 00 00 00
+B: 03 00 00 00 00 00 00 00 00
+B: 04 00 00 00 00 00 00 00 00
+B: 05 01 00 00 00 00 00 00 00
+B: 11 00 00 00 00 00 00 00 00
+B: 12 00 00 00 00 00 00 00 00
+B: 15 00 00 00 00 00 00 00 00
+B: 15 00 00 00 00 00 00 00 00
index 4aaa6a572c82113836b23b83876d7d957288f841..3d9ae69669fee3142974ca519dc74449d081635c 100755 (executable)
@@ -1,6 +1,22 @@
 #!/bin/sh
 set -e
 
+# args: <timeout>
+wait_suspend() {
+    timeout=$1
+    while [ $timeout -gt 0 ] && [ ! -e /run/suspend.flag ]; do
+        sleep 1
+        timeout=$((timeout - 1))
+        [ $(($timeout % 5)) -ne 0 ] || echo "   waiting for suspend, ${timeout}s remaining..."
+    done
+    if [ ! -e /run/suspend.flag ]; then
+        echo "closing lid did not cause suspend" >&2
+        exit 1
+    fi
+    rm /run/suspend.flag
+    echo " * closing lid caused suspend"
+}
+
 echo " * process is in session cgroup"
 grep 'systemd:.*session.*scope' /proc/self/cgroup
 echo " * daemon is started"
@@ -11,6 +27,55 @@ pidof systemd-logind > /dev/null
 echo " * loginctl succeeds"
 OUT=`loginctl`
 
+# cleanup handler
+trap 'rm -f /run/udev/rules.d/70-logindtest-*.rules; udevadm control --reload;
+      kill $KILL_PID;
+      rm /run/systemd/system/systemd-suspend.service;
+      if [ -d /sys/module/scsi_debug ]; then rmmod scsi_debug 2>/dev/null || (sleep 2; rmmod scsi_debug ) || true; fi' \
+              EXIT INT QUIT TERM PIPE
+
+# watch what's going on
+journalctl -f -u systemd-logind.service &
+KILL_PID="$KILL_PID $!"
+
+# create fake suspend
+U=$(systemctl cat systemd-suspend.service | sed '/^ExecStart=/ s_=.*$_=/bin/touch /run/suspend.flag_')
+echo "$U" > /run/systemd/system/systemd-suspend.service
+sync
+systemctl daemon-reload
+
+# create fake lid switch
+mkdir -p /run/udev/rules.d
+echo 'SUBSYSTEM=="input", KERNEL=="event*", ATTRS{name}=="Fake Lid Switch", TAG+="power-switch"' \
+    > /run/udev/rules.d/70-logindtest-lid.rules
+sync
+udevadm control --reload
+evemu-device $(dirname $0)/lidswitch.evemu &
+KILL_PID="$KILL_PID $!"
+while [ -z "$O" ]; do
+    sleep 0.1
+    O=$(grep -l '^Fake Lid Switch' /sys/class/input/*/device/name)
+done
+O=${O%/device/name}
+LID_DEV=/dev/${O#/sys/class/}
+
+# close lid
+evemu-event $LID_DEV --sync --type 5 --code 0 --value 1
+#FIXME: fix lid switch to work immediately (LP #1444166)
+wait_suspend 180
+
+# open lid again
+evemu-event $LID_DEV --sync --type 5 --code 0 --value 0
+
+echo " * waiting for 30s inhibition time between suspends"
+sleep 30
+
+# now closing lid should cause instant suspend
+evemu-event $LID_DEV --sync --type 5 --code 0 --value 1
+wait_suspend 2
+evemu-event $LID_DEV --sync --type 5 --code 0 --value 0
+
+# ACL tests
 if ! echo "$OUT" | grep -q "seat0"; then
     echo "Skipping ACL tests, as there is no seat"
     exit 0
@@ -25,13 +90,11 @@ echo "seat user: $USER"
 
 # we use scsi_debug to create new devices which we can put ACLs on
 # tell udev about the tagging, so that logind can pick it up
-mkdir -p /run/udev/rules.d/
-cat <<EOF > /run/udev/rules.d/60-scsi_debug-user.rules
+cat <<EOF > /run/udev/rules.d/70-logindtest-scsi_debug-user.rules
 SUBSYSTEM=="block", ATTRS{model}=="scsi_debug*", TAG+="uaccess"
 EOF
-trap "rm -f /run/udev/rules.d/60-scsi_debug-user.rules; pkill -HUP udevd || pkill -HUP systemd-udevd; rmmod scsi_debug 2>/dev/null || ( sleep 2; rmmod scsi_debug ) || true" 0 INT QUIT TERM PIPE
 sync
-pkill -HUP udevd || pkill -HUP systemd-udevd
+udevadm control --reload
 
 echo " * coldplug: logind started with existing device"
 killall systemd-logind