From 6173931868adc4e7c91aaf65aa8a7c3ef8d57b93 Mon Sep 17 00:00:00 2001 From: inikep Date: Thu, 15 Sep 2016 18:58:18 +0200 Subject: [PATCH 1/4] fixed memory leak reported by bryongloden --- programs/util.h | 18 +++++++++++++++--- 1 file changed, 15 insertions(+), 3 deletions(-) diff --git a/programs/util.h b/programs/util.h index e0d1e536c..571fc0a9d 100644 --- a/programs/util.h +++ b/programs/util.h @@ -199,6 +199,18 @@ UTIL_STATIC U32 UTIL_isDirectory(const char* infilename) return 0; } +/* + * A modified version of realloc(). + * If UTIL_realloc() fails the original block is freed. +*/ +UTIL_STATIC void *UTIL_realloc(void *ptr, size_t size) +{ + void *newptr = realloc(ptr, size); + if (newptr) return newptr; + free(ptr); + return NULL; +} + #ifdef _WIN32 # define UTIL_HAS_CREATEFILELIST @@ -245,7 +257,7 @@ UTIL_STATIC int UTIL_prepareFileList(const char *dirName, char** bufStart, size_ else if ((cFile.dwFileAttributes & FILE_ATTRIBUTE_NORMAL) || (cFile.dwFileAttributes & FILE_ATTRIBUTE_ARCHIVE) || (cFile.dwFileAttributes & FILE_ATTRIBUTE_COMPRESSED)) { if (*bufStart + *pos + pathLength >= *bufEnd) { ptrdiff_t newListSize = (*bufEnd - *bufStart) + LIST_SIZE_INCREASE; - *bufStart = (char*)realloc(*bufStart, newListSize); + *bufStart = (char*)UTIL_realloc(*bufStart, newListSize); *bufEnd = *bufStart + newListSize; if (*bufStart == NULL) { free(path); FindClose(hFile); return 0; } } @@ -299,7 +311,7 @@ UTIL_STATIC int UTIL_prepareFileList(const char *dirName, char** bufStart, size_ } else { if (*bufStart + *pos + pathLength >= *bufEnd) { ptrdiff_t newListSize = (*bufEnd - *bufStart) + LIST_SIZE_INCREASE; - *bufStart = (char*)realloc(*bufStart, newListSize); + *bufStart = (char*)UTIL_realloc(*bufStart, newListSize); *bufEnd = *bufStart + newListSize; if (*bufStart == NULL) { free(path); closedir(dir); return 0; } } @@ -355,7 +367,7 @@ UTIL_STATIC const char** UTIL_createFileList(const char **inputNames, unsigned i size_t len = strlen(inputNames[i]); if (buf + pos + len >= bufend) { ptrdiff_t newListSize = (bufend - buf) + LIST_SIZE_INCREASE; - buf = (char*)realloc(buf, newListSize); + buf = (char*)UTIL_realloc(buf, newListSize); bufend = buf + newListSize; if (!buf) return NULL; } From d28afac4f85416f7a34e237064bf1877fadefd85 Mon Sep 17 00:00:00 2001 From: inikep Date: Thu, 15 Sep 2016 19:56:04 +0200 Subject: [PATCH 2/4] test-zstd-speed.py: added support for directories --- tests/test-zstd-speed.py | 13 ++++++------- 1 file changed, 6 insertions(+), 7 deletions(-) diff --git a/tests/test-zstd-speed.py b/tests/test-zstd-speed.py index 055f27a43..9f2f02ede 100755 --- a/tests/test-zstd-speed.py +++ b/tests/test-zstd-speed.py @@ -17,7 +17,7 @@ import time import traceback import hashlib -script_version = 'v1.0.0 (2016-09-12)' +script_version = 'v1.0.1 (2016-09-15)' default_repo_url = 'https://github.com/facebook/zstd.git' working_dir_name = 'speedTest' working_path = os.getcwd() + '/' + working_dir_name # /path/to/zstd/tests/speedTest @@ -130,7 +130,7 @@ def get_last_results(resultsFileName): csize = [] cspeed = [] dspeed = [] - if (len(words) == 8): # results + if (len(words) == 8) or (len(words) == 9): # results: "filename" or "XX files" csize.append(int(words[1])) cspeed.append(float(words[3])) dspeed.append(float(words[5])) @@ -145,7 +145,7 @@ def benchmark_and_compare(branch, commit, last_commit, args, executableName, md5 % (os.getloadavg()[0], args.maxLoadAvg, sleepTime)) time.sleep(sleepTime) start_load = str(os.getloadavg()) - result = execute('programs/%s -qi5b1e%s %s' % (executableName, args.lastCLevel, testFilePath), + result = execute('programs/%s -rqi5b1e%s %s' % (executableName, args.lastCLevel, testFilePath), print_output=True) end_load = str(os.getloadavg()) linesExpected = args.lastCLevel + 1 @@ -198,8 +198,7 @@ def test_commit(branch, commit, last_commit, args, testFilePaths, have_mutt, hav if not args.dry_run: execute('make -C programs clean zstd CC=clang MOREFLAGS="-Werror -Wconversion -Wno-sign-conversion -DZSTD_GIT_COMMIT=%s" && ' % version + 'mv programs/zstd programs/zstd_clang && ' + - 'make -C programs clean zstd MOREFLAGS="-DZSTD_GIT_COMMIT=%s" && ' % version + - 'make -B -C programs zstd32 MOREFLAGS="-DZSTD_GIT_COMMIT=%s"' % version) + 'make -C programs clean zstd zstd32 MOREFLAGS="-DZSTD_GIT_COMMIT=%s"' % version) md5_zstd = hashfile(hashlib.md5(), clone_path + '/programs/zstd') md5_zstd32 = hashfile(hashlib.md5(), clone_path + '/programs/zstd32') md5_zstd_clang = hashfile(hashlib.md5(), clone_path + '/programs/zstd_clang') @@ -251,10 +250,10 @@ if __name__ == '__main__': testFilePaths = [] for fileName in testFileNames: fileName = os.path.expanduser(fileName) - if os.path.isfile(fileName): + if os.path.isfile(fileName) or os.path.isdir(fileName): testFilePaths.append(os.path.abspath(fileName)) else: - log("ERROR: File not found: " + fileName) + log("ERROR: File/directory not found: " + fileName) exit(1) # check availability of e-mail senders From ed0ea8d271b805691e9a77b2000b08cf59fc489f Mon Sep 17 00:00:00 2001 From: inikep Date: Thu, 15 Sep 2016 20:31:29 +0200 Subject: [PATCH 3/4] test-zstd-speed.py: added "-D dictName" --- tests/test-zstd-speed.py | 41 +++++++++++++++++++++++++++++++--------- 1 file changed, 32 insertions(+), 9 deletions(-) diff --git a/tests/test-zstd-speed.py b/tests/test-zstd-speed.py index 9f2f02ede..2bd370a7c 100755 --- a/tests/test-zstd-speed.py +++ b/tests/test-zstd-speed.py @@ -9,6 +9,10 @@ # of patent rights can be found in the PATENTS file in the same directory. # +# Limitations: +# - doesn't support filenames with spaces +# - dir1/zstd and dir2/zstd will be merged in a single results file + import argparse import os import string @@ -145,8 +149,10 @@ def benchmark_and_compare(branch, commit, last_commit, args, executableName, md5 % (os.getloadavg()[0], args.maxLoadAvg, sleepTime)) time.sleep(sleepTime) start_load = str(os.getloadavg()) - result = execute('programs/%s -rqi5b1e%s %s' % (executableName, args.lastCLevel, testFilePath), - print_output=True) + if args.dictionary: + result = execute('programs/%s -rqi5b1e%s -D %s %s' % (executableName, args.lastCLevel, args.dictionary, testFilePath), print_output=True) + else: + result = execute('programs/%s -rqi5b1e%s %s' % (executableName, args.lastCLevel, testFilePath), print_output=True) end_load = str(os.getloadavg()) linesExpected = args.lastCLevel + 1 if len(result) != linesExpected: @@ -208,9 +214,17 @@ def test_commit(branch, commit, last_commit, args, testFilePaths, have_mutt, hav logFileName = working_path + "/log_" + branch.replace("/", "_") + ".txt" text_to_send = [] results_files = "" + if args.dictionary: + dictName = args.dictionary.rpartition('/')[2] + else: + dictName = None + for filePath in testFilePaths: fileName = filePath.rpartition('/')[2] - resultsFileName = working_path + "/results_" + branch.replace("/", "_") + "_" + fileName.replace(".", "_") + ".txt" + if dictName: + resultsFileName = working_path + "/" + dictName.replace(".", "_") + "_" + branch.replace("/", "_") + "_" + fileName.replace(".", "_") + ".txt" + else: + resultsFileName = working_path + "/results_" + branch.replace("/", "_") + "_" + fileName.replace(".", "_") + ".txt" text = double_check(branch, commit, args, 'zstd', md5_zstd, 'gcc_version='+gcc_version, resultsFileName, filePath, fileName) if text: text_to_send.append(text) @@ -233,15 +247,16 @@ if __name__ == '__main__': parser = argparse.ArgumentParser() parser.add_argument('testFileNames', help='file names list for speed benchmark') parser.add_argument('emails', help='list of e-mail addresses to send warnings') - parser.add_argument('--message', help='attach an additional message to e-mail', default="") + parser.add_argument('--dictionary', '-D', help='path to the dictionary') + parser.add_argument('--message', '-m', help='attach an additional message to e-mail', default="") parser.add_argument('--repoURL', help='changes default repository URL', default=default_repo_url) - parser.add_argument('--lowerLimit', type=float, help='send email if speed is lower than given limit', default=0.98) - parser.add_argument('--ratioLimit', type=float, help='send email if ratio is lower than given limit', default=0.999) + parser.add_argument('--lowerLimit', '-l', type=float, help='send email if speed is lower than given limit', default=0.98) + parser.add_argument('--ratioLimit', '-r', type=float, help='send email if ratio is lower than given limit', default=0.999) parser.add_argument('--maxLoadAvg', type=float, help='maximum load average to start testing', default=0.75) parser.add_argument('--lastCLevel', type=int, help='last compression level for testing', default=5) - parser.add_argument('--sleepTime', type=int, help='frequency of repository checking in seconds', default=300) + parser.add_argument('--sleepTime', '-s', type=int, help='frequency of repository checking in seconds', default=300) parser.add_argument('--dry-run', dest='dry_run', action='store_true', help='not build', default=False) - parser.add_argument('--verbose', action='store_true', help='more verbose logs', default=False) + parser.add_argument('--verbose', '-v', action='store_true', help='more verbose logs', default=False) args = parser.parse_args() verbose = args.verbose @@ -256,6 +271,13 @@ if __name__ == '__main__': log("ERROR: File/directory not found: " + fileName) exit(1) + # check if dictionary is accessible + if args.dictionary: + args.dictionary = os.path.abspath(os.path.expanduser(args.dictionary)) + if not os.path.isfile(args.dictionary): + log("ERROR: Dictionary not found: " + args.dictionary) + exit(1) + # check availability of e-mail senders have_mutt = does_command_exist("mutt -h") have_mail = does_command_exist("mail -V") @@ -265,7 +287,7 @@ if __name__ == '__main__': clang_version = execute("clang -v 2>&1 | grep 'clang version' | sed -e 's:.*version \\([0-9.]*\\).*:\\1:' -e 's:\\.\\([0-9][0-9]\\):\\1:g'", verbose)[0]; gcc_version = execute("gcc -dumpversion", verbose)[0]; - + if verbose: print("PARAMETERS:\nrepoURL=%s" % args.repoURL) print("working_path=%s" % working_path) @@ -273,6 +295,7 @@ if __name__ == '__main__': print("testFilePath(%s)=%s" % (len(testFilePaths), testFilePaths)) print("message=%s" % args.message) print("emails=%s" % args.emails) + print("dictionary=%s" % args.dictionary) print("maxLoadAvg=%s" % args.maxLoadAvg) print("lowerLimit=%s" % args.lowerLimit) print("ratioLimit=%s" % args.ratioLimit) From dd8905b35102ee2b534aa63da5f4e59a4d8fa375 Mon Sep 17 00:00:00 2001 From: inikep Date: Thu, 15 Sep 2016 20:41:37 +0200 Subject: [PATCH 4/4] test-zstd-speed.py: better description of options --- tests/test-zstd-speed.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/tests/test-zstd-speed.py b/tests/test-zstd-speed.py index 2bd370a7c..56b4d46b9 100755 --- a/tests/test-zstd-speed.py +++ b/tests/test-zstd-speed.py @@ -245,7 +245,7 @@ def test_commit(branch, commit, last_commit, args, testFilePaths, have_mutt, hav if __name__ == '__main__': parser = argparse.ArgumentParser() - parser.add_argument('testFileNames', help='file names list for speed benchmark') + parser.add_argument('testFileNames', help='file or directory names list for speed benchmark') parser.add_argument('emails', help='list of e-mail addresses to send warnings') parser.add_argument('--dictionary', '-D', help='path to the dictionary') parser.add_argument('--message', '-m', help='attach an additional message to e-mail', default="")