From: Sebastien D. <sde...@us...> - 2005-01-03 16:28:03
|
Update of /cvsroot/tslogparser/tslogparser/admin/modules In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv22310/admin/modules Modified Files: opts.mod.php Log Message: finalize opts module Index: opts.mod.php =================================================================== RCS file: /cvsroot/tslogparser/tslogparser/admin/modules/opts.mod.php,v retrieving revision 1.2 retrieving revision 1.3 diff -u -d -r1.2 -r1.3 --- opts.mod.php 3 Jan 2005 14:22:56 -0000 1.2 +++ opts.mod.php 3 Jan 2005 16:27:49 -0000 1.3 @@ -490,6 +490,22 @@ return FALSE; } + /* Check the testsuite is an OPTS one */ + $sql = "SELECT ver_module from opts_versions" + ." WHERE ver_id=".$TS_id; + if ($parent->debug > 1) + echo htmlentities($sql)."<br>\n"; + $tmp = db_execute_select($sql); + if (!$tmp) + { + $parent->last_error="The testsuite cannot be found in the database.\n"; + return FALSE; + } + if ($tmp[0]["ver_module"] != "opts") + { + $parent->last_error="The testsuite is not an OPTS -- cannot be deleted within the current module.\n"; + return FALSE; + } /* Now, delete the testsuite description */ $sql = "DELETE from opts_version_descriptions" @@ -523,7 +539,182 @@ { if ( $parent->debug ) echo "opts->RUN_parse($RUN_name, $RUN_description, $TS_id, ...".strlen($CONTENT)."c...)\n"; - return false; + + /* Check this TS id first */ + $sql = "SELECT ver_id, ver_name, ver_comment, ver_module FROM opts_versions WHERE ver_id=$TS_id"; + if ($parent->debug > 1) + echo htmlentities($sql)."<br>\n"; + $release = db_execute_select($sql); + if (!$release) + { + $parent->last_error="The provided testsuite ID was not found in database\n"; + return false; + } + if ($release[0]["ver_module"] != "opts") + { + $parent->last_error="This testsuite's ID is not of type Open POSIX Test Suite. Aborted.\n"; + return false; + } + + /* Check that run name is free */ + $sql = "SELECT run_id, run_name, run_comments FROM opts_run WHERE run_name LIKE ".stringToDB($RUN_name); + if ($parent->debug > 1) + echo htmlentities($sql)."<br>\n"; + $res = db_execute_select($sql); + if ($res) + { + $elem=$res[0]; + $parent->last_error ="The test run '$RUN_name' is already in the database\n"; + $parent->last_error.="<i>".stringFromDB($elem["run_comments"])."</i>\n"; + return false; + } + + /* The trick for parsing the logfile is matching with a perl regexp */ + $log_data=array(); + + $regexp = "/conformance\/" + ."\w+\/" /* definition, interface, ... */ + ."((sys\/)?" /* special case for headers <sys/...> */ + ."\w+)\/" /* routine name matching */ + ."(speculative\/)?" /* we also want speculative tests */ + ."(\d*)-(\d*):" /* test name */ + ."\s*(build|link|execution):" /* Status type */ + ."\s*(FAILED|PASS|SKIP|UNSUPPORTED|UNTESTED|HUNG|INTERRUPTED|UNRESOLVED)" /* status */ + ."\s*:*\s*/"; + $num_match = 7; /* This is the number of grouping directives in this regexp */ + + /* Actually parse the logfile */ + $temp_array=preg_split($regexp, $CONTENT, -1, PREG_SPLIT_DELIM_CAPTURE); + + if ( $parent->debug > 4 ) + print_r($temp_array); + + if (count($temp_array) % ($num_match+1) != 1) + { + $parent->last_error="Regexp match error.\nInvalid logfile format -- expecting opts."; + return false; + } + + /* See preg_split documentation for more information on the data here */ + for ($idx=1; isset($temp_array[$idx]); $idx+=($num_match+1)) + { + $log_data[]=array( + "routine" => $temp_array[$idx+0], + "assert_num" => $temp_array[$idx+3], + "test_num" => $temp_array[$idx+4], + "status" => $temp_array[$idx+5]." ".$temp_array[$idx+6], + "log" => $temp_array[$idx+7] + ); + } + /* free some resources */ + unset($CONTENT); + unset($temp_array); + if ( $parent->debug > 1 ) + print_r($log_data); + /* We're done with the file parsing. */ + + /* Next step is to eliminate duplicates and match testcases with database definition */ + + /* We'll need the routine list */ + $routines=query_routines(); + if (!$routines) + { + $parent->last_error="Failed to get routines list from database"; + return false; + } + + /* We also need this testsuite complete definition */ + $sql = "SELECT descr_id, assert_routine, descr_num_assert, descr_num_test" + ." FROM opts_version_descriptions, opts_assertions" + ." WHERE opts_version_descriptions.descr_assert=opts_assertions.assert_id" + ." AND descr_version=$TS_id"; + if ($parent->debug > 1) + echo htmlentities($sql)."<br>\n"; + $opts_definition_tmp = db_execute_select($sql); + if (!$opts_definition_tmp) + { + $parent->last_error="The OPTS release description was not found in database.\n"; + return false; + } + /* We hash the result for efficiency */ + $opts_definition = array(); + foreach($opts_definition_tmp as $record) + $opts_definition + [$record["assert_routine"]] + [$record["descr_num_assert"]] + [$record["descr_num_test"]] + =$record["descr_id"]; + unset($opts_definition_tmp); + + /* We're ready to proceed: + * -> walk through the log file (analyzed) + * -> foreach test, find the corresponding description ID + * -> save a record with the information: description ID, test status, test log. + * -> this will then be used to generate the database entries. + */ + $result = array(); + foreach ($log_data as $record) + { + if (!isset($opts_definition + [$routines[$record["routine"]]["routine_id"]] + [$record["assert_num"]] + [$record["test_num"]])) + echo "The test ".$record["routine"]."/".$record["assert_num"]."-".$record["test_num"]." was not found in the database -- ignored\n"; + else + $result[$opts_definition + [$routines[$record["routine"]]["routine_id"]] + [$record["assert_num"]] + [$record["test_num"]] + ]=array( + "status"=>$record["status"], + "log" =>$record["log"]); + } + /* We can trash everything else :) */ + unset ($routines); + unset ($opts_definition); + unset ($log_data); + + echo "\n<b>".count($result)."</b> test results can be inserted in the results database.\n\n"; + + /* Now we've got to add the new run name in the database and get its ID */ + $sql = "INSERT INTO opts_run ( run_name, run_comments )" + ." VALUES ( ".stringToDB($RUN_name).", ".stringToDB($RUN_description)." )"; + if ($parent->debug > 1) + echo htmlentities($sql)."<br>\n"; + $res = db_execute_insert($sql); + if (!$res) + { + $parent->last_error="Failed to insert new run name"; + return false; + } + + $sql = "SELECT run_id, run_name, run_comments FROM opts_run WHERE run_name LIKE ".stringToDB($RUN_name); + if ($parent->debug > 1) + echo htmlentities($sql)."<br>\n"; + $res = db_execute_select($sql); + if (!$res) + { + $parent->last_error="Internal error: the run was inserted but disappeared\n"; + return false; + } + $run_id=$res[0]["run_id"]; + + $counter=0; + foreach($result as $desc_id => $testdata) + { + $sql = "INSERT INTO opts_run_results ( res_run, res_testcase, res_status, res_log )" + ." VALUES ( $run_id, $desc_id, ".stringToDB($testdata["status"]).", " + .stringToDB($testdata["log"])." )"; + if ($parent->debug > 1) + echo htmlentities($sql)."<br>\n"; + if (db_execute_insert($sql)) + $counter++; + else + echo "<b><i>Failed to execute the following instruction</i></b>; skipping.\n$sql\n"; + } + echo "<b>$counter</b> records added to the database!\n"; + + return true; } @@ -531,7 +722,54 @@ { if ( $parent->debug ) echo "opts->RUN_delete($RUN_id)\n"; - return false; + + /* Check this run belongs to an OPTS testsuite */ + $sql = "SELECT ver_module FROM opts_versions, opts_version_descriptions, opts_run_results" + ." WHERE res_run=$RUN_id" + ." AND res_testcase=descr_id AND descr_version=ver_id" + ." GROUP BY ver_module"; + if ($parent->debug > 1) + echo htmlentities($sql)."<br>\n"; + $tmp = db_execute_select($sql); + if (!$tmp) + { + $parent->last_error="The run ID or corresponding testsuite cannot be found in the database.\n"; + return FALSE; + } + if ($tmp[0]["ver_module"] != "opts") + { + $parent->last_error="The testsuite is not an OPTS -- cannot be deleted within the current module.\n"; + return FALSE; + } + + /* We can delete everything related to this run */ + $sql = "DELETE from opts_run_results " + ."WHERE res_run=$RUN_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_run_results\n"; + return FALSE; + } + if ($parent->debug > 1) + echo "$tmp rows deleted from opts_run_results<br>\n"; + + $sql = "DELETE from opts_run " + ."WHERE run_id=$RUN_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_run\n"; + return FALSE; + } + if ($parent->debug > 1) + echo "$tmp row deleted from opts_run<br>\n"; + + return true; } } |