/** Add a new build */ function add_build($build, $clientscheduleid = 0) { require_once 'models/buildgroup.php'; if (!is_numeric($build->ProjectId) || !is_numeric($build->SiteId)) { return; } //add_log('subprojectname: '.$build->SubProjectName, 'add_build'); $buildid = $build->GetIdFromName($build->SubProjectName); if ($buildid > 0 && !$build->Append) { remove_build($buildid); } // Move this into a Build::SetAppend($append, $buildid) method: // if (!$build->Exists() && $build->Append && empty($build->Id)) { $build->Id = $buildid; } // Find the groupid $buildGroup = new BuildGroup(); $build->GroupId = $buildGroup->GetGroupIdFromRule($build); $build->Save(); // If the build is part of a subproject we link the update file if (isset($build->SubProjectName) && $build->SubProjectName != '') { require_once 'models/buildupdate.php'; $BuildUpdate = new BuildUpdate(); $BuildUpdate->BuildId = $build->Id; $BuildUpdate->AssociateBuild($build->SiteId, $build->Name, $build->GetStamp()); } if ($clientscheduleid != 0) { require_once 'models/clientjobschedule.php'; $ClientJobSchedule = new ClientJobSchedule(); $ClientJobSchedule->Id = $clientscheduleid; $ClientJobSchedule->AssociateBuild($build->Id); } return $build->Id; }
public function testImageComparison() { // Submit test data. if (!$this->submission('InsightExample', dirname(__FILE__) . '/data/ImageComparisonTest.xml')) { $this->fail('Failed to submit test data'); return 1; } // Get the images created by this test. $pdo = get_link_identifier()->getPdo(); $stmt = $pdo->query("SELECT b.id AS buildid, i.id AS imgid FROM build b\n JOIN build2test b2t ON (b2t.buildid=b.id)\n JOIN test2image t2i ON (b2t.testid=t2i.testid)\n JOIN image i ON (i.id=t2i.imgid)\n WHERE b.name='image_comparison'"); $imgids = array(); $buildid = 0; while ($row = $stmt->fetch()) { $buildid = $row['buildid']; $imgids[] = $row['imgid']; } $num_imgs = count($imgids); if ($num_imgs !== 3) { $this->fail("Expected 3 images, found {$num_imgs}"); } foreach ($imgids as $imgid) { $image = new Image(); $image->Id = $imgid; $image->Load(); if (imagecreatefromstring($image->Data) === false) { $this->fail("Image {$imgid} is corrupted"); } } remove_build($buildid); }
public function cleanup() { // Restore our configuration and delete the build that we created. $this->removeLineFromConfig($this->ConfigLine); if ($this->BuildId > 0) { remove_build($this->BuildId); } }
public function testTestHistory() { // Submit our testing data. $rep = dirname(__FILE__) . '/data/TestHistory'; if (!$this->submission('InsightExample', "{$rep}/Test_1.xml")) { $this->fail('Failed to submit Test_1.xml'); return 1; } if (!$this->submission('InsightExample', "{$rep}/Test_2.xml")) { $this->fail('Failed to submit Test_1.xml'); return 1; } // Get the IDs for the two builds that we just created. $result = pdo_query("SELECT id FROM build WHERE name='TestHistory'"); $num_builds = pdo_num_rows($result); if ($num_builds != 2) { $this->fail("Expected 2 builds, found {$num_builds}"); return 1; } $buildids = array(); while ($row = pdo_fetch_array($result)) { $buildids[] = $row['id']; } // Verify that testing history matches what we expect. $content = $this->connect($this->url . '/api/v1/viewTest.php?groupid=15&previous_builds=' . $buildids[1] . ',+' . $buildids[0] . '&projectid=5&tests%5B%5D=fails&tests%5B%5D=notrun&tests%5B%5D=flaky&tests%5B%5D=passes&time_begin=2015-11-16T01:00:00&time_end=2015-11-17T01:00:00'); $jsonobj = json_decode($content, true); $success = true; $error_message = ''; foreach ($jsonobj['tests'] as $test) { $history = $test['history']; if ($test['name'] == 'fails' && $history != 'Broken') { $error_message = "Expected history for test 'fails' to be 'Broken', instead found '{$history}'"; $success = false; } if ($test['name'] == 'notrun' && $history != 'Inactive') { $error_message = "Expected history for test 'notrun' to be 'Inactive', instead found '{$history}'"; $success = false; } if ($test['name'] == 'flaky' && $history != 'Unstable') { $error_message = "Expected history for test 'flaky' to be 'Unstable', instead found '{$history}'"; $success = false; } if ($test['name'] == 'passes' && $history != 'Stable') { $error_message = "Expected history for test 'passes' to be 'Stable', instead found '{$history}'"; $success = false; } } // Delete the builds that we created during this test. remove_build($buildids[0]); remove_build($buildids[1]); if ($success) { $this->pass('Test passed'); return 0; } else { $this->fail($error_message); return 1; } }
/** Remove the first builds that are at the beginning of the queue */ function removeFirstBuilds($projectid, $days, $maxbuilds, $force = false) { require 'config/config.php'; require_once 'include/pdo.php'; require_once 'include/common.php'; @set_time_limit(0); if (!$force && !isset($CDASH_AUTOREMOVE_BUILDS)) { return; } if (!$force && $CDASH_AUTOREMOVE_BUILDS != '1') { return; } if ($days < 2) { return; } // First remove the builds with the wrong date $currentdate = time() - 3600 * 24 * $days; $startdate = date(FMT_DATETIME, $currentdate); add_log('about to query for builds to remove', 'removeFirstBuilds'); $builds = pdo_query("SELECT id FROM build\n WHERE parentid IN (0, -1) AND\n starttime<'{$startdate}' AND\n projectid=" . qnum($projectid) . "\n ORDER BY starttime ASC LIMIT {$maxbuilds}"); add_last_sql_error('dailyupdates::removeFirstBuilds'); $buildids = array(); while ($builds_array = pdo_fetch_array($builds)) { $buildids[] = $builds_array['id']; } $s = 'removing old buildids for projectid: ' . $projectid; add_log($s, 'removeFirstBuilds'); echo ' -- ' . $s . "\n"; // for "interactive" command line feedback remove_build($buildids); // Remove any job schedules that are older than our cutoff date // and not due to repeat again. require_once 'models/constants.php'; require_once 'models/clientjobschedule.php'; $sql = 'SELECT scheduleid FROM client_job AS cj LEFT JOIN client_jobschedule AS cjs ON cj.scheduleid = cjs.id WHERE cj.status > ' . CDASH_JOB_RUNNING . "\n AND cjs.projectid={$projectid} AND cj.startdate < '{$startdate}'\n AND (cjs.repeattime = 0.00 OR\n (cjs.enddate < '{$startdate}' AND cjs.enddate != '1980-01-01 00:00:00'))"; $job_schedules = pdo_query($sql); while ($job_schedule = pdo_fetch_array($job_schedules)) { $ClientJobSchedule = new ClientJobSchedule(); $ClientJobSchedule->Id = $job_schedule['scheduleid']; $ClientJobSchedule->Remove(); } // Remove any jobs that are older than our cutoff date. // This occurs when a job schedule is set to continue repeating, but // some of its past runs are older than our autoremove threshold. require_once 'models/clientjob.php'; $sql = 'SELECT cj.id FROM client_job AS cj LEFT JOIN client_jobschedule AS cjs ON cj.scheduleid = cjs.id WHERE cj.status > ' . CDASH_JOB_RUNNING . "\n AND cjs.projectid={$projectid} AND cj.startdate < '{$startdate}'"; $jobs = pdo_query($sql); while ($job = pdo_fetch_array($jobs)) { $ClientJob = new ClientJob(); $ClientJob->Id = $job['id']; $ClientJob->Remove(); } }
public function testDynamicAnalysisSummaryGetsDeleted() { // Remove the builds we just created. remove_build($this->ParentId); // Verify that the dynamicanalysisssummary rows got deleted. $result = pdo_query("\n SELECT b.id, b.parentid, das.numdefects FROM build AS b\n INNER JOIN dynamicanalysissummary AS das ON (das.buildid=b.id)\n WHERE b.name = 'cross_subproject_DA_example'"); $num_builds = pdo_num_rows($result); if ($num_builds != 0) { $this->fail("Expected 0 builds after deletion, found {$num_builds}"); } $this->pass('Test passed'); }
public function testTarFirst() { $this->BuildId = 0; $success = true; $success &= $this->submitTar(); $success &= $this->submitXML(); $success &= $this->verifyResults(); if ($success) { $this->pass("Passed"); } remove_build($this->BuildId); return $success; }
public function testNoBackup() { // Enable config setting. $this->addLineToConfig($this->ConfigLine); // Submit XML file. $xml = dirname(__FILE__) . '/data/nobackup/Build.xml'; if (!$this->submission('InsightExample', $xml)) { $this->fail('failed to submit Build.xml'); return 1; } // Submit gcov.tar to test the 'PUT' submission path. $post_result = $this->post($this->url . '/submit.php', array('project' => 'InsightExample', 'build' => 'nobackup', 'site' => 'localhost', 'stamp' => '20161004-0500-Nightly', 'starttime' => '1475599870', 'endtime' => '1475599870', 'track' => 'Nightly', 'type' => 'GcovTar', 'datafilesmd5[0]=' => '5454e16948a1d58d897e174b75cc5633')); $post_json = json_decode($post_result, true); if ($post_json['status'] != 0) { $this->fail('POST returned ' . $post_json['status'] . ":\n" . $post_json['description'] . "\n"); return 1; } $buildid = $post_json['buildid']; if (!is_numeric($buildid) || $buildid < 1) { $this->fail("Expected positive integer for buildid, instead got {$buildid}"); return 1; } $puturl = $this->url . "/submit.php?type=GcovTar&md5=5454e16948a1d58d897e174b75cc5633&filename=gcov.tar&buildid={$buildid}"; $filename = dirname(__FILE__) . '/data/gcov.tar'; $put_result = $this->uploadfile($puturl, $filename); $put_json = json_decode($put_result, true); if ($put_json['status'] != 0) { $this->fail('PUT returned ' . $put_json['status'] . ":\n" . $put_json['description'] . "\n"); return 1; } // Make sure they were both parsed correctly. echo "Waiting for async processing (2 seconds)\n"; sleep(2); $pdo = get_link_identifier()->getPdo(); $stmt = $pdo->prepare('SELECT b.builderrors, cs.loctested FROM build b JOIN coveragesummary cs ON (cs.buildid=b.id) WHERE b.id=?'); $stmt->execute(array($buildid)); $row = $stmt->fetch(); if ($row['builderrors'] != 0) { $this->fail("Unexpected number of build errors found"); } if ($row['loctested'] < 1) { $this->fail("Unexpected number of loctested found"); } $this->checkLog($this->logfilename); // Cleanup $this->removeLineFromConfig($this->ConfigLine); remove_build($buildid); }
public function testExternalLinksFromTests() { // Submit our testing data. $file_to_submit = dirname(__FILE__) . '/data/ExternalLinksFromTests/Test.xml'; if (!$this->submission('InsightExample', $file_to_submit)) { $this->fail("Failed to submit {$file_to_submit}"); return 1; } // Get the IDs for the build and test that we just created. $result = pdo_single_row_query("SELECT id FROM build WHERE name = 'test_output_link'"); $buildid = $result['id']; $result = pdo_single_row_query("SELECT testid FROM build2test WHERE buildid={$buildid}"); $testid = $result['testid']; // Use the API to verify that our external link was parsed properly. $this->get($this->url . "/api/v1/testDetails.php?test={$testid}&build={$buildid}"); $content = $this->getBrowser()->getContent(); $jsonobj = json_decode($content, true); $measurement = array_pop($jsonobj['test']['measurements']); $success = true; $error_msg = ''; if ($measurement['name'] !== 'Interesting website') { $error_msg = "Expected name to be 'Interesting website', instead found " . $measurement['name']; $success = false; } if ($measurement['type'] !== 'text/link') { $error_msg = "Expected type to be 'text/link', instead found " . $measurement['type']; $success = false; } if ($measurement['value'] !== 'http://www.google.com') { $error_msg = "Expected value to be 'http://www.google.com', instead found " . $measurement['value']; $success = false; } // Delete the build that we created during this test. remove_build($buildid); if (!$success) { $this->fail($error_msg); return 1; } $this->pass('Tests passed'); return 0; }
public function onlyColumn($method) { // Submit our testing file. $rep = dirname(__FILE__) . '/data/HideColumns'; if (!$this->submission('InsightExample', "{$rep}/{$method}.xml")) { return false; } // Use our API to verify which columns will be displayed. $content = $this->connect($this->url . '/api/v1/index.php?project=InsightExample&date=2015-10-06'); $jsonobj = json_decode($content, true); $buildgroup = array_pop($jsonobj['buildgroups']); $retval = false; switch ($method) { case 'Update': if ($buildgroup['hasupdatedata'] == true && $buildgroup['hasconfiguredata'] == false && $buildgroup['hascompilationdata'] == false && $buildgroup['hastestdata'] == false) { $retval = true; } break; case 'Configure': if ($buildgroup['hasupdatedata'] == false && $buildgroup['hasconfiguredata'] == true && $buildgroup['hascompilationdata'] == false && $buildgroup['hastestdata'] == false) { $retval = true; } break; case 'Build': if ($buildgroup['hasupdatedata'] == false && $buildgroup['hasconfiguredata'] == false && $buildgroup['hascompilationdata'] == true && $buildgroup['hastestdata'] == false) { $retval = true; } break; case 'Test': if ($buildgroup['hasupdatedata'] == false && $buildgroup['hasconfiguredata'] == false && $buildgroup['hascompilationdata'] == false && $buildgroup['hastestdata'] == true) { $retval = true; } break; } // Remove the build that we just created. $buildid_results = pdo_single_row_query("SELECT id FROM build WHERE name='HideColumns'"); $buildid = $buildid_results['id']; remove_build($buildid); return $retval; }
public function testParallelSubmissions() { // Delete the existing Trilinos build. $row = pdo_single_row_query("SELECT id FROM build\n WHERE parentid=-1 AND\n projectid=(SELECT id FROM project WHERE name='Trilinos') AND\n name='Windows_NT-MSVC10-SERIAL_DEBUG_DEV' AND\n starttime BETWEEN '2011-07-22 00:00:00' AND '2011-07-22 23:59:59'"); remove_build($row['id']); // Disable submission processing so that the queue will accumulate. $this->addLineToConfig($this->DisableProcessingConfig); // Re-submit the Trilinos build. $begin = time(); $this->submitFiles('ActualTrilinosSubmission', true); echo 'Submission took ' . (time() - $begin) . " seconds.\n"; // Re-enable submission processing and enable parallel processing $this->removeLineFromConfig($this->DisableProcessingConfig); $this->addLineToConfig($this->ParallelProcessingConfig); // Submit another file to Trilinos to start the processing loop. $file = dirname(__FILE__) . '/data/SubProjectNextPrevious/Build_1.xml'; $this->submission('Trilinos', $file); // Wait for processing to complete. $todo = 999; $begin = time(); while ($todo > 0) { $row = pdo_single_row_query('SELECT count(1) AS todo FROM submission WHERE status=0 OR status=1'); $todo = $row['todo']; sleep(1); if (time() - $begin > 120) { $this->fail("Processing took longer than 120 seconds.\n"); break; } } echo 'Processing took ' . (time() - $begin) . " seconds.\n"; // Verify the results. $this->verifyResults(); // Clean up by reverting our config settings and deleting the // extra build that we created to trigger the processing. $this->removeLineFromConfig($this->ParallelProcessingConfig); $row = pdo_single_row_query("SELECT build.id FROM build\n WHERE build.parentid=-1 AND\n projectid=(SELECT id FROM project WHERE name='Trilinos') AND\n stamp='20110723-1515-Experimental'"); remove_build($row['id']); }
public function testBuildFailureDetails() { echo "1. testBuildFailureDetails\n"; // Submit our test data. $rep = dirname(__FILE__) . '/data/BuildFailureDetails'; if (!$this->submission('EmailProjectExample', "{$rep}/Build_1.xml")) { $this->fail('failed to submit Build_1.xml'); return 1; } if (!$this->submission('EmailProjectExample', "{$rep}/Build_2.xml")) { $this->fail('failed to submit Build_2.xml'); return 1; } // Get the buildids that we just created so we can delete them later. $buildids = array(); $buildid_results = pdo_query("SELECT id FROM build WHERE name='test_buildfailure'"); while ($buildid_array = pdo_fetch_array($buildid_results)) { $buildids[] = $buildid_array['id']; } // Verify 4 buildfailures, 2 builds, and 2 details. $count_query = "\n SELECT COUNT(DISTINCT bf.id) AS numfails,\n COUNT(DISTINCT bf.buildid) AS numbuilds,\n COUNT(DISTINCT bf.detailsid) AS numdetails\n FROM buildfailure AS bf\n LEFT JOIN build AS b ON (b.id=bf.buildid)\n WHERE b.name='test_buildfailure'"; $count_results = pdo_single_row_query($count_query); if ($count_results['numfails'] != 4) { $this->fail('Expected 4 buildfailures, found ' . $count_results['numfails']); return 1; } if ($count_results['numbuilds'] != 2) { $this->fail('Expected 2 builds, found ' . $count_results['numbuilds']); return 1; } if ($count_results['numdetails'] != 2) { $this->fail('Expected 2 buildfailuredetails, found ' . $count_results['numdetails']); return 1; } // Delete one of the builds. remove_build($buildids[0]); // Verify 2 buildfailures, 1 build, and 2 details. $count_results = pdo_single_row_query($count_query); if ($count_results['numfails'] != 2) { $this->fail('Expected 2 buildfailures, found ' . $count_results['numfails']); return 1; } if ($count_results['numbuilds'] != 1) { $this->fail('Expected 1 build, found ' . $count_results['numbuilds']); return 1; } if ($count_results['numdetails'] != 2) { $this->fail('Expected 2 buildfailuredetails, found ' . $count_results['numdetails']); return 1; } // Delete the other build. remove_build($buildids[1]); // Verify that the rest of our data is now gone. $count_results = pdo_single_row_query($count_query); if ($count_results['numfails'] != 0) { $this->fail('Expected 0 buildfailures, found ' . $count_results['numfails']); return 1; } if ($count_results['numbuilds'] != 0) { $this->fail('Expected 0 builds, found ' . $count_results['numbuilds']); return 1; } if ($count_results['numdetails'] != 0) { $this->fail('Expected 0 buildfailuredetails, found ' . $count_results['numdetails']); return 1; } $this->pass('Test passed'); return 0; }
function remove_project_builds($projectid) { if (!is_numeric($projectid)) { return; } $build = pdo_query("SELECT id FROM build WHERE projectid='{$projectid}'"); $buildids = array(); while ($build_array = pdo_fetch_array($build)) { $buildids[] = $build_array["id"]; } remove_build($buildids); }
$builds = pdo_query("SELECT id,name,starttime FROM build WHERE starttime<'1975-12-31 23:59:59' OR starttime>'{$forwarddate}'"); while ($builds_array = pdo_fetch_array($builds)) { $buildid = $builds_array["id"]; echo $builds_array['name'] . "-" . $builds_array['starttime'] . "<br>"; } } /** Delete the builds with wrong date */ if ($DeleteBuildsWrongDate) { $currentdate = time() + 3600 * 24 * 3; // or 3 days away from now $forwarddate = date(FMT_DATETIME, $currentdate); $builds = pdo_query("SELECT id FROM build WHERE starttime<'1975-12-31 23:59:59' OR starttime>'{$forwarddate}'"); while ($builds_array = pdo_fetch_array($builds)) { $buildid = $builds_array["id"]; //echo $buildid."<br>"; remove_build($buildid); } } if ($FixBuildBasedOnRule) { // loop through the list of build2group $buildgroups = pdo_query("SELECT * from build2group"); while ($buildgroup_array = pdo_fetch_array($buildgroups)) { $buildid = $buildgroup_array["buildid"]; $build = pdo_query("SELECT * from build WHERE id='{$buildid}'"); $build_array = pdo_fetch_array($build); $type = $build_array["type"]; $name = $build_array["name"]; $siteid = $build_array["siteid"]; $projectid = $build_array["projectid"]; $submittime = $build_array["submittime"]; $build2grouprule = pdo_query("SELECT b2g.groupid FROM build2grouprule AS b2g, buildgroup as bg\n WHERE b2g.buildtype='{$type}' AND b2g.siteid='{$siteid}' AND b2g.buildname='{$name}'\n AND (b2g.groupid=bg.id AND bg.projectid='{$projectid}')\n AND '{$submittime}'>b2g.starttime AND ('{$submittime}'<b2g.endtime OR b2g.endtime='1980-01-01 00:00:00')");
public function testSubProjectNextPrevious() { // Submit our testing data. This sets up three days of data for the // Didasko subproject. // // Build_3.xml creates a build of Mesquite. The purpose of this is // to keep the 'Current' link honest. This test will fail if the // underlying functionality ignores the subproject & finds the // most recently submitted build instead. $filesToSubmit = array('Build_1.xml', 'Configure_1.xml', 'Notes_1.xml', 'Test_1.xml', 'Build_2.xml', 'Configure_2.xml', 'Notes_2.xml', 'Test_2.xml', 'Build_3.xml'); $dir = dirname(__FILE__) . '/data/SubProjectNextPrevious'; foreach ($filesToSubmit as $file) { if (!$this->submission('Trilinos', "{$dir}/{$file}")) { $this->fail("Failed to submit {$file}"); return 1; } } // Get the ids for the three subsequent builds of Didasko. $result = pdo_query("\n SELECT b.id FROM build AS b\n LEFT JOIN subproject2build AS sp2b ON sp2b.buildid=b.id\n LEFT JOIN subproject AS sp ON sp.id = sp2b.subprojectid\n WHERE sp.name = 'Didasko'\n ORDER BY b.starttime"); $num_rows = pdo_num_rows($result); if ($num_rows != 3) { $this->fail("Expected 3 rows, found {$num_rows}"); return 1; } $buildids = array(); while ($row = pdo_fetch_array($result)) { $buildids[] = $row['id']; } $first_buildid = $buildids[0]; $second_buildid = $buildids[1]; $third_buildid = $buildids[2]; // Verify the relevant pages have the correct links for // Previous, Next, and Current. $success = true; $error_msg = ''; $old_style_pages = array('viewConfigure', 'viewUpdate'); $new_style_pages = array('buildSummary', 'viewBuildError', 'viewNotes'); foreach ($old_style_pages as $page) { $this->get($this->url . "/{$page}.php?buildid=" . $first_buildid); $content = $this->getBrowser()->getContent(); if ($content == false) { $error_msg = "Error retrieving content from {$page}.php"; $success = false; break; } // Verify 'Next' from build #1 points to build #2 $pattern = "#<a href=\"[a-zA-Z.]+\\?buildid={$second_buildid}\">\\s*Next\\s*</a>#"; if (preg_match($pattern, $content) !== 1) { $error_msg = "Expected 'Next' link not found on {$page} for {$first_buildid}"; $success = false; break; } // Verify 'Current' from build #1 points to build #3 $pattern = "#<a href=\"[a-zA-Z.]+\\?buildid={$third_buildid}\">\\s*Current\\s*</a>#"; if (preg_match($pattern, $content) !== 1) { $error_msg = "Expected 'Current' link not found on {$page} for {$first_buildid}"; $success = false; break; } $this->get($this->url . "/{$page}.php?buildid=" . $second_buildid); $content = $this->getBrowser()->getContent(); if ($content == false) { $error_msg = "Error retrieving content from {$page}.php"; $success = false; break; } // Verify 'Previous' from build #2 points to build #1 $pattern = "#<a href=\"[a-zA-Z.]+\\?buildid={$first_buildid}\">\\s*Previous\\s*</a>#"; if (preg_match($pattern, $content) !== 1) { $error_msg = "Expected 'Previous' link not found on {$page} for {$second_buildid}"; $success = false; break; } // Verify 'Next' from build #2 points to build #3 $pattern = "#<a href=\"[a-zA-Z.]+\\?buildid={$third_buildid}\">\\s*Next\\s*</a>#"; if (preg_match($pattern, $content) !== 1) { $error_msg = "Expected 'Next' link not found on {$page} for {$second_buildid}"; $success = false; break; } // Verify 'Current' from build #2 points to build #3 $pattern = "#<a href=\"[a-zA-Z.]+\\?buildid={$third_buildid}\">\\s*Current\\s*</a>#"; if (preg_match($pattern, $content) !== 1) { $error_msg = "Expected 'Current' link not found on {$page} for {$second_buildid}"; $success = false; break; } $this->get($this->url . "/{$page}.php?buildid=" . $third_buildid); $content = $this->getBrowser()->getContent(); if ($content == false) { $error_msg = "Error retrieving content from {$page}.php"; $success = false; break; } // Verify 'Previous' from build #3 points to build #2 $pattern = "#<a href=\"[a-zA-Z.]+\\?buildid={$second_buildid}\">\\s*Previous\\s*</a>#"; if (preg_match($pattern, $content) !== 1) { $error_msg = "Expected 'Previous' link not found on {$page} for {$third_buildid}"; $success = false; break; } } foreach ($new_style_pages as $page) { $this->get($this->url . "/api/v1/{$page}.php?buildid=" . $first_buildid); $content = $this->getBrowser()->getContent(); $jsonobj = json_decode($content, true); // Verify 'Next' from build #1 points to build #2 if (strpos($jsonobj['menu']['next'], "buildid={$second_buildid}") === false) { $error_msg = "Expected 'Next' link not found on {$page} for {$first_buildid}"; $success = false; break; } // Verify 'Current' from build #1 points to build #3 if (strpos($jsonobj['menu']['current'], "buildid={$third_buildid}") === false) { $error_msg = "Expected 'Current' link not found on {$page} for {$first_buildid}"; $success = false; break; } $this->get($this->url . "/api/v1/{$page}.php?buildid=" . $second_buildid); $content = $this->getBrowser()->getContent(); $jsonobj = json_decode($content, true); // Verify 'Previous' from build #2 points to build #1 if (strpos($jsonobj['menu']['previous'], "buildid={$first_buildid}") === false) { $error_msg = "Expected 'Previous' link not found on {$page} for {$second_buildid}"; $success = false; break; } // Verify 'Next' from build #2 points to build #3 if (strpos($jsonobj['menu']['next'], "buildid={$third_buildid}") === false) { $error_msg = "Expected 'Next' link not found on {$page} for {$second_buildid}"; $success = false; break; } // Verify 'Current' from build #2 points to build #3 if (strpos($jsonobj['menu']['current'], "buildid={$third_buildid}") === false) { $error_msg = "Expected 'Current' link not found on {$page} for {$second_buildid}"; $success = false; break; } $this->get($this->url . "/api/v1/{$page}.php?buildid=" . $third_buildid); $content = $this->getBrowser()->getContent(); $jsonobj = json_decode($content, true); // Verify 'Previous' from build #3 points to build #2 if (strpos($jsonobj['menu']['previous'], "buildid={$second_buildid}") === false) { $error_msg = "Expected 'Previous' link not found on {$page} for {$third_buildid}"; $success = false; break; } } // Make sure that the parent builds link to each other correctly. $result = pdo_single_row_query("SELECT parentid FROM build WHERE id={$first_buildid}"); $first_parentid = $result['parentid']; $result = pdo_single_row_query("SELECT parentid FROM build WHERE id={$second_buildid}"); $second_parentid = $result['parentid']; $result = pdo_single_row_query("SELECT parentid FROM build WHERE id={$third_buildid}"); $third_parentid = $result['parentid']; $this->get($this->url . "/api/v1/index.php?project=Trilinos&parentid={$first_parentid}"); $content = $this->getBrowser()->getContent(); $jsonobj = json_decode($content, true); // Verify 'Next' from parent #1 points to parent #2 if (strpos($jsonobj['menu']['next'], "parentid={$second_parentid}") === false) { $error_msg = "Expected 'Next' link not found for first parent build"; $success = false; } // Verify 'Current' from parent #1 points to parent #3 if (strpos($jsonobj['menu']['current'], "parentid={$third_parentid}") === false) { $error_msg = "Expected 'Current' link not found for first parent build"; $success = false; } $this->get($this->url . "/api/v1/index.php?project=Trilinos&parentid={$second_parentid}"); $content = $this->getBrowser()->getContent(); $jsonobj = json_decode($content, true); // Verify 'Previous' from parent #2 points to parent #1 if (strpos($jsonobj['menu']['previous'], "parentid={$first_parentid}") === false) { $error_msg = "Expected 'Previous' link not found for second parent build"; $success = false; } // Verify 'Next' from parent #2 points to parent #3 if (strpos($jsonobj['menu']['next'], "parentid={$third_parentid}") === false) { $error_msg = "Expected 'Next' link not found for second parent build"; $success = false; } // Verify 'Current' from parent #2 points to parent #3 if (strpos($jsonobj['menu']['current'], "parentid={$third_parentid}") === false) { $error_msg = "Expected 'Current' link not found for second parent build"; $success = false; } $this->get($this->url . "/api/v1/index.php?project=Trilinos&parentid={$third_parentid}"); $content = $this->getBrowser()->getContent(); $jsonobj = json_decode($content, true); // Verify 'Previous' from parent #3 points to parent #2 if (strpos($jsonobj['menu']['previous'], "parentid={$second_parentid}") === false) { $error_msg = "Expected 'Previous' link not found for third parent build"; $success = false; } // Make sure that a build is not displayed when it does not // contain any of the whitelisted SubProjects. $this->get($this->url . '/api/v1/index.php?project=Trilinos&date=2011-07-23&filtercount=1&showfilters=1&field1=subprojects&compare1=93&value1=Teuchos'); $content = $this->getBrowser()->getContent(); $jsonobj = json_decode($content, true); $num_buildgroups = count($jsonobj['buildgroups']); if ($num_buildgroups !== 0) { $error_msg = "Expected 0 BuildGroups while whitelisting, found {$num_buildgroups}"; $success = false; } // Make sure that a build is not displayed when all of its // SubProjects have been blacklisted away. $this->get($this->url . '/api/v1/index.php?project=Trilinos&date=2011-07-23&filtercount=1&showfilters=1&field1=subprojects&compare1=92&value1=Didasko'); $content = $this->getBrowser()->getContent(); $jsonobj = json_decode($content, true); $num_buildgroups = count($jsonobj['buildgroups']); if ($num_buildgroups !== 0) { $error_msg = "Expected 0 BuildGroups while blacklisting, found {$num_buildgroups}"; $success = false; } // Make sure that the reported number of labels does not // change when an irrelevant blacklist criterion is added. $this->get($this->url . '/api/v1/index.php?project=Trilinos&date=2011-07-23&filtercount=1&showfilters=1&field1=subprojects&compare1=92&value1=Teuchos'); $content = $this->getBrowser()->getContent(); $jsonobj = json_decode($content, true); $buildgroup = array_pop($jsonobj['buildgroups']); $label = $buildgroup['builds'][0]['label']; if ($label !== 'Didasko') { $error_msg = "Expected label 'Didasko', found {$label}"; $success = false; } // Test the 'last clean build' feature. $this->get("{$this->url}/api/v1/build.php?buildid={$third_parentid}&getproblems=1"); $content = $this->getBrowser()->getContent(); $jsonobj = json_decode($content, true); if ($jsonobj['hasErrors'] !== true) { $error_msg = "Expected 'hasErrors' to be true"; $success = false; } if ($jsonobj['hasFailingTests'] !== false) { $error_msg = "Expected 'hasFailingTests' to be false"; $success = false; } if ($jsonobj['daysWithErrors'] !== 1) { $error_msg = "Expected 'daysWithErrors' to be 1, found " . $jsonobj['daysWithErrors']; $success = false; } if ($jsonobj['failingDate'] !== '2011-07-23') { $error_msg = "Expected 'failingDate' to be '2011-07-23', found " . $jsonobj['failingDate']; $success = false; } // Make sure the 'type' parameter is preserved across Previous/Next/Current // on viewBuildError.php. $this->get($this->url . "/api/v1/viewBuildError.php?type=1&buildid={$second_buildid}"); $content = $this->getBrowser()->getContent(); $jsonobj = json_decode($content, true); if (strpos($jsonobj['menu']['next'], "type=1") === false) { $error_msg = "type=1 not found in Next link of viewBuildError.php"; $success = false; } if (strpos($jsonobj['menu']['previous'], "type=1") === false) { $error_msg = "type=1 not found in Previous link of viewBuildError.php"; $success = false; } if (strpos($jsonobj['menu']['current'], "type=1") === false) { $error_msg = "type=1 not found in Current link of viewBuildError.php"; $success = false; } // Delete the builds that we created during this test. remove_build($second_parentid); remove_build($third_parentid); if (!$success) { $this->fail($error_msg); return 1; } $this->pass('Tests passed'); return 0; }
public function testBuildRemovalWorksAsExpected() { require_once 'include/common.php'; require_once 'include/pdo.php'; require_once 'models/build.php'; require_once 'models/buildconfigure.php'; require_once 'models/builderror.php'; require_once 'models/buildfailure.php'; require_once 'models/buildgroup.php'; require_once 'models/buildnote.php'; require_once 'models/buildupdate.php'; require_once 'models/coverage.php'; require_once 'models/dynamicanalysis.php'; require_once 'models/dynamicanalysissummary.php'; require_once 'models/image.php'; require_once 'models/label.php'; require_once 'models/test.php'; require_once 'models/uploadfile.php'; $time = gmdate(FMT_DATETIME); // Find an existing site. $row = pdo_single_row_query('SELECT id FROM site LIMIT 1'); $siteid = $row['id']; // Label $label = new Label(); $label->SetText('remove me'); // Build $build = new Build(); $build->Name = 'RemovalWorksAsExpected'; $build->SetStamp('20160822-1810-Experimental'); $build->ProjectId = 1; $build->InsertErrors = true; $build->SiteId = $siteid; $build->StartTime = $time; $build->EndTime = $time; $build->SubmitTime = $time; $build->AddLabel($label); $buildgroup = new BuildGroup(); $build->GroupId = $buildgroup->GetGroupIdFromRule($build); $info = new BuildInformation(); $info->SetValue('OSNAME', 'Windows'); $build->Information = $info; // BuildError $error = new BuildError(); $error->Text = 'error: asdf'; $build->AddError($error); // BuildFailure $failure = new BuildFailure(); $failure->StdError = 'failure: asdf'; $failure->AddArgument('arg1'); $failure->AddLabel($label); $build->AddError($failure); $build->Save(); // Create another build to test shared resources. $existing_build = new Build(); $existing_build->Id = $build->Id; $existing_build->FillFromId($build->Id); $existing_build->SetStamp('20160822-1811-Experimental'); $existing_build->SubmitTime = $time; $existing_build->InsertErrors = true; $existing_build->AddError($failure); $existing_build->Id = null; $existing_build->Save(); // BuildConfigure $configure = new BuildConfigure(); $configure->BuildId = $build->Id; $configure->StartTime = $time; $configure->EndTime = $time; $configure->Command = 'cmake'; $configure->Log = "precontext\nWARNING: bar\npostcontext"; $configure->Status = 5; $configure->AddLabel($label); $configure->Insert(); $configure->ComputeWarnings(); $configure->ComputeErrors(); // BuildNote $note = new BuildNote(); $note->Name = 'my note'; $note->Text = 'note text'; $note->Time = $time; $note->BuildId = $build->Id; $note->Insert(); $shared_note = new BuildNote(); $shared_note->Name = 'my shared note'; $shared_note->Text = 'shared note text'; $shared_note->Time = $time; $shared_note->BuildId = $build->Id; $shared_note->Insert(); $shared_note->BuildId = $existing_build->Id; $shared_note->Insert(); // buildtesttime $build->SaveTotalTestsTime(8); // BuildUpdate $updatefile = new BuildUpdateFile(); $updatefile->Author = 'My Self'; $updatefile->Committer = 'My Self'; $updatefile->Email = '*****@*****.**'; $updatefile->CommitterEmail = '*****@*****.**'; $updatefile->Revision = 2; $updatefile->PriorRevision = 1; $updatefile->Filename = 'foo.cpp'; $updatefile->Status = 'MODIFIED'; $update = new BuildUpdate(); $update->AddFile($updatefile); $update->BuildId = $build->Id; $update->StartTime = $time; $update->EndTime = $time; $update->Command = 'git fetch'; $update->Insert(); pdo_query("INSERT INTO build2update (buildid, updateid)\n VALUES ({$existing_build->Id}, {$update->UpdateId})"); // Coverage $file1 = new CoverageFile(); $file1->FullPath = '/path/to/unshared.php'; $file1->File .= "this unshared line gets covered<br>"; $file1->File .= "this unshared line does not<br>"; $coverage1 = new Coverage(); $coverage1->Covered = 1; $coverage1->CoverageFile = $file1; $coverage1->LocTested = 1; $coverage1->LocUntested = 1; $coverage1->AddLabel($label); $file2 = new CoverageFile(); $file2->FullPath = '/path/to/shared.php'; $file2->File .= "this shared line gets covered<br>"; $file2->File .= "this shared line does not<br>"; $coverage2 = new Coverage(); $coverage2->Covered = 1; $coverage2->CoverageFile = $file2; $coverage2->LocTested = 1; $coverage2->LocUntested = 1; $coverage2->AddLabel($label); $summary = new CoverageSummary(); $summary->BuildId = $build->Id; $summary->AddCoverage($coverage1); $summary->AddCoverage($coverage2); $summary->Insert(true); $file1->TrimLastNewline(); $file1->Update($build->Id); $log1 = new CoverageFileLog(); $log1->AddLine(1, 1); $log1->BuildId = $build->Id; $log1->FileId = $file1->Id; $log1->Insert(true); $file2->TrimLastNewline(); $file2->Update($build->Id); $log2 = new CoverageFileLog(); $log2->AddLine(1, 1); $log2->BuildId = $build->Id; $log2->FileId = $file2->Id; $log2->Insert(true); // Also add coverage to existing build to test that shared files // do not get deleted. $existing_cov = new Coverage(); $existing_cov->Covered = 1; $existing_cov->CoverageFile = $file2; $existing_cov->LocTested = 1; $existing_cov->LocUntested = 1; $existing_cov->AddLabel($label); $existing_summary = new CoverageSummary(); $existing_summary->BuildId = $existing_build->Id; $existing_summary->AddCoverage($existing_cov); $existing_summary->Insert(true); $file2->Update($existing_build->Id); $existing_log = new CoverageFileLog(); $existing_log->AddLine(1, 1); $existing_log->BuildId = $existing_build->Id; $existing_log->FileId = $file2->Id; $existing_log->Insert(true); // DynamicAnalysis $DA_defect = new DynamicAnalysisDefect(); $DA_defect->Type = 'Potential Memory Leak'; $DA_defect->Value = 5; $DA = new DynamicAnalysis(); $DA->BuildId = $build->Id; $DA->Checker = 'Valgrind'; $DA->FullCommandLine = 'php DA_removebuilds.php'; $DA->Log = 'build removed successfully'; $DA->Name = 'removal test'; $DA->Path = '/path/to/removal/DA'; $DA->Status = 'failed'; $DA->AddDefect($DA_defect); $DA->AddLabel($label); $DA->Insert(); $DA_summary = new DynamicAnalysisSummary(); $DA_summary->BuildId = $build->Id; $DA_summary->Checker = 'Valgrind'; $DA_summary->AddDefects($DA_defect->Value); $DA_summary->Insert(); // Test $test = new Test(); $test->ProjectId = 1; $test->CompressedOutput = false; $test->Details = 'Completed'; $test->Name = 'removal test'; $test->Path = '/path/to/removal/test'; $test->Command = 'php test_removebuilds.php'; $test->Output = 'build removed successfully'; $measurement = new TestMeasurement(); $measurement->Name = 'Exit Value'; $measurement->Type = 'text/string'; $measurement->Value = 5; $test->AddMeasurement($measurement); $image = new Image(); $image->Extension = 'image/png'; $image->Data = 'iVBORw0KGgoAAAANSUhEUgAAABwAAAASCAMAAAB/2U7WAAAABl' . 'BMVEUAAAD///+l2Z/dAAAASUlEQVR4XqWQUQoAIAxC2/0vXZDr' . 'EX4IJTRkb7lobNUStXsB0jIXIAMSsQnWlsV+wULF4Avk9fLq2r' . '8a5HSE35Q3eO2XP1A1wQkZSgETvDtKdQAAAABJRU5ErkJggg=='; $image->Name = 'remove_me.png'; $test->AddImage($image); $test->Insert(); $buildtest = new BuildTest(); $buildtest->BuildId = $build->Id; $buildtest->TestId = $test->Id; $buildtest->Status = 'passed'; $buildtest->Insert(); $test->AddLabel($label); $test->InsertLabelAssociations($build->Id); $test2 = new Test(); $test2->ProjectId = 1; $test2->CompressedOutput = false; $test2->Details = 'Completed'; $test2->Name = 'shared test'; $test2->Path = '/path/to/shared/test'; $test2->Command = 'php test_sharedtest.php'; $test2->Output = 'test shared successfully'; $measurement2 = new TestMeasurement(); $measurement2->Name = 'Exit Value'; $measurement2->Type = 'text/string'; $measurement2->Value = 0; $test2->AddMeasurement($measurement2); $image2 = new Image(); $image2->Extension = 'image/gif'; $image2->Name = 'smile.gif'; $image2->Data = base64_encode(file_get_contents(dirname(__FILE__) . '/data/smile.gif')); $test2->AddImage($image2); $test2->Insert(); $buildtest2 = new BuildTest(); $buildtest2->BuildId = $build->Id; $buildtest2->TestId = $test2->Id; $buildtest2->Status = 'passed'; $buildtest2->Insert(); $buildtest2->BuildId = $existing_build->Id; $buildtest2->Insert(); $test2->AddLabel($label); $test2->InsertLabelAssociations($build->Id); // UploadFile $filename = dirname(__FILE__) . '/data/smile.gif'; $upload1 = new UploadFile(); $upload1->Filename = $filename; $upload1->IsUrl = false; $upload1->BuildId = $build->Id; $upload1->Sha1Sum = sha1_file($filename); $upload1->Filesize = filesize($filename); $upload1->Insert(); $filename = dirname(__FILE__) . '/data/smile2.gif'; $upload2 = new UploadFile(); $upload2->Filename = $filename; $upload2->IsUrl = false; $upload2->BuildId = $build->Id; $upload2->Sha1Sum = sha1_file($filename); $upload2->Filesize = filesize($filename); $upload2->Insert(); $upload2->BuildId = $existing_build->Id; $upload2->Insert(); // Various tables that are too hard to spoof with models so we resort // to direct insertion. pdo_query("INSERT INTO buildemail (userid, buildid, category)\n VALUES (1, {$build->Id}, 0)"); pdo_query("INSERT INTO builderrordiff\n (buildid, type, difference_positive, difference_negative)\n VALUES ({$build->Id}, 0, 1, 1)"); pdo_query("INSERT INTO configureerrordiff (buildid, type, difference)\n VALUES ({$build->Id}, 0, 1)"); pdo_query("INSERT INTO coveragesummarydiff (buildid, loctested, locuntested)\n VALUES ({$build->Id}, 1, 1)"); pdo_query("INSERT INTO summaryemail (buildid, date, groupid)\n VALUES ({$build->Id}, '{$time}', 1)"); pdo_query("INSERT INTO subproject2build (subprojectid, buildid)\n VALUES (1, {$build->Id})"); pdo_query("INSERT INTO testdiff\n (buildid, type, difference_positive, difference_negative)\n VALUES ({$build->Id}, 0, 1, 1)"); // Check that everything was created successfully. $this->verify('build', 'id', '=', $build->Id, 1); $this->verify('build2group', 'buildid', '=', $build->Id, 1); $this->verify('buildemail', 'buildid', '=', $build->Id, 1); $this->verify('builderror', 'buildid', '=', $build->Id, 1); $this->verify('builderrordiff', 'buildid', '=', $build->Id, 1); $this->verify('buildinformation', 'buildid', '=', $build->Id, 1); $this->verify('buildtesttime', 'buildid', '=', $build->Id, 1); $this->verify('configure', 'buildid', '=', $build->Id, 1); $this->verify('configureerror', 'buildid', '=', $build->Id, 1); $this->verify('configureerrordiff', 'buildid', '=', $build->Id, 1); $this->verify('coveragesummary', 'buildid', '=', $build->Id, 1); $this->verify('coveragesummarydiff', 'buildid', '=', $build->Id, 1); $this->verify('coveragefilelog', 'buildid', '=', $build->Id, 2); $this->verify('dynamicanalysissummary', 'buildid', '=', $build->Id, 1); $this->verify('summaryemail', 'buildid', '=', $build->Id, 1); $this->verify('subproject2build', 'buildid', '=', $build->Id, 1); $this->verify('testdiff', 'buildid', '=', $build->Id, 1); list($buildfailureid, $detailsid) = $this->verify_get_columns('buildfailure', ['id', 'detailsid'], 'buildid', '=', $build->Id, 1); $this->verify('buildfailure2argument', 'buildfailureid', '=', $buildfailureid, 1); $this->verify('buildfailuredetails', 'id', '=', $detailsid, 1); $noteids = $this->verify_get_rows('build2note', 'noteid', 'buildid', '=', $build->Id, 2); $this->verify('note', 'id', 'IN', $noteids, 2); $coveragefileids = $this->verify_get_rows('coverage', 'fileid', 'buildid', '=', $build->Id, 2); $this->verify('coveragefile', 'id', 'IN', $coveragefileids, 2); $dynamicanalysisid = $this->verify_get_rows('dynamicanalysis', 'id', 'buildid', '=', $build->Id, 1); $this->verify('dynamicanalysisdefect', 'dynamicanalysisid', '=', $dynamicanalysisid, 1); $testids = $this->verify_get_rows('build2test', 'testid', 'buildid', '=', $build->Id, 2); $this->verify('test', 'id', 'IN', $testids, 2); $this->verify('testmeasurement', 'testid', 'IN', $testids, 2); $imgids = $this->verify_get_rows('test2image', 'imgid', 'testid', 'IN', $testids, 2); $this->verify('image', 'id', 'IN', $imgids, 2); $updateid = $this->verify_get_rows('build2update', 'updateid', 'buildid', '=', $build->Id, 1); $this->verify('buildupdate', 'id', '=', $updateid, 1); $this->verify('updatefile', 'updateid', '=', $updateid, 1); $uploadfileids = $this->verify_get_rows('build2uploadfile', 'fileid', 'buildid', '=', $build->Id, 2); $this->verify('uploadfile', 'id', 'IN', $uploadfileids, 2); $labelid = $this->verify_get_rows('label2build', 'labelid', 'buildid', '=', $build->Id, 1); $this->verify('label', 'id', '=', $labelid, 1); $this->verify('label2buildfailure', 'labelid', '=', $labelid, 2); $this->verify('label2coveragefile', 'labelid', '=', $labelid, 3); $this->verify('label2dynamicanalysis', 'labelid', '=', $labelid, 1); $this->verify('label2test', 'labelid', '=', $labelid, 2); // Remove the build. remove_build($build->Id); // Check that everything was deleted properly. $this->verify('build', 'id', '=', $build->Id, 0, true); $this->verify('build2group', 'buildid', '=', $build->Id, 0, true); $this->verify('build2note', 'buildid', '=', $build->Id, 0, true); $this->verify('build2test', 'buildid', '=', $build->Id, 0, true); $this->verify('build2update', 'buildid', '=', $build->Id, 0, true); $this->verify('build2uploadfile', 'buildid', '=', $build->Id, 0, true); $this->verify('buildemail', 'buildid', '=', $build->Id, 0, true); $this->verify('builderror', 'buildid', '=', $build->Id, 0, true); $this->verify('builderrordiff', 'buildid', '=', $build->Id, 0, true); $this->verify('buildfailure', 'buildid', '=', $build->Id, 0, true); $this->verify('buildfailure2argument', 'buildfailureid', '=', $buildfailureid, 0, true); $this->verify('buildfailuredetails', 'id', '=', $detailsid, 1, true); $this->verify('buildinformation', 'buildid', '=', $build->Id, 0, true); $this->verify('buildtesttime', 'buildid', '=', $build->Id, 0, true); $this->verify('buildupdate', 'id', '=', $updateid, 1, true); $this->verify('configure', 'buildid', '=', $build->Id, 0, true); $this->verify('configureerror', 'buildid', '=', $build->Id, 0, true); $this->verify('configureerrordiff', 'buildid', '=', $build->Id, 0, true); $this->verify('coverage', 'buildid', '=', $build->Id, 0, true); $this->verify('coveragefile', 'id', 'IN', $coveragefileids, 1, true); $this->verify('coveragefilelog', 'buildid', '=', $build->Id, 0, true); $this->verify('coveragesummary', 'buildid', '=', $build->Id, 0, true); $this->verify('coveragesummarydiff', 'buildid', '=', $build->Id, 0, true); $this->verify('dynamicanalysis', 'buildid', '=', $build->Id, 0, true); $this->verify('dynamicanalysissummary', 'buildid', '=', $build->Id, 0, true); $this->verify('dynamicanalysisdefect', 'dynamicanalysisid', '=', $dynamicanalysisid, 0, true); $this->verify('image', 'id', 'IN', $imgids, 1, true); $this->verify('label2build', 'buildid', '=', $build->Id, 0, true); $this->verify('label2buildfailure', 'labelid', '=', $labelid, 1, true); $this->verify('label2coveragefile', 'labelid', '=', $labelid, 1, true); $this->verify('label2dynamicanalysis', 'labelid', '=', $labelid, 0, true); $this->verify('label2test', 'labelid', '=', $labelid, 0, true); $this->verify('note', 'id', 'IN', $noteids, 1, true); $this->verify('summaryemail', 'buildid', '=', $build->Id, 0, true); $this->verify('subproject2build', 'buildid', '=', $build->Id, 0, true); $this->verify('test', 'id', 'IN', $testids, 1, true); $this->verify('test2image', 'testid', 'IN', $testids, 1, true); $this->verify('testdiff', 'buildid', '=', $build->Id, 0, true); $this->verify('testmeasurement', 'testid', 'IN', $testids, 1, true); $this->verify('updatefile', 'updateid', '=', $updateid, 1, true); $this->verify('uploadfile', 'id', 'IN', $uploadfileids, 1, true); }
public function testCleanup() { // Delete users created by this test. foreach ($this->Users as $user) { $user->Delete(); } // Delete builds. $pdo = get_link_identifier()->getPdo(); $stmt = $pdo->prepare("SELECT id FROM build WHERE name='GithubUserStats'"); $stmt->execute(); while ($row = $stmt->fetch()) { remove_build($row['id']); } // Delete project. $this->deleteProject($this->ProjectId); }
function rest_delete() { global $buildid; add_log('Build #' . $buildid . ' removed manually', 'buildAPI'); remove_build($buildid); }
while ($projects_array = pdo_fetch_array($projects)) { $xml .= '<availableproject>'; $xml .= add_XML_value('id', $projects_array['id']); $xml .= add_XML_value('name', $projects_array['name']); if ($projects_array['id'] == $projectid) { $xml .= add_XML_value('selected', '1'); } $xml .= '</availableproject>'; } $xml .= '<dayFrom>' . $dayFrom . '</dayFrom>'; $xml .= '<monthFrom>' . $monthFrom . '</monthFrom>'; $xml .= '<yearFrom>' . $yearFrom . '</yearFrom>'; $xml .= '<dayTo>' . $dayTo . '</dayTo>'; $xml .= '<monthTo>' . $monthTo . '</monthTo>'; $xml .= '<yearTo>' . $yearTo . '</yearTo>'; @($submit = $_POST['Submit']); // Delete the builds if (isset($submit)) { $begin = $yearFrom . '-' . $monthFrom . '-' . $dayFrom . ' 00:00:00'; $end = $yearTo . '-' . $monthTo . '-' . $dayTo . ' 00:00:00'; $sql = 'SELECT id FROM build WHERE projectid=' . qnum($projectid) . " AND\n parentid IN (0, -1) AND starttime<='{$end}' AND starttime>='{$begin}'\n ORDER BY starttime ASC"; $build = pdo_query($sql); $builds = array(); while ($build_array = pdo_fetch_array($build)) { $builds[] = $build_array['id']; } remove_build($builds); $xml .= add_XML_value('alert', 'Removed ' . count($builds) . ' builds.'); } $xml .= '</cdash>'; generate_XSLT($xml, 'removeBuilds');
public function testFilterLabels() { // Submit our test data. $rep = dirname(__FILE__) . '/data/FilterTestLabels'; if (!$this->submission('EmailProjectExample', "{$rep}/Build_1.xml")) { $this->fail('failed to submit Update_1.xml'); return 1; } if (!$this->submission('EmailProjectExample', "{$rep}/Test_1.xml")) { $this->fail('failed to submit Update_2.xml'); return 1; } // Turn this option on. pdo_query("UPDATE project SET sharelabelfilters=1\n WHERE name='EmailProjectExample'"); // Get the buildid that we just created so we can delete it later. $buildids = array(); $buildid_results = pdo_query("SELECT id FROM build WHERE name='labeltest_build'"); while ($buildid_array = pdo_fetch_array($buildid_results)) { $buildids[] = $buildid_array['id']; } if (count($buildids) != 1) { foreach ($buildids as $id) { remove_build($id); } $this->fail('Expected 1 build, found ' . count($buildids)); return 1; } $buildid = $buildids[0]; $success = true; $error_msg = ""; // If any of these checks fail, the build still needs to be deleted try { // First, check number of tests with no filters $content = $this->connect($this->url . '/api/v1/index.php?project=EmailProjectExample&date=2011-07-23'); $jsonobj = json_decode($content, true); $buildgroup = array_pop($jsonobj['buildgroups']); if ($buildgroup['numtestnotrun'] != 23) { throw new Exception('Expected numtestnotrun=23, found numtestnotrun= ' . qnum($buildgroup['numtestnotrun'])); } if ($buildgroup['numtestfail'] != 2) { throw new Exception('Expected numtestfail=2, found numtestfail= ' . qnum($buildgroup['numtestfail'])); } if ($buildgroup['numtestpass'] != 5) { throw new Exception('Expected numtestpass=5, found numtestpass= '******'numtestpass'])); } // Now, add a filter $content = $this->connect($this->url . '/api/v1/index.php?project=EmailProjectExample&date=2011-07-23&filtercount=1&showfilters=1&field1=label&compare1=63&value1=SM'); $jsonobj = json_decode($content, true); $buildgroup = array_pop($jsonobj['buildgroups']); if ($buildgroup['numtestnotrun'] != 4) { throw new Exception('Expected numtestnotrun=4, found numtestnotrun= ' . qnum($buildgroup['numtestnotrun'])); } if ($buildgroup['numtestfail'] != 0) { throw new Exception('Expected numtestfail=0, found numtestfail= ' . qnum($buildgroup['numtestfail'])); } if ($buildgroup['numtestpass'] != 0) { throw new Exception('Expected numtestpass=0, found numtestpass= '******'numtestpass'])); } } catch (Exception $e) { $success = false; $error_msg = $e->getMessage(); } // Delete the build remove_build($buildid); // Turn the option back off. pdo_query("UPDATE project SET sharelabelfilters=0\n WHERE name='EmailProjectExample'"); if (!$success) { $this->fail($error_msg); return 1; } $this->pass('Tests passed'); return 0; }
public function testReplaceBuild() { $success = true; $error_msg = ''; // Submit the first test file. $rep = dirname(__FILE__) . '/data/ReplaceBuild'; if (!$this->submission('EmailProjectExample', "{$rep}/Build_1.xml")) { $this->fail('failed to submit Build_1.xml'); return 1; } // Verify details about the build that we just created. $row = pdo_single_row_query("SELECT id, generator FROM build WHERE name='ReplaceBuild'"); $first_buildid = $row['id']; $first_generator = $row['generator']; if ($first_generator !== 'ctest-3.0') { $error_msg = "Expected 'ctest-3.0', found '{$first_generator}'"; echo "{$error_msg}\n"; $success = false; } // Mark this build as ready for replacement. if (!pdo_query("UPDATE build SET done=1 WHERE id={$first_buildid}")) { $error_msg = 'UPDATE query returned false'; echo "{$error_msg}\n"; $success = false; } // Submit the second test file. if (!$this->submission('EmailProjectExample', "{$rep}/Build_2.xml")) { $error_msg = 'Failed to submit Build_2.xml'; echo "{$error_msg}\n"; $success = false; } // Make sure the first build doesn't exist anymore. if (!($query = pdo_query("SELECT * FROM build WHERE id={$first_buildid}"))) { $error_msg = 'SELECT query returned false'; echo "{$error_msg}\n"; $success = false; } $num_rows = pdo_num_rows($query); if ($num_rows !== 0) { $error_msg = "Expected 0 rows, found {$num_rows}"; echo "{$error_msg}\n"; $success = false; remove_build($first_buildid); } // Verify the replacement build. $row = pdo_single_row_query("SELECT id, generator FROM build WHERE name='ReplaceBuild'"); $second_buildid = $row['id']; $second_generator = $row['generator']; if ($second_generator !== 'ctest-3.1') { $error_msg = "Expected 'ctest-3.1', found '{$second_generator}'"; echo "{$error_msg}\n"; $success = false; } // Delete the build that we created during this test. remove_build($second_buildid); if ($success) { $this->pass('Test passed'); return 0; } else { $this->fail($error_msg); return 1; } }
public function testUpdateAppend() { echo "1. testUpdateAppend\n"; // Submit our test data. $rep = dirname(__FILE__) . '/data/UpdateAppend'; if (!$this->submission('EmailProjectExample', "{$rep}/Update_1.xml")) { $this->fail('failed to submit Update_1.xml'); return 1; } if (!$this->submission('EmailProjectExample', "{$rep}/Update_2.xml")) { $this->fail('failed to submit Update_2.xml'); return 1; } if (!$this->submission('EmailProjectExample', "{$rep}/Update_3.xml")) { $this->fail('failed to submit Update_3.xml'); return 1; } // Get the buildid that we just created so we can delete it later. $buildids = array(); $buildid_results = pdo_query("SELECT id FROM build WHERE name='test_updateappend'"); while ($buildid_array = pdo_fetch_array($buildid_results)) { $buildids[] = $buildid_array['id']; } if (count($buildids) != 1) { foreach ($buildids as $id) { remove_build($id); } $this->fail('Expected 1 build, found ' . count($buildids)); return 1; } $buildid = $buildids[0]; // Get the updateid associated with the build id $query = pdo_query('SELECT updateid FROM build2update WHERE buildid=' . qnum($buildid)); $query_array = pdo_fetch_array($query); $updateid = $query_array['updateid']; $build_query = pdo_query('SELECT * FROM buildupdate WHERE id=' . qnum($updateid)); $buildupdate_array = pdo_fetch_array($build_query); // Check that values have been updated correctly // If any of these checks fail, the build still needs to be deleted try { $success = true; if ($buildupdate_array['nfiles'] != 3) { throw new Exception('Expected nfiles=3, found nfiles= ' . qnum($buildupdate_array['nfiles'])); } if ($buildupdate_array['warnings'] != 1) { throw new Exception('Expected warnings=1, found warnings= ' . qnum($buildupdate_array['nwarnings'])); } // Note: UpdateType is only read from the first Update if ($buildupdate_array['type'] != 'GIT') { throw new Exception('Expected type=GIT, found type= ' . $buildupdate_array['type']); } // Note: Commands from all Updates are concatenated together if ($buildupdate_array['command'] != 'Command 1Command 2Command 3') { throw new Exception('Expected command=Command 1Command 2Command 3, found command= ' . $buildupdate_array['command']); } // Note: MDT = GMT - 6 if ($buildupdate_array['starttime'] != '2015-08-24 04:04:14') { throw new Exception('Expected starttime=GIT, found starttime= ' . $buildupdate_array['starttime']); } if ($buildupdate_array['endtime'] != '2015-08-24 04:20:30') { throw new Exception('Expected endtime=2015-08-24 04:20:30, found endtime= ' . $buildupdate_array['endtime']); } // Note: UpdateReturnStatus is overwritten with each update if ($buildupdate_array['status'] != '') { throw new Exception("Expected status='', found status= " . $buildupdate_array['status']); } // Note: Revision and PriorRevision are only read from the first Update AND // only IF they're under the <Update> tag (not in <Updated> or <Revisions>) if ($buildupdate_array['revision'] != 3) { throw new Exception('Expected revision=3, found revision= ' . $buildupdate_array['revision']); } if ($buildupdate_array['priorrevision'] != 2) { throw new Exception('Expected priorrevision=2, found priorrevision= ' . $buildupdate_array['priorrevision']); } // Note: Path is only read from the first Update if ($buildupdate_array['path'] != 'mypath') { throw new Exception('Expected path=mypath, found path= ' . $buildupdate_array['path']); } } catch (Exception $e) { $success = false; $error_message = $e->getMessage(); } // Delete the build remove_build($buildid); if ($success) { $this->pass('Test passed'); return 0; } else { $this->fail($error_message); return 1; } }
/** Remove this build if it exists and has been marked as done. * This is called by XML handlers when a new replacement * submission is received. **/ public function RemoveIfDone() { if (!$this->Exists() || !$this->GetDone()) { return false; } remove_build($this->Id); $this->Id = 0; return true; }
/** Remove any children of the given build. */ function remove_children($parentid) { $childids = array(); $child_result = pdo_query("SELECT id FROM build WHERE parentid={$parentid}"); while ($child_array = pdo_fetch_array($child_result)) { $childids[] = $child_array['id']; } if (!empty($childids)) { remove_build($childids); } }
public function __destruct() { foreach ($this->builds as $build) { remove_build($build['id']); } }
public function testViewTestReturnsProperFormatForParentBuilds() { if (!$this->submission('BuildDetails', $this->testDataDir . '/' . 'Insight_Experimental_Test_Subbuild.xml')) { $this->fail('Failed to submit ' . $testDataFile); return 1; } $buildId = pdo_single_row_query("SELECT id FROM build WHERE name = 'BuildDetails-Linux-g++-4.1-LesionSizingSandbox_Debug-has-subbuild' AND parentid=-1"); $response = json_decode($this->get($this->url . '/api/v1/viewTest.php?buildid=' . $buildId['id'])); $this->assertTrue($response->parentBuild); foreach ($response->tests as $test) { $this->assertTrue(property_exists($test, 'subprojectid')); $this->assertTrue($test->subprojectname == 'some-subproject'); } remove_build($buildId['id']); }