Skip to content

Commit

Permalink
Merge pull request #520 from stewart-ibm/gcov-simplify
Browse files Browse the repository at this point in the history
gcov: simplify and use pure sockets
  • Loading branch information
stewartsmith authored Jul 22, 2019
2 parents a7326de + c7f74e3 commit 316b793
Showing 1 changed file with 30 additions and 26 deletions.
56 changes: 30 additions & 26 deletions testcases/gcov.py
Original file line number Diff line number Diff line change
Expand Up @@ -35,13 +35,14 @@
from common.Exceptions import CommandFailed
from common import OpTestInstallUtil

import socket

import logging
import OpTestLogger
log = OpTestLogger.optest_logger_glob.get_logger(__name__)

NR_GCOV_DUMPS = 0


class gcov():
'''
Base "test case" for extracting skiboot GCOV code coverage data from the
Expand Down Expand Up @@ -85,31 +86,34 @@ def runTest(self):
if not my_ip:
self.fail(
"We failed to get the IP from Petitboot or Host, check that the IP's are configured")
port = iutil.start_server(my_ip)

url = 'http://{}:{}/upload'.format(my_ip, port)
insanity = "(echo 'POST /upload/gcov HTTP/1.1'; \n"
insanity += "echo 'Host: {}:{}';\n".format(my_ip, port)
insanity += "echo 'Content-length: {}';\n".format(l[0])
insanity += "echo 'Origin: http://{}:{}'; \n".format(my_ip, port)
boundary = "OhGoodnessWhyDoIHaveToDoThis"
insanity += "echo 'Content-Type: multipart/form-data; "
insanity += "boundary={}';\n".format(boundary)
insanity += "echo; echo '--{}'; \n".format(boundary)
insanity += "echo 'Content-Disposition: form-data; name=\"file\"; "
insanity += "filename=\"gcov\"'; \n"
insanity += "echo 'Content-Type: application/octet-stream'; echo; \n"
insanity += "cat /sys/firmware/opal/exports/gcov; \n"
insanity += "echo; echo '--{}--';\n".format(boundary)
insanity += ") | nc {} {}".format(my_ip, port)
self.c.run_command(insanity)

global NR_GCOV_DUMPS
NR_GCOV_DUMPS = NR_GCOV_DUMPS + 1
filename = os.path.join(
self.gcov_dir, 'gcov-saved-{}'.format(NR_GCOV_DUMPS))
with open(filename, 'wb') as f:
f.write(iutil.get_uploaded_file('gcov'))

HOST, PORT = "0.0.0.0", 0
with socket.socket(socket.AF_INET, socket.SOCK_STREAM) as s:
s.bind((HOST, PORT))
port = s.getsockname()[1]
s.listen(1)
print(("# TCP Listening on %s" % port))

insanity = "cat /sys/firmware/opal/exports/gcov "
insanity += "| nc {} {}\n".format(my_ip, port)
self.c.get_console().send(insanity)
conn, addr = s.accept()
with conn:
print('Connected by ', addr)

global NR_GCOV_DUMPS
NR_GCOV_DUMPS = NR_GCOV_DUMPS + 1
filename = os.path.join(
self.gcov_dir, 'gcov-saved-{}'.format(NR_GCOV_DUMPS))
with open(filename, 'wb') as f:
size = int(l[0].split()[0])
while size:
data = conn.recv(4096)
size = size - len(data)
if not data: break
f.write(data)
self.c.get_console().expect('#')
self.c.run_command('echo Hello')


class Skiroot(gcov, unittest.TestCase):
Expand Down

0 comments on commit 316b793

Please sign in to comment.