diff options
author | Christian Grothoff <christian@grothoff.org> | 2012-07-09 11:19:47 +0000 |
---|---|---|
committer | Christian Grothoff <christian@grothoff.org> | 2012-07-09 11:19:47 +0000 |
commit | 8bdc9a4b52d7b36c2beacdf645a64d4f200ec280 (patch) | |
tree | 155e887260cfe79fdae0bec16fe054d75802f8f8 /src/statistics | |
parent | 078713080ee376ba8a490c70c474a1a2d22189c8 (diff) | |
download | gnunet-8bdc9a4b52d7b36c2beacdf645a64d4f200ec280.tar.gz gnunet-8bdc9a4b52d7b36c2beacdf645a64d4f200ec280.zip |
-LRN: Python-based test script for statistics
Diffstat (limited to 'src/statistics')
-rw-r--r-- | src/statistics/Makefile.am | 14 | ||||
-rw-r--r-- | src/statistics/test_gnunet_statistics.py.in | 151 | ||||
-rwxr-xr-x | src/statistics/test_gnunet_statistics.sh | 199 |
3 files changed, 163 insertions, 201 deletions
diff --git a/src/statistics/Makefile.am b/src/statistics/Makefile.am index ddf5fda0e..5485a9c18 100644 --- a/src/statistics/Makefile.am +++ b/src/statistics/Makefile.am | |||
@@ -83,10 +83,20 @@ test_statistics_api_watch_zero_value_LDADD = \ | |||
83 | $(top_builddir)/src/util/libgnunetutil.la | 83 | $(top_builddir)/src/util/libgnunetutil.la |
84 | 84 | ||
85 | check_SCRIPTS = \ | 85 | check_SCRIPTS = \ |
86 | test_gnunet_statistics.sh | 86 | test_gnunet_statistics.py |
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_statistics.py: test_gnunet_statistics.py.in Makefile | ||
95 | $(do_subst) < $(srcdir)/test_gnunet_statistics.py.in > test_gnunet_statistics.py | ||
96 | chmod +x test_gnunet_statistics.py | ||
87 | 97 | ||
88 | EXTRA_DIST = \ | 98 | EXTRA_DIST = \ |
89 | test_statistics_api_data.conf \ | 99 | test_statistics_api_data.conf \ |
90 | $(check_SCRIPTS) | 100 | test_gnunet_statistics.py.in |
91 | 101 | ||
92 | 102 | ||
diff --git a/src/statistics/test_gnunet_statistics.py.in b/src/statistics/test_gnunet_statistics.py.in new file mode 100644 index 000000000..b5697d246 --- /dev/null +++ b/src/statistics/test_gnunet_statistics.py.in | |||
@@ -0,0 +1,151 @@ | |||
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_st = [st, '-c', 'test_statistics_api_data.conf'] | ||
23 | run_arm = [arm, '-c', 'test_statistics_api_data.conf'] | ||
24 | debug = os.getenv ('DEBUG') | ||
25 | if debug: | ||
26 | run_arm += [debug.split (' ')] | ||
27 | |||
28 | def cleanup (): | ||
29 | shutil.rmtree (os.path.join (tmp, "test-gnunetd-statistics"), True) | ||
30 | |||
31 | def sub_run (args, want_stdo = True, want_stde = False, nofail = False): | ||
32 | if want_stdo: | ||
33 | stdo = subprocess.PIPE | ||
34 | else: | ||
35 | stdo = None | ||
36 | if want_stde: | ||
37 | stde = subprocess.PIPE | ||
38 | else: | ||
39 | stde = None | ||
40 | p = subprocess.Popen (args, stdout = stdo, stderr = stde) | ||
41 | stdo, stde = p.communicate () | ||
42 | if not nofail: | ||
43 | if p.returncode != 0: | ||
44 | sys.exit (p.returncode) | ||
45 | return (p.returncode, stdo, stde) | ||
46 | |||
47 | def fail (result): | ||
48 | print (result) | ||
49 | r_arm (['-e'], want_stdo = False) | ||
50 | sys.exit (1) | ||
51 | |||
52 | def r_arm (extra_args, **kw): | ||
53 | rc, stdo, stde = sub_run (run_arm + extra_args, **kw) | ||
54 | if rc != 0: | ||
55 | fail ("FAIL: error running {}".format (run_arm)) | ||
56 | return (rc, stdo, stde) | ||
57 | |||
58 | def r_st (extra_args, normal = True, **kw): | ||
59 | rc, stdo, stde = sub_run (run_st + extra_args, **kw) | ||
60 | if normal: | ||
61 | if rc != 0: | ||
62 | fail ("FAIL: error running {}".format (run_st)) | ||
63 | else: | ||
64 | if rc == 0: | ||
65 | fail ("FAIL: expected error while running {}".format (run_st)) | ||
66 | return (rc, stdo, stde) | ||
67 | |||
68 | def restart (): | ||
69 | print ("Restarting service...") | ||
70 | t = r_arm (['-k', 'statistics']) | ||
71 | time.sleep (1) | ||
72 | t = r_arm (['-i', 'statistics']) | ||
73 | time.sleep (1) | ||
74 | print ("DONE") | ||
75 | |||
76 | |||
77 | cleanup () | ||
78 | |||
79 | print ("Preparing: Starting service...") | ||
80 | t = r_arm (['-s'], want_stdo = False) | ||
81 | time.sleep (1) | ||
82 | t = r_arm (['-i', 'statistics'], want_stdo = False) | ||
83 | time.sleep (1) | ||
84 | print ("DONE") | ||
85 | |||
86 | print ("TEST: Bad argument checking...", end='') | ||
87 | r_st (['-x'], normal = False, nofail = True, want_stdo = False) | ||
88 | print ("PASS") | ||
89 | |||
90 | print ("TEST: Set value...", end='') | ||
91 | r_st (['-n', 'test', '-s', 'subsystem', '42'], nofail = True, want_stdo = False) | ||
92 | print ("PASS") | ||
93 | |||
94 | print ("TEST: Set another value...", end='') | ||
95 | r_st (['-n', 'other', '-s', 'osystem', '43'], nofail = True, want_stdo = False) | ||
96 | print ("PASS") | ||
97 | |||
98 | print ("TEST: Viewing all stats...", end='') | ||
99 | rc, stdo, stde = r_st ([], nofail = True, want_stdo = True) | ||
100 | if len (stdo.splitlines ()) != 2: | ||
101 | fail ("FAIL: unexpected output:\n{}".format (stdo)) | ||
102 | print ("PASS") | ||
103 | |||
104 | print ("TEST: Viewing stats by name...", end='') | ||
105 | rc, stdo, stde = r_st (['-n', 'other'], nofail = True, want_stdo = True) | ||
106 | if len ([x for x in stdo.splitlines () if re.search ('43', x)]) != 1: | ||
107 | fail ("FAIL: unexpected output:\n{}".format (stdo)) | ||
108 | print ("PASS") | ||
109 | |||
110 | print ("TEST: Viewing stats by subsystem...", end='') | ||
111 | rc, stdo, stde = r_st (['-s', 'subsystem'], nofail = True, want_stdo = True) | ||
112 | if len ([x for x in stdo.splitlines () if re.search ('42', x)]) != 1: | ||
113 | fail ("FAIL: unexpected output:\n{}".format (stdo)) | ||
114 | print ("PASS") | ||
115 | |||
116 | print ("TEST: Set persistent value...", end='') | ||
117 | rc, stdo, stde = r_st (['-n', 'lasting', '-s', 'subsystem', '40', '-p'], nofail = True, want_stdo = False) | ||
118 | rc, stdo, stde = r_st ([], nofail = True, want_stdo = True) | ||
119 | if len ([x for x in stdo.splitlines () if re.search ('40', x)]) != 1: | ||
120 | fail ("FAIL: unexpected output:\n{}".format (stdo)) | ||
121 | print ("PASS") | ||
122 | |||
123 | restart () | ||
124 | |||
125 | print ("TEST: Checking persistence...", end='') | ||
126 | rc, stdo, stde = r_st ([], nofail = True, want_stdo = True) | ||
127 | if len ([x for x in stdo.splitlines () if re.search ('40', x)]) != 1: | ||
128 | fail ("FAIL: unexpected output:\n{}".format (stdo)) | ||
129 | print ("PASS") | ||
130 | |||
131 | print ("TEST: Removing persistence...", end='') | ||
132 | rc, stdo, stde = r_st (['-n', 'lasting', '-s', 'subsystem', '40'], nofail = True, want_stdo = False) | ||
133 | rc, stdo, stde = r_st ([], nofail = True, want_stdo = True) | ||
134 | if len ([x for x in stdo.splitlines () if re.search ('!', x)]) != 0: | ||
135 | fail ("FAIL: unexpected output:\n{}".format (stdo)) | ||
136 | print ("PASS") | ||
137 | |||
138 | restart () | ||
139 | |||
140 | print ("TEST: Checking removed persistence...", end='') | ||
141 | rc, stdo, stde = r_st ([], nofail = True, want_stdo = True) | ||
142 | if len ([x for x in stdo.splitlines () if re.search ('40', x)]) != 0: | ||
143 | fail ("FAIL: unexpected output:\n{}".format (stdo)) | ||
144 | print ("PASS") | ||
145 | |||
146 | print ("Stopping service...") | ||
147 | t = r_arm (['-e'], want_stdo = False) | ||
148 | time.sleep (1) | ||
149 | print ("DONE") | ||
150 | |||
151 | cleanup () | ||
diff --git a/src/statistics/test_gnunet_statistics.sh b/src/statistics/test_gnunet_statistics.sh deleted file mode 100755 index eb2d618d9..000000000 --- a/src/statistics/test_gnunet_statistics.sh +++ /dev/null | |||
@@ -1,199 +0,0 @@ | |||
1 | #!/bin/sh | ||
2 | |||
3 | rm -rf /tmp/test-gnunetd-statistics/ | ||
4 | exe="./gnunet-statistics -c test_statistics_api_data.conf" | ||
5 | out=`mktemp /tmp/test-gnunet-statistics-logXXXXXXXX` | ||
6 | arm="gnunet-arm -c test_statistics_api_data.conf $DEBUG" | ||
7 | #DEBUG="-L DEBUG" | ||
8 | # ----------------------------------- | ||
9 | echo -n "Preparing: Starting service..." | ||
10 | |||
11 | $arm -s > /dev/null | ||
12 | sleep 1 | ||
13 | $arm -i statistics > /dev/null | ||
14 | sleep 1 | ||
15 | echo "DONE" | ||
16 | |||
17 | # ---------------------------------------------------------------------------------- | ||
18 | echo -n "TEST: Bad argument checking..." | ||
19 | |||
20 | if $exe -x 2> /dev/null; then | ||
21 | echo "FAIL: error running $exe" | ||
22 | $arm -e | ||
23 | exit 1 | ||
24 | fi | ||
25 | echo "PASS" | ||
26 | |||
27 | # ---------------------------------------------------------------------------------- | ||
28 | echo -n "TEST: Set value..." | ||
29 | |||
30 | if ! $exe $DEBUG -n test -s subsystem 42 ; then | ||
31 | echo "FAIL: error running $exe" | ||
32 | $arm -e | ||
33 | exit 1 | ||
34 | fi | ||
35 | echo "PASS" | ||
36 | |||
37 | # ---------------------------------------------------------------------------------- | ||
38 | echo -n "TEST: Set another value..." | ||
39 | |||
40 | if ! $exe $DEBUG -n other -s osystem 43 ; then | ||
41 | echo "FAIL: error running $exe" | ||
42 | $arm -e | ||
43 | exit 1 | ||
44 | fi | ||
45 | echo "PASS" | ||
46 | |||
47 | # ---------------------------------------------------------------------------------- | ||
48 | echo -n "TEST: viewing all stats..." | ||
49 | |||
50 | if ! $exe $DEBUG > $out; then | ||
51 | echo "FAIL: error running $exe" | ||
52 | $arm -e | ||
53 | exit 1 | ||
54 | fi | ||
55 | LINES=`cat $out | wc -l` | ||
56 | if test $LINES -ne 2; then | ||
57 | echo "FAIL: unexpected output" | ||
58 | $arm -e | ||
59 | exit 1 | ||
60 | fi | ||
61 | echo "PASS" | ||
62 | |||
63 | # ---------------------------------------------------------------------------------- | ||
64 | echo -n "TEST: viewing stats by name..." | ||
65 | |||
66 | if ! $exe $DEBUG -n other > $out; then | ||
67 | echo "FAIL: error running $exe" | ||
68 | $arm -e | ||
69 | exit 1 | ||
70 | fi | ||
71 | LINES=`cat $out | grep 43 | wc -l` | ||
72 | if test $LINES -ne 1; then | ||
73 | echo "FAIL: unexpected output" | ||
74 | $arm -e | ||
75 | exit 1 | ||
76 | fi | ||
77 | echo "PASS" | ||
78 | |||
79 | # ---------------------------------------------------------------------------------- | ||
80 | echo -n "TEST: viewing stats by subsystem..." | ||
81 | |||
82 | if ! $exe $DEBUG -s subsystem > $out; then | ||
83 | echo "FAIL: error running $exe" | ||
84 | $arm -e | ||
85 | exit 1 | ||
86 | fi | ||
87 | LINES=`cat $out | grep 42 | wc -l` | ||
88 | if test $LINES -ne 1; then | ||
89 | echo "FAIL: unexpected output" | ||
90 | $arm -e | ||
91 | exit 1 | ||
92 | fi | ||
93 | echo "PASS" | ||
94 | |||
95 | |||
96 | # ---------------------------------------------------------------------------------- | ||
97 | echo -n "TEST: Set persistent value..." | ||
98 | |||
99 | if ! $exe $DEBUG -n lasting -s subsystem 40 -p; then | ||
100 | echo "FAIL: error running $exe" | ||
101 | $arm -e | ||
102 | exit 1 | ||
103 | fi | ||
104 | if ! $exe $DEBUG > $out; then | ||
105 | echo "FAIL: error running $exe" | ||
106 | $arm -e | ||
107 | exit 1 | ||
108 | fi | ||
109 | LINES=`cat $out | grep 40 | wc -l` | ||
110 | if test $LINES -ne 1; then | ||
111 | echo "FAIL: unexpected output" | ||
112 | cat $out | ||
113 | $arm -e | ||
114 | exit 1 | ||
115 | fi | ||
116 | echo "PASS" | ||
117 | |||
118 | # ----------------------------------- | ||
119 | echo -n "Restarting service..." | ||
120 | $arm -k statistics > /dev/null | ||
121 | sleep 1 | ||
122 | $arm -i statistics > /dev/null | ||
123 | sleep 1 | ||
124 | echo "DONE" | ||
125 | |||
126 | # ---------------------------------------------------------------------------------- | ||
127 | echo -n "TEST: checking persistence..." | ||
128 | |||
129 | if ! $exe $DEBUG > $out; then | ||
130 | echo "FAIL: error running $exe" | ||
131 | $arm -e | ||
132 | exit 1 | ||
133 | fi | ||
134 | LINES=`cat $out | grep 40 | wc -l` | ||
135 | if test $LINES -ne 1; then | ||
136 | echo "FAIL: unexpected output" | ||
137 | cat $out | ||
138 | $arm -e | ||
139 | exit 1 | ||
140 | fi | ||
141 | echo "PASS" | ||
142 | |||
143 | |||
144 | |||
145 | # ---------------------------------------------------------------------------------- | ||
146 | echo -n "TEST: Removing persistence..." | ||
147 | |||
148 | if ! $exe $DEBUG -n lasting -s subsystem 40; then | ||
149 | echo "FAIL: error running $exe" | ||
150 | $arm -e | ||
151 | exit 1 | ||
152 | fi | ||
153 | if ! $exe $DEBUG > $out; then | ||
154 | echo "FAIL: error running $exe" | ||
155 | $arm -e | ||
156 | exit 1 | ||
157 | fi | ||
158 | LINES=`cat $out | grep \! | wc -l` | ||
159 | if test $LINES -ne 0; then | ||
160 | echo "FAIL: unexpected output" | ||
161 | cat $out | ||
162 | $arm -e | ||
163 | exit 1 | ||
164 | fi | ||
165 | echo "PASS" | ||
166 | |||
167 | |||
168 | # ----------------------------------- | ||
169 | echo -n "Restarting service..." | ||
170 | $arm -k statistics > /dev/null | ||
171 | sleep 1 | ||
172 | $arm -i statistics > /dev/null | ||
173 | sleep 1 | ||
174 | echo "DONE" | ||
175 | |||
176 | # ---------------------------------------------------------------------------------- | ||
177 | echo -n "TEST: checking removed persistence..." | ||
178 | |||
179 | if ! $exe $DEBUG > $out; then | ||
180 | echo "FAIL: error running $exe" | ||
181 | $arm -e | ||
182 | exit 1 | ||
183 | fi | ||
184 | LINES=`cat $out | grep 40 | wc -l` | ||
185 | if test $LINES -ne 0; then | ||
186 | echo "FAIL: unexpected output" | ||
187 | cat $out | ||
188 | $arm -e | ||
189 | exit 1 | ||
190 | fi | ||
191 | echo "PASS" | ||
192 | |||
193 | # ----------------------------------- | ||
194 | echo -n "Stopping service..." | ||
195 | $arm -e > /dev/null | ||
196 | sleep 1 | ||
197 | echo "DONE" | ||
198 | rm -f $out | ||
199 | rm -rf /tmp/test-gnunetd-statistics/ | ||