aboutsummaryrefslogtreecommitdiff
path: root/src/arm
diff options
context:
space:
mode:
authorChristian Grothoff <christian@grothoff.org>2012-07-09 19:39:27 +0000
committerChristian Grothoff <christian@grothoff.org>2012-07-09 19:39:27 +0000
commitb1d71c239212875ec2d44b4393687110a7c3870b (patch)
tree953c030c5137561c26f5c5024beb31db765f64a5 /src/arm
parent8f9464256fc06a884bf589b4004262a0549d11b3 (diff)
downloadgnunet-b1d71c239212875ec2d44b4393687110a7c3870b.tar.gz
gnunet-b1d71c239212875ec2d44b4393687110a7c3870b.zip
-LRN: switching to py for arm test as well
Diffstat (limited to 'src/arm')
-rw-r--r--src/arm/Makefile.am16
-rw-r--r--src/arm/test_gnunet_arm.py.in106
-rwxr-xr-xsrc/arm/test_gnunet_arm.sh65
3 files changed, 119 insertions, 68 deletions
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 = \
61 test_gnunet_service_manager 61 test_gnunet_service_manager
62 62
63check_SCRIPTS = \ 63check_SCRIPTS = \
64 test_gnunet_arm.sh 64 test_gnunet_arm.py
65 65
66if ENABLE_TEST_RUN 66if ENABLE_TEST_RUN
67TESTS = $(check_PROGRAMS) $(check_SCRIPTS) 67TESTS = $(check_PROGRAMS) $(check_SCRIPTS)
@@ -85,7 +85,17 @@ test_gnunet_service_manager_SOURCES = \
85 $(top_builddir)/src/arm/libgnunetarm.la \ 85 $(top_builddir)/src/arm/libgnunetarm.la \
86 $(top_builddir)/src/util/libgnunetutil.la 86 $(top_builddir)/src/util/libgnunetutil.la
87 87
88do_subst = $(SED) -e 's,[@]PYTHON[@],$(PYTHON),g'
89
90%.py: %.py.in Makefile
91 $(do_subst) < $(srcdir)/$< > $@
92 chmod +x $@
93
94test_gnunet_arm.py: test_gnunet_arm.py.in Makefile
95 $(do_subst) < $(srcdir)/test_gnunet_arm.py.in > test_gnunet_arm.py
96 chmod +x test_gnunet_arm.py
97
88EXTRA_DIST = \ 98EXTRA_DIST = \
89 test_arm_api_data.conf \ 99 test_arm_api_data.conf \
90 do_start_process.c \ 100 test_gnunet_arm.py.in \
91 $(check_SCRIPTS) 101 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 @@
1#!@PYTHON@
2from __future__ import print_function
3import os
4import sys
5import shutil
6import re
7import subprocess
8import time
9
10if os.name == "nt":
11 tmp = os.getenv ("TEMP")
12else:
13 tmp = "/tmp"
14
15if os.name == 'nt':
16 st = 'gnunet-statistics.exe'
17 arm = 'gnunet-arm.exe'
18else:
19 st = 'gnunet-statistics'
20 arm = 'gnunet-arm'
21
22run_arm = [arm, '-c', 'test_arm_api_data.conf', '--no-stdout', '--no-stderr']
23debug = os.getenv ('DEBUG')
24if debug:
25 run_arm += [debug.split (' ')]
26
27def cleanup ():
28 shutil.rmtree (os.path.join (tmp, "test-gnunetd-arm"), True)
29
30def sub_run (args, want_stdo = True, want_stde = False, nofail = False):
31 if want_stdo:
32 stdo = subprocess.PIPE
33 else:
34 stdo = None
35 if want_stde:
36 stde = subprocess.PIPE
37 else:
38 stde = None
39 p = subprocess.Popen (args, stdout = stdo, stderr = stde)
40 stdo, stde = p.communicate ()
41 if not nofail:
42 if p.returncode != 0:
43 sys.exit (p.returncode)
44 return (p.returncode, stdo, stde)
45
46def fail (result):
47 print (result)
48 r_arm (['-e'], want_stdo = False)
49 sys.exit (1)
50
51
52def end_arm_failer (command, rc, stdo, stde, normal):
53 if normal:
54 if rc != 0:
55 fail ("FAIL: error running {}\nCommand output was:\n{}\n{}".format (command, stdo, stde))
56 else:
57 if rc == 0:
58 fail ("FAIL: expected error while running {}\nCommand output was:\n{}\n{}".format (command, stdo, stde))
59
60def print_only_failer (command, rc, stdo, stde, normal):
61 if normal:
62 if rc != 0:
63 print ("FAIL: error running {}\nCommand output was:\n{}\n{}".format (command, stdo, stde))
64 sys.exit (1)
65 else:
66 if rc == 0:
67 print ("FAIL: expected error while running {}\nCommand output was:\n{}\n{}".format (command, stdo, stde))
68 sys.exit (1)
69
70
71def r_something (to_run, extra_args, failer = None, normal = True, **kw):
72 rc, stdo, stde = sub_run (to_run + extra_args, nofail = True, want_stde = True, **kw)
73 if failer is not None:
74 failer (to_run + extra_args, rc, stdo, stde, normal)
75 return (rc, stdo, stde)
76
77def r_arm (extra_args, **kw):
78 return r_something (run_arm, extra_args, **kw)
79
80cleanup ()
81
82print ("TEST: Bad argument checking...", end='')
83r_arm (['-x'], normal = False, failer = print_only_failer)
84print ("PASS")
85
86print ("TEST: Start ARM...", end='')
87r_arm (['-s'], failer = print_only_failer)
88time.sleep (1)
89print ("PASS")
90
91print ("TEST: Start another service...", end='')
92r_arm (['-i', 'resolver'], failer = end_arm_failer)
93time.sleep (1)
94print ("PASS")
95
96print ("TEST: Stop a service...", end='')
97r_arm (['-k', 'resolver'], failer = end_arm_failer)
98time.sleep (1)
99print ("PASS")
100
101print ("TEST: Stop ARM...", end='')
102r_arm (['-e'], failer = print_only_failer)
103time.sleep (1)
104print ("PASS")
105
106cleanup ()
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 @@
1#!/bin/sh
2
3exe="./gnunet-arm -c test_arm_api_data.conf"
4out=`mktemp /tmp/test-gnunet-arm-logXXXXXXXX`
5#DEBUG="-L DEBUG"
6
7
8# ----------------------------------------------------------------------------------
9echo -n "TEST: Bad argument checking... "
10
11if $exe -x 2> /dev/null; then
12 echo "FAIL: error running $exe"
13 exit 1
14fi
15echo "PASS"
16
17# ----------------------------------------------------------------------------------
18echo -n "TEST: Start ARM..."
19
20if ! $exe $DEBUG -s > $out ; then
21 echo "FAIL: error running $exe"
22 echo "Command output was:"
23 cat $out
24 exit 1
25fi
26echo "PASS"
27sleep 1
28
29# ----------------------------------------------------------------------------------
30echo -n "TEST: Start another service... "
31
32if ! $exe $DEBUG -i resolver > $out ; then
33 echo "FAIL: error running $exe"
34 echo "Command output was:"
35 cat $out
36 kill %%
37 exit 1
38fi
39sleep 1
40echo "PASS"
41
42# ----------------------------------------------------------------------------------
43echo -n "TEST: Stop a service... "
44
45if ! $exe $DEBUG -k resolver > $out; then
46 echo "FAIL: error running $exe"
47 $exe -e
48 exit 1
49fi
50sleep 1
51echo "PASS"
52
53# ----------------------------------------------------------------------------------
54echo -n "TEST: Stop ARM... "
55
56if ! $exe $DEBUG -e > $out; then
57 echo "FAIL: error running $exe"
58 exit 1
59fi
60sleep 1
61echo "PASS"
62
63rm -rf /tmp/test-gnunetd-arm/
64rm -f $out
65