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/test_gnunet_arm.py.in | |
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/test_gnunet_arm.py.in')
-rw-r--r-- | src/arm/test_gnunet_arm.py.in | 106 |
1 files changed, 106 insertions, 0 deletions
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 () | ||