From e65d11cc04e05a81f2cb60a296ef4367bd307a93 Mon Sep 17 00:00:00 2001 From: Michael Larabel Date: Thu, 30 Oct 2008 21:14:44 -0400 Subject: pts-core: Reorder a few functions --- pts-core/functions/pts-functions_tests.php | 220 +++++++++++++++++++++++++++++ 1 file changed, 220 insertions(+) (limited to 'pts-core/functions/pts-functions_tests.php') diff --git a/pts-core/functions/pts-functions_tests.php b/pts-core/functions/pts-functions_tests.php index 5a4e151..ac6c307 100644 --- a/pts-core/functions/pts-functions_tests.php +++ b/pts-core/functions/pts-functions_tests.php @@ -21,7 +21,227 @@ along with this program. If not, see . */ +function pts_save_result($save_to = null, $save_results = null) +{ + // Saves PTS result file + if(strpos($save_to, ".xml") === false) + { + $save_to .= ".xml"; + } + + $save_to_dir = dirname(SAVE_RESULTS_DIR . $save_to); + + if(!is_dir(SAVE_RESULTS_DIR)) + { + mkdir(SAVE_RESULTS_DIR); + } + if($save_to_dir != '.' && !is_dir($save_to_dir)) + { + mkdir($save_to_dir); + } + + if(!is_dir(SAVE_RESULTS_DIR . "pts-results-viewer")) + { + mkdir(SAVE_RESULTS_DIR . "pts-results-viewer"); + } + + pts_copy(RESULTS_VIEWER_DIR . "pts.js", SAVE_RESULTS_DIR . "pts-results-viewer/pts.js"); + pts_copy(RESULTS_VIEWER_DIR . "pts-results-viewer.xsl", SAVE_RESULTS_DIR . "pts-results-viewer/pts-results-viewer.xsl"); + pts_copy(RESULTS_VIEWER_DIR . "pts-viewer.css", SAVE_RESULTS_DIR . "pts-results-viewer/pts-viewer.css"); + pts_copy(RESULTS_VIEWER_DIR . "pts-logo.png", SAVE_RESULTS_DIR . "pts-results-viewer/pts-logo.png"); + + if($save_to == null || $save_results == null) + { + $bool = true; + } + else + { + $save_name = basename($save_to, ".xml"); + + if($save_name == "composite") + { + if(!is_dir($save_to_dir . "/result-graphs")) + { + mkdir($save_to_dir . "/result-graphs"); + } + + $xml_reader = new tandem_XmlReader($save_results); + $results_suite_name = $xml_reader->getXMLValue(P_RESULTS_SUITE_NAME); + $results_name = $xml_reader->getXMLArrayValues(P_RESULTS_TEST_TITLE); + $results_testname = $xml_reader->getXMLArrayValues(P_RESULTS_TEST_TESTNAME); + $results_version = $xml_reader->getXMLArrayValues(P_RESULTS_TEST_VERSION); + $results_attributes = $xml_reader->getXMLArrayValues(P_RESULTS_TEST_ATTRIBUTES); + $results_scale = $xml_reader->getXMLArrayValues(P_RESULTS_TEST_SCALE); + $results_proportion = $xml_reader->getXMLArrayValues(P_RESULTS_TEST_PROPORTION); + $results_result_format = $xml_reader->getXMLArrayValues(P_RESULTS_TEST_RESULTFORMAT); + $results_raw = $xml_reader->getXMLArrayValues(P_RESULTS_RESULTS_GROUP); + + $results_identifiers = array(); + $results_values = array(); + + foreach($results_raw as $result_raw) + { + $xml_results = new tandem_XmlReader($result_raw); + array_push($results_identifiers, $xml_results->getXMLArrayValues(S_RESULTS_RESULTS_GROUP_IDENTIFIER)); + array_push($results_values, $xml_results->getXMLArrayValues(S_RESULTS_RESULTS_GROUP_VALUE)); + } + + for($i = 0; $i < count($results_name); $i++) + { + if(strlen($results_version[$i]) > 2) + { + $results_name[$i] .= " v" . $results_version[$i]; + } + + if($results_result_format[$i] == "LINE_GRAPH") + { + $t = new pts_LineGraph($results_name[$i], $results_attributes[$i], $results_scale[$i]); + } + else if($results_result_format[$i] == "PASS_FAIL") + { + $t = new pts_PassFailGraph($results_name[$i], $results_attributes[$i], $results_scale[$i]); + } + else if($results_result_format[$i] == "MULTI_PASS_FAIL") + { + $t = new pts_MultiPassFailGraph($results_name[$i], $results_attributes[$i], $results_scale[$i]); + } + else + { + $t = new pts_BarGraph($results_name[$i], $results_attributes[$i], $results_scale[$i]); + } + + if(pts_gd_available() && getenv("SVG_DEBUG") == false) + { + // Render to PNG + $t->setRenderer("PNG"); + pts_copy(RESULTS_VIEWER_DIR . "pts-results-viewer.xsl", $save_to_dir . "/pts-results-viewer.xsl"); + } + else + { + if(!defined("PHP_SVG_TEXT")) + { + echo "\nThe PHP GD extension is missing, so the experimental SVG rendering engine is being used.\n"; + define("PHP_SVG_TEXT", 1); + } + + // Render to SVG + $t->setRenderer("SVG"); + pts_copy(RESULTS_VIEWER_DIR . "pts-svg-results-viewer.xsl", $save_to_dir . "/pts-results-viewer.xsl"); + } + + $t->loadGraphIdentifiers($results_identifiers[$i]); + $t->loadGraphValues($results_values[$i]); + $t->loadGraphProportion($results_proportion[$i]); + $t->loadGraphVersion(PTS_VERSION); + + $t->add_user_identifier("Test", $results_testname[$i]); + $t->add_user_identifier("Identifier", $results_suite_name); + $t->add_user_identifier("User", pts_current_user()); + + $t->save_graph($save_to_dir . "/result-graphs/" . ($i + 1) . "." . strtolower($t->getRenderer())); + $t->renderGraph(); + } + } + $bool = file_put_contents(SAVE_RESULTS_DIR . $save_to, $save_results); + if(defined("TEST_RESULTS_IDENTIFIER") && (pts_string_bool(pts_read_user_config(P_OPTION_LOG_VSYSDETAILS, "TRUE")) || (defined("IS_PCQS_MODE") && IS_PCQS_MODE) || getenv("SAVE_SYSTEM_DETAILS") != false)) + { + // Save verbose system information here + if(!is_dir($save_to_dir . "/system-details/")) + { + mkdir($save_to_dir . "/system-details/"); + } + if(!is_dir($save_to_dir . "/system-details/" . TEST_RESULTS_IDENTIFIER)) + { + mkdir($save_to_dir . "/system-details/" . TEST_RESULTS_IDENTIFIER); + } + + if(is_file("/var/log/Xorg.0.log")) + { + pts_copy("/var/log/Xorg.0.log", $save_to_dir . "/system-details/" . TEST_RESULTS_IDENTIFIER . "/Xorg.0.log"); + } + + // lspci + $file = shell_exec("lspci 2>&1"); + + if(strpos($file, "not found") == false) + { + @file_put_contents($save_to_dir . "/system-details/" . TEST_RESULTS_IDENTIFIER . "/lspci", $file); + } + + // sensors + $file = shell_exec("sensors 2>&1"); + + if(strpos($file, "not found") == false) + { + @file_put_contents($save_to_dir . "/system-details/" . TEST_RESULTS_IDENTIFIER . "/sensors", $file); + } + + // dmesg + $file = shell_exec("dmesg 2>&1"); + + if(strpos($file, "not found") == false) + { + @file_put_contents($save_to_dir . "/system-details/" . TEST_RESULTS_IDENTIFIER . "/dmesg", $file); + } + + if(IS_MACOSX) + { + // system_profiler (Mac OS X) + $file = shell_exec("system_profiler 2>&1"); + + if(strpos($file, "not found") == false) + { + @file_put_contents($save_to_dir . "/system-details/" . TEST_RESULTS_IDENTIFIER . "/system_profiler", $file); + } + } + + // cpuinfo + if(is_file("/proc/cpuinfo")) + { + $file = file_get_contents("/proc/cpuinfo"); + @file_put_contents($save_to_dir . "/system-details/" . TEST_RESULTS_IDENTIFIER . "/cpuinfo", $file); + } + } + file_put_contents($save_to_dir . "/index.html", "Phoronix Test Suite"); + } + + return $bool; +} +function pts_global_upload_result($result_file, $tags = "") +{ + // Upload a test result to the Phoronix Global database + $test_results = file_get_contents($result_file); + $test_results = str_replace(array("\n", "\t"), "", $test_results); + $switch_tags = array("Benchmark>" => "B>", "Results>" => "R>", "Group>" => "G>", "Entry>" => "E>", "Identifier>" => "I>", "Value>" => "V>", "System>" => "S>", "Attributes>" => "A>"); + + foreach($switch_tags as $f => $t) + { + $test_results = str_replace($f, $t, $test_results); + } + + $ToUpload = base64_encode($test_results); + $GlobalUser = pts_current_user(); + $GlobalKey = pts_read_user_config(P_OPTION_GLOBAL_UPLOADKEY, ""); + $tags = base64_encode($tags); + $return_stream = ""; + + $upload_data = array("result_xml" => $ToUpload, "global_user" => $GlobalUser, "global_key" => $GlobalKey, "tags" => $tags); + $upload_data = http_build_query($upload_data); + + $http_parameters = array("http" => array("method" => "POST", "content" => $upload_data)); + + $stream_context = stream_context_create($http_parameters); + $opened_url = @fopen("http://www.phoronix-test-suite.com/global/user-upload.php", "rb", false, $stream_context); + $response = @stream_get_contents($opened_url); + + if($response !== false) + { + $return_stream = $response; + } + + return $return_stream; +} function pts_test_needs_updated_install($identifier) { // Checks if test needs updating -- cgit