[prev in list] [next in list] [prev in thread] [next in thread] 

List:       php-cvs
Subject:    [PHP-CVS] com php-src: Add junit support for parallel test runner: run-tests.php
From:       Nikita Popov <nikic () php ! net>
Date:       2019-05-31 10:38:06
Message-ID: php-mail-8dd9e1a8d1b57623f74a2f61345d0fa21831670783 () git ! php ! net
[Download RAW message or body]

Commit:    dd2bf448693df98d060d784fed798ec9ba461fad
Author:    Nikita Popov <nikita.ppv@gmail.com>         Fri, 31 May 2019 12:38:06 +0200
Parents:   137747bdaf8a5fa0d01e2d3833147aba66eb314d
Branches:  PHP-7.4 master

Link:       http://git.php.net/?p=php-src.git;a=commitdiff;h=dd2bf448693df98d060d784fed798ec9ba461fad

Log:
Add junit support for parallel test runner

Changed paths:
  M  run-tests.php


Diff:
diff --git a/run-tests.php b/run-tests.php
index eed88ef..b8dbb9c 100755
--- a/run-tests.php
+++ b/run-tests.php
@@ -1544,6 +1544,9 @@ escape:
 									}
 								}
 							}
+							if (junit_enabled()) {
+								junit_merge_results($message["junit"]);
+							}
 							// intentional fall-through
 						case "ready":
 							// Schedule sequential tests only once we are down to one worker.
@@ -1712,8 +1715,10 @@ function run_worker() {
 			case "run_tests":
 				run_all_tests($command["test_files"], $command["env"], $command["redir_tested"]);
 				send_message($workerSock, [
-					"type" => "tests_finished"
+					"type" => "tests_finished",
+					"junit" => junit_enabled() ? $GLOBALS['JUNIT'] : null,
 				]);
+				junit_init();
 				break;
 			default:
 				send_message($workerSock, [
@@ -3317,28 +3322,30 @@ function show_result($result, $tested, $tested_file, $extra = '', $temp_filename
 function junit_init()
 {
 	// Check whether a junit log is wanted.
+	global $workerID;
 	$JUNIT = getenv('TEST_PHP_JUNIT');
 	if (empty($JUNIT)) {
-		$JUNIT = false;
-	} elseif (!$fp = fopen($JUNIT, 'w')) {
+		$GLOBALS['JUNIT'] = false;
+		return;
+	}
+	if ($workerID) {
+		$fp = null;
+	} else if (!$fp = fopen($JUNIT, 'w')) {
 		error("Failed to open $JUNIT for writing.");
-	} else {
-		$JUNIT = array(
-			'fp' => $fp,
-			'name' => 'PHP',
-			'test_total' => 0,
-			'test_pass' => 0,
-			'test_fail' => 0,
-			'test_error' => 0,
-			'test_skip' => 0,
-			'test_warn' => 0,
-			'execution_time' => 0,
-			'suites' => array(),
-			'files' => array()
-		);
 	}
-
-	$GLOBALS['JUNIT'] = $JUNIT;
+	$GLOBALS['JUNIT'] = array(
+		'fp' => $fp,
+		'name' => 'PHP',
+		'test_total' => 0,
+		'test_pass' => 0,
+		'test_fail' => 0,
+		'test_error' => 0,
+		'test_skip' => 0,
+		'test_warn' => 0,
+		'execution_time' => 0,
+		'suites' => array(),
+		'files' => array()
+	);
 }
 
 function junit_save_xml()
@@ -3544,6 +3551,7 @@ function junit_init_suite($suite_name)
 		'test_fail' => 0,
 		'test_error' => 0,
 		'test_skip' => 0,
+		'test_warn' => 0,
 		'files' => array(),
 		'execution_time' => 0,
 	);
@@ -3567,6 +3575,35 @@ function junit_finish_timer($file_name)
 	unset($JUNIT['files'][$file_name]['start']);
 }
 
+function junit_merge_results($junit)
+{
+	global $JUNIT;
+	$JUNIT['test_total'] += $junit['test_total'];
+	$JUNIT['test_pass']  += $junit['test_pass'];
+	$JUNIT['test_fail']  += $junit['test_fail'];
+	$JUNIT['test_error'] += $junit['test_error'];
+	$JUNIT['test_skip']  += $junit['test_skip'];
+	$JUNIT['test_warn']  += $junit['test_warn'];
+	$JUNIT['execution_time'] += $junit['execution_time'];
+	$JUNIT['files'] += $junit['files'];
+	foreach ($junit['suites'] as $name => $suite) {
+		if (!isset($JUNIT['suites'][$name])) {
+			$JUNIT['suites'][$name] = $suite;
+			continue;
+		}
+
+		$SUITE =& $JUNIT['suites'][$name];
+		$SUITE['test_total'] += $suite['test_total'];
+		$SUITE['test_pass']  += $suite['test_pass'];
+		$SUITE['test_fail']  += $suite['test_fail'];
+		$SUITE['test_error'] += $suite['test_error'];
+		$SUITE['test_skip']  += $suite['test_skip'];
+		$SUITE['test_warn']  += $suite['test_warn'];
+		$SUITE['execution_time'] += $suite['execution_time'];
+		$SUITE['files'] += $suite['files'];
+	}
+}
+
 class RuntestsValgrind
 {
 	protected $version = '';


--
PHP CVS Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php

[prev in list] [next in list] [prev in thread] [next in thread] 

Configure | About | News | Add a list | Sponsored by KoreLogic