forked from libtrading/libtrading
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathtest.py
More file actions
executable file
·179 lines (144 loc) · 3.99 KB
/
test.py
File metadata and controls
executable file
·179 lines (144 loc) · 3.99 KB
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
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
#!/usr/bin/env python
import subprocess
import getopt
import signal
import time
import sys
numfail = 0
fix_tests = [
#
# FIX session level test cases. See Volume 2 of the FIX 4.4 specification for
# details.
#
"2b_MsgSeqNumHigherThanExpected",
"2c_MsgSeqNumLowerThanExpected",
"4b_TestRequestMessageIsReceived"
]
def green(s):
return "\033[32m" + s + "\033[0m"
def red(s):
return "\033[31m" + s + "\033[0m"
try:
opts, args = getopt.getopt(sys.argv[1:], "v")
except getopt.GetoptError, err:
print str(err)
sys.exit(1)
verbose = 0
for o, a in opts:
if o == "-v":
verbose += 1
if verbose == 2:
out = open('/dev/stdout', 'w')
err = open('/dev/stderr', 'w')
else:
out = open('/dev/null', 'w')
err = open('/dev/null', 'w')
def popen_fix_server():
args = [
"./tools/fix/fix_server",
"-p", "9000",
"-f", "./tools/fix/scripts/%s" % test]
return subprocess.Popen(args, stderr = err, stdout = out)
def popen_fix_client():
args = [
"./tools/fix/fix_client",
"-h", "localhost",
"-p", "9000",
"-f", "./tools/fix/scripts/%s" % test]
return subprocess.Popen(args, stderr = err, stdout = out)
for test in fix_tests:
if verbose == 2:
print "%s\n%s\n" % (test, "-" * len(test))
server = popen_fix_server()
result = 1
try:
client = popen_fix_client()
result = client.wait()
finally:
if result != 0:
if verbose == 2:
status = "\n%s\n" % red("FAIL")
else:
status = "%-40s [%s]" % (test, red("FAIL"))
print status
numfail = numfail + 1
while server.poll() is None:
server.terminate()
while client.poll() is None:
client.terminate()
else:
if verbose == 2:
status = "\n%s\n" % green("PASS")
elif verbose == 1:
status = "%-40s [%s]" % (test, green("PASS"))
if verbose != 0:
print status
if numfail > 0:
print "\n" + red("FIX tests run: %d, Failures: %d" % (len(fix_tests), numfail))
else:
print "\nOK (%d FIX tests)" % (len(fix_tests))
if numfail != 0:
result = 1
else:
result = 0
if result != 0:
sys.exit(result)
fast_tests = [
"IncrementOperator",
"ConstantOperator",
"DefaultOperator",
"DeltaOperator",
"CopyOperator",
"NoneOperator",
]
def popen_fast_server():
args = [
"./tools/fast/fast_server",
"-p", "9000",
"-f", "./tools/fast/scripts/%s" % test,
"-t", "./tools/fast/scripts/%s.xml" % test]
return subprocess.Popen(args, stderr = err, stdout = out)
def popen_fast_client():
args = [
"./tools/fast/fast_client",
"-h", "localhost",
"-p", "9000",
"-f", "./tools/fast/scripts/%s" % test,
"-t", "./tools/fast/scripts/%s.xml" % test]
return subprocess.Popen(args, stderr = err, stdout = out)
for test in fast_tests:
if verbose == 2:
print "%s\n%s\n" % (test, "-" * len(test))
server = popen_fast_server()
result = 1
try:
client = popen_fast_client()
result = client.wait()
finally:
if result != 0:
if verbose == 2:
status = "\n%s\n" % red("FAIL")
else:
status = "%-40s [%s]" % (test, red("FAIL"))
print status
numfail = numfail + 1
while server.poll() is None:
server.terminate()
while client.poll() is None:
client.terminate()
else:
if verbose == 2:
status = "\n%s\n" % green("PASS")
elif verbose == 1:
status = "%-40s [%s]" % (test, green("PASS"))
if verbose != 0:
print status
if numfail > 0:
print "\n" + red("FAST tests run: %d, Failures: %d" % (len(fast_tests), numfail))
else:
print "\nOK (%d FAST tests)" % (len(fast_tests))
if numfail != 0:
result = 1
else:
result = 0
sys.exit(result)