How to use set_user_context method of phoromatic class

Best Phoronix-test-suite code snippet using phoromatic.set_user_context

phoromatic.php

Source:phoromatic.php Github

copy

Full Screen

...542 if(pts_strings::string_bool($json['phoromatic']['settings']['RunInstallCommand']))543 {544 if(isset($json['phoromatic']['pre_install_set_context']))545 {546 phoromatic::set_user_context($json['phoromatic']['pre_install_set_context'], self::$p_trigger_id, self::$p_schedule_id, 'PRE_INSTALL');547 }548 pts_test_installer::standard_install($suite_identifier, pts_strings::string_bool($json['phoromatic']['settings']['ForceInstallTests']), true);549 if(isset($json['phoromatic']['post_install_set_context']))550 {551 phoromatic::set_user_context($json['phoromatic']['post_install_set_context'], self::$p_trigger_id, self::$p_schedule_id, 'POST_INSTALL');552 }553 }554 $env_vars = isset($json['phoromatic']['environment_variables']) ? pts_strings::parse_value_string_vars($json['phoromatic']['environment_variables']) : array();555 $is_stress_run = isset($env_vars['PTS_CONCURRENT_TEST_RUNS']) && $env_vars['PTS_CONCURRENT_TEST_RUNS'] > 1;556 // Do the actual running557 phodevi::clear_cache();558 if($is_stress_run)559 {560 self::$test_run_manager = new pts_stress_run_manager(array(561 'UploadResults' => false,562 'SaveResults' => false,563 'PromptForTestDescription' => false,564 'RunAllTestCombinations' => false,565 'PromptSaveName' => false,566 'PromptForTestIdentifier' => false,567 'OpenBrowser' => false568 ), true);569 if(self::$test_run_manager->initial_checks($suite_identifier, 'SHORT'))570 {571 if(self::$test_run_manager->load_tests_to_run($suite_identifier))572 {573 self::$test_run_manager->action_on_stress_log_set(array('phoromatic', 'upload_stress_log_sane'));574 self::$in_stress_mode = $phoromatic_save_identifier;575 self::$test_run_manager->multi_test_stress_run_execute($env_vars['PTS_CONCURRENT_TEST_RUNS'], $env_vars['TOTAL_LOOP_TIME']);576 self::$in_stress_mode = false;577 self::upload_stress_log(self::$test_run_manager->get_stress_log());578 }579 }580 self::$benchmark_ticket_id = null;581 break;582 }583 else584 {585 self::$test_run_manager = new pts_test_run_manager(array(586 'UploadResults' => (isset($json['phoromatic']['settings']['UploadResultsToOpenBenchmarking']) && pts_strings::string_bool($json['phoromatic']['settings']['UploadResultsToOpenBenchmarking'])),587 'SaveResults' => true,588 'RunAllTestCombinations' => false,589 'OpenBrowser' => false590 ), true);591 }592 if(self::$test_run_manager->initial_checks($suite_identifier, 'SHORT'))593 {594 // Load the tests to run595 if(self::$test_run_manager->load_tests_to_run($suite_identifier))596 {597 phoromatic::update_system_status('Tests In Run Queue: ' . implode(', ', self::$test_run_manager->get_tests_to_run_identifiers()));598 if(isset($json['phoromatic']['pre_run_set_context']))599 {600 phoromatic::set_user_context($json['phoromatic']['pre_run_set_context'], self::$p_trigger_id, self::$p_schedule_id, 'PRE_RUN');601 }602 if(isset($json['phoromatic']['settings']['UploadResultsToOpenBenchmarking']) && pts_strings::string_bool($json['phoromatic']['settings']['UploadResultsToOpenBenchmarking']))603 {604 self::$test_run_manager->auto_upload_to_openbenchmarking();605 pts_openbenchmarking_client::override_client_setting('UploadSystemLogsByDefault', pts_strings::string_bool($json['phoromatic']['settings']['UploadSystemLogs']));606 }607 // Save results?608 // Run the actual tests609 self::$test_run_manager->auto_save_results($phoromatic_save_identifier, $phoromatic_results_identifier, (isset($json['phoromatic']['test_description']) ? $json['phoromatic']['test_description'] : 'A Phoromatic run.'));610 self::$test_run_manager->pre_execution_process();611 self::$test_run_manager->call_test_runs();612 phoromatic::update_system_status('Benchmarks Completed For: ' . $phoromatic_save_identifier);613 self::$test_run_manager->post_execution_process();614 $elapsed_benchmark_time = time() - $benchmark_timer;615 // Handle uploading data to server616 $result_file = new pts_result_file(self::$test_run_manager->get_file_name());617 $upload_system_logs = pts_strings::string_bool($json['phoromatic']['settings']['UploadSystemLogs']);618 $server_response = self::upload_test_result($result_file, $upload_system_logs, (isset($json['phoromatic']['schedule_id']) ? $json['phoromatic']['schedule_id'] : null), $phoromatic_save_identifier, $json['phoromatic']['trigger_id'], $elapsed_benchmark_time, $benchmark_ticket_id);619 //pts_client::$pts_logger->log('DEBUG RESPONSE MESSAGE: ' . $server_response);620 if(!pts_strings::string_bool($json['phoromatic']['settings']['ArchiveResultsLocally']))621 {622 pts_client::remove_saved_result_file(self::$test_run_manager->get_file_name());623 }624 }625 if(isset($json['phoromatic']['post_run_set_context']))626 {627 phoromatic::set_user_context($json['phoromatic']['post_run_set_context'], self::$p_trigger_id, self::$p_schedule_id, 'POST_RUN');628 }629 }630 self::$p_schedule_id = null;631 self::$is_running_as_phoromatic_node = false;632 self::$benchmark_ticket_id = null;633 break;634 case 'reboot':635 echo PHP_EOL . 'Phoromatic received a remote command to reboot.' . PHP_EOL;636 phoromatic::update_system_status('Attempting System Reboot');637 if(pts_client::executable_in_path('reboot'))638 {639 shell_exec('reboot');640 sleep(5);641 }642 break;643 case 'shutdown-if-supports-wake':644 $supports_wol = false;645 foreach(pts_network::get_network_wol() as $net_device)646 {647 if(strpos($net_device, 'g') !== false)648 {649 $supports_wol = true;650 break;651 }652 }653 if(!$supports_wol)654 break;655 case 'shutdown':656 if(isset($json['phoromatic']['client_update_script']) && !empty($json['phoromatic']['client_update_script']))657 {658 self::run_client_update_script($json['phoromatic']['client_update_script']);659 sleep(10);660 }661 echo PHP_EOL . 'Phoromatic received a remote command to shutdown.' . PHP_EOL;662 phoromatic::update_system_status('Attempting System Shutdown');663 if(pts_client::executable_in_path('poweroff'))664 {665 shell_exec('poweroff');666 sleep(5);667 }668 break;669 case 'maintenance':670 echo PHP_EOL . 'Idling, system maintenance mode set by Phoromatic Server.' . PHP_EOL;671 phoromatic::update_system_status('Maintenance Mode');672 sleep(60);673 break;674 case 'idle':675 if(isset($json['phoromatic']['client_update_script']) && !empty($json['phoromatic']['client_update_script']))676 {677 self::run_client_update_script($json['phoromatic']['client_update_script']);678 }679 //echo PHP_EOL . 'Idling, waiting for task.' . PHP_EOL;680 phoromatic::update_system_status('Idling, Waiting For Task');681 break;682 case 'exit':683 echo PHP_EOL . 'Phoromatic received a remote command to exit.' . PHP_EOL;684 phoromatic::update_system_status('Exiting Phoromatic');685 $do_exit = true;686 break;687 }688 }689 if(!$do_exit)690 {691 if($server_response == false)692 sleep(rand(10, 30));693 else if(self::$limit_network_communication)694 sleep(60, 240);695 else696 sleep(60);697 }698 }699 pts_client::release_lock(PTS_USER_PATH . 'phoromatic_lock');700 }701 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)702 {703 $system_logs = null;704 $system_logs_hash = null;705 // TODO: Potentially integrate this code below shared with pts_openbenchmarking_client into a unified function for validating system log files706 $system_log_dir = PTS_SAVE_RESULTS_PATH . $result_file->get_identifier() . '/system-logs/';707 if(is_dir($system_log_dir) && $upload_system_logs)708 {709 $is_valid_log = true;710 $finfo = function_exists('finfo_open') ? finfo_open(FILEINFO_MIME_TYPE) : false;711 foreach(pts_file_io::glob($system_log_dir . '*') as $log_dir)712 {713 if($is_valid_log == false || !is_dir($log_dir))714 {715 $is_valid_log = false;716 break;717 }718 foreach(pts_file_io::glob($log_dir . '/*') as $log_file)719 {720 if(!is_file($log_file))721 {722 $is_valid_log = false;723 break;724 }725 if($finfo && substr(finfo_file($finfo, $log_file), 0, 5) != 'text/')726 {727 $is_valid_log = false;728 break;729 }730 }731 }732 if($is_valid_log)733 {734 $system_logs_zip = pts_client::create_temporary_file('.zip');735 pts_compression::zip_archive_create($system_logs_zip, $system_log_dir);736 if(filesize($system_logs_zip) == 0)737 {738 pts_client::$pts_logger && pts_client::$pts_logger->log('System log ZIP file failed to generate. Missing PHP ZIP support?');739 }740 else if(filesize($system_logs_zip) < 2097152)741 {742 // If it's over 2MB, probably too big743 $system_logs = base64_encode(file_get_contents($system_logs_zip));744 $system_logs_hash = sha1($system_logs);745 }746 else747 {748 // trigger_error('The systems log attachment is too large to upload to OpenBenchmarking.org.', E_USER_WARNING);749 }750 unlink($system_logs_zip);751 }752 }753 $composite_xml = $result_file->get_xml();754 $composite_xml_hash = sha1($composite_xml);755 $composite_xml_type = 'composite_xml';756 // Compress the result file XML if it's big757 if(isset($composite_xml[50000]) && function_exists('gzdeflate'))758 {759 $composite_xml_gz = gzdeflate($composite_xml);760 if($composite_xml_gz != false)761 {762 $composite_xml = $composite_xml_gz;763 $composite_xml_type = 'composite_xml_gz';764 }765 }766 // Upload to Phoromatic767 $times_tried = 0;768 do769 {770 if($times_tried > 0)771 {772 sleep(rand(5, 20));773 }774 $res = phoromatic::upload_to_remote_server(array(775 'r' => 'result_upload',776 //'ob' => $ob_data['id'],777 'sched' => $schedule_id,778 'bid' => $benchmark_ticket_id,779 'o' => $save_identifier,780 'ts' => $trigger,781 'et' => $elapsed_time,782 $composite_xml_type => base64_encode($composite_xml),783 'composite_xml_hash' => $composite_xml_hash,784 'system_logs_zip' => $system_logs,785 'system_logs_hash' => $system_logs_hash786 ));787 $times_tried++;788 }789 while($res == false && $times_tried < 4);790 return $res;791 }792 private static function upload_stress_log($stress_log)793 {794 // Upload Logs to Phoromatic795 if($stress_log == null || self::$benchmark_ticket_id == null)796 {797 return;798 }799 $times_tried = 0;800 do801 {802 if($times_tried > 0)803 {804 sleep(rand(5, 20));805 }806 $res = phoromatic::upload_to_remote_server(array(807 'r' => 'stress_log_upload',808 'bid' => self::$benchmark_ticket_id,809 'l' => $stress_log810 ));811 $times_tried++;812 }813 while($res == false && $times_tried < 4);814 return $res;815 }816 public static function upload_stress_log_sane($stress_log)817 {818 static $last_log_upload = 0;819 if(time() > ($last_log_upload + 60))820 {821 self::upload_stress_log($stress_log);822 $last_log_upload = time();823 }824 }825 public static function recent_phoromatic_server_results()826 {827 self::setup_server_addressing();828 $server_response = phoromatic::upload_to_remote_server(array('r' => 'list_results'));829 $server_response = json_decode($server_response, true);830 if(isset($server_response['phoromatic']['results']) && !empty($server_response['phoromatic']['results']))831 {832 foreach($server_response['phoromatic']['results'] as $pprid => $result)833 {834 echo sprintf('%-26ls - %-25ls - %-30ls', $result['Title'], $pprid, date('j M H:i', strtotime($result['UploadTime']))) . PHP_EOL;835 echo sprintf(' %-20ls - %-25ls' . PHP_EOL, $result['SystemName'], $result['GroupName']) . PHP_EOL;836 }837 }838 else839 echo PHP_EOL . 'No Phoromatic Server results discovered.';840 echo PHP_EOL;841 }842 public static function clone_phoromatic_server_result($args)843 {844 self::setup_server_addressing();845 $id = $args[0];846 $server_response = phoromatic::upload_to_remote_server(array('r' => 'clone_result', 'i' => $id));847 $server_response = json_decode($server_response, true);848 if(isset($server_response['phoromatic']['result']['composite_xml']) && !empty($server_response['phoromatic']['result']['composite_xml']))849 {850 $composite_xml = base64_decode($server_response['phoromatic']['result']['composite_xml']);851 $result_file = new pts_result_file($composite_xml);852 // TODO XXX: Add system log downloading support853 pts_client::save_test_result($id . '/composite.xml', $result_file->get_xml(), true);854 echo PHP_EOL . 'Result File Saved As: ' . $id . PHP_EOL . PHP_EOL;855 }856 else857 echo PHP_EOL . 'No Phoromatic result found.' . PHP_EOL;858 }859 private static function run_client_update_script($update_script)860 {861 static $last_update_script_check_time = 0;862 // Don't keep checking it so check no more than every 20 minutes863 if($last_update_script_check_time < (time() - 1200) && !empty($update_script))864 {865 $last_update_script_check_time = time();866 $update_file = pts_client::create_temporary_file();867 $update_script = str_replace("\r", PHP_EOL, $update_script);868 file_put_contents($update_file, $update_script);869 phoromatic::update_system_status('Running Phoronix Test Suite Update Script');870 $env_vars = array();871 pts_client::shell_exec('bash ' . $update_file . ' 2>&1', $env_vars);872 }873 }874 private static function set_user_context($context_script, $trigger, $schedule_id, $process)875 {876 if(!empty($context_script))877 {878 $context_file = pts_client::create_temporary_file();879 file_put_contents($context_file, $context_script);880 chmod($context_file, 0755);881 pts_file_io::mkdir(pts_module::save_dir());882 $storage_path = pts_module::save_dir() . 'memory.pt2so';883 $storage_object = pts_storage_object::recover_from_file($storage_path);884 $notes_log_file = pts_module::save_dir() . sha1($trigger . $schedule_id . $process);885 // We check to see if the context was already set but the system rebooted or something in that script886 if($storage_object == false)887 {888 $storage_object = new pts_storage_object(true, true);...

Full Screen

Full Screen

set_user_context

Using AI Code Generation

copy

Full Screen

1$phoromatic = new phoromatic();2$phoromatic->set_user_context($user_id);3$phoromatic = new phoromatic();4$user_id = $phoromatic->get_user_context();5$phoromatic = phoromatic::get_instance();6$phoromatic->set_user_context($user_id);7$phoromatic = phoromatic::get_instance();8$phoromatic->set_user_context($user_id);9$phoromatic = phoromatic::get_instance();10$user_id = $phoromatic->get_user_context();11$phoromatic = phoromatic::get_instance();12$phoromatic->set_user_context($user_id);13$phoromatic = phoromatic::get_instance();14$phoromatic->set_user_context($user_id);15$phoromatic = phoromatic::get_instance();16$user_id = $phoromatic->get_user_context();17Method Description get_instance() Returns the phoromatic class instance. set_user_context($user_id) Sets the user context for the phoromatic class. get_user_context() Returns the user context of the phoromatic class. get_user_id() Returns the user id of the phoromatic class. get_user_name() Returns the user name of the ph

Full Screen

Full Screen

set_user_context

Using AI Code Generation

copy

Full Screen

1$phoromatic = new phoromatic();2$phoromatic->set_user_context($user_id);3$phoromatic = new phoromatic();4$phoromatic->set_user_context($user_id);5$phoromatic = new phoromatic();6$phoromatic->set_user_context($user_id);7$phoromatic = new phoromatic();8$phoromatic->set_user_context($user_id);9$phoromatic = new phoromatic();10$phoromatic->set_user_context($user_id);11$phoromatic = new phoromatic();12$phoromatic->set_user_context($user_id);13$phoromatic = new phoromatic();14$phoromatic->set_user_context($user_id);15$phoromatic = new phoromatic();16$phoromatic->set_user_context($user_id);17$phoromatic = new phoromatic();18$phoromatic->set_user_context($user_id);19$phoromatic = new phoromatic();20$phoromatic->set_user_context($user_id);21$phoromatic = new phoromatic();22$phoromatic->set_user_context($user_id);23$phoromatic = new phoromatic();24$phoromatic->set_user_context($user_id);

Full Screen

Full Screen

set_user_context

Using AI Code Generation

copy

Full Screen

1require_once('phoromatic.php');2$phoromatic = new phoromatic();3$phoromatic->set_user_context('user1');4require_once('phoromatic.php');5$phoromatic = new phoromatic();6echo $phoromatic->get_user_context();7require_once('phoromatic.php');8$phoromatic = new phoromatic();9$phoromatic->reset_user_context();10require_once('phoromatic.php');11$phoromatic = new phoromatic();12echo $phoromatic->get_user_context();13require_once('phoromatic.php');14$phoromatic = new phoromatic();15echo $phoromatic->get_user_context();16require_once('phoromatic.php');17$phoromatic = new phoromatic();18echo $phoromatic->get_user_context();19require_once('phoromatic.php');20$phoromatic = new phoromatic();21echo $phoromatic->get_user_context();22require_once('phoromatic.php');23$phoromatic = new phoromatic();24echo $phoromatic->get_user_context();25require_once('phoromatic.php');26$phoromatic = new phoromatic();27echo $phoromatic->get_user_context();28require_once('phoromatic.php');29$phoromatic = new phoromatic();30echo $phoromatic->get_user_context();31require_once('phoromatic.php');32$phoromatic = new phoromatic();33echo $phoromatic->get_user_context();

Full Screen

Full Screen

set_user_context

Using AI Code Generation

copy

Full Screen

1require_once 'phoromatic.php';2phoromatic_server::set_user_context();3require_once 'phoromatic.php';4phoromatic_server::get_user_context();5require_once 'phoromatic.php';6phoromatic_server::set_user_context();7require_once 'phoromatic.php';8phoromatic_server::get_user_context();9require_once 'phoromatic.php';10phoromatic_server::set_user_context();11require_once 'phoromatic.php';12phoromatic_server::get_user_context();13require_once 'phoromatic.php';14phoromatic_server::set_user_context();15require_once 'phoromatic.php';16phoromatic_server::get_user_context();17require_once 'phoromatic.php';18phoromatic_server::set_user_context();

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.

Try LambdaTest Now !!

Get 100 minutes of automation test minutes FREE!!

Next-Gen App & Browser Testing Cloud

Was this article helpful?

Helpful

NotHelpful