|
35 | 35 | from common.Exceptions import CommandFailed
|
36 | 36 | from common import OpTestInstallUtil
|
37 | 37 |
|
| 38 | +import socket |
| 39 | + |
38 | 40 | import logging
|
39 | 41 | import OpTestLogger
|
40 | 42 | log = OpTestLogger.optest_logger_glob.get_logger(__name__)
|
41 | 43 |
|
42 | 44 | NR_GCOV_DUMPS = 0
|
43 | 45 |
|
44 |
| - |
45 | 46 | class gcov():
|
46 | 47 | '''
|
47 | 48 | Base "test case" for extracting skiboot GCOV code coverage data from the
|
@@ -85,31 +86,34 @@ def runTest(self):
|
85 | 86 | if not my_ip:
|
86 | 87 | self.fail(
|
87 | 88 | "We failed to get the IP from Petitboot or Host, check that the IP's are configured")
|
88 |
| - port = iutil.start_server(my_ip) |
89 |
| - |
90 |
| - url = 'http://{}:{}/upload'.format(my_ip, port) |
91 |
| - insanity = "(echo 'POST /upload/gcov HTTP/1.1'; \n" |
92 |
| - insanity += "echo 'Host: {}:{}';\n".format(my_ip, port) |
93 |
| - insanity += "echo 'Content-length: {}';\n".format(l[0]) |
94 |
| - insanity += "echo 'Origin: http://{}:{}'; \n".format(my_ip, port) |
95 |
| - boundary = "OhGoodnessWhyDoIHaveToDoThis" |
96 |
| - insanity += "echo 'Content-Type: multipart/form-data; " |
97 |
| - insanity += "boundary={}';\n".format(boundary) |
98 |
| - insanity += "echo; echo '--{}'; \n".format(boundary) |
99 |
| - insanity += "echo 'Content-Disposition: form-data; name=\"file\"; " |
100 |
| - insanity += "filename=\"gcov\"'; \n" |
101 |
| - insanity += "echo 'Content-Type: application/octet-stream'; echo; \n" |
102 |
| - insanity += "cat /sys/firmware/opal/exports/gcov; \n" |
103 |
| - insanity += "echo; echo '--{}--';\n".format(boundary) |
104 |
| - insanity += ") | nc {} {}".format(my_ip, port) |
105 |
| - self.c.run_command(insanity) |
106 |
| - |
107 |
| - global NR_GCOV_DUMPS |
108 |
| - NR_GCOV_DUMPS = NR_GCOV_DUMPS + 1 |
109 |
| - filename = os.path.join( |
110 |
| - self.gcov_dir, 'gcov-saved-{}'.format(NR_GCOV_DUMPS)) |
111 |
| - with open(filename, 'wb') as f: |
112 |
| - f.write(iutil.get_uploaded_file('gcov')) |
| 89 | + |
| 90 | + HOST, PORT = "0.0.0.0", 0 |
| 91 | + with socket.socket(socket.AF_INET, socket.SOCK_STREAM) as s: |
| 92 | + s.bind((HOST, PORT)) |
| 93 | + port = s.getsockname()[1] |
| 94 | + s.listen(1) |
| 95 | + print(("# TCP Listening on %s" % port)) |
| 96 | + |
| 97 | + insanity = "cat /sys/firmware/opal/exports/gcov " |
| 98 | + insanity += "| nc {} {}\n".format(my_ip, port) |
| 99 | + self.c.get_console().send(insanity) |
| 100 | + conn, addr = s.accept() |
| 101 | + with conn: |
| 102 | + print('Connected by ', addr) |
| 103 | + |
| 104 | + global NR_GCOV_DUMPS |
| 105 | + NR_GCOV_DUMPS = NR_GCOV_DUMPS + 1 |
| 106 | + filename = os.path.join( |
| 107 | + self.gcov_dir, 'gcov-saved-{}'.format(NR_GCOV_DUMPS)) |
| 108 | + with open(filename, 'wb') as f: |
| 109 | + size = int(l[0].split()[0]) |
| 110 | + while size: |
| 111 | + data = conn.recv(4096) |
| 112 | + size = size - len(data) |
| 113 | + if not data: break |
| 114 | + f.write(data) |
| 115 | + self.c.get_console().expect('#') |
| 116 | + self.c.run_command('echo Hello') |
113 | 117 |
|
114 | 118 |
|
115 | 119 | class Skiroot(gcov, unittest.TestCase):
|
|
0 commit comments