summaryrefslogtreecommitdiffstats
path: root/non-puppet/qtmetrics2/src
diff options
context:
space:
mode:
Diffstat (limited to 'non-puppet/qtmetrics2/src')
-rw-r--r--non-puppet/qtmetrics2/src/Database.php64
-rw-r--r--non-puppet/qtmetrics2/src/Factory.php11
-rw-r--r--non-puppet/qtmetrics2/src/test/DatabaseTest.php42
-rw-r--r--non-puppet/qtmetrics2/src/test/FactoryTest.php14
4 files changed, 121 insertions, 10 deletions
diff --git a/non-puppet/qtmetrics2/src/Database.php b/non-puppet/qtmetrics2/src/Database.php
index bc4fea6..33b77b8 100644
--- a/non-puppet/qtmetrics2/src/Database.php
+++ b/non-puppet/qtmetrics2/src/Database.php
@@ -34,7 +34,7 @@
/**
* Database class
- * @since 21-09-2015
+ * @since 22-09-2015
* @author Juha Sippola
*/
@@ -871,6 +871,68 @@ class Database {
}
/**
+ * Get counts of blacklisted passed testfunctions for a testset in specified builds since specified date
+ * Only the testfunctions that are blacklisted, are only passed and have been run since the specified date are listed
+ * @param string $testset
+ * @param string $project
+ * @param string $runProject
+ * @param string $runState
+ * @param string $date
+ * @return array (string name, string testset, string project, string conf, int bpassed, int btotal)
+ */
+ public function getTestfunctionsBlacklistedPassedCountsTestset($testset, $project, $runProject, $runState, $date)
+ {
+ $result = array();
+ $query = $this->db->prepare("
+ SELECT
+ testfunction.name AS testfunction,
+ testset.name AS testset,
+ project.name AS project,
+ conf.name AS conf,
+ COUNT(CASE WHEN testfunction_run.result IN ('bpass', 'bxfail') THEN testfunction_run.result END) AS bpassed,
+ COUNT(CASE WHEN testfunction_run.result LIKE '%' THEN testfunction_run.result END) AS btotal
+ FROM testfunction_run
+ INNER JOIN testfunction ON testfunction_run.testfunction_id = testfunction.id
+ INNER JOIN testset_run ON testfunction_run.testset_run_id = testset_run.id
+ 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
+ INNER JOIN state ON project_run.state_id = state.id
+ WHERE
+ project_run.project_id = (SELECT id FROM project WHERE name = ?) AND
+ project_run.state_id = (SELECT id FROM state WHERE name = ?) AND
+ testset.name = ? AND
+ project.name = ? AND
+ project_run.timestamp >= ? AND
+ branch.archived = 0
+ GROUP BY testfunction.name, testset.name, project.name, conf.name
+ ORDER BY project.name, testset.name, testfunction.name, conf.name;
+ ");
+ $query->bindParam(1, $runProject);
+ $query->bindParam(2, $runState);
+ $query->bindParam(3, $testset);
+ $query->bindParam(4, $project);
+ $query->bindParam(5, $date);
+ $query->execute();
+ while($row = $query->fetch(PDO::FETCH_ASSOC)) {
+ if ($row['bpassed'] === $row['btotal']) { // return only those where only bpasses
+ $result[] = array(
+ 'name' => $row['testfunction'],
+ 'testset' => $row['testset'],
+ 'project' => $row['project'],
+ 'conf' => $row['conf'],
+ 'bpassed' => $row['bpassed'],
+ 'btotal' => $row['btotal']
+ );
+ }
+ }
+ return $result;
+ }
+
+ /**
* Get project run data by branch
* @param string $runProject
* @param string $runState
diff --git a/non-puppet/qtmetrics2/src/Factory.php b/non-puppet/qtmetrics2/src/Factory.php
index bb4e7c5..7867154 100644
--- a/non-puppet/qtmetrics2/src/Factory.php
+++ b/non-puppet/qtmetrics2/src/Factory.php
@@ -34,7 +34,7 @@
/**
* Factory class
- * @since 21-09-2015
+ * @since 22-09-2015
* @author Juha Sippola
*/
@@ -284,11 +284,13 @@ class Factory {
* Create Testfunction objects for those in database (with either failed or bpassed counts)
* List is limited by date (since) and length, and for specified builds only
* @param int $listType
+ * @param string $testset
+ * @param string $project
* @param string $runProject
* @param string $runState
* @return array Testfunction objects
*/
- public static function createTestfunctions($listType, $runProject, $runState)
+ public static function createTestfunctions($listType, $testset, $project, $runProject, $runState)
{
$objects = array();
$ini = self::conf();
@@ -308,7 +310,10 @@ class Factory {
if ($listType === self::LIST_BPASSES) {
$days = intval($ini['blacklisted_pass_last_days']) - 1;
$since = self::getSinceDate($days);
- $dbEntries = self::db()->getTestfunctionsBlacklistedPassedCounts($runProject, $runState, $since);
+ if ($testset === '')
+ $dbEntries = self::db()->getTestfunctionsBlacklistedPassedCounts($runProject, $runState, $since);
+ else
+ $dbEntries = self::db()->getTestfunctionsBlacklistedPassedCountsTestset($testset, $project, $runProject, $runState, $since);
foreach($dbEntries as $entry) {
$obj = new Testfunction($entry['name'], $entry['testset'], $entry['project'], $entry['conf']);
$obj->setBlacklistedCounts($entry['bpassed'], $entry['btotal']);
diff --git a/non-puppet/qtmetrics2/src/test/DatabaseTest.php b/non-puppet/qtmetrics2/src/test/DatabaseTest.php
index 74e5cfa..d5e4ad5 100644
--- a/non-puppet/qtmetrics2/src/test/DatabaseTest.php
+++ b/non-puppet/qtmetrics2/src/test/DatabaseTest.php
@@ -38,7 +38,7 @@ 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
- * @since 21-09-2015
+ * @since 22-09-2015
* @author Juha Sippola
*/
@@ -678,6 +678,46 @@ class DatabaseTest extends PHPUnit_Framework_TestCase
}
/**
+ * Test getTestfunctionsBlacklistedPassedCountsTestset
+ * @dataProvider testGetTestfunctionsBlacklistedPassedCountsTestsetData
+ */
+ public function testGetTestfunctionsBlacklistedPassedCountsTestset($testset, $project, $runProject, $runState, $date, $exp_testfunction, $exp_excluded_testfunction, $exp_testfunction_count_min, $exp_bpassed_min)
+ {
+ $testfunctions = array();
+ $bpassed = 0;
+ $db = Factory::db();
+ $result = $db->getTestfunctionsBlacklistedPassedCountsTestset($testset, $project, $runProject, $runState, $date);
+ foreach($result as $row) {
+ $this->assertArrayHasKey('name', $row);
+ $this->assertArrayHasKey('testset', $row);
+ $this->assertArrayHasKey('project', $row);
+ $this->assertArrayHasKey('conf', $row);
+ $this->assertArrayHasKey('bpassed', $row);
+ $this->assertArrayHasKey('btotal', $row);
+ $this->assertEquals($row['btotal'], $row['bpassed']);
+ $testfunctions[] = $row['name'];
+ $bpassed += $row['bpassed'];
+ }
+ $this->assertGreaterThanOrEqual($exp_testfunction_count_min, count($testfunctions));
+ if ($exp_testfunction_count_min > 0) {
+ $this->assertNotEmpty($result);
+ $this->assertContains($exp_testfunction, $testfunctions);
+ $this->assertNotContains($exp_excluded_testfunction, $testfunctions);
+ $this->assertGreaterThanOrEqual($exp_bpassed_min, $bpassed);
+ }
+ }
+ public function testGetTestfunctionsBlacklistedPassedCountsTestsetData()
+ {
+ return array(
+ array('tst_qfont', 'qtbase', 'Qt5', 'state', '2013-05-01', 'lastResortFont', 'resetFont', 1, 1), // in test data lastResortFont has bpassed and resetFont doesn't
+ array('tst_qfont', 'qtbase', 'Qt5', 'state', '2013-05-01', 'lastResortFont', 'styleName', 1, 1), // in test data lastResortFont has bpassed and styleName has bskipped as well
+ array('tst_qftp', 'qtbase', 'Qt5', 'state', '2013-05-01', 'lastResortFont', 'styleName', 0, 0),
+ array('tst_qfont', 'qtbase', 'Qt5', 'state', '2013-05-29', '', '', 0, 0),
+ array('tst_qfont', 'qtbase', 'Qt5', 'state', '2999-05-29', '', '', 0, 0)
+ );
+ }
+
+ /**
* Test getProjectBuildsByBranch
* @dataProvider testGetProjectBuildsByBranchData
*/
diff --git a/non-puppet/qtmetrics2/src/test/FactoryTest.php b/non-puppet/qtmetrics2/src/test/FactoryTest.php
index 78408a5..96530f7 100644
--- a/non-puppet/qtmetrics2/src/test/FactoryTest.php
+++ b/non-puppet/qtmetrics2/src/test/FactoryTest.php
@@ -37,7 +37,7 @@ require_once(__DIR__.'/../Factory.php');
/**
* Factory unit test class
* @example To run (in qtmetrics root directory): php <path-to-phpunit>/phpunit.phar ./src/test
- * @since 21-09-2015
+ * @since 22-09-2015
* @author Juha Sippola
*/
@@ -285,9 +285,9 @@ class FactoryTest extends PHPUnit_Framework_TestCase
* Test createTestfunctions
* @dataProvider testCreateTestfunctionsData
*/
- public function testCreateTestfunctions($listType, $runProject, $runState)
+ public function testCreateTestfunctions($listType, $testset, $project, $runProject, $runState)
{
- $testfunctions = Factory::createTestfunctions($listType, $runProject, $runState);
+ $testfunctions = Factory::createTestfunctions($listType, $testset, $project, $runProject, $runState);
foreach($testfunctions as $testfunction) {
$this->assertTrue($testfunction instanceof Testfunction);
$result = $testfunction->getResultCounts();
@@ -304,8 +304,12 @@ class FactoryTest extends PHPUnit_Framework_TestCase
public function testCreateTestfunctionsData()
{
return array(
- array(Factory::LIST_FAILURES, 'Qt5', 'state'),
- array(Factory::LIST_BPASSES, 'Qt5', 'state')
+ array(Factory::LIST_FAILURES, 'tst_qfont', 'qtbase', 'Qt5', 'state'),
+ array(Factory::LIST_FAILURES, 'tst_qftp', 'qtbase', 'Qt5', 'state'),
+ array(Factory::LIST_FAILURES, '', '', 'Qt5', 'state'),
+ array(Factory::LIST_BPASSES, 'tst_qfont', 'qtbase', 'Qt5', 'state'),
+ array(Factory::LIST_BPASSES, 'tst_qftp', 'qtbase', 'Qt5', 'state'),
+ array(Factory::LIST_BPASSES, '', '', 'Qt5', 'state')
);
}