--- /dev/null
+#!/bin/sh
+
+set -ex
+
+# Make a test user account
+useradd -m testuser
+
+# Give that user a ~/.dmrc that selects the session type under test
+cat >> /home/testuser/.dmrc << EOF
+[Desktop]
+Session=xsession-traditional
+EOF
+chown testuser:testuser /home/testuser/.dmrc
+chmod 644 /home/testuser/.dmrc
+
+# Make the user's ~/.xsession write to a named pipe to prove that it
+# ran. Then it just sleeps in a loop, to avoid ending the session and
+# worrying lightdm.
+cat >> /home/testuser/.xsession << EOF
+#!/bin/sh
+echo 'Hello from the test .xsession!' > /home/testuser/fifo
+while :; do sleep 60; done
+EOF
+chown testuser:testuser /home/testuser/.xsession
+chmod 755 /home/testuser/.xsession
+mkfifo -m 0666 /home/testuser/fifo
+
+# Configure lightdm to auto-login as the test user, to avoid needing
+# interactive input to the test run
+cat > /etc/lightdm/lightdm.conf << EOF
+[Seat:*]
+autologin-guest=false
+autologin-user=testuser
+autologin-user-timeout=0
+EOF
+
+# Now start lightdm, which should log in as testuser, which should run
+# testuser's .xsession, which should create the file saying it worked.
+systemctl start lightdm
+
+# Read from the fifo, and expect to see the hello message.
+#
+# It would be nice to somehow detect conditions that proved the test
+# _hadn't_ worked, e.g. by accidentally launching some other session
+# type. Then this test could be made to fail quickly. But I can't
+# think of any sensible way to do that, so instead I just use a crude
+# timeout.
+timeout 5m cat /home/testuser/fifo >&2