diff --git a/run-tests.php b/run-tests.php
index 79ac9490c9829..49f4bb2e90432 100755
--- a/run-tests.php
+++ b/run-tests.php
@@ -200,6 +200,26 @@ function verify_config()
$DETAILED = 0;
}
+// Check whether a junit log is wanted.
+$JUNIT = getenv('TEST_PHP_JUNIT');
+if (empty($JUNIT) || (!file_exists($JUNIT) && !is_writable(dirname($JUNIT))) || (file_exists($JUNIT) && !is_writable($JUNIT)) || !($JUNIT = @fopen($JUNIT, 'w'))) {
+ $JUNIT = FALSE;
+}
+else{
+ $JUNIT = array(
+ 'fp' => $JUNIT,
+ 'test_total' => 0,
+ 'test_pass' => 0,
+ 'test_fail' => 0,
+ 'test_error' => 0,
+ 'test_skip' => 0,
+ 'started_at' => microtime(true),
+ 'finished_at' => NULL,
+ 'execution_time'=> NULL,
+ 'result_xml' => '',
+ );
+}
+
if (getenv('SHOW_ONLY_GROUPS')) {
$SHOW_ONLY_GROUPS = explode(",", getenv('SHOW_ONLY_GROUPS'));
} else {
@@ -811,6 +831,10 @@ function save_or_mail_results()
if ($output_file != '' && $just_save_results) {
save_or_mail_results();
}
+
+ if ($JUNIT) {
+ save_junit_xml();
+ }
if (getenv('REPORT_EXIT_STATUS') == 1 and preg_match('/FAILED(?: |$)/', implode(' ', $test_results))) {
exit(1);
@@ -946,6 +970,10 @@ function test_sort($a, $b)
save_or_mail_results();
+if ($JUNIT) {
+ save_junit_xml();
+}
+
if (getenv('REPORT_EXIT_STATUS') == 1 and $sum_results['FAILED']) {
exit(1);
}
@@ -1165,6 +1193,7 @@ function run_test($php, $file, $env)
global $leak_check, $temp_source, $temp_target, $cfg, $environment;
global $no_clean;
global $valgrind_version;
+ global $JUNIT;
$temp_filenames = null;
$org_file = $file;
@@ -1300,6 +1329,14 @@ function run_test($php, $file, $env)
'diff' => '',
'info' => "$bork_info [$file]",
);
+
+ if ($JUNIT) {
+ $JUNIT['test_total']++;
+ $JUNIT['test_error']++;
+ $JUNIT['result_xml'] .= ''."\n";
+ $JUNIT['result_xml'] .= ''."\n";
+ $JUNIT['result_xml'] .= ''."\n";
+ }
return 'BORKED';
}
@@ -1322,6 +1359,13 @@ function run_test($php, $file, $env)
$php = realpath("./sapi/cgi/php-cgi") . ' -C ';
} else {
show_result('SKIP', $tested, $tested_file, "reason: CGI not available");
+ if ($JUNIT) {
+ $JUNIT['test_total']++;
+ $JUNIT['test_skip']++;
+ $JUNIT['result_xml'] .= ''."\n";
+ $JUNIT['result_xml'] .= 'CGI not available'."\n";
+ $JUNIT['result_xml'] .= ''."\n";
+ }
return 'SKIPPED';
}
}
@@ -1459,7 +1503,14 @@ function run_test($php, $file, $env)
$env['USE_ZEND_ALLOC'] = '1';
}
+ if ($JUNIT) {
+ $test_started_at = microtime(true);
+ }
$output = system_with_timeout("$extra $php $pass_options -q $ini_settings -d display_errors=0 $test_skipif", $env);
+ if ($JUNIT) {
+ $test_finished_at = microtime(true);
+ $test_execution_time= number_format($test_finished_at-$test_started_at, 2);
+ }
if (!$cfg['keep']['skip']) {
@unlink($test_skipif);
@@ -1481,6 +1532,13 @@ function run_test($php, $file, $env)
@unlink($test_skipif);
}
+ if ($JUNIT) {
+ $JUNIT['test_total']++;
+ $JUNIT['test_skip']++;
+ $JUNIT['result_xml'] .= ''."\n";
+ $JUNIT['result_xml'] .= ''."\n";
+ $JUNIT['result_xml'] .= ''."\n";
+ }
return 'SKIPPED';
}
@@ -1535,6 +1593,12 @@ function run_test($php, $file, $env)
// a redirected test never fails
$IN_REDIRECT = false;
+ if ($JUNIT) {
+ $JUNIT['test_total']++;
+ $JUNIT['test_pass']++;
+ $JUNIT['result_xml'] .= ''."\n";
+ $JUNIT['result_xml'] .= ''."\n";
+ }
return 'REDIR';
} else {
@@ -1566,6 +1630,13 @@ function run_test($php, $file, $env)
'diff' => '',
'info' => "$bork_info [$file]",
);
+ if ($JUNIT) {
+ $JUNIT['test_total']++;
+ $JUNIT['test_error']++;
+ $JUNIT['result_xml'] .= ''."\n";
+ $JUNIT['result_xml'] .= ''."\n";
+ $JUNIT['result_xml'] .= ''."\n";
+ }
return 'BORKED';
}
@@ -1619,6 +1690,13 @@ function run_test($php, $file, $env)
$env['REQUEST_METHOD'] = 'POST';
if (empty($request)) {
+ if ($JUNIT) {
+ $JUNIT['test_total']++;
+ $JUNIT['test_error']++;
+ $JUNIT['result_xml'] .= ''."\n";
+ $JUNIT['result_xml'] .= ''."\n";
+ $JUNIT['result_xml'] .= ''."\n";
+ }
return 'BORKED';
}
@@ -1681,7 +1759,14 @@ function run_test($php, $file, $env)
COMMAND $cmd
";
+ if ($JUNIT) {
+ $test_started_at = microtime(true);
+ }
$out = system_with_timeout($cmd, $env, isset($section_text['STDIN']) ? $section_text['STDIN'] : null);
+ if ($JUNIT) {
+ $test_finished_at = microtime(true);
+ $test_execution_time= number_format($test_finished_at-$test_started_at, 2);
+ }
if (array_key_exists('CLEAN', $section_text) && (!$no_clean || $cfg['keep']['clean'])) {
@@ -1870,6 +1955,12 @@ function run_test($php, $file, $env)
$info = " (warn: XFAIL section but test passes)";
}else {
show_result("PASS", $tested, $tested_file, '', $temp_filenames);
+ if ($JUNIT) {
+ $JUNIT['test_total']++;
+ $JUNIT['test_pass']++;
+ $JUNIT['result_xml'] .= ''."\n";
+ $JUNIT['result_xml'] .= ''."\n";
+ }
return 'PASSED';
}
}
@@ -1899,6 +1990,12 @@ function run_test($php, $file, $env)
$info = " (warn: XFAIL section but test passes)";
}else {
show_result("PASS", $tested, $tested_file, '', $temp_filenames);
+ if ($JUNIT) {
+ $JUNIT['test_total']++;
+ $JUNIT['test_pass']++;
+ $JUNIT['result_xml'] .= ''."\n";
+ $JUNIT['result_xml'] .= ''."\n";
+ }
return 'PASSED';
}
}
@@ -1994,6 +2091,23 @@ function run_test($php, $file, $env)
if (isset($old_php)) {
$php = $old_php;
}
+
+ if ($JUNIT) {
+ $JUNIT['result_xml'] .= ''."\n";
+ $JUNIT['test_total']++;
+ if (in_array('XFAIL', $restype)) {
+ $JUNIT['test_pass']++;
+ }
+ elseif (in_array('FAIL', $restype)) {
+ $JUNIT['test_fail']++;
+ $JUNIT['result_xml'] .= ''."\n";
+ }
+ else{
+ $JUNIT['test_error']++;
+ $JUNIT['result_xml'] .= ''."\n";
+ }
+ $JUNIT['result_xml'] .= ''."\n";
+ }
return $restype[0] . 'ED';
}
@@ -2481,6 +2595,20 @@ function show_result($result, $tested, $tested_file, $extra = '', $temp_filename
}
}
+function save_junit_xml() {
+ global $JUNIT;
+ $JUNIT['finished_at'] = microtime(true);
+ $JUNIT['execution_time']= number_format(($JUNIT['finished_at']-$JUNIT['started_at']), 2);
+ $JUNIT['result_xml'] = ''."\n".
+ ''."\n".
+ ''."\n".
+ $JUNIT['result_xml'].
+ ''."\n".
+ '';
+ fwrite($JUNIT['fp'], $JUNIT['result_xml']);
+}
+
+
/*
* Local variables:
* tab-width: 4