Example #1
0
function get_labels_JSON_from_query_results($qry, &$response)
{
    $rows = pdo_all_rows_query($qry);
    if (count($rows) > 0) {
        $labels = array();
        foreach ($rows as $row) {
            $labels[] = $row['text'];
        }
        $response['labels'] = $labels;
    }
}
Example #2
0
 function testProcessSubmissionsTest()
 {
     $this->login();
     echo "CTEST_FULL_OUTPUT\n";
     echo "this->logfilename='{$this->logfilename}'\n";
     echo "this->url='{$this->url}'\n";
     $content = $this->get($this->url . "/cdash/processsubmissions.php");
     if (strpos($content, "projectid/argv[1] should be a number") === false) {
         $this->fail("'projectid/argv[1] should be a number' not found when expected");
         echo "content (1):\n{$content}\n";
         return 1;
     }
     $content = $this->get($this->url . "/cdash/processsubmissions.php?projectid=1");
     if (strpos($content, "Done with ProcessSubmissions") === false) {
         $this->fail("'Done with ProcessSubmissions' not found when expected");
         echo "content (2):\n{$content}\n";
         return 1;
     }
     echo "log file perms: [";
     echo substr(sprintf('%o', fileperms($this->logfilename)), -4) . "]\n";
     // Simulate the processsubmissions.php "been processing for a long time"
     // issue. (Add records that are in the "processing" state, but appear to
     // be "old"... And records *after* that in the "queued" state.)
     // Then validate that processsubmissions properly processes the old record
     // *and* the queued records.
     //
     $this->addFakeSubmissionRecords("1");
     // Launch the first instance of the processor process via curl and tell
     // it to take a long time by sleeping each time through its loop.
     // (With 6 fake records just added, it'll sleep for about 6 seconds,
     // 1 second for each time through its loop...)
     //
     $this->launchViaCurl("/cdash/processsubmissions.php?projectid=1&sleep_in_loop=1", 1);
     // Sleep for 2 seconds, and then try to process submissions synchronously
     // and simultaneously... (This one should go through the "can't acquire
     // lock" code path.)
     //
     echo "sleep(2)\n";
     sleep(2);
     $content = $this->get($this->url . "/cdash/processsubmissions.php?projectid=1");
     if (strpos($content, "Another process is already processing") === false) {
         $this->fail("'Another process is already processing' not found when expected");
         echo "content (3):\n{$content}\n";
         return 1;
     }
     // Now... sleep for 10 seconds before checking to see if all processing
     // is done:
     //
     echo "sleep(10)\n";
     sleep(10);
     if (!$this->allRecordsProcessed("1")) {
         $rows = pdo_all_rows_query("SELECT * FROM submission WHERE status<2");
         echo print_r($rows, true) . "\n";
         $this->fail("some records still not processed after call 1 processsubmissions.php");
         return 1;
     }
     // Done, right? Not quite.
     // Now add some more fake submissions, and add a fake, stale processing
     // lock, such that the processing code has to go through the "acquire
     // lock by assuming existing lock is dead, so steal it" chunk of code.
     //
     $this->addFakeSubmissionRecords("1");
     $this->addFakeStaleProcessingLock("1");
     $content = $this->get($this->url . "/cdash/processsubmissions.php?projectid=1");
     if (!$this->allRecordsProcessed("1")) {
         $rows = pdo_all_rows_query("SELECT * FROM submission WHERE status<2");
         echo print_r($rows, true) . "\n";
         $this->fail("some records still not processed after call 2 processsubmissions.php");
         echo "content (4):\n{$content}\n";
         return 1;
     }
     // Finally, execute the processsubmissions.php script by php command line
     // to get coverage of the chunk of code that processes command line args.
     //
     $this->addFakeSubmissionRecords("1");
     $this->addFakeStaleProcessingLock("1");
     $this->launchViaCommandLine(1);
     if (!$this->allRecordsProcessed("1")) {
         $rows = pdo_all_rows_query("SELECT * FROM submission WHERE status<2");
         echo print_r($rows, true) . "\n";
         $this->fail("some records still not processed after call 3 processsubmissions.php");
         return 1;
     }
     // Actually, with this test, we expect some errors to be logged in the
     // cdash.log file, so do not do this check:
     //
     //if(!$this->checkLog($this->logfilename))
     //  {
     //  return 1;
     //  }
     $this->pass("Passed");
     return 0;
 }
Example #3
0
$xml .= add_XML_value('percentcoverage', $percentcoverage);
$xml .= add_XML_value('percentagegreen', $threshold);
// Above this number of the coverage is green
$metricpass = $threshold / 100;
$xml .= add_XML_value('metricpass', $metricpass);
// Below this number of the coverage is red
$metricerror = 0.7 * ($threshold / 100);
$xml .= add_XML_value('metricerror', $metricerror);
// Only execute the label-related queries if labels are being
// displayed:
//
if ($projectdisplaylabels) {
    // Get the set of labels involved:
    //
    $labels = array();
    $covlabels = pdo_all_rows_query('SELECT DISTINCT id, text FROM label, label2coveragefile WHERE ' . 'label.id=label2coveragefile.labelid AND ' . 'label2coveragefile.buildid=' . qnum($buildid));
    foreach ($covlabels as $row) {
        $labels[$row['id']] = $row['text'];
    }
    // For each label, compute the percentcoverage for files with
    // that label:
    //
    if (count($labels) > 0) {
        $xml .= '<labels>';
        foreach ($labels as $id => $label) {
            $row = pdo_single_row_query('SELECT COUNT(*) AS c, SUM(loctested) AS loctested, SUM(locuntested) AS locuntested ' . 'FROM label2coveragefile, coverage WHERE ' . 'label2coveragefile.labelid=' . qnum($id) . ' AND ' . 'label2coveragefile.buildid=' . qnum($buildid) . ' AND ' . 'coverage.buildid=label2coveragefile.buildid AND ' . 'coverage.fileid=label2coveragefile.coveragefileid');
            $loctested = $row['loctested'];
            $locuntested = $row['locuntested'];
            $percentcoverage = compute_percentcoverage($loctested, $locuntested);
            $xml .= '<label>';
            $xml .= add_XML_value('name', $label);
Example #4
0
function echo_project_data_sizes()
{
    echo "<h3>Project Data Sizes</h3>";
    echo "All sizes measured in millions of bytes<br/>";
    $sep = ', ';
    $sql = "SELECT p.name, SUM(LENGTH(t.output)+LENGTH(t.details)+LENGTH(t.command)+LENGTH(t.path)+LENGTH(t.name)) AS testsize " . "FROM project AS p, test AS t " . "WHERE p.id=t.projectid " . "GROUP BY p.name";
    $rows = pdo_all_rows_query($sql);
    echo '<pre>';
    echo 'project name, test size' . "\n";
    echo "\n";
    foreach ($rows as $row) {
        echo $row['name'] . $sep . $row['testsize'] / 1000000 . "\n";
    }
    echo '</pre>';
    echo '<br/>';
    $sql = "SELECT p.name, SUM(LENGTH(cov.log)) AS covsize " . "FROM project AS p, build AS b, coveragefilelog AS cov " . "WHERE p.id=b.projectid AND b.id=cov.buildid " . "GROUP BY p.name";
    $rows = pdo_all_rows_query($sql);
    echo '<pre>';
    echo 'project name, coverage size' . "\n";
    echo "\n";
    foreach ($rows as $row) {
        echo $row['name'] . $sep . $row['covsize'] / 1000000 . "\n";
    }
    echo '</pre>';
    echo '<br/>';
    $sql = "SELECT p.name, SUM(LENGTH(da.log)) AS dasize " . "FROM project AS p, build AS b, dynamicanalysis AS da " . "WHERE p.id=b.projectid AND b.id=da.buildid " . "GROUP BY p.name";
    $rows = pdo_all_rows_query($sql);
    echo '<pre>';
    echo 'project name, dynamic analysis size' . "\n";
    echo "\n";
    foreach ($rows as $row) {
        echo $row['name'] . $sep . $row['dasize'] / 1000000 . "\n";
    }
    echo '</pre>';
    echo '<br/>';
}
Example #5
0
function DeleteOldSubmissionRecords($projectid)
{
    global $CDASH_ASYNC_EXPIRATION_TIME;
    $delete_time = gmdate(FMT_DATETIMESTD, time() - $CDASH_ASYNC_EXPIRATION_TIME);
    $ids = pdo_all_rows_query("SELECT id FROM submission WHERE " . "(status=2 OR status=3 OR status=4 OR status=5) AND " . "projectid='{$projectid}' AND finished<'{$delete_time}' AND " . "finished!='1980-01-01 00:00:00'");
    $count = count($ids);
    if (0 == $count) {
        // Nothing to delete!
        return;
    }
    $idset = "(";
    foreach ($ids as $id_row) {
        $id = $id_row["id"];
        $idset .= "'{$id}', ";
    }
    // Avoid conditional ", " emission in the loop. OK to repeat an
    // element in this DELETE IN type of query:
    $idset .= "'" . $ids[0]["id"] . "')";
    pdo_delete_query("DELETE FROM submission WHERE id IN " . $idset);
    pdo_delete_query("DELETE FROM client_jobschedule2submission WHERE submissionid IN " . $idset);
    pdo_delete_query("DELETE FROM submission2ip WHERE submissionid IN " . $idset);
}
Example #6
0
function get_updates_xml_from_commits($projectname, $projectid, $dates, $commits)
{
    $xml = "<updates>\n";
    $xml .= "<timestamp>" . date(FMT_DATETIMETZ, $dates['nightly-0']) . "</timestamp>";
    // Get revision numbers for the current day and "the last time it ran before that..."
    // Only works if the LIMIT 2 query below returns exactly 2 records and the date from
    // the most recent record matches the current 'nightly-0' date... If those criteria
    // are not met, the revision strings will be empty and no revision information will
    // be displayed on the resulting web page.
    //
    $revision_current = '';
    $revision_prior = '';
    $qry = "SELECT date, revision FROM dailyupdate " . "WHERE projectid='{$projectid}' " . "  AND date <= '" . gmdate(FMT_DATE, $dates['nightly-0']) . "' " . "ORDER BY date DESC LIMIT 2";
    $rows = pdo_all_rows_query($qry);
    if (count($rows) == 2) {
        if ($rows[0]['date'] == gmdate(FMT_DATE, $dates['nightly-0'])) {
            $revision_current = $rows[0]['revision'];
            $revision_prior = $rows[1]['revision'];
        }
    }
    $xml .= add_XML_value("revision", $revision_current);
    $xml .= add_XML_value("priorrevision", $revision_prior);
    $xml .= add_XML_value("revisionurl", get_revision_url($projectid, $revision_current, $revision_prior));
    $xml .= add_XML_value("revisiondiff", get_revision_url($projectid, $revision_prior, ''));
    // no prior prior revision...
    $xml .= "<javascript>\n";
    // Args to dbAdd : "true" means directory, "false" means file
    //
    $xml .= "dbAdd(true, \"Updated files  (" . count($commits) . ")\", \"\", 0, \"\", \"1\", \"\", \"\", \"\", \"\", \"\")\n";
    $previousdir = "";
    usort($commits, "sort_by_directory_file_time");
    $projecturl = get_project_property($projectname, "cvsurl");
    foreach ($commits as $commit) {
        $directory = $commit['directory'];
        if ($directory != $previousdir) {
            $xml .= "dbAdd(true, \"" . $directory . "\", \"\", 1, \"\", \"1\", \"\", \"\", \"\", \"\", \"\")\n";
            $previousdir = $directory;
        }
        $filename = $commit['filename'];
        $revision = '';
        if ($commit['priorrevision'] != "-1") {
            $revision = $commit['revision'];
        }
        $time = gmdate(FMT_DATETIME, strtotime($commit['time']));
        $author = $commit['author'];
        // Only display email if the user is logged in
        if (isset($_SESSION['cdash'])) {
            if (isset($commit['email'])) {
                $email = $commit['email'];
            } else {
                $email = get_author_email($projectname, $author);
            }
        } else {
            // If the author is an email (git for instance) we remove everything after the @
            $posat = strpos($author, '@');
            if ($posat !== false) {
                $author = substr($author, 0, $posat);
            }
            $email = "";
        }
        $comment = $commit['comment'];
        $comment = str_replace("\n", " ", $comment);
        // Do this twice so that <something> ends up as
        // &amp;lt;something&amp;gt; because it gets sent to a
        // java script function not just displayed as html
        $comment = XMLStrFormat($comment);
        $comment = XMLStrFormat($comment);
        $diff_url = get_diff_url(get_project_id($projectname), $projecturl, $directory, $filename, $revision);
        $diff_url = XMLStrFormat($diff_url);
        $xml .= "dbAdd(false, \"" . $filename . "  Revision: " . $revision . "\",\"" . $diff_url . "\",2,\"\",\"1\",\"" . $author . "\",\"" . $email . "\",\"" . $comment . "\",\"" . $commit['bugurl'] . "\",\"" . $commit['bugid'] . "\",\"" . $commit['bugpos'] . "\")\n";
    }
    $xml .= "</javascript>\n";
    $xml .= "</updates>";
    return $xml;
}