Skip to content

Commit 316b793

Browse files
authored
Merge pull request #520 from stewart-ibm/gcov-simplify
gcov: simplify and use pure sockets
2 parents a7326de + c7f74e3 commit 316b793

File tree

1 file changed

+30
-26
lines changed

1 file changed

+30
-26
lines changed

testcases/gcov.py

+30-26
Original file line numberDiff line numberDiff line change
@@ -35,13 +35,14 @@
3535
from common.Exceptions import CommandFailed
3636
from common import OpTestInstallUtil
3737

38+
import socket
39+
3840
import logging
3941
import OpTestLogger
4042
log = OpTestLogger.optest_logger_glob.get_logger(__name__)
4143

4244
NR_GCOV_DUMPS = 0
4345

44-
4546
class gcov():
4647
'''
4748
Base "test case" for extracting skiboot GCOV code coverage data from the
@@ -85,31 +86,34 @@ def runTest(self):
8586
if not my_ip:
8687
self.fail(
8788
"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')
113117

114118

115119
class Skiroot(gcov, unittest.TestCase):

0 commit comments

Comments
 (0)