diff options
author | Christian Grothoff <christian@grothoff.org> | 2012-07-09 19:39:27 +0000 |
---|---|---|
committer | Christian Grothoff <christian@grothoff.org> | 2012-07-09 19:39:27 +0000 |
commit | b1d71c239212875ec2d44b4393687110a7c3870b (patch) | |
tree | 953c030c5137561c26f5c5024beb31db765f64a5 /src/arm | |
parent | 8f9464256fc06a884bf589b4004262a0549d11b3 (diff) | |
download | gnunet-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.am | 16 | ||||
-rw-r--r-- | src/arm/test_gnunet_arm.py.in | 106 | ||||
-rwxr-xr-x | src/arm/test_gnunet_arm.sh | 65 |
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 | ||
63 | check_SCRIPTS = \ | 63 | check_SCRIPTS = \ |
64 | test_gnunet_arm.sh | 64 | test_gnunet_arm.py |
65 | 65 | ||
66 | if ENABLE_TEST_RUN | 66 | if ENABLE_TEST_RUN |
67 | TESTS = $(check_PROGRAMS) $(check_SCRIPTS) | 67 | TESTS = $(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 | ||
88 | do_subst = $(SED) -e 's,[@]PYTHON[@],$(PYTHON),g' | ||
89 | |||
90 | %.py: %.py.in Makefile | ||
91 | $(do_subst) < $(srcdir)/$< > $@ | ||
92 | chmod +x $@ | ||
93 | |||
94 | test_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 | |||
88 | EXTRA_DIST = \ | 98 | EXTRA_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@ | ||
2 | from __future__ import print_function | ||
3 | import os | ||
4 | import sys | ||
5 | import shutil | ||
6 | import re | ||
7 | import subprocess | ||
8 | import time | ||
9 | |||
10 | if os.name == "nt": | ||
11 | tmp = os.getenv ("TEMP") | ||
12 | else: | ||
13 | tmp = "/tmp" | ||
14 | |||
15 | if os.name == 'nt': | ||
16 | st = 'gnunet-statistics.exe' | ||
17 | arm = 'gnunet-arm.exe' | ||
18 | else: | ||
19 | st = 'gnunet-statistics' | ||
20 | arm = 'gnunet-arm' | ||
21 | |||
22 | run_arm = [arm, '-c', 'test_arm_api_data.conf', '--no-stdout', '--no-stderr'] | ||
23 | debug = os.getenv ('DEBUG') | ||
24 | if debug: | ||
25 | run_arm += [debug.split (' ')] | ||
26 | |||
27 | def cleanup (): | ||
28 | shutil.rmtree (os.path.join (tmp, "test-gnunetd-arm"), True) | ||
29 | |||
30 | def 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 | |||
46 | def fail (result): | ||
47 | print (result) | ||
48 | r_arm (['-e'], want_stdo = False) | ||
49 | sys.exit (1) | ||
50 | |||
51 | |||
52 | def 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 | |||
60 | def 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 | |||
71 | def 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 | |||
77 | def r_arm (extra_args, **kw): | ||
78 | return r_something (run_arm, extra_args, **kw) | ||
79 | |||
80 | cleanup () | ||
81 | |||
82 | print ("TEST: Bad argument checking...", end='') | ||
83 | r_arm (['-x'], normal = False, failer = print_only_failer) | ||
84 | print ("PASS") | ||
85 | |||
86 | print ("TEST: Start ARM...", end='') | ||
87 | r_arm (['-s'], failer = print_only_failer) | ||
88 | time.sleep (1) | ||
89 | print ("PASS") | ||
90 | |||
91 | print ("TEST: Start another service...", end='') | ||
92 | r_arm (['-i', 'resolver'], failer = end_arm_failer) | ||
93 | time.sleep (1) | ||
94 | print ("PASS") | ||
95 | |||
96 | print ("TEST: Stop a service...", end='') | ||
97 | r_arm (['-k', 'resolver'], failer = end_arm_failer) | ||
98 | time.sleep (1) | ||
99 | print ("PASS") | ||
100 | |||
101 | print ("TEST: Stop ARM...", end='') | ||
102 | r_arm (['-e'], failer = print_only_failer) | ||
103 | time.sleep (1) | ||
104 | print ("PASS") | ||
105 | |||
106 | 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 @@ | |||
1 | #!/bin/sh | ||
2 | |||
3 | exe="./gnunet-arm -c test_arm_api_data.conf" | ||
4 | out=`mktemp /tmp/test-gnunet-arm-logXXXXXXXX` | ||
5 | #DEBUG="-L DEBUG" | ||
6 | |||
7 | |||
8 | # ---------------------------------------------------------------------------------- | ||
9 | echo -n "TEST: Bad argument checking... " | ||
10 | |||
11 | if $exe -x 2> /dev/null; then | ||
12 | echo "FAIL: error running $exe" | ||
13 | exit 1 | ||
14 | fi | ||
15 | echo "PASS" | ||
16 | |||
17 | # ---------------------------------------------------------------------------------- | ||
18 | echo -n "TEST: Start ARM..." | ||
19 | |||
20 | if ! $exe $DEBUG -s > $out ; then | ||
21 | echo "FAIL: error running $exe" | ||
22 | echo "Command output was:" | ||
23 | cat $out | ||
24 | exit 1 | ||
25 | fi | ||
26 | echo "PASS" | ||
27 | sleep 1 | ||
28 | |||
29 | # ---------------------------------------------------------------------------------- | ||
30 | echo -n "TEST: Start another service... " | ||
31 | |||
32 | if ! $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 | ||
38 | fi | ||
39 | sleep 1 | ||
40 | echo "PASS" | ||
41 | |||
42 | # ---------------------------------------------------------------------------------- | ||
43 | echo -n "TEST: Stop a service... " | ||
44 | |||
45 | if ! $exe $DEBUG -k resolver > $out; then | ||
46 | echo "FAIL: error running $exe" | ||
47 | $exe -e | ||
48 | exit 1 | ||
49 | fi | ||
50 | sleep 1 | ||
51 | echo "PASS" | ||
52 | |||
53 | # ---------------------------------------------------------------------------------- | ||
54 | echo -n "TEST: Stop ARM... " | ||
55 | |||
56 | if ! $exe $DEBUG -e > $out; then | ||
57 | echo "FAIL: error running $exe" | ||
58 | exit 1 | ||
59 | fi | ||
60 | sleep 1 | ||
61 | echo "PASS" | ||
62 | |||
63 | rm -rf /tmp/test-gnunetd-arm/ | ||
64 | rm -f $out | ||
65 | |||