How to use fork method of pts_client class

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

pts_client.php

Source:pts_client.php Github

copy

Full Screen

...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')));1142 if(count($terminal_width) == 2 && is_numeric($terminal_width[1]) && $terminal_width[1] >= 80)1143 {1144 $chars = $terminal_width[1];1145 }1146 }1147 else if(pts_client::executable_in_path('tput'))1148 {1149 $terminal_width = trim(shell_exec('tput cols 2>&1'));1150 if(is_numeric($terminal_width) && $terminal_width > 1)1151 {1152 $chars = $terminal_width;1153 }1154 }1155 $terminal_width = $chars;1156 }1157 return $terminal_width;1158 }1159 public static function is_process_running($process)1160 {1161 if(phodevi::is_linux())1162 {1163 // Checks if process is running on the system1164 $running = shell_exec('ps -C ' . strtolower($process) . ' 2>&1');1165 $running = trim(str_replace(array('PID', 'TTY', 'TIME', 'CMD'), '', $running));1166 }1167 else if(phodevi::is_solaris())1168 {1169 // Checks if process is running on the system1170 $ps = shell_exec('ps -ef 2>&1');1171 $running = strpos($ps, ' ' . strtolower($process)) != false ? 'TRUE' : null;1172 }1173 else if(pts_client::executable_in_path('ps') != false)1174 {1175 // Checks if process is running on the system1176 $ps = shell_exec('ps -ax 2>&1');1177 $running = strpos($ps, ' ' . strtolower($process)) != false ? 'TRUE' : null;1178 }1179 else1180 {1181 $running = null;1182 }1183 return !empty($running);1184 }1185 public static function parse_value_string_double_identifier($value_string)1186 {1187 // i.e. with PRESET_OPTIONS='stream.run-type=Add'1188 $values = array();1189 foreach(explode(';', $value_string) as $preset)1190 {1191 if(count($preset = pts_strings::trim_explode('=', $preset)) == 2)1192 {1193 $dot = strrpos($preset[0], '.');1194 if($dot !== false && ($test = substr($preset[0], 0, $dot)) != null && ($option = substr($preset[0], ($dot + 1))) != null)1195 {1196 $values[$test][$option] = $preset[1];1197 }1198 }1199 }1200 return $values;1201 }1202 public static function create_temporary_file($file_extension = null)1203 {1204 $temp_file = tempnam(pts_client::temporary_directory(), 'PTS');1205 if($file_extension)1206 {1207 $extended_file = pts_client::temporary_directory() . '/' . basename($temp_file) . $file_extension;1208 if(rename($temp_file, $extended_file))1209 {1210 $temp_file = $extended_file;1211 }1212 }1213 return $temp_file;1214 }1215 public static function create_temporary_directory($prefix = null)1216 {1217 $tmpdir = pts_client::temporary_directory();1218 do1219 {1220 $randname = '/pts-' . $prefix . rand(0, 9999);1221 }1222 while(is_dir($tmpdir . $randname));1223 mkdir($tmpdir . $randname);1224 return $tmpdir . $randname . '/';1225 }1226 public static function temporary_directory()1227 {1228 return sys_get_temp_dir();1229 }1230 public static function read_env($var)1231 {1232 return getenv($var);1233 }1234 public static function pts_set_environment_variable($name, $value)1235 {1236 // Sets an environmental variable1237 return getenv($name) == false && putenv($name . '=' . $value);1238 }1239 public static function shell_exec($exec, $extra_vars = null)1240 {1241 // Same as shell_exec() but with the PTS env variables added in1242 // Convert pts_client::environmental_variables() into shell export variable syntax1243 $var_string = '';1244 $extra_vars = ($extra_vars == null ? pts_client::environmental_variables() : array_merge(pts_client::environmental_variables(), $extra_vars));1245 foreach(array_keys($extra_vars) as $key)1246 {1247 $var_string .= 'export ' . $key . '=' . str_replace(' ', '\ ', trim($extra_vars[$key])) . ';';1248 }1249 $var_string .= ' ';1250 return shell_exec($var_string . $exec);1251 }1252 public static function executable_in_path($executable, $ignore_paths_with = false)1253 {1254 static $cache = null;1255 if(!isset($cache[$executable]) || $ignore_paths_with)1256 {1257 $paths = pts_strings::trim_explode((phodevi::is_windows() ? ';' : ':'), (($path = pts_client::read_env('PATH')) == false ? '/usr/local/bin:/usr/bin:/usr/sbin:/bin' : $path));1258 $executable_path = false;1259 foreach($paths as $path)1260 {1261 $path = pts_strings::add_trailing_slash($path);1262 if(is_executable($path . $executable))1263 {1264 if($ignore_paths_with && stripos($path, $ignore_paths_with) !== false)1265 {1266 continue;1267 }1268 $executable_path = $path . $executable;1269 break;1270 }1271 }1272 if($ignore_paths_with)1273 {1274 // Don't cache calls using the $ignore_paths_with parameter1275 return $executable_path;1276 }1277 $cache[$executable] = $executable_path;1278 }1279 return $cache[$executable];1280 }1281 public static function display_web_page($URL, $alt_text = null, $default_open = true, $auto_open = false)1282 {1283 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'))1284 {1285 return;1286 }1287 if($auto_open == false)1288 {1289 $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);1290 }1291 else1292 {1293 $view_results = true;1294 }1295 if($view_results)1296 {1297 static $browser = null;1298 if($browser == null)1299 {1300 $config_browser = pts_config::read_user_config('PhoronixTestSuite/Options/General/DefaultBrowser', null);1301 if($config_browser != null && (is_executable($config_browser) || ($config_browser = pts_client::executable_in_path($config_browser))))1302 {1303 $browser = $config_browser;1304 }1305 else if(phodevi::is_windows())1306 {1307 $windows_browsers = array(1308 'C:\Program Files (x86)\Mozilla Firefox\firefox.exe',1309 'C:\Program Files\Internet Explorer\iexplore.exe'1310 );1311 foreach($windows_browsers as $browser_test)1312 {1313 if(is_executable($browser_test))1314 {1315 $browser = $browser_test;1316 break;1317 }1318 }1319 if(substr($URL, 0, 1) == '\\')1320 {1321 $URL = 'file:///C:' . str_replace('/', '\\', $URL);1322 }1323 }1324 else1325 {1326 $possible_browsers = array('firefox', 'mozilla', 'x-www-browser', 'iceweasel', 'konqueror', 'epiphany', 'google-chrome', 'midori', 'epiphany-browser', 'epiphany', 'midori', 'qupzilla', 'open', 'xdg-open');1327 foreach($possible_browsers as &$b)1328 {1329 if(($b = pts_client::executable_in_path($b)))1330 {1331 $browser = $b;1332 break;1333 }1334 }1335 }1336 }1337 if($browser != null)1338 {1339 shell_exec($browser . ' "' . $URL . '" 2> /dev/null &');1340 }1341 else1342 {1343 echo PHP_EOL . 'No Web Browser Found.' . PHP_EOL;1344 }1345 }1346 }1347 public static function cache_hardware_calls()1348 {1349 phodevi::system_hardware(true);1350 phodevi::supported_sensors();1351 phodevi::unsupported_sensors();1352 }1353 public static function cache_software_calls()1354 {1355 phodevi::system_software(true);1356 }1357 public static function remove_saved_result_file($identifier)1358 {1359 pts_file_io::delete(PTS_SAVE_RESULTS_PATH . $identifier, null, true);1360 }1361 public static function saved_test_results()1362 {1363 $results = array();1364 $ignore_ids = array();1365 foreach(pts_file_io::glob(PTS_SAVE_RESULTS_PATH . '*/composite.xml') as $result_file)1366 {1367 $identifier = basename(dirname($result_file));1368 if(!in_array($identifier, $ignore_ids))1369 {1370 $results[] = $identifier;1371 }1372 }1373 return $results;1374 }1375 public static function timed_function($function, $function_parameters, $time, $continue_while_true_function = null, $continue_while_true_function_parameters)1376 {1377 if(($time < 0.5 && $time != -1) || $time > 300)1378 {1379 return;1380 }1381 if(function_exists('pcntl_fork') && function_exists('posix_setsid'))1382 {1383 $current_pid = function_exists('posix_getpid') ? posix_getpid() : -1;1384 $pid = pcntl_fork();1385 if($pid == -1)1386 {1387 trigger_error('Could not fork ' . $function . '.', E_USER_ERROR);1388 }1389 else if($pid)1390 {1391 self::$forked_pids[] = $pid;1392 }1393 else1394 {1395 posix_setsid();1396 $loop_continue = true;1397 while($loop_continue && is_file(PTS_USER_LOCK) && ($continue_while_true_function === true || ($loop_continue = call_user_func_array($continue_while_true_function, $continue_while_true_function_parameters))))1398 {1399 call_user_func_array($function, $function_parameters);1400 if($time > 0)1401 {1402 sleep($time);1403 }1404 else if($time == -1)1405 {1406 $loop_continue = false;1407 }1408 if($current_pid != -1 && !is_dir('/proc/' . $current_pid))1409 {1410 exit;1411 }1412 clearstatcache();1413 }1414 if(function_exists('posix_kill'))1415 {1416 posix_kill(posix_getpid(), SIGINT);1417 }1418 exit(0);1419 }1420 }1421 else1422 {1423 if(is_array($function))1424 {1425 $function = implode(':', $function);1426 }1427 trigger_error('php-pcntl and php-posix must be installed for calling ' . $function . '.', E_USER_ERROR);1428 }1429 }1430 public static function fork($fork_function, $fork_function_parameters = null)1431 {1432 if(!is_array($fork_function_parameters))1433 {1434 $fork_function_parameters = array($fork_function_parameters);1435 }1436 if(function_exists('pcntl_fork'))1437 {1438 $current_pid = function_exists('posix_getpid') ? posix_getpid() : -1;1439 $pid = pcntl_fork();1440 if($pid == -1)1441 {1442 trigger_error('Could not fork ' . $fork_function . '.', E_USER_ERROR);1443 }1444 else if($pid)1445 {1446 // PARENT1447 self::$forked_pids[] = $pid;1448 return true;1449 }1450 else1451 {1452 // CHILD1453 // posix_setsid();1454 call_user_func_array($fork_function, $fork_function_parameters);1455 if(function_exists('posix_kill'))1456 {1457 posix_kill(posix_getpid(), SIGINT);1458 }1459 exit(0);1460 }1461 }1462 else1463 {1464 // No PCNTL Support1465 call_user_func_array($fork_function, $fork_function_parameters);1466 }1467 return false;1468 }1469 public static function code_error_handler($error_code, $error_string, $error_file, $error_line)1470 {1471 /*if(!(error_reporting() & $error_code))1472 {1473 return;1474 }*/1475 switch($error_code)1476 {1477 case E_USER_ERROR:1478 $error_type = 'PROBLEM';1479 if(pts_client::is_debug_mode() == false)...

Full Screen

Full Screen

fork

Using AI Code Generation

copy

Full Screen

1require_once('pts_client.php');2$pts_client = new pts_client();3$pts_client->fork();4require_once('pts_client.php');5$pts_client = new pts_client();6$pts_client->connect();7$pts_client->send('Hello world');8$pts_client->close();9require_once('pts_client.php');10$pts_client = new pts_client();11$pts_client->connect();12$pts_client->send('Hello world');13$pts_client->close();14require_once('pts_client.php');15$pts_client = new pts_client();16$pts_client->fork();

Full Screen

Full Screen

fork

Using AI Code Generation

copy

Full Screen

1require_once('pts_client.php');2$pts = new pts_client();3$pts->fork('1.php');4$pts->fork('2.php');5$pts->fork('3.php');6$pts->fork('4.php');7$pts->fork('5.php');8$pts->fork('6.php');9$pts->fork('7.php');10$pts->fork('8.php');11$pts->fork('9.php');12$pts->fork('10.php');13$pts->fork('11.php');14$pts->fork('12.php');15$pts->fork('13.php');16$pts->fork('14.php');17$pts->fork('15.php');18$pts->fork('16.php');19$pts->fork('17.php');20$pts->fork('18.php');21$pts->fork('19.php');22$pts->fork('20.php');23$pts->fork('21.php');24$pts->fork('22.php');25$pts->fork('23.php');26$pts->fork('24.php');27$pts->fork('25.php');28$pts->fork('26.php');29$pts->fork('27.php');30$pts->fork('28.php');31$pts->fork('29.php');32$pts->fork('30.php');33$pts->fork('31.php');34$pts->fork('32.php');35$pts->fork('33.php');36$pts->fork('34.php');37$pts->fork('35.php');38$pts->fork('36.php');39$pts->fork('37.php');40$pts->fork('38.php');41$pts->fork('39.php');42$pts->fork('40.php');43$pts->fork('41.php');44$pts->fork('42.php');45$pts->fork('43.php');46$pts->fork('44.php');47$pts->fork('45.php');48$pts->fork('46.php');49$pts->fork('47.php');50$pts->fork('48.php');51$pts->fork('49.php');52$pts->fork('50.php');53$pts->fork('51.php');54$pts->fork('52.php');55$pts->fork('53.php');56$pts->fork('54.php');57$pts->fork('55.php');58$pts->fork('56.php');59$pts->fork('57.php');60$pts->fork('58.php');61$pts->fork('59.php');62$pts->fork('60.php');

Full Screen

Full Screen

fork

Using AI Code Generation

copy

Full Screen

1include "pts_client.php";2$pts_client = new pts_client();3$pts_client->fork();4if($pts_client->is_child)5{6 echo "This is child process";7}8{9 echo "This is parent process";10}

Full Screen

Full Screen

fork

Using AI Code Generation

copy

Full Screen

1require_once('pts_client.php');2$pts = new pts_client();3$pts->set_path_to_pts_client('/usr/local/bin/pts_client');4$pts->set_path_to_pts_test('/usr/local/bin/pts_test');5$pts->set_path_to_pts_render('/usr/local/bin/pts_render');6$pts->set_path_to_pts_report('/usr/local/bin/pts_report');7$pts->set_path_to_pts_result_parser('/usr/local/bin/pts_result_parser');8$pts->set_path_to_pts_upload_result('/usr/local/bin/pts_upload_result');9$pts->set_path_to_pts_merge_results('/usr/local/bin/pts_merge_results');10$pts->set_path_to_pts_delete_result('/usr/local/bin/pts_delete_result');11$pts->set_path_to_pts_result_merge('/usr/local/bin/pts_result_merge');12$pts->set_path_to_pts_result_parser('/usr/local/bin/pts_result_parser');13$pts->set_path_to_pts_upload_result('/usr/local/bin/pts_upload_result');14$pts->set_path_to_pts_merge_results('/usr/local/bin/pts_merge_results');15$pts->set_path_to_pts_delete_result('/usr/local/bin/pts_delete_result');16$pts->set_path_to_pts_result_merge('/usr/local/bin/pts_result_merge');17$pts->set_path_to_pts_result_parser('/usr/local/bin/pts_result_parser');18$pts->set_path_to_pts_upload_result('/usr/local/bin/pts_upload_result');

Full Screen

Full Screen

fork

Using AI Code Generation

copy

Full Screen

1include_once("pts_client.php");2$pts_client = new pts_client();3$pts_client->fork("3.php", array("var1" => "value1"));4echo $var2;5include_once("pts_client.php");6$pts_client = new pts_client();7$pts_client->fork("4.php", array("var1" => "value1"));8echo $var2;9include_once("pts_client.php");10$pts_client = new pts_client();11$pts_client->fork("5.php", array("var1" => "value1"));12echo $var2;13include_once("pts_client.php");14$pts_client = new pts_client();15$pts_client->fork("6.php", array("var1" => "value1"));16echo $var2;

Full Screen

Full Screen

fork

Using AI Code Generation

copy

Full Screen

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

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 fork code on LambdaTest Cloud Grid

Execute automation tests with fork 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