Skip to content

Commit

Permalink
Python 3 fixes for Fuchsia code. (google#1530)
Browse files Browse the repository at this point in the history
  • Loading branch information
oliverchang authored Mar 10, 2020
1 parent cb03caa commit b2a2e81
Show file tree
Hide file tree
Showing 4 changed files with 19 additions and 22 deletions.
2 changes: 1 addition & 1 deletion src/python/bot/fuzzers/libfuzzer.py
Original file line number Diff line number Diff line change
Expand Up @@ -642,7 +642,7 @@ def fuzz(self,
additional_args)
self.fuzzer.monitor(return_code)
self.process_logs_and_crash(artifact_prefix)
with open(self.fuzzer.logfile) as logfile:
with open(self.fuzzer.logfile, 'rb') as logfile:
symbolized_output = logfile.read()

self._pull_new_corpus_from_target_to_host(corpus_directories,
Expand Down
33 changes: 15 additions & 18 deletions src/python/platforms/fuchsia/util/device.py
Original file line number Diff line number Diff line change
Expand Up @@ -170,7 +170,7 @@ def getpids(self):
for fuzzer in self.host.fuzzers:
tgt = (fuzzer[1] + '.cmx')[:32]
url = ('fuchsia-pkg://fuchsia.com/%s#meta' % fuzzer[0])[:32]
for line in str(out).split('\n'):
for line in out.decode('utf-8').split('\n'):
match = re.search(tgt + r'\[(\d+)\]: ' + url, line)
if match:
pids[fuzzer[1]] = int(match.group(1))
Expand All @@ -193,13 +193,13 @@ def ls(self, path):
try:
p = self._ssh(['ls', '-l', path], stdout=subprocess.PIPE).popen()
out, _ = p.communicate()
for line in str(out).split('\n'):
for line in out.decode('utf-8').split('\n'):
# Line ~= '-rw-r--r-- 1 0 0 8192 Mar 18 22:02 some-name'
parts = line.split()
# When we're running ls over ssh, we may get a note about
# "Warning: Permanently added [address] to the list of known hosts"
# Don't try to treat those as file paths
if len(parts) > 8 and "Warning:" not in parts:
if len(parts) > 8 and 'Warning:' not in parts:
results[' '.join(parts[8:])] = int(parts[4])
except subprocess.CalledProcessError:
pass
Expand Down Expand Up @@ -231,9 +231,9 @@ def _guess_pid(self):
"""
out = self._dump_log(['--only', 'reset,Fuzzer,Sanitizer'])
pid = -1
for line in out.split('\n'):
for line in out.split(b'\n'):
# Log lines are like '[timestamp][pid][tid][name] data'
parts = line.split('][')
parts = line.split(b'][')
if len(parts) > 2:
pid = int(parts[1])
return pid
Expand All @@ -254,14 +254,14 @@ def process_logs(self, logfile, guess_pid=False, retcode=0):
A list of the test artifacts (e.g. crashes) reported in the logs.
"""
pid = -1
pid_pattern = re.compile(r'==([0-9]+)==')
mutation_pattern = re.compile(r'^MS: [0-9]*')
pid_pattern = re.compile(br'==([0-9]+)==')
mutation_pattern = re.compile(br'^MS: [0-9]*')
artifacts = []
artifact_pattern = re.compile(r'Test unit written to data/(\S*)')
repro_pattern = re.compile(r'Running: .*')
artifact_pattern = re.compile(br'Test unit written to data/(\S*)')
repro_pattern = re.compile(br'Running: .*')
line_with_crash_message = None
with open(logfile) as log:
with open(logfile + '.tmp', 'w') as tmp:
with open(logfile, 'rb') as log:
with open(logfile + '.tmp', 'wb') as tmp:
for line in log:
# Check for a line that tells us the process ID
match = pid_pattern.search(line)
Expand All @@ -280,12 +280,9 @@ def process_logs(self, logfile, guess_pid=False, retcode=0):
pid = self._guess_pid()
if pid > 0:
raw = self._dump_log(['--pid', str(pid)])
for item in raw:
if re.search(r'.*ERROR: AddressSanitizer.*', item):
tmp.write(item)
sym = self.host.symbolize(raw)
tmp.write('\n'.join(sym))
tmp.write('\n')
tmp.write(b'\n'.join(sym))
tmp.write(b'\n')

# Check for an artifact being reported.
match = artifact_pattern.search(line)
Expand All @@ -302,8 +299,8 @@ def process_logs(self, logfile, guess_pid=False, retcode=0):
# TODO(flowerhack): Change the log output in Fuchsia itself, s.t. the
# ordering is correct the *first* time, and we won't have to do this
# fix-up-the-logs dance!
with open(logfile + '.tmp') as tmp:
with open(logfile, 'w') as final:
with open(logfile + '.tmp', 'rb') as tmp:
with open(logfile, 'wb') as final:
if line_with_crash_message:
final.write(line_with_crash_message)

Expand Down
4 changes: 2 additions & 2 deletions src/python/platforms/fuchsia/util/host.py
Original file line number Diff line number Diff line change
Expand Up @@ -179,8 +179,8 @@ def symbolize(self, raw):
p.stdin = subprocess.PIPE
p.stdout = subprocess.PIPE
out, _ = p.popen().communicate(raw)
processed_out = re.sub(r'[0-9\[\]\.]*\[klog\] INFO: ', '', out)
return processed_out.split('\n')
processed_out = re.sub(br'[0-9\[\]\.]*\[klog\] INFO: ', b'', out)
return processed_out.split(b'\n')

def notify_user(self, title, body):
"""Displays a message to the user in a platform-specific way"""
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -300,7 +300,7 @@ def test_prune(self):
corpus = os.listdir(self.corpus_dir)
self.assertEqual(2, len(corpus))
six.assertCountEqual(self, [
'31836aeaab22dc49555a97edb4c753881432e01d',
'801c34269f74ed383fc97de33604b8a905adb635',
'7cf184f4c67ad58283ecb19349720b0cae756829'
], corpus)
quarantine = os.listdir(self.quarantine_dir)
Expand Down

0 comments on commit b2a2e81

Please sign in to comment.