Skip to content

JUNIT support #2

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
wants to merge 2 commits into from
Closed
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
128 changes: 128 additions & 0 deletions run-tests.php
Original file line number Diff line number Diff line change
@@ -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'] .= '<testcase classname="'.$shortname.'" name="'.htmlspecialchars($tested_file, ENT_QUOTES).'" time="0">'."\n";
$JUNIT['result_xml'] .= '<error type="BORKED" message="'.$bork_info.'" />'."\n";
$JUNIT['result_xml'] .= '</testcase>'."\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'] .= '<testcase classname="'.$shortname.'" name="'.htmlspecialchars($tested, ENT_QUOTES).'" time="0">'."\n";
$JUNIT['result_xml'] .= '<skipped>CGI not available</skipped>'."\n";
$JUNIT['result_xml'] .= '</testcase>'."\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'] .= '<testcase classname="'.$shortname.'" name="'.htmlspecialchars($tested, ENT_QUOTES).'" time="'.$test_execution_time.'">'."\n";
$JUNIT['result_xml'] .= '<skipped><![CDATA['."\n".$m[1]."\n".']]></skipped>'."\n";
$JUNIT['result_xml'] .= '</testcase>'."\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'] .= '<testcase classname="'.$shortname.'" name="'.htmlspecialchars($tested, ENT_QUOTES).'" time="'.$test_execution_time.'">'."\n";
$JUNIT['result_xml'] .= '</testcase>'."\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'] .= '<testcase classname="'.$shortname.'" name="'.htmlspecialchars($tested, ENT_QUOTES).'" time="'.$test_execution_time.'">'."\n";
$JUNIT['result_xml'] .= '<error type="BORKED" message="'.$bork_info.'" />'."\n";
$JUNIT['result_xml'] .= '</testcase>'."\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'] .= '<testcase classname="'.$shortname.'" name="'.htmlspecialchars($tested, ENT_QUOTES).'" time="'.$test_execution_time.'">'."\n";
$JUNIT['result_xml'] .= '<error type="BORKED" message="empty $request" />'."\n";
$JUNIT['result_xml'] .= '</testcase>'."\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'] .= '<testcase classname="'.$shortname.'" name="'.htmlspecialchars($tested, ENT_QUOTES).'" time="'.$test_execution_time.'">'."\n";
$JUNIT['result_xml'] .= '</testcase>'."\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'] .= '<testcase classname="'.$shortname.'" name="'.htmlspecialchars($tested, ENT_QUOTES).'" time="'.$test_execution_time.'">'."\n";
$JUNIT['result_xml'] .= '</testcase>'."\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'] .= '<testcase classname="'. str_replace($cwd . '/', '', $tested_file).'" name="'.htmlspecialchars($tested, ENT_QUOTES).'" time="'.$test_execution_time.'">'."\n";
$JUNIT['test_total']++;
if (in_array('XFAIL', $restype)) {
$JUNIT['test_pass']++;
}
elseif (in_array('FAIL', $restype)) {
$JUNIT['test_fail']++;
$JUNIT['result_xml'] .= '<failure type="'.$restype[0].'ED" message="'.$info.'"><![CDATA['."\n".$diff."\n".']]></failure>'."\n";
}
else{
$JUNIT['test_error']++;
$JUNIT['result_xml'] .= '<error type="'.$restype[0].'ED" message="'.$info.'"><![CDATA['."\n".$diff."\n".']]></error>'."\n";
}
$JUNIT['result_xml'] .= '</testcase>'."\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'] = '<?xml version="1.0" encoding="UTF-8"?>'."\n".
'<testsuites>'."\n".
'<testsuite name="php-src" tests="'.$JUNIT['test_total'].'" failures="'.$JUNIT['test_fail'].'" errors="'.$JUNIT['test_error'].'" skip="'.$JUNIT['test_skip'].'" time="'.$JUNIT['execution_time'].'">'."\n".
$JUNIT['result_xml'].
'</testsuite>'."\n".
'</testsuites>';
fwrite($JUNIT['fp'], $JUNIT['result_xml']);
}


/*
* Local variables:
* tab-width: 4