public static function read_osx_system_profiler($data_type, $object, $multiple_objects = false, $ignore_values = array())
 {
     $value = $multiple_objects ? array() : false;
     if (pts_client::executable_in_path('system_profiler')) {
         $info = trim(shell_exec('system_profiler ' . $data_type . ' 2>&1'));
         $lines = explode("\n", $info);
         for ($i = 0; $i < count($lines) && ($value == false || $multiple_objects); $i++) {
             $line = pts_strings::colon_explode($lines[$i]);
             if (isset($line[0]) == false) {
                 continue;
             }
             $line_object = str_replace(' ', null, $line[0]);
             if (($cut_point = strpos($line_object, '(')) > 0) {
                 $line_object = substr($line_object, 0, $cut_point);
             }
             if (strtolower($line_object) == strtolower($object) && isset($line[1])) {
                 $this_value = trim($line[1]);
                 if (!empty($this_value) && !in_array($this_value, $ignore_values)) {
                     if ($multiple_objects) {
                         array_push($value, $this_value);
                     } else {
                         $value = $this_value;
                     }
                 }
             }
         }
     }
     return $value;
 }
 public static function what_provides($files_needed)
 {
     $packages_needed = array();
     foreach (pts_arrays::to_array($files_needed) as $file) {
         if (pts_client::executable_in_path('apt-file')) {
             if (!defined('APT_FILE_UPDATED')) {
                 shell_exec('apt-file update 2>&1');
                 define('APT_FILE_UPDATED', 1);
             }
             // Try appending common paths
             if (strpos($file, '.h') !== false) {
                 $apt_provides = self::run_apt_file_provides('/usr/include/' . $file);
                 if ($apt_provides != null) {
                     $packages_needed[$file] = $apt_provides;
                 }
             } else {
                 if (strpos($file, '.so') !== false) {
                     $apt_provides = self::run_apt_file_provides('/usr/lib/' . $file);
                     if ($apt_provides != null) {
                         $packages_needed[$file] = $apt_provides;
                     }
                 } else {
                     foreach (array('/usr/bin/', '/bin/', '/usr/sbin') as $possible_path) {
                         $apt_provides = self::run_apt_file_provides($possible_path . $file);
                         if ($apt_provides != null) {
                             $packages_needed[$file] = $apt_provides;
                             break;
                         }
                     }
                 }
             }
         }
     }
     return $packages_needed;
 }
 public function generate_download_object_list($do_file_checks = true)
 {
     $download_xml_file = $this->test_profile->get_file_download_spec();
     if ($download_xml_file != null) {
         $xml_parser = new pts_test_downloads_nye_XmlReader($download_xml_file);
         $package_url = $xml_parser->getXMLArrayValues('PhoronixTestSuite/Downloads/Package/URL');
         $package_md5 = $xml_parser->getXMLArrayValues('PhoronixTestSuite/Downloads/Package/MD5');
         $package_sha256 = $xml_parser->getXMLArrayValues('PhoronixTestSuite/Downloads/Package/SHA256');
         $package_filename = $xml_parser->getXMLArrayValues('PhoronixTestSuite/Downloads/Package/FileName');
         $package_filesize = $xml_parser->getXMLArrayValues('PhoronixTestSuite/Downloads/Package/FileSize');
         $package_platform = $xml_parser->getXMLArrayValues('PhoronixTestSuite/Downloads/Package/PlatformSpecific');
         $package_architecture = $xml_parser->getXMLArrayValues('PhoronixTestSuite/Downloads/Package/ArchitectureSpecific');
         foreach (array_keys($package_url) as $i) {
             if (!empty($package_platform[$i]) && $do_file_checks) {
                 $platforms = pts_strings::comma_explode($package_platform[$i]);
                 if (!in_array(phodevi::operating_system(), $platforms) && !(phodevi::is_bsd() && in_array('Linux', $platforms) && (pts_client::executable_in_path('kldstat') && strpos(shell_exec('kldstat -n linux 2>&1'), 'linux.ko') != false))) {
                     // This download does not match the operating system
                     continue;
                 }
             }
             if (!empty($package_architecture[$i]) && $do_file_checks) {
                 $architectures = pts_strings::comma_explode($package_architecture[$i]);
                 if (phodevi::cpu_arch_compatible($architectures) == false) {
                     // This download does not match the CPU architecture
                     continue;
                 }
             }
             $this->test_files[] = new pts_test_file_download($package_url[$i], $package_filename[$i], $package_filesize[$i], $package_md5[$i], $package_sha256[$i], $package_platform[$i], $package_architecture[$i]);
         }
     }
 }
 private static function net_counter($IFACE = 'en0')
 {
     $net_counter = -1;
     if (pts_client::executable_in_path('netstat') != false) {
         $netstat_lines = explode("\n", shell_exec('netstat -ib 2>&1'));
         $ibytes_index = -1;
         $obytes_index = -1;
         $ibytes = -1;
         $obytes = -1;
         foreach ($netstat_lines as $line) {
             if (strtok($line, ' ') == 'Name') {
                 $ibytes_index = strpos($line, 'Ierrs') + 6;
                 $obytes_index = strpos($line, 'Oerrs') + 6;
                 continue;
             }
             //$netstat_data = pts_strings::trim_explode(' ', $line);
             /*
              * Sample output:
              * Name  Mtu   Network       Address            Ipkts Ierrs     Ibytes    Opkts Oerrs     Obytes  Coll
              * en0   1500  <Link#4>    00:25:4b:c5:95:66    23350     0   19111634    13494     0    1632167     0
              */
             if (strtok($line, ' ') == $IFACE) {
                 $ibytes = strtok(substr($line, $ibytes_index), ' ');
                 $obytes = strtok(substr($line, $obytes_index), ' ');
                 $net_counter = $ibytes + $obytes;
             }
             if ($ibytes != -1 && $obytes != -1) {
                 break;
             }
         }
     }
     return $net_counter;
 }
 public static function __run_manager_setup(&$test_run_manager)
 {
     // Verify LINUX_PERF is set, `perf` can be found, and is Linux
     if (getenv('LINUX_PERF') == 0 || !pts_client::executable_in_path('perf') || !phodevi::is_linux()) {
         return pts_module::MODULE_UNLOAD;
         // This module doesn't have anything else to do
     }
     echo PHP_EOL . 'Linux PERF Monitoring Enabled.' . PHP_EOL . PHP_EOL;
     // This module won't be too useful if you're not saving the results to see the graphs
     $test_run_manager->force_results_save();
 }
 public static function read_acpiconf($desc)
 {
     $info = false;
     if (pts_client::executable_in_path('acpiconf 2> /dev/null')) {
         $output = shell_exec('acpiconf -i0');
         if (($point = strpos($output, $desc . ':')) !== false) {
             $info = substr($output, $point + strlen($desc) + 1);
             $info = substr($info, 0, strpos($info, "\n"));
             $info = trim($info);
         }
     }
     return $info;
 }
 public static function read_hal_property($udi, $key)
 {
     $value = false;
     if (pts_client::executable_in_path('hal-get-property')) {
         foreach (pts_arrays::to_array($udi) as $udi_check) {
             $value = trim(shell_exec('hal-get-property --udi ' . $udi_check . ' --key ' . $key . ' 2> /dev/null'));
             if ($value != false) {
                 break;
             }
         }
     }
     return $value;
 }
 public static function __startup()
 {
     // Make sure the file is removed to avoid potential problems if it was leftover from earlier run
     pts_module::remove_file('is_running');
     if (pts_client::executable_in_path('import') == false) {
         echo PHP_EOL . 'ImageMagick must first be installed onto this system!' . PHP_EOL;
         return pts_module::MODULE_UNLOAD;
     }
     if (($interval = pts_module::read_variable('SCREENSHOT_INTERVAL')) > 1 && is_numeric($interval)) {
         self::$screenshot_interval = $interval;
         return true;
     }
     return pts_module::MODULE_UNLOAD;
     self::$existing_screenshots = pts_file_io::glob(pts_module::save_dir() . 'screenshot-*.png');
 }
 protected function send_wol_wakeup($mac, $ip)
 {
     $sent_wol_request = false;
     if (PTS_IS_DAEMONIZED_SERVER_PROCESS) {
         foreach (array('etherwake', 'ether-wake') as $etherwake) {
             if (pts_client::executable_in_path($etherwake)) {
                 shell_exec($etherwake . ' ' . $mac . ' 2>&1');
                 $sent_wol_request = true;
                 sleep(5);
                 break;
             }
         }
     }
     if (true || $sent_wol_request == false) {
         pts_network::send_wol_packet($ip, $mac);
         $sent_wol_request = true;
     }
     return $sent_wol_request;
 }
 private function set_probe_mode()
 {
     if (phodevi::is_ati_graphics() && phodevi::is_linux()) {
         $this->probe_ati_overdrive = true;
     } else {
         if (phodevi::is_mesa_graphics() && pts_client::executable_in_path('radeontop')) {
             $this->probe_radeontop = true;
         } else {
             if (phodevi::is_nvidia_graphics()) {
                 $util = $this->read_nvidia_settings_gpu_utilization();
                 if ($util !== false) {
                     $this->probe_nvidia_settings = true;
                 } else {
                     if (pts_client::executable_in_path('nvidia-smi')) {
                         $this->probe_nvidia_smi = true;
                     }
                 }
             }
         }
     }
 }
 protected static function process_user_config_external_hook_process($process, $cmd_value, $description_string = null, &$passed_obj = null)
 {
     if (!empty($cmd_value) && (is_executable($cmd_value) || ($cmd_value = pts_client::executable_in_path($cmd_value)))) {
         $descriptor_spec = array(0 => array('pipe', 'r'), 1 => array('pipe', 'w'), 2 => array('pipe', 'w'));
         $env_vars = array('PTS_EXTERNAL_TEST_HOOK' => $process);
         if ($passed_obj instanceof pts_test_result) {
             $env_vars['PTS_EXTERNAL_TEST_IDENTIFIER'] = $passed_obj->test_profile->get_identifier();
             $env_vars['PTS_EXTERNAL_TEST_RUN_POSITION'] = $passed_obj->test_result_buffer->get_count() + 1;
             $env_vars['PTS_EXTERNAL_TEST_RUN_COUNT'] = $passed_obj->test_profile->get_times_to_run();
             $env_vars['PTS_EXTERNAL_TEST_ARGS'] = $passed_obj->get_arguments();
             $env_vars['PTS_EXTERNAL_TEST_DESCRIPTION'] = $passed_obj->get_arguments_description();
             $env_vars['PTS_EXTERNAL_TEST_RESULT_SET'] = $passed_obj->test_result_buffer->get_values_as_string();
             $env_vars['PTS_EXTERNAL_TEST_RESULT'] = $passed_obj->get_result() != 0 ? $passed_obj->get_result() : pts_arrays::last_element($passed_obj->test_result_buffer->get_values());
             $env_vars['PTS_EXTERNAL_TEST_HASH'] = bin2hex($passed_obj->get_comparison_hash());
             $env_vars['PTS_EXTERNAL_TEST_STD_DEV_PERCENT'] = pts_math::percent_standard_deviation($passed_obj->test_result_buffer->get_values());
             if (is_file($passed_obj->test_profile->get_install_dir() . 'cache-share-' . PTS_INIT_TIME . '.pt2so')) {
                 // There's a cache share present
                 $env_vars['PTS_EXTERNAL_TEST_CACHE_SHARE'] = 1;
             }
         } else {
             if ($passed_obj instanceof pts_test_run_manager) {
                 $env_vars['PTS_EXTERNAL_TESTS_IN_QUEUE'] = implode(':', $passed_obj->get_tests_to_run_identifiers());
                 $env_vars['PTS_EXTERNAL_TEST_FILE_NAME'] = $passed_obj->get_file_name();
                 $env_vars['PTS_EXTERNAL_TEST_IDENTIFIER'] = $passed_obj->get_results_identifier();
             }
         }
         $description_string != null && pts_client::$display->test_run_instance_error($description_string);
         $proc = proc_open($cmd_value, $descriptor_spec, $pipes, null, $env_vars);
         $std_output = stream_get_contents($pipes[1]);
         $return_value = proc_close($proc);
         // If you want PTS to exit or something when your script returns !0, you could add an 'exit;' or whatever you want below
         // The contents of $std_output is anything that may have been written by your script, if you want it to be interpreted by anything in this module
         if ($return_value != 0) {
             return false;
         }
     }
     return true;
 }
 public static function what_provides($files_needed)
 {
     $packages_needed = array();
     foreach (pts_arrays::to_array($files_needed) as $file) {
         if (pts_client::executable_in_path('dnf')) {
             $dnf_provides = self::run_dnf_provides($file);
             if ($dnf_provides != null) {
                 $packages_needed[$file] = $dnf_provides;
             } else {
                 // Try appending common paths
                 if (strpos($file, '.h') !== false) {
                     $dnf_provides = self::run_dnf_provides('/usr/include/' . $file);
                     if ($dnf_provides != null) {
                         $packages_needed[$file] = $dnf_provides;
                     }
                 } else {
                     if (strpos($file, '.so') !== false) {
                         $dnf_provides = self::run_dnf_provides('/usr/lib/' . $file);
                         if ($dnf_provides != null) {
                             $packages_needed[$file] = $dnf_provides;
                         }
                     } else {
                         foreach (array('/usr/bin/', '/bin/', '/usr/sbin') as $possible_path) {
                             $dnf_provides = self::run_dnf_provides($possible_path . $file);
                             if ($dnf_provides != null) {
                                 $packages_needed[$file] = $dnf_provides;
                                 break;
                             }
                         }
                     }
                 }
             }
         }
     }
     return $packages_needed;
 }
 public static function create_compiler_mask(&$test_install_request)
 {
     if (phodevi::is_bsd()) {
         // XXX: Using the compiler-mask causes a number of tests to fail to properly install due to compiler issues with at least PC-BSD 10.0
         return false;
     }
     // or pass false to $test_install_request to bypass the test checks
     $compilers = array();
     $external_dependencies = $test_install_request != false ? $test_install_request->test_profile->get_external_dependencies() : false;
     if ($test_install_request === false || in_array('build-utilities', $external_dependencies)) {
         // Handle C/C++ compilers for this external dependency
         $compilers['CC'] = array(pts_strings::first_in_string(pts_client::read_env('CC'), ' '), 'gcc', 'clang', 'icc', 'pcc');
         $compilers['CXX'] = array(pts_strings::first_in_string(pts_client::read_env('CXX'), ' '), 'g++', 'clang++', 'cpp');
     }
     if ($test_install_request === false || in_array('fortran-compiler', $external_dependencies)) {
         // Handle Fortran for this external dependency
         $compilers['F9X'] = array(pts_strings::first_in_string(pts_client::read_env('F9X'), ' '), pts_strings::first_in_string(pts_client::read_env('F95'), ' '), 'gfortran', 'f90', 'f95', 'fortran');
     }
     if (empty($compilers)) {
         // If the test profile doesn't request a compiler external dependency, probably not compiling anything
         return false;
     }
     foreach ($compilers as $compiler_type => $possible_compilers) {
         // Compilers to check for, listed in order of priority
         $compiler_found = false;
         foreach ($possible_compilers as $i => $possible_compiler) {
             // first check to ensure not null sent to executable_in_path from env variable
             if ($possible_compiler && (($compiler_path = is_executable($possible_compiler)) || ($compiler_path = pts_client::executable_in_path($possible_compiler, 'ccache')))) {
                 // Replace the array of possible compilers with a string to the detected compiler executable
                 $compilers[$compiler_type] = $compiler_path;
                 $compiler_found = true;
                 break;
             }
         }
         if ($compiler_found == false) {
             unset($compilers[$compiler_type]);
         }
     }
     if (!empty($compilers)) {
         // Create a temporary directory that will be at front of PATH and serve for masking the actual compiler
         if ($test_install_request instanceof pts_test_install_request) {
             $mask_dir = pts_client::temporary_directory() . '/pts-compiler-mask-' . $test_install_request->test_profile->get_identifier_base_name() . $test_install_request->test_profile->get_test_profile_version() . '/';
         } else {
             $mask_dir = pts_client::temporary_directory() . '/pts-compiler-mask-' . rand(100, 999) . '/';
         }
         pts_file_io::mkdir($mask_dir);
         $compiler_extras = array('CC' => array('safeguard-names' => array('gcc', 'cc'), 'environment-variables' => 'CFLAGS'), 'CXX' => array('safeguard-names' => array('g++', 'c++'), 'environment-variables' => 'CXXFLAGS'), 'F9X' => array('safeguard-names' => array('gfortran', 'f95'), 'environment-variables' => 'F9XFLAGS'));
         foreach ($compilers as $compiler_type => $compiler_path) {
             $compiler_name = basename($compiler_path);
             $main_compiler = $mask_dir . $compiler_name;
             // take advantage of environment-variables to be sure they're found in the string
             $env_var_check = PHP_EOL;
             /*
             foreach(pts_arrays::to_array($compiler_extras[$compiler_type]['environment-variables']) as $env_var)
             {
             	// since it's a dynamic check in script could probably get rid of this check...
             	if(true || getenv($env_var))
             	{
             		$env_var_check .= 'if [[ $COMPILER_OPTIONS != "*$' . $env_var . '*" ]]' . PHP_EOL . 'then ' . PHP_EOL . 'COMPILER_OPTIONS="$COMPILER_OPTIONS $' . $env_var . '"' . PHP_EOL . 'fi' . PHP_EOL;
             	}
             }
             */
             // Write the main mask for the compiler
             file_put_contents($main_compiler, '#!/bin/bash' . PHP_EOL . 'COMPILER_OPTIONS="$@"' . PHP_EOL . $env_var_check . PHP_EOL . 'echo $COMPILER_OPTIONS >> ' . $mask_dir . $compiler_type . '-options-' . $compiler_name . PHP_EOL . $compiler_path . ' "$@"' . PHP_EOL);
             // Make executable
             chmod($main_compiler, 0755);
             // The two below code chunks ensure the proper compiler is always hit
             if ($test_install_request instanceof pts_test_install_request && !in_array($compiler_name, pts_arrays::to_array($compiler_extras[$compiler_type]['safeguard-names'])) && getenv($compiler_type) == false) {
                 // So if e.g. clang becomes the default compiler, since it's not GCC, it will ensure CC is also set to clang beyond the masking below
                 $test_install_request->special_environment_vars[$compiler_type] = $compiler_name;
             }
             // Just in case any test profile script is statically always calling 'gcc' or anything not CC, try to make sure it hits one of the safeguard-names so it redirects to the intended compiler under test
             foreach (pts_arrays::to_array($compiler_extras[$compiler_type]['safeguard-names']) as $safe_name) {
                 if (!is_file($mask_dir . $safe_name)) {
                     symlink($main_compiler, $mask_dir . $safe_name);
                 }
             }
         }
         if ($test_install_request instanceof pts_test_install_request) {
             $test_install_request->compiler_mask_dir = $mask_dir;
             // Appending the rest of the path will be done automatically within call_test_script
             $test_install_request->special_environment_vars['PATH'] = $mask_dir;
         }
         return $mask_dir;
     }
     return false;
 }
 private static function vendor_identifier($type)
 {
     $os_vendor = phodevi::read_property('system', 'vendor-identifier');
     switch ($type) {
         case 'package-list':
             $file_check_success = is_file(PTS_EXDEP_PATH . 'xml/' . $os_vendor . '-packages.xml');
             break;
         case 'installer':
             $file_check_success = is_file(PTS_EXDEP_PATH . 'scripts/install-' . $os_vendor . '-packages.sh');
             break;
     }
     if ($file_check_success == false) {
         // Check the aliases to figure out the upstream distribution
         $os_vendor = false;
         $exdep_generic_parser = new pts_exdep_generic_parser();
         foreach ($exdep_generic_parser->get_vendors_list() as $this_vendor) {
             $exdep_platform_parser = new pts_exdep_platform_parser($this_vendor);
             $aliases = $exdep_platform_parser->get_aliases();
             if (in_array($os_vendor, $aliases)) {
                 $os_vendor = $this_vendor;
                 break;
             }
         }
         if ($os_vendor == false) {
             // Attempt to match the current operating system by seeing what package manager matches
             foreach ($exdep_generic_parser->get_vendors_list() as $this_vendor) {
                 $exdep_platform_parser = new pts_exdep_platform_parser($this_vendor);
                 $package_manager = $exdep_platform_parser->get_package_manager();
                 if ($package_manager != null && pts_client::executable_in_path($package_manager)) {
                     $os_vendor = $this_vendor;
                     break;
                 }
             }
         }
     }
     return $os_vendor;
 }
 public static function run_connection($args)
 {
     if (pts_client::create_lock(PTS_USER_PATH . 'phoromatic_lock') == false) {
         trigger_error('Phoromatic is already running.', E_USER_ERROR);
         return false;
     }
     define('PHOROMATIC_PROCESS', true);
     if (pts_client::$pts_logger == false) {
         pts_client::$pts_logger = new pts_logger();
     }
     pts_client::$pts_logger->log(pts_title(true) . ' [' . PTS_CORE_VERSION . '] starting Phoromatic client');
     if (phodevi::system_uptime() < 60) {
         echo 'PHOROMATIC: Sleeping for 60 seconds as system freshly started.' . PHP_EOL;
         pts_client::$pts_logger->log('Sleeping for 60 seconds as system freshly started');
         sleep(60);
     }
     $server_setup = self::setup_server_addressing($args);
     //$http_comm = new phoromatic_client_comm_http();
     if (!$server_setup) {
         if (PTS_IS_DAEMONIZED_SERVER_PROCESS) {
             if (pts_client::executable_in_path('reboot')) {
                 shell_exec('reboot');
                 sleep(5);
             }
         }
         return false;
     }
     $times_failed = 0;
     $has_success = false;
     $do_exit = false;
     $just_started = true;
     self::setup_system_environment();
     pts_client::$pts_logger->log('SYSTEM HARDWARE: ' . phodevi::system_hardware(true));
     pts_client::$pts_logger->log('SYSTEM SOFTWARE: ' . phodevi::system_software(true));
     while ($do_exit == false) {
         $server_response = phoromatic::upload_to_remote_server(array('r' => 'start'));
         if ($server_response == false) {
             $times_failed++;
             pts_client::$pts_logger->log('Server response failed');
             if ($times_failed >= 2) {
                 trigger_error('Communication with server failed.', E_USER_ERROR);
                 if (PTS_IS_DAEMONIZED_SERVER_PROCESS == false && $times_failed > 5) {
                     return false;
                 } else {
                     if (PTS_IS_DAEMONIZED_SERVER_PROCESS && $times_failed > 10) {
                         if (pts_client::executable_in_path('reboot')) {
                             shell_exec('reboot');
                             sleep(5);
                         }
                     }
                 }
             }
         } else {
             if (substr($server_response, 0, 1) == '[') {
                 // Likely a notice/warning from server
                 echo PHP_EOL . substr($server_response, 0, strpos($server_response, PHP_EOL)) . PHP_EOL;
             } else {
                 if (substr($server_response, 0, 1) == '{') {
                     $times_failed = 0;
                     $json = json_decode($server_response, true);
                     if ($has_success == false) {
                         $has_success = true;
                         pts_module::save_file('last-phoromatic-server', self::$server_address . ':' . self::$server_http_port . '/' . self::$account_id);
                     }
                     if ($json != null) {
                         if (isset($json['phoromatic']['error']) && !empty($json['phoromatic']['error'])) {
                             trigger_error($json['phoromatic']['error'], E_USER_ERROR);
                         }
                         if (isset($json['phoromatic']['response']) && !empty($json['phoromatic']['response'])) {
                             echo PHP_EOL . $json['phoromatic']['response'] . PHP_EOL;
                         }
                     }
                     if ($just_started) {
                         if (PTS_IS_DAEMONIZED_SERVER_PROCESS) {
                             $pid = pcntl_fork();
                             if ($pid == 0) {
                                 // Start the tick thread
                                 self::tick_thread();
                             }
                         }
                         $just_started = false;
                     }
                     if (isset($json['phoromatic']['pre_set_sys_env_vars']) && !empty($json['phoromatic']['pre_set_sys_env_vars'])) {
                         // pre_set_sys_env_vars was added during PTS 5.8 development
                         // Sets environment variables on client as specified via the Phoromatic Server's systems page
                         foreach (explode(';', $json['phoromatic']['pre_set_sys_env_vars']) as $i => $v_string) {
                             $var = explode('=', $v_string);
                             if (count($var) == 2) {
                                 putenv($var[0] . '=' . $var[1]);
                             }
                         }
                     }
                     switch (isset($json['phoromatic']['task']) ? $json['phoromatic']['task'] : null) {
                         case 'install':
                             phoromatic::update_system_status('Installing Tests');
                             pts_suite_nye_XmlReader::set_temporary_suite('pre-seed', $json['phoromatic']['test_suite']);
                             pts_test_installer::standard_install('pre-seed');
                             break;
                         case 'benchmark':
                             // Make sure all latest tests are available
                             pts_openbenchmarking::refresh_repository_lists(null, true);
                             $benchmark_timer = time();
                             self::$is_running_as_phoromatic_node = true;
                             $test_flags = pts_c::auto_mode | pts_c::batch_mode;
                             $suite_identifier = sha1(time() . rand(2, 1000));
                             pts_suite_nye_XmlReader::set_temporary_suite($suite_identifier, $json['phoromatic']['test_suite']);
                             self::$p_save_identifier = $json['phoromatic']['trigger_id'];
                             $phoromatic_results_identifier = self::$p_save_identifier;
                             $phoromatic_save_identifier = $json['phoromatic']['save_identifier'];
                             self::$p_schedule_id = isset($json['phoromatic']['schedule_id']) ? $json['phoromatic']['schedule_id'] : false;
                             self::$p_trigger_id = self::$p_save_identifier;
                             $benchmark_ticket_id = isset($json['phoromatic']['benchmark_ticket_id']) ? $json['phoromatic']['benchmark_ticket_id'] : null;
                             phoromatic::update_system_status('Running Benchmarks For: ' . $phoromatic_save_identifier);
                             if (pts_strings::string_bool($json['phoromatic']['settings']['RunInstallCommand'])) {
                                 if (isset($json['phoromatic']['pre_install_set_context'])) {
                                     phoromatic::set_user_context($json['phoromatic']['pre_install_set_context'], self::$p_trigger_id, self::$p_schedule_id, 'PRE_INSTALL');
                                 }
                                 if (pts_strings::string_bool($json['phoromatic']['settings']['ForceInstallTests'])) {
                                     $test_flags |= pts_c::force_install;
                                 }
                                 pts_client::set_test_flags($test_flags);
                                 pts_test_installer::standard_install($suite_identifier);
                                 if (isset($json['phoromatic']['post_install_set_context'])) {
                                     phoromatic::set_user_context($json['phoromatic']['post_install_set_context'], self::$p_trigger_id, self::$p_schedule_id, 'POST_INSTALL');
                                 }
                             }
                             $env_vars = isset($json['phoromatic']['environment_variables']) ? pts_strings::parse_value_string_vars($json['phoromatic']['environment_variables']) : array();
                             // Do the actual running
                             phodevi::clear_cache();
                             if (pts_test_run_manager::initial_checks($suite_identifier, 0, 'SHORT')) {
                                 self::$test_run_manager = new pts_test_run_manager($test_flags);
                                 pts_test_run_manager::set_batch_mode(array('UploadResults' => isset($json['phoromatic']['settings']['UploadResultsToOpenBenchmarking']) && pts_strings::string_bool($json['phoromatic']['settings']['UploadResultsToOpenBenchmarking']), 'SaveResults' => true, 'RunAllTestCombinations' => false, 'OpenBrowser' => false));
                                 // Load the tests to run
                                 if (self::$test_run_manager->load_tests_to_run($suite_identifier)) {
                                     phoromatic::update_system_status('Tests In Run Queue: ' . implode(', ', self::$test_run_manager->get_tests_to_run_identifiers()));
                                     if (isset($json['phoromatic']['pre_run_set_context'])) {
                                         phoromatic::set_user_context($json['phoromatic']['pre_run_set_context'], self::$p_trigger_id, self::$p_schedule_id, 'PRE_RUN');
                                     }
                                     if (isset($json['phoromatic']['settings']['UploadResultsToOpenBenchmarking']) && pts_strings::string_bool($json['phoromatic']['settings']['UploadResultsToOpenBenchmarking'])) {
                                         self::$test_run_manager->auto_upload_to_openbenchmarking();
                                         pts_openbenchmarking_client::override_client_setting('UploadSystemLogsByDefault', pts_strings::string_bool($json['phoromatic']['settings']['UploadSystemLogs']));
                                     }
                                     // Save results?
                                     // Run the actual tests
                                     if (isset($env_vars['PTS_CONCURRENT_TEST_RUNS']) && $env_vars['PTS_CONCURRENT_TEST_RUNS'] > 1) {
                                         $total_loop_time = isset($env_vars['TOTAL_LOOP_TIME']) ? $env_vars['TOTAL_LOOP_TIME'] : false;
                                         pts_client::$pts_logger->log('STRESS / MULTI-TEST EXECUTION STARTED @ ' . date('Y-m-d H:i:s'));
                                         pts_client::$pts_logger->log('CONCURRENT RUNS = ' . $env_vars['PTS_CONCURRENT_TEST_RUNS'] . ' TOTAL LOOP TIME = ' . $total_loop_time);
                                         $r = self::$test_run_manager->multi_test_stress_run_execute($env_vars['PTS_CONCURRENT_TEST_RUNS'], $total_loop_time);
                                         if ($r == false) {
                                             return;
                                         }
                                         pts_client::$pts_logger->log('STRESS / MULTI-TEST EXECUTION ENDED @ ' . date('Y-m-d H:i:s'));
                                     } else {
                                         self::$test_run_manager->auto_save_results($phoromatic_save_identifier, $phoromatic_results_identifier, isset($json['phoromatic']['test_description']) ? $json['phoromatic']['test_description'] : 'A Phoromatic run.');
                                         self::$test_run_manager->pre_execution_process();
                                         self::$test_run_manager->call_test_runs();
                                     }
                                     phoromatic::update_system_status('Benchmarks Completed For: ' . $phoromatic_save_identifier);
                                     self::$test_run_manager->post_execution_process();
                                     $elapsed_benchmark_time = time() - $benchmark_timer;
                                     // Handle uploading data to server
                                     $result_file = new pts_result_file(self::$test_run_manager->get_file_name());
                                     $upload_system_logs = pts_strings::string_bool($json['phoromatic']['settings']['UploadSystemLogs']);
                                     $server_response = self::upload_test_result($result_file, $upload_system_logs, isset($json['phoromatic']['schedule_id']) ? $json['phoromatic']['schedule_id'] : null, $phoromatic_save_identifier, $json['phoromatic']['trigger_id'], $elapsed_benchmark_time, $benchmark_ticket_id);
                                     //pts_client::$pts_logger->log('DEBUG RESPONSE MESSAGE: ' . $server_response);
                                     if (!pts_strings::string_bool($json['phoromatic']['settings']['ArchiveResultsLocally'])) {
                                         pts_client::remove_saved_result_file(self::$test_run_manager->get_file_name());
                                     }
                                 }
                                 if (isset($json['phoromatic']['post_install_set_context'])) {
                                     phoromatic::set_user_context($json['phoromatic']['post_install_set_context'], self::$p_trigger_id, self::$p_schedule_id, 'POST_RUN');
                                 }
                             }
                             self::$p_schedule_id = null;
                             self::$is_running_as_phoromatic_node = false;
                             break;
                         case 'reboot':
                             echo PHP_EOL . 'Phoromatic received a remote command to reboot.' . PHP_EOL;
                             phoromatic::update_system_status('Attempting System Reboot');
                             if (pts_client::executable_in_path('reboot')) {
                                 shell_exec('reboot');
                                 sleep(5);
                             }
                             break;
                         case 'shutdown-if-supports-wake':
                             $supports_wol = false;
                             foreach (pts_network::get_network_wol() as $net_device) {
                                 if (strpos($net_device, 'g') !== false) {
                                     $supports_wol = true;
                                     break;
                                 }
                             }
                             if (!$supports_wol) {
                                 break;
                             }
                         case 'shutdown':
                             if (isset($json['phoromatic']['client_update_script']) && !empty($json['phoromatic']['client_update_script'])) {
                                 self::run_client_update_script($json['phoromatic']['client_update_script']);
                                 sleep(10);
                             }
                             echo PHP_EOL . 'Phoromatic received a remote command to shutdown.' . PHP_EOL;
                             phoromatic::update_system_status('Attempting System Shutdown');
                             if (pts_client::executable_in_path('poweroff')) {
                                 shell_exec('poweroff');
                                 sleep(5);
                             }
                             break;
                         case 'maintenance':
                             echo PHP_EOL . 'Idling, system maintenance mode set by Phoromatic Server.' . PHP_EOL;
                             phoromatic::update_system_status('Maintenance Mode');
                             sleep(60);
                             break;
                         case 'idle':
                             if (isset($json['phoromatic']['client_update_script']) && !empty($json['phoromatic']['client_update_script'])) {
                                 self::run_client_update_script($json['phoromatic']['client_update_script']);
                             }
                             //echo PHP_EOL . 'Idling, waiting for task.' . PHP_EOL;
                             phoromatic::update_system_status('Idling, Waiting For Task');
                             break;
                         case 'exit':
                             echo PHP_EOL . 'Phoromatic received a remote command to exit.' . PHP_EOL;
                             phoromatic::update_system_status('Exiting Phoromatic');
                             $do_exit = true;
                             break;
                     }
                 }
             }
         }
         if (!$do_exit) {
             if ($server_response == false) {
                 sleep(rand(10, 30));
             } else {
                 sleep(60);
             }
         }
     }
     pts_client::release_lock(PTS_USER_PATH . 'phoromatic_lock');
 }
 public static function find_zeroconf_phoromatic_servers($find_multiple = false)
 {
     if (!pts_network::network_support_available()) {
         return null;
     }
     $hosts = $find_multiple ? array() : null;
     if (PTS_IS_CLIENT && pts_client::executable_in_path('avahi-browse')) {
         $avahi_browse = explode(PHP_EOL, shell_exec('avahi-browse -p -r -t _http._tcp 2>&1'));
         foreach (array_reverse($avahi_browse) as $avahi_line) {
             if (strrpos($avahi_line, 'phoromatic-server') !== false) {
                 $avahi_line = explode(';', $avahi_line);
                 if (isset($avahi_line[8]) && ip2long($avahi_line[7]) !== false && is_numeric($avahi_line[8])) {
                     $server_ip = $avahi_line[7];
                     $server_port = $avahi_line[8];
                     //echo $server_ip . ':' . $server_port;
                     if ($find_multiple) {
                         array_push($hosts, array($server_ip, $server_port));
                     } else {
                         $hosts = array($server_ip, $server_port);
                         break;
                     }
                 }
             }
         }
     }
     return $hosts;
 }
Example #17
0
 public static function run($r)
 {
     // Lets get stuff ready.
     if (PHP_VERSION_ID < 50400) {
         echo 'Running an unsupported PHP version. PHP 5.4+ is required to use this feature.' . PHP_EOL . PHP_EOL;
         return false;
     }
     $web_port = 0;
     $blocked_ports = array(2049, 3659, 4045, 6000);
     // SERVER JUST RUNNING FOR LOCAL SYSTEM, SO ALSO COME UP WITH RANDOM FREE PORT
     $server_ip = 'localhost';
     // Randomly choose a port and ensure it's not being used...
     $fp = false;
     $errno = null;
     $errstr = null;
     do {
         if ($fp != false) {
             fclose($fp);
         }
         $web_port = rand(2000, 5999);
         $web_socket_port = $web_port - 1;
     } while (($fp = fsockopen('127.0.0.1', $web_port, $errno, $errstr, 5)) != false || ($fp = fsockopen('127.0.0.1', $web_socket_port, $errno, $errstr, 5)) != false || in_array($web_port, $blocked_ports) || in_array($web_socket_port, $blocked_ports));
     // Check if we are running on Windows or a *nix.
     if (strtoupper(substr(PHP_OS, 0, 3)) === 'WIN') {
         $script_path = PTS_USER_PATH . 'web-server-launcher.bat';
         pts_file_io::unlink($script_path);
         // Lets turn off echo so we don't need to see every command.
         $server_launcher = '@echo off' . PHP_EOL;
         $server_launcher .= 'if "%~1"==":run_ws_server" goto :run_ws_server' . PHP_EOL;
         $server_launcher .= 'if "%~1"==":run_local_server" goto :run_local_server' . PHP_EOL;
         $server_launcher .= 'set CURRENT_DIR="%cd%"' . PHP_EOL . PHP_EOL;
         $server_launcher .= 'start cmd /c "%~f0" :run_ws_server' . PHP_EOL;
         $server_launcher .= 'start cmd /c "%~f0" :run_local_server' . PHP_EOL . PHP_EOL;
         // Setup configurations
         $server_launcher .= 'set PTS_WEBSOCKET_PORT=' . $web_socket_port . PHP_EOL;
         $server_launcher .= 'set PTS_MODE="CLIENT"' . PHP_EOL . PHP_EOL;
         // Windows has no sleep so we ping an invalid ip for a second!
         $server_launcher .= 'ping 192.0.2.2 -n 1 -w 1000 > nul' . PHP_EOL;
         // Browser Launching
         if (($browser = pts_client::executable_in_path('chromium-browser')) || ($browser = pts_client::executable_in_path('google-chrome'))) {
             $server_launcher .= 'echo "Launching Browser"' . PHP_EOL;
             $server_launcher .= $browser . ' --temp-profile --app=http://localhost:' . $web_port . ' -start-maximized';
             // chromium-browser --kiosk URL starts full-screen
         } else {
             if (($browser = pts_client::executable_in_path('firefox')) || ($browser = pts_client::executable_in_path('xdg-open'))) {
                 $server_launcher .= 'echo "Launching Browser"' . PHP_EOL;
                 $server_launcher .= $browser . ' http://localhost:' . $web_port;
                 // XXX: Need this here since Firefox and some other browsers will return right away rather than wait on process....
                 $server_launcher .= PHP_EOL . 'echo -n "Press [ENTER] to kill server..."' . PHP_EOL . 'read var_name';
             } else {
                 $server_launcher .= 'echo "Launch: http://localhost:' . $web_port . '"' . PHP_EOL;
                 $server_launcher .= PHP_EOL . 'echo "Press any key to kill server..."' . PHP_EOL . 'pause';
             }
         }
         // Shutdown / Kill Servers (Might want to find a cleaner way)
         $server_launcher .= PHP_EOL . 'taskkill /f /im php.exe';
         // For now lets clean this up.
         $server_launcher .= PHP_EOL . 'del /f ' . getenv('PTS_EXT_LAUNCH_SCRIPT_DIR') . 'run*' . PHP_EOL;
         $server_launcher .= 'exit /B' . PHP_EOL . PHP_EOL;
         // HTTP Server Setup
         $server_launcher .= ':run_local_server' . PHP_EOL;
         if (strpos(getenv('PHP_BIN'), 'hhvm')) {
             echo PHP_EOL . 'Unfortunately, the HHVM built-in web server has abandoned upstream. Users will need to use the PHP binary or other alternatives.' . PHP_EOL . PHP_EOL;
             return false;
         } else {
             $server_launcher .= getenv('PHP_BIN') . ' -S ' . $server_ip . ':' . $web_port . ' -t ' . PTS_CORE_PATH . 'web-interface 2> null  &' . PHP_EOL;
         }
         $server_launcher .= 'exit' . PHP_EOL . PHP_EOL;
         // WebSocket Server Setup
         $server_launcher .= ':run_ws_server' . PHP_EOL;
         $server_launcher .= 'cd ' . getenv('PTS_DIR') . PHP_EOL;
         $server_launcher .= getenv('PHP_BIN') . ' pts-core\\phoronix-test-suite.php start-ws-server &' . PHP_EOL;
         $server_launcher .= 'exit';
         // I dont believe this needs to be done for windows?
         //$server_launcher .= PHP_EOL . 'del /f ~\\.phoronix-test-suite\\run-lock*';
         file_put_contents($script_path, $server_launcher);
     } else {
         $script_path = getenv('PTS_EXT_LAUNCH_SCRIPT_DIR') . '/web-server-launcher';
         pts_file_io::unlink($script_path);
         $server_launcher = '#!/bin/sh' . PHP_EOL;
         // WebSocket Server Setup
         $server_launcher .= 'export PTS_WEBSOCKET_PORT=' . $web_socket_port . PHP_EOL;
         $server_launcher .= 'export PTS_WEBSOCKET_SERVER=GUI' . PHP_EOL;
         $server_launcher .= 'cd ' . getenv('PTS_DIR') . ' && PTS_MODE="CLIENT" ' . getenv('PHP_BIN') . ' pts-core/phoronix-test-suite.php start-ws-server &' . PHP_EOL;
         $server_launcher .= 'websocket_server_pid=$!' . PHP_EOL;
         // HTTP Server Setup
         if (strpos(getenv('PHP_BIN'), 'hhvm')) {
             echo PHP_EOL . 'Unfortunately, the HHVM built-in web server has abandoned upstream. Users will need to use the PHP binary or other alternatives.' . PHP_EOL . PHP_EOL;
             return false;
         } else {
             $server_launcher .= getenv('PHP_BIN') . ' -S ' . $server_ip . ':' . $web_port . ' -t ' . PTS_CORE_PATH . 'web-interface/ 2> /dev/null  &' . PHP_EOL;
             //2> /dev/null
         }
         $server_launcher .= 'http_server_pid=$!' . PHP_EOL;
         $server_launcher .= 'sleep 1' . PHP_EOL;
         // Browser Launching
         if (($browser = pts_client::executable_in_path('chromium-browser')) || ($browser = pts_client::executable_in_path('google-chrome'))) {
             $server_launcher .= 'echo "Launching Browser"' . PHP_EOL;
             $server_launcher .= $browser . ' --temp-profile --app=http://localhost:' . $web_port . ' -start-maximized';
             // chromium-browser --kiosk URL starts full-screen
         } else {
             if (($browser = pts_client::executable_in_path('firefox')) || ($browser = pts_client::executable_in_path('xdg-open'))) {
                 $server_launcher .= 'echo "Launching Browser"' . PHP_EOL;
                 $server_launcher .= $browser . ' http://localhost:' . $web_port;
                 // XXX: Need this here since Firefox and some other browsers will return right away rather than wait on process....
                 $server_launcher .= PHP_EOL . 'echo -n "Press [ENTER] to kill server..."' . PHP_EOL . 'read var_name';
             } else {
                 $server_launcher .= 'echo "Launch: http://localhost:' . $web_port . '"' . PHP_EOL;
                 $server_launcher .= PHP_EOL . 'echo -n "Press [ENTER] to kill server..."' . PHP_EOL . 'read var_name';
             }
         }
         // Shutdown / Kill Servers
         $server_launcher .= PHP_EOL . 'kill $http_server_pid';
         $server_launcher .= PHP_EOL . 'kill $websocket_server_pid';
         $server_launcher .= PHP_EOL . 'rm -f ~/.phoronix-test-suite/run-lock*';
         file_put_contents($script_path, $server_launcher);
     }
     echo 'To start server run new script: ' . $script_path;
 }
 public static function software_glxinfo_glsl_version()
 {
     $info = false;
     if (isset(phodevi::$vfs->glxinfo)) {
         $glxinfo = phodevi::$vfs->glxinfo;
     } else {
         if (PTS_IS_CLIENT && pts_client::executable_in_path('fglrxinfo')) {
             $glxinfo = shell_exec('fglrxinfo 2> /dev/null');
         }
     }
     foreach (array('OpenGL core profile shading language version string:', 'OpenGL shading language version string:') as $shader_v_string) {
         if (isset($glxinfo) && $info == false && ($pos = strpos($glxinfo, $shader_v_string)) !== false) {
             $info = substr($glxinfo, $pos + strlen($shader_v_string));
             $info = substr($info, 0, strpos($info, "\n"));
             $info = trim($info);
         }
     }
     return $info;
 }
 private static function sys_battery_power()
 {
     // Returns power consumption rate in mW
     $rate = -1;
     if (phodevi::is_linux()) {
         $power_now = phodevi_linux_parser::read_sysfs_node('/sys/class/power_supply/*/power_now', 'POSITIVE_NUMERIC', array('status' => 'Discharging'));
         if ($power_now != -1) {
             // sysfs power_now seems to be displayed in microWatts
             $rate = pts_math::set_precision($power_now / 1000, 2);
         }
         if ($rate == -1) {
             $battery = array('/battery/BAT0/state', '/battery/BAT1/state');
             $state = phodevi_linux_parser::read_acpi($battery, 'charging state');
             $power = phodevi_linux_parser::read_acpi($battery, 'present rate');
             $voltage = phodevi_linux_parser::read_acpi($battery, 'present voltage');
             if ($state == 'discharging') {
                 $power_unit = substr($power, strrpos($power, ' ') + 1);
                 $power = substr($power, 0, strpos($power, ' '));
                 if ($power_unit == 'mA') {
                     $voltage_unit = substr($voltage, strrpos($voltage, ' ') + 1);
                     $voltage = substr($voltage, 0, strpos($voltage, ' '));
                     if ($voltage_unit == 'mV') {
                         $rate = round($power * $voltage / 1000);
                     }
                 } else {
                     if ($power_unit == 'mW') {
                         $rate = $power;
                     }
                 }
             }
         }
         if ($rate == -1 && is_file('/sys/class/power_supply/BAT0/voltage_now') && is_file('/sys/class/power_supply/BAT0/current_now')) {
             $voltage_now = pts_file_io::file_get_contents('/sys/class/power_supply/BAT0/voltage_now') / 1000;
             $current_now = pts_file_io::file_get_contents('/sys/class/power_supply/BAT0/current_now') / 1000;
             $power_now = $voltage_now * $current_now / 1000;
             if ($power_now > 1) {
                 $rate = $power_now;
             }
         }
         if ($rate == -1 && is_file('/sys/class/power_supply/BAT1/voltage_now') && is_file('/sys/class/power_supply/BAT1/current_now')) {
             $voltage_now = pts_file_io::file_get_contents('/sys/class/power_supply/BAT1/voltage_now') / 1000;
             $current_now = pts_file_io::file_get_contents('/sys/class/power_supply/BAT1/current_now') / 1000;
             $power_now = $voltage_now * $current_now / 1000;
             if ($power_now > 1) {
                 $rate = $power_now;
             }
         }
     } else {
         if (phodevi::is_macosx()) {
             $amperage = abs(phodevi_osx_parser::read_osx_system_profiler('SPPowerDataType', 'Amperage'));
             // in mA
             $voltage = phodevi_osx_parser::read_osx_system_profiler('SPPowerDataType', 'Voltage');
             // in mV
             if ($amperage > 0 && $voltage > 0) {
                 $rate = round($amperage * $voltage / 1000);
             } else {
                 if (pts_client::executable_in_path('ioreg')) {
                     $ioreg = trim(shell_exec("ioreg -l | grep LegacyBatteryInfo | cut -d '{' -f 2 | tr -d \\} | tr ',' '=' | awk -F'=' '{print (\$2*\$10/10^22)}' 2>&1"));
                     if (is_numeric($ioreg) && $ioreg > 0) {
                         $rate = $ioreg;
                     }
                 }
             }
         } else {
             if (phodevi::is_solaris()) {
                 $battery = phodevi_solaris_parser::read_hal_property('/org/freedesktop/Hal/devices/pseudo/acpi_drv_0_battery0_0', 'battery.reporting.rate');
                 if (is_numeric($battery)) {
                     $rate = $battery;
                 }
             } else {
                 if (phodevi::is_bsd()) {
                     $battery = phodevi_bsd_parser::read_acpiconf('Present rate');
                     if ($battery && substr($battery, -2) == 'mW') {
                         $rate = substr($battery, 0, strpos($battery, ' '));
                     }
                 }
             }
         }
     }
     return $rate;
 }
 public function is_test_platform_supported()
 {
     // Check if the system's OS is supported by a test
     $supported = true;
     $platforms = $this->get_supported_platforms();
     if (!empty($platforms) && !in_array(phodevi::operating_system(), $platforms)) {
         if (phodevi::is_bsd() && in_array('Linux', $platforms) && (pts_client::executable_in_path('kldstat') && strpos(shell_exec('kldstat -n linux 2>&1'), 'linux.ko') != false)) {
             // The OS is BSD but there is Linux API/ABI compatibility support loaded
             $supported = true;
         } else {
             if (phodevi::is_hurd() && in_array('Linux', $platforms) && in_array('BSD', $platforms)) {
                 // For now until test profiles explicity express Hurd support, just list as supported the tests that work on both BSD and Linux
                 // TODO: fill in Hurd support for test profiles / see what works
                 $supported = true;
             } else {
                 $supported = false;
             }
         }
     }
     return $supported;
 }
    public static function run($r)
    {
        if (pts_client::create_lock(PTS_USER_PATH . 'phoromatic_server_lock') == false) {
            trigger_error('The Phoromatic Server is already running.', E_USER_ERROR);
            return false;
        }
        pts_file_io::unlink(getenv('PTS_EXT_LAUNCH_SCRIPT_DIR') . '/phoromatic-server-launcher');
        if (PHP_VERSION_ID < 50400) {
            echo 'Running an unsupported PHP version. PHP 5.4+ is required to use this feature.' . PHP_EOL . PHP_EOL;
            return false;
        }
        if (!function_exists('socket_create_listen')) {
            echo 'PHP Sockets support is needed to use the Phoromatic Server.' . PHP_EOL . PHP_EOL;
            return false;
        }
        $server_launcher = '#!/bin/sh' . PHP_EOL;
        $web_port = 0;
        $remote_access = pts_config::read_user_config('PhoronixTestSuite/Options/Server/RemoteAccessPort', 'RANDOM');
        $fp = false;
        $errno = null;
        $errstr = null;
        if ($remote_access == 'RANDOM') {
            do {
                if ($fp) {
                    fclose($fp);
                }
                $remote_access = rand(8000, 8999);
            } while (($fp = fsockopen('127.0.0.1', $remote_access, $errno, $errstr, 5)) != false);
            echo 'Port ' . $remote_access . ' chosen as random port for this instance. Change the default port via the Phoronix Test Suite user configuration file.' . PHP_EOL;
        }
        $remote_access = is_numeric($remote_access) && $remote_access > 1 ? $remote_access : false;
        $blocked_ports = array(2049, 3659, 4045, 6000, 9000);
        if ($remote_access) {
            // ALLOWING SERVER TO BE REMOTELY ACCESSIBLE
            $server_ip = '0.0.0.0';
            if (($fp = fsockopen('127.0.0.1', $remote_access, $errno, $errstr, 5)) != false) {
                fclose($fp);
                trigger_error('Port ' . $remote_access . ' is already in use by another server process. Close that process or change the Phoronix Test Suite server port via' . pts_config::get_config_file_location() . ' to proceed.', E_USER_ERROR);
                return false;
            } else {
                $web_port = $remote_access;
                $web_socket_port = pts_config::read_user_config('PhoronixTestSuite/Options/Server/WebSocketPort', '');
                while ($web_socket_port == null || !is_numeric($web_socket_port) || ($fp = fsockopen('127.0.0.1', $web_socket_port, $errno, $errstr, 5)) != false) {
                    if ($fp) {
                        fclose($fp);
                    }
                    $web_socket_port = rand(8000, 8999);
                }
            }
        } else {
            echo PHP_EOL . PHP_EOL . 'You must first configure the remote web / Phoromatic settings via:' . PHP_EOL . '    ' . pts_config::get_config_file_location() . PHP_EOL . PHP_EOL . 'The RemoteAccessPort should be a network port to use for HTTP communication while WebSocketPort should be set to another available network port. Set to RANDOM if wishing to use randomly chosen available ports.' . PHP_EOL . PHP_EOL;
            return false;
        }
        if (!extension_loaded('sqlite3')) {
            echo PHP_EOL . PHP_EOL . 'PHP SQLite3 support must first be enabled before accessing the Phoromatic server (e.g. installing the php5-sqlite or php-pdo package depending on the distribution).' . PHP_EOL . PHP_EOL;
            return false;
        }
        // Setup server logger
        define('PHOROMATIC_SERVER', true);
        // Just create the logger so now it will flush it out
        $pts_logger = new pts_logger();
        $pts_logger->clear_log();
        echo pts_core::program_title(true) . ' starting Phoromatic Server' . PHP_EOL;
        $pts_logger->log(pts_core::program_title(true) . ' starting Phoromatic Server on ' . pts_network::get_local_ip());
        echo 'Phoronix Test Suite User-Data Directory Path: ' . PTS_USER_PATH . PHP_EOL;
        echo 'Phoronix Test Suite Configuration File: ' . pts_config::get_config_file_location() . PHP_EOL;
        echo 'Phoromatic Server Log File: ' . $pts_logger->get_log_file_location() . PHP_EOL;
        $pts_logger->log('PTS_USER_PATH = ' . PTS_USER_PATH);
        $pts_logger->log('PTS_DOWNLOAD_CACHE_PATH = ' . PTS_DOWNLOAD_CACHE_PATH);
        $pts_logger->log('XML Configuration File = ' . pts_config::get_config_file_location());
        // WebSocket Server Setup
        $server_launcher .= 'export PTS_WEB_PORT=' . $web_port . PHP_EOL;
        $server_launcher .= 'export PTS_WEBSOCKET_PORT=' . $web_socket_port . PHP_EOL;
        $server_launcher .= 'export PTS_WEBSOCKET_SERVER=PHOROMATIC' . PHP_EOL;
        $server_launcher .= 'export PTS_NO_FLUSH_LOGGER=1' . PHP_EOL;
        $server_launcher .= 'export PTS_PHOROMATIC_SERVER=1' . PHP_EOL;
        $server_launcher .= 'export PTS_PHOROMATIC_LOG_LOCATION=' . $pts_logger->get_log_file_location() . PHP_EOL;
        $server_launcher .= 'cd ' . getenv('PTS_DIR') . ' && PTS_MODE="CLIENT" ' . getenv('PHP_BIN') . ' pts-core/phoronix-test-suite.php start-ws-server &' . PHP_EOL;
        $server_launcher .= 'websocket_server_pid=$!' . PHP_EOL;
        $pts_logger->log('Starting WebSocket process on port ' . $web_socket_port);
        $server_launcher .= 'cd ' . getenv('PTS_DIR') . ' && PTS_MODE="CLIENT" ' . getenv('PHP_BIN') . ' pts-core/phoronix-test-suite.php start-phoromatic-event-server &' . PHP_EOL;
        $server_launcher .= 'event_server_pid=$!' . PHP_EOL;
        // HTTP Server Setup
        if (false && pts_client::executable_in_path('nginx') && is_file('/run/php-fpm/php-fpm.pid')) {
            // NGINX
            $nginx_conf = 'error_log /tmp/error.log;
			pid /tmp/nginx.pid;
			worker_processes 1;

			events {
			  worker_connections 1024;
			}

			http {
			  client_body_temp_path /tmp/client_body;
			  fastcgi_temp_path /tmp/fastcgi_temp;
			  proxy_temp_path /tmp/proxy_temp;
			  scgi_temp_path /tmp/scgi_temp;
			  uwsgi_temp_path /tmp/uwsgi_temp;
			  tcp_nopush on;
			  tcp_nodelay on;
			  keepalive_timeout 180;
			  types_hash_max_size 2048;
			  include /etc/nginx/mime.types;
			  index index.php;

			  server {
			    listen ' . $web_port . ';
			    listen [::]:' . $web_port . ' default ipv6only=on;
			    access_log /tmp/access.log;
			    error_log /tmp/error.log;
			    root ' . PTS_CORE_PATH . 'phoromatic/public_html;
				index index.php;
			      try_files $uri $uri/ /index.php;
				location / {
				autoindex on;
				}
				location ~ \\.php$ {
				     include        /etc/nginx/fastcgi_params;
				     fastcgi_param  SCRIPT_FILENAME  $document_root/$fastcgi_script_name;
				     fastcgi_split_path_info ^(.+\\.php)(/.+)$;
				     fastcgi_pass   127.0.0.1:9000;
				     fastcgi_index  index.php;
				}
			  }
			}';
            $nginx_conf_file = tempnam(PTS_USER_PATH, 'nginx_conf_');
            file_put_contents($nginx_conf_file, $nginx_conf);
            $server_launcher .= 'nginx -c ' . $nginx_conf_file . PHP_EOL . 'rm -f ' . $nginx_conf_file . PHP_EOL;
        } else {
            if (($mongoose = pts_client::executable_in_path('mongoose')) && ($php_cgi = pts_client::executable_in_path('php-cgi'))) {
                // Mongoose Embedded Web Server
                $server_launcher .= $mongoose . ' -p ' . $web_port . ' -r ' . PTS_CORE_PATH . 'phoromatic/public_html/ -I ' . $php_cgi . ' -i index.php > /dev/null 2>> $PTS_PHOROMATIC_LOG_LOCATION &' . PHP_EOL;
                //2> /dev/null
            } else {
                if (strpos(getenv('PHP_BIN'), 'hhvm')) {
                    echo PHP_EOL . 'Unfortunately, the HHVM built-in web server has abandoned upstream. Users will need to use the PHP binary or other alternatives.' . PHP_EOL . PHP_EOL;
                    return;
                } else {
                    // PHP Web Server
                    $server_launcher .= getenv('PHP_BIN') . ' -S ' . $server_ip . ':' . $web_port . ' -t ' . PTS_CORE_PATH . 'phoromatic/public_html/ > /dev/null 2>> $PTS_PHOROMATIC_LOG_LOCATION &' . PHP_EOL;
                    //2> /dev/null
                }
            }
        }
        $server_launcher .= 'http_server_pid=$!' . PHP_EOL;
        $server_launcher .= 'sleep 1' . PHP_EOL;
        $server_launcher .= 'echo "The Phoromatic Web Interface Is Accessible At: http://localhost:' . $web_port . '"' . PHP_EOL;
        $pts_logger->log('Starting HTTP process @ http://localhost:' . $web_port);
        // Avahi for zeroconf network discovery support
        if (pts_config::read_user_config('PhoronixTestSuite/Options/Server/AdvertiseServiceZeroConf', 'TRUE')) {
            if (is_dir('/etc/avahi/services') && is_writable('/etc/avahi/services')) {
                file_put_contents('/etc/avahi/services/phoromatic-server.service', '<?xml version="1.0" standalone=\'no\'?>
<!DOCTYPE service-group SYSTEM "avahi-service.dtd">
<service-group>
  <name replace-wildcards="yes">phoromatic-server-%h</name>
  <service>
    <type>_http._tcp</type>
    <port>' . $web_port . '</port>
  </service>
</service-group>');
            } else {
                if (pts_client::executable_in_path('avahi-publish')) {
                    $hostname = phodevi::read_property('system', 'hostname');
                    $hostname = $hostname == null ? rand(0, 99) : $hostname;
                    $server_launcher .= 'avahi-publish -s phoromatic-server-' . $hostname . ' _http._tcp ' . $web_port . ' "Phoronix Test Suite Phoromatic" > /dev/null 2> /dev/null &' . PHP_EOL;
                    $server_launcher .= 'avahi_publish_pid=$!' . PHP_EOL;
                }
            }
        }
        // Wait for input to shutdown process..
        if (!PTS_IS_DAEMONIZED_SERVER_PROCESS) {
            $server_launcher .= PHP_EOL . 'echo -n "Press [ENTER] to kill server..."' . PHP_EOL;
            $server_launcher .= PHP_EOL . 'read var_name';
        } else {
            $server_launcher .= PHP_EOL . 'while [ ! -f "/var/lib/phoronix-test-suite/end-phoromatic-server" ];';
            $server_launcher .= PHP_EOL . 'do';
            $server_launcher .= PHP_EOL . 'sleep 1';
            $server_launcher .= PHP_EOL . 'done';
            $server_launcher .= PHP_EOL . 'rm -f /var/lib/phoronix-test-suite/end-phoromatic-server' . PHP_EOL;
        }
        // Shutdown / Kill Servers
        $server_launcher .= PHP_EOL . 'kill $http_server_pid';
        $server_launcher .= PHP_EOL . 'kill $websocket_server_pid';
        $server_launcher .= PHP_EOL . 'kill $event_server_pid';
        if (is_writable('/etc/avahi/services') && is_file('/etc/avahi/services/phoromatic-server.service')) {
            $server_launcher .= PHP_EOL . 'rm -f /etc/avahi/services/phoromatic-server.service';
        } else {
            $server_launcher .= PHP_EOL . 'kill $avahi_publish_pid';
        }
        $server_launcher .= PHP_EOL . 'rm -f ~/.phoronix-test-suite/run-lock*';
        file_put_contents(getenv('PTS_EXT_LAUNCH_SCRIPT_DIR') . '/phoromatic-server-launcher', $server_launcher);
    }
Example #22
0
 public static function system_uptime()
 {
     // Returns the system's uptime in seconds
     $uptime = 1;
     if (is_file('/proc/uptime')) {
         $uptime = pts_strings::first_in_string(pts_file_io::file_get_contents('/proc/uptime'));
     } else {
         if (($uptime_cmd = pts_client::executable_in_path('uptime')) != false) {
             $uptime_counter = 0;
             $uptime_output = shell_exec($uptime_cmd . ' 2>&1');
             $uptime_output = substr($uptime_output, strpos($uptime_output, ' up') + 3);
             $uptime_output = substr($uptime_output, 0, strpos($uptime_output, ' user'));
             $uptime_output = substr($uptime_output, 0, strrpos($uptime_output, ',')) . ' ';
             if (($day_end_pos = strpos($uptime_output, ' day')) !== false) {
                 $day_output = substr($uptime_output, 0, $day_end_pos);
                 $day_output = substr($day_output, strrpos($day_output, ' ') + 1);
                 if (is_numeric($day_output)) {
                     $uptime_counter += $day_output * 86400;
                 }
             }
             if (($mins_end_pos = strpos($uptime_output, ' mins')) !== false) {
                 $mins_output = substr($uptime_output, 0, $day_end_pos);
                 $mins_output = substr($mins_output, strrpos($mins_output, ' ') + 1);
                 if (is_numeric($mins_output)) {
                     $uptime_counter += $mins_output * 60;
                 }
             }
             if (($time_split_pos = strpos($uptime_output, ':')) !== false) {
                 $hours_output = substr($uptime_output, 0, $time_split_pos);
                 $hours_output = substr($hours_output, strrpos($hours_output, ' ') + 1);
                 $mins_output = substr($uptime_output, $time_split_pos + 1);
                 $mins_output = substr($mins_output, 0, strpos($mins_output, ' '));
                 if (is_numeric($hours_output)) {
                     $uptime_counter += $hours_output * 3600;
                 }
                 if (is_numeric($mins_output)) {
                     $uptime_counter += $mins_output * 60;
                 }
             }
             if (is_numeric($uptime_counter) && $uptime_counter > 0) {
                 $uptime = $uptime_counter;
             }
         }
     }
     return intval($uptime);
 }
Example #23
0
 public static function display_web_page($URL, $alt_text = null, $default_open = true, $auto_open = false)
 {
     if (pts_client::read_env('DISPLAY') == false && pts_client::read_env('WAYLAND_DISPLAY') == false && phodevi::is_windows() == false && phodevi::is_macosx() == false || defined('PHOROMATIC_PROCESS')) {
         return;
     }
     if ($auto_open == false) {
         $view_results = pts_user_io::prompt_bool_input($alt_text == null ? 'Do you want to view the results in your web browser' : $alt_text, $default_open);
     } else {
         $view_results = true;
     }
     if ($view_results) {
         static $browser = null;
         if ($browser == null) {
             $config_browser = pts_config::read_user_config('PhoronixTestSuite/Options/General/DefaultBrowser', null);
             if ($config_browser != null && (is_executable($config_browser) || ($config_browser = pts_client::executable_in_path($config_browser)))) {
                 $browser = $config_browser;
             } else {
                 if (phodevi::is_windows()) {
                     $windows_browsers = array('C:\\Program Files (x86)\\Mozilla Firefox\\firefox.exe', 'C:\\Program Files\\Internet Explorer\\iexplore.exe');
                     foreach ($windows_browsers as $browser_test) {
                         if (is_executable($browser_test)) {
                             $browser = $browser_test;
                             break;
                         }
                     }
                     if (substr($URL, 0, 1) == '\\') {
                         $URL = 'file:///C:' . str_replace('/', '\\', $URL);
                     }
                 } else {
                     $possible_browsers = array('firefox', 'mozilla', 'x-www-browser', 'open', 'xdg-open', 'iceweasel', 'konqueror', 'epiphany', 'google-chrome');
                     foreach ($possible_browsers as &$b) {
                         if ($b = pts_client::executable_in_path($b)) {
                             $browser = $b;
                             break;
                         }
                     }
                 }
             }
         }
         if ($browser != null) {
             shell_exec($browser . ' "' . $URL . '" 2> /dev/null &');
         } else {
             echo PHP_EOL . 'No Web Browser Found.' . PHP_EOL;
         }
     }
 }
 public static function support_check()
 {
     if (phodevi::is_ati_graphics() && phodevi::is_linux()) {
         $gpu_usage = self::ati_overdrive_core_usage();
         if (is_numeric($gpu_usage)) {
             self::$probe_ati_overdrive = true;
             return true;
         }
     } else {
         if (phodevi::is_mesa_graphics()) {
             if (pts_client::executable_in_path('radeontop')) {
                 $test = self::radeontop_gpu_usage();
                 if (is_numeric($test) && $test >= 0) {
                     self::$probe_radeontop = true;
                     return true;
                 }
             } else {
                 if (is_readable('/sys/kernel/debug/dri/0/radeon_fence_info')) {
                     $fence_speed = self::radeon_fence_speed();
                     if (is_numeric($fence_speed) && $fence_speed >= 0) {
                         self::$probe_radeon_fences = true;
                         return true;
                     }
                 } else {
                     if (is_readable('/sys/kernel/debug/dri/0/i915_gem_seqno')) {
                         $commands = self::intel_command_speed();
                         if (is_numeric($commands) && $commands > 0) {
                             self::$probe_intel_commands = true;
                             return true;
                         }
                     }
                 }
             }
         } else {
             if (phodevi::is_nvidia_graphics()) {
                 $util = self::read_nvidia_settings_gpu_utilization();
                 if ($util !== false) {
                     self::$probe_nvidia_settings = true;
                     return true;
                 } else {
                     if (pts_client::executable_in_path('nvidia-smi')) {
                         $usage = self::nvidia_core_usage();
                         if (is_numeric($usage) && $usage >= 0 && $usage <= 100) {
                             self::$probe_nvidia_smi = true;
                             return true;
                         }
                     }
                 }
             }
         }
     }
     return false;
 }
 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);
 }
 public static function sw_wine_version()
 {
     $wine_version = null;
     if (pts_client::executable_in_path('wine') != false) {
         $wine_version = trim(shell_exec('wine --version 2>&1'));
     } else {
         if (pts_client::executable_in_path('winecfg.exe') != false && pts_client::read_env('WINE_VERSION')) {
             $wine_version = trim(pts_client::read_env('WINE_VERSION'));
             if (stripos($wine_version, 'wine') === false) {
                 $wine_version = 'wine-' . $wine_version;
             }
         }
     }
     return $wine_version;
 }
 public static function call_test_script($test_profile, $script_name, $print_string = null, $pass_argument = null, $extra_vars_append = null, $use_ctp = true)
 {
     $extra_vars = pts_tests::extra_environmental_variables($test_profile);
     if (isset($extra_vars_append['PATH'])) {
         // Special case variable where you likely want the two merged rather than overwriting
         $extra_vars['PATH'] = $extra_vars_append['PATH'] . (substr($extra_vars_append['PATH'], -1) != ':' ? ':' : null) . $extra_vars['PATH'];
         unset($extra_vars_append['PATH']);
     }
     if (is_array($extra_vars_append)) {
         $extra_vars = array_merge($extra_vars, $extra_vars_append);
     }
     // TODO: call_test_script could be better cleaned up to fit more closely with new pts_test_profile functions
     $result = null;
     $test_directory = $test_profile->get_install_dir();
     pts_file_io::mkdir($test_directory, 0777, true);
     $os_postfix = '_' . strtolower(phodevi::operating_system());
     $test_profiles = array($test_profile);
     if ($use_ctp) {
         $test_profiles = array_merge($test_profiles, $test_profile->extended_test_profiles());
     }
     if (pts_client::executable_in_path('bash')) {
         $sh = 'bash';
     } else {
         $sh = 'sh';
     }
     foreach ($test_profiles as &$this_test_profile) {
         $test_resources_location = $this_test_profile->get_resource_dir();
         if (is_file($run_file = $test_resources_location . $script_name . $os_postfix . '.sh') || is_file($run_file = $test_resources_location . $script_name . '.sh')) {
             if (!empty($print_string)) {
                 pts_client::$display->test_run_message($print_string);
             }
             if (phodevi::is_windows() || pts_client::read_env('USE_PHOROSCRIPT_INTERPRETER') != false) {
                 $phoroscript = new pts_phoroscript_interpreter($run_file, $extra_vars, $test_directory);
                 $phoroscript->execute_script($pass_argument);
                 $this_result = null;
             } else {
                 $this_result = pts_client::shell_exec('cd ' . $test_directory . ' && ' . $sh . ' ' . $run_file . ' "' . $pass_argument . '" 2>&1', $extra_vars);
             }
             if (trim($this_result) != null) {
                 $result = $this_result;
             }
         }
     }
     return $result;
 }
 public static function gpu_model()
 {
     // Report graphics processor string
     $info = phodevi_parser::read_glx_renderer();
     $video_ram = phodevi::read_property('gpu', 'memory-capacity');
     if (phodevi::is_ati_graphics() && phodevi::is_linux()) {
         $crossfire_status = phodevi_linux_parser::read_amd_pcsdb('SYSTEM/Crossfire/chain/*,Enable');
         $crossfire_status = pts_arrays::to_array($crossfire_status);
         $crossfire_card_count = 0;
         for ($i = 0; $i < count($crossfire_status); $i++) {
             if ($crossfire_status[$i] == '0x00000001') {
                 $crossfire_card_count += 2;
                 // For now assume each chain is 2 cards, but proper way would be NumSlaves + 1
             }
         }
         $adapters = phodevi_linux_parser::read_amd_graphics_adapters();
         if (count($adapters) > 0) {
             $video_ram = $video_ram > 64 ? ' ' . $video_ram . 'MB' : null;
             // assume more than 64MB of vRAM
             if ($crossfire_card_count > 1 && $crossfire_card_count <= count($adapters)) {
                 $unique_adapters = array_unique($adapters);
                 if (count($unique_adapters) == 1) {
                     if (strpos($adapters[0], 'X2') > 0 && $crossfire_card_count > 1) {
                         $crossfire_card_count -= 1;
                     }
                     $info = $crossfire_card_count . ' x ' . $adapters[0] . $video_ram . ' CrossFire';
                 } else {
                     $info = implode(', ', $unique_adapters) . ' CrossFire';
                 }
             } else {
                 $info = $adapters[0] . $video_ram;
             }
         }
     } else {
         if (phodevi::is_macosx()) {
             $system_profiler_info = implode(' + ', phodevi_osx_parser::read_osx_system_profiler('SPDisplaysDataType', 'ChipsetModel', true));
             if (!empty($system_profiler_info)) {
                 $info = $system_profiler_info;
             }
         } else {
             if (phodevi::is_nvidia_graphics()) {
                 if ($info == null) {
                     if (pts_client::executable_in_path('nvidia-settings')) {
                         $nv_gpus = shell_exec('nvidia-settings -q gpus 2>&1');
                         // TODO: search for more than one GPU
                         $nv_gpus = substr($nv_gpus, strpos($nv_gpus, '[0]'));
                         $nv_gpus = substr($nv_gpus, strpos($nv_gpus, '(') + 1);
                         $nv_gpus = substr($nv_gpus, 0, strpos($nv_gpus, ')'));
                         if (stripos($nv_gpus, 'GeForce') !== false || stripos($nv_gpus, 'Quadro') !== false) {
                             $info = $nv_gpus;
                         }
                     }
                 }
                 $sli_mode = phodevi_parser::read_nvidia_extension('SLIMode');
                 if (!empty($sli_mode) && $sli_mode != 'Off') {
                     $info .= ' SLI';
                 }
             } else {
                 if (phodevi::is_solaris()) {
                     if (($cut = strpos($info, 'DRI ')) !== false) {
                         $info = substr($info, $cut + 4);
                     }
                     if (($cut = strpos($info, ' Chipset')) !== false) {
                         $info = substr($info, 0, $cut);
                     }
                     if ($info == false && isset(phodevi::$vfs->xorg_log)) {
                         $xorg_log = phodevi::$vfs->xorg_log;
                         if (($x = strpos($xorg_log, '(0): Chipset: ')) !== false) {
                             $xorg_log = substr($xorg_log, $x + 14);
                             $xorg_log = str_replace(array('(R)', '"'), null, substr($xorg_log, 0, strpos($xorg_log, PHP_EOL)));
                             if (($c = strpos($xorg_log, '[')) || ($c = strpos($xorg_log, '('))) {
                                 $xorg_log = substr($xorg_log, 0, $c);
                             }
                             if (phodevi::is_product_string($xorg_log)) {
                                 $info = $xorg_log;
                             }
                         }
                     }
                 } else {
                     if (phodevi::is_bsd()) {
                         $drm_info = phodevi_bsd_parser::read_sysctl('dev.drm.0.%desc');
                         if (!$drm_info) {
                             $drm_info = phodevi_bsd_parser::read_sysctl('dev.nvidia.0.%desc');
                         }
                         if (!$drm_info) {
                             $agp_info = phodevi_bsd_parser::read_sysctl('dev.agp.0.%desc');
                             if ($agp_info != false) {
                                 $info = $agp_info;
                             }
                         } else {
                             $info = $drm_info;
                         }
                         if ($info == null && isset(phodevi::$vfs->xorg_log)) {
                             $xorg_log = phodevi::$vfs->xorg_log;
                             if (($e = strpos($xorg_log, ' at 01@00:00:0')) !== false) {
                                 $xorg_log = substr($xorg_log, 0, $e);
                                 $info = substr($xorg_log, strrpos($xorg_log, 'Found ') + 6);
                             }
                         }
                     } else {
                         if (phodevi::is_windows()) {
                             $info = phodevi_windows_parser::read_cpuz('Display Adapters', 'Name');
                         }
                     }
                 }
             }
         }
     }
     if (empty($info) || strpos($info, 'Mesa ') !== false || strpos($info, 'Gallium ') !== false) {
         if (phodevi::is_windows() == false) {
             $info_pci = phodevi_linux_parser::read_pci('VGA compatible controller', false);
             if (!empty($info_pci)) {
                 $info = $info_pci;
                 if (strpos($info, 'Intel 2nd Generation Core Family') !== false || strpos($info, 'Gen Core') !== false) {
                     // Try to come up with a better non-generic string
                     $was_reset = false;
                     if (isset(phodevi::$vfs->xorg_log)) {
                         /*
                         $ cat /var/log/Xorg.0.log | grep -i Chipset
                         [     8.421] (II) intel: Driver for Intel Integrated Graphics Chipsets: i810,
                         [     8.421] (II) VESA: driver for VESA chipsets: vesa
                         [     8.423] (II) intel(0): Integrated Graphics Chipset: Intel(R) Sandybridge Mobile (GT2+)
                         [     8.423] (--) intel(0): Chipset: "Sandybridge Mobile (GT2+)"
                         */
                         $xorg_log = phodevi::$vfs->xorg_log;
                         if (($x = strpos($xorg_log, 'Integrated Graphics Chipset: ')) !== false) {
                             $xorg_log = substr($xorg_log, $x + 29);
                             $xorg_log = str_replace(array('(R)', '"'), null, substr($xorg_log, 0, strpos($xorg_log, PHP_EOL)));
                             if (stripos($xorg_log, 'Intel') === false) {
                                 $xorg_log = 'Intel ' . $xorg_log;
                             }
                             // if string is too long, likely not product
                             if (!isset($xorg_log[45])) {
                                 $info = $xorg_log;
                                 $was_reset = true;
                             }
                         } else {
                             if (($x = strpos($xorg_log, '(0): Chipset: ')) !== false) {
                                 $xorg_log = substr($xorg_log, $x + 14);
                                 $xorg_log = str_replace(array('(R)', '"'), null, substr($xorg_log, 0, strpos($xorg_log, PHP_EOL)));
                                 if (stripos($xorg_log, 'Intel') === false) {
                                     $xorg_log = 'Intel ' . $xorg_log;
                                 }
                                 // if string is too long, likely not product
                                 if (!isset($xorg_log[45])) {
                                     $info = $xorg_log;
                                     $was_reset = true;
                                 }
                             }
                         }
                     }
                     if ($was_reset == false && isset(phodevi::$vfs->i915_capabilities)) {
                         $i915_caps = phodevi::$vfs->i915_capabilities;
                         if (($x = strpos($i915_caps, 'gen: ')) !== false) {
                             $gen = substr($i915_caps, $x + 5);
                             $gen = substr($gen, 0, strpos($gen, PHP_EOL));
                             if (is_numeric($gen)) {
                                 $info = 'Intel Gen' . $gen;
                                 if (strpos($i915_caps, 'is_mobile: yes') !== false) {
                                     $info .= ' Mobile';
                                 }
                             }
                         }
                     }
                 }
             }
         }
         if (($start_pos = strpos($info, ' DRI ')) > 0) {
             $info = substr($info, $start_pos + 5);
         }
         if (empty($info) && isset(phodevi::$vfs->xorg_log)) {
             $log_parse = phodevi::$vfs->xorg_log;
             $log_parse = substr($log_parse, strpos($log_parse, 'Chipset') + 8);
             $log_parse = substr($log_parse, 0, strpos($log_parse, 'found'));
             if (strpos($log_parse, '(--)') === false && strlen(str_ireplace(array('ATI', 'NVIDIA', 'VIA', 'Intel'), '', $log_parse)) != strlen($log_parse)) {
                 $info = $log_parse;
             }
         }
         if (empty($info) && is_readable('/sys/class/graphics/fb0/name')) {
             switch (pts_file_io::file_get_contents('/sys/class/graphics/fb0/name')) {
                 case 'omapdrm':
                     $info = 'Texas Instruments OMAP';
                     // The OMAP DRM driver currently is for OMAP2/3/4 hardware
                     break;
                 case 'exynos':
                     $info = 'Samsung EXYNOS';
                     // The Exynos DRM driver
                     break;
                 case 'tegra_fb':
                     $info = 'NVIDIA TEGRA';
                     // The Exynos DRM driver
                     break;
                 default:
                     if (is_file('/dev/mali')) {
                         $info = 'ARM Mali';
                         // One of the ARM Mali models
                     }
                     break;
             }
         }
         if (substr($info, -1) == ')' && ($open_p = strrpos($info, '(')) != false) {
             $end_check = strpos($info, ' ', $open_p);
             $to_check = substr($info, $open_p + 1, $end_check - $open_p - 1);
             // Don't report card revision from PCI info
             if ($to_check == 'rev') {
                 $info = substr($info, 0, $open_p - 1);
             }
         }
     }
     if (($bracket_open = strpos($info, '[')) !== false) {
         // Report only the information inside the brackets if it's more relevant...
         // Mainly with Linux systems where the PCI information is reported like 'nVidia GF104 [GeForce GTX 460]'
         if (($bracket_close = strpos($info, ']', $bracket_open + 1)) !== false) {
             $inside_bracket = substr($info, $bracket_open + 1, $bracket_close - $bracket_open - 1);
             if (stripos($inside_bracket, 'Quadro') !== false || stripos($inside_bracket, 'GeForce') !== false) {
                 $info = $inside_bracket . ' ' . substr($info, $bracket_close + 1);
             } else {
                 if (stripos($inside_bracket, 'Radeon') !== false || stripos($inside_bracket, 'Fire') !== false || stripos($inside_bracket, 'Fusion') !== false) {
                     $info = $inside_bracket . ' ' . substr($info, $bracket_close + 1);
                 }
             }
         }
     }
     if (stripos($info, 'NVIDIA') === false && (stripos($info, 'Quadro') !== false || stripos($info, 'GeForce') !== false)) {
         $info = 'NVIDIA' . ' ' . $info;
     } else {
         if (stripos($info, 'ATI') === false && stripos($info, 'AMD') === false && (stripos($info, 'Radeon') !== false || stripos($info, 'Fire') !== false || stripos($info, 'Fusion') !== false)) {
             // Fire would be for FireGL or FirePro hardware
             $info = 'AMD ' . $info;
         }
     }
     if (phodevi::is_linux() && ($vendor = phodevi_linux_parser::read_pci_subsystem_value('VGA compatible controller')) != null && stripos($info, $vendor) === false && (stripos($info, 'AMD') !== false || stripos($info, 'NVIDIA') !== false)) {
         $info = $vendor . ' ' . $info;
     }
     if ($video_ram > 64 && strpos($info, $video_ram) == false) {
         $info .= ' ' . $video_ram . 'MB';
     }
     $clean_phrases = array('OpenGL Engine');
     $info = str_replace($clean_phrases, null, $info);
     return $info;
 }
 public function cache_isset_names($name)
 {
     // Cache the isset call names with their values when checking files/commands since Phodevi will likely hit each one potentially multiple times and little overhead to caching them
     static $isset_cache;
     if (!isset($isset_cache[$name])) {
         if (isset($this->options[$name]['type'])) {
             $isset_cache[$name] = $this->options[$name]['type'] == 'F' && is_readable($this->options[$name]['F']) || $this->options[$name]['type'] == 'C' && pts_client::executable_in_path(pts_strings::first_in_string($this->options[$name]['C']));
         } else {
             $isset_cache[$name] = false;
             foreach ($this->options[$name] as $try) {
                 $isset_cache[$name] = $try['type'] == 'F' && is_readable($try['F']) || $try['type'] == 'C' && pts_client::executable_in_path(pts_strings::first_in_string($try['C']));
                 if ($isset_cache[$name]) {
                     break;
                 }
             }
         }
     }
     return $isset_cache[$name];
 }
 public static function read_pci($desc, $clean_string = true)
 {
     // Read PCI bus information
     static $pci_info = null;
     $info = false;
     $desc = pts_arrays::to_array($desc);
     if ($pci_info == null) {
         if (!is_executable('/usr/bin/lspci') && is_executable('/sbin/lspci')) {
             $lspci_cmd = '/sbin/lspci';
         } else {
             if ($lspci = pts_client::executable_in_path('lspci')) {
                 $lspci_cmd = $lspci;
             } else {
                 return false;
             }
         }
         $pci_info = shell_exec($lspci_cmd . ' 2> /dev/null');
     }
     for ($i = 0; $i < count($desc) && empty($info); $i++) {
         if (substr($desc[$i], -1) != ':') {
             $desc[$i] .= ':';
         }
         if (($pos = strpos($pci_info, $desc[$i])) !== false) {
             $sub_pci_info = str_replace(array('[AMD]', '[AMD/ATI]'), null, substr($pci_info, $pos + strlen($desc[$i])));
             $EOL = strpos($sub_pci_info, "\n");
             if ($clean_string) {
                 if (($temp = strpos($sub_pci_info, '/')) < $EOL && $temp > 0) {
                     if (($temp = strpos($sub_pci_info, ' ', $temp + 2)) < $EOL && $temp > 0) {
                         $EOL = $temp;
                     }
                 }
                 if (($temp = strpos($sub_pci_info, '(')) < $EOL && $temp > 0) {
                     $EOL = $temp;
                 }
                 if (($temp = strpos($sub_pci_info, '[')) < $EOL && $temp > 0) {
                     $EOL = $temp;
                 }
             }
             $sub_pci_info = trim(substr($sub_pci_info, 0, $EOL));
             if (($strlen = strlen($sub_pci_info)) >= 6 && $strlen < 128) {
                 $info = pts_strings::strip_string($sub_pci_info);
             }
         }
     }
     return $info;
 }