check-early
[oweals/gnunet.git] / src / statistics / test_gnunet_statistics.sh
index 43f629f36dad4291f04cb561228c9a5d07870952..55190502a804a278ad77dceffafdd87fddac550b 100755 (executable)
@@ -1,13 +1,17 @@
-#!/bin/bash
+#!/bin/sh
 
 rm -rf /tmp/test-gnunetd-statistics/
 exe="./gnunet-statistics -c test_statistics_api_data.conf"
-base=/tmp/gnunet-test-statistics
+out=`mktemp /tmp/test-gnunet-statistics-logXXXXXXXX`
+arm="gnunet-arm -c test_statistics_api_data.conf $DEBUG"
 #DEBUG="-L DEBUG"
 # -----------------------------------
 echo -n "Preparing: Starting service..."
-./gnunet-service-statistics $DEBUG -c test_statistics_api_data.conf  &
+
+$arm -s > /dev/null
 sleep 1
+$arm -i statistics > /dev/null
+sleep 1 
 echo "DONE"
 
 # ----------------------------------------------------------------------------------
@@ -15,7 +19,7 @@ echo -n "TEST: Bad argument checking..."
 
 if $exe -x 2> /dev/null; then
   echo "FAIL: error running $exe"
-  kill %%
+  $arm -e
   exit 1
 fi
 echo "PASS"
@@ -25,7 +29,7 @@ echo -n "TEST: Set value..."
 
 if ! $exe $DEBUG -n test -s subsystem 42 ; then
   echo "FAIL: error running $exe"
-  kill %%
+  $arm -e
   exit 1
 fi
 echo "PASS"
@@ -35,7 +39,7 @@ echo -n "TEST: Set another value..."
 
 if ! $exe $DEBUG -n other -s osystem 43 ; then
   echo "FAIL: error running $exe"
-  kill %%
+  $arm -e
   exit 1
 fi
 echo "PASS"
@@ -43,15 +47,15 @@ echo "PASS"
 # ----------------------------------------------------------------------------------
 echo -n "TEST: viewing all stats..."
 
-if ! $exe $DEBUG > $base.out; then
+if ! $exe $DEBUG > $out; then
     echo "FAIL: error running $exe"
-    kill %%
+    $arm -e
     exit 1
 fi
-LINES=`cat $base.out | wc -l`
+LINES=`cat $out | wc -l`
 if test $LINES -ne 2; then
     echo "FAIL: unexpected output"
-    kill %%
+    $arm -e
     exit 1
 fi
 echo "PASS"
@@ -59,15 +63,15 @@ echo "PASS"
 # ----------------------------------------------------------------------------------
 echo -n "TEST: viewing stats by name..."
 
-if ! $exe $DEBUG -n other > $base.out; then
+if ! $exe $DEBUG -n other > $out; then
     echo "FAIL: error running $exe"
-    kill %%
+    $arm -e
     exit 1
 fi
-LINES=`cat $base.out | grep 43 | wc -l`
+LINES=`cat $out | grep 43 | wc -l`
 if test $LINES -ne 1; then
     echo "FAIL: unexpected output"
-    kill %%
+    $arm -e
     exit 1
 fi
 echo "PASS"
@@ -75,15 +79,15 @@ echo "PASS"
 # ----------------------------------------------------------------------------------
 echo -n "TEST: viewing stats by subsystem..."
 
-if ! $exe $DEBUG -s subsystem > $base.out; then
+if ! $exe $DEBUG -s subsystem > $out; then
     echo "FAIL: error running $exe"
-    kill %%
+    $arm -e
     exit 1
 fi
-LINES=`cat $base.out | grep 42 | wc -l`
+LINES=`cat $out | grep 42 | wc -l`
 if test $LINES -ne 1; then
     echo "FAIL: unexpected output"
-    kill %%
+    $arm -e
     exit 1
 fi
 echo "PASS"
@@ -94,37 +98,44 @@ echo -n "TEST: Set persistent value..."
 
 if ! $exe $DEBUG -n lasting -s subsystem 40 -p; then
   echo "FAIL: error running $exe"
-  kill %%
+  $arm -e
   exit 1
 fi
+if ! $exe $DEBUG > $out; then
+    echo "FAIL: error running $exe"
+    $arm -e
+    exit 1
+fi
+LINES=`cat $out | grep 40 | wc -l`
+if test $LINES -ne 1; then
+    echo "FAIL: unexpected output"
+    cat $out
+    $arm -e
+    exit 1
+fi
 echo "PASS"
 
 # -----------------------------------
 echo -n "Restarting service..."
+$arm -k statistics > /dev/null
 sleep 1
-if ! kill %%;
-then
-  echo "FAIL: could not kill service"
-  kill %%
-  exit 1
-fi
-sleep 1
-./gnunet-service-statistics $DEBUG  -c test_statistics_api_data.conf  &
+$arm -i statistics > /dev/null
 sleep 1
-
+echo "DONE"
 
 # ----------------------------------------------------------------------------------
 echo -n "TEST: checking persistence..."
 
-if ! $exe $DEBUG > $base.out; then
+if ! $exe $DEBUG > $out; then
     echo "FAIL: error running $exe"
-    kill %%
+    $arm -e
     exit 1
 fi
-LINES=`cat $base.out | grep 40 | wc -l`
+LINES=`cat $out | grep 40 | wc -l`
 if test $LINES -ne 1; then
     echo "FAIL: unexpected output"
-    kill %%
+    cat $out
+    $arm -e
     exit 1
 fi
 echo "PASS"
@@ -136,7 +147,7 @@ echo -n "TEST: Removing persistence..."
 
 if ! $exe  $DEBUG -n lasting -s subsystem 40; then
   echo "FAIL: error running $exe"
-  kill %%
+  $arm -e
   exit 1
 fi
 echo "PASS"
@@ -144,34 +155,32 @@ echo "PASS"
 
 # -----------------------------------
 echo -n "Restarting service..."
+$arm -k statistics > /dev/null
 sleep 1
-if ! kill %%;
-then
-  echo "FAIL: could not kill service"
-  kill %%
-  exit 1
-fi
-sleep 1
-./gnunet-service-statistics $DEBUG -c test_statistics_api_data.conf  &
+$arm -i statistics > /dev/null
 sleep 1
-
+echo "DONE"
 
 # ----------------------------------------------------------------------------------
 echo -n "TEST: checking removed persistence..."
 
-if ! $exe $DEBUG > $base.out; then
+if ! $exe $DEBUG > $out; then
     echo "FAIL: error running $exe"
-    kill %%
+    $arm -e
     exit 1
 fi
-LINES=`cat $base.out | grep 40 | wc -l`
+LINES=`cat $out | grep 40 | wc -l`
 if test $LINES -ne 0; then
     echo "FAIL: unexpected output"
-    kill %%
+    $arm -e
     exit 1
 fi
 echo "PASS"
 
-kill %%
-rm -f $base.out
+# -----------------------------------
+echo -n "Stopping service..."
+$arm -e > /dev/null
+sleep 1
+echo "DONE"
+rm -f $out
 rm -rf /tmp/test-gnunetd-statistics/