From b1d71c239212875ec2d44b4393687110a7c3870b Mon Sep 17 00:00:00 2001 From: Christian Grothoff Date: Mon, 9 Jul 2012 19:39:27 +0000 Subject: [PATCH] -LRN: switching to py for arm test as well --- src/arm/Makefile.am | 16 ++++- src/arm/test_gnunet_arm.py.in | 106 ++++++++++++++++++++++++++++++++++ src/arm/test_gnunet_arm.sh | 65 --------------------- 3 files changed, 119 insertions(+), 68 deletions(-) create mode 100644 src/arm/test_gnunet_arm.py.in delete mode 100755 src/arm/test_gnunet_arm.sh diff --git a/src/arm/Makefile.am b/src/arm/Makefile.am index 7da1e2c60..035681ba6 100644 --- a/src/arm/Makefile.am +++ b/src/arm/Makefile.am @@ -61,7 +61,7 @@ check_PROGRAMS = \ test_gnunet_service_manager check_SCRIPTS = \ - test_gnunet_arm.sh + test_gnunet_arm.py if ENABLE_TEST_RUN TESTS = $(check_PROGRAMS) $(check_SCRIPTS) @@ -85,7 +85,17 @@ test_gnunet_service_manager_SOURCES = \ $(top_builddir)/src/arm/libgnunetarm.la \ $(top_builddir)/src/util/libgnunetutil.la +do_subst = $(SED) -e 's,[@]PYTHON[@],$(PYTHON),g' + +%.py: %.py.in Makefile + $(do_subst) < $(srcdir)/$< > $@ + chmod +x $@ + +test_gnunet_arm.py: test_gnunet_arm.py.in Makefile + $(do_subst) < $(srcdir)/test_gnunet_arm.py.in > test_gnunet_arm.py + chmod +x test_gnunet_arm.py + EXTRA_DIST = \ test_arm_api_data.conf \ - do_start_process.c \ - $(check_SCRIPTS) + test_gnunet_arm.py.in \ + do_start_process.c diff --git a/src/arm/test_gnunet_arm.py.in b/src/arm/test_gnunet_arm.py.in new file mode 100644 index 000000000..c7698a3ce --- /dev/null +++ b/src/arm/test_gnunet_arm.py.in @@ -0,0 +1,106 @@ +#!@PYTHON@ +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_arm = [arm, '-c', 'test_arm_api_data.conf', '--no-stdout', '--no-stderr'] +debug = os.getenv ('DEBUG') +if debug: + run_arm += [debug.split (' ')] + +def cleanup (): + shutil.rmtree (os.path.join (tmp, "test-gnunetd-arm"), 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 end_arm_failer (command, rc, stdo, stde, normal): + if normal: + if rc != 0: + fail ("FAIL: error running {}\nCommand output was:\n{}\n{}".format (command, stdo, stde)) + else: + if rc == 0: + fail ("FAIL: expected error while running {}\nCommand output was:\n{}\n{}".format (command, stdo, stde)) + +def print_only_failer (command, rc, stdo, stde, normal): + if normal: + if rc != 0: + print ("FAIL: error running {}\nCommand output was:\n{}\n{}".format (command, stdo, stde)) + sys.exit (1) + else: + if rc == 0: + print ("FAIL: expected error while running {}\nCommand output was:\n{}\n{}".format (command, stdo, stde)) + sys.exit (1) + + +def r_something (to_run, extra_args, failer = None, normal = True, **kw): + rc, stdo, stde = sub_run (to_run + extra_args, nofail = True, want_stde = True, **kw) + if failer is not None: + failer (to_run + extra_args, rc, stdo, stde, normal) + return (rc, stdo, stde) + +def r_arm (extra_args, **kw): + return r_something (run_arm, extra_args, **kw) + +cleanup () + +print ("TEST: Bad argument checking...", end='') +r_arm (['-x'], normal = False, failer = print_only_failer) +print ("PASS") + +print ("TEST: Start ARM...", end='') +r_arm (['-s'], failer = print_only_failer) +time.sleep (1) +print ("PASS") + +print ("TEST: Start another service...", end='') +r_arm (['-i', 'resolver'], failer = end_arm_failer) +time.sleep (1) +print ("PASS") + +print ("TEST: Stop a service...", end='') +r_arm (['-k', 'resolver'], failer = end_arm_failer) +time.sleep (1) +print ("PASS") + +print ("TEST: Stop ARM...", end='') +r_arm (['-e'], failer = print_only_failer) +time.sleep (1) +print ("PASS") + +cleanup () diff --git a/src/arm/test_gnunet_arm.sh b/src/arm/test_gnunet_arm.sh deleted file mode 100755 index 4a5b7266d..000000000 --- a/src/arm/test_gnunet_arm.sh +++ /dev/null @@ -1,65 +0,0 @@ -#!/bin/sh - -exe="./gnunet-arm -c test_arm_api_data.conf" -out=`mktemp /tmp/test-gnunet-arm-logXXXXXXXX` -#DEBUG="-L DEBUG" - - -# ---------------------------------------------------------------------------------- -echo -n "TEST: Bad argument checking... " - -if $exe -x 2> /dev/null; then - echo "FAIL: error running $exe" - exit 1 -fi -echo "PASS" - -# ---------------------------------------------------------------------------------- -echo -n "TEST: Start ARM..." - -if ! $exe $DEBUG -s > $out ; then - echo "FAIL: error running $exe" - echo "Command output was:" - cat $out - exit 1 -fi -echo "PASS" -sleep 1 - -# ---------------------------------------------------------------------------------- -echo -n "TEST: Start another service... " - -if ! $exe $DEBUG -i resolver > $out ; then - echo "FAIL: error running $exe" - echo "Command output was:" - cat $out - kill %% - exit 1 -fi -sleep 1 -echo "PASS" - -# ---------------------------------------------------------------------------------- -echo -n "TEST: Stop a service... " - -if ! $exe $DEBUG -k resolver > $out; then - echo "FAIL: error running $exe" - $exe -e - exit 1 -fi -sleep 1 -echo "PASS" - -# ---------------------------------------------------------------------------------- -echo -n "TEST: Stop ARM... " - -if ! $exe $DEBUG -e > $out; then - echo "FAIL: error running $exe" - exit 1 -fi -sleep 1 -echo "PASS" - -rm -rf /tmp/test-gnunetd-arm/ -rm -f $out - -- 2.25.1