-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathrun.py
More file actions
53 lines (44 loc) · 1.5 KB
/
Copy pathrun.py
File metadata and controls
53 lines (44 loc) · 1.5 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
import argparse
import subprocess
import time
import signal
import os
from basicHttp import basicHttp
from virtualhost import virtualhost
from keepalive import keepalive
from rangeheader import rangeheader
from parallelhttp import parallelhttp
from logTest import logTest
def main():
parser = argparse.ArgumentParser(description='HTTP tests')
parser.add_argument('http_server', help='Path to http server file.')
parser.add_argument('config_file', help='Path to configuration file.')
args = parser.parse_args()
print(args.http_server)
try:
proc = subprocess.Popen(['python', args.http_server, args.config_file])
except subprocess.CalledProcessError as err:
print("Could not start server: {}".format(err))
print('server started successfully')
time.sleep(1)
total_score = 0
tests = [(basicHttp, 30), (virtualhost, 20), (parallelhttp, 20),
(keepalive, 15), (rangeheader, 15)]
for test, scaler in tests:
#print("loop")
t = test(args.config_file)
result = t.run() * scaler
total_score += result
# print("loop1")
print("---------------------\nTest for bonus")
t = logTest(args.config_file)
bonus = (t.run() == 1)
print("---------------------\nTotal score is: {}".format(total_score))
if bonus:
print("You got bonus +5% on midterm!")
else:
print("No bonus, try harder!")
# stop service
os.kill(proc.pid, signal.SIGUSR1)
if __name__ == '__main__':
main()