The test suite used to be called from the top_srcdir with the previous
build system based on only autoconf. With the switch to use automake,
the tests are run from each subdirectory, which means the paths used
for the executables and data files no longer resolve.

Use the opportunity to make them aware of the srcdir vs builddir
distinction so that out-of-tree builds can be supported in the future.
---
 checks/Makefile.am              |  3 ++-
 checks/check_compiler.sh        |  5 ++++-
 checks/check_date.c             | 14 ++++++++++++
 checks/check_fakesmsc.sh        |  6 +++---
 checks/check_fakewap.sh         | 10 ++++-----
 checks/check_headers.sh         |  2 +-
 checks/check_http.sh            | 20 ++++++++---------
 checks/check_httpsmsc_kannel.sh | 10 ++++-----
 checks/check_ppg.sh             | 38 ++++++++++++++++-----------------
 checks/check_sendsms.sh         | 16 +++++++-------
 checks/check_smpp.sh            |  4 ++--
 11 files changed, 73 insertions(+), 55 deletions(-)

diff --git a/checks/Makefile.am b/checks/Makefile.am
index d63fa104..faf50d77 100644
--- a/checks/Makefile.am
+++ b/checks/Makefile.am
@@ -28,4 +28,5 @@ dist_noinst_DATA = \
        test_dates
 
 check: all $(SUBDIRS)
-       $(top_builddir)/utils/run-checks $(PROGRAMS) $(SCRIPTS)
+       top_srcdir="$(top_srcdir)" top_builddir="$(top_builddir)" \
+               $(top_srcdir)/utils/run-checks $(PROGRAMS) $(SCRIPTS)
diff --git a/checks/check_compiler.sh b/checks/check_compiler.sh
index a7cd666a..adf774c0 100755
--- a/checks/check_compiler.sh
+++ b/checks/check_compiler.sh
@@ -4,7 +4,10 @@
 
 set -e
 
-test/wml_tester -b test/testcase.wml | test/decompile | diff test/testcase.wml 
- > check_compiler.log 2>&1
+$top_builddir/test/wml_tester -b $top_srcdir/test/testcase.wml \
+  | $top_builddir/test/decompile \
+  | diff $top_srcdir/test/testcase.wml - \
+  > check_compiler.log 2>&1
 ret=$?
 
 if [ "$ret" != 0 ]
diff --git a/checks/check_date.c b/checks/check_date.c
index f8a2c76e..3cbc3d36 100644
--- a/checks/check_date.c
+++ b/checks/check_date.c
@@ -61,6 +61,8 @@
 #include "gw-config.h"
 
 #include <string.h>
+#include <stdlib.h>
+#include <unistd.h>
 
 #include "gwlib/gwlib.h"
 
@@ -76,6 +78,18 @@ static void check_reversible(void)
     long pos, endpos, tabpos;
     Octstr *date, *canondate;
     long timeval;
+    const char *srcdir;
+
+    srcdir = getenv("top_srcdir");
+    if (srcdir == NULL) {
+        warning(0, "Could not get top_srcdir environment variable");
+        exit(1);
+    }
+
+    if (chdir(srcdir) < 0) {
+        warning(0, "Could not change directory to top_srcdir");
+        exit(1);
+    }
 
     dates = octstr_read_file("checks/test_dates");
     if (dates == NULL)
diff --git a/checks/check_fakesmsc.sh b/checks/check_fakesmsc.sh
index 8c097704..915bb8c6 100755
--- a/checks/check_fakesmsc.sh
+++ b/checks/check_fakesmsc.sh
@@ -10,15 +10,15 @@ interval=0
 loglevel=0
 host=127.0.0.1
 
-gw/bearerbox -v $loglevel gw/smskannel.conf > check_fakesmsc_bb.log 2>&1 &
+$top_builddir/gw/bearerbox -v $loglevel $top_srcdir/gw/smskannel.conf > 
check_fakesmsc_bb.log 2>&1 &
 bbpid=$!
 sleep 2
 
-test/fakesmsc -H $host -r 20000 -i $interval -m $times '123 234 text nop' \
+$top_builddir/test/fakesmsc -H $host -r 20000 -i $interval -m $times '123 234 
text nop' \
     > check_fakesmsc.log 2>&1 &
 sleep 1
 
-gw/smsbox -v $loglevel gw/smskannel.conf > check_fakesmsc_sms.log 2>&1 &
+$top_builddir/gw/smsbox -v $loglevel $top_srcdir/gw/smskannel.conf > 
check_fakesmsc_sms.log 2>&1 &
 
 running="yes"
 while [ $running = "yes" ]
diff --git a/checks/check_fakewap.sh b/checks/check_fakewap.sh
index 44403700..312dec7f 100755
--- a/checks/check_fakewap.sh
+++ b/checks/check_fakewap.sh
@@ -11,23 +11,23 @@ port=8040
 url="http://$host:$port/hello.wml";
 loglevel=0
 
-test/test_http_server -f test/hello.wml -p $port > check_http.log 2>&1 &
+$top_builddir/test/test_http_server -f $top_srcdir/test/hello.wml -p $port > 
check_http.log 2>&1 &
 httppid=$!
 
-gw/bearerbox -v $loglevel gw/wapkannel.conf > check_bb.log 2>&1 &
+$top_builddir/gw/bearerbox -v $loglevel $top_srcdir/gw/wapkannel.conf > 
check_bb.log 2>&1 &
 bbpid=$!
 
 sleep 2
 
-gw/wapbox -v $loglevel gw/wapkannel.conf > check_wap.log 2>&1 &
+$top_builddir/gw/wapbox -v $loglevel $top_srcdir/gw/wapkannel.conf > 
check_wap.log 2>&1 &
 wappid=$!
 
 sleep 2
 
-test/fakewap -g $host -m $times $url > check_fake.log 2>&1
+$top_builddir/test/fakewap -g $host -m $times $url > check_fake.log 2>&1
 ret=$?
 
-test/test_http -qv 4 http://$host:$port/quit
+$top_builddir/test/test_http -qv 4 http://$host:$port/quit
 
 kill -INT $bbpid 
 kill -INT $wappid
diff --git a/checks/check_headers.sh b/checks/check_headers.sh
index 89ef58a5..c35eb381 100755
--- a/checks/check_headers.sh
+++ b/checks/check_headers.sh
@@ -7,7 +7,7 @@ set -e
 
 loglevel=1
 
-test/test_headers -v $loglevel test/header_test > check_headers.log 2>&1
+$top_builddir/test/test_headers -v $loglevel $top_builddir/test/header_test > 
check_headers.log 2>&1
 ret=$?
 
 if [ "$ret" != 0 ] || \
diff --git a/checks/check_http.sh b/checks/check_http.sh
index 7565d49d..bba32844 100755
--- a/checks/check_http.sh
+++ b/checks/check_http.sh
@@ -15,26 +15,26 @@ url="http://$host:$port/foo.txt";
 url_ssl="https://$host:$port_ssl/foo.txt"; 
 quiturl="http://$host:$port/quit"; 
 quiturl_ssl="https://$host:$port_ssl/quit"; 
-ssl_cert="gw/cert.pem" 
-ssl_key="gw/key.pem" 
+ssl_cert="$top_srcdir/gw/cert.pem"
+ssl_key="$top_srcdir/gw/key.pem"
 ssl_clientcert="/tmp/clientcert.pem" 
 loglevel=0
 ssl_enabled="yes"
  
 cat $ssl_cert $ssl_key > $ssl_clientcert 
  
-test/test_http_server -p $port -v $loglevel > check_http_server.log 2>&1 & 
+$top_builddir/test/test_http_server -p $port -v $loglevel > 
check_http_server.log 2>&1 &
 serverpid=$! 
 sleep 1 
  
-test/test_http_server -p $port_ssl -v $loglevel -s -c $ssl_cert -k $ssl_key > 
check_https_server.log 2>&1 & 
+$top_builddir/test/test_http_server -p $port_ssl -v $loglevel -s -c $ssl_cert 
-k $ssl_key > check_https_server.log 2>&1 &
 serverpid_ssl=$!
 sleep 1 
  
-test/test_http -r $times $url > check_http.log 2>&1 
+$top_builddir/test/test_http -r $times $url > check_http.log 2>&1
 ret=$?
 
-test/test_http -r 1 -s -c $ssl_clientcert $url_ssl > check_https.log 2>&1 
+$top_builddir/test/test_http -r 1 -s -c $ssl_clientcert $url_ssl > 
check_https.log 2>&1
 ret=$? 
 
 if grep 'SSL not compiled in' check_https.log > /dev/null
@@ -46,18 +46,18 @@ fi
 if test "$ssl_enabled" = "yes"
 then
     echo -n ' checking SSL connections, too...'
-    test/test_http -r $times -s -c $ssl_clientcert $url_ssl > check_https.log 
2>&1 
+    $top_builddir/test/test_http -r $times -s -c $ssl_clientcert $url_ssl > 
check_https.log 2>&1
     ret=$?
 else
-    test/test_http -r 1 -s -c $ssl_clientcert $quiturl_ssl >> check_https.log 
2>&1
+    $top_builddir/test/test_http -r 1 -s -c $ssl_clientcert $quiturl_ssl >> 
check_https.log 2>&1
     rm -f check_https.log
     sleep 1
 fi
  
-test/test_http -r 1 $quiturl >> check_http.log 2>&1
+$top_builddir/test/test_http -r 1 $quiturl >> check_http.log 2>&1
 if test "$ssl_enabled" = "yes"
 then
-     test/test_http -r 1 -s -c $ssl_clientcert $quiturl_ssl >> check_https.log 
2>&1
+     $top_builddir/test/test_http -r 1 -s -c $ssl_clientcert $quiturl_ssl >> 
check_https.log 2>&1
      sleep 1
 fi
  
diff --git a/checks/check_httpsmsc_kannel.sh b/checks/check_httpsmsc_kannel.sh
index 40cc93a9..8de3a905 100755
--- a/checks/check_httpsmsc_kannel.sh
+++ b/checks/check_httpsmsc_kannel.sh
@@ -10,20 +10,20 @@ interval=0
 loglevel=0
 host=127.0.0.1
 
-gw/bearerbox -v $loglevel gw/smskannel.conf > check_httpsmsc_kannel_sbb.log 
2>&1 &
+$top_builddir/gw/bearerbox -v $loglevel $top_srcdir/gw/smskannel.conf > 
check_httpsmsc_kannel_sbb.log 2>&1 &
 sbbpid=$!
 sleep 1
 
-gw/bearerbox -v $loglevel gw/other_smskannel.conf > 
check_httpsmsc_kannel_cbb.log 2>&1 &
+$top_builddir/gw/bearerbox -v $loglevel $top_srcdir/gw/other_smskannel.conf > 
check_httpsmsc_kannel_cbb.log 2>&1 &
 cbbpid=$!
 sleep 2
 
-test/fakesmsc -H $host -i $interval -m $times '123 234 text relay nop' \
+$top_builddir/test/fakesmsc -H $host -i $interval -m $times '123 234 text 
relay nop' \
     > check_httpsmsc_kannel_fake.log 2>&1 &
 sleep 1
 
-gw/smsbox -v $loglevel gw/smskannel.conf > check_httpsmsc_kannel_ssb.log 2>&1 &
-gw/smsbox -v $loglevel gw/other_smskannel.conf > check_httpsmsc_kannel_csb.log 
2>&1 &
+$top_builddir/gw/smsbox -v $loglevel $top_srcdir/gw/smskannel.conf > 
check_httpsmsc_kannel_ssb.log 2>&1 &
+$top_builddir/gw/smsbox -v $loglevel $top_srcdir/gw/other_smskannel.conf > 
check_httpsmsc_kannel_csb.log 2>&1 &
 
 running="yes"
 while [ $running = "yes" ]
diff --git a/checks/check_ppg.sh b/checks/check_ppg.sh
index 73ee36aa..3e5f5085 100755
--- a/checks/check_ppg.sh
+++ b/checks/check_ppg.sh
@@ -21,7 +21,7 @@ password="bar"
 prefix="test"
 contents="sl" 
 # Kannel configuration file
-conf_file="gw/pushkannel.conf"
+conf_file="$top_srcdir/gw/pushkannel.conf"
 # Push content. Use only sl, because compilers should be tested separately
 content_file="$prefix/sl.txt"
 # Ok ip control files
@@ -38,7 +38,7 @@ blacklist="$prefix/blacklist.txt"
 whitelist="$prefix/whitelist.txt"
 
 sleep 1
-test/test_http_server -p $list_port -w $whitelist -b $blacklist > 
check_http_list.log 2>&1 & listid=$!
+$top_builddir/test/test_http_server -p $list_port -w $whitelist -b $blacklist 
> check_http_list.log 2>&1 & listid=$!
 error=no
 
 # ok control files requesting an ip bearer. Names contain string 'ip'. Bearer-
@@ -48,13 +48,13 @@ for control_file in $ip_control_files;
     do 
         if [ -f $control_file ]
         then
-            gw/bearerbox -v $loglevel $conf_file > check_bb.tmp 2>&1 & bbpid=$!
+            $top_builddir/gw/bearerbox -v $loglevel $conf_file > check_bb.tmp 
2>&1 & bbpid=$!
             sleep 2 
 
-            gw/wapbox -v $loglevel $conf_file > check_wap.tmp 2>&1 & wappid=$!
+            $top_builddir/gw/wapbox -v $loglevel $conf_file > check_wap.tmp 
2>&1 & wappid=$!
             sleep 2
 
-            test/test_ppg -c $contents 
http://$host:$push_port/cgi-bin/wap-push.cgi?username=$username'&'password=$password
 $content_file $control_file > check_ppg.tmp 2>&1 
+            $top_builddir/test/test_ppg -c $contents 
http://$host:$push_port/cgi-bin/wap-push.cgi?username=$username'&'password=$password
 $content_file $control_file > check_ppg.tmp 2>&1 
             sleep 1
 
             if ! grep "and type push response" check_ppg.tmp > /dev/null
@@ -120,13 +120,13 @@ for control_file in $wrong_ip_files;
         if [ -f $control_file ]
         then
             have_iperrors=yes
-            gw/bearerbox -v $loglevel $conf_file > check_bb.tmp 2>&1 & bbpid=$!
+            $top_builddir/gw/bearerbox -v $loglevel $conf_file > check_bb.tmp 
2>&1 & bbpid=$!
             sleep 2 
 
-            gw/wapbox -v $loglevel $conf_file > check_wap.tmp 2>&1 & wappid=$!
+            $top_builddir/gw/wapbox -v $loglevel $conf_file > check_wap.tmp 
2>&1 & wappid=$!
             sleep 2
 
-            test/test_ppg -c $contents 
http://$host:$push_port/cgi-bin/wap-push.cgi?username=$username'&'password=$password
 $content_file $control_file > check_ppg.tmp 2>&1
+            $top_builddir/test/test_ppg -c $contents 
http://$host:$push_port/cgi-bin/wap-push.cgi?username=$username'&'password=$password
 $content_file $control_file > check_ppg.tmp 2>&1
             sleep 1
 
             if ! grep "and type push response" check_ppg.tmp > /dev/null &&
@@ -193,13 +193,13 @@ for control_file in $sms_control_files;
     do 
         if [ -f $control_file ]
         then
-            test/test_http_server -p $server_port > check_http_sim.tmp 2>&1 & 
simid=$!
+            $top_builddir/test/test_http_server -p $server_port > 
check_http_sim.tmp 2>&1 & simid=$!
             sleep 1
-            gw/bearerbox -v $loglevel $conf_file > check_bb.tmp 2>&1 & bbpid=$!
+            $top_builddir/gw/bearerbox -v $loglevel $conf_file > check_bb.tmp 
2>&1 & bbpid=$!
             sleep 2 
-            gw/wapbox -v $loglevel $conf_file > check_wap.tmp 2>&1 & wappid=$!
+            $top_builddir/gw/wapbox -v $loglevel $conf_file > check_wap.tmp 
2>&1 & wappid=$!
             sleep 2
-            test/test_ppg -c $contents 
http://$host:$push_port/cgi-bin/wap-push.cgi?username=$username'&'password=$password
 $content_file $control_file > check_ppg.tmp 2>&1 
+            $top_builddir/test/test_ppg -c $contents 
http://$host:$push_port/cgi-bin/wap-push.cgi?username=$username'&'password=$password
 $content_file $control_file > check_ppg.tmp 2>&1 
             sleep 1
 
             if ! grep "and type push response" check_ppg.tmp > /dev/null
@@ -227,7 +227,7 @@ for control_file in $sms_control_files;
             sleep 1
             kill -INT $bbpid
             sleep 2
-            test/test_http -qv 4 http://$host:$server_port/quit
+            $top_builddir/test/test_http -qv 4 http://$host:$server_port/quit
             sleep 2
 # We can panic when we are going down, too
             if test "$error" != "yes"  
@@ -272,15 +272,15 @@ for control_file in $wrong_sms_files;
     do 
         if [ -f $control_file ]
         then
-            test/test_http_server -p $server_port > check_http_sim.tmp 2>&1 & 
simid=$
+            $top_builddir/test/test_http_server -p $server_port > 
check_http_sim.tmp 2>&1 & simid=$
             sleep 1
-            gw/bearerbox -v $loglevel $conf_file > check_bb.tmp 2>&1 & bbpid=$!
+            $top_builddir/gw/bearerbox -v $loglevel $conf_file > check_bb.tmp 
2>&1 & bbpid=$!
             sleep 2 
 
-            gw/wapbox -v $loglevel $conf_file > check_wap.tmp 2>&1 & wappid=$!
+            $top_builddir/gw/wapbox -v $loglevel $conf_file > check_wap.tmp 
2>&1 & wappid=$!
             sleep 2
 
-            test/test_ppg -c $contents 
http://$host:$push_port/cgi-bin/wap-push.cgi?username=$username'&'password=$password
 $content_file $control_file > check_ppg.tmp 2>&1
+            $top_builddir/test/test_ppg -c $contents 
http://$host:$push_port/cgi-bin/wap-push.cgi?username=$username'&'password=$password
 $content_file $control_file > check_ppg.tmp 2>&1
             sleep 1
 
             if ! grep "and type push response" check_ppg.tmp > /dev/null &&
@@ -310,7 +310,7 @@ for control_file in $wrong_sms_files;
             sleep 2
             kill -INT $bbpid
             sleep 1
-            test/test_http -qv 4 http://$host:$server_port/quit
+            $top_builddir/test/test_http -qv 4 http://$host:$server_port/quit
             sleep 2
 
 # We can panic when we are going down, too
@@ -351,7 +351,7 @@ done
 
 kill -INT $listid
 sleep 1
-test/test_http -qv 4 http://$host:$list_port/quit
+$top_builddir/test/test_http -qv 4 http://$host:$list_port/quit
 wait
 
 if test "$error" = "yes"
diff --git a/checks/check_sendsms.sh b/checks/check_sendsms.sh
index 82319c8c..0b49f170 100755
--- a/checks/check_sendsms.sh
+++ b/checks/check_sendsms.sh
@@ -17,16 +17,16 @@ password=foobar
 url="http://$host:$sendsmsport/cgi-bin/sendsms?from=123&to=234&\
 text=test&username=$username&password=$password"
 
-gw/bearerbox -v $loglevel gw/smskannel.conf > check_sendsms_bb.log 2>&1 &
+$top_builddir/gw/bearerbox -v $loglevel $top_srcdir/gw/smskannel.conf > 
check_sendsms_bb.log 2>&1 &
 bbpid=$!
 
 sleep 2
 
-test/fakesmsc -H $host -r 20000 -i $interval -m $times '123 234 text nop' \
+$top_builddir/test/fakesmsc -H $host -r 20000 -i $interval -m $times '123 234 
text nop' \
     > check_sendsms_smsc.log 2>&1 &
 
 sleep 1
-gw/smsbox -v $loglevel gw/smskannel.conf > check_sendsms_sms.log 2>&1 &
+$top_builddir/gw/smsbox -v $loglevel $top_srcdir/gw/smskannel.conf > 
check_sendsms_sms.log 2>&1 &
 
 sleep 2
 
@@ -37,7 +37,7 @@ text=test&username=$username&password=$password"
 i=0
 while [ $i -lt $times ]
 do
-    test/test_http $url >> check_sendsms.log 2>&1
+    $top_builddir/test/test_http $url >> check_sendsms.log 2>&1
     i=`expr $i + 1`
 done
 
@@ -56,7 +56,7 @@ fi
 url="http://$host:$sendsmsport/cgi-bin/sendsms?from=123&to=234&\
 text=&username=$username&password=$password"
 
-test/test_http $url >> check_sendsms.log 2>&1
+$top_builddir/test/test_http $url >> check_sendsms.log 2>&1
 sleep 1
 
 if grep 'WARNING:|ERROR:|PANIC:' check_sendsms*.log >/dev/null
@@ -70,7 +70,7 @@ fi
 url="http://$host:$sendsmsport/cgi-bin/sendsms?from=&to=234&\
 text=test&username=$username&password=$password"
 
-test/test_http $url >> check_sendsms.log 2>&1
+$top_builddir/test/test_http $url >> check_sendsms.log 2>&1
 sleep 1
 
 if grep 'WARNING:|ERROR:|PANIC:' check_sendsms*.log >/dev/null ||
@@ -85,7 +85,7 @@ fi
 url="http://$host:$sendsmsport/cgi-bin/sendsms?from=123&to=&\
 text=&username=$username&password=$password"
 
-test/test_http $url >> check_sendsms.log 2>&1
+$top_builddir/test/test_http $url >> check_sendsms.log 2>&1
 sleep 1
 
 if grep 'WARNING:|ERROR:|PANIC:' check_sendsms*.log >/dev/null ||
@@ -100,7 +100,7 @@ fi
 url="http://$host:$sendsmsport/cgi-bin/sendsms?from=123&to=234&\
 text=&username=&password=$password"
 
-test/test_http $url >> check_sendsms.log 2>&1
+$top_builddir/test/test_http $url >> check_sendsms.log 2>&1
 sleep 1
 
 if grep 'WARNING:|ERROR:|PANIC:' check_sendsms*.log >/dev/null ||
diff --git a/checks/check_smpp.sh b/checks/check_smpp.sh
index 41032e21..3b50aa0e 100755
--- a/checks/check_smpp.sh
+++ b/checks/check_smpp.sh
@@ -7,10 +7,10 @@ set -e
 
 times=10
 
-test/drive_smpp -v 0 -m $times 2> check_smpp_drive.log 1>&2 & 
+$top_builddir/test/drive_smpp -v 0 -m $times 2> check_smpp_drive.log 1>&2 &
 sleep 1
 
-gw/bearerbox -v 0 test/drive_smpp.conf 2> check_smpp_bb.log 1>&2 &  
+$top_builddir/gw/bearerbox -v 0 $top_srcdir/test/drive_smpp.conf 2> 
check_smpp_bb.log 1>&2 &
 bbpid=$!
 
 running=yes
-- 
2.43.0


Reply via email to