]>
git.saurik.com Git - apple/xnu.git/blob - tools/tests/perf_index/test_controller.py
2 from __future__
import absolute_import
, print_function
10 def waitformsgs(client_sockets
, msg
):
11 client_sockets_set
= set(client_sockets
)
12 while len(client_sockets_set
) > 0:
13 rl
, _
, _
= select
.select(client_sockets_set
, [], [])
14 for client_socket
in rl
:
15 sentmsg
= client_socket
.recv(1024)
17 client_sockets_set
.remove(client_socket
)
19 def main(num_clients
, test_type
, num_threads
, job_size
, args
):
21 control_socket
= socket
.socket()
22 control_socket
.setsockopt(socket
.SOL_SOCKET
, socket
.SO_REUSEADDR
, 1)
23 control_socket
.bind(("", _CONTROL_PORT
))
24 control_socket
.listen(num_clients
)
25 while(len(client_sockets
)<num_clients
):
26 client_socket
, _
= control_socket
.accept()
27 msg
= "\0".join(["%s\0%d\0%d" % (test_type
, num_threads
, job_size
)] + args
) + "\0\0"
28 client_socket
.send(msg
)
29 client_sockets
.append(client_socket
)
31 control_socket
.close()
33 waitformsgs(client_sockets
, "Ready")
35 start_time
= time
.time()
37 for client_socket
in client_sockets
:
38 client_socket
.shutdown(socket
.SHUT_WR
)
40 waitformsgs(client_sockets
, "Done")
43 for client_socket
in client_sockets
:
46 end_time
= time
.time()
47 return end_time
- start_time
50 sys
.stderr
.write("usage: start_tests.py num_clients type threads size\n")
53 if __name__
== "__main__":
57 num_clients
= int(sys
.argv
[1])
58 test_type
= sys
.argv
[2]
59 num_threads
= int(sys
.argv
[3])
60 job_size
= int(sys
.argv
[4])
65 print(main(num_clients
, test_type
, num_threads
, job_size
, args
))