Skip to content

Instantly share code, notes, and snippets.

@nmoinvaz
Last active November 5, 2020 00:48
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save nmoinvaz/e0e9bdef38ee380b0801bc76def0b2fb to your computer and use it in GitHub Desktop.
Save nmoinvaz/e0e9bdef38ee380b0801bc76def0b2fb to your computer and use it in GitHub Desktop.
import sys
if sys.version_info.major < 3:
print('Python 3 or higher is required to run this script')
exit(1)
import os
import argparse
import codecs
import pprint
import stat
import subprocess
import time
import logging
from sys import platform
parser = argparse.ArgumentParser(description='Host burn test script')
parser.add_argument('--runs', help='Number of runs', action='store', default=1)
args, unknown = parser.parse_known_args()
def run_process_ex(cmd, silent=False, clean=True, max_output=8192, capture_errors=True):
logging.info('Process - Start - {0}'.format(cmd))
retval = {'result': False, 'output': '', 'exitcode': -1}
if capture_errors:
stderr_pipe = subprocess.STDOUT
else:
stderr_pipe = open(os.devnull, 'w')
process = subprocess.Popen(cmd, shell=True, stdout=subprocess.PIPE, stderr=stderr_pipe)
if max_output > 0:
while True:
line = process.stdout.readline()
if line == b'' and process.poll() is not None:
break
if clean:
line = line.replace(b'\n', b'')
line = line.replace(b'\r', b'')
if line == b'':
continue
retval['output'] += line.decode('utf8')
if max_output > 0 and len(retval['output']) > max_output:
retval['output'] = retval['output'][-max_output:]
if not silent:
logging.info(line.decode('utf8', 'ignore'))
else:
process.wait()
retval['exitcode'] = process.returncode
if process.returncode == 0:
retval['result'] = True
logging.debug('Process - Exit - {0} - {1}'.format(retval['result'], retval['exitcode']))
if not retval['result'] and silent:
logging.info(retval['output'])
return retval
def run_process(cmd):
return run_process_ex(cmd)['result']
def main():
global args
global config
root = logging.getLogger()
root.setLevel(logging.DEBUG)
handler = logging.StreamHandler(sys.stdout)
handler.setLevel(logging.INFO)
formatter = logging.Formatter('%(asctime)s - %(levelname)s - %(message)s')
handler.setFormatter(formatter)
root.addHandler(handler)
debugfile = os.path.expanduser('~/Desktop/host.developer.log')
logging.info('Platform - {0}'.format(platform))
logging.info('Working Directory - {0}'.format(os.getcwd()))
logging.info(f'Debug file - {debugfile}')
host_cmd = 'host.exe --debugfile'
for arg in unknown:
host_cmd += ' ' + arg
stop = False
for i in range(int(args.runs)):
print(f'Run {i}')
run_process(host_cmd)
with open(debugfile) as f:
if 'Not all memory' in f.read():
stop = True
if stop:
break
if __name__ == "__main__":
if not main():
sys.exit(1)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment