public static function client_commands_array()
 {
     $options = array('Test Installation' => array(), 'Testing' => array(), 'Batch Testing' => array(), 'OpenBenchmarking.org' => array(), 'System' => array(), 'Information' => array(), 'Asset Creation' => array(), 'Result Management' => array(), 'Result Analytics' => array(), 'Other' => array());
     foreach (pts_file_io::glob(PTS_COMMAND_PATH . '*.php') as $option_php_file) {
         $option_php = basename($option_php_file, '.php');
         $name = str_replace('_', '-', $option_php);
         if (!in_array(pts_strings::first_in_string($name, '-'), array('dump', 'task'))) {
             include_once $option_php_file;
             $reflect = new ReflectionClass($option_php);
             $constants = $reflect->getConstants();
             $doc_description = isset($constants['doc_description']) ? constant($option_php . '::doc_description') : 'No summary is available.';
             $doc_section = isset($constants['doc_section']) ? constant($option_php . '::doc_section') : 'Other';
             $name = isset($constants['doc_use_alias']) ? constant($option_php . '::doc_use_alias') : $name;
             $skip = isset($constants['doc_skip']) ? constant($option_php . '::doc_skip') : false;
             $doc_args = array();
             if ($skip) {
                 continue;
             }
             if (method_exists($option_php, 'argument_checks')) {
                 $doc_args = call_user_func(array($option_php, 'argument_checks'));
             }
             if (!empty($doc_section) && !isset($options[$doc_section])) {
                 $options[$doc_section] = array();
             }
             array_push($options[$doc_section], array($name, $doc_args, $doc_description));
         }
     }
     return $options;
 }
 public static function run($r)
 {
     $options = array();
     foreach (pts_file_io::glob(PTS_COMMAND_PATH . '*.php') as $option_php) {
         $name = str_replace('_', '-', basename($option_php, '.php'));
         if (!in_array(pts_strings::first_in_string($name, '-'), array('dump', 'debug', 'task'))) {
             array_push($options, $name);
         }
     }
     $is_true = isset($r[0]) && $r[0] == 'TRUE';
     echo implode($is_true ? ' ' : PHP_EOL, $options) . ($is_true ? null : PHP_EOL);
 }
 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 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;
 }
 public function get_result_scale_formatted()
 {
     return trim(pts_strings::first_in_string($this->get_result_scale(), '|'));
 }
 public static function sw_display_driver($with_version = true)
 {
     if (phodevi::is_windows()) {
         return null;
     }
     $display_driver = phodevi::read_property('system', 'dri-display-driver');
     if (empty($display_driver)) {
         if (phodevi::is_ati_graphics() && phodevi::is_linux()) {
             $display_driver = 'fglrx';
         } else {
             if (phodevi::is_nvidia_graphics() || is_file('/proc/driver/nvidia/version')) {
                 $display_driver = 'nvidia';
             } else {
                 if ((phodevi::is_mesa_graphics() || phodevi::is_bsd()) && stripos(phodevi::read_property('gpu', 'model'), 'NVIDIA') !== false) {
                     if (is_file('/sys/class/drm/version')) {
                         // If there's DRM loaded and NVIDIA, it should be Nouveau
                         $display_driver = 'nouveau';
                     } else {
                         // The dead xf86-video-nv doesn't use any DRM
                         $display_driver = 'nv';
                     }
                 } else {
                     // Fallback to hopefully detect the module, takes the first word off the GPU string and sees if it is the module
                     // This works in at least the case of the Cirrus driver
                     $display_driver = strtolower(pts_strings::first_in_string(phodevi::read_property('gpu', 'model')));
                 }
             }
         }
     }
     if (!empty($display_driver)) {
         $driver_version = phodevi_parser::read_xorg_module_version($display_driver . '_drv');
         if ($driver_version == false || $driver_version == '1.0.0') {
             switch ($display_driver) {
                 case 'amd':
                     // See if it's radeon driver
                     $driver_version = phodevi_parser::read_xorg_module_version('radeon_drv');
                     if ($driver_version != false) {
                         $display_driver = 'radeon';
                     }
                     break;
                 case 'vmwgfx':
                     // See if it's VMware driver
                     $driver_version = phodevi_parser::read_xorg_module_version('vmware_drv');
                     if ($driver_version != false) {
                         $display_driver = 'vmware';
                     }
                     break;
                 case 'radeon':
                     // RadeonHD driver also reports DRI driver as 'radeon', so try reading that instead
                     $driver_version = phodevi_parser::read_xorg_module_version('radeonhd_drv');
                     if ($driver_version != false) {
                         $display_driver = 'radeonhd';
                     }
                     break;
                 case 'nvidia':
                 case 'NVIDIA':
                 case 'nouveau':
                     // NVIDIA's binary driver usually ends up reporting 1.0.0
                     if ($nvs_value = phodevi_parser::read_nvidia_extension('NvidiaDriverVersion')) {
                         $display_driver = 'NVIDIA';
                         $driver_version = $nvs_value;
                     } else {
                         // NVIDIA's binary driver appends their driver version on the end of the OpenGL version string
                         $glxinfo = phodevi_parser::software_glxinfo_version();
                         if (($pos = strpos($glxinfo, 'NVIDIA ')) != false) {
                             $display_driver = 'NVIDIA';
                             $driver_version = substr($glxinfo, $pos + 7);
                         }
                     }
                     break;
                 default:
                     if (is_readable('/sys/class/graphics/fb0/name')) {
                         // This path works for at least finding NVIDIA Tegra 2 DDX (via tegra_fb)
                         $display_driver = file_get_contents('/sys/class/graphics/fb0/name');
                         $display_driver = str_replace(array('drm', '_fb'), null, $display_driver);
                         $driver_version = phodevi_parser::read_xorg_module_version($display_driver . '_drv');
                     }
                     break;
             }
         }
         if ($driver_version == false) {
             // If the version is empty, chances are the DDX driver string is incorrect
             $display_driver = null;
             // See if the VESA or fbdev driver is in use
             foreach (array('modesetting', 'fbdev', 'vesa') as $drv) {
                 $drv_version = phodevi_parser::read_xorg_module_version($drv . '_drv');
                 if ($drv_version) {
                     $display_driver = $drv;
                     $driver_version = $drv_version;
                     break;
                 }
             }
         }
         if (!empty($driver_version) && $with_version && $driver_version != '0.0.0') {
             $display_driver .= ' ' . $driver_version;
             // XXX: The below check is disabled since the Catalyst Version no longer seems reliably reported (circa Catalyst 13.x)
             if (false && phodevi::is_ati_graphics() && strpos($display_driver, 'fglrx') !== false) {
                 $catalyst_version = phodevi_linux_parser::read_amd_pcsdb('AMDPCSROOT/SYSTEM/LDC,Catalyst_Version');
                 if ($catalyst_version != null && $catalyst_version > 10.1 && $catalyst_version != 10.5 && $catalyst_version != 11.8) {
                     // This option was introduced around Catalyst 10.5 but seems to not be updated properly until Catalyst 10.11/10.12
                     $display_driver .= ' Catalyst ' . $catalyst_version . '';
                 }
             }
         }
     }
     return $display_driver;
 }
 public static function locate_test_profile_lead_binary(&$test_profile)
 {
     $test_profile_launcher = $test_profile->get_test_executable_dir() . $test_profile->get_test_executable();
     if (!is_file($test_profile_launcher)) {
         echo PHP_EOL . $test_profile_launcher . ' not found.' . PHP_EOL;
         return false;
     }
     $original_launcher_contents = file_get_contents($test_profile_launcher);
     $test_binary = false;
     if ($s = strpos($original_launcher_contents, '$LOG_FILE')) {
         $launcher_contents = substr($original_launcher_contents, 0, $s);
         $test_binary = pts_strings::first_in_string(trim(str_replace(array('	', '   ', 'mpirun', 'mpiexec', './'), '', substr($launcher_contents, strrpos($launcher_contents, PHP_EOL) + 1))));
     }
     if (strpos($test_binary, '.app') && strpos($original_launcher_contents, '$LOG_FILE') != ($s = strrpos($original_launcher_contents, '$LOG_FILE'))) {
         $launcher_contents = substr($original_launcher_contents, 0, $s);
         $test_binary = pts_strings::first_in_string(trim(str_replace(array('	', '   ', 'mpirun', 'mpiexec', './'), '', substr($launcher_contents, strrpos($launcher_contents, PHP_EOL) + 1))));
     }
     if ($test_binary) {
         if (is_executable($test_profile->get_test_executable_dir() . '/' . $test_binary)) {
             $test_binary = $test_profile->get_test_executable_dir() . '/' . $test_binary;
         } else {
             if ($s = strpos($launcher_contents, PHP_EOL . 'cd ')) {
                 $cd = substr($launcher_contents, $s + 4);
                 $cd = substr($cd, 0, strpos($cd, PHP_EOL));
                 if (is_executable($test_profile->get_test_executable_dir() . '/' . $cd . '/' . $test_binary)) {
                     $test_binary = $test_profile->get_test_executable_dir() . '/' . $cd . '/' . $test_binary;
                 }
             }
         }
     }
     return $test_binary;
 }
Exemplo n.º 8
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);
 }