Refactor crash test stderr parsing logic into a function (#12109)

Summary:
This is a simple refactor for the crash test script to put shared logic for parsing stderr into a function. There is no functional change.

Pull Request resolved: https://github.com/facebook/rocksdb/pull/12109

Test Plan: manually tested the script

Reviewed By: ajkr

Differential Revision: D51692172

Pulled By: jowlyzhang

fbshipit-source-id: d346d64e981d9c489c380ff6ce33296a224b5877
This commit is contained in:
Yu Zhang 2023-12-01 11:01:29 -08:00 committed by Facebook GitHub Bot
parent b760af321f
commit 7eca51dfc3
1 changed files with 22 additions and 40 deletions

View File

@ -814,6 +814,24 @@ def execute_cmd(cmd, timeout=None):
return hit_timeout, child.returncode, outs.decode("utf-8"), errs.decode("utf-8") return hit_timeout, child.returncode, outs.decode("utf-8"), errs.decode("utf-8")
def exit_if_stderr_has_errors(stderr, print_stderr=True):
if print_stderr:
for line in stderr.split("\n"):
if line != "" and not line.startswith("WARNING"):
print("stderr has error message:")
print("***" + line + "***")
stderrdata = stderr.lower()
errorcount = stderrdata.count("error") - stderrdata.count("got errors 0 times")
print("#times error occurred in output is " + str(errorcount) + "\n")
if errorcount > 0:
print("TEST FAILED. Output has 'error'!!!\n")
sys.exit(2)
if stderrdata.find("fail") >= 0:
print("TEST FAILED. Output has 'fail'!!!\n")
sys.exit(2)
# This script runs and kills db_stress multiple times. It checks consistency # This script runs and kills db_stress multiple times. It checks consistency
# in case of unsafe crashes in RocksDB. # in case of unsafe crashes in RocksDB.
def blackbox_crash_main(args, unknown_args): def blackbox_crash_main(args, unknown_args):
@ -846,21 +864,7 @@ def blackbox_crash_main(args, unknown_args):
print(errs) print(errs)
sys.exit(2) sys.exit(2)
for line in errs.split("\n"): exit_if_stderr_has_errors(errs);
if line != "" and not line.startswith("WARNING"):
print("stderr has error message:")
print("***" + line + "***")
stderrdata = errs.lower()
errorcount = stderrdata.count("error") - stderrdata.count("got errors 0 times")
print("#times error occurred in output is " + str(errorcount) + "\n")
if errorcount > 0:
print("TEST FAILED. Output has 'error'!!!\n")
sys.exit(2)
if stderrdata.find("fail") >= 0:
print("TEST FAILED. Output has 'fail'!!!\n")
sys.exit(2)
time.sleep(1) # time to stabilize before the next run time.sleep(1) # time to stabilize before the next run
@ -880,21 +884,7 @@ def blackbox_crash_main(args, unknown_args):
# Print stats of the final run # Print stats of the final run
print("stdout:", outs) print("stdout:", outs)
for line in errs.split("\n"): exit_if_stderr_has_errors(errs)
if line != "" and not line.startswith("WARNING"):
print("stderr has error message:")
print("***" + line + "***")
stderrdata = errs.lower()
errorcount = stderrdata.count("error") - stderrdata.count("got errors 0 times")
print("#times error occurred in output is " + str(errorcount) + "\n")
if errorcount > 0:
print("TEST FAILED. Output has 'error'!!!\n")
sys.exit(2)
if stderrdata.find("fail") >= 0:
print("TEST FAILED. Output has 'fail'!!!\n")
sys.exit(2)
# we need to clean up after ourselves -- only do this on test success # we need to clean up after ourselves -- only do this on test success
shutil.rmtree(dbname, True) shutil.rmtree(dbname, True)
@ -1056,16 +1046,8 @@ def whitebox_crash_main(args, unknown_args):
print("TEST FAILED. See kill option and exit code above!!!\n") print("TEST FAILED. See kill option and exit code above!!!\n")
sys.exit(1) sys.exit(1)
stderrdata = stderrdata.lower() #stderr already printed above
errorcount = stderrdata.count("error") - stderrdata.count("got errors 0 times") exit_if_stderr_has_errors(stderrdata, False)
print("#times error occurred in output is " + str(errorcount) + "\n")
if errorcount > 0:
print("TEST FAILED. Output has 'error'!!!\n")
sys.exit(2)
if stderrdata.find("fail") >= 0:
print("TEST FAILED. Output has 'fail'!!!\n")
sys.exit(2)
# First half of the duration, keep doing kill test. For the next half, # First half of the duration, keep doing kill test. For the next half,
# try different modes. # try different modes.