-
Notifications
You must be signed in to change notification settings - Fork 389
Expand file tree
/
Copy pathtest.py
More file actions
executable file
·52 lines (39 loc) · 1.2 KB
/
test.py
File metadata and controls
executable file
·52 lines (39 loc) · 1.2 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
#!/usr/bin/env python3
import _thread
import http.server
import sys
import urllib.error
import urllib.parse
import urllib.request
from vmrunner import vmrunner
HOST = ''
PORT = 9011
DO_SERVE = True
class RequestHandler(http.server.BaseHTTPRequestHandler):
def do_GET(s):
s.send_response(200)
s.send_header("Content-type", "text/plain; charset=utf-8",)
s.end_headers()
s.wfile.write(s.path.encode("utf-8"))
def Client_test():
server_class = http.server.HTTPServer
httpd = server_class((HOST, PORT), RequestHandler)
global DO_SERVE
while(DO_SERVE):
httpd.handle_request()
DO_SERVE = False
httpd.server_close()
# Start web server in a separate thread
_thread.start_new_thread(Client_test, ())
def Server_test(triggerline):
res = urllib.request.urlopen("http://10.0.0.46:8080").read()
assert(res.decode('utf-8') == "Hello")
# Get an auto-created VM from the vmrunner
vm = vmrunner.vms[0]
# Add custom event for testing server
vm.on_output("Listening on port 8080", Server_test)
if len(sys.argv) > 1:
vm.boot(image_name=str(sys.argv[1]))
else:
# Boot the VM, taking a timeout as parameter
vm.boot(20,image_name='net_http.elf.bin')