Fix script used for fuzzer nightly test

This commit is contained in:
Bhargava Shastry 2020-02-18 12:48:21 +05:30
parent 9871daa053
commit 5d5bb00716
2 changed files with 16 additions and 23 deletions

View File

@ -413,6 +413,7 @@ jobs:
- run: - run:
name: Regression tests name: Regression tests
command: | command: |
git clone https://github.com/ethereum/solidity-fuzzing-corpus /tmp/solidity-fuzzing-corpus
mkdir -p test_results mkdir -p test_results
scripts/regressions.py -o test_results scripts/regressions.py -o test_results
- run: *gitter_notify_failure - run: *gitter_notify_failure

View File

@ -31,7 +31,7 @@ class PrintDotsThread(object):
time.sleep(self.interval) time.sleep(self.interval)
class regressor(): class regressor():
_re_sanitizer_log = re.compile(r"""(.*runtime error: (?P<sanitizer>\w+).*|std::exception::what: (?P<description>\w+).*)""") _re_sanitizer_log = re.compile(r"""ERROR: (libFuzzer|UndefinedBehaviorSanitizer)""")
def __init__(self, description, args): def __init__(self, description, args):
self._description = description self._description = description
@ -44,7 +44,7 @@ class regressor():
def parseCmdLine(self, description, args): def parseCmdLine(self, description, args):
argParser = ArgumentParser(description) argParser = ArgumentParser(description)
argParser.add_argument('-o', '--out-dir', required=True, type=str, argParser.add_argument('-o', '--out-dir', required=True, type=str,
help="""Directory where test results will be written""") help="""Directory where test results will be written""")
return argParser.parse_args(args) return argParser.parse_args(args)
@staticmethod @staticmethod
@ -89,8 +89,7 @@ class regressor():
## Log may contain non ASCII characters, so we simply stringify them ## Log may contain non ASCII characters, so we simply stringify them
## since they don't matter for regular expression matching ## since they don't matter for regular expression matching
rawtext = str(open(logfile, 'rb').read()) rawtext = str(open(logfile, 'rb').read())
list = re.findall(self._re_sanitizer_log, rawtext) return not re.search(self._re_sanitizer_log, rawtext)
return len(list) == 0
def run(self): def run(self):
""" """
@ -106,29 +105,22 @@ class regressor():
logfile = os.path.join(self._logpath, "{}.log".format(basename)) logfile = os.path.join(self._logpath, "{}.log".format(basename))
corpus_dir = "/tmp/solidity-fuzzing-corpus/{0}_seed_corpus" \ corpus_dir = "/tmp/solidity-fuzzing-corpus/{0}_seed_corpus" \
.format(basename) .format(basename)
cmd = "find {0} -type f | xargs -n1 {1}".format(corpus_dir, fuzzer) cmd = "find {0} -type f | xargs -n1 sh -c '{1} $0 || exit 255'".format(corpus_dir, fuzzer)
cmd_status = self.run_cmd(cmd, logfile=logfile) self.run_cmd(cmd, logfile=logfile)
if cmd_status: ret = self.process_log(logfile)
ret, numLeaks = self.process_log(logfile) if not ret:
if not ret: print(
print( "\t[-] libFuzzer reported failure for {0}. "
"\t[-] libFuzzer reported failure for {0}. " "Failure logged to test_results".format(
"Failure logged to test_results".format( basename))
basename)) testStatus.append(False)
testStatus.append(cmd_status)
else:
print("\t[+] {0} passed regression tests but leaked "
"memory.".format(basename))
print("\t\t[+] Suppressed {0} memory leak reports".format(
numLeaks))
testStatus.append(0)
else: else:
print("\t[+] {0} passed regression tests.".format(basename)) print("\t[+] {0} passed regression tests.".format(basename))
testStatus.append(cmd_status) testStatus.append(True)
return any(testStatus) return all(testStatus)
if __name__ == '__main__': if __name__ == '__main__':
dotprinter = PrintDotsThread() dotprinter = PrintDotsThread()
tool = regressor(DESCRIPTION, sys.argv[1:]) tool = regressor(DESCRIPTION, sys.argv[1:])
sys.exit(tool.run()) sys.exit(not tool.run())