From: Sebastien D. <sde...@us...> - 2005-01-03 14:23:09
|
Update of /cvsroot/tslogparser/tslogparser/admin/modules In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv25792/admin/modules Modified Files: ltp.mod.php opts.mod.php readme.txt Log Message: Updated HISTORY, database, and opts module is able to parse a testsuite directory Index: opts.mod.php =================================================================== RCS file: /cvsroot/tslogparser/tslogparser/admin/modules/opts.mod.php,v retrieving revision 1.1 retrieving revision 1.2 diff -u -d -r1.1 -r1.2 --- opts.mod.php 31 Dec 2004 15:13:12 -0000 1.1 +++ opts.mod.php 3 Jan 2005 14:22:56 -0000 1.2 @@ -24,37 +24,32 @@ var $assertion; var $xml_parser; + var $debug=0; - function opts_xml_routines() - { - $this->assertion = array("cur"=>-1); - $this->xml_parser = xml_parser_create(); - xml_parser_set_option($this->xml_parser, XML_OPTION_CASE_FOLDING, true); - xml_set_element_handler($this->xml_parser, array($this, "startElement"), array($this, "endElement")); - xml_set_character_data_handler($this->xml_parser, array($this, "characterData")); - } - /* The functions below are used within the XML parser -- see PHP doc for more info */ function startElement($parser, $name, $attrs) { + if ($this->debug) + echo "startElement($name)\n"; if ($name == "ASSERTION") { - echo "startElement($name, ".$attrs["ID"].")\n"; $this->assertion["cur"]=$attrs["ID"]; $this->assertion[$attrs["ID"]]=""; } } - function endElement($name) + function endElement($parser, $name) { - echo "endElement($name)\n"; + if ($this->debug) + echo "endElement($name)\n"; if ($name == "ASSERTION") $this->assertion["cur"]=-1; } - function characterData($data) + function characterData($parser, $data) { - var_dump($data); + if ($this->debug) + echo $data; if (($this->assertion["cur"] != -1) && (trim($data))) $this->assertion[$this->assertion["cur"]] .= $data."\n"; } @@ -62,18 +57,38 @@ /* This function is called for each assertions.xml file */ function parse_assertions($file) { + /* Open the file for reading */ + if ($this->debug) + echo "Opening <i>$file</i>\n"; if (!($fp = fopen($file, "r"))) { die("could not open XML input"); } + /* Create the XML parser */ + $this->assertion = array("cur"=>-1); + $this->xml_parser = xml_parser_create(); + xml_set_object($this->xml_parser, $this); + xml_parser_set_option($this->xml_parser, XML_OPTION_CASE_FOLDING, true); + xml_set_element_handler($this->xml_parser, "startElement", "endElement"); + xml_set_character_data_handler($this->xml_parser, "characterData"); + + /* Parse the file */ while ($data = fread($fp, 4096)) { + if ($this->debug) + echo "Raw:<hr>".htmlentities($data)."<hr>\n"; if (!xml_parse($this->xml_parser, $data, feof($fp))) { die(sprintf("XML error: %s at line %d<br>\nin ".$file, xml_error_string(xml_get_error_code($this->xml_parser)), xml_get_current_line_number($this->xml_parser))); } } + + /* Clean up the XML parser */ + xml_parser_free($this->xml_parser); + unset($this->assertion["cur"]); + + /* return */ return $this->assertion; } } @@ -105,8 +120,8 @@ */ function TS_parse(&$parent, $TS_name, $TS_description, $path) { - echo "opts->TS_parse($TS_name, $TS_description, $path)\n"; - $releases=query_version(); + if ( $parent->debug ) + echo "opts->TS_parse($TS_name, $TS_description, $path)\n"; $xmlparser = new opts_xml_routines(); @@ -234,27 +249,288 @@ closedir($dh); /* We've parsed the whole tree */ - echo "<pre>\n"; - print_r($opts_tree); - echo "</pre>\n"; + if ($parent->debug > 1) + print_r($opts_tree); + + /* The database shall be initialized here */ + if (!is_db_init()) + { + $parent->last_error="Database was not initialized\n"; + return FALSE; + } + + /* Check no release with the same name already exist */ + $releases=query_version($TS_name, 1); + if ($releases) + { + $parent->last_error= "The release '$TS_name' is already in the database \n". + "<i>".stringFromDB($releases[$TS_name]["ver_comment"])."</i>\n"; + return FALSE; + } + + /* Now, compare the $opts_tree with the $current_asserts and build up the list of assertions + to be added to the database.*/ + + $current_routines=query_routines(); + + /* We start with looking for missing routines */ + $missing_routines=array(); + + /* browse the new release assertions */ + foreach ($opts_tree as $domain) + { + foreach ($domain as $routine=>$asserts) + { + /* If the routine name is missing from opts_routines table, we'll add it */ + if (!isset($current_routines[$routine])) + $missing_routines[]=$routine; + } + } + + if ($parent->debug > 1) + print_r($missing_routines); + + /* If any routine is missing, it must be added previously to further processing */ + if ($missing_routines) + { + echo "New routines are being added to the database...\n"; + $counter=0; + foreach ($missing_routines as $routine) + { + $sql = "INSERT INTO opts_routines ( rou_name, rou_comment ) " + ."VALUES ( ".stringToDB($routine)."," + .stringToDB("Added on ".date("F j, Y")." with release '$new_release_name'")." )"; + if ($parent->debug > 1) + echo htmlentities($sql)."<br>\n"; + if (db_execute_insert($sql)) + $counter++; + else + echo "Failed to add $routine to the database...\n"; + } + echo "Done. <b>$counter</b> routine have been added.\n\n"; + $current_routines=query_routines(); + } + + $current_asserts=query_all_asserts(); + $missing_assertions=array(); + + + /* browse the new release assertions */ + foreach ($opts_tree as $domain) + { + foreach ($domain as $routine=>$asserts) + { + /* Check if the routine is already in the database */ + if (!isset($current_asserts[$routine])) + { + if (!isset($current_routines[$routine])) + { + $parent->last_error="Internal script error: routine $routine was not added in 1st pass"; + return FALSE; + } + + /* We now schedule addition of the assertions for this routine, as none was already defined */ + foreach ($asserts["assertions"] as $id => $assert) + { + + $missing_assertions[]=array( + "routine"=>$routine, + "assert"=>$assert, + "oldid"=>$id); + } + } + else + { + foreach ($asserts["assertions"] as $id => $assert) + { + /* Check if this assertion text was already in the database */ + if(!in_array($assert, $current_asserts[$routine])) + $missing_assertions[]=array( + "routine"=>$routine, + "assert"=>$assert, + "oldid"=>$id); + } + } + } + } + if ($parent->debug > 1) + print_r($missing_assertions); + + /* If any assertion is missing, it must be added previously to further processing */ + if ($missing_assertions) + { + echo "New assertions are being added to the database...\n"; + $counter=0; + foreach ($missing_assertions as $assertion) + { + $sql = "INSERT INTO opts_assertions ( assert_routine, assert_text ) " + ."VALUES ( ".$current_routines[$assertion["routine"]]["routine_id"]."," + .stringToDB($assertion["assert"])." )"; + if ($parent->debug > 1) + echo htmlentities($sql)."<br>\n"; + if (db_execute_insert($sql)) + $counter++; + else + echo "Failed to add assertion ".$assertion["oldid"]." of ".$assertion["routine"]." to the database...\n"; + } + echo "Done. <b>$counter</b> assertions have been added.\n\n"; + $current_asserts=query_all_asserts(); + } + + /* OK, we can now create the new release of OPTS in the database */ + $sql="INSERT INTO opts_versions (ver_name, ver_comment) " + . "VALUES ( ".stringToDB($TS_name).", " + . stringToDB($TS_description)." )"; + if ($parent->debug > 1) + echo htmlentities($sql)."<br>\n"; + if (!db_execute_insert($sql)) + { + $parent->last_error= "Failed to insert new version in the database\n"; + return FALSE; + } + + /* We retrieve the new release uniqueID */ + $releases=query_version($TS_name, 1); + + if (!$releases) + { + $parent->last_error= "Internal error: the new OPTS version was not created\n"; + return FALSE; + } + if ($parent->debug > 1) + print_r($current_asserts); + + /* We can create the full release description */ + $release_description = array(); + $missing_test=0; + foreach ($opts_tree as $domain) + { + foreach ($domain as $routine=>$asserts) + { + if (!isset($current_asserts[$routine]) || !isset($current_routines[$routine])) + { + + $parent->last_error= "Internal script error: routine $routine was not added in 1st pass"; + return FALSE; + } + + /* We now schedule addition of the assertions for this routine, as none was already defined */ + foreach ($asserts["assertions"] as $id => $assert) + { + if (!isset($asserts["testcase"][$id])) + $missing_test++; + else + { + foreach ($asserts["testcase"][$id] as $number => $infos) + { + $release_description[]=array( + "descr_assert" => array_search($assert, $current_asserts[$routine]), + "descr_num_assert" => $id, + "descr_num_test" => $number, + "descr_info" => $infos); + } + unset($asserts["testcase"][$id]); + } + } + if (isset($asserts["testcase"])) + foreach($asserts["testcase"] as $id => $tcinfos) + echo "<b>Warning</b>, $routine's test $id-* has no matching assertions and therefore will be ignored.\n"; + } + } + + if ($missing_test) + echo "\n<i>Info:</i> $missing_test assertions are not tested.\n\n"; + + /* We've enough information now; we can create the release */ + reset($releases); + $rlstmp=current($releases); + $release_id=$rlstmp["ver_id"]; + + $counter=0; + foreach ($release_description as $testcase) + { + $sql = "INSERT INTO opts_version_descriptions " + ." (descr_version, descr_assert, descr_num_assert, descr_num_test, descr_info)" + ." VALUES (".$release_id.", " + .$testcase["descr_assert"].", " + .$testcase["descr_num_assert"].", " + .$testcase["descr_num_test"].", " + .stringToDB($testcase["descr_info"])." )"; + if ($parent->debug > 1) + echo htmlentities($sql)."<br>\n"; + if (db_execute_insert($sql)) + $counter++; + else + echo "Failed to execute: ".htmlentities($sql)."\n"; + } + + echo "<b><i>$counter testcases have been added</i></b>\n\n"; + echo "Process terminated.\n"; + return TRUE; } - function TS_delete($TS_id) + function TS_delete(&$parent, $TS_id) { - return false; + + if ( $parent->debug ) + echo "opts->TS_delete($TS_id)\n"; + + /* Check there is no run within this testsuite */ + $sql = "SELECT * from opts_run_results, opts_version_descriptions" + ." WHERE res_testcase=descr_id" + ." AND descr_version=".$TS_id; + if ($parent->debug > 1) + echo htmlentities($sql)."<br>\n"; + $tmp = db_execute_select($sql); + if ($tmp) + { + $parent->last_error="The testsuite contains runs -- cannot be deleted.\n Delete the runs first.\n"; + return FALSE; + } + + + /* Now, delete the testsuite description */ + $sql = "DELETE from opts_version_descriptions" + ." WHERE descr_version=".$TS_id; + + if ($parent->debug > 1) + echo htmlentities($sql)."<br>\n"; + $tmp = db_execute_insert($sql); + echo "$tmp rows deleted from opts_version_descriptions<br>\n"; + + /* and the testsuite name */ + $sql = "DELETE from opts_versions" + ." WHERE ver_id=".$TS_id; + + if ($parent->debug > 1) + echo htmlentities($sql)."<br>\n"; + $tmp = db_execute_insert($sql); + if ($tmp == 0) + { + $parent->last_error="No row deleted in opts_version\n"; + return FALSE; + } + if ($parent->debug > 1) + echo "$tmp rows deleted from opts_version<br>\n"; + + return true; } - function RUN_parse($RUN_name, $RUN_description, $TS_id, $CONTENT) + function RUN_parse(&$parent, $RUN_name, $RUN_description, $TS_id, &$CONTENT) { + if ( $parent->debug ) + echo "opts->RUN_parse($RUN_name, $RUN_description, $TS_id, ...".strlen($CONTENT)."c...)\n"; return false; } - function RUN_delete($RUN_id) + function RUN_delete(&$parent, $RUN_id) { + if ( $parent->debug ) + echo "opts->RUN_delete($RUN_id)\n"; return false; } } Index: ltp.mod.php =================================================================== RCS file: /cvsroot/tslogparser/tslogparser/admin/modules/ltp.mod.php,v retrieving revision 1.1 retrieving revision 1.2 diff -u -d -r1.1 -r1.2 --- ltp.mod.php 31 Dec 2004 15:13:12 -0000 1.1 +++ ltp.mod.php 3 Jan 2005 14:22:56 -0000 1.2 @@ -16,8 +16,9 @@ * Temple Place - Suite 330, Boston MA 02111-1307, USA. */ - /* This module is for use with the Open POSIX Test Suite. - Based on code from earlier TSLogParser releases. */ + /* This module is an exemple model for a new module. + Adapt it for your own needs and please submit your new modules + on the project mailing list. */ class ltp { function module_info() @@ -30,19 +31,19 @@ echo "<p>See the <a href='http://ltp.sourceforge.net/'>test suite homepage</a> for more information.</p>\n"; return; } - function TS_parse($TS_name, $TS_description, $path) + function TS_parse(&$parent, $TS_name, $TS_description, $path) { return $false; } - function TS_delete($TS_id) + function TS_delete(&$parent, $TS_id) { return $false; } - function RUN_parse($RUN_name, $RUN_description, $TS_id, $CONTENT) + function RUN_parse(&$parent, $RUN_name, $RUN_description, $TS_id, $CONTENT) { return $false; } - function RUN_delete($RUN_id) + function RUN_delete(&$parent, $RUN_id) { return $false; } Index: readme.txt =================================================================== RCS file: /cvsroot/tslogparser/tslogparser/admin/modules/readme.txt,v retrieving revision 1.1 retrieving revision 1.2 diff -u -d -r1.1 -r1.2 --- readme.txt 31 Dec 2004 15:13:12 -0000 1.1 +++ readme.txt 3 Jan 2005 14:22:56 -0000 1.2 @@ -1,2 +1,3 @@ Modules decription: -see file modules.inc.php for details \ No newline at end of file +see file modules.inc.php in parent directory for details + |