How to use current_command method of pts_client class

Best Phoronix-test-suite code snippet using pts_client.current_command

pts_client.php

Source:pts_client.php Github

copy

Full Screen

...18class pts_client19{20 public static $display = false;21 public static $pts_logger = false;22 private static $current_command = null;23 protected static $lock_pointers = null;24 private static $forked_pids = array();25 protected static $phoromatic_servers = array();26 protected static $debug_mode = false;27 protected static $full_output = false;28 public static function create_lock($lock_file)29 {30 if(isset(self::$lock_pointers[$lock_file]) || is_writable(dirname($lock_file)) == false || disk_free_space(dirname($lock_file)) < 1024)31 {32 return false;33 }34 self::$lock_pointers[$lock_file] = fopen($lock_file, 'w');35 chmod($lock_file, 0644);36 return self::$lock_pointers[$lock_file] != false && flock(self::$lock_pointers[$lock_file], LOCK_EX | LOCK_NB);37 }38 public static function is_locked($lock_file)39 {40 $fp = fopen($lock_file, 'w');41 $is_locked = $fp && !flock($fp, LOCK_EX | LOCK_NB);42 $fp && fclose($fp);43 return $is_locked;44 }45 public static function release_lock($lock_file)46 {47 // Remove lock48 if(isset(self::$lock_pointers[$lock_file]) == false)49 {50 pts_file_io::unlink($lock_file);51 return false;52 }53 if(is_resource(self::$lock_pointers[$lock_file]))54 {55 fclose(self::$lock_pointers[$lock_file]);56 }57 pts_file_io::unlink($lock_file);58 unset(self::$lock_pointers[$lock_file]);59 }60 public static function init()61 {62 pts_core::init();63 if(defined('QUICK_START') && QUICK_START)64 {65 return true;66 }67 if(function_exists('cli_set_process_title') && PHP_OS == 'Linux')68 {69 cli_set_process_title('Phoronix Test Suite');70 }71 pts_define('PHP_BIN', pts_client::read_env('PHP_BIN'));72 $dir_init = array(PTS_USER_PATH);73 foreach($dir_init as $dir)74 {75 pts_file_io::mkdir($dir);76 }77 if(PTS_IS_CLIENT)78 {79 pts_network::client_startup();80 }81 self::core_storage_init_process();82 if(!is_file(PTS_TEMP_STORAGE))83 {84 self::build_temp_cache();85 }86 pts_define('PTS_TEST_INSTALL_DEFAULT_PATH', pts_strings::parse_for_home_directory(pts_config::read_user_config('PhoronixTestSuite/Options/Installation/EnvironmentDirectory', '~/.phoronix-test-suite/installed-tests/')));87 pts_define('PTS_SAVE_RESULTS_PATH', pts_strings::parse_for_home_directory(pts_config::read_user_config('PhoronixTestSuite/Options/Testing/ResultsDirectory', '~/.phoronix-test-suite/test-results/')));88 self::extended_init_process();89 $openbenchmarking = pts_storage_object::read_from_file(PTS_CORE_STORAGE, 'openbenchmarking');90 $openbenchmarking_account_settings = pts_storage_object::read_from_file(PTS_CORE_STORAGE, 'openbenchmarking_account_settings');91 if($openbenchmarking != null)92 {93 // OpenBenchmarking.org Account94 pts_openbenchmarking_client::init_account($openbenchmarking, $openbenchmarking_account_settings);95 }96 return true;97 }98 private static function extended_init_process()99 {100 // Extended Initalization Process101 $directory_check = array(102 PTS_TEST_INSTALL_DEFAULT_PATH,103 PTS_SAVE_RESULTS_PATH,104 PTS_MODULE_LOCAL_PATH,105 PTS_MODULE_DATA_PATH,106 PTS_DOWNLOAD_CACHE_PATH,107 PTS_OPENBENCHMARKING_SCRATCH_PATH,108 PTS_TEST_PROFILE_PATH,109 PTS_TEST_SUITE_PATH,110 PTS_TEST_PROFILE_PATH . 'local/',111 PTS_TEST_SUITE_PATH . 'local/'112 );113 foreach($directory_check as $dir)114 {115 pts_file_io::mkdir($dir);116 }117 // Setup ~/.phoronix-test-suite/xsl/118 pts_file_io::mkdir(PTS_USER_PATH . 'xsl/');119 copy(PTS_CORE_STATIC_PATH . 'xsl/pts-test-installation-viewer.xsl', PTS_USER_PATH . 'xsl/' . 'pts-test-installation-viewer.xsl');120 copy(PTS_CORE_STATIC_PATH . 'xsl/pts-user-config-viewer.xsl', PTS_USER_PATH . 'xsl/' . 'pts-user-config-viewer.xsl');121 copy(PTS_CORE_STATIC_PATH . 'images/pts-308x160.png', PTS_USER_PATH . 'xsl/' . 'pts-logo.png');122 // pts_compatibility ops here123 pts_client::init_display_mode();124 }125 public static function module_framework_init()126 {127 // Process initially called when PTS starts up128 // Check for modules to auto-load from the configuration file129 $load_modules = pts_config::read_user_config('PhoronixTestSuite/Options/Modules/LoadModules', null);130 if(!empty($load_modules))131 {132 foreach(pts_strings::comma_explode($load_modules) as $module)133 {134 $module_r = pts_strings::trim_explode('=', $module);135 if(count($module_r) == 2)136 {137 // TODO: end up hooking this into pts_module::read_variable() rather than using the real env138 pts_client::set_environment_variable($module_r[0], $module_r[1]);139 }140 else141 {142 pts_module_manager::attach_module($module);143 }144 }145 }146 // Check for modules to load manually in PTS_MODULES147 if(($load_modules = pts_client::read_env('PTS_MODULES')) !== false)148 {149 foreach(pts_strings::comma_explode($load_modules) as $module)150 {151 if(!pts_module_manager::is_module_attached($module))152 {153 pts_module_manager::attach_module($module);154 }155 }156 }157 // Detect modules to load automatically158 pts_module_manager::detect_modules_to_load();159 // Clean-up modules list160 pts_module_manager::clean_module_list();161 // Reset counter162 pts_module_manager::set_current_module(null);163 // Load the modules164 $module_store_list = array();165 foreach(pts_module_manager::attached_modules() as $module)166 {167 $class_vars = get_class_vars($module);168 $module_store_vars = isset($class_vars['module_store_vars']) ? $class_vars['module_store_vars'] : null;169 if(is_array($module_store_vars))170 {171 foreach($module_store_vars as $store_var)172 {173 if(!in_array($store_var, $module_store_list))174 {175 $module_store_list[] = $store_var;176 }177 }178 }179 }180 // Should any of the module options be saved to the results?181 foreach($module_store_list as $var)182 {183 $var_value = pts_client::read_env($var);184 if(!empty($var_value))185 {186 pts_module_manager::var_store_add($var, $var_value);187 }188 }189 pts_module_manager::module_process('__startup');190 pts_define('PTS_STARTUP_TASK_PERFORMED', true);191 register_shutdown_function(array('pts_module_manager', 'module_process'), '__shutdown');192 }193 public static function environmental_variables()194 {195 // The PTS environmental variables passed during the testing process, etc196 static $env_variables = null;197 if($env_variables == null)198 {199 $env_variables = array(200 'PTS_VERSION' => PTS_VERSION,201 'PTS_CODENAME' => PTS_CODENAME,202 'PTS_DIR' => PTS_PATH,203 'PHP_BIN' => PHP_BIN,204 'NUM_CPU_CORES' => phodevi::read_property('cpu', 'core-count'),205 'NUM_CPU_NODES' => phodevi::read_property('cpu', 'node-count'),206 'NUM_CPU_JOBS' => (phodevi::read_property('cpu', 'core-count') * 2),207 'SYS_MEMORY' => phodevi::read_property('memory', 'capacity'),208 'VIDEO_MEMORY' => phodevi::read_property('gpu', 'memory-capacity'),209 'VIDEO_WIDTH' => pts_arrays::first_element(phodevi::read_property('gpu', 'screen-resolution')),210 'VIDEO_HEIGHT' => pts_arrays::last_element(phodevi::read_property('gpu', 'screen-resolution')),211 'VIDEO_MONITOR_COUNT' => phodevi::read_property('monitor', 'count'),212 'VIDEO_MONITOR_LAYOUT' => phodevi::read_property('monitor', 'layout'),213 'VIDEO_MONITOR_SIZES' => phodevi::read_property('monitor', 'modes'),214 'OPERATING_SYSTEM' => phodevi::read_property('system', 'vendor-identifier'),215 'OS_VERSION' => phodevi::read_property('system', 'os-version'),216 'OS_ARCH' => phodevi::read_property('system', 'kernel-architecture'),217 'OS_TYPE' => phodevi::operating_system(),218 'THIS_RUN_TIME' => PTS_INIT_TIME,219 'DEBUG_REAL_HOME' => pts_core::user_home_directory()220 );221 if(!pts_client::executable_in_path('cc') && pts_client::executable_in_path('gcc') && getenv('CC') == false)222 {223 // This helps some test profiles build correctly if they don't do a cc check internally224 $env_variables['CC'] = 'gcc';225 }226 }227 return $env_variables;228 }229 public static function test_install_root_path()230 {231 if(getenv('PTS_TEST_INSTALL_ROOT_PATH') != false && is_dir(getenv('PTS_TEST_INSTALL_ROOT_PATH')) && is_writable(getenv('PTS_TEST_INSTALL_ROOT_PATH')))232 {233 return getenv('PTS_TEST_INSTALL_ROOT_PATH');234 }235 else236 {237 if(!defined('PTS_TEST_INSTALL_DEFAULT_PATH'))238 pts_define('PTS_TEST_INSTALL_DEFAULT_PATH', pts_strings::parse_for_home_directory(pts_config::read_user_config('PhoronixTestSuite/Options/Installation/EnvironmentDirectory', '~/.phoronix-test-suite/installed-tests/')));239 return PTS_TEST_INSTALL_DEFAULT_PATH;240 }241 }242 public static function user_run_save_variables()243 {244 static $runtime_variables = null;245 if($runtime_variables == null)246 {247 $runtime_variables = array(248 'VIDEO_RESOLUTION' => phodevi::read_property('gpu', 'screen-resolution-string'),249 'VIDEO_CARD' => phodevi::read_name('gpu'),250 'VIDEO_DRIVER' => phodevi::read_property('system', 'display-driver-string'),251 'OPENGL_DRIVER' => str_replace('(', '', phodevi::read_property('system', 'opengl-driver')),252 'OPERATING_SYSTEM' => phodevi::read_property('system', 'operating-system'),253 'PROCESSOR' => phodevi::read_name('cpu'),254 'MOTHERBOARD' => phodevi::read_name('motherboard'),255 'CHIPSET' => phodevi::read_name('chipset'),256 'KERNEL_VERSION' => phodevi::read_property('system', 'kernel'),257 'COMPILER' => phodevi::read_property('system', 'compiler'),258 'HOSTNAME' => phodevi::read_property('system', 'hostname')259 );260 }261 return $runtime_variables;262 }263 public static function supports_colored_text_output()264 {265 return (function_exists('posix_isatty') && posix_isatty(STDOUT)) || (PTS_IS_CLIENT && getenv('LS_COLORS'));266 }267 public static function cli_colored_text($str, $color, $bold = false)268 {269 if(!self::supports_colored_text_output() || empty($color))270 {271 return $str;272 }273 $attribute = ($bold ? '1' : '0');274 $colors = array(275 'black' => $attribute . ';30',276 'gray' => '1;30', // gray not bold doesn't look good in all consoles277 'blue' => $attribute . ';34',278 'green' => $attribute . ';32',279 'red' => $attribute . ';31',280 'cyan' => $attribute . ';36',281 );282 if(!isset($colors[$color]))283 {284 return $str;285 }286 return "\033[" . $colors[$color] . 'm' . $str . "\033[0m";287 }288 public static function cli_just_bold($str)289 {290 if(!self::supports_colored_text_output())291 {292 return $str;293 }294 return "\033[1m$str\033[0m";295 }296 public static function save_test_result($save_to = null, $save_results = null, $render_graphs = true, $result_identifier = null)297 {298 // Saves PTS result file299 if(substr($save_to, -4) != '.xml')300 {301 $save_to .= '.xml';302 }303 $save_to = str_replace(PTS_SAVE_RESULTS_PATH, null, $save_to);304 $save_to_dir = pts_client::setup_test_result_directory($save_to);305 if($save_to == null || $save_results == null)306 {307 $bool = false;308 }309 else310 {311 $save_name = basename($save_to, '.xml');312 if($save_name == 'composite' && $render_graphs)313 {314 pts_client::generate_result_file_graphs($save_results, $save_to_dir);315 }316 $bool = file_put_contents(PTS_SAVE_RESULTS_PATH . $save_to, $save_results);317 if($result_identifier != null && pts_config::read_bool_config('PhoronixTestSuite/Options/Testing/SaveSystemLogs', 'TRUE'))318 {319 // Save verbose system information here320 $system_log_dir = $save_to_dir . '/system-logs/' . $result_identifier . '/';321 pts_file_io::mkdir($system_log_dir, 0777, true);322 // Backup system files323 // TODO: move out these files/commands to log out to respective Phodevi components so only what's relevant will be logged324 $system_log_files = array(325 '/var/log/Xorg.0.log',326 '/proc/cpuinfo',327 '/proc/meminfo',328 '/proc/modules',329 '/proc/mounts',330 '/proc/cmdline',331 '/proc/version',332 '/proc/mdstat',333 '/etc/X11/xorg.conf',334 '/sys/kernel/debug/dri/0/radeon_pm_info',335 '/sys/kernel/debug/dri/0/i915_capabilities',336 '/sys/kernel/debug/dri/0/i915_cur_delayinfo',337 '/sys/kernel/debug/dri/0/i915_drpc_info',338 '/sys/devices/system/cpu/cpu0/cpufreq/scaling_available_frequencies',339 );340 /*341 if(phodevi::is_linux())342 {343 // the kernel config file might just be too large to upload for now344 $system_log_files[] = '/boot/config-' . php_uname('r');345 }346 */347 foreach($system_log_files as $file)348 {349 if(is_file($file) && is_readable($file) && filesize($file) < 1000000)350 {351 // copy() can't be used in this case since it will result in a blank file for /proc/ file-system352 $file_contents = file_get_contents($file);353 $file_contents = pts_strings::remove_line_timestamps($file_contents);354 file_put_contents($system_log_dir . basename($file), $file_contents);355 }356 }357 // Generate logs from system commands to backup358 $system_log_commands = array(359 'lspci -mmkvvvnn',360 'lscpu',361 'cc -v',362 // 'lsusb',363 'lsmod',364 'sensors',365 'dmesg',366 'vdpauinfo',367 'cpufreq-info',368 'glxinfo',369 'clinfo',370 'vulkaninfo',371 'uname -a',372 // 'udisks --dump',373 'upower --dump',374 );375 if(phodevi::is_bsd())376 {377 $system_log_commands[] = 'sysctl -a';378 $system_log_commands[] = 'kenv';379 }380 if(is_readable('/dev/mem'))381 {382 $system_log_commands[] = 'dmidecode';383 }384 foreach($system_log_commands as $command_string)385 {386 $command = explode(' ', $command_string);387 if(($command_bin = pts_client::executable_in_path($command[0])))388 {389 $cmd_output = shell_exec('cd ' . dirname($command_bin) . ' && ./' . $command_string . ' 2>&1');390 if(strlen($cmd_output) > 900000)391 {392 // Don't preserve really large logs, likely filled with lots of junk393 $cmd_output = null;394 continue;395 }396 // Try to filter out any serial numbers, etc.397 phodevi_vfs::cleanse_file($cmd_output, $command[0]);398 $cmd_output = pts_strings::remove_line_timestamps($cmd_output);399 file_put_contents($system_log_dir . $command[0], $cmd_output);400 }401 }402 // Dump some common / important environmental variables403 $environment_variables = array(404 'PATH' => null,405 'CFLAGS' => null,406 'CXXFLAGS' => null,407 'LD_LIBRARY_PATH' => null,408 'CC' => null,409 'CXX' => null,410 'LIBGL_DRIVERS_PATH' => null411 );412 foreach($environment_variables as $variable => &$value)413 {414 $v = getenv($variable);415 if($v != null)416 {417 $value = $v;418 }419 else420 {421 unset($environment_variables[$variable]);422 }423 }424 if(!empty($environment_variables))425 {426 $variable_dump = null;427 foreach($environment_variables as $variable => $value)428 {429 $variable_dump .= $variable . '=' . $value . PHP_EOL;430 }431 file_put_contents($system_log_dir . 'environment-variables', $variable_dump);432 }433 pts_module_manager::module_process('__post_test_run_system_logs', $system_log_dir);434 }435 }436 return $bool;437 }438 public static function init_display_mode($override_display_mode = false)439 {440 if(PTS_IS_WEB_CLIENT && !defined('PHOROMATIC_SERVER'))441 {442 self::$display = new pts_web_display_mode();443 return;444 }445 $env_mode = pts_client::is_debug_mode() ? 'BASIC' : $override_display_mode;446 switch(($env_mode != false || ($env_mode = pts_client::read_env('PTS_DISPLAY_MODE')) != false ? $env_mode : pts_config::read_user_config('PhoronixTestSuite/Options/General/DefaultDisplayMode', 'DEFAULT')))447 {448 case 'BASIC':449 self::$display = new pts_basic_display_mode();450 break;451 case 'BATCH':452 case 'CONCISE':453 self::$display = new pts_concise_display_mode();454 break;455 case 'SHORT':456 self::$display = new pts_short_display_mode();457 break;458 case 'DEFAULT':459 default:460 self::$display = new pts_concise_display_mode();461 break;462 }463 }464 public static function program_requirement_checks($only_show_required = false, $always_report = false)465 {466 $extension_checks = pts_needed_extensions();467 $printed_required_header = false;468 $printed_optional_header = false;469 foreach($extension_checks as $extension)470 {471 if($extension[1] == false || $always_report)472 {473 if($always_report)474 {475 $printed_required_header = true;476 $printed_optional_header = true;477 echo ($extension[1] == false ? 'MISSING' : 'PRESENT') . ' - ';478 }479 if($extension[0] == 1)480 {481 // Oops, this extension is required482 if($printed_required_header == false)483 {484 echo PHP_EOL . 'The following PHP extensions are REQUIRED:' . PHP_EOL . PHP_EOL;485 $printed_required_header = true;486 }487 }488 else489 {490 if(($only_show_required || PTS_IS_DAEMONIZED_SERVER_PROCESS) && $printed_required_header == false)491 {492 continue;493 }494 // This extension is missing but optional495 if($printed_optional_header == false)496 {497 echo PHP_EOL . ($printed_required_header ? null : 'NOTICE: ') . 'The following PHP extensions are OPTIONAL but recommended:' . PHP_EOL . PHP_EOL;498 $printed_optional_header = true;499 }500 }501 echo sprintf('%-9ls %-30ls' . PHP_EOL, $extension[2], $extension[3]);502 }503 }504 if($printed_required_header || $printed_optional_header)505 {506 echo PHP_EOL;507 if($printed_required_header && !$always_report)508 {509 exit;510 }511 }512 }513 private static function build_temp_cache()514 {515 $pso = pts_storage_object::recover_from_file(PTS_TEMP_STORAGE);516 if($pso == false)517 {518 $pso = new pts_storage_object();519 }520 $pso->add_object('environmental_variables_for_modules', pts_module_manager::modules_environmental_variables());521 $pso->add_object('command_alias_list', pts_documentation::client_commands_aliases());522 $pso->save_to_file(PTS_TEMP_STORAGE);523 }524 private static function core_storage_init_process()525 {526 $pso = pts_storage_object::recover_from_file(PTS_CORE_STORAGE);527 if($pso == false)528 {529 $pso = new pts_storage_object(true, true);530 }531 // OpenBenchmarking.org - GSID532 $global_gsid = $pso->read_object('global_system_id');533 $global_gsid_e = $pso->read_object('global_system_id_e');534 $global_gsid_p = $pso->read_object('global_system_id_p');535 if(empty($global_gsid) || pts_openbenchmarking::is_valid_gsid_format($global_gsid) == false)536 {537 // Global System ID for anonymous uploads, etc538 $requested_gsid = true;539 $global_gsid = pts_openbenchmarking_client::request_gsid();540 if(is_array($global_gsid))541 {542 $pso->add_object('global_system_id', $global_gsid['gsid']); // GSID543 $pso->add_object('global_system_id_p', $global_gsid['gsid_p']); // GSID_P544 $pso->add_object('global_system_id_e', $global_gsid['gsid_e']); // GSID_E545 pts_define('PTS_GSID', $global_gsid['gsid']);546 pts_define('PTS_GSID_E', $global_gsid['gsid_e']);547 }548 }549 else if(pts_openbenchmarking::is_valid_gsid_e_format($global_gsid_e) == false || pts_openbenchmarking::is_valid_gsid_p_format($global_gsid_p) == false)550 {551 pts_define('PTS_GSID', $global_gsid);552 $requested_gsid = false;553 $global_gsid = pts_openbenchmarking_client::retrieve_gsid();554 if(is_array($global_gsid))555 {556 $pso->add_object('global_system_id_p', $global_gsid['gsid_p']); // GSID_P557 $pso->add_object('global_system_id_e', $global_gsid['gsid_e']); // GSID_E558 pts_define('PTS_GSID_E', $global_gsid['gsid_e']);559 }560 }561 else562 {563 pts_define('PTS_GSID', $global_gsid);564 pts_define('PTS_GSID_E', $global_gsid_e);565 $requested_gsid = false;566 }567 $machine_self_id = $pso->read_object('machine_self_id');568 if(empty($machine_self_id))569 {570 $ns = md5('phoronix-test-suite');571 $binary_ns = null;572 for($i = 0; $i < strlen($ns); $i += 2)573 {574 $binary_ns .= chr(hexdec($ns[$i] . $ns[$i + 1]));575 }576 $msi_hash = sha1($binary_ns . uniqid(PTS_CORE_VERSION, true) . getenv('USERNAME') . getenv('USER') . getenv('HOSTNAME') . pts_network::get_local_ip());577 $machine_self_id = sprintf('%08s-%04s-%04x-%04x-%12s', substr($msi_hash, 0, 8), substr($msi_hash, 8, 4), (hexdec(substr($msi_hash, 12, 4)) & 0x0fff) | 0x5000, (hexdec(substr($msi_hash, 16, 4)) & 0x3fff) | 0x8000, substr($msi_hash, 20, 12));578 // machine_self_id is self-generated unique name for Phoromatic/OB purposes in UUIDv5 format579 $pso->add_object('machine_self_id', $machine_self_id);580 }581 pts_define('PTS_MACHINE_SELF_ID', $machine_self_id);582 // Last Run Processing583 $last_core_version = $pso->read_object('last_core_version');584 pts_define('FIRST_RUN_ON_PTS_UPGRADE', ($last_core_version != PTS_CORE_VERSION));585 if(FIRST_RUN_ON_PTS_UPGRADE || ($pso->read_object('last_php_version') != PTS_PHP_VERSION))586 {587 // Report any missing/recommended extensions588 self::program_requirement_checks();589 }590 if(FIRST_RUN_ON_PTS_UPGRADE)591 {592 if($requested_gsid == false)593 {594 pts_openbenchmarking_client::update_gsid();595 }596 pts_client::build_temp_cache();597 }598 $pso->add_object('last_core_version', PTS_CORE_VERSION); // PTS version last run599 $pso->add_object('last_php_version', PTS_PHP_VERSION); // PHP version last run600 //$last_pts_version = $pso->read_object('last_pts_version');601 // do something here with $last_pts_version if you want that information602 $pso->add_object('last_pts_version', PTS_VERSION); // PTS version last run603 // Last Run Processing604 $last_run = $pso->read_object('last_run_time');605 pts_define('IS_FIRST_RUN_TODAY', (substr($last_run, 0, 10) != date('Y-m-d')));606 $pso->add_object('last_run_time', date('Y-m-d H:i:s')); // Time PTS was last run607 pts_define('TIME_SINCE_LAST_RUN', ceil((time() - strtotime($last_run)) / 60)); // TIME_SINCE_LAST_RUN is in minutes608 // User Agreement Checking609 $agreement_cs = $pso->read_object('user_agreement_cs');610 $pso->add_object('user_agreement_cs', $agreement_cs); // User agreement check-sum611 // Phodevi Cache Handling612 $phodevi_cache = $pso->read_object('phodevi_smart_cache');613 if($phodevi_cache instanceof phodevi_cache && pts_client::read_env('NO_PHODEVI_CACHE') == false)614 {615 $phodevi_cache = $phodevi_cache->restore_cache(PTS_USER_PATH, PTS_CORE_VERSION);616 phodevi::set_device_cache($phodevi_cache);617 if(($external_phodevi_cache = pts_client::read_env('EXTERNAL_PHODEVI_CACHE')))618 {619 if(is_dir($external_phodevi_cache) && is_file($external_phodevi_cache . '/core.pt2so'))620 {621 $external_phodevi_cache .= '/core.pt2so';622 }623 if(is_file($external_phodevi_cache))624 {625 $external_phodevi_cache = pts_storage_object::force_recover_from_file($external_phodevi_cache);626 if($external_phodevi_cache != false)627 {628 $external_phodevi_cache = $external_phodevi_cache->read_object('phodevi_smart_cache');629 $external_phodevi_cache = $external_phodevi_cache->restore_cache(null, PTS_CORE_VERSION);630 if($external_phodevi_cache != false)631 {632 //unset($external_phodevi_cache['system']['operating-system']);633 //unset($external_phodevi_cache['system']['vendor-identifier']);634 phodevi::set_device_cache($external_phodevi_cache);635 }636 }637 }638 }639 }640 // Archive to disk641 $pso->save_to_file(PTS_CORE_STORAGE);642 }643 public static function register_phoromatic_server($server_ip, $http_port)644 {645 self::$phoromatic_servers[] = array('ip' => $server_ip, 'http_port' => $http_port);646 }647 public static function available_phoromatic_servers()648 {649 $phoromatic_servers = array();650 $possible_servers = pts_network::find_zeroconf_phoromatic_servers(true);651 foreach(self::$phoromatic_servers as $server)652 {653 $possible_servers[] = array($server['ip'], $server['http_port']);654 }655 $user_config_phoromatic_servers = pts_config::read_user_config('PhoronixTestSuite/Options/General/PhoromaticServers', '');656 foreach(explode(',', $user_config_phoromatic_servers) as $static_server)657 {658 $static_server = explode(':', $static_server);659 if(count($static_server) == 2)660 {661 $possible_servers[] = array($static_server[0], $static_server[1]);662 }663 }664 if(is_file(PTS_USER_PATH . 'phoromatic-servers'))665 {666 $phoromatic_servers_file = pts_file_io::file_get_contents(PTS_USER_PATH . 'phoromatic-servers');667 foreach(explode(PHP_EOL, $phoromatic_servers_file) as $ps_file_line)668 {669 $ps_file_line = explode(':', trim($ps_file_line));670 if(count($ps_file_line) == 2 && ip2long($ps_file_line[0]) !== false && is_numeric($ps_file_line) && $ps_file_line > 100)671 {672 $possible_servers[] = array($ps_file_line[0], $ps_file_line[1]);673 }674 }675 }676 foreach($possible_servers as $possible_server)677 {678 // possible_server[0] is the Phoromatic Server IP679 // possible_server[1] is the Phoromatic Server HTTP PORT680 if(in_array($possible_server[0], array_keys($phoromatic_servers)))681 {682 continue;683 }684 $server_response = pts_network::http_get_contents('http://' . $possible_server[0] . ':' . $possible_server[1] . '/server.php', false, false, 3);685 if(stripos($server_response, 'Phoromatic') !== false)686 {687 trigger_error('Phoromatic Server Auto-Detected At: ' . $possible_server[0] . ':' . $possible_server[1], E_USER_NOTICE);688 $phoromatic_servers[$possible_server[0]] = array('ip' => $possible_server[0], 'http_port' => $possible_server[1]);689 }690 }691 return $phoromatic_servers;692 }693 public static function user_agreement_check($command)694 {695 $pso = pts_storage_object::recover_from_file(PTS_CORE_STORAGE);696 if($pso == false)697 {698 return false;699 }700 $config_md5 = $pso->read_object('user_agreement_cs');701 $current_md5 = md5_file(PTS_PATH . 'pts-core/user-agreement.txt');702 if(($config_md5 != $current_md5 || pts_config::read_user_config('PhoronixTestSuite/Options/OpenBenchmarking/AnonymousUsageReporting', 'UNKNOWN') == 'UNKNOWN') && !PTS_IS_DAEMONIZED_SERVER_PROCESS && getenv('PTS_SILENT_MODE') != 1 && $config_md5 != 'enterprise-agree')703 {704 $prompt_in_method = pts_client::check_command_for_function($command, 'pts_user_agreement_prompt');705 $user_agreement = file_get_contents(PTS_PATH . 'pts-core/user-agreement.txt');706 if($prompt_in_method)707 {708 $user_agreement_return = call_user_func(array($command, 'pts_user_agreement_prompt'), $user_agreement);709 if(is_array($user_agreement_return))710 {711 if(count($user_agreement_return) == 3)712 {713 list($agree, $usage_reporting) = $user_agreement_return;714 }715 else716 {717 $agree = array_shift($user_agreement_return);718 $usage_reporting = -1;719 }720 }721 else722 {723 $agree = $user_agreement_return;724 $usage_reporting = -1;725 }726 }727 if($prompt_in_method == false || $usage_reporting == -1)728 {729 pts_client::$display->generic_heading('User Agreement');730 echo wordwrap($user_agreement, 65);731 $agree = pts_user_io::prompt_bool_input('Do you agree to these terms and wish to proceed', true);732 $usage_reporting = $agree ? pts_user_io::prompt_bool_input('Enable anonymous usage / statistics reporting', true) : -1;733 }734 if($agree)735 {736 echo PHP_EOL;737 $pso->add_object('user_agreement_cs', $current_md5);738 $pso->save_to_file(PTS_CORE_STORAGE);739 }740 else741 {742 pts_client::exit_client('In order to run the Phoronix Test Suite, you must agree to the listed terms.');743 }744 pts_config::user_config_generate(array(745 'PhoronixTestSuite/Options/OpenBenchmarking/AnonymousUsageReporting' => pts_config::bool_to_string($usage_reporting)));746 }747 }748 public static function swap_variables($user_str, $replace_call)749 {750 if(is_array($replace_call))751 {752 if(count($replace_call) != 2 || method_exists($replace_call[0], $replace_call[1]) == false)753 {754 echo PHP_EOL . 'Var Swap With Method Failed.' . PHP_EOL;755 return $user_str;756 }757 }758 else if(!function_exists($replace_call))759 {760 echo PHP_EOL . 'Var Swap With Function Failed.' . PHP_EOL;761 return $user_str;762 }763 $offset = 0;764 $replace_call_return = false;765 while($offset < strlen($user_str) && ($s = strpos($user_str, '$', $offset)) !== false)766 {767 $s++;768 $var_name = substr($user_str, $s, (($e = strpos($user_str, ' ', $s)) == false ? strlen($user_str) : $e) - $s);769 if($replace_call_return === false)770 {771 $replace_call_return = call_user_func($replace_call);772 }773 $var_replacement = isset($replace_call_return[$var_name]) ? $replace_call_return[$var_name] : null;774 if($var_replacement != null)775 {776 $user_str = str_replace('$' . $var_name, $var_replacement, $user_str);777 }778 else779 {780 // echo "\nVariable Swap For $var_name Failed.\n";781 }782 $offset = $s + strlen($var_replacement);783 }784 return $user_str;785 }786 public static function setup_test_result_directory($save_to)787 {788 $save_to_dir = PTS_SAVE_RESULTS_PATH . $save_to;789 if(strpos(basename($save_to_dir), '.'))790 {791 $save_to_dir = dirname($save_to_dir);792 }793 if($save_to_dir != '.')794 {795 pts_file_io::mkdir($save_to_dir);796 }797 copy(PTS_CORE_STATIC_PATH . 'result-viewer.html', $save_to_dir . '/index.html');798 return $save_to_dir;799 }800 public static function remove_installed_test(&$test_profile)801 {802 pts_file_io::delete($test_profile->get_install_dir(), null, true);803 }804 public static function exit_client($string = null, $exit_status = 0)805 {806 // Exit the Phoronix Test Suite client807 pts_define('PTS_EXIT', 1);808 if($string != null)809 {810 echo PHP_EOL . $string . PHP_EOL;811 }812 exit($exit_status);813 }814 public static function current_user()815 {816 // Current system user817 return ($pts_user = pts_openbenchmarking_client::user_name()) != null ? $pts_user : phodevi::read_property('system', 'username');818 }819 public static function test_profile_debug_message($message)820 {821 $reported = false;822 if(pts_client::is_debug_mode())823 {824 pts_client::$display->test_run_instance_error($message);825 $reported = true;826 }827 return $reported;828 }829 public static function generate_result_file_graphs($test_results_identifier, $save_to_dir = false, $extra_attributes = null)830 {831 if($save_to_dir)832 {833 if(pts_file_io::mkdir($save_to_dir . '/result-graphs') == false)834 {835 // Don't delete old files now, in case any modules (e.g. FlameGrapher) output something in there ahead of time836 /*// Directory must exist, so remove any old graph files first837 foreach(pts_file_io::glob($save_to_dir . '/result-graphs/*') as $old_file)838 {839 unlink($old_file);840 }*/841 }842 }843 if($test_results_identifier instanceof pts_result_file)844 {845 $result_file = &$test_results_identifier;846 }847 else848 {849 $result_file = new pts_result_file($test_results_identifier);850 }851 $generated_graphs = array();852 $generated_graph_tables = false;853 // Render overview chart854 if($save_to_dir)855 {856 $chart = new pts_ResultFileTable($result_file);857 $chart->renderChart($save_to_dir . '/result-graphs/overview.BILDE_EXTENSION');858 $intent = -1;859 if(($intent = pts_result_file_analyzer::analyze_result_file_intent($result_file, $intent, true)) || $result_file->get_system_count() == 1)860 {861 $chart = new pts_ResultFileCompactSystemsTable($result_file, $intent);862 }863 else864 {865 $chart = new pts_ResultFileSystemsTable($result_file);866 }867 $chart->renderChart($save_to_dir . '/result-graphs/systems.BILDE_EXTENSION');868 unset($chart);869 if($intent && is_dir($save_to_dir . '/system-logs/'))870 {871 $chart = new pts_DetailedSystemComponentTable($result_file, $save_to_dir . '/system-logs/', $intent);872 if($chart)873 {874 $chart->renderChart($save_to_dir . '/result-graphs/detailed_component.BILDE_EXTENSION');875 }876 }877 }878 $result_objects = $result_file->get_result_objects();879 $test_titles = array();880 foreach($result_objects as &$result_object)881 {882 $test_titles[] = $result_object->test_profile->get_title();883 }884 $offset = 0;885 foreach($result_objects as $key => &$result_object)886 {887 $save_to = $save_to_dir;888 $offset++;889 if($save_to_dir && is_dir($save_to_dir))890 {891 $save_to .= '/result-graphs/' . $offset . '.BILDE_EXTENSION';892 if(PTS_IS_CLIENT)893 {894 if($result_file->is_multi_way_comparison(null, $extra_attributes) || pts_client::read_env('GRAPH_GROUP_SIMILAR'))895 {896 $table_keys = array();897 foreach($test_titles as $this_title_index => $this_title)898 {899 if(isset($test_titles[$key]) && $this_title == $test_titles[$key])900 {901 $table_keys[] = $this_title_index;902 }903 }904 }905 else906 {907 $table_keys = $key;908 }909 $chart = new pts_ResultFileTable($result_file, null, $table_keys);910 $chart->renderChart($save_to_dir . '/result-graphs/' . $offset . '_table.BILDE_EXTENSION');911 unset($chart);912 $generated_graph_tables = true;913 }914 }915 $graph = pts_render::render_graph($result_object, $result_file, $save_to, $extra_attributes);916 if($graph == false)917 {918 continue;919 }920 $generated_graphs[] = $graph;921 }922 // Generate mini / overview graphs923 if($save_to_dir)924 {925 $graph = new pts_OverviewGraph($result_file);926 if($graph->doSkipGraph() == false)927 {928 $graph->renderGraph();929 // Check to see if skip_graph was realized during the rendering process930 if($graph->doSkipGraph() == false)931 {932 $graph->svg_dom->output($save_to_dir . '/result-graphs/visualize.BILDE_EXTENSION');933 }934 }935 unset($graph);936 $graph = new pts_RadarOverviewGraph($result_file);937 if($graph->doSkipGraph() == false)938 {939 $graph->renderGraph();940 // Check to see if skip_graph was realized during the rendering process941 if($graph->doSkipGraph() == false)942 {943 $graph->svg_dom->output($save_to_dir . '/result-graphs/radar.BILDE_EXTENSION');944 }945 }946 unset($graph);947 }948 // Save the result viewer949 if(count($generated_graphs) > 0 && $save_to_dir)950 {951 copy(PTS_CORE_STATIC_PATH . 'result-viewer.html', $save_to_dir . '/index.html');952 }953 return $generated_graphs;954 }955 public static function process_shutdown_tasks()956 {957 // TODO: possibly do something like posix_getpid() != pts_client::$startup_pid in case shutdown function is called from a child process958 // Generate Phodevi Smart Cache959 if(pts_client::read_env('NO_PHODEVI_CACHE') == false && pts_client::read_env('EXTERNAL_PHODEVI_CACHE') == false)960 {961 if(pts_config::read_bool_config('PhoronixTestSuite/Options/General/UsePhodeviCache', 'TRUE'))962 {963 pts_storage_object::set_in_file(PTS_CORE_STORAGE, 'phodevi_smart_cache', phodevi::get_phodevi_cache_object(PTS_USER_PATH, PTS_CORE_VERSION));964 }965 else966 {967 pts_storage_object::set_in_file(PTS_CORE_STORAGE, 'phodevi_smart_cache', null);968 }969 }970 if(is_array(self::$lock_pointers))971 {972 foreach(array_keys(self::$lock_pointers) as $lock_file)973 {974 self::release_lock($lock_file);975 }976 }977 foreach(self::$forked_pids as $pid)978 {979 if(is_dir('/proc/' . $pid) && function_exists('posix_kill'))980 {981 posix_kill($pid, SIGKILL);982 }983 }984 }985 public static function do_anonymous_usage_reporting()986 {987 return pts_config::read_bool_config('PhoronixTestSuite/Options/OpenBenchmarking/AnonymousUsageReporting', 0);988 }989 public static function check_command_for_function($option, $check_function)990 {991 $in_option = false;992 if(is_file(PTS_COMMAND_PATH . $option . '.php'))993 {994 if(!class_exists($option, false) && is_file(PTS_COMMAND_PATH . $option . '.php'))995 {996 include(PTS_COMMAND_PATH . $option . '.php');997 }998 if(method_exists($option, $check_function))999 {1000 $in_option = true;1001 }1002 }1003 return $in_option;1004 }1005 public static function regenerate_graphs($result_file_identifier, $full_process_string = false, $extra_graph_attributes = null)1006 {1007 $save_to_dir = pts_client::setup_test_result_directory($result_file_identifier);1008 $generated_graphs = pts_client::generate_result_file_graphs($result_file_identifier, $save_to_dir, $extra_graph_attributes);1009 $generated = count($generated_graphs) > 0;1010 if($generated && $full_process_string)1011 {1012 echo PHP_EOL . $full_process_string . PHP_EOL;1013 pts_client::display_web_page(PTS_SAVE_RESULTS_PATH . $result_file_identifier . '/index.html');1014 }1015 return $generated;1016 }1017 public static function execute_command($command, $pass_args = null)1018 {1019 if(!class_exists($command, false) && is_file(PTS_COMMAND_PATH . $command . '.php'))1020 {1021 include(PTS_COMMAND_PATH . $command . '.php');1022 }1023 if(is_file(PTS_COMMAND_PATH . $command . '.php') && method_exists($command, 'argument_checks'))1024 {1025 $argument_checks = call_user_func(array($command, 'argument_checks'));1026 foreach($argument_checks as &$argument_check)1027 {1028 $function_check = $argument_check->get_function_check();1029 $method_check = false;1030 if(is_array($function_check) && count($function_check) == 2)1031 {1032 $method_check = $function_check[0];1033 $function_check = $function_check[1];1034 }1035 if(substr($function_check, 0, 1) == '!')1036 {1037 $function_check = substr($function_check, 1);1038 $return_fails_on = true;1039 }1040 else1041 {1042 $return_fails_on = false;1043 }1044 1045 if($method_check != false)1046 {1047 if(!method_exists($method_check, $function_check))1048 {1049 echo PHP_EOL . 'Method check fails.' . PHP_EOL;1050 continue;1051 }1052 $function_check = array($method_check, $function_check);1053 }1054 else if(!function_exists($function_check))1055 {1056 continue;1057 }1058 if($argument_check->get_argument_index() == 'VARIABLE_LENGTH')1059 {1060 $return_value = null;1061 foreach($pass_args as $arg)1062 {1063 $return_value = call_user_func_array($function_check, array($arg));1064 if($return_value == true)1065 {1066 break;1067 }1068 }1069 }1070 else1071 {1072 $return_value = call_user_func_array($function_check, array((isset($pass_args[$argument_check->get_argument_index()]) ? $pass_args[$argument_check->get_argument_index()] : null)));1073 }1074 if($return_value == $return_fails_on)1075 {1076 $command_alias = defined($command . '::doc_use_alias') ? constant($command . '::doc_use_alias') : $command;1077 if((isset($pass_args[$argument_check->get_argument_index()]) && !empty($pass_args[$argument_check->get_argument_index()])) || ($argument_check->get_argument_index() == 'VARIABLE_LENGTH' && !empty($pass_args)))1078 {1079 trigger_error('Invalid Argument: ' . implode(' ', $pass_args), E_USER_ERROR);1080 }1081 else1082 {1083 trigger_error('Phoronix Test Suite Argument Missing.', E_USER_ERROR);1084 }1085 echo PHP_EOL . pts_client::cli_just_bold('CORRECT SYNTAX:') . PHP_EOL . 'phoronix-test-suite ' . str_replace('_', '-', $command_alias) . ' ' . implode(' ', $argument_checks) . PHP_EOL . PHP_EOL;1086 if(method_exists($command, 'invalid_command'))1087 {1088 call_user_func_array(array($command, 'invalid_command'), $pass_args);1089 echo PHP_EOL;1090 }1091 return false;1092 }1093 else1094 {1095 if($argument_check->get_function_return_key() != null && !isset($pass_args[$argument_check->get_function_return_key()]))1096 {1097 $pass_args[$argument_check->get_function_return_key()] = $return_value;1098 }1099 }1100 }1101 }1102 pts_module_manager::module_process('__pre_option_process', $command);1103 if(is_file(PTS_COMMAND_PATH . $command . '.php'))1104 {1105 self::$current_command = $command;1106 if(method_exists($command, 'run'))1107 {1108 call_user_func(array($command, 'run'), $pass_args);1109 }1110 else1111 {1112 echo PHP_EOL . 'There is an error in the requested command: ' . $command . PHP_EOL . PHP_EOL;1113 }1114 }1115 else if(($t = pts_module::valid_run_command($command)) != false)1116 {1117 list($module, $module_command) = $t;1118 pts_module_manager::set_current_module($module);1119 pts_module_manager::run_command($module, $module_command, $pass_args);1120 pts_module_manager::set_current_module(null);1121 }1122 echo PHP_EOL;1123 pts_module_manager::module_process('__post_option_process', $command);1124 }1125 public static function current_command()1126 {1127 return self::$current_command;1128 }1129 public static function terminal_width()1130 {1131 static $terminal_width = null;1132 if($terminal_width == null)1133 {1134 $chars = 80;1135 if(pts_client::read_env('TERMINAL_WIDTH') != false && is_numeric(pts_client::read_env('TERMINAL_WIDTH')) >= 80)1136 {1137 $terminal_width = pts_client::read_env('TERMINAL_WIDTH');1138 }1139 else if(pts_client::executable_in_path('stty'))1140 {1141 $terminal_width = explode(' ', trim(shell_exec('stty size 2>&1')));...

Full Screen

Full Screen

current_command

Using AI Code Generation

copy

Full Screen

1require_once('pts_client.php');2$pts_client = new pts_client();3$pts_client->current_command();4require_once('pts_client.php');5$pts_client = new pts_client();6$pts_client->current_command();7require_once('pts_client.php');8$pts_client = new pts_client();9$pts_client->current_command();10require_once('pts_client.php');11$pts_client = new pts_client();12$pts_client->current_command();13require_once('pts_client.php');14$pts_client = new pts_client();15$pts_client->current_command();16require_once('pts_client.php');17$pts_client = new pts_client();18$pts_client->current_command();19require_once('pts_client.php');20$pts_client = new pts_client();21$pts_client->current_command();22require_once('pts_client.php');23$pts_client = new pts_client();24$pts_client->current_command();25require_once('pts_client.php');26$pts_client = new pts_client();27$pts_client->current_command();

Full Screen

Full Screen

current_command

Using AI Code Generation

copy

Full Screen

1echo $client->current_command();2echo $client->current_test_run();3echo $client->current_test_run();4echo $client->current_test_run();5echo $client->current_test_run();6echo $client->current_test_run();7echo $client->current_test_run();8echo $client->current_test_run();9echo $client->current_test_run();10echo $client->current_test_run();11echo $client->current_test_run();12echo $client->current_test_run();13echo $client->current_test_run();14echo $client->current_test_run();15echo $client->current_test_run();16echo $client->current_test_run();17echo $client->current_test_run();18echo $client->current_test_run();

Full Screen

Full Screen

Automation Testing Tutorials

Learn to execute automation testing from scratch with LambdaTest Learning Hub. Right from setting up the prerequisites to run your first automation test, to following best practices and diving deeper into advanced test scenarios. LambdaTest Learning Hubs compile a list of step-by-step guides to help you be proficient with different test automation frameworks i.e. Selenium, Cypress, TestNG etc.

LambdaTest Learning Hubs:

YouTube

You could also refer to video tutorials over LambdaTest YouTube channel to get step by step demonstration from industry experts.

Run Phoronix-test-suite automation tests on LambdaTest cloud grid

Perform automation testing on 3000+ real desktop and mobile devices online.

Trigger current_command code on LambdaTest Cloud Grid

Execute automation tests with current_command on a cloud-based Grid of 3000+ real browsers and operating systems for both web and mobile applications.

Test now for Free

Try LambdaTest Now !!

Get 100 minutes of automation test minutes FREE!!

Next-Gen App & Browser Testing Cloud

Was this article helpful?

Helpful

NotHelpful