diff --git a/tests/capabilityschematest b/tests/capabilityschematest
index 4439842..78fbc8e 100755
--- a/tests/capabilityschematest
+++ b/tests/capabilityschematest
@@ -1,6 +1,6 @@
 #!/bin/sh
 
-: ${srcdir=.}
+: ${srcdir=$(dirname $0)}
 . $srcdir/test-lib.sh
 . $abs_srcdir/schematestutils.sh
 
diff --git a/tests/domaincapsschematest b/tests/domaincapsschematest
index 9baf44a..2c19ac4 100755
--- a/tests/domaincapsschematest
+++ b/tests/domaincapsschematest
@@ -1,6 +1,6 @@
 #!/bin/sh
 
-: ${srcdir=.}
+: ${srcdir=$(dirname $0)}
 . $srcdir/test-lib.sh
 . $abs_srcdir/schematestutils.sh
 
diff --git a/tests/domainschematest b/tests/domainschematest
index ba90180..31ee536 100755
--- a/tests/domainschematest
+++ b/tests/domainschematest
@@ -1,6 +1,6 @@
 #!/bin/sh
 
-: ${srcdir=.}
+: ${srcdir=$(dirname $0)}
 . $srcdir/test-lib.sh
 . $abs_srcdir/schematestutils.sh
 
diff --git a/tests/domainsnapshotschematest b/tests/domainsnapshotschematest
index 1bdc539..ba28e05 100755
--- a/tests/domainsnapshotschematest
+++ b/tests/domainsnapshotschematest
@@ -1,6 +1,6 @@
 #!/bin/sh
 
-: ${srcdir=.}
+: ${srcdir=$(dirname $0)}
 . $srcdir/test-lib.sh
 . $abs_srcdir/schematestutils.sh
 
diff --git a/tests/interfaceschematest b/tests/interfaceschematest
index 1ddbc53..47745ea 100755
--- a/tests/interfaceschematest
+++ b/tests/interfaceschematest
@@ -1,6 +1,6 @@
 #!/bin/sh
 
-: ${srcdir=.}
+: ${srcdir=$(dirname $0)}
 . $srcdir/test-lib.sh
 . $abs_srcdir/schematestutils.sh
 
diff --git a/tests/networkschematest b/tests/networkschematest
index 46f3fc5..fe46893 100755
--- a/tests/networkschematest
+++ b/tests/networkschematest
@@ -1,6 +1,6 @@
 #!/bin/sh
 
-: ${srcdir=.}
+: ${srcdir=$(dirname $0)}
 . $srcdir/test-lib.sh
 . $abs_srcdir/schematestutils.sh
 
diff --git a/tests/nodedevschematest b/tests/nodedevschematest
index 03a1577..07b1f7b 100755
--- a/tests/nodedevschematest
+++ b/tests/nodedevschematest
@@ -1,6 +1,6 @@
 #!/bin/sh
 
-: ${srcdir=.}
+: ${srcdir=$(dirname $0)}
 . $srcdir/test-lib.sh
 . $abs_srcdir/schematestutils.sh
 
diff --git a/tests/nwfilterschematest b/tests/nwfilterschematest
index 2c50c03..8703e21 100755
--- a/tests/nwfilterschematest
+++ b/tests/nwfilterschematest
@@ -1,6 +1,6 @@
 #!/bin/sh
 
-: ${srcdir=.}
+: ${srcdir=$(dirname $0)}
 . $srcdir/test-lib.sh
 . $abs_srcdir/schematestutils.sh
 
diff --git a/tests/secretschematest b/tests/secretschematest
index f64d1a3..23b0e2f 100755
--- a/tests/secretschematest
+++ b/tests/secretschematest
@@ -1,6 +1,6 @@
 #!/bin/sh
 
-: ${srcdir=.}
+: ${srcdir=$(dirname $0)}
 . $srcdir/test-lib.sh
 . $abs_srcdir/schematestutils.sh
 
diff --git a/tests/storagepoolschematest b/tests/storagepoolschematest
index d54b827..ebea711 100755
--- a/tests/storagepoolschematest
+++ b/tests/storagepoolschematest
@@ -1,6 +1,6 @@
 #!/bin/sh
 
-: ${srcdir=.}
+: ${srcdir=$(dirname $0)}
 . $srcdir/test-lib.sh
 . $abs_srcdir/schematestutils.sh
 
diff --git a/tests/storagevolschematest b/tests/storagevolschematest
index 9045e6b..395df57 100755
--- a/tests/storagevolschematest
+++ b/tests/storagevolschematest
@@ -1,6 +1,6 @@
 #!/bin/sh
 
-: ${srcdir=.}
+: ${srcdir=$(dirname $0)}
 . $srcdir/test-lib.sh
 . $abs_srcdir/schematestutils.sh
 
diff --git a/tests/test-lib.sh b/tests/test-lib.sh
index aff179c..920b01e 100644
--- a/tests/test-lib.sh
+++ b/tests/test-lib.sh
@@ -18,10 +18,11 @@
 #
 # Based on an idea from GNU coreutils
 
-test -z "$abs_srcdir" && abs_srcdir=$(pwd)
-test -z "$abs_builddir" && abs_builddir=$(pwd)
-test -z "$abs_top_srcdir" && abs_top_srcdir=$(pwd)/..
-test -z "$abs_top_builddir" && abs_top_builddir=$(pwd)/..
+_scriptdir="$(realpath $(dirname $0))"
+test -z "$abs_srcdir" && abs_srcdir=$_scriptdir
+test -z "$abs_builddir" && abs_builddir=$_scriptdir
+test -z "$abs_top_srcdir" && abs_top_srcdir=$_scriptdir/..
+test -z "$abs_top_builddir" && abs_top_builddir=$_scriptdir/..
 test -z "$LC_ALL" && LC_ALL=C
 
 # Skip this test if the shell lacks support for functions.
