1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
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 ()
|