-
Notifications
You must be signed in to change notification settings - Fork 7
/
run.py
72 lines (54 loc) · 1.46 KB
/
run.py
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
#!/usr/bin/env python2
import sys, os
import hashlib
from subprocess import Popen, PIPE
str2 = "test_test" * (1 << 20)
str1 = "Test_Test!"
use_ssh = True
ssh = []
src = os.getenv("TCP_SRC", "localhost")
dst = os.getenv("TCP_DST", "localhost")
sport = os.getenv("TCP_SPORT", "12345")
dport = os.getenv("TCP_DPORT", "54321")
ssh_key = os.getenv("TCP_SSHKEY", "")
if src != "localhost":
if Popen(["scp", "-i", ssh_key, "tcp-constructor", "tcp-test.py", "tcp-constructor.py", "root@%s:" % dst]).wait():
sys.exit(1)
ssh = ["ssh", "-i", ssh_key, "root@%s" % dst]
print sys.argv[1]
args = [sys.argv[1],
"--addr", src, "--port", sport, "--seq", "555",
"--next",
"--addr", dst, "--port", dport, "--seq", "666",
"--reverse", "--", "./tcp-test.py"]
p1 = Popen(ssh + args + ["dst"], stdout = PIPE, stdin = PIPE)
args.remove("--reverse");
p2 = Popen(args + ["src"], stdout = PIPE, stdin = PIPE)
p1.stdout.read(5)
p2.stdout.read(5)
p1.stdin.write("start")
p2.stdin.write("start")
p1.stdin.write(str1)
p1.stdin.close()
p2.stdin.write(str2)
p2.stdin.close()
s = p1.stdout.read()
m = hashlib.md5()
m.update(str2)
str2 = m.hexdigest()
if str2 != eval(s):
print "FAIL", repr(str2), repr(s)
sys.exit(5);
s = p1.stdout.read()
m = hashlib.md5()
m.update(str1)
str1 = m.hexdigest()
s = p2.stdout.read()
if str1 != eval(s):
print "FAIL", repr(str1), s
sys.exit(5);
if p1.wait():
sys.exit(1)
if p2.wait():
sys.exit(1)
print "PASS"