-
Notifications
You must be signed in to change notification settings - Fork 0
/
test.py
executable file
·113 lines (86 loc) · 3.11 KB
/
test.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
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
#!/usr/bin/python
import argparse
import subprocess
import sys
import os
import signal
import platform
success = True
def close_server(uut):
os.kill(uut.pid, signal.SIGINT)
resLine = uut.stdout.readline()
return resLine == "Server exiting cleanly.\n"
def wdribble(port, f):
return ["support/wdribble-Darwin-i386", "0", port,
"1", "0", "0", "127.0.0.1", f];
def print_result(test):
print("...." + ("PASSED" if test else "FAILED"))
return test
parser = argparse.ArgumentParser();
parser.add_argument("prog_dir",
help="The directory containing the project source files.")
args = parser.parse_args()
nothing = open("/dev/null", "w");
os.chdir(args.prog_dir)
sys.stdout.write("Compiling program")
subprocess.call(["make", "clean"], stdout=nothing)
if not (print_result(not subprocess.call(["make", "all"], stdout=nothing))):
success = False
sys.exit()
binName = "json-server-" + platform.system() + "-" + platform.machine()
errorLog = open("error.log", "a")
uut = subprocess.Popen(
["./" + binName],
stdout=subprocess.PIPE,
stdin=subprocess.PIPE,
stderr=errorLog
)
declLine = uut.stdout.readline()
uutPort = int(declLine.split(" ")[-1])
sys.stdout.write(declLine)
print("Port: " + str(uutPort))
sys.stdout.write("Testing if server exits cleanly")
if not print_result(close_server(uut)):
success = False
uut.wait()
nothing.close()
errorLog.close()
if success:
print("SUCCESS :)")
else:
print("FAIL :(")
# parser.add_argument("ref_port", help="the port of the server to be tested");
# parser.add_argument("uut_port", help="the port of the server to be tested");
# args = parser.parse_args();
# ref = ["./wdribble-Darwin-i386", "0", args.ref_port,
# "1", "0", "0", "127.0.0.1", "/big_file.iso"];
# uut = ["./wdribble-Darwin-i386", "0", args.uut_port,
# "1", "0", "0", "127.0.0.1", "/big_file.iso"];
# tests = [("/", "index"),
# ("/asdfg", "404"),
# ("/no.html", "403"),
# ("/f", "listing")];
# processes = [];
# nothing = open('/dev/null', 'w');
# print("Testing Errors");
# for path, name in tests:
# subprocess.call("./wdribble-Darwin-i386 0 " + args.ref_port + " 1 0 0 127.0.0.1 " + path + " > " + name + ".out 2> /dev/null", shell=True);
# subprocess.call("./wdribble-Darwin-i386 0 " + args.uut_port + " 1 0 0 127.0.0.1 " + path + " > " + name + ".myout 2> /dev/null", shell=True);
# try:
# subprocess.check_output(["diff", name + ".out", name + ".myout"]);
# except subprocess.CalledProcessError as error:
# print("Failed " + name + " test with diff return code " + str(error.returncode));
# print("Testing Concurrency");
# processes.append(subprocess.Popen(uut, stdout=nothing));
# uut[-1] = "/";
# for _ in range(100):
# processes.append(subprocess.Popen(uut, stdout=nothing, stderr=nothing));
# print("Waiting for processes");
# for process in processes:
# process.wait();
# print("Testing CGI Quit")
# uut[-1] = "/cgi-bin/quit";
# processes.append(subprocess.Popen(uut));
# uut[-1] = "/cgi-bin/quit?confirm=1";
# processes.append(subprocess.Popen(uut));
# print("Finished!");