public static function init()
 {
     self::$flags = 0;
     self::$os_identifier_sha1 = sha1(phodevi::read_property('system', 'vendor-identifier'));
     self::$is_live_cd = 1 << 1;
     self::$no_network_communication = 1 << 2;
     self::$no_openbenchmarking_reporting = 1 << 3;
     self::$user_agreement_skip = 1 << 4;
     self::$skip_md5_checks = 1 << 5;
     self::$remove_test_on_completion = 1 << 6;
     self::$no_phodevi_cache = 1 << 7;
     self::$no_external_dependencies = 1 << 8;
     self::$upload_to_openbenchmarking = 1 << 9;
     switch (self::$os_identifier_sha1) {
         case 'b28d6a7148b34595c5b397dfcf5b12ac7932b3dc':
             // Moscow 2011-04 client
             self::$flags = self::$is_live_cd | self::$no_network_communication | self::$no_openbenchmarking_reporting | self::$user_agreement_skip | self::$skip_md5_checks | self::$remove_test_on_completion;
             break;
     }
     if (pts_client::read_env('NO_FILE_HASH_CHECKS') != false || pts_client::read_env('NO_MD5_CHECKS') != false) {
         self::$flags |= self::$skip_md5_checks;
     }
     if (pts_config::read_bool_config('PhoronixTestSuite/Options/Testing/RemoveTestInstallOnCompletion', 'FALSE')) {
         self::$flags |= self::$remove_test_on_completion;
     }
     if (pts_config::read_bool_config('PhoronixTestSuite/Options/Testing/AlwaysUploadResultsToOpenBenchmarking', 'FALSE')) {
         self::$flags |= self::$upload_to_openbenchmarking;
     }
     if (pts_client::read_env('NO_PHODEVI_CACHE') != false) {
         self::$flags |= self::$no_phodevi_cache;
     }
     if (pts_client::read_env('NO_EXTERNAL_DEPENDENCIES') != false || pts_client::read_env('SKIP_EXTERNAL_DEPENDENCIES') == 1) {
         // NO_EXTERNAL_DEPENDENCIES was deprecated in PTS 3.6 and replaced by more versatile SKIP_EXTERNAL_DEPENDENCIES
         self::$flags |= self::$no_external_dependencies;
     }
 }
 public static function install_dependencies(&$test_profiles)
 {
     // PTS External Dependencies install on distribution
     if (phodevi::is_windows() || phodevi::is_macosx() || pts_flags::no_external_dependencies()) {
         // Windows doesn't use any external dependencies
         return true;
     }
     // Find all the tests that need to be checked
     $tests_to_check = array();
     foreach ($test_profiles as $test_profile) {
         if (!in_array($test_profile, $tests_to_check) && $test_profile->is_supported()) {
             array_push($tests_to_check, $test_profile);
         }
     }
     // Find all of the POSSIBLE test dependencies
     $required_test_dependencies = array();
     foreach ($tests_to_check as &$test_profile) {
         foreach ($test_profile->get_dependencies() as $test_dependency) {
             if (empty($test_dependency)) {
                 continue;
             }
             if (isset($required_test_dependencies[$test_dependency]) == false) {
                 $required_test_dependencies[$test_dependency] = array();
             }
             array_push($required_test_dependencies[$test_dependency], $test_profile);
         }
     }
     if (pts_c::$test_flags & pts_c::skip_tests_with_missing_dependencies) {
         // Remove tests that have external dependencies that aren't satisfied and then return
         $generic_packages_needed = array();
         $required_test_dependencies_copy = $required_test_dependencies;
         $dependencies_to_install = self::check_dependencies_missing_from_system($required_test_dependencies_copy, $generic_packages_needed);
         self::remove_tests_with_missing_dependencies($test_profiles, $generic_packages_needed, $required_test_dependencies);
         return true;
     }
     if (!empty($required_test_dependencies)) {
         // The 'common-dependencies' package is any general non-explicitly-required but nice-to-have packages like mesa-utils for providing glxinfo about the system
         // So if we're going to be installing external dependencies anyways, might as well try to see the common-dependencies are satisfied
         $required_test_dependencies['common-dependencies'] = array();
     }
     // Does the user wish to skip any particular dependencies?
     if (pts_client::read_env('SKIP_EXTERNAL_DEPENDENCIES')) {
         $dependencies_to_skip = explode(',', pts_client::read_env('SKIP_EXTERNAL_DEPENDENCIES'));
         foreach ($dependencies_to_skip as $dependency_name) {
             if (isset($required_test_dependencies[$dependency_name])) {
                 unset($required_test_dependencies[$dependency_name]);
             }
         }
     }
     // Make a copy for use to check at end of process to see if all dependencies were actually found
     $required_test_dependencies_copy = $required_test_dependencies;
     // Find the dependencies that are actually missing from the system
     $dependencies_to_install = self::check_dependencies_missing_from_system($required_test_dependencies);
     // If it's automated and can't install without root, return true if there are no dependencies to do otherwise false
     if (pts_c::$test_flags & pts_c::auto_mode && phodevi::is_root() == false) {
         return count($dependencies_to_install) == 0;
     }
     // Do the actual dependency install process
     if (count($dependencies_to_install) > 0) {
         self::install_packages_on_system($dependencies_to_install);
     }
     // There were some dependencies not supported on this OS or are missing from the distro's XML file
     if (count($required_test_dependencies) > 0 && count($dependencies_to_install) == 0) {
         $exdep_generic_parser = new pts_exdep_generic_parser();
         $to_report = array();
         foreach (array_keys($required_test_dependencies) as $dependency) {
             $dependency_data = $exdep_generic_parser->get_package_data($dependency);
             if ($dependency_data['possible_packages'] != null) {
                 array_push($to_report, $dependency_data['title'] . PHP_EOL . 'Possible Package Names: ' . $dependency_data['possible_packages']);
             }
         }
         if (count($to_report) > 0) {
             echo PHP_EOL . 'Some additional dependencies are required, but they could not be installed automatically for your operating system.' . PHP_EOL . 'Below are the software packages that must be installed.' . PHP_EOL . PHP_EOL;
             foreach ($to_report as $report) {
                 pts_client::$display->generic_heading($report);
             }
             if (pts_c::$test_flags ^ pts_c::batch_mode && pts_c::$test_flags ^ pts_c::auto_mode) {
                 echo 'The above dependencies should be installed before proceeding. Press any key when you\'re ready to continue.';
                 pts_user_io::read_user_input();
                 echo PHP_EOL;
             }
         }
     }
     // Find the dependencies that are still missing from the system
     if (pts_c::$test_flags ^ pts_c::batch_mode && pts_c::$test_flags ^ pts_c::auto_mode && !defined('PHOROMATIC_PROCESS')) {
         $generic_packages_needed = array();
         $required_test_dependencies = $required_test_dependencies_copy;
         $dependencies_to_install = self::check_dependencies_missing_from_system($required_test_dependencies_copy, $generic_packages_needed);
         if (count($generic_packages_needed) > 0) {
             echo PHP_EOL . 'There are dependencies still missing from the system:' . PHP_EOL;
             echo pts_user_io::display_text_list(self::generic_names_to_titles($generic_packages_needed));
             $actions = array('IGNORE' => 'Ignore missing dependencies and proceed with installation.', 'SKIP_TESTS_WITH_MISSING_DEPS' => 'Skip installing the tests with missing dependencies.', 'REATTEMPT_DEP_INSTALL' => 'Re-attempt to install the missing dependencies.', 'QUIT' => 'Quit the current Phoronix Test Suite process.');
             $selected_action = pts_user_io::prompt_text_menu('Missing dependencies action', $actions, false, true);
             switch ($selected_action) {
                 case 'IGNORE':
                     break;
                 case 'SKIP_TESTS_WITH_MISSING_DEPS':
                     // Unset the tests that have dependencies still missing
                     self::remove_tests_with_missing_dependencies($test_profiles, $generic_packages_needed, $required_test_dependencies);
                     break;
                 case 'REATTEMPT_DEP_INSTALL':
                     self::install_packages_on_system($dependencies_to_install);
                     break;
                 case 'QUIT':
                     exit(0);
             }
         }
     }
     return true;
 }
 public static function client_startup()
 {
     if (($proxy_address = pts_config::read_user_config('PhoronixTestSuite/Options/Networking/ProxyAddress', false)) && ($proxy_port = pts_config::read_user_config('PhoronixTestSuite/Options/Networking/ProxyPort', false))) {
         self::$network_proxy['proxy'] = $proxy_address . ':' . $proxy_port;
         self::$network_proxy['address'] = $proxy_address;
         self::$network_proxy['port'] = $proxy_port;
     } else {
         if (($env_proxy = getenv('http_proxy')) != false && count($env_proxy = pts_strings::colon_explode($env_proxy)) == 2) {
             self::$network_proxy['proxy'] = $env_proxy[0] . ':' . $env_proxy[1];
             self::$network_proxy['address'] = $env_proxy[0];
             self::$network_proxy['port'] = $env_proxy[1];
         }
     }
     self::$network_timeout = pts_config::read_user_config('PhoronixTestSuite/Options/Networking/Timeout', 20);
     if (ini_get('allow_url_fopen') == 'Off') {
         if (!defined('PHOROMATIC_SERVER')) {
             echo PHP_EOL . 'The allow_url_fopen option in your PHP configuration must be enabled for network support.' . PHP_EOL . PHP_EOL;
         }
         self::$disable_network_support = true;
     } else {
         if (pts_config::read_bool_config('PhoronixTestSuite/Options/Networking/NoInternetCommunication', 'FALSE')) {
             if (!defined('PHOROMATIC_SERVER')) {
                 echo PHP_EOL . 'Internet Communication Is Disabled Per Your User Configuration.' . PHP_EOL . PHP_EOL;
             }
             self::$disable_internet_support = true;
         } else {
             if (pts_config::read_bool_config('PhoronixTestSuite/Options/Networking/NoNetworkCommunication', 'FALSE')) {
                 if (!defined('PHOROMATIC_SERVER')) {
                     echo PHP_EOL . 'Network Communication Is Disabled Per Your User Configuration.' . PHP_EOL . PHP_EOL;
                 }
                 self::$disable_network_support = true;
             } else {
                 if (pts_flags::no_network_communication() == true) {
                     //echo PHP_EOL . 'Network Communication Is Disabled Per Your User Configuration.' . PHP_EOL . PHP_EOL;
                     self::$disable_network_support = true;
                 } else {
                     if (!PTS_IS_WEB_CLIENT) {
                         $server_response = pts_network::http_get_contents('http://www.phoronix-test-suite.com/PTS', false, false);
                         if ($server_response != 'PTS') {
                             // Failed to connect to PTS server
                             // As a last resort, see if it can resolve IP to Google.com as a test for Internet connectivity...
                             // i.e. in case Phoronix server is down or some other issue, so just see if Google will resolve
                             // If google.com fails to resolve, it will simply return the original string
                             if (gethostbyname('google.com') == 'google.com') {
                                 echo PHP_EOL;
                                 if (PTS_IS_DAEMONIZED_SERVER_PROCESS) {
                                     // Wait some seconds in case network is still coming up
                                     foreach (array(20, 40) as $time_to_wait) {
                                         sleep($time_to_wait);
                                         $server_response = pts_network::http_get_contents('http://www.phoronix-test-suite.com/PTS', false, false);
                                         if ($server_response != 'PTS' && gethostbyname('google.com') == 'google.com') {
                                             trigger_error('No Internet Connectivity After Wait', E_USER_WARNING);
                                             self::$disable_internet_support = true;
                                         } else {
                                             self::$disable_internet_support = false;
                                             break;
                                         }
                                     }
                                 } else {
                                     trigger_error('No Internet Connectivity', E_USER_WARNING);
                                     self::$disable_internet_support = true;
                                 }
                             }
                         }
                     }
                 }
             }
         }
     }
     if (pts_network::network_support_available() == false && ini_get('file_uploads') == 'Off') {
         echo PHP_EOL . 'The file_uploads option in your PHP configuration must be enabled for network support.' . PHP_EOL . PHP_EOL;
     }
 }
 public static function process_shutdown_tasks()
 {
     // TODO: possibly do something like posix_getpid() != pts_client::$startup_pid in case shutdown function is called from a child process
     // Generate Phodevi Smart Cache
     if (pts_flags::no_phodevi_cache() == false && pts_client::read_env('EXTERNAL_PHODEVI_CACHE') == false) {
         if (pts_config::read_bool_config('PhoronixTestSuite/Options/General/UsePhodeviCache', 'TRUE')) {
             pts_storage_object::set_in_file(PTS_CORE_STORAGE, 'phodevi_smart_cache', phodevi::get_phodevi_cache_object(PTS_USER_PATH, PTS_CORE_VERSION));
         } else {
             pts_storage_object::set_in_file(PTS_CORE_STORAGE, 'phodevi_smart_cache', null);
         }
     }
     if (is_array(self::$lock_pointers)) {
         foreach (array_keys(self::$lock_pointers) as $lock_file) {
             self::release_lock($lock_file);
         }
     }
     foreach (self::$forked_pids as $pid) {
         if (is_dir('/proc/' . $pid) && function_exists('posix_kill')) {
             posix_kill($pid, SIGKILL);
         }
     }
 }
 public function check_file_hash($file)
 {
     if (!is_file($file)) {
         return false;
     } else {
         if (pts_client::read_env('NO_FILE_HASH_CHECKS') != false || pts_flags::skip_md5_checks()) {
             return true;
         } else {
             if ($this->sha256) {
                 return hash_file('sha256', $file) == $this->sha256;
             } else {
                 if ($this->md5) {
                     return md5_file($file) == $this->md5;
                 } else {
                     if (filesize($file) > 0) {
                         return true;
                     } else {
                         return false;
                     }
                 }
             }
         }
     }
 }
 protected static function download_test_files(&$test_install_request, $download_location = false)
 {
     // Download needed files for a test
     if ($test_install_request->get_download_object_count() == 0) {
         return true;
     }
     $identifier = $test_install_request->test_profile->get_identifier();
     pts_client::$display->test_install_downloads($test_install_request);
     if ($download_location == false) {
         $download_location = $test_install_request->test_profile->get_install_dir();
     }
     pts_file_io::mkdir($download_location);
     $module_pass = array($identifier, $test_install_request->get_download_objects());
     pts_module_manager::module_process('__pre_test_download', $module_pass);
     foreach ($test_install_request->get_download_objects() as $download_package) {
         $package_filename = $download_package->get_filename();
         $download_destination = $download_location . $package_filename;
         $download_destination_temp = $download_destination . '.pts';
         if ($download_package->get_download_location_type() == null) {
             // Attempt a possible last-minute look-aside copy cache in case a previous test in the install queue downloaded this file already
             $lookaside_copy = pts_test_install_manager::file_lookaside_test_installations($download_package);
             if ($lookaside_copy) {
                 if ($download_package->get_filesize() == 0) {
                     $download_package->set_filesize(filesize($lookaside_copy));
                 }
                 $download_package->set_download_location('LOOKASIDE_DOWNLOAD_CACHE', array($lookaside_copy));
             }
         }
         switch ($download_package->get_download_location_type()) {
             case 'IN_DESTINATION_DIR':
                 pts_client::$display->test_install_download_file('FILE_FOUND', $download_package);
                 continue;
             case 'REMOTE_DOWNLOAD_CACHE':
                 $download_tries = 0;
                 do {
                     foreach ($download_package->get_download_location_path() as $remote_download_cache_file) {
                         pts_client::$display->test_install_download_file('DOWNLOAD_FROM_CACHE', $download_package);
                         pts_network::download_file($remote_download_cache_file, $download_destination_temp);
                         if (!is_file($download_destination_temp) || filesize($download_destination_temp) == 0) {
                             self::test_install_error(null, $test_install_request, 'The file failed to download from the cache.');
                             pts_file_io::unlink($download_destination_temp);
                             break;
                         } else {
                             if ($download_package->check_file_hash($download_destination_temp)) {
                                 rename($download_destination_temp, $download_destination);
                                 break;
                             } else {
                                 self::test_install_error(null, $test_install_request, 'The check-sum of the downloaded file failed.');
                                 pts_file_io::unlink($download_destination_temp);
                             }
                         }
                     }
                     $download_tries++;
                 } while (!is_file($download_destination) && $download_tries < 2);
                 if (is_file($download_destination)) {
                     continue;
                 }
             case 'MAIN_DOWNLOAD_CACHE':
             case 'LOCAL_DOWNLOAD_CACHE':
             case 'LOOKASIDE_DOWNLOAD_CACHE':
                 $download_cache_file = pts_arrays::last_element($download_package->get_download_location_path());
                 if (is_file($download_cache_file)) {
                     if (pts_config::read_bool_config('PhoronixTestSuite/Options/Installation/SymLinkFilesFromCache', 'FALSE') && $download_package->get_download_location_type() != 'LOOKASIDE_DOWNLOAD_CACHE' || pts_flags::is_live_cd()) {
                         // For look-aside copies never symlink (unless a pre-packaged LiveCD) in case the other test ends up being un-installed
                         // SymLinkFilesFromCache is disabled by default
                         pts_client::$display->test_install_download_file('LINK_FROM_CACHE', $download_package);
                         symlink($download_cache_file, $download_destination);
                     } else {
                         // File is to be copied
                         // Try up to two times to copy a file
                         $attempted_copies = 0;
                         do {
                             pts_client::$display->test_install_download_file('COPY_FROM_CACHE', $download_package);
                             // $context = stream_context_create();
                             // stream_context_set_params($context, array('notification' => array('pts_network', 'stream_status_callback')));
                             // TODO: get the context working correctly for this copy()
                             copy($download_cache_file, $download_destination_temp);
                             pts_client::$display->test_install_progress_completed();
                             // Verify that the file was copied fine
                             if ($download_package->check_file_hash($download_destination_temp)) {
                                 rename($download_destination_temp, $download_destination);
                                 break;
                             } else {
                                 self::test_install_error(null, $test_install_request, 'The check-sum of the copied file failed.');
                                 pts_file_io::unlink($download_destination_temp);
                             }
                             $attempted_copies++;
                         } while ($attempted_copies < 2);
                     }
                     if (is_file($download_destination)) {
                         continue;
                     }
                 }
             default:
                 $package_urls = $download_package->get_download_url_array();
                 // Download the file
                 if (!is_file($download_destination) && count($package_urls) > 0 && $package_urls[0] != null) {
                     $fail_count = 0;
                     do {
                         if (pts_network::internet_support_available()) {
                             if (pts_c::$test_flags ^ pts_c::batch_mode && pts_c::$test_flags ^ pts_c::auto_mode && pts_config::read_bool_config('PhoronixTestSuite/Options/Installation/PromptForDownloadMirror', 'FALSE') && count($package_urls) > 1) {
                                 // Prompt user to select mirror
                                 do {
                                     echo PHP_EOL . 'Available Download Mirrors:' . PHP_EOL . PHP_EOL;
                                     $url = pts_user_io::prompt_text_menu('Select Preferred Mirror', $package_urls, false);
                                 } while (pts_strings::is_url($url) == false);
                             } else {
                                 // Auto-select mirror
                                 shuffle($package_urls);
                                 do {
                                     $url = array_pop($package_urls);
                                 } while (pts_strings::is_url($url) == false && !empty($package_urls));
                             }
                             pts_client::$display->test_install_download_file('DOWNLOAD', $download_package);
                             $download_start = time();
                             pts_network::download_file($url, $download_destination_temp);
                             $download_end = time();
                         } else {
                             self::test_install_error(null, $test_install_request, 'Internet support is needed and it\'s disabled or not available.');
                             return false;
                         }
                         if ($download_package->check_file_hash($download_destination_temp)) {
                             // Download worked
                             if (is_file($download_destination_temp)) {
                                 rename($download_destination_temp, $download_destination);
                             }
                             if ($download_package->get_filesize() > 0 && $download_end != $download_start) {
                                 pts_download_speed_manager::update_download_speed_average($download_package->get_filesize(), $download_end - $download_start);
                             }
                         } else {
                             // Download failed
                             if (is_file($download_destination_temp) && filesize($download_destination_temp) < 500 && (stripos(file_get_contents($download_destination_temp), 'not found') !== false || strpos(file_get_contents($download_destination_temp), 404) !== false)) {
                                 self::test_install_error(null, $test_install_request, 'File Not Found: ' . $url);
                                 $md5_failed = false;
                             } else {
                                 if (is_file($download_destination_temp) && filesize($download_destination_temp) > 0) {
                                     self::test_install_error(null, $test_install_request, 'Checksum Failed: ' . $url);
                                     $md5_failed = true;
                                 } else {
                                     self::test_install_error(null, $test_install_request, 'Download Failed: ' . $url);
                                     $md5_failed = false;
                                 }
                             }
                             pts_file_io::unlink($download_destination_temp);
                             $fail_count++;
                             if ($fail_count > 3) {
                                 $try_again = false;
                             } else {
                                 if (count($package_urls) > 0 && $package_urls[0] != null) {
                                     self::test_install_error(null, $test_install_request, 'Attempting to download from alternate mirror.');
                                     $try_again = true;
                                 } else {
                                     if (pts_c::$test_flags & pts_c::batch_mode || pts_c::$test_flags & pts_c::auto_mode) {
                                         $try_again = false;
                                     } else {
                                         if ($md5_failed) {
                                             $try_again = pts_user_io::prompt_bool_input('Try downloading the file again', true, 'TRY_DOWNLOAD_AGAIN');
                                         } else {
                                             $try_again = false;
                                         }
                                     }
                                     if ($try_again) {
                                         array_push($package_urls, $url);
                                     }
                                 }
                             }
                             if (!$try_again) {
                                 //self::test_install_error(null, $test_install_request, 'Download of Needed Test Dependencies Failed!');
                                 return false;
                             }
                         }
                     } while (!is_file($download_destination));
                 }
                 pts_module_manager::module_process('__interim_test_download', $module_pass);
         }
     }
     pts_module_manager::module_process('__post_test_download', $identifier);
     return true;
 }
 public static function cleanup_tests_to_run(&$to_run_objects)
 {
     $skip_tests = ($e = pts_client::read_env('SKIP_TESTS')) ? pts_strings::comma_explode($e) : false;
     $tests_verified = array();
     $tests_missing = array();
     foreach ($to_run_objects as &$run_object) {
         if ($skip_tests && (in_array($run_object->get_identifier(false), $skip_tests) || $run_object instanceof pts_test_profile && in_array($run_object->get_identifier_base_name(), $skip_tests))) {
             pts_client::$display->generic_sub_heading('Skipping: ' . $run_object->get_identifier());
             continue;
         } else {
             if ($run_object instanceof pts_test_profile) {
                 if ($run_object->get_title() == null) {
                     pts_client::$display->generic_sub_heading('Not A Test: ' . $run_object);
                     continue;
                 } else {
                     if ($run_object->is_supported(false) == false) {
                         continue;
                     }
                     if ($run_object->is_test_installed() == false) {
                         // Check to see if older version of test is currently installed
                         // TODO: show change-log between installed versions and upstream
                         array_push($tests_missing, $run_object);
                         continue;
                     }
                 }
             } else {
                 if ($run_object instanceof pts_result_file) {
                     $num_installed = 0;
                     foreach ($run_object->get_contained_test_profiles() as $test_profile) {
                         if ($test_profile == null || $test_profile->get_identifier() == null || $test_profile->is_supported(false) == false) {
                             continue;
                         } else {
                             if ($test_profile->is_test_installed() == false) {
                                 array_push($tests_missing, $test_profile);
                             } else {
                                 $num_installed++;
                             }
                         }
                     }
                     if ($num_installed == 0) {
                         continue;
                     }
                 } else {
                     if ($run_object instanceof pts_test_suite || $run_object instanceof pts_virtual_test_suite || $run_object instanceof pts_virtual_test_queue) {
                         if ($run_object->is_core_version_supported() == false) {
                             pts_client::$display->generic_sub_heading($run_object->get_title() . ' is a suite not supported by this version of the Phoronix Test Suite.');
                             continue;
                         }
                         $num_installed = 0;
                         foreach ($run_object->get_contained_test_profiles() as $test_profile) {
                             if ($test_profile == null || $test_profile->get_identifier() == null || $test_profile->is_supported(false) == false) {
                                 continue;
                             }
                             if ($test_profile->is_test_installed() == false) {
                                 array_push($tests_missing, $test_profile);
                             } else {
                                 $num_installed++;
                             }
                         }
                         if ($num_installed == 0) {
                             continue;
                         }
                     } else {
                         pts_client::$display->generic_sub_heading('Not Recognized: ' . $run_object);
                         continue;
                     }
                 }
             }
         }
         array_push($tests_verified, $run_object);
     }
     $to_run_objects = $tests_verified;
     if (count($tests_missing) > 0 && !defined('PHOROMATIC_PROCESS')) {
         $tests_missing = array_unique($tests_missing);
         if (count($tests_missing) == 1) {
             trigger_error($tests_missing[0] . ' is not installed.', E_USER_ERROR);
             // PHP_EOL . 'To install, run: phoronix-test-suite install ' . $tests_missing[0]
         } else {
             $message = PHP_EOL . PHP_EOL . 'Multiple tests are not installed:' . PHP_EOL . PHP_EOL;
             $message .= pts_user_io::display_text_list($tests_missing);
             //$message .= PHP_EOL . 'To install, run: phoronix-test-suite install ' . implode(' ', $tests_missing) . PHP_EOL . PHP_EOL;
             echo $message;
         }
         if ((pts_c::$test_flags & pts_c::batch_mode) == false && (pts_c::$test_flags & pts_c::auto_mode) == false && pts_flags::is_live_cd() == false && pts_client::current_command() != 'benchmark') {
             $stop_and_install = pts_user_io::prompt_bool_input('Would you like to stop and install these tests now', true);
             if ($stop_and_install) {
                 pts_test_installer::standard_install($tests_missing, pts_c::$test_flags);
                 self::cleanup_tests_to_run($to_run_objects);
             }
         }
     }
     return true;
 }
 public static function auto_process_test_option($test_identifier, $option_identifier, &$option_names, &$option_values, &$option_messages)
 {
     // Some test items have options that are dynamically built
     switch ($option_identifier) {
         case 'auto-resolution':
             // Base options off available screen resolutions
             if (count($option_names) == 1 && count($option_values) == 1) {
                 if (PTS_IS_CLIENT && pts_flags::is_live_cd() && !defined('PHOROMATIC_SERVER')) {
                     // Just use the stock resolution when operating from a LiveCD
                     $available_video_modes = array(phodevi::read_property('gpu', 'screen-resolution'));
                 } else {
                     if (PTS_IS_CLIENT && phodevi::read_property('gpu', 'screen-resolution') && phodevi::read_property('gpu', 'screen-resolution') != array(-1, -1) && !defined('PHOROMATIC_SERVER')) {
                         $available_video_modes = phodevi::read_property('gpu', 'available-modes');
                     } else {
                         $available_video_modes = array();
                     }
                 }
                 if (empty($available_video_modes)) {
                     // Use hard-coded defaults
                     $available_video_modes = array(array(800, 600), array(1024, 768), array(1280, 768), array(1280, 960), array(1280, 1024), array(1366, 768), array(1400, 1050), array(1600, 900), array(1680, 1050), array(1600, 1200), array(1920, 1080), array(2560, 1600), array(3840, 2160));
                 }
                 $format_name = $option_names[0];
                 $format_value = $option_values[0];
                 $option_names = array();
                 $option_values = array();
                 foreach ($available_video_modes as $video_mode) {
                     $this_name = str_replace('$VIDEO_WIDTH', $video_mode[0], $format_name);
                     $this_name = str_replace('$VIDEO_HEIGHT', $video_mode[1], $this_name);
                     $this_value = str_replace('$VIDEO_WIDTH', $video_mode[0], $format_value);
                     $this_value = str_replace('$VIDEO_HEIGHT', $video_mode[1], $this_value);
                     array_push($option_names, $this_name);
                     array_push($option_values, $this_value);
                 }
             }
             break;
         case 'auto-disk-partitions':
         case 'auto-disk-mount-points':
             // Base options off available disk partitions
             if (PTS_IS_CLIENT == false) {
                 echo 'ERROR: This option is not supported in this configuration.';
                 return;
             }
             /*if(phodevi::is_linux())
             		{
             			$all_devices = array_merge(pts_file_io::glob('/dev/hd*'), pts_file_io::glob('/dev/sd*'));
             		}
             		else if(phodevi::is_bsd())
             		{
             			$all_devices = array_merge(pts_file_io::glob('/dev/ad*'), pts_file_io::glob('/dev/ada*'));
             		}
             		else
             		{
             			$all_devices = array();
             		}*/
             $all_devices = array_merge(pts_file_io::glob('/dev/hd*'), pts_file_io::glob('/dev/sd*'), pts_file_io::glob('/dev/md*'));
             foreach ($all_devices as &$device) {
                 if (!is_numeric(substr($device, -1))) {
                     unset($device);
                 }
             }
             $all_devices = array_merge($all_devices, pts_file_io::glob('/dev/mapper/*'));
             $option_values = array();
             foreach ($all_devices as $partition) {
                 array_push($option_values, $partition);
             }
             if ($option_identifier == 'auto-disk-mount-points') {
                 $partitions_d = $option_values;
                 $option_values = array();
                 $option_names = array();
                 $mounts = is_file('/proc/mounts') ? file_get_contents('/proc/mounts') : null;
                 array_push($option_values, '');
                 array_push($option_names, 'Default Test Directory');
                 if (pts_flags::is_live_cd() == false) {
                     foreach ($partitions_d as $partition_d) {
                         $mount_point = substr($a = substr($mounts, strpos($mounts, $partition_d) + strlen($partition_d) + 1), 0, strpos($a, ' '));
                         if (is_dir($mount_point) && is_writable($mount_point) && !in_array($mount_point, array('/boot', '/boot/efi'))) {
                             array_push($option_values, $mount_point);
                             array_push($option_names, $mount_point);
                             // ' [' . $partition_d . ']'
                         }
                     }
                 }
             } else {
                 $option_names = $option_values;
             }
             break;
         case 'auto-disks':
             // Base options off attached disks
             if (PTS_IS_CLIENT == false) {
                 echo 'ERROR: This option is not supported in this configuration.';
                 return;
             }
             $all_devices = array_merge(pts_file_io::glob('/dev/hd*'), pts_file_io::glob('/dev/sd*'), pts_file_io::glob('/dev/md*'));
             foreach ($all_devices as &$device) {
                 if (is_numeric(substr($device, -1))) {
                     unset($device);
                 }
             }
             $option_values = array();
             foreach ($all_devices as $disk) {
                 array_push($option_values, $disk);
             }
             $option_names = $option_values;
             break;
         case 'auto-removable-media':
             if (PTS_IS_CLIENT == false) {
                 echo 'ERROR: This option is not supported in this configuration.';
                 return;
             }
             foreach (array_merge(pts_file_io::glob('/media/*/'), pts_file_io::glob('/Volumes/*/')) as $media_check) {
                 if (is_dir($media_check) && is_writable($media_check)) {
                     array_push($option_names, $media_check);
                     array_push($option_values, $media_check);
                 }
             }
             break;
         case 'auto-file-select':
             if (PTS_IS_CLIENT == false) {
                 echo 'ERROR: This option is not supported in this configuration.';
                 return;
             }
             $names = $option_names;
             $values = $option_values;
             $option_names = array();
             $option_values = array();
             for ($i = 0; $i < count($names) && $i < count($values); $i++) {
                 if (is_file($values[$i])) {
                     array_push($option_names, $names[$i]);
                     array_push($option_values, $values[$i]);
                 }
             }
             break;
         case 'auto-directory-select':
             if (PTS_IS_CLIENT == false) {
                 echo 'ERROR: This option is not supported in this configuration.';
                 return;
             }
             $names = $option_names;
             $values = $option_values;
             $option_names = array();
             $option_values = array();
             for ($i = 0; $i < count($names) && $i < count($values); $i++) {
                 if (is_dir($values[$i]) && is_writable($removable_media[$i])) {
                     array_push($option_names, $names[$i]);
                     array_push($option_values, $values[$i]);
                 }
             }
             break;
     }
 }
 public static function run($r)
 {
     $is_moscow = pts_flags::os_identifier_hash() == 'b28d6a7148b34595c5b397dfcf5b12ac7932b3dc';
     if ($is_moscow) {
         // Auto mount?
         $drives = pts_file_io::glob('/dev/sda*');
         sort($drives);
         if (false && count($drives) > 0 && !is_dir('/media/pts-auto-mount') && is_writable('/media/')) {
             $last_drive = array_pop($drives);
             echo PHP_EOL . 'Attempting to auto-mount drive: ' . $last_drive . PHP_EOL;
             mkdir('/media/pts-auto-mount');
             exec('mount ' . $last_drive . ' /media/pts-auto-mount');
             putenv('PTS_TEST_INSTALL_ROOT_PATH=/media/pts-auto-mount/');
         }
         // Auto save results
         $test_results_name = phodevi::read_property('motherboard', 'serial-number');
         if ($test_results_name == null) {
             $test_results_name = phodevi::read_name('motherboard');
         }
         if ($test_results_name == null) {
             $test_results_name = phodevi::read_property('system', 'vendor-identifier');
         }
         putenv('TEST_RESULTS_NAME=' . str_replace(' ', null, $test_results_name));
         putenv('TEST_RESULTS_IDENTIFIER=' . $test_results_name);
         putenv('TEST_RESULTS_DESCRIPTION=Tests using ' . phodevi::read_property('system', 'operating-system') . ' on ' . date('d F Y') . ' of ' . $test_results_name . '.');
         self::select_drive_mount();
     }
     pts_openbenchmarking::refresh_repository_lists();
     pts_client::$display->generic_heading('Interactive Benchmarking');
     echo 'System Hardware:' . PHP_EOL . phodevi::system_hardware(true) . (phodevi::read_property('motherboard', 'serial-number') != null ? PHP_EOL . 'System Serial Number: ' . phodevi::read_property('motherboard', 'serial-number') : null) . PHP_EOL . PHP_EOL . PHP_EOL;
     $reboot_on_exit = pts_flags::is_live_cd() && pts_client::user_home_directory() == '/root/';
     do {
         $options = array('RUN_TEST' => 'Run A Test', 'RUN_SUITE' => 'Run A Suite [A Collection Of Tests]', 'RUN_SYSTEM_TEST' => 'Run Complex System Test', 'SHOW_INFO' => 'Show System Hardware / Software Information', 'SHOW_SENSORS' => 'Show Auto-Detected System Sensors', 'SET_RUN_COUNT' => 'Set Test Run Repetition');
         if ($is_moscow) {
             unset($options['RUN_SUITE']);
             //	$options['SELECT_DRIVE_MOUNT'] = 'Select Disk Drive To Use For Testing';
         }
         if (count(pts_client::saved_test_results()) > 0) {
             $options['BACKUP_RESULTS_TO_USB'] = 'Backup Results To Media Storage';
         }
         $options['EXIT'] = $reboot_on_exit ? 'Exit & Reboot' : 'Exit';
         $response = pts_user_io::prompt_text_menu('Select Task', $options, false, true);
         switch ($response) {
             case 'RUN_TEST':
                 $supported_tests = pts_openbenchmarking::available_tests();
                 $supported_tests = pts_types::identifiers_to_test_profile_objects($supported_tests, false, true);
                 $longest_title_length = 0;
                 foreach ($supported_tests as $i => &$test_profile) {
                     if ($test_profile->get_title() == null || pts_test_run_manager::test_profile_system_compatibility_check($test_profile) == false) {
                         unset($supported_tests[$i]);
                         continue;
                     }
                     if ($is_moscow && pts_test_install_request::test_files_available_locally($test_profile) == false) {
                         // Don't show tests where files need to be downloaded
                         unset($supported_tests[$i]);
                         continue;
                     }
                     $longest_title_length = max($longest_title_length, strlen($test_profile->get_title()));
                 }
                 $t = array();
                 foreach ($supported_tests as $i => &$test_profile) {
                     if ($test_profile instanceof pts_test_profile) {
                         $t[$test_profile->get_identifier()] = sprintf('%-' . ($longest_title_length + 1) . 'ls - %-10ls', $test_profile->get_title(), $test_profile->get_test_hardware_type());
                     }
                 }
                 $supported_tests = $t;
                 asort($supported_tests);
                 $tests_to_run = pts_user_io::prompt_text_menu('Select Test', $supported_tests, true, true);
                 $tests_to_run = explode(',', $tests_to_run);
                 pts_test_installer::standard_install($tests_to_run);
                 $run_manager = pts_test_run_manager::standard_run($tests_to_run, pts_c::defaults_mode | pts_c::auto_mode);
                 if ($run_manager != false) {
                     pts_client::display_web_page(PTS_SAVE_RESULTS_PATH . $run_manager->get_file_name() . '/index.html', null, true, true);
                 }
                 break;
             case 'RUN_SUITE':
                 $possible_suites = pts_openbenchmarking::available_suites();
                 foreach (array_map('strtolower', pts_types::subsystem_targets()) as $subsystem) {
                     array_push($possible_suites, 'pts/' . $subsystem);
                 }
                 $suites_to_run = pts_user_io::prompt_text_menu('Select Suite', $possible_suites, true);
                 foreach (explode(',', $suites_to_run) as $suite_to_run) {
                     pts_test_installer::standard_install($suite_to_run);
                     pts_test_run_manager::standard_run($suite_to_run, pts_c::defaults_mode | pts_c::auto_mode);
                 }
                 break;
             case 'SELECT_DRIVE_MOUNT':
                 self::select_drive_mount();
                 break;
             case 'RUN_SYSTEM_TEST':
                 pts_client::$display->generic_heading('System Test');
                 $system_tests = array('apache', 'c-ray', 'ramspeed', 'postmark');
                 pts_test_installer::standard_install($system_tests);
                 $run_manager = pts_test_run_manager::standard_run($system_tests, pts_c::defaults_mode | pts_c::auto_mode);
                 if ($run_manager != false) {
                     pts_client::display_web_page(PTS_SAVE_RESULTS_PATH . $run_manager->get_file_name() . '/index.html', null, true, true);
                 }
                 break;
             case 'SHOW_INFO':
                 pts_client::$display->generic_heading('System Software / Hardware Information');
                 echo 'Hardware:' . PHP_EOL . phodevi::system_hardware(true) . PHP_EOL . PHP_EOL;
                 echo 'Software:' . PHP_EOL . phodevi::system_software(true) . PHP_EOL . PHP_EOL;
                 break;
             case 'SHOW_SENSORS':
                 pts_client::$display->generic_heading('Detected System Sensors');
                 foreach (phodevi::supported_sensors() as $sensor) {
                     echo phodevi::sensor_name($sensor) . ': ' . phodevi::read_sensor($sensor) . ' ' . phodevi::read_sensor_unit($sensor) . PHP_EOL;
                 }
                 break;
             case 'SET_RUN_COUNT':
                 $run_count = pts_user_io::prompt_user_input('Set the minimum number of times each test should repeat', false);
                 putenv('FORCE_TIMES_TO_RUN=' . trim($run_count));
                 break;
             case 'BACKUP_RESULTS_TO_USB':
                 pts_client::$display->generic_heading('Backing Up Test Results');
                 if ($is_moscow) {
                     $drives = pts_file_io::glob('/dev/sd*');
                     sort($drives);
                     if (count($drives) > 0 && is_writable('/media/')) {
                         $select_drive = pts_user_io::prompt_text_menu('Select Drive / Partition To Save Results', $drives);
                         echo PHP_EOL . 'Attempting to mount: ' . $select_drive . PHP_EOL;
                         mkdir('/media/00-results-backup');
                         exec('mount ' . $select_drive . ' /media/00-results-backup');
                     }
                 }
                 foreach (pts_file_io::glob('/media/*') as $media_dir) {
                     if (!is_writable($media_dir)) {
                         echo PHP_EOL . $media_dir . ' is not writable.' . PHP_EOL;
                         continue;
                     }
                     echo PHP_EOL . 'Writing Test Results To: ' . $media_dir . PHP_EOL;
                     pts_file_io::copy(PTS_SAVE_RESULTS_PATH, $media_dir . '/');
                     break;
                 }
                 if ($is_moscow && is_dir('/media/00-results-backup')) {
                     exec('umount /media/00-results-backup');
                     rmdir('/media/00-results-backup');
                 }
                 break;
         }
         echo PHP_EOL . PHP_EOL;
     } while ($response != 'EXIT');
     if ($reboot_on_exit) {
         if (is_dir('/media/pts-auto-mount')) {
             pts_file_io::delete('/media/pts-auto-mount/pts', null, true);
             exec('umount /media/pts-auto-mount 2>&1');
         }
         exec('reboot');
     }
 }