public static function run($r)
 {
     pts_client::$display->generic_heading(count(pts_module_manager::available_modules()) . ' Modules');
     foreach (pts_module_manager::available_modules() as $module) {
         pts_module_manager::load_module($module);
         echo sprintf('%-22ls - %-32ls [%s]' . PHP_EOL, $module, pts_module_manager::module_call($module, 'module_name') . ' v' . pts_module_manager::module_call($module, 'module_version'), pts_module_manager::module_call($module, 'module_author'));
     }
     echo PHP_EOL;
 }
 public static function run($r)
 {
     $module = strtolower($r[0]);
     pts_module_manager::attach_module($module);
     $processes = array('__startup', '__pre_option_process', '__pre_install_process', '__pre_test_download', '__interim_test_download', '__post_test_download', '__pre_test_install', '__post_test_install', '__post_install_process', '__pre_run_process', '__pre_test_run', '__interim_test_run', '__post_test_run', '__post_run_process', '__post_option_process', '__shutdown');
     foreach ($processes as $process) {
         echo 'Calling: ' . $process . '()' . PHP_EOL;
         pts_module_manager::module_process($process);
         sleep(1);
     }
     echo PHP_EOL;
 }
 public static function run($r)
 {
     $module = strtolower($r[0]);
     $pre_message = null;
     if (!class_exists($module)) {
         pts_module_manager::load_module($module);
     }
     $module_name = pts_module_manager::module_call($module, 'module_name');
     $module_description = pts_module_manager::module_call($module, 'module_description');
     $module_setup = pts_module_manager::module_call($module, 'module_setup');
     pts_client::$display->generic_heading($module_name . ' Module Configuration');
     echo $module_description . PHP_EOL;
     if (count($module_setup) == 0) {
         echo PHP_EOL . 'There are no options available for configuring with the ' . $module . ' module.' . PHP_EOL;
     } else {
         if (($module_presets = pts_client::read_env('PTS_MODULE_SETUP')) != false) {
             $module_presets = pts_client::parse_value_string_double_identifier($module_presets);
         }
         $set_options = array();
         foreach ($module_setup as $module_option) {
             if ($module_option instanceof pts_module_option) {
                 $option_identifier = $module_option->get_identifier();
                 if (isset($module_presets[$module][$option_identifier]) && $module_option->is_supported_value($module_presets[$module][$option_identifier])) {
                     echo PHP_EOL . $module_option->get_formatted_question();
                     echo $module_presets[$module][$option_identifier] . PHP_EOL;
                     $input = $module_presets[$module][$option_identifier];
                 } else {
                     do {
                         echo PHP_EOL . $module_option->get_formatted_question();
                         $input = pts_user_io::read_user_input();
                     } while (!$module_option->is_supported_value($input));
                 }
                 if (empty($input)) {
                     $input = $module_option->get_default_value();
                 }
                 $set_options[$option_identifier] = $input;
             }
         }
         $set_options = pts_module_manager::module_call($module, 'module_setup_validate', $set_options);
         if (!empty($set_options)) {
             pts_module::module_config_save($module, $set_options);
         }
     }
     echo PHP_EOL;
 }
 public static function run($args)
 {
     $module = $args[0];
     pts_module_manager::load_module($module);
     pts_client::$display->generic_heading(pts_module_manager::module_call($module, 'module_name') . ' Module');
     if (in_array($args[0], pts_module_manager::attached_modules())) {
         echo '** This module is currently loaded. **' . PHP_EOL;
     }
     echo 'Version: ' . pts_module_manager::module_call($module, 'module_version') . PHP_EOL;
     echo 'Author: ' . pts_module_manager::module_call($module, 'module_author') . PHP_EOL;
     echo 'Description: ' . pts_module_manager::module_call($module, 'module_description') . PHP_EOL;
     echo PHP_EOL . pts_module_manager::module_call($module, 'module_info') . PHP_EOL;
     $all_options = pts_module_manager::module_call($module, 'user_commands');
     if (count($all_options) > 0) {
         echo 'Module User Commands:' . PHP_EOL;
         foreach (array_keys($all_options) as $option) {
             echo '- ' . $module . '.' . str_replace('_', '-', $option) . PHP_EOL;
         }
         echo PHP_EOL;
     }
 }
 protected static function install_test_process(&$test_install_request, $no_prompts)
 {
     // Install a test
     $identifier = $test_install_request->test_profile->get_identifier();
     $test_install_directory = $test_install_request->test_profile->get_install_dir();
     pts_file_io::mkdir(dirname($test_install_directory));
     pts_file_io::mkdir($test_install_directory);
     $installed = false;
     if (ceil(disk_free_space($test_install_directory) / 1048576) < $test_install_request->test_profile->get_download_size() + 128) {
         self::test_install_error(null, $test_install_request, 'There is not enough space at ' . $test_install_directory . ' for the test files.');
     } else {
         if (ceil(disk_free_space($test_install_directory) / 1048576) < $test_install_request->test_profile->get_environment_size(false) + 128) {
             self::test_install_error(null, $test_install_request, 'There is not enough space at ' . $test_install_directory . ' for this test.');
         } else {
             pts_test_installer::setup_test_install_directory($test_install_request, true);
             // Download test files
             $download_test_files = pts_test_installer::download_test_files($test_install_request, false, $no_prompts);
             if ($download_test_files == false) {
                 self::test_install_error(null, $test_install_request, 'Downloading of needed test files failed.');
                 return false;
             }
             if ($test_install_request->test_profile->get_file_installer() != false) {
                 self::create_compiler_mask($test_install_request);
                 pts_module_manager::module_process('__pre_test_install', $identifier);
                 pts_client::$display->test_install_begin($test_install_request);
                 $pre_install_message = $test_install_request->test_profile->get_pre_install_message();
                 $post_install_message = $test_install_request->test_profile->get_post_install_message();
                 $install_agreement = $test_install_request->test_profile->get_installation_agreement_message();
                 if (!empty($install_agreement)) {
                     if (pts_strings::is_url($install_agreement)) {
                         $install_agreement = pts_network::http_get_contents($install_agreement);
                         if (empty($install_agreement)) {
                             self::test_install_error(null, $test_install_request, 'The user agreement could not be found. Test installation aborted.');
                             return false;
                         }
                     }
                     echo $install_agreement . PHP_EOL;
                     if (!$no_prompts) {
                         $user_agrees = pts_user_io::prompt_bool_input('Do you agree to these terms', false, 'INSTALL_AGREEMENT');
                         if (!$user_agrees) {
                             self::test_install_error(null, $test_install_request, 'User agreement failed; this test will not be installed.');
                             return false;
                         }
                     }
                 }
                 pts_client::$display->display_interrupt_message($pre_install_message);
                 $install_time_length_start = microtime(true);
                 $install_log = pts_tests::call_test_script($test_install_request->test_profile, 'install', null, $test_install_directory, $test_install_request->special_environment_vars, false);
                 $test_install_request->install_time_duration = ceil(microtime(true) - $install_time_length_start);
                 pts_client::$display->display_interrupt_message($post_install_message);
                 if (!empty($install_log)) {
                     file_put_contents($test_install_directory . 'install.log', $install_log);
                     pts_file_io::unlink($test_install_directory . 'install-failed.log');
                     pts_client::$display->test_install_output($install_log);
                 }
                 if (is_file($test_install_directory . 'install-exit-status')) {
                     // If the installer writes its exit status to ~/install-exit-status, if it's non-zero the install failed
                     $install_exit_status = pts_file_io::file_get_contents($test_install_directory . 'install-exit-status');
                     unlink($test_install_directory . 'install-exit-status');
                     if ($install_exit_status != 0 && phodevi::is_windows() == false) {
                         $install_error = null;
                         // TODO: perhaps better way to handle this than to remove pts-install.xml
                         pts_file_io::unlink($test_install_directory . 'pts-install.xml');
                         if (is_file($test_install_directory . 'install.log')) {
                             $install_log = pts_file_io::file_get_contents($test_install_directory . 'install.log');
                             $install_error = pts_tests::scan_for_error($install_log, $test_install_directory);
                             copy($test_install_directory . 'install.log', $test_install_directory . 'install-failed.log');
                         }
                         //pts_test_installer::setup_test_install_directory($test_install_request, true); // Remove installed files from the bunked installation
                         self::test_install_error(null, $test_install_request, 'The installer exited with a non-zero exit status.');
                         if ($install_error != null) {
                             $test_install_request->install_error = pts_tests::pretty_error_string($install_error);
                             if ($test_install_request->install_error != null) {
                                 self::test_install_error(null, $test_install_request, 'ERROR: ' . $test_install_request->install_error);
                             }
                         }
                         pts_client::$display->test_install_error('LOG: ' . str_replace(pts_core::user_home_directory(), '~/', $test_install_directory) . 'install-failed.log' . PHP_EOL);
                         if (pts_client::do_anonymous_usage_reporting()) {
                             // If anonymous usage reporting enabled, report test install failure to OpenBenchmarking.org
                             pts_openbenchmarking_client::upload_usage_data('test_install_failure', array($test_install_request, $install_error));
                         }
                         return false;
                     }
                 }
                 pts_module_manager::module_process('__post_test_install', $identifier);
                 $installed = true;
                 if (pts_config::read_bool_config('PhoronixTestSuite/Options/Installation/RemoveDownloadFiles', 'FALSE')) {
                     // Remove original downloaded files
                     foreach ($test_install_request->get_download_objects() as $download_object) {
                         pts_file_io::unlink($test_install_directory . $download_object->get_filename());
                     }
                 }
             } else {
                 pts_client::$display->test_install_error('No installation script found.');
                 $installed = true;
             }
             // Additional validation checks?
             $custom_validated_output = pts_tests::call_test_script($test_install_request->test_profile, 'validate-install', PHP_EOL . 'Validating Installation...' . PHP_EOL, $test_install_directory, null, false);
             if (!empty($custom_validated_output) && !pts_strings::string_bool($custom_validated_output)) {
                 $installed = false;
             }
         }
     }
     echo PHP_EOL;
     return $installed;
 }
示例#6
0
 public static function execute_command($command, $pass_args = null)
 {
     if (!class_exists($command, false) && is_file(PTS_COMMAND_PATH . $command . '.php')) {
         include PTS_COMMAND_PATH . $command . '.php';
     }
     if (is_file(PTS_COMMAND_PATH . $command . '.php') && method_exists($command, 'argument_checks')) {
         $argument_checks = call_user_func(array($command, 'argument_checks'));
         foreach ($argument_checks as &$argument_check) {
             $function_check = $argument_check->get_function_check();
             $method_check = false;
             if (is_array($function_check) && count($function_check) == 2) {
                 $method_check = $function_check[0];
                 $function_check = $function_check[1];
             }
             if (substr($function_check, 0, 1) == '!') {
                 $function_check = substr($function_check, 1);
                 $return_fails_on = true;
             } else {
                 $return_fails_on = false;
             }
             if ($method_check != false) {
                 if (!method_exists($method_check, $function_check)) {
                     echo PHP_EOL . 'Method check fails.' . PHP_EOL;
                     continue;
                 }
                 $function_check = array($method_check, $function_check);
             } else {
                 if (!function_exists($function_check)) {
                     continue;
                 }
             }
             if ($argument_check->get_argument_index() == 'VARIABLE_LENGTH') {
                 $return_value = null;
                 foreach ($pass_args as $arg) {
                     $return_value = call_user_func_array($function_check, array($arg));
                     if ($return_value == true) {
                         break;
                     }
                 }
             } else {
                 $return_value = call_user_func_array($function_check, array(isset($pass_args[$argument_check->get_argument_index()]) ? $pass_args[$argument_check->get_argument_index()] : null));
             }
             if ($return_value == $return_fails_on) {
                 $command_alias = defined($command . '::doc_use_alias') ? constant($command . '::doc_use_alias') : $command;
                 if (isset($pass_args[$argument_check->get_argument_index()]) && !empty($pass_args[$argument_check->get_argument_index()]) || $argument_check->get_argument_index() == 'VARIABLE_LENGTH' && !empty($pass_args)) {
                     trigger_error('Invalid Argument: ' . implode(' ', $pass_args), E_USER_ERROR);
                 } else {
                     trigger_error('Phoronix Test Suite Argument Missing.', E_USER_ERROR);
                 }
                 echo PHP_EOL . 'CORRECT SYNTAX:' . PHP_EOL . 'phoronix-test-suite ' . str_replace('_', '-', $command_alias) . ' ' . implode(' ', $argument_checks) . PHP_EOL . PHP_EOL;
                 if (method_exists($command, 'invalid_command')) {
                     call_user_func_array(array($command, 'invalid_command'), $pass_args);
                     echo PHP_EOL;
                 }
                 return false;
             } else {
                 if ($argument_check->get_function_return_key() != null && !isset($pass_args[$argument_check->get_function_return_key()])) {
                     $pass_args[$argument_check->get_function_return_key()] = $return_value;
                 }
             }
         }
     }
     pts_module_manager::module_process('__pre_option_process', $command);
     if (is_file(PTS_COMMAND_PATH . $command . '.php')) {
         self::$current_command = $command;
         if (method_exists($command, 'run')) {
             call_user_func(array($command, 'run'), $pass_args);
         } else {
             echo PHP_EOL . 'There is an error in the requested command: ' . $command . PHP_EOL . PHP_EOL;
         }
     } else {
         if (($t = pts_module::valid_run_command($command)) != false) {
             list($module, $module_command) = $t;
             pts_module_manager::set_current_module($module);
             pts_module_manager::run_command($module, $module_command, $pass_args);
             pts_module_manager::set_current_module(null);
         }
     }
     echo PHP_EOL;
     pts_module_manager::module_process('__post_option_process', $command);
 }
 public static function run($r)
 {
     $pdf = new pts_pdf_template(pts_title(false), 'Test Client Documentation');
     $html_doc = new pts_html_template(pts_title(false), 'Test Client Documentation');
     $pdf->AddPage();
     $pdf->Image(PTS_CORE_STATIC_PATH . 'images/pts-308x160.png', 69, 85, 73, 38, 'PNG', 'http://www.phoronix-test-suite.com/');
     $pdf->Ln(120);
     $pdf->WriteStatement('www.phoronix-test-suite.com', 'C', 'http://www.phoronix-test-suite.com/');
     $pdf->Ln(15);
     $pdf->WriteBigHeaderCenter(pts_title(true));
     $pdf->WriteHeaderCenter('User Manual');
     //$pdf->WriteText($result_file->get_description());
     $pts_options = pts_documentation::client_commands_array();
     // Write the test options HTML
     $dom = new DOMDocument();
     $html = $dom->createElement('html');
     $dom->appendChild($html);
     $head = $dom->createElement('head');
     $title = $dom->createElement('title', 'User Options');
     $head->appendChild($title);
     $html->appendChild($head);
     $body = $dom->createElement('body');
     $html->appendChild($body);
     $p = $dom->createElement('p', 'The following options are currently supported by the Phoronix Test Suite client. A list of available options can also be found by running ');
     $em = $dom->createElement('em', 'phoronix-test-suite help.');
     $p->appendChild($em);
     $phr = $dom->createElement('hr');
     $p->appendChild($phr);
     $body->appendChild($p);
     foreach ($pts_options as $section => &$contents) {
         if (empty($contents)) {
             continue;
         }
         $header = $dom->createElement('h1', $section);
         $body->appendChild($header);
         sort($contents);
         foreach ($contents as &$option) {
             $sub_header = $dom->createElement('h3', $option[0]);
             $em = $dom->CreateElement('em', '  ' . implode(' ', $option[1]));
             $sub_header->appendChild($em);
             $body->appendChild($sub_header);
             $p = $dom->createElement('p', $option[2]);
             $body->appendChild($p);
         }
     }
     $dom->saveHTMLFile(PTS_PATH . 'documentation/stubs/00_user_options.html');
     // Write the module options HTML
     $dom = new DOMDocument();
     $html = $dom->createElement('html');
     $dom->appendChild($html);
     $head = $dom->createElement('head');
     $title = $dom->createElement('title', 'Module Options');
     $head->appendChild($title);
     $html->appendChild($head);
     $body = $dom->createElement('body');
     $html->appendChild($body);
     $p = $dom->createElement('p', 'The following list is the modules included with the Phoronix Test Suite that are intended to extend the functionality of pts-core. Some of these options have commands that can be run directly in a similiar manner to the other Phoronix Test Suite user commands. Some modules are just meant to be loaded directly by adding the module name to the LoadModules tag in ~/.phoronix-test-suite/user-config.xml or via the PTS_MODULES environmental variable. A list of available modules is also available by running ');
     $em = $dom->createElement('em', 'phoronix-test-suite list-modules.');
     $p->appendChild($em);
     $phr = $dom->createElement('hr');
     $p->appendChild($phr);
     $body->appendChild($p);
     foreach (pts_module_manager::available_modules(true) as $module) {
         pts_module_manager::load_module($module);
         $header = $dom->createElement('h2', pts_module_manager::module_call($module, 'module_name'));
         $body->appendChild($header);
         $desc = $dom->createElement('p', pts_module_manager::module_call($module, 'module_description'));
         $body->appendChild($desc);
         $all_options = pts_module_manager::module_call($module, 'user_commands');
         if (count($all_options) > 0) {
             //	$sub_header = $dom->createElement('h3', 'Module Commands');
             //	$body->appendChild($sub_header);
             foreach ($all_options as $key => $option) {
                 $p = $dom->createElement('p', 'phoronix-test-suite ' . $module . '.' . str_replace('_', '-', $key));
                 $body->appendChild($p);
             }
         }
         $vars = pts_module_manager::module_call($module, 'module_environmental_variables');
         if (is_array($vars) && count($vars) > 0) {
             $p = $dom->createElement('p', 'This module utilizes the following environmental variables: ' . implode(', ', $vars) . '.');
             $body->appendChild($p);
         }
     }
     $dom->saveHTMLFile(PTS_PATH . 'documentation/stubs/00_zmodule_options.html');
     // Write the external dependencies HTML
     $dom = new DOMDocument();
     $html = $dom->createElement('html');
     $dom->appendChild($html);
     $head = $dom->createElement('head');
     $title = $dom->createElement('title', 'External Dependencies');
     $head->appendChild($title);
     $html->appendChild($head);
     $body = $dom->createElement('body');
     $html->appendChild($body);
     $p = $dom->createElement('p', 'The Phoronix Test Suite has a feature known as &quot;External Dependencies&quot; where the Phoronix Test Suite can attempt to automatically install some of the test-specific dependencies on supported distributions. If running on a distribution where there is currently no External Dependencies profile, the needed package name(s) are listed for manual installation.');
     $body->appendChild($p);
     $p = $dom->createElement('p', 'Below are a list of the operating systems that currently have external dependencies support within the Phoronix Test Suite for the automatic installation of needed test files.');
     $body->appendChild($p);
     $phr = $dom->createElement('hr');
     $p->appendChild($phr);
     $exdep_generic_parser = new pts_exdep_generic_parser();
     $vendors = array_merge($exdep_generic_parser->get_vendor_aliases_formatted(), $exdep_generic_parser->get_vendors_list_formatted());
     sort($vendors);
     $ul = $dom->createElement('ul');
     $p->appendChild($ul);
     foreach ($vendors as $vendor) {
         $li = $dom->createElement('li', $vendor);
         $p->appendChild($li);
     }
     $dom->saveHTMLFile(PTS_PATH . 'documentation/stubs/02_external_dependencies.html');
     // Write the virtual suites HTML
     $dom = new DOMDocument();
     $html = $dom->createElement('html');
     $dom->appendChild($html);
     $head = $dom->createElement('head');
     $title = $dom->createElement('title', 'Virtual Test Suites');
     $head->appendChild($title);
     $html->appendChild($head);
     $body = $dom->createElement('body');
     $html->appendChild($body);
     $p = $dom->createElement('p', 'Virtual test suites are not like a traditional test suite defined by the XML suite specification. Virtual test suites are dynamically generated in real-time by the Phoronix Test Suite client based upon the specified test critera. Virtual test suites can automatically consist of all test profiles that are compatible with a particular operating system or test profiles that meet other critera. When running a virtual suite, the OpenBenchmarking.org repository of the test profiles to use for generating the dynamic suite must be prefixed. ');
     $body->appendChild($p);
     $p = $dom->createElement('p', 'Virtual test suites can be installed and run just like a normal XML test suite and shares nearly all of the same capabilities. However, when running a virtual suite, the user will be prompted to input any user-configuration options for needed test profiles just as they would need to do if running the test individually. When running a virtual suite, the user also has the ability to select individual tests within the suite to run or to run all of the contained test profiles. Virtual test suites are also only supported for an OpenBenchmarking.org repository if there is no test profile or test suite of the same name in the repository. Below is a list of common virtual test suites for the main Phoronix Test Suite repository, but the dynamic list of available virtual test suites based upon the enabled repositories is available by running ');
     $em = $dom->createElement('em', 'phoronix-test-suite list-available-virtual-suites.');
     $p->appendChild($em);
     $phr = $dom->createElement('hr');
     $p->appendChild($phr);
     $body->appendChild($p);
     foreach (pts_virtual_test_suite::available_virtual_suites() as $virtual_suite) {
         $sub_header = $dom->createElement('h3', $virtual_suite->get_title());
         $em = $dom->CreateElement('em', '  ' . $virtual_suite->get_identifier());
         $sub_header->appendChild($em);
         $body->appendChild($sub_header);
         $p = $dom->createElement('p', $virtual_suite->get_description());
         $body->appendChild($p);
     }
     $dom->saveHTMLFile(PTS_PATH . 'documentation/stubs/55_virtual_suites.html');
     // Load the HTML documentation
     foreach (pts_file_io::glob(PTS_PATH . 'documentation/stubs/*_*.html') as $html_file) {
         $pdf->html_to_pdf($html_file);
         $html_doc->html_to_html($html_file);
     }
     if (!is_writable(PTS_PATH . 'documentation/')) {
         echo PHP_EOL . 'Not writable: ' . PTS_PATH . 'documentation/';
     } else {
         $pdf_file = PTS_PATH . 'documentation/phoronix-test-suite.pdf';
         $pdf->Output($pdf_file);
         $html_doc->Output(PTS_PATH . 'documentation/phoronix-test-suite.html');
         echo PHP_EOL . 'Saved To: ' . $pdf_file . PHP_EOL . PHP_EOL;
         // Also re-generate the man page
         $man_page = '.TH phoronix-test-suite 1  "www.phoronix-test-suite.com" "' . PTS_VERSION . '"' . PHP_EOL . '.SH NAME' . PHP_EOL;
         $man_page .= 'phoronix-test-suite \\- The Phoronix Test Suite is an extensible open-source platform for performing testing and performance evaluation.' . PHP_EOL;
         $man_page .= '.SH SYNOPSIS' . PHP_EOL . '.B phoronix-test-suite [options]' . PHP_EOL . '.br' . PHP_EOL . '.B phoronix-test-suite benchmark [test | suite]' . PHP_EOL;
         $man_page .= '.SH DESCRIPTION' . PHP_EOL . pts_documentation::basic_description() . PHP_EOL;
         $man_page .= '.SH OPTIONS' . PHP_EOL . '.TP' . PHP_EOL;
         foreach ($pts_options as $section => &$contents) {
             if (empty($contents)) {
                 continue;
             }
             $man_page .= '.SH ' . strtoupper($section) . PHP_EOL;
             sort($contents);
             foreach ($contents as &$option) {
                 $man_page .= '.B ' . trim($option[0] . ' ' . (!empty($option[1]) && is_array($option[1]) ? implode(' ', $option[1]) : null)) . PHP_EOL . $option[2] . PHP_EOL . '.TP' . PHP_EOL;
             }
         }
         $man_page .= '.SH SEE ALSO' . PHP_EOL . '.B Websites:' . PHP_EOL . '.br' . PHP_EOL . 'http://www.phoronix-test-suite.com/' . PHP_EOL . '.br' . PHP_EOL . 'http://commercial.phoronix-test-suite.com/' . PHP_EOL . '.br' . PHP_EOL . 'http://www.openbenchmarking.org/' . PHP_EOL . '.br' . PHP_EOL . 'http://www.phoronix.com/' . PHP_EOL . '.br' . PHP_EOL . 'http://www.phoronix.com/forums/' . PHP_EOL;
         $man_page .= '.SH AUTHORS' . PHP_EOL . 'Copyright 2008 - ' . date('Y') . ' by Phoronix Media, Michael Larabel.' . PHP_EOL . '.TP' . PHP_EOL;
         file_put_contents(PTS_PATH . 'documentation/man-pages/phoronix-test-suite.1', $man_page);
     }
     // simple README
     $readme = '# Phoronix Test Suite ' . PTS_VERSION . PHP_EOL . 'http://www.phoronix-test-suite.com/' . PHP_EOL . PHP_EOL;
     $readme .= pts_documentation::basic_description() . PHP_EOL . PHP_EOL;
     $readme .= pts_file_io::file_get_contents(PTS_PATH . 'documentation/stubs/readme-basics.txt') . PHP_EOL . PHP_EOL;
     $readme = wordwrap($readme, 80, PHP_EOL);
     file_put_contents(PTS_PATH . 'README.md', $readme);
     // Phoromatic Documentation
     $pdf = new pts_pdf_template(pts_title(false), 'Phoromatic Documentation');
     $html_doc = new pts_html_template(pts_title(false), 'Phoromatic Documentation');
     $pdf->AddPage();
     $pdf->Image(PTS_CORE_STATIC_PATH . 'images/pts-308x160.png', 69, 85, 73, 38, 'PNG', 'http://www.phoronix-test-suite.com/');
     $pdf->Ln(120);
     $pdf->WriteStatement('www.phoronix-test-suite.com', 'C', 'http://www.phoronix-test-suite.com/');
     $pdf->Ln(15);
     $pdf->Image(PTS_CORE_STATIC_PATH . 'images/phoromatic-390x56.png', 55, 250, 0, 0, 'PNG', 'http://www.phoronix-test-suite.com/');
     //$pdf->Image(PTS_CORE_STATIC_PATH . 'images/phoromatic-390x56.png', 69, 85, 73, 38, 'PNG', 'http://www.phoromatic.com/');
     $pdf->WriteBigHeaderCenter(pts_title(true));
     $pdf->WriteHeaderCenter('Phoromatic User Manual');
     $pdf->html_to_pdf(PTS_PATH . 'documentation/phoromatic.html');
     $pdf_file = PTS_PATH . 'documentation/phoromatic.pdf';
     $pdf->Output($pdf_file);
     echo PHP_EOL . 'Saved To: ' . $pdf_file . PHP_EOL . PHP_EOL;
 }
 public static function upload_test_result(&$object, $return_json_data = false)
 {
     if ($object instanceof pts_test_run_manager) {
         $result_file = new pts_result_file($object->get_file_name());
         $local_file_name = $object->get_file_name();
         $results_identifier = $object->get_results_identifier();
     } else {
         if ($object instanceof pts_result_file) {
             $result_file =& $object;
             $local_file_name = $result_file->get_identifier();
             $results_identifier = null;
         }
     }
     // Ensure the results can be shared
     if (self::result_upload_supported($result_file) == false) {
         return false;
     }
     if (pts_network::internet_support_available() == false) {
         echo PHP_EOL . 'No network support available.' . PHP_EOL;
         return false;
     }
     $composite_xml = $result_file->getRawXml();
     $system_log_dir = PTS_SAVE_RESULTS_PATH . $result_file->get_identifier() . '/system-logs/';
     $upload_system_logs = false;
     if (is_dir($system_log_dir)) {
         if (pts_config::read_bool_config('PhoronixTestSuite/Options/OpenBenchmarking/AlwaysUploadSystemLogs', 'FALSE')) {
             $upload_system_logs = true;
         } else {
             if (isset(self::$client_settings['UploadSystemLogsByDefault'])) {
                 $upload_system_logs = self::$client_settings['UploadSystemLogsByDefault'];
             } else {
                 if (is_dir($system_log_dir)) {
                     $upload_system_logs = pts_user_io::prompt_bool_input('Would you like to attach the system logs (lspci, dmesg, lsusb, etc) to the test result', true, 'UPLOAD_SYSTEM_LOGS');
                 }
             }
         }
     }
     $system_logs = null;
     $system_logs_hash = null;
     if ($upload_system_logs) {
         $is_valid_log = true;
         $finfo = function_exists('finfo_open') ? finfo_open(FILEINFO_MIME_TYPE) : false;
         foreach (pts_file_io::glob($system_log_dir . '*') as $log_dir) {
             if ($is_valid_log == false || !is_dir($log_dir)) {
                 $is_valid_log = false;
                 break;
             }
             foreach (pts_file_io::glob($log_dir . '/*') as $log_file) {
                 if (!is_file($log_file)) {
                     $is_valid_log = false;
                     break;
                 }
                 if ($finfo && substr(finfo_file($finfo, $log_file), 0, 5) != 'text/') {
                     $is_valid_log = false;
                     break;
                 }
             }
         }
         if ($is_valid_log) {
             $system_logs_zip = pts_client::create_temporary_file('.zip');
             pts_compression::zip_archive_create($system_logs_zip, $system_log_dir);
             if (filesize($system_logs_zip) < 2097152) {
                 // If it's over 2MB, probably too big
                 $system_logs = base64_encode(file_get_contents($system_logs_zip));
                 $system_logs_hash = sha1($system_logs);
             } else {
                 trigger_error('The systems log attachment is too large to upload to OpenBenchmarking.org.', E_USER_WARNING);
             }
             unlink($system_logs_zip);
         }
     }
     $composite_xml_hash = sha1($composite_xml);
     $composite_xml_type = 'composite_xml';
     // Compress the result file XML if it's big
     if (isset($composite_xml[50000]) && function_exists('gzdeflate')) {
         $composite_xml_gz = gzdeflate($composite_xml);
         if ($composite_xml_gz != false) {
             $composite_xml = $composite_xml_gz;
             $composite_xml_type = 'composite_xml_gz';
         }
     }
     $to_post = array($composite_xml_type => base64_encode($composite_xml), 'composite_xml_hash' => $composite_xml_hash, 'local_file_name' => $local_file_name, 'this_results_identifier' => $results_identifier, 'system_logs_zip' => $system_logs, 'system_logs_hash' => $system_logs_hash);
     if (isset(self::$client_settings['ResultUploadsDefaultDisplayStatus']) && is_numeric(self::$client_settings['ResultUploadsDefaultDisplayStatus'])) {
         $to_post['display_status'] = self::$client_settings['ResultUploadsDefaultDisplayStatus'];
     }
     $json_response = pts_openbenchmarking::make_openbenchmarking_request('upload_test_result', $to_post);
     $json_response = json_decode($json_response, true);
     if (!is_array($json_response)) {
         trigger_error('Unhandled Exception', E_USER_ERROR);
         return false;
     }
     if (isset($json_response['openbenchmarking']['upload']['error'])) {
         trigger_error($json_response['openbenchmarking']['upload']['error'], E_USER_ERROR);
     }
     if (isset($json_response['openbenchmarking']['upload']['url'])) {
         echo PHP_EOL . 'Results Uploaded To: ' . $json_response['openbenchmarking']['upload']['url'] . PHP_EOL;
         pts_module_manager::module_process('__event_openbenchmarking_upload', $json_response);
     }
     //$json['openbenchmarking']['upload']['id']
     if (isset(self::$client_settings['RemoveLocalResultsOnUpload']) && self::$client_settings['RemoveLocalResultsOnUpload'] && $local_file_name != null) {
         pts_client::remove_saved_result_file($local_file_name);
     }
     if ($return_json_data) {
         return isset($json_response['openbenchmarking']['upload']) ? $json_response['openbenchmarking']['upload'] : false;
     }
     return isset($json_response['openbenchmarking']['upload']['url']) ? $json_response['openbenchmarking']['upload']['url'] : false;
 }
 private static function module_name()
 {
     $module_name = 'unknown';
     if (($current = pts_module_manager::get_current_module()) != null) {
         $module_name = $current;
     } else {
         $bt = debug_backtrace();
         for ($i = 0; $i < count($bt) && $module_name == "unknown"; $i++) {
             if ($bt[$i]["class"] != "pts_module") {
                 $module_name = $bt[$i]["class"];
             }
         }
     }
     return $module_name;
 }
 public static function run_test(&$test_run_manager, &$test_run_request)
 {
     $test_identifier = $test_run_request->test_profile->get_identifier();
     $extra_arguments = $test_run_request->get_arguments();
     $arguments_description = $test_run_request->get_arguments_description();
     $full_output = pts_config::read_bool_config('PhoronixTestSuite/Options/General/FullOutput', 'FALSE');
     // Do the actual test running process
     $test_directory = $test_run_request->test_profile->get_install_dir();
     if (!is_dir($test_directory)) {
         return false;
     }
     $lock_file = $test_directory . 'run_lock';
     if (pts_client::create_lock($lock_file) == false && $test_run_manager->is_multi_test_stress_run() == false) {
         self::test_run_error($test_run_manager, $test_run_request, 'The ' . $test_identifier . ' test is already running.');
         return false;
     }
     $active_result_buffer = new pts_test_result_buffer_active();
     $test_run_request->active =& $active_result_buffer;
     $execute_binary = $test_run_request->test_profile->get_test_executable();
     $times_to_run = $test_run_request->test_profile->get_times_to_run();
     $ignore_runs = $test_run_request->test_profile->get_runs_to_ignore();
     $test_type = $test_run_request->test_profile->get_test_hardware_type();
     $allow_cache_share = $test_run_request->test_profile->allow_cache_share();
     $min_length = $test_run_request->test_profile->get_min_length();
     $max_length = $test_run_request->test_profile->get_max_length();
     if ($test_run_request->test_profile->get_environment_testing_size() > 1 && ceil(disk_free_space($test_directory) / 1048576) < $test_run_request->test_profile->get_environment_testing_size()) {
         // Ensure enough space is available on disk during testing process
         self::test_run_error($test_run_manager, $test_run_request, 'There is not enough space (at ' . $test_directory . ') for this test to run.');
         pts_client::release_lock($lock_file);
         return false;
     }
     $to_execute = $test_run_request->test_profile->get_test_executable_dir();
     $pts_test_arguments = trim($test_run_request->test_profile->get_default_arguments() . ' ' . str_replace($test_run_request->test_profile->get_default_arguments(), '', $extra_arguments) . ' ' . $test_run_request->test_profile->get_default_post_arguments());
     $extra_runtime_variables = pts_tests::extra_environmental_variables($test_run_request->test_profile);
     // Start
     $cache_share_pt2so = $test_directory . 'cache-share-' . PTS_INIT_TIME . '.pt2so';
     $cache_share_present = $allow_cache_share && is_file($cache_share_pt2so);
     $test_run_request->set_used_arguments_description($arguments_description);
     pts_module_manager::module_process('__pre_test_run', $test_run_request);
     $time_test_start = time();
     pts_client::$display->test_run_start($test_run_manager, $test_run_request);
     if (!$cache_share_present) {
         $pre_output = pts_tests::call_test_script($test_run_request->test_profile, 'pre', 'Running Pre-Test Script', $pts_test_arguments, $extra_runtime_variables, true);
         if ($pre_output != null && (pts_client::is_debug_mode() || $full_output)) {
             pts_client::$display->test_run_instance_output($pre_output);
         }
         if (is_file($test_directory . 'pre-test-exit-status')) {
             // If the pre script writes its exit status to ~/pre-test-exit-status, if it's non-zero the test run failed
             $exit_status = pts_file_io::file_get_contents($test_directory . 'pre-test-exit-status');
             unlink($test_directory . 'pre-test-exit-status');
             if ($exit_status != 0) {
                 self::test_run_instance_error($test_run_manager, $test_run_request, 'The pre run script exited with a non-zero exit status.' . PHP_EOL);
                 self::test_run_error($test_run_manager, $test_run_request, 'This test execution has been abandoned.');
                 return false;
             }
         }
     }
     pts_client::$display->display_interrupt_message($test_run_request->test_profile->get_pre_run_message());
     $runtime_identifier = time();
     $execute_binary_prepend = '';
     if ($test_run_request->exec_binary_prepend != null) {
         $execute_binary_prepend = $test_run_request->exec_binary_prepend;
     }
     if (!$cache_share_present && $test_run_request->test_profile->is_root_required()) {
         if (phodevi::is_root() == false) {
             pts_client::$display->test_run_error('This test must be run as the root / administrator account.');
         }
         $execute_binary_prepend .= ' ' . PTS_CORE_STATIC_PATH . 'root-access.sh ';
     }
     if ($allow_cache_share && !is_file($cache_share_pt2so)) {
         $cache_share = new pts_storage_object(false, false);
     }
     if ($test_run_manager->get_results_identifier() != null && $test_run_manager->get_file_name() != null && pts_config::read_bool_config('PhoronixTestSuite/Options/Testing/SaveTestLogs', 'FALSE')) {
         $backup_test_log_dir = PTS_SAVE_RESULTS_PATH . $test_run_manager->get_file_name() . '/test-logs/active/' . $test_run_manager->get_results_identifier() . '/';
         pts_file_io::delete($backup_test_log_dir);
         pts_file_io::mkdir($backup_test_log_dir, 0777, true);
     } else {
         $backup_test_log_dir = false;
     }
     for ($i = 0, $abort_testing = false, $time_test_start_actual = time(), $defined_times_to_run = $times_to_run; $i < $times_to_run && $i < 256 && !$abort_testing; $i++) {
         pts_client::$display->test_run_instance_header($test_run_request);
         $test_log_file = $test_directory . basename($test_identifier) . '-' . $runtime_identifier . '-' . ($i + 1) . '.log';
         $is_expected_last_run = $i == $times_to_run - 1;
         $test_extra_runtime_variables = array_merge($extra_runtime_variables, array('LOG_FILE' => $test_log_file, 'DISPLAY' => getenv('DISPLAY'), 'PATH' => getenv('PATH')));
         $restored_from_cache = false;
         if ($cache_share_present) {
             $cache_share = pts_storage_object::recover_from_file($cache_share_pt2so);
             if ($cache_share) {
                 $test_result = $cache_share->read_object('test_results_output_' . $i);
                 $test_extra_runtime_variables['LOG_FILE'] = $cache_share->read_object('log_file_location_' . $i);
                 if ($test_extra_runtime_variables['LOG_FILE'] != null) {
                     file_put_contents($test_extra_runtime_variables['LOG_FILE'], $cache_share->read_object('log_file_' . $i));
                     $test_run_time = 0;
                     // This wouldn't be used for a cache share since it would always be the same, but declare the value so the variable is at least initialized
                     $restored_from_cache = true;
                 }
             }
             unset($cache_share);
         }
         if ($restored_from_cache == false) {
             $test_run_command = 'cd ' . $to_execute . ' && ' . $execute_binary_prepend . './' . $execute_binary . ' ' . $pts_test_arguments . ' 2>&1';
             pts_client::test_profile_debug_message('Test Run Command: ' . $test_run_command);
             $is_monitoring = pts_test_result_parser::system_monitor_task_check($test_run_request->test_profile);
             $test_run_time_start = time();
             if (phodevi::is_windows() || pts_client::read_env('USE_PHOROSCRIPT_INTERPRETER') != false) {
                 $phoroscript = new pts_phoroscript_interpreter($to_execute . '/' . $execute_binary, $test_extra_runtime_variables, $to_execute);
                 $phoroscript->execute_script($pts_test_arguments);
                 $test_result = null;
             } else {
                 //$test_result = pts_client::shell_exec($test_run_command, $test_extra_runtime_variables);
                 $descriptorspec = array(0 => array('pipe', 'r'), 1 => array('pipe', 'w'), 2 => array('pipe', 'w'));
                 $test_process = proc_open('exec ' . $execute_binary_prepend . './' . $execute_binary . ' ' . $pts_test_arguments . ' 2>&1', $descriptorspec, $pipes, $to_execute, array_merge($_ENV, pts_client::environmental_variables(), $test_extra_runtime_variables));
                 if (is_resource($test_process)) {
                     //echo proc_get_status($test_process)['pid'];
                     pts_module_manager::module_process('__test_running', $test_process);
                     $test_result = stream_get_contents($pipes[1]);
                     fclose($pipes[1]);
                     fclose($pipes[2]);
                     $return_value = proc_close($test_process);
                 }
             }
             $test_run_time = time() - $test_run_time_start;
             $monitor_result = $is_monitoring ? pts_test_result_parser::system_monitor_task_post_test($test_run_request->test_profile) : 0;
         }
         if (!isset($test_result[10240]) || pts_client::is_debug_mode() || $full_output) {
             pts_client::$display->test_run_instance_output($test_result);
         }
         if (is_file($test_log_file) && trim($test_result) == null && (filesize($test_log_file) < 10240 || pts_client::is_debug_mode() || $full_output)) {
             $test_log_file_contents = file_get_contents($test_log_file);
             pts_client::$display->test_run_instance_output($test_log_file_contents);
             unset($test_log_file_contents);
         }
         $test_run_request->test_result_standard_output = $test_result;
         $exit_status_pass = true;
         if (is_file($test_directory . 'test-exit-status')) {
             // If the test script writes its exit status to ~/test-exit-status, if it's non-zero the test run failed
             $exit_status = pts_file_io::file_get_contents($test_directory . 'test-exit-status');
             unlink($test_directory . 'test-exit-status');
             if ($exit_status != 0) {
                 self::test_run_instance_error($test_run_manager, $test_run_request, 'The test exited with a non-zero exit status.');
                 if ($is_expected_last_run && is_file($test_log_file)) {
                     $scan_log = pts_file_io::file_get_contents($test_log_file);
                     $test_run_error = pts_tests::scan_for_error($scan_log, $test_run_request->test_profile->get_test_executable_dir());
                     if ($test_run_error) {
                         self::test_run_instance_error($test_run_manager, $test_run_request, 'E: ' . $test_run_error);
                     }
                 }
                 $exit_status_pass = false;
             }
         }
         if (!in_array($i + 1, $ignore_runs) && $exit_status_pass) {
             if (isset($monitor_result) && $monitor_result != 0) {
                 $test_run_request->active->active_result = $monitor_result;
             } else {
                 pts_test_result_parser::parse_result($test_run_request, $test_extra_runtime_variables['LOG_FILE']);
             }
             pts_client::test_profile_debug_message('Test Result Value: ' . $test_run_request->active->active_result);
             if (!empty($test_run_request->active->active_result)) {
                 if ($test_run_time < 2 && intval($test_run_request->active->active_result) == $test_run_request->active->active_result && $test_run_request->test_profile->get_estimated_run_time() > 60 && !$restored_from_cache) {
                     // If the test ended in less than two seconds, outputted some int, and normally the test takes much longer, then it's likely some invalid run
                     self::test_run_instance_error($test_run_manager, $test_run_request, 'The test run ended prematurely.');
                     if ($is_expected_last_run && is_file($test_log_file)) {
                         $scan_log = pts_file_io::file_get_contents($test_log_file);
                         $test_run_error = pts_tests::scan_for_error($scan_log, $test_run_request->test_profile->get_test_executable_dir());
                         if ($test_run_error) {
                             self::test_run_instance_error($test_run_manager, $test_run_request, 'E: ' . $test_run_error);
                         }
                     }
                 } else {
                     // TODO integrate active_result into active buffer
                     $active_result_buffer->add_trial_run_result($test_run_request->active->active_result, $test_run_request->active->active_min_result, $test_run_request->active->active_max_result);
                 }
             } else {
                 if ($test_run_request->test_profile->get_display_format() != 'NO_RESULT') {
                     self::test_run_instance_error($test_run_manager, $test_run_request, 'The test run did not produce a result.');
                     if ($is_expected_last_run && is_file($test_log_file)) {
                         $scan_log = pts_file_io::file_get_contents($test_log_file);
                         $test_run_error = pts_tests::scan_for_error($scan_log, $test_run_request->test_profile->get_test_executable_dir());
                         if ($test_run_error) {
                             self::test_run_instance_error($test_run_manager, $test_run_request, 'E: ' . $test_run_error);
                         }
                     }
                 }
             }
             if ($allow_cache_share && !is_file($cache_share_pt2so)) {
                 $cache_share->add_object('test_results_output_' . $i, $test_run_request->active->active_result);
                 $cache_share->add_object('log_file_location_' . $i, $test_extra_runtime_variables['LOG_FILE']);
                 $cache_share->add_object('log_file_' . $i, is_file($test_log_file) ? file_get_contents($test_log_file) : null);
             }
         }
         if ($is_expected_last_run && $active_result_buffer->get_trial_run_count() > floor(($i - 2) / 2) && !$cache_share_present && $test_run_manager->do_dynamic_run_count()) {
             // The later check above ensures if the test is failing often the run count won't uselessly be increasing
             // Should we increase the run count?
             $increase_run_count = false;
             if ($defined_times_to_run == $i + 1 && $active_result_buffer->get_trial_run_count() > 0 && $active_result_buffer->get_trial_run_count() < $defined_times_to_run && $i < 64) {
                 // At least one run passed, but at least one run failed to produce a result. Increase count to try to get more successful runs
                 $increase_run_count = $defined_times_to_run - $active_result_buffer->get_trial_run_count();
             } else {
                 if ($active_result_buffer->get_trial_run_count() >= 2) {
                     // Dynamically increase run count if needed for statistical significance or other reasons
                     $increase_run_count = $test_run_manager->increase_run_count_check($active_result_buffer, $defined_times_to_run, $test_run_time);
                     if ($increase_run_count === -1) {
                         $abort_testing = true;
                     } else {
                         if ($increase_run_count == true) {
                             // Just increase the run count one at a time
                             $increase_run_count = 1;
                         }
                     }
                 }
             }
             if ($increase_run_count > 0) {
                 $times_to_run += $increase_run_count;
                 $is_expected_last_run = false;
                 //$test_run_request->test_profile->set_times_to_run($times_to_run);
             }
         }
         if ($times_to_run > 1 && $i < $times_to_run - 1) {
             if ($cache_share_present == false) {
                 $interim_output = pts_tests::call_test_script($test_run_request->test_profile, 'interim', 'Running Interim Test Script', $pts_test_arguments, $extra_runtime_variables, true);
                 if ($interim_output != null && (pts_client::is_debug_mode() || $full_output)) {
                     pts_client::$display->test_run_instance_output($interim_output);
                 }
                 //sleep(2); // Rest for a moment between tests
             }
             pts_module_manager::module_process('__interim_test_run', $test_run_request);
         }
         if (is_file($test_log_file)) {
             if ($is_expected_last_run) {
                 // For now just passing the last test log file...
                 // TODO XXX: clean this up with log files to preserve when needed, let multiple log files exist for extra_data, etc
                 pts_test_result_parser::generate_extra_data($test_run_request, $test_log_file);
             }
             if ($backup_test_log_dir) {
                 copy($test_log_file, $backup_test_log_dir . basename($test_log_file));
             }
             if (pts_client::test_profile_debug_message('Log File At: ' . $test_log_file) == false) {
                 unlink($test_log_file);
             }
         }
         if (is_file(PTS_USER_PATH . 'halt-testing') || is_file(PTS_USER_PATH . 'skip-test')) {
             pts_client::release_lock($lock_file);
             return false;
         }
         pts_client::$display->test_run_instance_complete($test_run_request);
     }
     $time_test_end_actual = time();
     if ($cache_share_present == false) {
         $post_output = pts_tests::call_test_script($test_run_request->test_profile, 'post', 'Running Post-Test Script', $pts_test_arguments, $extra_runtime_variables, true);
         if ($post_output != null && (pts_client::is_debug_mode() || $full_output)) {
             pts_client::$display->test_run_instance_output($post_output);
         }
         if (is_file($test_directory . 'post-test-exit-status')) {
             // If the post script writes its exit status to ~/post-test-exit-status, if it's non-zero the test run failed
             $exit_status = pts_file_io::file_get_contents($test_directory . 'post-test-exit-status');
             unlink($test_directory . 'post-test-exit-status');
             if ($exit_status != 0) {
                 self::test_run_instance_error($test_run_manager, $test_run_request, 'The post run script exited with a non-zero exit status.' . PHP_EOL);
                 $abort_testing = true;
             }
         }
     }
     if ($abort_testing) {
         self::test_run_error($test_run_manager, $test_run_request, 'This test execution has been abandoned.');
         return false;
     }
     // End
     $time_test_end = time();
     $time_test_elapsed = $time_test_end - $time_test_start;
     $time_test_elapsed_actual = $time_test_end_actual - $time_test_start_actual;
     if (!empty($min_length)) {
         if ($min_length > $time_test_elapsed_actual) {
             // The test ended too quickly, results are not valid
             self::test_run_error($test_run_manager, $test_run_request, 'This test ended prematurely.');
             return false;
         }
     }
     if (!empty($max_length)) {
         if ($max_length < $time_test_elapsed_actual) {
             // The test took too much time, results are not valid
             self::test_run_error($test_run_manager, $test_run_request, 'This test run was exhausted.');
             return false;
         }
     }
     if ($allow_cache_share && !is_file($cache_share_pt2so) && $cache_share instanceof pts_storage_object) {
         $cache_share->save_to_file($cache_share_pt2so);
         unset($cache_share);
     }
     if ($test_run_manager->get_results_identifier() != null && pts_config::read_bool_config('PhoronixTestSuite/Options/Testing/SaveInstallationLogs', 'FALSE')) {
         if (is_file($test_run_request->test_profile->get_install_dir() . 'install.log')) {
             $backup_log_dir = PTS_SAVE_RESULTS_PATH . $test_run_manager->get_file_name() . '/installation-logs/' . $test_run_manager->get_results_identifier() . '/';
             pts_file_io::mkdir($backup_log_dir, 0777, true);
             copy($test_run_request->test_profile->get_install_dir() . 'install.log', $backup_log_dir . basename($test_identifier) . '.log');
         }
     }
     // Fill in missing test details
     if (empty($arguments_description)) {
         $arguments_description = $test_run_request->test_profile->get_test_subtitle();
     }
     $file_var_checks = array(array('pts-results-scale', 'set_result_scale', null), array('pts-results-proportion', 'set_result_proportion', null), array('pts-results-quantifier', 'set_result_quantifier', null), array('pts-test-version', 'set_version', null), array('pts-test-description', null, 'set_used_arguments_description'), array('pts-footnote', null, null));
     foreach ($file_var_checks as &$file_check) {
         list($file, $set_function, $result_set_function) = $file_check;
         if (is_file($test_directory . $file)) {
             $file_contents = pts_file_io::file_get_contents($test_directory . $file);
             unlink($test_directory . $file);
             if (!empty($file_contents)) {
                 if ($set_function != null) {
                     call_user_func(array($test_run_request->test_profile, $set_function), $file_contents);
                 } else {
                     if ($result_set_function != null) {
                         if ($result_set_function == 'set_used_arguments_description') {
                             $arguments_description = $file_contents;
                         } else {
                             call_user_func(array($test_run_request, $result_set_function), $file_contents);
                         }
                     } else {
                         if ($file == 'pts-footnote') {
                             $test_run_request->test_profile->test_installation->set_install_footnote($file_contents);
                         }
                     }
                 }
             }
         }
     }
     if (empty($arguments_description)) {
         $arguments_description = 'Phoronix Test Suite v' . PTS_VERSION;
     }
     foreach (pts_client::environmental_variables() as $key => $value) {
         $arguments_description = str_replace('$' . $key, $value, $arguments_description);
         if (!in_array($key, array('VIDEO_MEMORY', 'NUM_CPU_CORES', 'NUM_CPU_JOBS'))) {
             $extra_arguments = str_replace('$' . $key, $value, $extra_arguments);
         }
     }
     // Any device notes to add to PTS test notes area?
     foreach (phodevi::read_device_notes($test_type) as $note) {
         pts_test_notes_manager::add_note($note);
     }
     // As of PTS 4.4, this is removed and superceded effectively by reporting the notes to table
     // Any special information (such as forced AA/AF levels for graphics) to add to the description string of the result?
     /*
     if(($special_string = phodevi::read_special_settings_string($test_type)) != null)
     {
     	if(strpos($arguments_description, $special_string) === false)
     	{
     		if($arguments_description != null)
     		{
     			$arguments_description .= ' | ';
     		}
     
     		$arguments_description .= $special_string;
     	}
     }
     */
     // Result Calculation
     $test_run_request->set_used_arguments_description($arguments_description);
     $test_run_request->set_used_arguments($extra_arguments);
     pts_test_result_parser::calculate_end_result($test_run_request, $active_result_buffer);
     // Process results
     pts_client::$display->test_run_end($test_run_request);
     pts_client::$display->display_interrupt_message($test_run_request->test_profile->get_post_run_message());
     pts_module_manager::module_process('__post_test_run', $test_run_request);
     $report_elapsed_time = $cache_share_present == false && $test_run_request->active->get_result() != 0;
     pts_tests::update_test_install_xml($test_run_request->test_profile, $report_elapsed_time ? $time_test_elapsed : 0);
     pts_storage_object::add_in_file(PTS_CORE_STORAGE, 'total_testing_time', $time_test_elapsed / 60);
     if ($report_elapsed_time && pts_client::do_anonymous_usage_reporting() && $time_test_elapsed >= 60) {
         // If anonymous usage reporting enabled, report test run-time to OpenBenchmarking.org
         pts_openbenchmarking_client::upload_usage_data('test_complete', array($test_run_request, $time_test_elapsed));
     }
     // Remove lock
     pts_client::release_lock($lock_file);
     return $active_result_buffer;
 }
 public function determine_tests_to_run(&$to_run_objects)
 {
     $unique_test_count = count(array_unique($to_run_objects));
     $run_contains_a_no_result_type = false;
     $request_results_save = false;
     foreach ($to_run_objects as &$run_object) {
         // TODO: determine whether to print the titles of what's being run?
         if ($run_object instanceof pts_test_profile) {
             if ($run_object->get_identifier() == null || $run_object->get_title() == null || $this->validate_test_to_run($run_object) == false) {
                 continue;
             }
             if ($run_contains_a_no_result_type == false && $run_object->get_display_format() == 'NO_RESULT') {
                 $run_contains_a_no_result_type = true;
             }
             if ($request_results_save == false && $run_object->do_auto_save_results()) {
                 $request_results_save = true;
             }
             foreach (self::test_prompts_to_result_objects($run_object) as $result_object) {
                 $this->add_test_result_object($result_object);
             }
         } else {
             if ($run_object instanceof pts_test_suite) {
                 $this->pre_run_message = $run_object->get_pre_run_message();
                 $this->post_run_message = $run_object->get_post_run_message();
                 if ($run_object->get_run_mode() == 'PCQS') {
                     $this->is_pcqs = true;
                 }
                 foreach ($run_object->get_contained_test_result_objects() as $result_object) {
                     $this->add_test_result_object($result_object);
                 }
             } else {
                 if ($run_object instanceof pts_virtual_test_queue) {
                     foreach ($run_object->get_contained_test_result_objects() as $result_object) {
                         $this->add_test_result_object($result_object);
                     }
                 } else {
                     if ($run_object instanceof pts_result_file) {
                         // Print the $to_run ?
                         $this->run_description = $run_object->get_description();
                         $preset_vars = $run_object->get_preset_environment_variables();
                         $result_objects = $run_object->get_result_objects();
                         $this->set_save_name($run_object->get_identifier(), false);
                         $this->file_name_title = $run_object->get_title();
                         pts_module_manager::process_environment_variables_string_to_set($preset_vars);
                         foreach ($result_objects as &$result_object) {
                             if ($result_object->test_profile->get_identifier() == null) {
                                 continue;
                             }
                             $test_result = new pts_test_result($result_object->test_profile);
                             $test_result->set_used_arguments($result_object->get_arguments());
                             $test_result->set_used_arguments_description($result_object->get_arguments_description());
                             $this->add_test_result_object($test_result);
                         }
                     } else {
                         if ($run_object instanceof pts_virtual_test_suite) {
                             $virtual_suite_tests = $run_object->get_contained_test_profiles();
                             foreach (array_keys($virtual_suite_tests) as $i) {
                                 if ($virtual_suite_tests[$i]->is_supported(false) == false || $this->validate_test_to_run($virtual_suite_tests[$i]) == false) {
                                     unset($virtual_suite_tests[$i]);
                                 }
                             }
                             sort($virtual_suite_tests);
                             if (count($virtual_suite_tests) > 1) {
                                 array_push($virtual_suite_tests, 'All Tests In Suite');
                             }
                             if (!$this->auto_mode && !$this->batch_mode) {
                                 $run_index = explode(',', pts_user_io::prompt_text_menu('Select the tests in the virtual suite to run', $virtual_suite_tests, true, true));
                             } else {
                                 $run_index = -1;
                             }
                             if (count($virtual_suite_tests) > 2 && in_array(count($virtual_suite_tests) - 1, $run_index) || $run_index == -1) {
                                 // The appended 'All Tests In Suite' was selected, so run all
                             } else {
                                 foreach (array_keys($virtual_suite_tests) as $i) {
                                     if (!in_array($i, $run_index)) {
                                         unset($virtual_suite_tests[$i]);
                                     }
                                 }
                             }
                             foreach ($virtual_suite_tests as &$test_profile) {
                                 if ($test_profile instanceof pts_test_profile) {
                                     // The user is to configure virtual suites manually
                                     foreach (self::test_prompts_to_result_objects($test_profile) as $result_object) {
                                         $this->add_test_result_object($result_object);
                                     }
                                 }
                             }
                         } else {
                             trigger_error($run_object . ' is not recognized.', E_USER_ERROR);
                             continue;
                         }
                     }
                 }
             }
         }
     }
     // AlwaysUploadResultsToOpenBenchmarking AutoSortRunQueue
     if (pts_config::read_bool_config('PhoronixTestSuite/Options/Testing/AutoSortRunQueue', 'TRUE') && $this->force_save_results == false) {
         // Not that it matters much, but if $this->force_save_results is set that means likely running from a result file...
         // so if running a result file, don't change the ordering of the existing results
         // Sort the run order so that all tests that are similar are grouped together, etc
         usort($this->tests_to_run, array('pts_test_run_manager', 'cmp_result_object_sort'));
     }
     if (pts_client::read_env('RUN_TESTS_IN_RANDOM_ORDER')) {
         shuffle($this->tests_to_run);
     }
     $this->prompt_save_results = $run_contains_a_no_result_type == false || $unique_test_count > 1;
     $this->force_save_results = $this->force_save_results || $request_results_save;
 }
 public static function run($r)
 {
     if (pts_openbenchmarking_client::user_name() == false) {
         echo PHP_EOL . 'You must first be logged into an OpenBenchmarking.org account.' . PHP_EOL;
         echo PHP_EOL . 'Create An Account: http://openbenchmarking.org/';
         echo PHP_EOL . 'Log-In Command: phoronix-test-suite openbenchmarking-setup' . PHP_EOL . PHP_EOL;
         return false;
     }
     ini_set('memory_limit', '2048M');
     foreach (pts_types::identifiers_to_test_profile_objects($r, false, true) as $test_profile) {
         $qualified_identifier = $test_profile->get_identifier();
         // First make sure the test profile is already in the OpenBenchmarking.org database...
         $json = pts_openbenchmarking::make_openbenchmarking_request('is_test_profile', array('i' => $qualified_identifier));
         $json = json_decode($json, true);
         if (!isset($json['openbenchmarking']['test']['valid']) || $json['openbenchmarking']['test']['valid'] != 'TRUE') {
             echo PHP_EOL . $qualified_identifier . ' must first be uploaded to OpenBenchmarking.org.' . PHP_EOL;
             //	break;
         }
         // Set some other things...
         pts_client::pts_set_environment_variable('FORCE_TIMES_TO_RUN', 1);
         pts_client::pts_set_environment_variable('TEST_RESULTS_NAME', $test_profile->get_title() . ' Testing ' . date('Y-m-d'));
         pts_client::pts_set_environment_variable('TEST_RESULTS_IDENTIFIER', 'Sample Run');
         pts_client::pts_set_environment_variable('TEST_RESULTS_DESCRIPTION', 1);
         pts_openbenchmarking_client::override_client_setting('AutoUploadResults', true);
         pts_openbenchmarking_client::override_client_setting('UploadSystemLogsByDefault', true);
         // Take screenshots
         pts_client::pts_set_environment_variable('SCREENSHOT_INTERVAL', 9);
         pts_module_manager::attach_module('timed_screenshot');
         $force_ss = true;
         $reference_ss_file = pts_module_manager::module_call('timed_screenshot', 'take_screenshot', $force_ss);
         sleep(2);
         $apitrace = pts_file_io::glob('/usr/local/lib/*/apitrace/wrappers/glxtrace.so');
         if (!empty($apitrace) && pts_client::executable_in_path('apitrace')) {
             $apitrace = array_shift($apitrace);
             putenv('LD_PRELOAD=' . $apitrace);
         } else {
             $apitrace = false;
         }
         // So for any compiling tasks they will try to use the most aggressive instructions possible
         putenv('CFLAGS=-march=native -O3');
         putenv('CXXFLAGS=-march=native -O3');
         pts_test_installer::standard_install($qualified_identifier, true);
         $run_manager = new pts_test_run_manager(false, 2);
         $run_manager->standard_run($qualified_identifier);
         if ($apitrace) {
             putenv('LD_PRELOAD=');
         }
         if ($reference_ss_file) {
             $reference_ss = pts_image::image_file_to_gd($reference_ss_file);
             unlink($reference_ss_file);
             $screenshots_gd = array();
             $screenshots = pts_module_manager::module_call('timed_screenshot', 'get_screenshots');
             var_dump($screenshots);
             foreach ($screenshots as $ss_file) {
                 $screenshots_gd[$ss_file] = pts_image::image_file_to_gd($ss_file);
                 if ($screenshots_gd[$ss_file] == false) {
                     continue;
                 }
                 $ss_delta = pts_image::gd_image_delta_composite($reference_ss, $screenshots_gd[$ss_file], true);
                 if (count($ss_delta) < floor(imagesx($reference_ss) * 0.5600000000000001) || filesize($ss_file) > 2097152) {
                     // If less than 56% of the pixels are changing on X, then likely not much to show off... (CLI only likely)
                     // Or if filesize of image is beyond 2MB
                     //echo 'dropping' . $ss_file . PHP_EOL;
                     unset($screenshots_gd[$ss_file]);
                     pts_file_io::unlink($ss_file);
                 }
             }
             $ss_files = array_keys($screenshots_gd);
             shuffle($ss_files);
             // Don't upload more than 4MB worth of screenshots
             while (pts_file_io::array_filesize($ss_files) > 1048576 * 2) {
                 $f = array_pop($ss_files);
                 unlink($f);
             }
             if (count($ss_files) > 0) {
                 $c = 1;
                 foreach ($ss_files as $i => $file) {
                     $new_file = dirname($file) . '/screenshot-' . $c . '.png';
                     rename($file, $new_file);
                     $ss_files[$i] = $new_file;
                     $c++;
                 }
                 $ss_zip_file = PTS_OPENBENCHMARKING_SCRATCH_PATH . 'screenshots-' . $test_profile->get_identifier_base_name() . '-' . $test_profile->get_test_profile_version() . '.zip';
                 $zip_created = pts_compression::zip_archive_create($ss_zip_file, $ss_files);
                 if ($zip_created) {
                     echo count($ss_files) . ' screenshots captured for use.';
                     //'tp_sha1' => sha1_file($zip_file),
                     //'tp_zip' => base64_encode(file_get_contents($zip_file)),
                 }
                 foreach ($ss_files as $file) {
                     //	pts_file_io::unlink($file);
                 }
             }
         }
         $test_binary = self::locate_test_profile_lead_binary($test_profile);
         $shared_library_dependencies = array();
         $instruction_usage = array();
         $gl_calls = null;
         if (is_executable($test_binary)) {
             if ($apitrace) {
                 // Find the trace...
                 $test_binary_dir = dirname($test_binary);
                 $trace_file = glob($test_binary_dir . '/*.trace');
                 if ($trace_file) {
                     echo 'Analyzing GL traces';
                     $trace_file = array_shift($trace_file);
                     $gl_usage = self::analyze_apitrace_trace_glpop($trace_file);
                     if (!empty($gl_usage)) {
                         $gl_calls = implode(',', $gl_usage);
                     }
                 }
             }
             $ldd = trim(shell_exec('ldd ' . $test_binary));
             foreach (explode(PHP_EOL, $ldd) as $line) {
                 $line = explode(' => ', $line);
                 if (count($line) == 2) {
                     $shared_library_dependencies[] = trim(basename($line[0]));
                 }
             }
             echo PHP_EOL . 'SHARED LIBRARY DEPENDENCIES: ' . PHP_EOL;
             print_r($shared_library_dependencies);
             foreach (array('core-avx-i', 'bdver2') as $march) {
                 // So for any compiling tasks they will try to use the most aggressive instructions possible
                 putenv('CFLAGS=-march=' . $march . ' -O3');
                 putenv('CXXFLAGS=-march=' . $march . ' -O3');
                 pts_test_installer::standard_install($qualified_identifier, true);
                 $instruction_usage[$march] = self::analyze_binary_instruction_usage($test_binary);
                 if ($instruction_usage[$march] == null) {
                     unset($instruction_usage[$march]);
                 }
             }
             if (!empty($instruction_usage) && count(array_unique($instruction_usage)) == 1) {
                 $generic = array_pop($instruction_usage);
                 $instruction_usage = array('generic' => $generic);
             }
             var_dump($instruction_usage);
         } else {
             echo PHP_EOL . $test_binary;
             echo PHP_EOL . 'Test binary could not be found.' . PHP_EOL;
             //		return false;
         }
     }
     sleep(10);
     var_dump($shared_library_dependencies);
     var_dump($instruction_usage);
     var_dump($gl_calls);
     $server_response = pts_openbenchmarking::make_openbenchmarking_request('upload_test_meta', array('i' => $test_profile->get_identifier(), 'screenshots_zip' => $ss_zip_conts = base64_encode(file_get_contents($ss_zip_file)), 'screenshots_zip_sha1' => sha1($ss_zip_conts), 'ldd_libraries' => implode(',', $shared_library_dependencies), 'opengl_calls' => $gl_calls, 'instruction_set_usage' => base64_encode(json_encode($instruction_usage))));
     var_dump($server_response);
     $json = json_decode($server_response, true);
     pts_file_io::unlink($ss_zip_file);
 }
示例#13
0
 protected static function phoromatic_setup_module()
 {
     if (!pts_module::is_module_setup()) {
         echo PHP_EOL . 'You first must run:' . PHP_EOL . PHP_EOL . 'phoronix-test-suite module-setup phoromatic' . PHP_EOL . PHP_EOL;
         return false;
     }
     self::$phoromatic_host = pts_module::read_option('remote_host');
     self::$phoromatic_account = pts_module::read_option('remote_account');
     self::$phoromatic_verifier = pts_module::read_option('remote_verifier');
     self::$phoromatic_system = pts_module::read_option('remote_system');
     if (extension_loaded('openssl') == false) {
         // OpenSSL is not supported therefore no HTTPS support
         self::$phoromatic_host = str_replace('https://', 'http://', self::$phoromatic_host);
     }
     $phoromatic = 'phoromatic';
     pts_module_manager::attach_module($phoromatic);
     return true;
 }
 public static function set_current_module($module = null)
 {
     self::$current_module = $module;
 }