diff --git a/tests/compat.sh b/tests/compat.sh
index 49e7ee56d..61866628d 100755
--- a/tests/compat.sh
+++ b/tests/compat.sh
@@ -1049,6 +1049,11 @@ run_client() {
 # MAIN
 #
 
+if cd $( dirname $0 ); then :; else
+    echo "cd $( dirname $0 ) failed" >&2
+    exit 1
+fi
+
 get_options "$@"
 
 # sanity checks, avoid an avalanche of errors
diff --git a/tests/ssl-opt.sh b/tests/ssl-opt.sh
index b54b777c4..2c0c9ffd3 100755
--- a/tests/ssl-opt.sh
+++ b/tests/ssl-opt.sh
@@ -460,6 +460,11 @@ cleanup() {
 # MAIN
 #
 
+if cd $( dirname $0 ); then :; else
+    echo "cd $( dirname $0 ) failed" >&2
+    exit 1
+fi
+
 get_options "$@"
 
 # sanity checks, avoid an avalanche of errors