diff options
author | Juha Sippola <juhasippola@outlook.com> | 2015-08-05 09:54:17 +0300 |
---|---|---|
committer | Tony SarajΓ€rvi <tony.sarajarvi@theqtcompany.com> | 2015-09-16 07:33:31 +0000 |
commit | f6371c61dffb03a2d3d5e1b8c6d3e3086f9f5afc (patch) | |
tree | 3243484de3db3628749aa85595829f2034b4789c | |
parent | 253f868a6a164ce50021e5e6e4aaf219343e0e52 (diff) |
Qt Metrics 2: Configuration functions
Changes for configuration database searches.
Change-Id: I2f5ed85a869f064233fc11361e650e33db61e18c
Reviewed-by: Tony SarajΓ€rvi <tony.sarajarvi@theqtcompany.com>
-rw-r--r-- | non-puppet/qtmetrics2/src/Database.php | 171 | ||||
-rw-r--r-- | non-puppet/qtmetrics2/src/Factory.php | 54 | ||||
-rw-r--r-- | non-puppet/qtmetrics2/src/TestsetRun.php | 15 | ||||
-rw-r--r-- | non-puppet/qtmetrics2/src/test/DatabaseTest.php | 135 | ||||
-rw-r--r-- | non-puppet/qtmetrics2/src/test/FactoryTest.php | 60 |
5 files changed, 422 insertions, 13 deletions
diff --git a/non-puppet/qtmetrics2/src/Database.php b/non-puppet/qtmetrics2/src/Database.php index db81c05..ce5f5ab 100644 --- a/non-puppet/qtmetrics2/src/Database.php +++ b/non-puppet/qtmetrics2/src/Database.php @@ -34,8 +34,8 @@ /** * Database class - * @version 0.8 - * @since 06-07-2015 + * @version 0.9 + * @since 21-07-2015 * @author Juha Sippola */ @@ -307,6 +307,60 @@ class Database { } /** + * Get the latest configuration build result by branch for given project and state + * @param string $conf + * @param string $runProject + * @param string $runState + * @return array (string name, string result, string buildKey, string timestamp, string duration) + */ + public function getLatestConfBranchBuildResults($conf, $runProject, $runState) + { + $result = array(); + $builds = self::getLatestProjectBranchBuildKeys($runProject, $runState); + foreach ($builds as $build) { + $query = $this->db->prepare(" + SELECT + branch.name, + conf_run.result, + project_run.build_key, + conf_run.forcesuccess, + conf_run.insignificant, + conf_run.timestamp, + conf_run.duration + FROM conf_run + INNER JOIN conf ON conf_run.conf_id = conf.id + INNER JOIN project_run ON conf_run.project_run_id = project_run.id + INNER JOIN branch ON project_run.branch_id = branch.id + WHERE + conf.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.branch_id = (SELECT id from branch WHERE name = ?) AND + project_run.build_key = ?; + "); + $query->execute(array( + $conf, + $runProject, + $runState, + $build['name'], + $build['key'] + )); + while($row = $query->fetch(PDO::FETCH_ASSOC)) { + $result[] = array( + 'name' => $row['name'], + 'result' => $row['result'], + 'buildKey' => $row['build_key'], + 'forcesuccess' => $row['forcesuccess'], + 'insignificant' => $row['insignificant'], + 'timestamp' => $row['timestamp'], + 'duration' => $row['duration'] + ); + } + } + return $result; + } + + /** * Get the latest testset result by branch for given project and state * @param string $runProject * @param string $runState @@ -974,6 +1028,119 @@ class Database { } /** + * Get results for failed testsets in specified configuration builds by branch + * Only the failures are listed + * @param $conf + * @param string $runProject + * @param string $runState + * @return array (string branch, string build_key, string testset, string project, string result, string timestamp, string duration, int run) + */ + public function getTestsetConfResultsByBranch($conf, $runProject, $runState) + { + $result = array(); + $query = $this->db->prepare(" + SELECT + branch.name AS branch, + project_run.build_key, + testset.name AS testset, + project.name AS project, + testset_run.result, + project_run.timestamp, + testset_run.duration, + testset_run.run + FROM testset_run + INNER JOIN testset ON testset_run.testset_id = testset.id + INNER JOIN project ON testset.project_id = project.id + INNER JOIN conf_run ON testset_run.conf_run_id = conf_run.id + INNER JOIN conf ON conf_run.conf_id = conf.id + INNER JOIN project_run ON conf_run.project_run_id = project_run.id + INNER JOIN branch ON project_run.branch_id = branch.id + WHERE + testset_run.result LIKE '%failed' AND + conf.name = ? AND + project_run.project_id = (SELECT id FROM project WHERE name = ?) AND + project_run.state_id = (SELECT id FROM state WHERE name = ?) + ORDER BY branch.name, project.name, testset.name, project_run.build_key DESC; + "); + $query->execute(array( + $conf, + $runProject, + $runState + )); + while($row = $query->fetch(PDO::FETCH_ASSOC)) { + $result[] = array( + 'branch' => $row['branch'], + 'buildKey' => $row['build_key'], + 'testset' => $row['testset'], + 'project' => $row['project'], + 'result' => $row['result'], + 'timestamp' => $row['timestamp'], + 'duration' => $row['duration'], + 'run' => $row['run'] + ); + } + return $result; + } + + /** + * Get results for failed testsets in specified configuration builds and project by branch + * Only the failures are listed + * @param $conf + * @param $testsetProject + * @param string $runProject + * @param string $runState + * @return array (string branch, string build_key, string testset, string project, string result, string timestamp, string duration, int run) + */ + public function getTestsetConfProjectResultsByBranch($conf, $testsetProject, $runProject, $runState) + { + $result = array(); + $query = $this->db->prepare(" + SELECT + branch.name AS branch, + project_run.build_key, + testset.name AS testset, + project.name AS project, + testset_run.result, + project_run.timestamp, + testset_run.duration, + testset_run.run + FROM testset_run + INNER JOIN testset ON testset_run.testset_id = testset.id + INNER JOIN project ON testset.project_id = project.id + INNER JOIN conf_run ON testset_run.conf_run_id = conf_run.id + INNER JOIN conf ON conf_run.conf_id = conf.id + INNER JOIN project_run ON conf_run.project_run_id = project_run.id + INNER JOIN branch ON project_run.branch_id = branch.id + WHERE + testset_run.result LIKE '%failed' AND + project.name = ? AND + conf.name = ? AND + project_run.project_id = (SELECT id FROM project WHERE name = ?) AND + project_run.state_id = (SELECT id FROM state WHERE name = ?) + ORDER BY branch.name, project.name, testset.name, project_run.build_key DESC; + "); + $query->execute(array( + $testsetProject, + $conf, + $runProject, + $runState + )); + while($row = $query->fetch(PDO::FETCH_ASSOC)) { + $result[] = array( + 'branch' => $row['branch'], + 'buildKey' => $row['build_key'], + 'testset' => $row['testset'], + 'project' => $row['project'], + 'result' => $row['result'], + 'timestamp' => $row['timestamp'], + 'duration' => $row['duration'], + 'run' => $row['run'] + ); + } + return $result; + } + + /** * Get the timestamp when database last refreshed * @return string (timestamp) */ diff --git a/non-puppet/qtmetrics2/src/Factory.php b/non-puppet/qtmetrics2/src/Factory.php index b1a86c3..4e57365 100644 --- a/non-puppet/qtmetrics2/src/Factory.php +++ b/non-puppet/qtmetrics2/src/Factory.php @@ -34,14 +34,15 @@ /** * Factory class - * @version 0.6 - * @since 06-07-2015 + * @version 0.7 + * @since 20-07-2015 * @author Juha Sippola */ require_once 'Database.php'; require_once 'Project.php'; require_once 'ProjectRun.php'; +require_once 'Conf.php'; require_once 'ConfRun.php'; require_once 'Testset.php'; require_once 'TestsetRun.php'; @@ -162,6 +163,20 @@ class Factory { } /** + * Create Configuration object for that in database + * @param string $conf + * @param string $runProject + * @param string $runState + * @return array Conf object + */ + public static function createConf($conf, $runProject, $runState) + { + $obj = new Conf($conf); + $obj->setStatus($runProject, $runState); + return $obj; + } + + /** * 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 @@ -299,6 +314,41 @@ class Factory { } /** + * Create TestsetRun objects in a configuration for those in database + * @param string $conf + * @param string $testsetProject + * @param string $runProject + * @param string $runState + * @return array TestsetRun objects + */ + public static function createTestsetRunsInConf($conf, $testsetProject, $runProject, $runState) + { + $objects = array(); + if (empty($testsetProject)) + $dbEntries = self::db()->getTestsetConfResultsByBranch($conf, $runProject, $runState); + else + $dbEntries = self::db()->getTestsetConfProjectResultsByBranch($conf, $testsetProject, $runProject, $runState); + foreach($dbEntries as $entry) { + $obj = new TestsetRun( + $entry['testset'], + $entry['project'], + $runProject, + $entry['branch'], + $runState, + $entry['buildKey'], + $conf, + $entry['run'], + TestsetRun::stripResult($entry['result']), + TestsetRun::isInsignificant($entry['result']), + $entry['timestamp'], + $entry['duration'] + ); + $objects[] = $obj; + } + return $objects; + } + + /** * Get the date that was n days before the last database refresh date. * @param int $days * @return string (date in unix date format) diff --git a/non-puppet/qtmetrics2/src/TestsetRun.php b/non-puppet/qtmetrics2/src/TestsetRun.php index e90f5cc..6da6161 100644 --- a/non-puppet/qtmetrics2/src/TestsetRun.php +++ b/non-puppet/qtmetrics2/src/TestsetRun.php @@ -34,8 +34,8 @@ /** * TestsetRun class - * @version 0.4 - * @since 30-06-2015 + * @version 0.5 + * @since 15-07-2015 * @author Juha Sippola */ @@ -97,7 +97,7 @@ class TestsetRun extends ProjectRun { public function __construct($name, $testsetProjectName, $projectName, $branchName, $stateName, $buildKey, $confName, $run, $result, $insignificant, $timestamp, $duration) { parent::__construct($projectName, $branchName, $stateName, $buildKey, $result, $timestamp, $duration); $this->name = $name; - $this->$testsetProjectName = $testsetProjectName; + $this->testsetProjectName = $testsetProjectName; $this->confName = $confName; $this->run = $run; $this->insignificant = $insignificant; @@ -113,6 +113,15 @@ class TestsetRun extends ProjectRun { } /** + * Get name of the testset project. + * @return string + */ + public function getTestsetProjectName() + { + return $this->testsetProjectName; + } + + /** * Get configuration name. * @return string */ diff --git a/non-puppet/qtmetrics2/src/test/DatabaseTest.php b/non-puppet/qtmetrics2/src/test/DatabaseTest.php index cff443a..8fc798c 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.8 - * @since 06-07-2015 + * @version 0.9 + * @since 21-07-2015 * @author Juha Sippola */ @@ -299,6 +299,39 @@ class DatabaseTest extends PHPUnit_Framework_TestCase } /** + * Test getLatestConfBranchBuildResults + * @dataProvider testGetLatestConfBranchBuildResultsData + */ + public function testGetLatestConfBranchBuildResults($conf, $project, $state, $exp_branch, $exp_results) + { + $branches = array(); + $db = Factory::db(); + $result = $db->getLatestConfBranchBuildResults($conf, $project, $state); + $this->assertNotEmpty($result); + foreach($result as $row) { + $this->assertArrayHasKey('name', $row); + $this->assertArrayHasKey('result', $row); + $this->assertArrayHasKey('buildKey', $row); + $this->assertArrayHasKey('forcesuccess', $row); + $this->assertArrayHasKey('insignificant', $row); + $this->assertArrayHasKey('timestamp', $row); + $this->assertArrayHasKey('duration', $row); + $this->assertContains($row['result'], $exp_results); + $branches[] = $row['name']; + } + $this->assertContains($exp_branch, $branches); + } + public function testGetLatestConfBranchBuildResultsData() + { + return array( + array('linux-g++-32_developer-build_Ubuntu_10.04_x86', 'Qt5', 'state', 'dev', array('SUCCESS', 'FAILURE', 'ABORTED')), + array('win32-msvc2010_developer-build_angle_Windows_7', 'Qt5', 'state', 'master', array('SUCCESS', 'FAILURE', 'ABORTED')), + array('win32-msvc2010_developer-build_angle_Windows_7', 'Qt5', 'state', 'release', array('SUCCESS', 'FAILURE', 'ABORTED')), + array('win32-msvc2010_developer-build_angle_Windows_7', 'Qt5', 'state', 'stable', array('SUCCESS', 'FAILURE', 'ABORTED')) + ); + } + + /** * Test getLatestProjectBranchTestsetResults * @dataProvider testGetLatestProjectBranchTestsetResultsData */ @@ -778,7 +811,6 @@ class DatabaseTest extends PHPUnit_Framework_TestCase $branches = array(); $confs = array(); $keys = array(); - $results = array(); $db = Factory::db(); $result = $db->getTestsetProjectResultsByBranchConf($testsetProject, $runProject, $runState); foreach($result as $row) { @@ -815,6 +847,103 @@ class DatabaseTest extends PHPUnit_Framework_TestCase } /** + * Test getTestsetConfResultsByBranch + * @dataProvider testGetTestsetConfResultsByBranchData + */ + public function testGetTestsetConfResultsByBranch($conf, $runProject, $runState, $exp_branch, $exp_testset, $exp_testset_excluded, $exp_project, $exp_key, $has_data) + { + $branches = array(); + $keys = array(); + $testsets = array(); + $projects = array(); + $db = Factory::db(); + $result = $db->getTestsetConfResultsByBranch($conf, $runProject, $runState); + foreach($result as $row) { + $this->assertArrayHasKey('branch', $row); + $this->assertArrayHasKey('buildKey', $row); + $this->assertArrayHasKey('testset', $row); + $this->assertArrayHasKey('project', $row); + $this->assertArrayHasKey('result', $row); + $this->assertArrayHasKey('timestamp', $row); + $this->assertArrayHasKey('duration', $row); + $this->assertArrayHasKey('run', $row); + $branches[] = $row['branch']; + $keys[] = $row['buildKey']; + $testsets[] = $row['testset']; + $projects[] = $row['project']; + } + if ($has_data) { + $this->assertNotEmpty($result); + $this->assertContains($exp_branch, $branches); + $this->assertContains($exp_key, $keys); + $this->assertContains($exp_testset, $testsets); + $this->assertNotContains($exp_testset_excluded, $testsets); + $this->assertContains($exp_project, $projects); + } else { + $this->assertEmpty($result); + } + } + public function testGetTestsetConfResultsByBranchData() + { + return array( + array('linux-g++_developer-build_qtnamespace_qtlibinfix_Ubuntu_11.10_x64', 'Qt5', 'state', 'dev', 'tst_qftp', 'na', 'qtbase', '1023', 1), + array('linux-g++-32_developer-build_Ubuntu_10.04_x86', 'Qt5', 'state', 'stable', 'tst_qftp', 'na', 'qtbase', '1348', 1), + array('macx-clang_developer-build_OSX_10.8', 'Qt5', 'state', 'stable', 'tst_qfont', 'tst_networkselftest', 'qtbase', '1348', 1), + array('linux-g++-32_developer-build_Ubuntu_10.04_x86', 'Qt5', 'state', 'dev', 'tst_qftp', 'na', 'qtbase', 'BuildKeyInStringFormat12345', 1), + array('invalid', 'Qt5', 'state', '', '', '', '', '', 0) + ); + } + + /** + * Test getTestsetConfProjectResultsByBranch + * @dataProvider testGetTestsetConfProjectResultsByBranchData + */ + public function testGetTestsetConfProjectResultsByBranch($conf, $testsetProject, $runProject, $runState, $exp_branch, $exp_testset, $exp_testset_excluded, $exp_project, $exp_key, $has_data) + { + $branches = array(); + $keys = array(); + $testsets = array(); + $projects = array(); + $db = Factory::db(); + $result = $db->getTestsetConfProjectResultsByBranch($conf, $testsetProject, $runProject, $runState); + foreach($result as $row) { + $this->assertArrayHasKey('branch', $row); + $this->assertArrayHasKey('buildKey', $row); + $this->assertArrayHasKey('testset', $row); + $this->assertArrayHasKey('project', $row); + $this->assertArrayHasKey('result', $row); + $this->assertArrayHasKey('timestamp', $row); + $this->assertArrayHasKey('duration', $row); + $this->assertArrayHasKey('run', $row); + $branches[] = $row['branch']; + $keys[] = $row['buildKey']; + $testsets[] = $row['testset']; + $projects[] = $row['project']; + } + if ($has_data) { + $this->assertNotEmpty($result); + $this->assertContains($exp_branch, $branches); + $this->assertContains($exp_key, $keys); + $this->assertContains($exp_testset, $testsets); + $this->assertNotContains($exp_testset_excluded, $testsets); + $this->assertContains($exp_project, $projects); + } else { + $this->assertEmpty($result); + } + } + public function testGetTestsetConfProjectResultsByBranchData() + { + return array( + array('linux-g++_developer-build_qtnamespace_qtlibinfix_Ubuntu_11.10_x64', 'qtbase', 'Qt5', 'state', 'dev', 'tst_qftp', 'na', 'qtbase', '1023', 1), + array('linux-g++-32_developer-build_Ubuntu_10.04_x86', 'qtbase', 'Qt5', 'state', 'stable', 'tst_qftp', 'na', 'qtbase', '1348', 1), + array('macx-clang_developer-build_OSX_10.8', 'qtbase', 'Qt5', 'state', 'stable', 'tst_qfont', 'tst_networkselftest', 'qtbase', '1348', 1), + array('linux-g++-32_developer-build_Ubuntu_10.04_x86', 'qtbase', 'Qt5', 'state', 'dev', 'tst_qftp', 'na', 'qtbase', 'BuildKeyInStringFormat12345', 1), + array('linux-g++-32_developer-build_Ubuntu_10.04_x86', 'invalid', 'Qt5', 'state', '', '', '', '', '', 0), + array('invalid', 'qtbase', 'Qt5', 'state', '', '', '', '', '', 0) + ); + } + + /** * Test getDbRefreshed */ public function testGetDbRefreshed() diff --git a/non-puppet/qtmetrics2/src/test/FactoryTest.php b/non-puppet/qtmetrics2/src/test/FactoryTest.php index 6508397..cfc75bd 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.5 - * @since 01-07-2015 + * @version 0.6 + * @since 20-07-2015 * @author Juha Sippola */ @@ -167,6 +167,23 @@ class FactoryTest extends PHPUnit_Framework_TestCase } /** + * Test createConf + * @dataProvider testCreateConfData + */ + public function testCreateConf($conf, $runProject, $runState) + { + $conf = Factory::createConf($conf, $runProject, $runState); + $this->assertTrue($conf instanceof Conf); + $this->assertNotEmpty($conf->getStatus()); + } + public function testCreateConfData() + { + return array( + array('win32-msvc2010_developer-build_angle_Windows_7', 'Qt5', 'state',) + ); + } + + /** * Test createTestsets * @dataProvider testCreateTestsetsData */ @@ -310,7 +327,44 @@ class FactoryTest extends PHPUnit_Framework_TestCase array('tst_qftp', 'qtbase', 'Qt5', 'state', 'stable', '1348', 'win64-msvc2012_developer-build_qtnamespace_Windows_8', 1), array('tst_qfont', 'qtbase', 'Qt5', 'state', 'dev', 'BuildKeyInStringFormat12345', 'linux-g++-32_developer-build_Ubuntu_10.04_x86', 1), array('invalid', 'qtbase', 'Qt5', 'state', '', '', '', 0), - array('tst_qftp', 'invalid', 'Qt5', 'state', '', '', '', 0), + array('tst_qftp', 'invalid', 'Qt5', 'state', '', '', '', 0) + ); + } + + /** + * Test createTestsetRunsInConf + * @dataProvider testCreateTestsetRunsInConfData + */ + public function testCreateTestsetRunsInConf($conf, $testsetProject, $runProject, $runState, $exp_branch, $exp_buildKey, $exp_testset, $has_data) + { + $branches = array(); + $buildKeys = array(); + $testsets = array(); + $runs = Factory::createTestsetRunsInConf($conf, $testsetProject, $runProject, $runState); + foreach($runs as $run) { + $this->assertTrue($run instanceof TestsetRun); + $branches[] = $run->getBranchName(); + $buildKeys[] = $run->getBuildKey(); + $testsets[] = $run->getName(); + } + if ($has_data) { + $this->assertContains($exp_branch, $branches); + $this->assertContains($exp_buildKey, $buildKeys); + $this->assertContains($exp_testset, $testsets); + } else { + $this->assertEmpty($runs); + } + } + public function testCreateTestsetRunsInConfData() + { + return array( + array('win64-msvc2012_developer-build_qtnamespace_Windows_8', '', 'Qt5', 'state', 'stable', '1348', 'tst_qftp', 1), + array('linux-g++-32_developer-build_Ubuntu_10.04_x86', '', 'Qt5', 'state', 'stable', 'BuildKeyInStringFormat12345', 'tst_qftp', 1), + array('invalid', '', 'Qt5', 'state', '', '', '', 0), + array('win64-msvc2012_developer-build_qtnamespace_Windows_8', 'qtbase', 'Qt5', 'state', 'stable', '1348', 'tst_qftp', 1), + array('linux-g++-32_developer-build_Ubuntu_10.04_x86', 'qtbase', 'Qt5', 'state', 'stable', 'BuildKeyInStringFormat12345', 'tst_qftp', 1), + array('linux-g++-32_developer-build_Ubuntu_10.04_x86', 'invalid', 'Qt5', 'state', '', '', '', 0), + array('invalid', 'qtbase', 'Qt5', 'state', '', '', '', 0) ); } |