From 95da743a56cc0744569bd6467932e68c632e213a Mon Sep 17 00:00:00 2001 From: inikep Date: Wed, 22 Jun 2016 12:12:35 +0200 Subject: [PATCH] test-zstd-speed.py: send e-mail in case of error --- tests/test-zstd-speed.py | 130 +++++++++++++++++++++------------------ 1 file changed, 70 insertions(+), 60 deletions(-) diff --git a/tests/test-zstd-speed.py b/tests/test-zstd-speed.py index 2c13fd38..c693b218 100755 --- a/tests/test-zstd-speed.py +++ b/tests/test-zstd-speed.py @@ -1,16 +1,19 @@ #! /usr/bin/env python -# execute(), fetch(), notify() are based on https://github.com/getlantern/build-automation/blob/master/build.py import argparse import os import string import time import traceback -from subprocess import Popen, PIPE +import subprocess default_repo_url = 'https://github.com/Cyan4973/zstd.git' -test_dir_name = 'speedTest' +working_dir_name = 'speedTest' +working_path = os.getcwd() + '/' + working_dir_name # /path/to/zstd/tests/speedTest +clone_path = working_path + '/' + 'zstd' # /path/to/zstd/tests/speedTest/zstd email_header = '[ZSTD_speedTest]' +pid = str(os.getpid()) + def log(text): print(time.strftime("%Y/%m/%d %H:%M:%S") + ' - ' + text) @@ -18,36 +21,34 @@ def log(text): def execute(command, print_output=False, print_error=True, param_shell=True): log("> " + command) - popen = Popen(command, stdout=PIPE, stderr=PIPE, shell=param_shell, cwd=execute.cwd) - itout = iter(popen.stdout.readline, b"") - iterr = iter(popen.stderr.readline, b"") - stdout_lines = list(itout) - stderr_lines = list(iterr) - popen.communicate() + popen = subprocess.Popen(command, stdout=subprocess.PIPE, stderr=subprocess.STDOUT, shell=param_shell, cwd=execute.cwd) + stdout = popen.communicate()[0] + stdout_lines = stdout.splitlines() if print_output: - print(''.join(stdout_lines)) - print(''.join(stderr_lines)) + print('\n'.join(stdout_lines)) if popen.returncode is not None and popen.returncode != 0: if not print_output and print_error: - print(''.join(stderr_lines)) - return popen.returncode, stdout_lines, stderr_lines + print('\n'.join(stdout_lines)) + raise RuntimeError('\n'.join(stdout_lines)) + return stdout_lines execute.cwd = None def does_command_exist(command): - result, stdoutdata, stderrdata = execute(command, False, False); - return result == 0 + try: + execute(command, False, False); + except Exception as e: + return False + return True -def fetch(): +def get_branches(): execute('git fetch -p') - returncode, output, stderrdata = execute('git branch -rl') + output = execute('git branch -rl') for line in output: if "HEAD" in line: output.remove(line) # remove "origin/HEAD -> origin/dev" - branches = map(lambda l: l.strip(), output) - print("branches=%s" % branches) - return map(lambda b: (b, execute('git show -s --format=%h ' + b)[1][0].strip()), branches) + return map(lambda l: l.strip(), output) def notify(branch, commit, last_commit): @@ -55,10 +56,10 @@ def notify(branch, commit, last_commit): branch = branch.split('/')[1] fmt = '--format="%h: (%an) %s, %ar"' if last_commit is None: - returncode, commits, stderrdata = execute('git log -n 10 %s %s' % (fmt, commit)) + commits = execute('git log -n 10 %s %s' % (fmt, commit)) else: - returncode, commits, stderrdata = execute('git --no-pager log %s %s..%s' % (fmt, last_commit, commit)) - text = text_tmpl.substitute({'last_commit': last_commit, 'commits': ''.join(commits)}) + commits = execute('git --no-pager log %s %s..%s' % (fmt, last_commit, commit)) + text = text_tmpl.substitute({'last_commit': last_commit, 'commits': '\n'.join(commits)}) print(str("commits for %s: %s" % (commit, text))) @@ -98,21 +99,22 @@ def benchmark_and_compare(branch, commit, resultsFileName, lastCLevel, testFileP log("WARNING: bench loadavg=%.2f is higher than %s, sleeping for %s seconds" % (os.getloadavg()[0], maxLoadAvg, sleepTime)) time.sleep(sleepTime) start_load = str(os.getloadavg()) - returncode, result, stderrdata = execute('programs/zstd -qi5b1e' + str(lastCLevel) + ' ' + testFilePath) + result = execute('programs/zstd -qi5b1e' + str(lastCLevel) + ' ' + testFilePath, print_output=True) end_load = str(os.getloadavg()) linesExpected = lastCLevel + 2; if len(result) != linesExpected: - log("ERROR: number of result lines=%d is different that expected %d" % (len(result), linesExpected)) - return "" + raise RuntimeError("ERROR: number of result lines=%d is different that expected %d" % (len(result), linesExpected)) with open(resultsFileName, "a") as myfile: myfile.write(branch + " " + commit + "\n") - myfile.writelines(result) + myfile.write('\n'.join(result) + '\n') myfile.close() if (last_cspeed == None): + log("WARNING: No data for comparison for branch=%s file=%s " % (branch, fileName)) return "" commit, cspeed, dspeed = get_last_commit(resultsFileName) text = "" for i in range(0, min(len(cspeed), len(last_cspeed))): + print("%s: -%d cspeed=%6.2f clast=%6.2f cdiff=%1.4f dspeed=%6.2f dlast=%6.2f ddiff=%1.4f %s" % (branch, i+1, cspeed[i], last_cspeed[i], cspeed[i]/last_cspeed[i], dspeed[i], last_dspeed[i], dspeed[i]/last_dspeed[i], fileName)) if (cspeed[i]/last_cspeed[i] < lower_limit): text += "WARNING: File=%s level=%d cspeed=%s last=%s diff=%s\n" % (fileName, i+1, cspeed[i], last_cspeed[i], cspeed[i]/last_cspeed[i]) if (dspeed[i]/last_dspeed[i] < lower_limit): @@ -122,31 +124,37 @@ def benchmark_and_compare(branch, commit, resultsFileName, lastCLevel, testFileP return text -def send_simple_email(emails, email_topic, have_mutt, have_mail): - if have_mutt: - execute('mutt -s "' + email_header + ' ' + email_topic + '" ' + emails + '