diff options
-rw-r--r-- | non-puppet/qtmetrics2/index.php | 28 | ||||
-rw-r--r-- | non-puppet/qtmetrics2/src/Database.php | 52 | ||||
-rw-r--r-- | non-puppet/qtmetrics2/src/Factory.php | 34 | ||||
-rw-r--r-- | non-puppet/qtmetrics2/src/Project.php | 41 | ||||
-rw-r--r-- | non-puppet/qtmetrics2/src/Testset.php | 26 | ||||
-rw-r--r-- | non-puppet/qtmetrics2/src/test/DatabaseTest.php | 68 | ||||
-rw-r--r-- | non-puppet/qtmetrics2/src/test/FactoryTest.php | 56 | ||||
-rw-r--r-- | non-puppet/qtmetrics2/src/test/ProjectTest.php | 22 | ||||
-rw-r--r-- | non-puppet/qtmetrics2/src/test/TestsetTest.php | 26 | ||||
-rw-r--r-- | non-puppet/qtmetrics2/templates/about.php | 6 | ||||
-rw-r--r-- | non-puppet/qtmetrics2/templates/testset.php | 18 | ||||
-rw-r--r-- | non-puppet/qtmetrics2/templates/testsets_top.php | 15 | ||||
-rw-r--r-- | non-puppet/qtmetrics2/testparser.pl | 57 |
13 files changed, 277 insertions, 172 deletions
diff --git a/non-puppet/qtmetrics2/index.php b/non-puppet/qtmetrics2/index.php index 9b50dc8..353568e 100644 --- a/non-puppet/qtmetrics2/index.php +++ b/non-puppet/qtmetrics2/index.php @@ -34,8 +34,8 @@ /** * Qt Metrics API - * @version 0.1 - * @since 08-06-2015 + * @version 0.2 + * @since 12-06-2015 * @author Juha Sippola */ @@ -54,6 +54,7 @@ $app = new \Slim\Slim(array( $app->get('/', function() use($app) { + $ini = Factory::conf(); $app->render('home.php', array( 'overviewRoute' => Slim\Slim::getInstance()->urlFor('root') . 'overview', 'branchRoute' => Slim\Slim::getInstance()->urlFor('root') . 'branch', @@ -62,7 +63,9 @@ $app->get('/', function() use($app) 'refreshed' => Factory::db()->getDbRefreshed() . ' (GMT)', 'states' => Factory::db()->getStates(), 'branches' => Factory::db()->getBranches(), - 'projects' => Factory::createProjects(), // managed as objects + 'projects' => Factory::createProjects( + $ini['master_build_project'], + $ini['master_build_state']), // managed as objects 'platforms' => Factory::db()->getTargetPlatforms() )); })->name('root'); @@ -86,7 +89,12 @@ $app->get('/test/top', function() use($app) 'topN' => $ini['top_failures_n'], 'lastDays' => $ini['top_failures_last_days'], 'sinceDate' => $since, - 'testsets' => Factory::createTestsets(Factory::LIST_FAILURES) // managed as objects + 'masterProject' => $ini['master_build_project'], + 'masterState' => $ini['master_build_state'], + 'testsets' => Factory::createTestsets( + Factory::LIST_FAILURES, + $ini['master_build_project'], + $ini['master_build_state']) // managed as objects )); }); @@ -109,7 +117,10 @@ $app->get('/test/flaky', function() use($app) 'topN' => $ini['flaky_testsets_n'], 'lastDays' => $ini['flaky_testsets_last_days'], 'sinceDate' => $since, - 'testsets' => Factory::createTestsets(Factory::LIST_FLAKY) // managed as objects + 'testsets' => Factory::createTestsets( + Factory::LIST_FLAKY, + null, + null) // managed as objects )); }); @@ -129,7 +140,12 @@ $app->get('/testset/:testset', function($testset) use($app) 'refreshed' => Factory::db()->getDbRefreshed() . ' (GMT)', 'lastDaysFailures' => $ini['top_failures_last_days'], 'lastDaysFlaky' => $ini['flaky_testsets_last_days'], - 'testset' => Factory::createTestset($testset) // managed as object + 'masterProject' => $ini['master_build_project'], + 'masterState' => $ini['master_build_state'], + 'testset' => Factory::createTestset( + $testset, + $ini['master_build_project'], + $ini['master_build_state']) // managed as objects )); } else { $app->render('empty.php', array( diff --git a/non-puppet/qtmetrics2/src/Database.php b/non-puppet/qtmetrics2/src/Database.php index c8fd354..c54268e 100644 --- a/non-puppet/qtmetrics2/src/Database.php +++ b/non-puppet/qtmetrics2/src/Database.php @@ -34,8 +34,8 @@ /** * Database class - * @version 0.1 - * @since 04-06-2015 + * @version 0.2 + * @since 11-06-2015 * @author Juha Sippola */ @@ -279,14 +279,15 @@ class Database { /** * Get the latest build result by configuration and branch for given project and state * @param string $testset - * @param string $project - * @param string $state + * @param string $testsetProject + * @param string $runProject + * @param string $runState * @return array (string name, string branch, string result) */ - public function getLatestTestsetConfBuildResults($testset, $project, $state) + public function getLatestTestsetConfBuildResults($testset, $testsetProject, $runProject, $runState) { $result = array(); - $builds = self::getLatestProjectBranchBuildNumbers($project, $state); + $builds = self::getLatestProjectBranchBuildNumbers($runProject, $runState); foreach ($builds as $build) { $query = $this->db->prepare(" SELECT conf.name AS conf, branch.name AS branch, testset_run.result @@ -304,9 +305,9 @@ class Database { "); $query->execute(array( $testset, - $project, - $project, - $state, + $testsetProject, + $runProject, + $runState, $build['name'], $build['number'] )); @@ -322,14 +323,15 @@ class Database { } /** - * Get counts of all passed and failed runs by testset since specified date (list length limited) + * Get counts of all passed and failed runs by testset in specified builds since specified date (list length limited) * Only the testsets that have failed since the specified date are listed - * Scope is state builds only + * @param string $runProject + * @param string $runState * @param string $date * @param int $limit * @return array (string name, string project, int passed, int failed) */ - public function getTestsetsResultCounts($date, $limit) + public function getTestsetsResultCounts($runProject, $runState, $date, $limit) { $result = array(); $query = $this->db->prepare(" @@ -344,14 +346,18 @@ class Database { INNER JOIN conf_run ON testset_run.conf_run_id = conf_run.id INNER JOIN project_run ON conf_run.project_run_id = project_run.id INNER JOIN state ON project_run.state_id = state.id - WHERE state.name = 'state' AND + WHERE + project_run.project_id = (SELECT id FROM project WHERE name = ?) AND + project_run.state_id = (SELECT id FROM state WHERE name = ?) AND project_run.timestamp >= ? GROUP BY testset.name ORDER BY failed DESC, testset.name ASC LIMIT ?; "); - $query->bindParam(1, $date); - $query->bindParam(2, $limit, PDO::PARAM_INT); // int data type must be separately set + $query->bindParam(1, $runProject); + $query->bindParam(2, $runState); + $query->bindParam(3, $date); + $query->bindParam(4, $limit, PDO::PARAM_INT); // int data type must be separately set $query->execute(); while($row = $query->fetch(PDO::FETCH_ASSOC)) { if ($row['failed'] > 0) { // return only those where failures identified @@ -367,14 +373,15 @@ class Database { } /** - * Get counts of all passed and failed runs for a testset since specified date + * Get counts of all passed and failed runs for a testset in specified builds since specified date * If several testsets found with the same name in different projects, all are listed - * Scope is state builds only * @param string $testset + * @param string $runProject + * @param string $runState * @param string $date * @return array (string name, string project, int passed, int failed) */ - public function getTestsetResultCounts($testset, $date) + public function getTestsetResultCounts($testset, $runProject, $runState, $date) { $result = array(); $query = $this->db->prepare(" @@ -389,14 +396,18 @@ class Database { INNER JOIN conf_run ON testset_run.conf_run_id = conf_run.id INNER JOIN project_run ON conf_run.project_run_id = project_run.id INNER JOIN state ON project_run.state_id = state.id - WHERE testset.name = ? AND - state.name = 'state' AND + WHERE + testset.name = ? AND + project_run.project_id = (SELECT id FROM project WHERE name = ?) AND + project_run.state_id = (SELECT id FROM state WHERE name = ?) AND project_run.timestamp >= ? GROUP BY testset.name ORDER BY project.name; "); $query->execute(array( $testset, + $runProject, + $runState, $date )); while($row = $query->fetch(PDO::FETCH_ASSOC)) { @@ -508,5 +519,4 @@ class Database { } - ?> diff --git a/non-puppet/qtmetrics2/src/Factory.php b/non-puppet/qtmetrics2/src/Factory.php index 02114d4..ce1751e 100644 --- a/non-puppet/qtmetrics2/src/Factory.php +++ b/non-puppet/qtmetrics2/src/Factory.php @@ -34,8 +34,8 @@ /** * Factory class - * @version 0.1 - * @since 04-06-2015 + * @version 0.2 + * @since 12-06-2015 * @author Juha Sippola */ @@ -137,15 +137,17 @@ class Factory { /** * Create Project objects for those in database + * @param string $runProject + * @param string $runState * @return array Project objects */ - public static function createProjects() + public static function createProjects($runProject, $runState) { $objects = array(); $dbEntries = self::db()->getProjects(); foreach($dbEntries as $entry) { $obj = new Project($entry['name']); - $obj->setStatus(); + $obj->setStatus($runProject, $runState); $objects[] = $obj; } return $objects; @@ -153,25 +155,30 @@ class Factory { /** * Create Testset objects for those in database (with either result or flaky counts) + * List is limited by date (since) and length, failure result list and counts for specified builds only * @param int $listType + * @param string $runProject + * @param string $runState * @return array Testset objects */ - public static function createTestsets($listType) + public static function createTestsets($listType, $runProject, $runState) { $objects = array(); $ini = self::conf(); + // Failure result list (from specified builds only) if ($listType == self::LIST_FAILURES) { $days = intval($ini['top_failures_last_days']) - 1; $since = self::getSinceDate($days); $limit = intval($ini['top_failures_n']); - $dbEntries = self::db()->getTestsetsResultCounts($since, $limit); + $dbEntries = self::db()->getTestsetsResultCounts($runProject, $runState, $since, $limit); foreach($dbEntries as $entry) { $obj = new Testset($entry['name'], $entry['project']); - $obj->setStatus(); + $obj->setStatus($runProject, $runState); $obj->setTestsetResultCounts($entry['passed'], $entry['failed']); $objects[] = $obj; } } + // Flaky list (all builds) if ($listType == self::LIST_FLAKY) { $days = intval($ini['flaky_testsets_last_days']) - 1; $since = self::getSinceDate($days); @@ -189,10 +196,13 @@ class Factory { /** * Create Testset object(s) for those in database * If several testsets with same name in different projects, all are created + * Counts are limited by date (since) and length, failure result counts for specified builds only * @param string $name + * @param string $runProject + * @param string $runState * @return array Testset object(s) */ - public static function createTestset($name) + public static function createTestset($name, $runProject, $runState) { $objects = array(); $ini = self::conf(); @@ -200,16 +210,16 @@ class Factory { $dbTestset = self::db()->getTestsetProject($name); foreach($dbTestset as $testset) { $obj = new Testset($testset['name'], $testset['project']); - $obj->setStatus(); - // Get testset result counts + $obj->setStatus($runProject, $runState); + // Failure result counts (from specified builds only) $days = intval($ini['top_failures_last_days']) - 1; $since = self::getSinceDate($days); - $dbTestsetDetails = self::db()->getTestsetResultCounts($name, $since); + $dbTestsetDetails = self::db()->getTestsetResultCounts($name, $runProject, $runState, $since); foreach($dbTestsetDetails as $detail) { if ($testset['project'] == $detail['project']) $obj->setTestsetResultCounts($detail['passed'], $detail['failed']); } - // Get testset flaky counts + // Flaky counts (all builds) $days = intval($ini['flaky_testsets_last_days']) - 1; $since = self::getSinceDate($days); $dbTestsetDetails = self::db()->getTestsetFlakyCounts($name, $since); diff --git a/non-puppet/qtmetrics2/src/Project.php b/non-puppet/qtmetrics2/src/Project.php index 992cc88..0df5846 100644 --- a/non-puppet/qtmetrics2/src/Project.php +++ b/non-puppet/qtmetrics2/src/Project.php @@ -34,8 +34,8 @@ /** * Project class - * @version 0.1 - * @since 02-06-2015 + * @version 0.2 + * @since 12-06-2015 * @author Juha Sippola */ @@ -91,27 +91,34 @@ class Project { } /** - * Set status of the project calculated from the latest branch build results (in state builds only). + * Set status of the project calculated from the testset results in the latest branch builds (in specified builds only). + * @param string $runProject + * @param string $runState */ - public function setStatus() + public function setStatus($runProject, $runState) { - $builds = Factory::db()->getLatestProjectBranchBuildResults($this->name, 'state'); $status = self::STATUS_EMPTY; $statusText = ProjectRun::RESULT_EMPTY; - foreach ($builds as $build) { - if ($build['result'] == ProjectRun::RESULT_SUCCESS AND $status <= self::STATUS_SUCCESS) { - $status = self::STATUS_SUCCESS; - $statusText = ProjectRun::RESULT_SUCCESS; - } - if ($build['result'] == ProjectRun::RESULT_FAILURE AND $status <= self::STATUS_FAILURE) { - $status = self::STATUS_FAILURE; - $statusText = ProjectRun::RESULT_FAILURE; - } - if ($build['result'] == ProjectRun::RESULT_ABORTED AND $status <= self::STATUS_ABORTED) { - $status = self::STATUS_ABORTED; - $statusText = ProjectRun::RESULT_ABORTED; + // Status for project with project_run + if ($this->name == $runProject) { + $builds = Factory::db()->getLatestProjectBranchBuildResults($runProject, $runState); + foreach ($builds as $build) { + if ($build['result'] == ProjectRun::RESULT_SUCCESS AND $status <= self::STATUS_SUCCESS) { + $status = self::STATUS_SUCCESS; + $statusText = ProjectRun::RESULT_SUCCESS; + } + if ($build['result'] == ProjectRun::RESULT_FAILURE AND $status <= self::STATUS_FAILURE) { + $status = self::STATUS_FAILURE; + $statusText = ProjectRun::RESULT_FAILURE; + } + if ($build['result'] == ProjectRun::RESULT_ABORTED AND $status <= self::STATUS_ABORTED) { + $status = self::STATUS_ABORTED; + $statusText = ProjectRun::RESULT_ABORTED; + } } } + // Status based on testset results not implemented yet + $this->status = $statusText; return; } diff --git a/non-puppet/qtmetrics2/src/Testset.php b/non-puppet/qtmetrics2/src/Testset.php index 9e0bdf4..ce2d543 100644 --- a/non-puppet/qtmetrics2/src/Testset.php +++ b/non-puppet/qtmetrics2/src/Testset.php @@ -34,8 +34,8 @@ /** * Testset class - * @version 0.1 - * @since 04-06-2015 + * @version 0.2 + * @since 11-06-2015 * @author Juha Sippola */ @@ -88,9 +88,9 @@ class Testset { { $this->name = $name; $this->projectName = $projectName; - $this->status = TestsetRun::RESULT_EMPTY; // not initially set - $this->testsetResultCounts = array(); // not initially set - $this->testsetFlakyCounts = array(); // not initially set + $this->status = TestsetRun::RESULT_EMPTY; // not initially set + $this->testsetResultCounts = array('passed' => null, 'failed' => null); // not initially set + $this->testsetFlakyCounts = array('flaky' => null, 'total' => null); // not initially set } /** @@ -121,11 +121,13 @@ class Testset { } /** - * Set status of the testset calculated from the latest configuration build results (in state builds only). + * Set status of the testset calculated from the latest configuration build results (in specified builds only). + * @param string $runProject + * @param string $runState */ - public function setStatus() + public function setStatus($runProject, $runState) { - $builds = Factory::db()->getLatestTestsetConfBuildResults($this->name, $this->projectName, 'state'); + $builds = Factory::db()->getLatestTestsetConfBuildResults($this->name, $this->projectName, $runProject, $runState); $status = self::STATUS_EMPTY; $statusText = TestsetRun::RESULT_EMPTY; foreach ($builds as $build) { @@ -143,7 +145,7 @@ class Testset { } /** - * Get count of testset results in latest Project builds (all configurations, state builds only). + * Get count of testset results in latest Project builds (all configurations, specified builds only). * @return array (int passed, int failed) */ public function getTestsetResultCounts() @@ -152,7 +154,7 @@ class Testset { } /** - * Set count of testset results in latest Project builds (all configurations, state builds only). + * Set count of testset results in latest Project builds (all configurations, specified builds only). */ public function setTestsetResultCounts($passed, $failed) { @@ -161,7 +163,7 @@ class Testset { } /** - * Get count of flaky testsets in latest Project builds (all configurations, all states). + * Get count of flaky testsets in latest Project builds (all configurations, all builds). * @return array (int passed, int failed) */ public function getTestsetFlakyCounts() @@ -170,7 +172,7 @@ class Testset { } /** - * Set count of flaky testsets in latest Project builds (all configurations, all states). + * Set count of flaky testsets in latest Project builds (all configurations, all builds). */ public function setTestsetFlakyCounts($flaky, $total) { diff --git a/non-puppet/qtmetrics2/src/test/DatabaseTest.php b/non-puppet/qtmetrics2/src/test/DatabaseTest.php index 965f4b2..680b101 100644 --- a/non-puppet/qtmetrics2/src/test/DatabaseTest.php +++ b/non-puppet/qtmetrics2/src/test/DatabaseTest.php @@ -38,8 +38,8 @@ require_once(__DIR__.'/../Factory.php'); * Database unit test class * Some of the tests require the test data as inserted into database with qtmetrics_insert.sql * @example To run (in qtmetrics root directory): php <path-to-phpunit>/phpunit.phar ./src/test - * @version 0.1 - * @since 09-06-2015 + * @version 0.2 + * @since 10-06-2015 * @author Juha Sippola */ @@ -65,7 +65,8 @@ class DatabaseTest extends PHPUnit_Framework_TestCase public function testGetProjectsData() { return array( - array('QtBase') + array('qtbase'), + array('Qt5') ); } @@ -158,8 +159,8 @@ class DatabaseTest extends PHPUnit_Framework_TestCase public function testGetTestsetProjectData() { return array( - array('tst_qfont', 'QtBase', 1), - array('tst_qftp', 'QtBase', 2), + array('tst_qfont', 'qtbase', 1), + array('tst_qftp', 'qtbase', 2), array('tst_qftp', 'Qt5', 2), array('invalid-name', '', 0) ); @@ -217,7 +218,7 @@ class DatabaseTest extends PHPUnit_Framework_TestCase public function testGetLatestProjectBranchBuildNumbersData() { return array( - array('Qtbase', 'state', 'dev', 100) // Assuming any dev build has number > 100 + array('Qt5', 'state', 'dev', 100) // Assuming any dev build has number > 100 ); } @@ -235,7 +236,7 @@ class DatabaseTest extends PHPUnit_Framework_TestCase public function testGetLatestProjectBranchBuildNumberData() { return array( - array('Qtbase', 'dev', 'state', 100) // Assuming any dev build has number > 100 + array('Qt5', 'dev', 'state', 100) // Assuming any dev build has number > 100 ); } @@ -260,7 +261,7 @@ class DatabaseTest extends PHPUnit_Framework_TestCase public function testGetLatestProjectBranchBuildResultsData() { return array( - array('Qtbase', 'state', 'dev', array('SUCCESS', 'FAILURE', 'ABORTED')) + array('Qt5', 'state', 'dev', array('SUCCESS', 'FAILURE', 'ABORTED')) ); } @@ -268,11 +269,11 @@ class DatabaseTest extends PHPUnit_Framework_TestCase * Test getLatestTestsetConfBuildResults * @dataProvider testGetLatestTestsetConfBuildResultsData */ - public function testGetLatestTestsetConfBuildResults($testset, $project, $state, $exp_conf, $exp_branches, $exp_results) + public function testGetLatestTestsetConfBuildResults($testset, $testsetProject, $runProject, $state, $exp_conf, $exp_branches, $exp_results) { $confs = array(); $db = Factory::db(); - $result = $db->getLatestTestsetConfBuildResults($testset, $project, $state); + $result = $db->getLatestTestsetConfBuildResults($testset, $testsetProject, $runProject, $state); $this->assertNotEmpty($result); foreach($result as $row) { $this->assertArrayHasKey('name', $row); @@ -287,9 +288,9 @@ class DatabaseTest extends PHPUnit_Framework_TestCase public function testGetLatestTestsetConfBuildResultsData() { return array( - array('tst_qftp', 'Qtbase', 'state', 'linux-g++_developer-build_qtnamespace_qtlibinfix_Ubuntu_11.10_x64', array('dev', 'stable', 'master'), array('passed', 'failed', 'ipassed', 'ifailed')), - array('tst_qftp', 'Qtbase', 'state', 'linux-g++_developer-build_qtnamespace_qtlibinfix_Ubuntu_11.10_x64', array('dev', 'stable', 'master'), array('passed', 'failed', 'ipassed', 'ifailed')), - array('tst_qfont', 'Qtbase', 'state', 'macx-clang_developer-build_OSX_10.8', array('dev', 'stable', 'master'), array('passed', 'failed', 'ipassed', 'ifailed')) + array('tst_qftp', 'qtbase', 'Qt5', 'state', 'linux-g++_developer-build_qtnamespace_qtlibinfix_Ubuntu_11.10_x64', array('dev', 'stable', 'master'), array('passed', 'failed', 'ipassed', 'ifailed')), + array('tst_qftp', 'qtbase', 'Qt5', 'state', 'linux-g++_developer-build_qtnamespace_qtlibinfix_Ubuntu_11.10_x64', array('dev', 'stable', 'master'), array('passed', 'failed', 'ipassed', 'ifailed')), + array('tst_qfont', 'qtbase', 'Qt5', 'state', 'macx-clang_developer-build_OSX_10.8', array('dev', 'stable', 'master'), array('passed', 'failed', 'ipassed', 'ifailed')) ); } @@ -297,12 +298,12 @@ class DatabaseTest extends PHPUnit_Framework_TestCase * Test getTestsetsResultCounts * @dataProvider testGetTestsetsResultCountsData */ - public function testGetTestsetsResultCounts($date, $limit, $exp_testset, $exp_excluded_testset, $exp_testset_count_min, $exp_failed_min) + public function testGetTestsetsResultCounts($runProject, $runState, $date, $limit, $exp_testset, $exp_excluded_testset, $exp_testset_count_min, $exp_failed_min) { $testsets = array(); $failed = 0; $db = Factory::db(); - $result = $db->getTestsetsResultCounts($date, $limit); + $result = $db->getTestsetsResultCounts($runProject, $runState, $date, $limit); foreach($result as $row) { $this->assertArrayHasKey('name', $row); $this->assertArrayHasKey('project', $row); @@ -322,11 +323,11 @@ class DatabaseTest extends PHPUnit_Framework_TestCase public function testGetTestsetsResultCountsData() { return array( - array('2013-05-01', 10, 'tst_qftp', 'tst_networkselftest', 2, 1), // in test data only tst_qfont and tst_qftp have failures - array('2013-05-01', 1, 'tst_qftp', 'tst_networkselftest', 1, 1), - array('2013-05-28', 10, 'tst_qftp', 'tst_networkselftest', 2, 1), - array('2013-05-29', 10, '', '', 0, 0), - array('2999-05-29', 10, '', '', 0, 0) + array('Qt5', 'state', '2013-05-01', 10, 'tst_qftp', 'tst_networkselftest', 2, 1), // in test data only tst_qfont and tst_qftp have failures + array('Qt5', 'state', '2013-05-01', 1, 'tst_qftp', 'tst_networkselftest', 1, 1), + array('Qt5', 'state', '2013-05-28', 10, 'tst_qftp', 'tst_networkselftest', 2, 1), + array('Qt5', 'state', '2013-05-29', 10, '', '', 0, 0), + array('Qt5', 'state', '2999-05-29', 10, '', '', 0, 0) ); } @@ -334,12 +335,12 @@ class DatabaseTest extends PHPUnit_Framework_TestCase * Test getTestsetResultCounts * @dataProvider testGetTestsetResultCountsData */ - public function testGetTestsetResultCounts($testset, $date, $exp_project, $exp_testset_count_min, $exp_failed_min) + public function testGetTestsetResultCounts($testset, $runProject, $runState, $date, $exp_project, $exp_testset_count_min, $exp_failed_min) { $testsets = array(); $failed = 0; $db = Factory::db(); - $result = $db->getTestsetResultCounts($testset, $date); + $result = $db->getTestsetResultCounts($testset, $runProject, $runState, $date); foreach($result as $row) { $this->assertArrayHasKey('name', $row); $this->assertArrayHasKey('project', $row); @@ -360,12 +361,13 @@ class DatabaseTest extends PHPUnit_Framework_TestCase public function testGetTestsetResultCountsData() { return array( - array('tst_qftp', '2013-05-01', 'QtBase', 1, 1), - array('tst_qftp', '2013-05-28', 'QtBase', 1, 1), - array('tst_qftp', '2013-05-29', 'QtBase', 0, 0), - array('tst_qftp', '2999-05-29', 'QtBase', 0, 0), - array('tst_networkselftest', '2013-05-01', 'QtBase', 1, 0), // tst_networkselftest has been run but not failed - array('invalid-name', '2013-05-29', '', 0, 0) + array('tst_qftp', 'Qt5', 'state', '2013-05-01', 'qtbase', 1, 1), + array('tst_qftp', 'Qt5', 'state', '2013-05-28', 'qtbase', 1, 1), + array('tst_qftp', 'Qt5', 'state', '2013-05-29', 'qtbase', 0, 0), + array('tst_qftp', 'Qt5', 'state', '2999-05-29', 'qtbase', 0, 0), + array('tst_qftp', 'qtbase', 'state', '2013-05-01', '', 0, 0), // QtBase build not run (Qt5 only) + array('tst_networkselftest', 'Qt5', 'state', '2013-05-01', 'qtbase', 1, 0), // tst_networkselftest has been run but not failed + array('invalid-name', 'Qt5', 'state', '2013-05-29', '', 0, 0) ); } @@ -436,11 +438,11 @@ class DatabaseTest extends PHPUnit_Framework_TestCase public function testGetTestsetFlakyCountsData() { return array( - array('tst_qfont', '2013-05-01', 'QtBase', 1, 1), - array('tst_qfont', '2013-05-28', 'QtBase', 1, 1), - array('tst_qfont', '2013-05-29', 'QtBase', 0, 0), - array('tst_qfont', '2999-05-29', 'QtBase', 0, 0), - array('tst_networkselftest', '2013-05-01', 'QtBase', 1, 0), // tst_networkselftest has been run but not flaky + array('tst_qfont', '2013-05-01', 'qtbase', 1, 1), + array('tst_qfont', '2013-05-28', 'qtbase', 1, 1), + array('tst_qfont', '2013-05-29', 'qtbase', 0, 0), + array('tst_qfont', '2999-05-29', 'qtbase', 0, 0), + array('tst_networkselftest', '2013-05-01', 'qtbase', 1, 0), // tst_networkselftest has been run but not flaky array('invalid-name', '2013-05-29', '', 0, 0) ); } diff --git a/non-puppet/qtmetrics2/src/test/FactoryTest.php b/non-puppet/qtmetrics2/src/test/FactoryTest.php index bd96061..7bde27d 100644 --- a/non-puppet/qtmetrics2/src/test/FactoryTest.php +++ b/non-puppet/qtmetrics2/src/test/FactoryTest.php @@ -37,8 +37,8 @@ require_once(__DIR__.'/../Factory.php'); /** * Factory unit test class * @example To run (in qtmetrics root directory): php <path-to-phpunit>/phpunit.phar ./src/test - * @version 0.1 - * @since 04-06-2015 + * @version 0.2 + * @since 12-06-2015 * @author Juha Sippola */ @@ -128,12 +128,12 @@ class FactoryTest extends PHPUnit_Framework_TestCase * Test createProjects * @dataProvider testCreateProjectsData */ - public function testCreateProjects($status_check) + public function testCreateProjects($runProject, $runState) { - $projects = Factory::createProjects(); + $projects = Factory::createProjects($runProject, $runState); foreach($projects as $project) { $this->assertTrue($project instanceof Project); - if (in_array($project->getName(), $status_check)) { // check only the projects with project_run data + if ($project->getName() == $runProject) { // check only the projects with project_run data $this->assertNotEmpty($project->getStatus()); } } @@ -141,7 +141,7 @@ class FactoryTest extends PHPUnit_Framework_TestCase public function testCreateProjectsData() { return array( - array(array('QtBase', 'Qt5', 'QtConnectivity')) + array('Qt5', 'state',) // project with project_run data ); } @@ -149,9 +149,9 @@ class FactoryTest extends PHPUnit_Framework_TestCase * Test createTestsets * @dataProvider testCreateTestsetsData */ - public function testCreateTestsets($list_type, $status_check, $result_check, $flaky_check) + public function testCreateTestsets($listType, $runProject, $runState, $status_check) { - $testsets = Factory::createTestsets($list_type); + $testsets = Factory::createTestsets($listType, $runProject, $runState); foreach($testsets as $testset) { $this->assertTrue($testset instanceof Testset); $status = $testset->getStatus(); @@ -161,21 +161,13 @@ class FactoryTest extends PHPUnit_Framework_TestCase $this->assertEmpty($status); } $result = $testset->getTestsetResultCounts(); - if (in_array($testset->getName(), $result_check)) { - $this->assertNotNull($result); - $this->assertArrayHasKey('passed', $result); - $this->assertArrayHasKey('failed', $result); - } else { - $this->assertNull($result); - } + $this->assertNotNull($result); + $this->assertArrayHasKey('passed', $result); + $this->assertArrayHasKey('failed', $result); $flaky = $testset->getTestsetFlakyCounts(); - if (in_array($testset->getName(), $flaky_check)) { - $this->assertNotNull($flaky); - $this->assertArrayHasKey('flaky', $flaky); - $this->assertArrayHasKey('total', $flaky); - } else { - $this->assertNull($flaky); - } + $this->assertNotNull($flaky); + $this->assertArrayHasKey('flaky', $flaky); + $this->assertArrayHasKey('total', $flaky); } } public function testCreateTestsetsData() @@ -183,15 +175,15 @@ class FactoryTest extends PHPUnit_Framework_TestCase return array( array( Factory::LIST_FAILURES, - array('tst_qftp', 'tst_qfont', 'tst_networkselftest'), // check only the testsets with testset_run data - array('tst_qftp', 'tst_qfont', 'tst_networkselftest'), // check only the testsets with testset_run data - array('not-set') // flaky data not set for failures list + 'Qt5', + 'state', + array('tst_qftp', 'tst_qfont', 'tst_networkselftest') // check only the testsets with testset_run data ), array( Factory::LIST_FLAKY, - array('not-set'), // status not set for flaky list - array('not-set'), // result data not set for flaky list - array('tst_qftp', 'tst_qfont', 'tst_networkselftest') // check only the testsets with testset_run data + 'Qt5', + 'state', + array('not-set') // status not set for flaky list ) ); } @@ -200,9 +192,9 @@ class FactoryTest extends PHPUnit_Framework_TestCase * Test createTestset * @dataProvider testCreateTestsetData */ - public function testCreateTestset($testset, $project) + public function testCreateTestset($testset, $project, $runProject, $runState) { - $testsets = Factory::createTestset($testset); + $testsets = Factory::createTestset($testset, $runProject, $runState); foreach($testsets as $testset) { $this->assertTrue($testset instanceof Testset); if ($testset->getProjectName() == $project) { @@ -222,8 +214,8 @@ class FactoryTest extends PHPUnit_Framework_TestCase public function testCreateTestsetData() { return array( - array('tst_qftp', 'QtBase'), // testset with testset_run data - array('tst_qfont', 'QtBase') // testset with testset_run data + array('tst_qftp', 'qtbase', 'Qt5', 'state',), // testset with testset_run data + array('tst_qfont', 'qtbase', 'Qt5', 'state',) // testset with testset_run data ); } diff --git a/non-puppet/qtmetrics2/src/test/ProjectTest.php b/non-puppet/qtmetrics2/src/test/ProjectTest.php index b30cd5c..8ea8fed 100644 --- a/non-puppet/qtmetrics2/src/test/ProjectTest.php +++ b/non-puppet/qtmetrics2/src/test/ProjectTest.php @@ -37,8 +37,8 @@ require_once(__DIR__.'/../Factory.php'); /** * Project unit test class * @example To run (in qtmetrics root directory): php <path-to-phpunit>/phpunit.phar ./src/test - * @version 0.1 - * @since 07-05-2015 + * @version 0.2 + * @since 12-05-2015 * @author Juha Sippola */ @@ -57,7 +57,8 @@ class ProjectTest extends PHPUnit_Framework_TestCase public function testGetNameData() { return array( - array('QtBase'), + array('qtbase'), + array('Qt5'), array('MyProject') ); } @@ -66,17 +67,22 @@ class ProjectTest extends PHPUnit_Framework_TestCase * Test getStatus and setStatus * @dataProvider testGetStatusData */ - public function testGetStatus($name, $exp_build_results) + public function testGetStatus($name, $runProject, $runState, $exp_build_results) { $project = new Project($name); - $project->setStatus(); - $this->assertContains($project->getStatus(), $exp_build_results); + if ($runProject == $name) { // project with project_run data + $project->setStatus($runProject, $runState); + $this->assertContains($project->getStatus(), $exp_build_results); + } else { + $this->assertEmpty($project->getStatus()); + } } public function testGetStatusData() { return array( - array('QtBase', array('SUCCESS', 'FAILURE', 'ABORTED')), - array('InvalidProject', array('')) + array('Qt5', 'Qt5', 'state', array('SUCCESS', 'FAILURE', 'ABORTED')), // status based on build result for the master build project + array('QtBase', 'Qt5', 'state', array()), // status based on testset results not implemented yet + array('InvalidProject', 'Qt5', 'state', array()) ); } diff --git a/non-puppet/qtmetrics2/src/test/TestsetTest.php b/non-puppet/qtmetrics2/src/test/TestsetTest.php index 472056c..dae7ce1 100644 --- a/non-puppet/qtmetrics2/src/test/TestsetTest.php +++ b/non-puppet/qtmetrics2/src/test/TestsetTest.php @@ -37,8 +37,8 @@ require_once(__DIR__.'/../Factory.php'); /** * Testset unit test class * @example To run (in qtmetrics root directory): php <path-to-phpunit>/phpunit.phar ./src/test - * @version 0.1 - * @since 04-06-2015 + * @version 0.2 + * @since 11-06-2015 * @author Juha Sippola */ @@ -67,17 +67,17 @@ class TestsetTest extends PHPUnit_Framework_TestCase * Test setStatus and getStatus * @dataProvider testGetStatusData */ - public function testGetStatus($name, $project, $exp_results) + public function testGetStatus($name, $project, $runProject, $runState, $exp_results) { $testset = new Testset($name, $project); - $testset->setStatus(); + $testset->setStatus($runProject, $runState); $this->assertContains($testset->getStatus(), $exp_results); } public function testGetStatusData() { return array( - array('tst_qftp', 'QtBase', array('passed', 'failed', 'ipassed', 'ifailed')), - array('tst_invalid', 'QtBase', array('')) + array('tst_qftp', 'QtBase', 'Qt5', 'state', array('passed', 'failed', 'ipassed', 'ifailed')), + array('tst_invalid', 'QtBase', 'Qt5', 'state', array('')) ); } @@ -88,6 +88,13 @@ class TestsetTest extends PHPUnit_Framework_TestCase public function testGetTestsetResultCounts($name, $project, $passed, $failed) { $testset = new Testset($name, $project); + // Counts not set + $result = $testset->getTestsetResultCounts(); + $this->assertArrayHasKey('passed', $result); + $this->assertArrayHasKey('failed', $result); + $this->assertNull($result['passed']); + $this->assertNull($result['failed']); + // Counts set $testset->setTestsetResultCounts($passed, $failed); $result = $testset->getTestsetResultCounts(); $this->assertArrayHasKey('passed', $result); @@ -111,6 +118,13 @@ class TestsetTest extends PHPUnit_Framework_TestCase public function testGetTestsetFlakyCounts($name, $project, $flaky, $total) { $testset = new Testset($name, $project); + // Counts not set + $result = $testset->getTestsetFlakyCounts(); + $this->assertArrayHasKey('flaky', $result); + $this->assertArrayHasKey('total', $result); + $this->assertNull($result['flaky']); + $this->assertNull($result['total']); + // Counts set $testset->setTestsetFlakyCounts($flaky, $total); $result = $testset->getTestsetFlakyCounts(); $this->assertArrayHasKey('flaky', $result); diff --git a/non-puppet/qtmetrics2/templates/about.php b/non-puppet/qtmetrics2/templates/about.php index 5cf863a..b1dfb4d 100644 --- a/non-puppet/qtmetrics2/templates/about.php +++ b/non-puppet/qtmetrics2/templates/about.php @@ -34,8 +34,8 @@ /** * About window content - * @version 0.1 - * @since 08-06-2015 + * @version 0.2 + * @since 16-06-2015 * @author Juha Sippola */ @@ -44,4 +44,4 @@ <p>This is Qt Metrics revision 2 with redesigned UI and database.</p> <p>These pages are still <strong>under construction</strong> and therefore the views and functionality is limited.</p> <p>See the <a href="https://wiki.qt.io/Qt_Metrics_2_Backlog" target="_blank">backlog</a> for development items currently identified or in progress.</p> -<p><small>Version 0.1 (8-Jun-2015)</small></p> +<p><small>Version 0.2 (16-Jun-2015)</small></p> diff --git a/non-puppet/qtmetrics2/templates/testset.php b/non-puppet/qtmetrics2/templates/testset.php index 7e2befa..e26a06a 100644 --- a/non-puppet/qtmetrics2/templates/testset.php +++ b/non-puppet/qtmetrics2/templates/testset.php @@ -34,8 +34,8 @@ /** * Testset page - * @version 0.1 - * @since 03-06-2015 + * @version 0.2 + * @since 11-06-2015 * @author Juha Sippola */ @@ -46,6 +46,8 @@ $breadcrumb = $this->data['breadcrumb']; $refreshed = $this->data['refreshed']; $lastDaysFailures = $this->data['lastDaysFailures']; $lastDaysFlaky = $this->data['lastDaysFlaky']; +$masterProject = $this->data['masterProject']; +$masterState = $this->data['masterState']; /** * @var Testset[] $testsets */ @@ -82,12 +84,14 @@ $testsets = $this->data['testset']; <div class="well infoWell"> <span class="glyphicon glyphicon-info-sign"></span> <strong>Testset</strong><br> <ul> - <li><strong>latest result</strong> shows the overall testset status based on the latest project configuration - <strong>state</strong> builds across all branches (shows failed if failed in one or in several).</li> - <li><strong>failed</strong> count shows the number of <strong>state</strong> builds where - <?php echo $testset->getName() ?> failed during the last <?php echo $lastDaysFailures ?> days.</li> + <li><strong>latest result</strong> shows the overall testset status based on the latest + <strong><?php echo "$masterProject $masterState" ?></strong> builds across all branches + (shows failed if failed in one or in several).</li> + <li><strong>failed</strong> count shows the number of <strong><?php echo "$masterProject $masterState" ?></strong> + builds where <?php echo $testset->getName() ?> failed during the last <?php echo $lastDaysFailures ?> days.</li> <li><strong>flaky</strong> count shows the number of <strong>all</strong> builds where - <?php echo $testset->getName() ?> failed on the first run but, when rerun, it passed (during the last <?php echo $lastDaysFlaky ?> days).</li> + <?php echo $testset->getName() ?> failed on the first run but, when rerun, it passed + (during the last <?php echo $lastDaysFlaky ?> days).</li> </ul> </div> </div> diff --git a/non-puppet/qtmetrics2/templates/testsets_top.php b/non-puppet/qtmetrics2/templates/testsets_top.php index 0eb96cf..1f37e4e 100644 --- a/non-puppet/qtmetrics2/templates/testsets_top.php +++ b/non-puppet/qtmetrics2/templates/testsets_top.php @@ -34,8 +34,8 @@ /** * Top failures (testsets) page - * @version 0.1 - * @since 03-06-2015 + * @version 0.2 + * @since 11-06-2015 * @author Juha Sippola */ @@ -51,6 +51,8 @@ $refreshed = $this->data['refreshed']; $topN = $this->data['topN']; $lastDays = $this->data['lastDays']; $sinceDate = $this->data['sinceDate']; +$masterProject = $this->data['masterProject']; +$masterState = $this->data['masterState']; /** * @var Testset[] $testsets */ @@ -85,10 +87,11 @@ $testsets = $this->data['testsets']; <div class="well infoWell"> <span class="glyphicon glyphicon-info-sign"></span> <strong>Top failures</strong><br> <ul> - <li>Lists testsets by number of <strong>state</strong> builds where it failed during the last - <?php echo $lastDays ?> days.</li> - <li><strong>latest result</strong> shows the overall testset status based on the latest project - <strong>state</strong> builds across all branches (shows failed if failed in one or in several).</li> + <li>Lists testsets by number of <strong><?php echo "$masterProject $masterState" ?></strong> + builds where it failed during the last <?php echo $lastDays ?> days.</li> + <li><strong>latest result</strong> shows the overall testset status based on the latest + <strong><?php echo "$masterProject $masterState" ?></strong> builds across all branches + (shows failed if failed in one or in several).</li> </ul> </div> </div> diff --git a/non-puppet/qtmetrics2/testparser.pl b/non-puppet/qtmetrics2/testparser.pl index 7f1dd64..b947610 100644 --- a/non-puppet/qtmetrics2/testparser.pl +++ b/non-puppet/qtmetrics2/testparser.pl @@ -838,6 +838,26 @@ sub get_log_data return (\%logdata); } +sub parse_module_from_path { + my $path = shift; + $path =~ s/\\/\//g; + my ($returnval) = $path =~ m/.*\/(.*)\/tests\/.*/; + if (!defined $returnval) { # exception: qtqa tests not in a 'tests' folder + ($returnval) = $path =~ m/.*\/(.*)\/scripts/; + } + return $returnval; +} + +sub parse_testpath_from_path { + my $path = shift; + $path =~ s/\\/\//g; + my ($returnval) = $path =~ m/.*\/(.*\/tests\/.*)/; + if (!defined $returnval) { # exception: qtqa tests not in a 'tests' folder + ($returnval) = $path =~ m/.*\/(.*\/scripts)/; + } + return $returnval; +} + sub get_test_results { print "Getting test results.\n"; @@ -854,6 +874,8 @@ sub get_test_results # stores the state if we're between "Testing" and "Totals:", meaning, we're storing autotestdata. my $testdata = 0; my $testsetname = ""; + my $testsetmodule = ""; + my $testsetpath = ""; foreach my $line (@filecontent) { $line =~ s/[\n|\r]$//g; $phase = 1 if ($line =~ m/^$RESULTPARTSTR$/); @@ -862,14 +884,19 @@ sub get_test_results $autotest = 0 if ($line =~ m/#=#.*?#=#\s\<(.*)\s#=# Elapsed (\d+) second\(s\).$/); if (1 == $autotest) { - if ($line =~ m/^QtQA::App::TestRunner: begin (.*):\s\[/) { + if ($line =~ m/^QtQA::App::TestRunner: begin (.*?)\s@\s(.*):\s\[/) { $testsetname = $1; - next if ($testsetname =~ m/license/); - next if ($testsetname =~ m/tst_headers/); - next if ($testsetname =~ m/tst_bic/); + $testsetmodule = parse_module_from_path($2); + $testsetpath = parse_testpath_from_path($2); + # testsets can be skipped if needed (e.g. unsupported format) + #next if ($testsetname =~ m/license/); + #next if ($testsetname =~ m/tst_headers/); + #next if ($testsetname =~ m/tst_bic/); $testdata = 1; # set initial values for a new test set if (!$testresults{all_tests}{$testsetname}) { + $testresults{all_tests}{$testsetname}{module} = $testsetmodule; + $testresults{all_tests}{$testsetname}{path} = $testsetpath; $testresults{all_tests}{$testsetname}{runs} = 0; $testresults{all_tests}{$testsetname}{passed} = 0; $testresults{all_tests}{$testsetname}{failed} = 0; @@ -1032,7 +1059,7 @@ sub sql_drop_tables sub sql_create_tables { my $dbh = shift; - print "Creating new tables.\n"; + print "Creating new tables (if they do not exist yet).\n"; $dbh->{AutoCommit} = 0; # enable transactions, if possible $dbh->{RaiseError} = 1; @@ -1485,13 +1512,22 @@ sub sql #insert data into test tables if (defined $datahash{cfg}{$cfg}{testresults}{all_tests}) { - my $timestamp_cfg = $datahash{cfg}{$cfg}{builddata}{TIMESTAMP} ? "\"$datahash{cfg}{$cfg}{builddata}{TIMESTAMP}\"" : "0"; foreach my $test (keys %{$datahash{cfg}{$cfg}{testresults}{all_tests}}) { + # insert testset project first + my $testset_project = $datahash{cfg}{$cfg}{testresults}{all_tests}{$test}{module}; + print "ERORR: $test doesn't have parent module set (in $cfg).\n" if (!defined $testset_project); + if ("0E0" eq $dbh->do ("SELECT name FROM project WHERE name = \"$testset_project\"")) { + my $query = + "INSERT INTO project (name) VALUES (\"$testset_project\")"; + print OUTPUT "$query\n" if $VERBOSE or $output; + $dbh->do ($query) or print "insert into project failed: $!\n" if !$output; + } + # insert testset connected to its parent project if ("0E0" eq $dbh->do ("SELECT testset.name FROM testset INNER JOIN project ON testset.project_id = project.id - WHERE testset.name = \"$test\" AND project.name = \"$projectname\"")) { + WHERE testset.name = \"$test\" AND project.name = \"$testset_project\"")) { my $query = - "INSERT INTO testset (project_id, name) SELECT id, \"$test\" FROM project WHERE project.name = \"$projectname\""; + "INSERT INTO testset (project_id, name) SELECT id, \"$test\" FROM project WHERE project.name = \"$testset_project\""; print OUTPUT "$query\n" if $VERBOSE or $output; $dbh->do ($query) or print "insert into testset failed: $!\n" if !$output; } @@ -1502,6 +1538,7 @@ sub sql } else { $testset_result = $datahash{cfg}{$cfg}{testresults}{all_tests}{$test}{insignificant} ? "\"ifailed\"" : "\"failed\""; } + # testset is connected to its parent project (e.g. QtConnectivity) while testset_run to project where run (e.g. Qt5) my $query = "INSERT INTO testset_run (testset_id, conf_run_id, run, result, duration, testcases_passed, testcases_failed, testcases_skipped, testcases_blacklisted) SELECT testset.id, @@ -1515,7 +1552,7 @@ sub sql $datahash{cfg}{$cfg}{testresults}{all_tests}{$test}{blacklisted} FROM testset, conf_run WHERE testset.name = \"$test\" AND - testset.project_id = (SELECT id FROM project WHERE project.name = \"$projectname\") AND + testset.project_id = (SELECT id FROM project WHERE project.name = \"$testset_project\") AND conf_run.id = ( SELECT conf_run.id FROM conf_run @@ -1693,6 +1730,8 @@ sub run $db_status{total} = $#inputfolders+1; print "Processing $inputfolder...\n"; + next if ($inputfolder =~ m/qt_4/i); # exception: exclude Qt_4.8 + sql_update_progress($dbh, \%db_status); my $statefile = catfile($inputfolder, $BUILDSTATEFILE); my $mainlogfile = catfile($inputfolder, $BUILDLOGFILE); |