gnunet-svn
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

[GNUnet-SVN] r22559 - gnunet/src/statistics


From: gnunet
Subject: [GNUnet-SVN] r22559 - gnunet/src/statistics
Date: Mon, 9 Jul 2012 13:19:47 +0200

Author: grothoff
Date: 2012-07-09 13:19:47 +0200 (Mon, 09 Jul 2012)
New Revision: 22559

Added:
   gnunet/src/statistics/test_gnunet_statistics.py.in
Removed:
   gnunet/src/statistics/test_gnunet_statistics.sh
Modified:
   gnunet/src/statistics/Makefile.am
Log:
-LRN: Python-based test script for statistics


Modified: gnunet/src/statistics/Makefile.am
===================================================================
--- gnunet/src/statistics/Makefile.am   2012-07-09 11:17:55 UTC (rev 22558)
+++ gnunet/src/statistics/Makefile.am   2012-07-09 11:19:47 UTC (rev 22559)
@@ -83,10 +83,20 @@
   $(top_builddir)/src/util/libgnunetutil.la  
 
 check_SCRIPTS = \
-  test_gnunet_statistics.sh
+  test_gnunet_statistics.py
 
+do_subst = $(SED) -e 's,address@hidden@],$(PYTHON),g'
+
+%.py: %.py.in Makefile
+       $(do_subst) < $(srcdir)/$< > $@
+       chmod +x $@
+
+test_gnunet_statistics.py: test_gnunet_statistics.py.in Makefile
+       $(do_subst) < $(srcdir)/test_gnunet_statistics.py.in > 
test_gnunet_statistics.py
+       chmod +x test_gnunet_statistics.py
+
 EXTRA_DIST = \
   test_statistics_api_data.conf \
-  $(check_SCRIPTS) 
+  test_gnunet_statistics.py.in
 
 

Added: gnunet/src/statistics/test_gnunet_statistics.py.in
===================================================================
--- gnunet/src/statistics/test_gnunet_statistics.py.in                          
(rev 0)
+++ gnunet/src/statistics/test_gnunet_statistics.py.in  2012-07-09 11:19:47 UTC 
(rev 22559)
@@ -0,0 +1,151 @@
address@hidden@
+from __future__ import print_function
+import os
+import sys
+import shutil
+import re
+import subprocess
+import time
+
+if os.name == "nt":
+  tmp = os.getenv ("TEMP")
+else:
+  tmp = "/tmp"
+
+if os.name == 'nt':
+  st = 'gnunet-statistics.exe'
+  arm = 'gnunet-arm.exe'
+else:
+  st = 'gnunet-statistics'
+  arm = 'gnunet-arm'
+
+run_st = [st, '-c', 'test_statistics_api_data.conf']
+run_arm = [arm, '-c', 'test_statistics_api_data.conf']
+debug = os.getenv ('DEBUG')
+if debug:
+  run_arm += [debug.split (' ')]
+
+def cleanup ():
+  shutil.rmtree (os.path.join (tmp, "test-gnunetd-statistics"), True)
+
+def sub_run (args, want_stdo = True, want_stde = False, nofail = False):
+  if want_stdo:
+    stdo = subprocess.PIPE
+  else:
+    stdo = None
+  if want_stde:
+    stde = subprocess.PIPE
+  else:
+    stde = None
+  p = subprocess.Popen (args, stdout = stdo, stderr = stde)
+  stdo, stde = p.communicate ()
+  if not nofail:
+    if p.returncode != 0:
+      sys.exit (p.returncode)
+  return (p.returncode, stdo, stde)
+
+def fail (result):
+  print (result)
+  r_arm (['-e'], want_stdo = False)
+  sys.exit (1)
+
+def r_arm (extra_args, **kw):
+  rc, stdo, stde = sub_run (run_arm + extra_args, **kw)
+  if rc != 0:
+    fail ("FAIL: error running {}".format (run_arm))
+  return (rc, stdo, stde)
+
+def r_st (extra_args, normal = True, **kw):
+  rc, stdo, stde = sub_run (run_st + extra_args, **kw)
+  if normal:
+    if rc != 0:
+      fail ("FAIL: error running {}".format (run_st))
+  else:
+    if rc == 0:
+      fail ("FAIL: expected error while running {}".format (run_st))
+  return (rc, stdo, stde)
+
+def restart ():
+  print ("Restarting service...")
+  t = r_arm (['-k', 'statistics'])
+  time.sleep (1)
+  t = r_arm (['-i', 'statistics'])
+  time.sleep (1)
+  print ("DONE")
+
+
+cleanup ()
+
+print ("Preparing: Starting service...")
+t = r_arm (['-s'], want_stdo = False)
+time.sleep (1)
+t = r_arm (['-i', 'statistics'], want_stdo = False)
+time.sleep (1)
+print ("DONE")
+
+print ("TEST: Bad argument checking...", end='')
+r_st (['-x'], normal = False, nofail = True, want_stdo = False)
+print ("PASS")
+
+print ("TEST: Set value...", end='')
+r_st (['-n', 'test', '-s', 'subsystem', '42'], nofail = True, want_stdo = 
False)
+print ("PASS")
+
+print ("TEST: Set another value...", end='')
+r_st (['-n', 'other', '-s', 'osystem', '43'], nofail = True, want_stdo = False)
+print ("PASS")
+
+print ("TEST: Viewing all stats...", end='')
+rc, stdo, stde = r_st ([], nofail = True, want_stdo = True)
+if len (stdo.splitlines ()) != 2:
+  fail ("FAIL: unexpected output:\n{}".format (stdo))
+print ("PASS")
+
+print ("TEST: Viewing stats by name...", end='')
+rc, stdo, stde = r_st (['-n', 'other'], nofail = True, want_stdo = True)
+if len ([x for x in stdo.splitlines () if re.search ('43', x)]) != 1:
+  fail ("FAIL: unexpected output:\n{}".format (stdo))
+print ("PASS")
+
+print ("TEST: Viewing stats by subsystem...", end='')
+rc, stdo, stde = r_st (['-s', 'subsystem'], nofail = True, want_stdo = True)
+if len ([x for x in stdo.splitlines () if re.search ('42', x)]) != 1:
+  fail ("FAIL: unexpected output:\n{}".format (stdo))
+print ("PASS")
+
+print ("TEST: Set persistent value...", end='')
+rc, stdo, stde = r_st (['-n', 'lasting', '-s', 'subsystem', '40', '-p'], 
nofail = True, want_stdo = False)
+rc, stdo, stde = r_st ([], nofail = True, want_stdo = True)
+if len ([x for x in stdo.splitlines () if re.search ('40', x)]) != 1:
+  fail ("FAIL: unexpected output:\n{}".format (stdo))
+print ("PASS")
+
+restart ()
+
+print ("TEST: Checking persistence...", end='')
+rc, stdo, stde = r_st ([], nofail = True, want_stdo = True)
+if len ([x for x in stdo.splitlines () if re.search ('40', x)]) != 1:
+  fail ("FAIL: unexpected output:\n{}".format (stdo))
+print ("PASS")
+
+print ("TEST: Removing persistence...", end='')
+rc, stdo, stde = r_st (['-n', 'lasting', '-s', 'subsystem', '40'], nofail = 
True, want_stdo = False)
+rc, stdo, stde = r_st ([], nofail = True, want_stdo = True)
+if len ([x for x in stdo.splitlines () if re.search ('!', x)]) != 0:
+  fail ("FAIL: unexpected output:\n{}".format (stdo))
+print ("PASS")
+
+restart ()
+
+print ("TEST: Checking removed persistence...", end='')
+rc, stdo, stde = r_st ([], nofail = True, want_stdo = True)
+if len ([x for x in stdo.splitlines () if re.search ('40', x)]) != 0:
+  fail ("FAIL: unexpected output:\n{}".format (stdo))
+print ("PASS")
+
+print ("Stopping service...")
+t = r_arm (['-e'], want_stdo = False)
+time.sleep (1)
+print ("DONE")
+
+cleanup ()

Deleted: gnunet/src/statistics/test_gnunet_statistics.sh
===================================================================
--- gnunet/src/statistics/test_gnunet_statistics.sh     2012-07-09 11:17:55 UTC 
(rev 22558)
+++ gnunet/src/statistics/test_gnunet_statistics.sh     2012-07-09 11:19:47 UTC 
(rev 22559)
@@ -1,199 +0,0 @@
-#!/bin/sh
-
-rm -rf /tmp/test-gnunetd-statistics/
-exe="./gnunet-statistics -c test_statistics_api_data.conf"
-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..."
-
-$arm -s > /dev/null
-sleep 1
-$arm -i statistics > /dev/null
-sleep 1 
-echo "DONE"
-
-# 
----------------------------------------------------------------------------------
-echo -n "TEST: Bad argument checking..."
-
-if $exe -x 2> /dev/null; then
-  echo "FAIL: error running $exe"
-  $arm -e
-  exit 1
-fi
-echo "PASS"
-
-# 
----------------------------------------------------------------------------------
-echo -n "TEST: Set value..."
-
-if ! $exe $DEBUG -n test -s subsystem 42 ; then
-  echo "FAIL: error running $exe"
-  $arm -e
-  exit 1
-fi
-echo "PASS"
-
-# 
----------------------------------------------------------------------------------
-echo -n "TEST: Set another value..."
-
-if ! $exe $DEBUG -n other -s osystem 43 ; then
-  echo "FAIL: error running $exe"
-  $arm -e
-  exit 1
-fi
-echo "PASS"
-
-# 
----------------------------------------------------------------------------------
-echo -n "TEST: viewing all stats..."
-
-if ! $exe $DEBUG > $out; then
-    echo "FAIL: error running $exe"
-    $arm -e
-    exit 1
-fi
-LINES=`cat $out | wc -l`
-if test $LINES -ne 2; then
-    echo "FAIL: unexpected output"
-    $arm -e
-    exit 1
-fi
-echo "PASS"
-
-# 
----------------------------------------------------------------------------------
-echo -n "TEST: viewing stats by name..."
-
-if ! $exe $DEBUG -n other > $out; then
-    echo "FAIL: error running $exe"
-    $arm -e
-    exit 1
-fi
-LINES=`cat $out | grep 43 | wc -l`
-if test $LINES -ne 1; then
-    echo "FAIL: unexpected output"
-    $arm -e
-    exit 1
-fi
-echo "PASS"
-
-# 
----------------------------------------------------------------------------------
-echo -n "TEST: viewing stats by subsystem..."
-
-if ! $exe $DEBUG -s subsystem > $out; then
-    echo "FAIL: error running $exe"
-    $arm -e
-    exit 1
-fi
-LINES=`cat $out | grep 42 | wc -l`
-if test $LINES -ne 1; then
-    echo "FAIL: unexpected output"
-    $arm -e
-    exit 1
-fi
-echo "PASS"
-
-
-# 
----------------------------------------------------------------------------------
-echo -n "TEST: Set persistent value..."
-
-if ! $exe $DEBUG -n lasting -s subsystem 40 -p; then
-  echo "FAIL: error running $exe"
-  $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
-$arm -i statistics > /dev/null
-sleep 1
-echo "DONE"
-
-# 
----------------------------------------------------------------------------------
-echo -n "TEST: checking persistence..."
-
-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 "TEST: Removing persistence..."
-
-if ! $exe  $DEBUG -n lasting -s subsystem 40; then
-  echo "FAIL: error running $exe"
-  $arm -e
-  exit 1
-fi
-if ! $exe $DEBUG > $out; then
-    echo "FAIL: error running $exe"
-    $arm -e
-    exit 1
-fi
-LINES=`cat $out | grep \! | wc -l`
-if test $LINES -ne 0; 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
-$arm -i statistics > /dev/null
-sleep 1
-echo "DONE"
-
-# 
----------------------------------------------------------------------------------
-echo -n "TEST: checking removed persistence..."
-
-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 0; then
-    echo "FAIL: unexpected output"
-    cat $out
-    $arm -e
-    exit 1
-fi
-echo "PASS"
-
-# -----------------------------------
-echo -n "Stopping service..."
-$arm -e > /dev/null
-sleep 1
-echo "DONE"
-rm -f $out
-rm -rf /tmp/test-gnunetd-statistics/




reply via email to

[Prev in Thread] Current Thread [Next in Thread]