From: Sebastien D. <sde...@us...> - 2005-06-14 12:42:57
|
Update of /cvsroot/tslogparser/tslogparser/admin/modules In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv6286/admin/modules Modified Files: tahi.mod.php Log Message: Changes for TAHI support Index: tahi.mod.php =================================================================== RCS file: /cvsroot/tslogparser/tslogparser/admin/modules/tahi.mod.php,v retrieving revision 1.2 retrieving revision 1.3 diff -u -d -r1.2 -r1.3 --- tahi.mod.php 10 Jun 2005 14:50:32 -0000 1.2 +++ tahi.mod.php 14 Jun 2005 12:42:47 -0000 1.3 @@ -46,11 +46,9 @@ === Table opts_routines rou_id : 198 - rou_name : Normal Operations - Registration - rou_comment: NULL + rou_name : 2.2 + rou_comment: Processing Mobility Headers -- Receiving CoTI - Note: the rou_comment could contain complete hierarchy of test categories. - === Table opts_assertions assert_id : 1466 assert_routine : 198 @@ -71,30 +69,68 @@ descr_assert : 1466 descr_num_asser : 1 descr_num_test : 1 - descr_info : CN-1-1 + descr_info : ./CN-1-1.seq Note: descr_num_assert is not usefull for this module - we put dummy values. descr_num_test is obtained from the INDEX file (# of test) + === Table opts_run + run_id : 20 + run_name : Mipl2-rc2 without IPsec + run comment : configuration file available at http://... + + === Table opts_run_results + res_run : 20 + res_testcase : 6435 + res_status : PASS + res_log : (contenu du fichier 1.html) + + */ -/* The following function parses the file $complete_path/INDEX and saves the +/* The following function parses the file $root/$ts_type/INDEX and saves the result into $tahi_tree. It returns TRUE on success and FALSE on failure. */ -function parse_INDEX(&$tahi_tree, $complete_path, $debug) +function parse_INDEX(&$tahi_tree, $root, $ts_type, $debug) { - /* The format of $tahi_tree is as follows: */ + /* The format of $tahi_tree is as follows: + + $tahi_tree=array( + "mipv6-mn-0" => array( + "name" => "Basic Sequence" + "tests" => array( + 1 => array( + "filename" => "./MN-0-0-0-1-001.seq" + "testname" => "MN-0-0-0-1-001 - Mobile Node Operation-1" + "content" => (file content) + ) + 2 => array( + "filename" => ... + ) + ) + ) + "mipv6-mn-14/4" => array( + "name" => "Mobile to Mobile / Binding Error" + "tests" => array( + 116 => ... + ) + + + */ if ($debug) - echo "parse_INDEX($complete_path)\n"; + echo "parse_INDEX($root/$ts_type)\n"; /* Read the file */ - $fichier = file($complete_path."/INDEX"); + $fichier = file("$root/$ts_type/INDEX"); - $hierarchy = "default"; + $cur_hierarchy = $ts_type; + $cur_level = 0; + $tab_hierarchy=array(); + $counter = 0; /* Browse the file content */ foreach ($fichier as $ligne) @@ -120,21 +156,36 @@ if (preg_match("/^&print:\s*<B>(.*)\<\/B>$/", $ligne, $regs)) { $match = TRUE; - //if ($debug) - // echo "Hierarchy: ".htmlentities($regs[1])."\n"; $hierarchy = str_replace(" ", " ", trim(strip_tags($regs[1]))); + //if ($debug) + // echo "Hierarchy: ".htmlentities($hierarchy)."\n"; /* We are looking for hierarchical information: n. <blablah> => level 1 n.m. <blablah> => level 2 (n) <blabla> => sublevel */ + if (preg_match("/^(\d+)\.\s(.*)$/", $hierarchy,$regs)) + { + $cur_level=$regs[1]; + $cur_hierarchy=$regs[2]; + $tab_hierarchy[$cur_level]=$cur_hierarchy; + } + if (preg_match("/^(\d+)\.(\d+)\.\s(.*)$/", $hierarchy,$regs)) + { + $cur_level=$regs[1].".".$regs[2]; + $cur_hierarchy=$tab_hierarchy[$regs[1]]." -- ".$regs[3]; + $tab_hierarchy[$cur_level]=$cur_hierarchy; + } + $tmp_level = $cur_level; + $tmp_hierarchy=$cur_hierarchy; + + if (preg_match("/^\((\d+)\)\s(.*)$/", $hierarchy,$regs)) + { + $tmp_level=$cur_level."/".$regs[1]; + $tmp_hierarchy=$cur_hierarchy." / ".$regs[2]; + } - // TEMP: at this time, we only keep the top of the stack - $tahi_tree[]=array( - "hierarchy" => $hierarchy - "tests" => array() - ); } if (preg_match("/^([^:]+):[^:]*:[^:]*:[^:]*:([^:]+):?$/",$ligne,$regs)) @@ -142,13 +193,31 @@ $match = TRUE; //if ($debug) // echo "Test info: ".htmlentities($regs[1]." => ".$regs[2])."\n"; + + $counter++; + + if (!isset($tahi_tree[$ts_type."-".$tmp_level])) + $tahi_tree[$ts_type."-".$tmp_level]=array( + "name" => $tmp_hierarchy, + "tests" => array() + ); + + $tahi_tree[$ts_type."-".$tmp_level]["tests"][$counter]=array( + "filename" => $regs[1], + "testname" => $regs[2], + "content" => file_get_contents("$root/$ts_type/".$regs[1]) + ); + } if (!$match) echo "Ignored the following line: ".htmlentities($ligne)."\n"; } - return FALSE; +// if ($debug) +// print_r($tahi_tree); + + return TRUE; } @@ -229,12 +298,11 @@ $found = TRUE; /* Now we found the file we were looking for: $path/$file/INDEX */ - if (! parse_INDEX($tahi_tree, $path."/".$file, $parent->debug)) + if (! parse_INDEX($tahi_tree, $path, $file, $parent->debug)) { $parent->last_error= "Parsing of INDEX failed\n"; return FALSE; } - } closedir ($dh2); } @@ -248,7 +316,7 @@ /* We've parsed the whole tree */ - if ($parent->debug > 1) + if ($parent->debug > 2) print_r($tahi_tree); /* The database shall be initialized here */ @@ -263,26 +331,136 @@ if ($releases) { $parent->last_error= "The release '$TS_name' is already in the database \n". - "<i>".stringFromDB($releases[$TS_name]["ver_comment"])."</i>\n"; + "<i>(".stringFromDB($releases[$TS_name]["ver_comment"]).")</i>\n"; return FALSE; } /* Now, compare the $tahi_tree with the $current_tests and build up the list of tests to be added to the database.*/ + + + $current_categories=query_routines(); + + /* We start with looking for missing routines */ + $missing_category=array(); + /* browse the new release assertions */ + foreach ($tahi_tree as $category=>$data) + { + /* If the category is missing from opts_routines table, we'll add it */ + if (!isset($current_categories[$category])) + $missing_category[]=$category; + else /* check the category was not renumbered from the previous entered version */ + if ($data["name"] != $current_categories[$category]["routine_comment"]) + { + echo "Inconsistency found for category <b>$category</b><br>\n"; + echo "Old name: ".$current_categories[$category]["routine_comment"]."<br>\n"; + echo "New name: ".$data["name"]."\n"; + + $parent->last_error= "Unable to add $category to the database\n"; + return FALSE; + } + + } - /* If any routine is missing, it must be added previously to further processing */ + if ($parent->debug > 1) + print_r($missing_category); - /* browse the new release assertions */ + /* If any category is missing, it must be added previously to further processing */ + if ($missing_category) + { + echo "New categories of tests are being added to the database...\n"; + $counter=0; + foreach ($missing_category as $cat) + { + $sql = "INSERT INTO opts_routines ( rou_name, rou_comment ) " + ."VALUES ( ".stringToDB($cat)."," + .stringToDB($tahi_tree[$cat]["name"])." )"; + if ($parent->debug > 1) + echo htmlentities($sql)."<br>\n"; + if (db_execute_insert($sql)) + $counter++; + else + echo "Failed to add $cat to the database...\n"; + } + echo "Done. <b>$counter</b> categories have been added.\n\n"; + $current_categories=query_routines(); + } + + /* Now we are adding new tests if any */ + + $current_tests=query_all_asserts(); + $missing_tests=array(); + /* Check for existing tests */ + foreach ($tahi_tree as $cat => $cat_data) + { + if (!isset($current_tests[$cat])) + { + if (!isset($current_categories[$cat])) + { + $parent->last_error="Internal script error: category $cat was not added in 1st pass"; + return FALSE; + } + + /* We now schedule addition of these tests for this category, as none was already defined */ + foreach ($cat_data["tests"] as $test_data) + { + $missing_tests[]=array( + "cat"=>$cat, + "name"=>$test_data["testname"], + "file"=>$test_data["filename"], + "content"=>&$test_data["content"]); + } + } + else /* some tests were already defined in this category */ + { + foreach ($cat_data["tests"] as $test_data) + { + /* Check if this test content was already in the database */ + if(!in_array($test_data["content"], $current_tests[$cat])) + $missing_tests[]=array( + "cat"=>$cat, + "name"=>$test_data["testname"], + "file"=>$test_data["filename"], + "content"=>&$test_data["content"] + ); + } + } + } + if ($parent->debug > 1) + print_r($missing_tests); + /* If any assertion is missing, it must be added previously to further processing */ + if ($missing_tests) + { + echo "New tests are being added to the database...\n"; + $counter=0; + foreach ($missing_tests as $test) + { + $sql = "INSERT INTO opts_assertions ( assert_routine, assert_text ) " + ."VALUES ( ".$current_categories[$test["cat"]]["routine_id"]."," + .stringToDB($test["content"])." )"; + if ($parent->debug > 1) + echo htmlentities($sql)."<br>\n"; + if (db_execute_insert($sql)) + $counter++; + else + echo "Failed to add test ".$test["testname"]." (".$test["filename"].") to the database...\n"; + } + echo "Done. <b>$counter</b> tests have been added.\n\n"; + $current_tests=query_all_asserts(); + } + /* OK, we can now create the new release of TAHI in the database */ - $sql="INSERT INTO opts_versions (ver_name, ver_comment) " + $sql="INSERT INTO opts_versions (ver_name, ver_comment, ver_module) " . "VALUES ( ".stringToDB($TS_name).", " - . stringToDB($TS_description)." )"; + . stringToDB($TS_description).", " + . "'tahi' )"; 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"; @@ -297,12 +475,53 @@ $parent->last_error= "Internal error: the new TAHI version was not created\n"; return FALSE; } - if ($parent->debug > 1) - print_r($current_asserts); + if ($parent->debug > 2) + print_r($current_tests); /* We can create the full release description */ + $release_description = array(); + foreach ($tahi_tree as $cat => $cat_data) + { + if (!isset($current_tests[$cat]) || !isset($current_categories[$cat])) + { + $parent->last_error= "Internal script error: category $cat was not added in 1st pass"; + return FALSE; + } + + foreach ($cat_data["tests"] as $test_nr => $test_data) + { + $release_description[]=array( + "descr_assert" => array_search($test_data["content"], $current_tests[$cat]), + "descr_num_test" => $test_nr, + "descr_info" => $test_data["filename"]); + } + } /* 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"].", " + ."0, " + .$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; } @@ -376,6 +595,9 @@ { if ( $parent->debug ) echo "tahi->RUN_parse($RUN_name, $RUN_description, $TS_id, ...".strlen($CONTENT)."c...)\n"; + + /* We won't need the CONTENT var here -- we free some memory */ + unset($CONTENT); /* Check this TS id first */ $sql = "SELECT ver_id, ver_name, ver_comment, ver_module FROM opts_versions WHERE ver_id=$TS_id"; @@ -406,17 +628,195 @@ return false; } - /* Parse the results files */ + /* Parse the results files -- which shall be a tar.gz file. + -> uncompress the file into a temp directory + -> look for the results + -> parse these results + */ + + /* Set a longer execution time */ + set_time_limit(60); + + /* This is quite dirty... we simply ignore the CONTENT string. */ + $tar = new Archive_Tar($_FILES['logfile']['tmp_name']); + $tar->setErrorHandling(PEAR_ERROR_PRINT); + + $tmpdir = "../ts/".time(); + + if (!$tar->extractModify($tmpdir, "")) + { + $parent->last_error ="Archive extraction failed. Please provide the results as a 'tar.gz' file.\n"; + return false; + } + + /* Find directory name from inside archive, if any */ + /* 1 - check the files are inside a subdirectory */ + if (!is_file($tmpdir."/report.html")) + { + /* 2 - open the directory where files were extracted */ + if ($dh = opendir($tmpdir)) + { + /* 3 - list the files. We assume there is only 1 directory here */ + while (($file = readdir($dh)) !== false) + { + if (($file == ".") || ($file == "..")) + continue; + if (is_dir($tmpdir."/".$file)) + { + $tmpdir .= "/".$file; + break; + } + $parent->last_error ="Unexpected entry in archive: $file"; + return false; + } + /* 4 - close the directory */ + closedir($dh); + } + else + { + $parent->last_error = "Unable to open temporary directory $tmpdir"; + return FALSE; + } + } + + if (!is_file($tmpdir."/report.html")) + { + $parent->last_error = "Unable to find 'report.html' file in uploaded results."; + return FALSE; + } + + $log = file($tmpdir."/report.html"); + if (!$log) + { + $parent->last_error = "Unable to read '$tmpdir/report.html' file."; + return FALSE; + } + + /* Example of a tests status: + <TD>7</TD><TD><A HREF="./MN-3-3-1-1-003.html">MN-3-3-1-1-003 - Use Neighbor Unreachability Detection (Target Address=global)</A></TD><TD ALIGN="CENTER">PASS</TD><TD ALIGN="CENTER"><A HREF="7.html">X</A></TD><TD ALIGN="CENTER"><A HREF="./MN-3-3-1-1-003.seq">X</A></TD><TD ALIGN="CENTER"><A HREF="./mip6_mn_common.def">X</A></TD><TD ALIGN="CENTER"><A HREF="7.html.Link0.dump">Link0</A> </TD></TR> + <TD>4</TD><TD>CN-2-1-1 - Receiving HoTI - Invalid Mobility Option (Nonce Indices option)</TD><TD ALIGN="CENTER">PASS</TD><TD ALIGN="CENTER"><A HREF="4.html">X</A></TD><TD ALIGN="CENTER"><A HREF="./CN-2-1-1.seq">X</A></TD><TD ALIGN="CENTER"><A HREF="./mip6cnt.def">X</A></TD><TD ALIGN="CENTER"><A HREF="4.html.Link0.dump">Link0</A> </TD></TR> - /* Next step is to eliminate duplicates and match testcases with database definition */ + + What we try and match is: + <TD>(param1)</TD><TD><A HREF="(*)">(param2)</A></TD><TD ALIGN="CENTER">(param3)</TD><TD ALIGN="CENTER"><A HREF="(param4)">X</A></TD><TD ALIGN="CENTER"><A HREF="(param5)">X</A></TD><TD ALIGN="CENTER">(*)</TD><TD ALIGN="CENTER">(*)</TD></TR> + where: + param1: # of the test (format: numeric) + param2: Name of the test. + param3: Status + param4: log file + param5: filename of the testcase + */ + $test_results=array(); + + $regex = "/^<TD>" + ."(\d+)" // param1 + ."<\/TD>" + ."<TD>(?:<A HREF=\"[^\"]*\">)?" + ."(.*?)" // param2 + ."(?:<\/A>)?<\/TD>" + ."<TD ALIGN=\"CENTER\">" + ."(.*?)" // param3 + ."<\/TD>" + ."<TD ALIGN=\"CENTER\"><A HREF=\"" + ."(.*?)" // param4 + ."\">X<\/A><\/TD>" + ."<TD ALIGN=\"CENTER\"><A HREF=\"" + ."(.*?)" // param5 + ."\">X<\/A><\/TD>" + ."<TD ALIGN=\"CENTER\">.*?<\/TD>" + ."<TD ALIGN=\"CENTER\">.*?<\/TD>" + ."<\/TR>$/"; + + foreach ($log as $nr => $ligne) + { + /* Line parsing */ + if (preg_match($regex, $ligne, $regs)) + { + $test_results[$regs[1]]=array( + "name" => trim($regs[2]), + "status" => trim(strip_tags($regs[3])), + "log" => $tmpdir."/".$regs[4], + "filename" => trim($regs[5]) + ); + } + else + { + if ($parent->debug) + echo "Discarded: ".htmlentities($ligne)."\n"; + } + } + + /* We also need the release description from the database */ + $sql = "SELECT descr_id, descr_num_test, descr_info" + ." FROM opts_version_descriptions" + ." WHERE descr_version=$TS_id"; + if ($parent->debug > 1) + echo htmlentities($sql)."<br>\n"; + $version_description = db_execute_select($sql); + if (!$version_description) + { + $parent->last_error="The TAHI release description was not found in database.\n"; + return false; + } /* We're ready to proceed: - * -> walk through the log file (analyzed) - * -> foreach test, find the corresponding description ID + * -> walk through the release description + * -> foreach test, find the corresponding result * -> save a record with the information: description ID, test status, test log. * -> this will then be used to generate the database entries. */ + $parsed_results=array(); + $missing_results=array(); + foreach ($version_description as $record) + { + if (!isset($test_results[$record["descr_num_test"]])) + { + $missing_results[]=$record["descr_num_test"]; + continue; + } + if ($test_results[$record["descr_num_test"]]["filename"] != $record["descr_info"]) + { + echo "Test ".$record["descr_num_test"]." does not match database description (" + .$test_results[$record["descr_num_test"]]["filename"]." != " . $record["descr_info"].".\n" + ."Result ignored"; + continue; + } + /* Ok we found a corrsponding entry */ + $parsed_results[]=array( + "res_testcase" => $record["descr_id"], + "res_status" => $test_results[$record["descr_num_test"]]["status"], + "res_log" => $test_results[$record["descr_num_test"]]["log"] + ); + + /* remove this test result */ + unset($test_results[$record["descr_num_test"]]); + } + + if ($missing_results) + { + echo count($missing_results)." tests are missing from analyzed logfile.\n"; + if ($parent->debug) + { + echo "Missing tests results:\n"; + print_r($missing_results); + } + } + unset ($missing_results); + + if ($test_results) + { + echo count($test_results)." tests are missing from release description in database.\n"; + if ($parent->debug) + { + echo "Missing tests description:\n"; + print_r($test_results); + } + } + + unset($test_results); + + /* 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)." )"; @@ -440,8 +840,47 @@ } $run_id=$res[0]["run_id"]; + /* Add the records in opts_run_results */ - + $count=0; + foreach ($parsed_results as $entry) + { + $sql = "INSERT INTO opts_run_results " + ."(res_run, res_testcase, res_status, res_log) " + ." VALUES (" + .$run_id.", " + .$entry["res_testcase"].", " + .stringToDB($entry["res_status"]).", " + .stringToDB(html_entity_decode(file_get_contents($entry["res_log"]))).")"; + if ($parent->debug > 1) + echo htmlentities($sql)."<br>\n"; + $res = db_execute_insert($sql); + if (!$res) + echo "Failed to add record for test ".$entry["res_testcase"]."\n"; + else + $count++; + } + echo "$count results were inserted in the database.\n"; + + /* Delete the extracted tarball */ + function deldir($dir) { + $dh=opendir($dir); + while ($file=readdir($dh)) { + if($file!="." && $file!="..") { + $fullpath=$dir."/".$file; + if(!is_dir($fullpath)) { + unlink($fullpath); + } else { + deldir($fullpath); + } + } + } + closedir($dh); + rmdir($dir); + } + + deldir($tmpdir); + return true; } @@ -481,8 +920,7 @@ $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"; + echo "$tmp rows deleted from opts_run_results<br>\n"; $sql = "DELETE from opts_run " ."WHERE run_id=$RUN_id"; @@ -494,8 +932,7 @@ $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"; + echo "$tmp row deleted from opts_run<br>\n"; return true; } |