Last active
January 26, 2016 10:01
-
-
Save pierrejoye/13a759cfbfaeb84fef07 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
diff --git a/run-tests.php b/run-tests.php | |
index 15b7fe2..05a83e3 100755 | |
--- a/run-tests.php | |
+++ b/run-tests.php | |
@@ -576,13 +576,22 @@ if (isset($argc) && $argc > 1) { | |
//case 'l' | |
case 'm': | |
$leak_check = true; | |
- $valgrind_cmd = "valgrind --version"; | |
+ if (defined('PHP_WINDOWS_VERSION_MAJOR')) { | |
+ $valgrind_cmd = "drmemory.exe -version"; | |
+ } else { | |
+ $valgrind_cmd = "valgrind --version"; | |
+ } | |
+ | |
$valgrind_header = system_with_timeout($valgrind_cmd, $environment); | |
$replace_count = 0; | |
if (!$valgrind_header) { | |
error("Valgrind returned no version info, cannot proceed.\nPlease check if Valgrind is installed."); | |
} else { | |
- $valgrind_version = preg_replace("/valgrind-(\d+)\.(\d+)\.(\d+)([.\w_-]+)?(\s+)/", '$1.$2.$3', $valgrind_header, 1, $replace_count); | |
+ if (defined('PHP_WINDOWS_VERSION_MAJOR')) { | |
+ $valgrind_version = trim(preg_replace("/Dr\. Memory version (\d+)\.(\d+)\.(\d+) -- build (\d+)/", '$1.$2.$3-$4', $valgrind_header, 1, $replace_count)); | |
+ } else { | |
+ $valgrind_version = preg_replace("/valgrind-(\d+)\.(\d+)\.(\d+)([.\w_-]+)?(\s+)/", '$1.$2.$3', $valgrind_header, 1, $replace_count); | |
+ } | |
if ($replace_count != 1) { | |
error("Valgrind returned invalid version info (\"$valgrind_header\"), cannot proceed."); | |
} | |
@@ -835,6 +844,10 @@ HELP; | |
} | |
junit_save_xml(); | |
+ /* cleanup */ | |
+ if (defined('PHP_WINDOWS_VERSION_MAJOR')) { | |
+ system('rmdir /s /q drmemory_tmp'); | |
+ } | |
if (getenv('REPORT_EXIT_STATUS') == 1 and $sum_results['FAILED']) { | |
exit(1); | |
@@ -1070,7 +1083,7 @@ function error_report($testname, $logname, $tested) | |
} | |
} | |
-function system_with_timeout($commandline, $env = null, $stdin = null) | |
+function system_with_timeout($commandline, $env = null, $stdin = null, &$code = NULL) | |
{ | |
global $leak_check, $cwd; | |
@@ -1792,13 +1805,19 @@ TEST $file | |
$env['USE_ZEND_ALLOC'] = '0'; | |
$env['ZEND_DONT_UNLOAD_MODULES'] = 1; | |
- if (version_compare($valgrind_version, '3.3.0', '>=')) { | |
- /* valgrind 3.3.0+ doesn't have --log-file-exactly option */ | |
- $cmd = "valgrind -q --tool=memcheck --trace-children=yes --log-file=$memcheck_filename $cmd"; | |
+ if (defined('PHP_WINDOWS_VERSION_MAJOR')) { | |
+ if (!is_dir('drmemory_tmp')) { | |
+ mkdir('drmemory_tmp'); | |
+ } | |
+ $cmd = "drmemory -suppress suppress.txt -quiet -batch -exit_code_if_errors 500 -logdir drmemory_tmp -- $cmd"; | |
} else { | |
- $cmd = "valgrind -q --tool=memcheck --trace-children=yes --log-file-exactly=$memcheck_filename $cmd"; | |
+ if (version_compare($valgrind_version, '3.3.0', '>=')) { | |
+ /* valgrind 3.3.0+ doesn't have --log-file-exactly option */ | |
+ $cmd = "valgrind -q --tool=memcheck --trace-children=yes --log-file=$memcheck_filename $cmd"; | |
+ } else { | |
+ $cmd = "valgrind -q --tool=memcheck --trace-children=yes --log-file-exactly=$memcheck_filename $cmd"; | |
+ } | |
} | |
- | |
} else { | |
$env['USE_ZEND_ALLOC'] = '1'; | |
$env['ZEND_DONT_UNLOAD_MODULES'] = 0; | |
@@ -1817,9 +1836,13 @@ COMMAND $cmd | |
"; | |
junit_start_timer($shortname); | |
- | |
- $out = system_with_timeout($cmd, $env, isset($section_text['STDIN']) ? $section_text['STDIN'] : null); | |
- | |
+ $code = 0; | |
+ if (defined('PHP_WINDOWS_VERSION_MAJOR') && $leak_check) { | |
+ $out = system_with_timeout($cmd, $env, isset($section_text['STDIN']) ? $section_text['STDIN'] : null, $code); | |
+ } else { | |
+ $out = system_with_timeout($cmd, $env, isset($section_text['STDIN']) ? $section_text['STDIN'] : null); | |
+ | |
+ } | |
junit_finish_timer($shortname); | |
if (array_key_exists('CLEAN', $section_text) && (!$no_clean || $cfg['keep']['clean'])) { | |
@@ -1849,10 +1872,16 @@ COMMAND $cmd | |
$passed = false; | |
if ($leak_check) { // leak check | |
- $leaked = filesize($memcheck_filename) > 0; | |
- | |
- if (!$leaked) { | |
- @unlink($memcheck_filename); | |
+ if (defined('PHP_WINDOWS_VERSION_MAJOR')) { | |
+ $leaked = ($code == 500); | |
+ if ($leaked) { | |
+ $mem_results_file = glob('drmemory_tmp/DrMemory*/results.txt')[0]; | |
+ copy($mem_results_file, $memcheck_filename); | |
+ } | |
+ } else { | |
+ if (!(filesize($memcheck_filename) > 0)) { | |
+ @unlink($memcheck_filename); | |
+ } | |
} | |
} | |
@@ -1990,7 +2019,7 @@ COMMAND $cmd | |
// %f allows two points "-.0.0" but that is the best *simple* expression | |
} | |
/* DEBUG YOUR REGEX HERE | |
- var_dump($wanted_re); | |
+ ($wanted_re); | |
print(str_repeat('=', 80) . "\n"); | |
var_dump($output); | |
*/ |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment