Best Phoronix-test-suite code snippet using phoromatic.tick_thread
phoromatic.php
Source:phoromatic.php
...190 {191 echo PHP_EOL . 'No Phoromatic Servers detected.' . PHP_EOL . PHP_EOL;192 }193 }194 protected static function tick_thread($force_manual_poll = false)195 {196 static $last_phoromatic_log = 0;197 while(true)198 {199 $j = array();200 $log_size = pts_client::$pts_logger->get_log_file_size();201 if($log_size != $last_phoromatic_log)202 {203 $phoromatic_log = file_get_contents(pts_client::$pts_logger->get_log_file_location());204 $last_phoromatic_log = $log_size;205 $j['phoromatic']['client-log'] = $phoromatic_log;206 }207 foreach(phodevi::supported_sensors() as $sensor)208 {209 $j['phoromatic']['stats']['sensors'][phodevi::sensor_name($sensor)] = array('value' => phodevi::read_sensor($sensor), 'unit' => phodevi::read_sensor_unit($sensor));210 }211 $j['phoromatic']['stats']['uptime'] = ceil(phodevi::system_uptime() / 60);212 $server_response = phoromatic::upload_to_remote_server(array(213 'r' => 'tick',214 'j' => json_encode($j),215 ));216 if($force_manual_poll)217 {218 return;219 }220 $server_response = json_decode($server_response, true);221 if($server_response && isset($server_response['phoromatic']['tick_thread']))222 {223 switch($server_response['phoromatic']['tick_thread'])224 {225 case 'reboot':226 phodevi::reboot();227 break;228 case 'halt-testing':229 touch(PTS_USER_PATH . 'halt-testing');230 break;231 }232 }233 // Randomize the thread work a little bit to ensure not hitting the systems at the same time234 sleep(rand(60, 90));235 }236 }237 protected static function upload_to_remote_server($to_post, $server_address = null, $server_http_port = null, $account_id = null, $try_https = false)238 {239 static $last_communication_minute = null;240 static $communication_attempts = 0;241 if($last_communication_minute == date('i') && $communication_attempts > 8)242 {243 // Something is wrong, Phoromatic shouldn't be communicating with server more than four times a minute244 return false;245 }246 else247 {248 if(date('i') != $last_communication_minute)249 {250 $last_communication_minute = date('i');251 $communication_attempts = 0;252 }253 $communication_attempts++;254 }255 if($server_address == null && self::$server_address != null)256 {257 $server_address = self::$server_address;258 }259 if($server_http_port == null && self::$server_http_port != null)260 {261 $server_http_port = self::$server_http_port;262 }263 if($account_id == null && self::$account_id != null)264 {265 $account_id = self::$account_id;266 }267 if($try_https)268 {269 $try_https = self::phoromatic_server_supports_https($server_address, $server_http_port);270 }271 $to_post['aid'] = $account_id;272 $to_post['pts'] = PTS_VERSION;273 $to_post['pts_core'] = PTS_CORE_VERSION;274 $to_post['gsid'] = defined('PTS_GSID') ? PTS_GSID : null;275 $to_post['lip'] = phodevi::read_property('network', 'ip');276 $to_post['h'] = phodevi::system_hardware(true);277 $to_post['nm'] = phodevi::read_property('network', 'mac-address');278 $to_post['nw'] = implode(', ', pts_network::get_network_wol());279 $to_post['s'] = phodevi::system_software(true);280 $to_post['n'] = phodevi::read_property('system', 'hostname');281 $to_post['pp'] = json_encode(phodevi::read_all_properties());282 $to_post['msi'] = PTS_MACHINE_SELF_ID;283 return pts_network::http_upload_via_post((self::$use_https || $try_https ? 'https://' : 'http://') . $server_address . ':' . $server_http_port . '/phoromatic.php', $to_post, false);284 }285 protected static function update_system_status($current_task, $estimated_time_remaining = 0, $percent_complete = 0, $for_schedule = null, $estimate_to_next_comm = 0)286 {287 static $last_msg = null;288 // Avoid an endless flow of "idling" messages, etc289 if($current_task != $last_msg)290 pts_client::$pts_logger && pts_client::$pts_logger->log($current_task);291 $last_msg = $current_task;292 if(self::$limit_network_communication)293 {294 static $last_comm_time = 0;295 if(time() > ($last_comm_time + 800 + rand(0, 180)))296 {297 // It's been at least half hour since last update, so report in state...298 $last_comm_time = time();299 }300 else301 {302 return;303 }304 }305 return phoromatic::upload_to_remote_server(array(306 'r' => 'update_system_status',307 'a' => $current_task,308 'time' => $estimated_time_remaining,309 'pc' => $percent_complete,310 'sched' => (!empty($for_schedule) ? $for_schedule : self::$p_schedule_id),311 'bid' => (!empty(self::$benchmark_ticket_id) ? self::$benchmark_ticket_id : 0),312 'o' => $estimate_to_next_comm313 ));314 }315 protected static function set_server_info($address, $port, $account_id)316 {317 self::$server_address = $address;318 self::$server_http_port = $port;319 self::$account_id = $account_id;320 self::$use_https = self::phoromatic_server_supports_https(self::$server_address, self::$server_http_port);321 }322 protected static function setup_server_addressing($server_string = null)323 {324 self::$has_run_server_setup_func = true;325 if(isset($server_string[0]) && strpos($server_string[0], '/', strpos($server_string[0], ':')) > 6)326 {327 pts_client::$pts_logger && pts_client::$pts_logger->log('Attempting to connect to Phoromatic Server: ' . $server_string[0]);328 self::set_server_info(substr($server_string[0], 0, strpos($server_string[0], ':')), substr($server_string[0], strlen(substr($server_string[0], 0, strpos($server_string[0], ':'))) + 1, -1 - strlen(substr($server_string[0], strrpos($server_string[0], '/') + 1))), substr($server_string[0], strrpos($server_string[0], '/') + 1));329 pts_client::$display->generic_heading('Server IP: ' . self::$server_address . PHP_EOL . 'Server HTTP Port: ' . self::$server_http_port . PHP_EOL . 'Account ID: ' . self::$account_id);330 pts_client::register_phoromatic_server(self::$server_address, self::$server_http_port);331 }332 else if(($last_server = trim(pts_module::read_file('last-phoromatic-server'))) && !empty($last_server))333 {334 pts_client::$pts_logger && pts_client::$pts_logger->log('Attempting to connect to last server connection: ' . $last_server);335 $last_account_id = substr($last_server, strrpos($last_server, '/') + 1);336 $last_server_address = substr($last_server, 0, strpos($last_server, ':'));337 $last_server_http_port = substr($last_server, strlen($last_server_address) + 1, -1 - strlen($last_account_id));338 pts_client::$pts_logger && pts_client::$pts_logger->log('Last Server IP: ' . $last_server_address . ' Last Server HTTP Port: ' . $last_server_http_port . ' Last Account ID: ' . $last_account_id);339 for($i = 0; $i < 10; $i++)340 {341 $server_response = phoromatic::upload_to_remote_server(array(342 'r' => 'ping',343 ), $last_server_address, $last_server_http_port, $last_account_id, true);344 $server_response = json_decode($server_response, true);345 if($server_response && isset($server_response['phoromatic']['ping']))346 {347 self::set_server_info($last_server_address, $last_server_http_port, $last_account_id);348 pts_client::$pts_logger && pts_client::$pts_logger->log('Phoromatic Server connection restored');349 pts_client::register_phoromatic_server(self::$server_address, self::$server_http_port);350 break;351 }352 else353 {354 pts_client::$pts_logger && pts_client::$pts_logger->log('Phoromatic Server connection failed');355 sleep((12 * ($i + 1)));356 }357 }358 }359 if(self::$server_address == null)360 {361 $archived_servers = pts_client::available_phoromatic_servers();362 if(!empty($archived_servers))363 {364 pts_client::$pts_logger && pts_client::$pts_logger->log('Attempting to auto-discover Phoromatic Servers');365 self::attempt_phoromatic_server_auto_discover($archived_servers);366 }367 }368 if(self::$server_address == null || self::$server_http_port == null || self::$account_id == null)369 {370 pts_client::$pts_logger && pts_client::$pts_logger->log('Phoromatic Server connection setup failed');371 echo PHP_EOL . 'You must pass the Phoromatic Server information as an argument to phoromatic.connect, or otherwise configure your network setup.' . PHP_EOL . ' e.g. phoronix-test-suite phoromatic.connect 192.168.1.2:5555/I0SSJY' . PHP_EOL . PHP_EOL;372 if(PTS_IS_DAEMONIZED_SERVER_PROCESS && !empty($archived_servers))373 {374 echo 'The Phoromatic client appears to be running as a system service/daemon so will attempt to continue auto-polling to find the Phoromatic Server.' . PHP_EOL . PHP_EOL;375 $success = false;376 do377 {378 pts_client::$pts_logger && pts_client::$pts_logger->log('Will auto-poll connected servers every 90 seconds looking for a claim by a Phoromatic Server');379 sleep(90);380 $success = self::attempt_phoromatic_server_auto_discover($archived_servers);381 }382 while($success == false);383 }384 else385 {386 return false;387 }388 }389 return true;390 }391 protected static function attempt_phoromatic_server_auto_discover(&$phoromatic_servers)392 {393 foreach($phoromatic_servers as &$archived_server)394 {395 pts_client::$pts_logger && pts_client::$pts_logger->log('Attempting to auto-discover Phoromatic Server on: ' . $archived_server['ip'] . ': ' . $archived_server['http_port']);396 $server_response = phoromatic::upload_to_remote_server(array(397 'r' => 'ping',398 ), $archived_server['ip'], $archived_server['http_port'], null, true);399 $server_response = json_decode($server_response, true);400 if($server_response && isset($server_response['phoromatic']['account_id']))401 {402 self::set_server_info($archived_server['ip'], $archived_server['http_port'], $server_response['phoromatic']['account_id']);403 return true;404 }405 }406 return false;407 }408 protected static function setup_system_environment()409 {410 if(is_writable('/boot/grub/grubenv') && pts_client::executable_in_path('grub-editenv'))411 {412 // In case system fails or reboots in process and don't want to hang on GRUB recordfail413 shell_exec('grub-editenv /boot/grub/grubenv unset recordfail 2>&1');414 }415 }416 public static function run_connection($args)417 {418 if(pts_client::create_lock(PTS_USER_PATH . 'phoromatic_lock') == false)419 {420 trigger_error('Phoromatic is already running.', E_USER_ERROR);421 return false;422 }423 define('PHOROMATIC_PROCESS', true);424 if(pts_client::$pts_logger == false)425 {426 pts_client::$pts_logger = new pts_logger();427 }428 pts_client::$pts_logger->log(pts_core::program_title() . ' [' . PTS_CORE_VERSION . '] starting Phoromatic client');429 if(phodevi::system_uptime() < 60)430 {431 echo 'PHOROMATIC: Sleeping for 60 seconds as system freshly started.' . PHP_EOL;432 pts_client::$pts_logger->log('Sleeping for 60 seconds as system freshly started');433 sleep(60);434 }435 $server_setup = self::setup_server_addressing($args);436 //$http_comm = new phoromatic_client_comm_http();437 /*438 if(!$server_setup)439 {440 if(getenv('PTS_NO_REBOOT_ON_NETWORK_FAILURE') == false && PTS_IS_DAEMONIZED_SERVER_PROCESS)441 {442 phodevi::reboot();443 }444 return false;445 }446 */447 $times_failed = 0;448 $has_success = false;449 $do_exit = false;450 $just_started = true;451 self::setup_system_environment();452 pts_client::$pts_logger->log('SYSTEM HARDWARE: ' . phodevi::system_hardware(true));453 pts_client::$pts_logger->log('SYSTEM SOFTWARE: ' . phodevi::system_software(true));454 while($do_exit == false)455 {456 $server_response = phoromatic::upload_to_remote_server(array(457 'r' => 'start',458 ));459 if($server_response == false)460 {461 $times_failed++;462 pts_client::$pts_logger->log('Server response failed');463 if($times_failed >= 2)464 {465 trigger_error('Communication with server failed.', E_USER_ERROR);466 if(PTS_IS_DAEMONIZED_SERVER_PROCESS == false && $times_failed > 5)467 {468 return false;469 }470 else if(PTS_IS_DAEMONIZED_SERVER_PROCESS && $times_failed > 10)471 {472 if(getenv('PTS_NO_REBOOT_ON_NETWORK_FAILURE') == false)473 {474 phodevi::reboot();475 }476 }477 }478 }479 else if(substr($server_response, 0, 1) == '[')480 {481 // Likely a notice/warning from server482 echo PHP_EOL . substr($server_response, 0, strpos($server_response, PHP_EOL)) . PHP_EOL;483 }484 else if(substr($server_response, 0, 1) == '{')485 {486 $times_failed = 0;487 $json = json_decode($server_response, true);488 if($has_success == false)489 {490 $has_success = true;491 pts_module::save_file('last-phoromatic-server', self::$server_address . ':' . self::$server_http_port . '/' . self::$account_id);492 }493 if($json != null)494 {495 if(isset($json['phoromatic']['error']) && !empty($json['phoromatic']['error']))496 {497 trigger_error($json['phoromatic']['error'], E_USER_ERROR);498 }499 if(isset($json['phoromatic']['response']) && !empty($json['phoromatic']['response']))500 {501 echo PHP_EOL . $json['phoromatic']['response'] . PHP_EOL;502 }503 if(isset($json['phoromatic']['system_id']) && !empty($json['phoromatic']['system_id']))504 {505 if(self::$system_id != $json['phoromatic']['system_id'])506 {507 // The Phoromatic server/account's system ID for this given system508 self::$system_id = $json['phoromatic']['system_id'];509 // Save the system ID to text file if it's useful for other purposes...510 pts_module::set_option('system_id', self::$system_id);511 }512 }513 if(isset($json['phoromatic']['server_core_version']) && !empty($json['phoromatic']['server_core_version']))514 {515 if(self::$server_core_version != $json['phoromatic']['server_core_version'])516 {517 // The PTS core version of the Phoromatic Server518 self::$server_core_version = $json['phoromatic']['server_core_version'];519 }520 }521 }522 self::$limit_network_communication = isset($json['phoromatic']['settings']['LimitNetworkCommunication']) && pts_strings::string_bool($json['phoromatic']['settings']['LimitNetworkCommunication']);523 if(self::$limit_network_communication)524 {525 // Sleep to ensure network communication is somewhat random in case all systems started at same time526 sleep(rand(0, 20));527 }528 if($just_started)529 {530 if(PTS_IS_DAEMONIZED_SERVER_PROCESS && !self::$limit_network_communication && function_exists('pcntl_fork'))531 {532 $pid = pcntl_fork();533 if($pid == 0)534 {535 // Start the tick thread536 self::tick_thread();537 }538 }539 self::upload_test_install_manifest();540 $just_started = false;541 }542 pts_tests::clear_extra_env_vars();543 if(isset($json['phoromatic']['pre_set_sys_env_vars']) && !empty($json['phoromatic']['pre_set_sys_env_vars']))544 {545 // pre_set_sys_env_vars was added during PTS 5.8 development546 // Sets environment variables on client as specified via the Phoromatic Server's systems page547 foreach(explode(';', $json['phoromatic']['pre_set_sys_env_vars']) as $i => $v_string)548 {549 $var = explode('=', $v_string);550 if(count($var) == 2)551 {552 putenv($var[0] . '=' . $var[1]);553 pts_tests::add_extra_env_var($var[0], $var[1]);554 }555 }556 }557 $task = isset($json['phoromatic']['task']) ? $json['phoromatic']['task'] : null;558 if($task != 'idle')559 {560 pts_client::$pts_logger->log("Received " . $task . " command");561 }562 switch($task)563 {564 case 'install':565 phoromatic::update_system_status('Installing Tests');566 $phoromatic_suite = new pts_test_suite($json['phoromatic']['test_suite']);567 pts_test_installer::standard_install($phoromatic_suite, false, true);568 break;569 case 'benchmark':570 // Make sure all latest tests are available571 pts_openbenchmarking::refresh_repository_lists(null, true);572 $benchmark_timer = time();573 self::$is_running_as_phoromatic_node = true;574 $phoromatic_suite = new pts_test_suite($json['phoromatic']['test_suite']);575 $phoromatic_results_identifier = $json['phoromatic']['trigger_id'];576 self::$p_save_identifier = $json['phoromatic']['save_identifier'];577 self::$p_schedule_id = isset($json['phoromatic']['schedule_id']) ? $json['phoromatic']['schedule_id'] : false;578 self::$p_trigger_id = $json['phoromatic']['trigger_id'];579 self::$benchmark_ticket_id = isset($json['phoromatic']['benchmark_ticket_id']) ? $json['phoromatic']['benchmark_ticket_id'] : null;580 phoromatic::update_system_status('Running Benchmarks For: ' . self::$p_save_identifier);581 // PTS 10.8 result viewer should deal fine with binary logs so can just upload by default there...582 pts_client::$skip_log_file_type_checks = self::$server_core_version >= 10800 || (isset($json['phoromatic']['settings']['AllowAnyDataForLogFiles']) && pts_strings::string_bool($json['phoromatic']['settings']['AllowAnyDataForLogFiles']));583 self::$progressive_result_uploads = isset($json['phoromatic']['settings']['ProgressiveResultUploads']) && pts_strings::string_bool($json['phoromatic']['settings']['ProgressiveResultUploads']);584 pts_module::set_option('skip_log_file_type_checks', (pts_client::$skip_log_file_type_checks ? 1 : 0));585 if(pts_strings::string_bool($json['phoromatic']['settings']['RunInstallCommand']))586 {587 if(isset($json['phoromatic']['pre_install_set_context']))588 {589 phoromatic::set_user_context($json['phoromatic']['pre_install_set_context'], self::$p_trigger_id, self::$p_schedule_id, 'PRE_INSTALL');590 }591 pts_test_installer::standard_install($phoromatic_suite, pts_strings::string_bool($json['phoromatic']['settings']['ForceInstallTests']), true);592 if(isset($json['phoromatic']['post_install_set_context']))593 {594 phoromatic::set_user_context($json['phoromatic']['post_install_set_context'], self::$p_trigger_id, self::$p_schedule_id, 'POST_INSTALL');595 }596 }597 $env_vars = isset($json['phoromatic']['environment_variables']) ? pts_strings::parse_value_string_vars($json['phoromatic']['environment_variables']) : array();598 $is_stress_run = isset($env_vars['PTS_CONCURRENT_TEST_RUNS']) && $env_vars['PTS_CONCURRENT_TEST_RUNS'] > 1;599 // Do the actual running600 phodevi::clear_cache();601 $original_env_var_overrides = pts_env::get_overrides();602 $original_pts_modules = pts_module_manager::attached_modules();603 if(isset($json['phoromatic']['settings']['GlobalEnvironmentVariables']) && !empty($json['phoromatic']['settings']['GlobalEnvironmentVariables']))604 {605 // The global environment variables set on the Phoromatic Settings page, rather than individual schedule/benchmark ticket specific env vars606 pts_env::set_array(pts_strings::parse_value_string_vars($json['phoromatic']['settings']['GlobalEnvironmentVariables']));607 }608 if(!empty($env_vars))609 {610 pts_env::set_array($env_vars);611 }612 if($is_stress_run)613 {614 self::$test_run_manager = new pts_stress_run_manager(array(615 'UploadResults' => false,616 'SaveResults' => false,617 'PromptForTestDescription' => false,618 'RunAllTestCombinations' => false,619 'PromptSaveName' => false,620 'PromptForTestIdentifier' => false,621 'OpenBrowser' => false622 ), true);623 if(self::$test_run_manager->initial_checks($phoromatic_suite, 'SHORT'))624 {625 if(self::$test_run_manager->load_tests_to_run($phoromatic_suite))626 {627 self::$test_run_manager->action_on_stress_log_set(array('phoromatic', 'upload_stress_log_sane'));628 self::$in_stress_mode = self::$p_save_identifier;629 self::$test_run_manager->multi_test_stress_run_execute($env_vars['PTS_CONCURRENT_TEST_RUNS'], $env_vars['TOTAL_LOOP_TIME']);630 self::$in_stress_mode = false;631 self::upload_stress_log(self::$test_run_manager->get_stress_log());632 }633 }634 self::$benchmark_ticket_id = null;635 break;636 }637 else638 {639 self::$test_run_manager = new pts_test_run_manager(array(640 'UploadResults' => (isset($json['phoromatic']['settings']['UploadResultsToOpenBenchmarking']) && pts_strings::string_bool($json['phoromatic']['settings']['UploadResultsToOpenBenchmarking'])),641 'SaveResults' => true,642 'RunAllTestCombinations' => false,643 'OpenBrowser' => false644 ), true);645 }646 if(self::$test_run_manager->initial_checks($phoromatic_suite, 'SHORT'))647 {648 // Load the tests to run649 if(self::$test_run_manager->load_tests_to_run($phoromatic_suite))650 {651 phoromatic::update_system_status('Tests In Run Queue: ' . implode(', ', self::$test_run_manager->get_tests_to_run_identifiers()));652 if(isset($json['phoromatic']['pre_run_set_context']))653 {654 phoromatic::set_user_context($json['phoromatic']['pre_run_set_context'], self::$p_trigger_id, self::$p_schedule_id, 'PRE_RUN');655 }656 if(isset($json['phoromatic']['settings']['UploadResultsToOpenBenchmarking']) && pts_strings::string_bool($json['phoromatic']['settings']['UploadResultsToOpenBenchmarking']))657 {658 self::$test_run_manager->auto_upload_to_openbenchmarking();659 pts_openbenchmarking_client::override_client_setting('UploadSystemLogsByDefault', pts_strings::string_bool($json['phoromatic']['settings']['UploadSystemLogs']));660 }661 // Save results?662 // Run the actual tests663 self::$test_run_manager->auto_save_results(self::$p_save_identifier, $phoromatic_results_identifier, (isset($json['phoromatic']['test_description']) ? $json['phoromatic']['test_description'] : 'A Phoromatic run.'));664 self::$test_run_manager->pre_execution_process();665 self::$test_run_manager->call_test_runs();666 phoromatic::update_system_status('Benchmarks Completed For: ' . self::$p_save_identifier);667 self::$test_run_manager->post_execution_process();668 $elapsed_benchmark_time = time() - $benchmark_timer;669 // Handle uploading data to server670 $result_file = new pts_result_file(self::$test_run_manager->get_file_name());671 $upload_system_logs = pts_strings::string_bool($json['phoromatic']['settings']['UploadSystemLogs']);672 pts_module::set_option('upload_system_logs', ($upload_system_logs ? 1 : 0));673 $upload_install_logs = isset($json['phoromatic']['settings']['UploadInstallLogs']) && pts_strings::string_bool($json['phoromatic']['settings']['UploadInstallLogs']);674 pts_module::set_option('upload_install_logs', ($upload_install_logs ? 1 : 0));675 $upload_run_logs = isset($json['phoromatic']['settings']['UploadRunLogs']) && pts_strings::string_bool($json['phoromatic']['settings']['UploadRunLogs']);676 pts_module::set_option('upload_run_logs', ($upload_run_logs ? 1 : 0));677 $server_response = self::upload_test_result($result_file, $upload_system_logs, self::$p_schedule_id, self::$p_save_identifier, self::$p_trigger_id, $elapsed_benchmark_time, self::$benchmark_ticket_id);678 //pts_client::$pts_logger->log('DEBUG RESPONSE MESSAGE: ' . $server_response);679 if(!pts_strings::string_bool($json['phoromatic']['settings']['ArchiveResultsLocally']))680 {681 pts_results::remove_saved_result_file(self::$test_run_manager->get_file_name());682 }683 }684 if(isset($json['phoromatic']['post_run_set_context']))685 {686 phoromatic::set_user_context($json['phoromatic']['post_run_set_context'], self::$p_trigger_id, self::$p_schedule_id, 'POST_RUN');687 }688 }689 self::$p_schedule_id = null;690 self::$is_running_as_phoromatic_node = false;691 self::$benchmark_ticket_id = null;692 // Restore any environment variables that may have been set within process / overridden693 if(!empty($original_env_var_overrides))694 {695 pts_env::set_array($original_env_var_overrides, true);696 $original_env_var_overrides = null;697 }698 // Unload any modules that were loaded just during this benchmarking run (i.e. by a passed environment variable from Phoromatic)699 pts_module_manager::detach_extra_modules($original_pts_modules);700 break;701 case 'reboot':702 echo PHP_EOL . 'Phoromatic received a remote command to reboot.' . PHP_EOL;703 phoromatic::update_system_status('Attempting System Reboot');704 self::tick_thread(true);705 phodevi::reboot();706 break;707 case 'shutdown-if-supports-wake':708 $supports_wol = false;709 foreach(pts_network::get_network_wol() as $net_device)710 {711 if(strpos($net_device, 'g') !== false)712 {713 $supports_wol = true;714 break;715 }716 }717 if(!$supports_wol)718 break;719 case 'shutdown':720 if(isset($json['phoromatic']['client_update_script']) && !empty($json['phoromatic']['client_update_script']))721 {722 self::run_client_update_script($json['phoromatic']['client_update_script']);723 sleep(10);724 }725 echo PHP_EOL . 'Phoromatic received a remote command to shutdown.' . PHP_EOL;726 phoromatic::update_system_status('Attempting System Shutdown');727 self::tick_thread(true);728 phodevi::shutdown();729 break;730 case 'maintenance':731 echo PHP_EOL . 'Idling, system maintenance mode set by Phoromatic Server.' . PHP_EOL;732 phoromatic::update_system_status('Maintenance Mode' . self::check_for_separate_pts_thread_process());733 sleep(60);734 break;735 case 'idle':736 if(isset($json['phoromatic']['client_update_script']) && !empty($json['phoromatic']['client_update_script']))737 {738 self::run_client_update_script($json['phoromatic']['client_update_script']);739 }740 //echo PHP_EOL . 'Idling, waiting for task.' . PHP_EOL;741 phoromatic::update_system_status('Idling, Waiting For Task' . self::check_for_separate_pts_thread_process());742 break;743 case 'exit':744 echo PHP_EOL . 'Phoromatic received a remote command to exit.' . PHP_EOL;745 phoromatic::update_system_status('Exiting Phoromatic');746 self::tick_thread(true);747 $do_exit = true;748 break;749 }750 }751 if(!$do_exit)752 {753 if($server_response == false)754 sleep(rand(10, 30));755 else if(self::$limit_network_communication)756 sleep(rand(60, 240));757 else758 sleep(60);759 }760 }761 pts_client::release_lock(PTS_USER_PATH . 'phoromatic_lock');762 }763 private static function check_for_separate_pts_thread_process()764 {765 $report = null;766 $log_file = pts_logger::default_log_file_path() . 'phoronix-test-suite-benchmark.log';767 if(is_file($log_file) && filemtime($log_file) > (time() - 1200))768 {769 $log_file = pts_file_io::file_get_contents($log_file);770 $log_file = substr($log_file, strrpos($log_file, PHP_EOL) + 1);771 if(($x = strpos($log_file, ']')) !== false)772 {773 $log_file = substr($log_file, ($x + 1));774 }775 $report .= '; Separate Process: ' . trim($log_file);776 }777 return $report;778 }779 public static function __post_test_run()780 {781 // Progressively upload result file at end of each test execution782 if(self::$progressive_result_uploads)783 {784 self::upload_progressive_test_result();785 }786 }787 private static function upload_progressive_test_result()788 {789 if(!self::$progressive_result_uploads || !(self::$test_run_manager->result_file instanceof pts_result_file))790 {791 return false;792 }793 $composite_xml = self::$test_run_manager->result_file->get_xml();794 return phoromatic::upload_to_remote_server(array(795 'r' => 'result_upload',796 'sched' => self::$p_schedule_id,797 'bid' => self::$benchmark_ticket_id,798 'o' => self::$p_save_identifier,799 'ts' => self::$p_trigger_id,800 'composite_xml' => base64_encode($composite_xml),801 'composite_xml_hash' => sha1($composite_xml),802 'progressive_upload' => 1803 ));804 }805 private static function upload_test_result(&$result_file, $upload_system_logs = true, $schedule_id = 0, $save_identifier = null, $trigger = null, $elapsed_time = 0, $benchmark_ticket_id = null)806 {807 $system_logs = null;808 $system_logs_hash = null;809 if(self::$server_core_version < 10602)810 {811 // On newer PTS servers, upload as separate upload afterwards to better handle large log files that otherwise may go beyond max request size, etc812 // TODO: Potentially integrate this code below shared with pts_openbenchmarking_client into a unified function for validating system log files813 $system_log_dir = $result_file->get_system_log_dir();814 if(is_dir($system_log_dir) && ($upload_system_logs || pts_module::read_option('upload_system_logs', 0) != 0))815 {816 $is_valid_log = true;817 if(pts_client::$skip_log_file_type_checks == false)818 {819 // For security/malicious purposes, ensure system log directory only contains text files820 $is_valid_log = pts_file_io::directory_only_contains_text_files($system_log_dir);821 }822 if($is_valid_log)823 {824 $system_logs_zip = pts_client::create_temporary_file('.zip');825 pts_compression::zip_archive_create($system_logs_zip, $system_log_dir);826 if(filesize($system_logs_zip) == 0)827 {828 pts_client::$pts_logger && pts_client::$pts_logger->log('System log ZIP file failed to generate. Missing PHP ZIP support?');829 }830 else if(pts_client::$skip_log_file_type_checks == false && filesize($system_logs_zip) > 2097152)831 {832 // If it's over 2MB, probably too big833 pts_client::$pts_logger && pts_client::$pts_logger->log('System log ZIP file too big to upload');834 }835 else836 {837 $system_logs = base64_encode(file_get_contents($system_logs_zip));838 $system_logs_hash = sha1($system_logs);839 }840 unlink($system_logs_zip);841 }842 }843 }844 $composite_xml = $result_file->get_xml();845 $composite_xml_hash = sha1($composite_xml);846 $composite_xml_type = 'composite_xml';847 // Compress the result file XML if it's big848 if(isset($composite_xml[50000]) && function_exists('gzdeflate'))849 {850 $composite_xml_gz = gzdeflate($composite_xml);851 if($composite_xml_gz != false)852 {853 $composite_xml = $composite_xml_gz;854 $composite_xml_type = 'composite_xml_gz';855 }856 }857 // Upload to Phoromatic858 $times_tried = 0;859 do860 {861 if($times_tried > 0)862 {863 sleep(rand(5, 20));864 }865 $res = phoromatic::upload_to_remote_server(array(866 'r' => 'result_upload',867 //'ob' => $ob_data['id'],868 'sched' => $schedule_id,869 'bid' => $benchmark_ticket_id,870 'o' => $save_identifier,871 'ts' => $trigger,872 'et' => $elapsed_time,873 $composite_xml_type => base64_encode($composite_xml),874 'composite_xml_hash' => $composite_xml_hash,875 'system_logs_zip' => $system_logs,876 'system_logs_hash' => $system_logs_hash,877 'progressive_upload' => (self::$progressive_result_uploads ? 2 : 0)878 ));879 $times_tried++;880 }881 while($res == false && $times_tried < 4);882 $server_response = json_decode($res, true);883 if(isset($server_response['phoromatic']['upload_id']) && !empty($server_response['phoromatic']['upload_id']))884 {885 // On newer PTS servers, upload as separate upload afterwards to better handle large log files that otherwise may go beyond max request size, etc886 $log_types = array();887 if($upload_system_logs)888 {889 $log_types['system-logs'] = $result_file->get_system_log_dir();890 }891 if(pts_module::read_option('upload_install_logs', 0) != 0)892 {893 $log_types['installation-logs'] = $result_file->get_test_installation_log_dir();894 }895 if(pts_module::read_option('upload_run_logs', 0) != 0)896 {897 $log_types['test-logs'] = $result_file->get_test_log_dir();898 }899 foreach($log_types as $index => $log_dir)900 {901 if(is_dir($log_dir))902 {903 $is_valid_log = true;904 if(pts_client::$skip_log_file_type_checks == false)905 {906 // For security/malicious purposes, ensure system log directory only contains text files907 $is_valid_log = pts_file_io::directory_only_contains_text_files($log_dir);908 }909 if($is_valid_log)910 {911 $system_logs_zip = pts_client::create_temporary_file('.zip');912 pts_compression::zip_archive_create($system_logs_zip, $log_dir);913 if(filesize($system_logs_zip) == 0)914 {915 pts_client::$pts_logger && pts_client::$pts_logger->log($index . ' log ZIP file failed to generate. Missing PHP ZIP support?');916 }917 else918 {919 $system_logs = base64_encode(file_get_contents($system_logs_zip));920 $system_logs_hash = sha1($system_logs);921 }922 unlink($system_logs_zip);923 phoromatic::upload_to_remote_server(array(924 'r' => 'result_log_upload',925 'i' => $server_response['phoromatic']['upload_id'],926 'system_logs_type' => $index,927 'system_logs_zip' => $system_logs,928 'system_logs_hash' => $system_logs_hash929 ));930 }931 }932 }933 }934 return $res;935 }936 private static function upload_stress_log($stress_log)937 {938 // Upload Logs to Phoromatic939 if($stress_log == null || self::$benchmark_ticket_id == null)940 {941 return;942 }943 $times_tried = 0;944 do945 {946 if($times_tried > 0)947 {948 sleep(rand(5, 20));949 }950 $res = phoromatic::upload_to_remote_server(array(951 'r' => 'stress_log_upload',952 'bid' => self::$benchmark_ticket_id,953 'l' => pts_user_io::strip_ansi_escape_sequences($stress_log)954 ));955 $times_tried++;956 }957 while($res == false && $times_tried < 4);958 return $res;959 }960 public static function upload_stress_log_sane($stress_log)961 {962 static $last_log_upload = 0;963 if(time() > ($last_log_upload + 60))964 {965 self::upload_stress_log($stress_log);966 $last_log_upload = time();967 }968 }969 public static function recent_phoromatic_server_results()970 {971 self::setup_server_addressing();972 $server_response = phoromatic::upload_to_remote_server(array('r' => 'list_results'), null, null, null, true);973 $server_response = json_decode($server_response, true);974 if(isset($server_response['phoromatic']['results']) && !empty($server_response['phoromatic']['results']))975 {976 foreach($server_response['phoromatic']['results'] as $pprid => $result)977 {978 echo pts_client::cli_just_bold($result['Title']) . ' ' . $pprid . ' ' . date('j M H:i', strtotime($result['UploadTime'])) . PHP_EOL;979 echo ' ' . $result['SystemName'] . ' ' . $result['GroupName'];980 echo PHP_EOL . PHP_EOL;981 }982 }983 else984 echo PHP_EOL . 'No Phoromatic Server results discovered.';985 echo PHP_EOL;986 }987 public static function clone_phoromatic_server_result($args)988 {989 self::setup_server_addressing();990 $id = $args[0];991 $server_response = phoromatic::upload_to_remote_server(array('r' => 'clone_result', 'i' => $id), null, null, null, true);992 $server_response = json_decode($server_response, true);993 if(isset($server_response['phoromatic']['result']['composite_xml']) && !empty($server_response['phoromatic']['result']['composite_xml']))994 {995 $composite_xml = base64_decode($server_response['phoromatic']['result']['composite_xml']);996 $result_file = new pts_result_file($composite_xml);997 // TODO XXX: Add system log downloading support998 pts_client::save_test_result($id . '/composite.xml', $result_file->get_xml(), true);999 echo PHP_EOL . 'Result File Saved As: ' . $id . PHP_EOL . PHP_EOL;1000 }1001 else1002 echo PHP_EOL . 'No Phoromatic result found.' . PHP_EOL;1003 }1004 private static function run_client_update_script($update_script)1005 {1006 static $last_update_script_check_time = 0;1007 // Don't keep checking it so check no more than every 30 minutes1008 if($last_update_script_check_time < (time() - (60 * 30)) && !empty($update_script))1009 {1010 $last_update_script_check_time = time();1011 $update_file = pts_client::create_temporary_file();1012 $update_script = str_replace("\r", PHP_EOL, $update_script);1013 file_put_contents($update_file, $update_script);1014 phoromatic::update_system_status('Running Phoromatic Update Script');1015 $env_vars = array();1016 $append_cmd = '';1017 if(phodevi::is_windows() && is_executable('C:\cygwin64\bin\bash.exe') && strpos($update_script, '#!/bin') !== false)1018 {1019 $cmd = 'C:\cygwin64\bin\bash.exe';1020 }1021 else if(phodevi::is_windows() && is_executable('C:\Windows\System32\cmd.exe'))1022 {1023 $cmd = 'C:\Windows\System32\cmd.exe /c';1024 }1025 else if(pts_client::executable_in_path('bash'))1026 {1027 $cmd = 'bash';1028 $append_cmd = ' 2>&1';1029 }1030 else1031 {1032 $cmd = 'sh';1033 $append_cmd = ' 2>&1';1034 }1035 pts_client::$pts_logger && pts_client::$pts_logger->log('Running Update Script: ' . $cmd . ' ' . $update_file . $append_cmd);1036 $update_output = pts_client::shell_exec($cmd . ' ' . $update_file . $append_cmd, $env_vars);1037 if(trim($update_output) != '')1038 {1039 pts_client::$pts_logger && pts_client::$pts_logger->log('Update Script Output: ' . trim($update_output));1040 }1041 unlink($update_file);1042 phoromatic::update_system_status('Phoromatic Update Script Completed');1043 self::tick_thread(true);1044 }1045 }1046 private static function set_user_context($context_script, $trigger, $schedule_id, $process)1047 {1048 if(!empty($context_script))1049 {1050 $context_file = pts_client::create_temporary_file();1051 file_put_contents($context_file, $context_script);1052 chmod($context_file, 0755);1053 pts_file_io::mkdir(pts_module::save_dir());1054 $storage_path = pts_module::save_dir() . 'memory.pt2so';1055 $storage_object = pts_storage_object::recover_from_file($storage_path);1056 $notes_log_file = pts_module::save_dir() . sha1($trigger . $schedule_id . $process);1057 // We check to see if the context was already set but the system rebooted or something in that script...
tick.php
Source:tick.php
...94 $stmt->execute();95 }96}97$json['phoromatic']['response'] = 'tick';98$json['phoromatic']['tick_thread'] = $send_event;99echo json_encode($json);100exit;101?>...
tick_thread
Using AI Code Generation
1$phoromatic = new phoromatic();2$phoromatic->tick_thread();3$phoromatic = new phoromatic();4$phoromatic->tick_thread();5$phoromatic = new phoromatic();6$phoromatic->tick_thread();7$phoromatic = new phoromatic();8$phoromatic->tick_thread();9$phoromatic = new phoromatic();10$phoromatic->tick_thread();11$phoromatic = new phoromatic();12$phoromatic->tick_thread();13$phoromatic = new phoromatic();14$phoromatic->tick_thread();15$phoromatic = new phoromatic();16$phoromatic->tick_thread();17$phoromatic = new phoromatic();18$phoromatic->tick_thread();19$phoromatic = new phoromatic();20$phoromatic->tick_thread();21$phoromatic = new phoromatic();22$phoromatic->tick_thread();23$phoromatic = new phoromatic();24$phoromatic->tick_thread();25$phoromatic = new phoromatic();26$phoromatic->tick_thread();
tick_thread
Using AI Code Generation
1$phoromatic = new phoromatic();2$phoromatic->tick_thread();3$phoromatic = new phoromatic();4$phoromatic->tick_thread();5$phoromatic = new phoromatic();6$phoromatic->tick_thread();
tick_thread
Using AI Code Generation
1require_once('phoromatic.php');2$phoromatic = new Phoromatic();3$phoromatic->tick_thread();4require_once('phoromatic.php');5$phoromatic = new Phoromatic();6$phoromatic->tick_thread();7require_once('phoromatic.php');8$phoromatic = new Phoromatic();9$phoromatic->tick_thread();10require_once('phoromatic.php');11$phoromatic = new Phoromatic();12$phoromatic->tick_thread();13require_once('phoromatic.php');14$phoromatic = new Phoromatic();15$phoromatic->tick_thread();16require_once('phoromatic.php');17$phoromatic = new Phoromatic();18$phoromatic->tick_thread();19require_once('phoromatic.php');20$phoromatic = new Phoromatic();21$phoromatic->tick_thread();22require_once('phoromatic.php');23$phoromatic = new Phoromatic();24$phoromatic->tick_thread();25require_once('phoromatic.php');26$phoromatic = new Phoromatic();27$phoromatic->tick_thread();28require_once('phoromatic.php');29$phoromatic = new Phoromatic();30$phoromatic->tick_thread();31require_once('phoromatic.php');32$phoromatic = new Phoromatic();33$phoromatic->tick_thread();
tick_thread
Using AI Code Generation
1require_once('phoromatic.php');2$phoromatic = new phoromatic();3$phoromatic->tick_thread();4require_once('phoromatic.php');5$phoromatic = new phoromatic();6$phoromatic->add_result();7require_once('phoromatic.php');8$phoromatic = new phoromatic();9$phoromatic->get_results();10require_once('phoromatic.php');11$phoromatic = new phoromatic();12$phoromatic->get_summary();13require_once('phoromatic.php');14$phoromatic = new phoromatic();15$phoromatic->get_result();16require_once('phoromatic.php');17$phoromatic = new phoromatic();18$phoromatic->get_result();19require_once('phoromatic.php');20$phoromatic = new phoromatic();21$phoromatic->get_result();22require_once('phoromatic.php');23$phoromatic = new phoromatic();24$phoromatic->get_result();25require_once('phoromatic.php');26$phoromatic = new phoromatic();27$phoromatic->get_result();28require_once('phoromatic.php');29$phoromatic = new phoromatic();30$phoromatic->get_result();
tick_thread
Using AI Code Generation
1$phoromatic = new Phoromatic();2$phoromatic->tick_thread(2);3$phoromatic = new Phoromatic();4$phoromatic->tick_thread(2);5$phoromatic = new Phoromatic();6$phoromatic->tick_thread(3);
tick_thread
Using AI Code Generation
1require_once('phoromatic.php');2$phoromatic = new phoromatic();3$phoromatic->tick_thread();4require_once('phoromatic.php');5$phoromatic = new phoromatic();6$phoromatic->tick_thread();7require_once('phoromatic.php');8$phoromatic = new phoromatic();9$phoromatic->tick_thread();10require_once('phoromatic.php');11$phoromatic = new phoromatic();12$phoromatic->tick_thread();13require_once('phoromatic.php');14$phoromatic = new phoromatic();15$phoromatic->tick_thread();16require_once('phoromatic.php');17$phoromatic = new phoromatic();18$phoromatic->tick_thread();19require_once('phoromatic.php');20$phoromatic = new phoromatic();21$phoromatic->tick_thread();
tick_thread
Using AI Code Generation
1require_once 'phoromatic.php';2$phoromatic = new phoromatic();3if (isset($_GET['test_id'])) {4 $test_id = $_GET['test_id'];5 $result = $phoromatic->get_test_result($test_id);6 echo json_encode($result);7 exit();8}9if (isset($_GET['test'])) {10 $test_id = $phoromatic->tick_thread($_GET['test']);11 header("Location: 4.php?test_id=$test_id");12 exit();13}14require_once 'phoromatic.php';15$phoromatic = new phoromatic();16if (isset($_GET['test'])) {17 $result = $phoromatic->tick($_GET['test']);18 echo json_encode($result);19 exit();20}21require_once 'phoromatic.php';22$phoromatic = new phoromatic();23if (isset($_GET['test_id'])) {24 $result = $phoromatic->get_test_result($_GET['test_id']);25 echo json_encode($result);26 exit();27}28require_once 'phoromatic.php';29$phoromatic = new phoromatic();30if (isset($_GET['test'])) {31 $result = $phoromatic->tick($_GET['test']);32 echo json_encode($result);33 exit();34}
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.
You could also refer to video tutorials over LambdaTest YouTube channel to get step by step demonstration from industry experts.
Execute automation tests with tick_thread on a cloud-based Grid of 3000+ real browsers and operating systems for both web and mobile applications.
Test now for FreeGet 100 minutes of automation test minutes FREE!!