# | http://www.php.net/license/3_01.txt | # | If you did not receive a copy of the PHP license and are unable to | # | obtain it through the world-wide-web, please send a note to | # | license@php.net so we can mail you a copy immediately. | # +----------------------------------------------------------------------+ # | Author: Olivier Doucet <*****@*****.**> | # +----------------------------------------------------------------------+ # $Id$ $startTime = microtime(true); include "../include/functions.php"; include "../include/release-qa.php"; // sanitize if (!preg_match('@^[a-z0-9]{32}$@', $_GET['signature'])) { exit('Invalid signature'); } if (!is_valid_php_version($_GET['version'], $QA_RELEASES)) { exit('invalid version'); } $signature = $_GET['signature']; $version = $_GET['version']; $dbFile = dirname(__FILE__) . '/db/' . $version . '.sqlite'; $database = new SQLite3($dbFile, SQLITE3_OPEN_READONLY); if (!$database) { die("Error opening DB file: " . $database->lastErrorMsg()); } // GET infos from DB $query = 'SELECT reports.* FROM failed JOIN reports ON reports.id=failed.id_report WHERE signature=X\'' . $signature . '\''; $q = $database->query($query); $reportsArray = array(); while ($tab = $q->fetchArray(SQLITE3_ASSOC)) { $reportsArray[$tab['id']] = $tab;
/** * Insert PHP make test results in SQLite database * * The following structure must be used as first array : * [status] => enum(failed, success) * [version] => string - example: 5.4.1-dev * [userEmail] => mangled * [date] => unix timestamp * [phpinfo] => string - phpinfo() output (CLI) * [buildEnvironment] => build environment * [failedTest] => array: list of failed test. Example: array('/Zend/tests/declare_001.phpt') * [expectedFailedTest] => array of expected failed test (same format as failedTest) * [succeededTest] => array of successfull tests. Provided only when parsing ci.qa results (for now) * [tests] => array testName => array ( 'output' => string("Current output of test") 'diff' => string("Diff with expected output of this test") * @param array array to insert * @param array releases we accept (so that we don't accept a report that claims to be PHP 8.1 for example) * @return boolean success or not (for the moment, error leads to a call to 'exit;' ... not good I know) */ function insertToDb_phpmaketest($array, $QA_RELEASES = array()) { if (!is_array($array)) { // impossible to fetch data. We'll record this error later ... } else { if (strtolower($array['status']) == 'failed') { $array['status'] = 0; } elseif (strtolower($array['status']) == 'success') { $array['status'] = 1; } else { die('status unknown: ' . $array['status']); } if (!is_valid_php_version($array['version'], $QA_RELEASES)) { exit('invalid version'); } $dbFile = dirname(__FILE__) . '/db/' . $array['version'] . '.sqlite'; $queriesCreate = array('failed' => 'CREATE TABLE IF NOT EXISTS failed ( `id` integer PRIMARY KEY AUTOINCREMENT, `id_report` bigint(20) NOT NULL, `test_name` varchar(128) NOT NULL, `output` STRING NOT NULL, `diff` STRING NOT NULL, `signature` binary(16) NOT NULL )', 'expectedfail' => 'CREATE TABLE IF NOT EXISTS expectedfail ( `id` integer PRIMARY KEY AUTOINCREMENT, `id_report` bigint(20) NOT NULL, `test_name` varchar(128) NOT NULL )', 'success' => 'CREATE TABLE IF NOT EXISTS success ( `id` integer PRIMARY KEY AUTOINCREMENT, `id_report` bigint(20) NOT NULL, `test_name` varchar(128) NOT NULL )', 'reports' => 'CREATE TABLE IF NOT EXISTS reports ( id integer primary key AUTOINCREMENT, date datetime NOT NULL, status smallint(1) not null, nb_failed unsigned int(10) NOT NULL, nb_expected_fail unsigned int(10) NOT NULL, success unsigned int(10) NOT NULL, build_env STRING NOT NULL, phpinfo STRING NOT NULL, user_email varchar(64) default null )'); if (!file_exists($dbFile)) { //Create DB $dbi = new SQLite3($dbFile, SQLITE3_OPEN_READWRITE | SQLITE3_OPEN_CREATE); foreach ($queriesCreate as $table => $query) { $dbi->exec($query); if ($dbi->lastErrorCode() != '') { echo "ERROR when creating table " . $table . ": " . $dbi->lastErrorMsg() . "\n"; exit; } } $dbi->close(); } $dbi = new SQLite3($dbFile, SQLITE3_OPEN_READWRITE) or exit('cannot open DB to record results'); // handle tests with no success if (!isset($array['succeededTest'])) { $array['succeededTest'] = array(); } $query = "INSERT INTO `reports` (`id`, `date`, `status`, \n `nb_failed`, `nb_expected_fail`, `success`, `build_env`, `phpinfo`, user_email) VALUES (null, \n datetime(" . (int) $array['date'] . ", 'unixepoch', 'localtime'), \n " . (int) $array['status'] . ", \n " . count($array['failedTest']) . ", \n " . count($array['expectedFailedTest']) . ", \n " . count($array['succeededTest']) . ", \n ('" . $dbi->escapeString($array['buildEnvironment']) . "'), \n ('" . $dbi->escapeString($array['phpinfo']) . "'),\n " . (!$array['userEmail'] ? "NULL" : "'" . $dbi->escapeString($array['userEmail']) . "'") . "\n )"; $dbi->query($query); if ($dbi->lastErrorCode() != '') { echo "ERROR: " . $dbi->lastErrorMsg() . "\n"; exit; } $reportId = $dbi->lastInsertRowID(); foreach ($array['failedTest'] as $name) { if (substr($name, 0, 1) != '/') { $name = '/' . $name; } $test = $array['tests'][$name]; $query = "INSERT INTO `failed` \n (`id`, `id_report`, `test_name`, signature, `output`, `diff`) VALUES (null, \n '" . $reportId . "', '" . $name . "', \n X'" . md5($name . '__' . $test['diff']) . "',\n ('" . $dbi->escapeString($test['output']) . "'), ('" . $dbi->escapeString($test['diff']) . "'))"; @$dbi->query($query); if ($dbi->lastErrorCode() != '') { echo "ERROR when inserting failed test : " . $dbi->lastErrorMsg() . "\n"; exit; } } foreach ($array['expectedFailedTest'] as $name) { $query = "INSERT INTO `expectedfail` \n (`id`, `id_report`, `test_name`) VALUES (null, '" . $reportId . "', '" . $name . "')"; @$dbi->query($query); if ($dbi->lastErrorCode() != '') { echo "ERROR when inserting expected fail test : " . $dbi->lastErrorMsg() . "\n"; exit; } } foreach ($array['succeededTest'] as $name) { // sqlite files too big .. For the moment, keep only one success over time $res = $dbi->query('SELECT id, id_report FROM `success` WHERE test_name LIKE \'' . $dbi->escapeString($name) . '\''); if ($res->numColumns() > 0) { // hit ! do nothing atm } else { $query = "INSERT INTO `success` (`id`, `id_report`, `test_name`)\n VALUES (null, '" . $reportId . "', '" . $dbi->escapeString($name) . "')"; @$dbi->query($query); if ($dbi->lastErrorCode() != '') { echo "ERROR when inserting succeeded test : " . $dbi->lastErrorMsg() . "\n"; exit; } } } $dbi->close(); // remove cache if (file_exists($dbFile . '.cache')) { unlink($dbFile . '.cache'); } } return true; }