diff --git a/common/sanity-check b/common/sanity-check
new file mode 100755
index 0000000000000000000000000000000000000000..83bc192d651df02399bc98e0cb17b9feeb11e545
--- /dev/null
+++ b/common/sanity-check
@@ -0,0 +1,61 @@
+#!/bin/sh
+
+# sanity-check
+#
+# Verify that the Apertis system basically works.
+#
+# Please add more basic checks here as you run into situations where they fail
+
+# Copyright © 2015-2016 Collabora Ltd.
+#
+# SPDX-License-Identifier: MPL-2.0
+# This Source Code Form is subject to the terms of the Mozilla Public
+# License, v. 2.0. If a copy of the MPL was not distributed with this
+# file, You can obtain one at http://mozilla.org/MPL/2.0/.
+
+set -e
+
+failed=0
+
+fail () {
+    failed=1
+    tag="$1"
+    shift
+    echo "TEST_RESULT:fail:$tag:$*" >&2
+}
+
+getent passwd root || fail getent-passwd-root
+getent passwd user || fail getent-passwd-user
+
+env || fail lava-env
+common/run-test-in-systemd --name=system-env common/sanity-check-env system || :
+common/run-test-in-systemd --name=user-env --user=user common/sanity-check-env user || :
+
+id || fail lava-id
+common/run-test-in-systemd --name=system-id id || :
+common/run-test-in-systemd --name=user-id id || :
+
+test -S /run/dbus/system_bus_socket || fail system-bus-is-up
+test -d /run/user/$(id -u user)/systemd || fail user-session-is-up
+test -S /run/user/$(id -u user)/bus || fail user-bus-is-up
+
+test -e /etc/debian_version || fail has-debian_version
+cat /etc/os-release || fail os-release
+# These two should really test for Apertis, but that would currently
+# fail - see https://phabricator.apertis.org/T133 - so they also
+# allow Ubuntu
+grep -E '^NAME=("?)(Apertis|Ubuntu)\1$' /etc/os-release || fail os-release-name
+grep -E '^ID=("?)(apertis|ubuntu)\1$' /etc/os-release || fail os-release-id
+
+if ! test -S /run/user/$(id -u user)/wayland-0; then
+    common/run-test-in-systemd --user=user --name=x11-works -- xterm -e /bin/true
+fi
+
+if test "x$failed" != "x0"; then
+    echo "Failed, see above for details" >&2
+    exit "$failed"
+fi
+
+exit 0
+
+# vim:set sw=4 sts=4 et:
diff --git a/common/sanity-check.yaml b/common/sanity-check.yaml
index eea46836b38fba4ea4415b505baa79052f6b7313..8382ef75c7c09ddd6083df75cc8219a3c6a510fe 100644
--- a/common/sanity-check.yaml
+++ b/common/sanity-check.yaml
@@ -8,36 +8,9 @@ metadata:
   environment:
   - lava-test-shell
 
-# please add more basic checks here as you run into situations where they fail
 run:
   steps:
-    - "lava-test-case getent-passwd-root --shell getent passwd root"
-    - "lava-test-case getent-passwd-user --shell getent passwd user"
-
-    - "lava-test-case lava-env --shell env"
-    - "common/run-test-in-systemd --name=system-env common/sanity-check-env system"
-    - "common/run-test-in-systemd --name=user-env --user=user common/sanity-check-env user"
-
-    - "lava-test-case lava-id --shell id"
-    - "common/run-test-in-systemd --name=system-id id"
-    - "common/run-test-in-systemd --name=user-id id"
-
-    - "lava-test-case system-bus-is-up --shell test -S /run/dbus/system_bus_socket"
-    - "lava-test-case user-session-is-up --shell test -d /run/user/1000/systemd"
-    - "lava-test-case user-bus-is-up --shell test -S /run/user/1000/bus"
-
-    - "lava-test-case has-debian_version --shell test -e /etc/debian_version"
-    - "lava-test-case os-release --shell cat /etc/os-release"
-    # do this in r-t-i-s because l-t-c has trouble with backslashes
-    # These two should really test for Apertis, but that would currently
-    # fail - see https://phabricator.apertis.org/T133 - so they also
-    # allow Ubuntu
-    - "common/run-test-in-systemd --name=os-release-name grep -E '^NAME=(\"?)(Apertis|Ubuntu)\\1$' /etc/os-release"
-    - "common/run-test-in-systemd --name=os-release-id grep -E '^ID=(\"?)(apertis|ubuntu)\\1$' /etc/os-release"
-
-    # run this as the user so we don't require cross-uid X11 sharing
-    # skip it if we are (meant to be) using Wayland
-    - "test -S /run/user/1000/wayland-0 || common/run-test-in-systemd --user=user --name=x11-works -- xterm -e /bin/true"
+    - "lava-test-case sanity-check --shell common/sanity-check"
 
 parse:
   pattern: 'TEST_RESULT:(?P<result>\w+):(?P<test_case_id>[^:]+):'