Best Phoronix-test-suite code snippet using pts_test_run_manager.get_tests_to_run
pts_stress_run_manager.php
Source:pts_stress_run_manager.php  
...35		pts_client::$display->test_run_process_start($this);36		$this->allow_test_cache_share = false;37		$this->disable_dynamic_run_count();38		$this->multi_test_stress_run = $tests_to_run_concurrently;39		$possible_tests_to_run = $this->get_tests_to_run();40		if(is_numeric($total_loop_time))41		{42			$total_loop_time = $total_loop_time * 60;43		}44		$this->loop_until_time = is_numeric($total_loop_time) && $total_loop_time > 1 ? time() + $total_loop_time : false;45		$this->stress_tests_executed = array();46		$this->multi_test_stress_start_time = time();47		$this->thread_collection_dir = pts_client::create_temporary_directory('stress-threads');48		$this->sensors_to_monitor = array();49		$this->sensor_data_archived = array();50		$this->sensor_data_archived_units = array();51		$this->stress_logger = new pts_logger(null, 'phoronix-test-suite-stress-' . date('ymdHi') . '.log');52		$this->stress_logger->log('Log Initialized');53		putenv('FORCE_TIMES_TO_RUN=1');54		// Determine how frequently to print reports / status updates55		$time_report_counter = time();56		if($total_loop_time == 'infinite')57		{58			$report_counter_frequency = 5 * 60;59		}60		else if($total_loop_time > (3 * 60 * 60))61		{62			$report_counter_frequency = 30 * 60;63		}64		else if($total_loop_time > (60 * 60))65		{66			$report_counter_frequency = 10 * 60;67		}68		else if($total_loop_time > (20 * 60))69		{70			$report_counter_frequency = 5 * 60;71		}72		else if($total_loop_time > (10 * 60))73		{74			$report_counter_frequency = 2 * 60;75		}76		else77		{78			$report_counter_frequency = 60;79		}80		// SIGTERM handling81		if(function_exists('pcntl_signal'))82		{83			declare(ticks = 1);84			pcntl_signal(SIGTERM, array($this, 'sig_handler'));85			pcntl_signal(SIGHUP, array($this, 'sig_handler'));86			pcntl_signal(SIGINT, array($this, 'sig_handler'));87		}88		else89		{90			$this->stress_print_and_log('PHP PCNTL support is needed if wishing to gracefully interrupt testing with signals.' . PHP_EOL);91		}92		// SENSOR SETUP WORK93		$sensor_interval_frequency = is_numeric($total_loop_time) && $total_loop_time > 1 ? max($total_loop_time / 1000, 3) : 6;94		$sensor_time_since_last_poll = time();95		foreach(phodevi::supported_sensors(array('cpu_temp', 'cpu_usage', 'gpu_usage', 'gpu_temp', 'hdd_read_speed', 'hdd_write_speed', 'memory_usage', 'swap_usage', 'sys_temp')) as $sensor)96		{97			$supported_devices = call_user_func(array($sensor[2], 'get_supported_devices'));98			if($supported_devices === NULL)99			{100				$supported_devices = array(null);101			}102			foreach($supported_devices as $device)103			{104				$sensor_object = new $sensor[2](0, $device);105				if(phodevi::read_sensor($sensor_object) != -1)106				{107					array_push($this->sensors_to_monitor, $sensor_object);108					$this->sensor_data_archived[phodevi::sensor_object_name($sensor_object)] = array();109					$this->sensor_data_archived_units[phodevi::sensor_object_name($sensor_object)] = phodevi::read_sensor_object_unit($sensor_object);110				}111			}112		}113		$table = array();114		foreach(phodevi::system_hardware(false) as $component => $value)115		{116			$table[] = array($component . ': ', $value);117		}118		foreach(phodevi::system_software(false) as $component => $value)119		{120			$table[] = array($component . ': ', $value);121		}122		$this->stress_print_and_log('SYSTEM INFORMATION: ' . PHP_EOL . phodevi::system_centralized_view() . PHP_EOL . PHP_EOL);123		// BEGIN THE LOOP124		while(!empty($possible_tests_to_run))125		{126			if($continue_test_flag == false)127				break;128			if(($time_report_counter + $report_counter_frequency) <= time() && count(pts_file_io::glob($this->thread_collection_dir . '*')) > 0)129			{130				// ISSUE STATUS REPORT131				$this->stress_print_and_log($this->stress_status_report());132				$time_report_counter = time();133			}134			$this->stress_subsystems_active = array();135			$test_identifiers_active = array();136			while(($waited_pid = pcntl_waitpid(-1, $status, WNOHANG)) > 0)137			{138				pts_file_io::unlink($this->thread_collection_dir . $waited_pid);139			}140			foreach(pts_file_io::glob($this->thread_collection_dir . '*') as $pid_file)141			{142				$pid = basename($pid_file);143				$waited_pid = pcntl_waitpid($pid, $status, WNOHANG);144				if(!file_exists('/proc/' . $pid))145				{146					unlink($pid_file);147					continue;148				}149				$test = new pts_test_profile(file_get_contents($pid_file));150				// Count the number of tests per stress subsystems active151				if(!isset($this->stress_subsystems_active[$test->get_test_hardware_type()]))152				{153					$this->stress_subsystems_active[$test->get_test_hardware_type()] = 1;154				}155				else156				{157					$this->stress_subsystems_active[$test->get_test_hardware_type()] += 1;158				}159				if(!in_array($test->get_identifier(), $test_identifiers_active))160				{161					$test_identifiers_active[] = $test->get_identifier();162				}163			}164			if(!empty($possible_tests_to_run) && count(pts_file_io::glob($this->thread_collection_dir . '*')) < $this->multi_test_stress_run && (!$total_loop_time || $total_loop_time == 'infinite' || $this->loop_until_time > time()))165			{166				shuffle($possible_tests_to_run);167				$test_to_run = false;168				$test_run_index = -1;169				if(getenv('DONT_BALANCE_TESTS_FOR_SUBSYSTEMS') == false)170				{171					// Try to pick a test for a hardware subsystem not yet being explicitly utilized172					foreach($possible_tests_to_run as $i => $test)173					{174						$hw_subsystem_type = $test->test_profile->get_test_hardware_type();175						if(!isset($this->stress_subsystems_active[$hw_subsystem_type]) && !$this->skip_test_check($test))176						{177							$test_run_index = $i;178							$test_to_run = $test;179							break;180						}181					}182				}183				if($test_run_index == -1 && getenv('DONT_TRY_TO_ENSURE_TESTS_ARE_UNIQUE') == false)184				{185					// Try to pick a test from a test profile not currently active186					foreach($possible_tests_to_run as $i => $test)187					{188						if(!in_array($test->test_profile->get_identifier(), $test_identifiers_active) && !$this->skip_test_check($test))189						{190							$test_run_index = $i;191							$test_to_run = $test;192							break;193						}194					}195				}196				if($test_run_index == -1)197				{198					// Last resort, just randomly pick a true "random" test199					$test_run_index = array_rand(array_keys($possible_tests_to_run));200					$test_to_run = $possible_tests_to_run[$test_run_index];201					if($this->skip_test_check($test_to_run))202					{203						continue;204					}205				}206				$pid = pcntl_fork();207				if($pid == -1)208				{209					$this->stress_print_and_log('Forking Failure.');210				}211				if($pid)212				{213					// parent214					$test_identifier = $test_to_run->test_profile->get_identifier();215					file_put_contents($this->thread_collection_dir . $pid, $test_identifier);216					if(!isset($this->stress_tests_executed[$test_identifier]))217					{218						$this->stress_tests_executed[$test_identifier] = 1;219					}220					else221					{222						$this->stress_tests_executed[$test_identifier]++;223					}224				}225				else226				{227					// child228					$this->stress_child_thread = true;229					//echo PHP_EOL . pts_client::cli_colored_text('Starting: ', 'green', true) . $test_to_run->test_profile->get_identifier() . ($test_to_run->get_arguments_description() != null ? ' [' . $test_to_run->get_arguments_description()  . ']' : null) . PHP_EOL;230					$continue_test_flag = $this->process_test_run_request($test_to_run);231					//echo PHP_EOL . pts_client::cli_colored_text('Ended: ', 'red', true) . $test_to_run->test_profile->get_identifier() . ($test_to_run->get_arguments_description() != null ? ' [' . $test_to_run->get_arguments_description()  . ']' : null) . PHP_EOL;232					pts_file_io::unlink($this->thread_collection_dir . getmypid());233					//echo PHP_EOL;234					exit(0);235				}236				if($total_loop_time == false)237				{238					unset($possible_tests_to_run[$test_run_index]);239				}240				else if($total_loop_time == 'infinite')241				{242					//$this->stress_print_and_log('Continuing to test indefinitely' . PHP_EOL);243				}244				else245				{246					if($this->loop_until_time > time())247					{248						$time_left = ceil(($this->loop_until_time - time()) / 60);249					//	echo 'Continuing to test for ' . $time_left . ' more minutes' . PHP_EOL;250					}251				}252			}253			if(is_numeric($this->loop_until_time) && $this->loop_until_time < time())254			{255				// Time to Quit256				$this->stress_print_and_log('TEST TIME EXPIRED; NO NEW TESTS WILL EXECUTE; CURRENT TESTS WILL FINISH' . PHP_EOL);257				// This halt-testing touch will let tests exit early (i.e. between multiple run steps)258				file_put_contents(PTS_USER_PATH . 'halt-testing', 'stress-run is done... This text really is not important, just checking for file presence.');259				// Final report260				$this->stress_print_and_log($this->final_stress_report());261				break;262			}263			if($sensor_time_since_last_poll + $sensor_interval_frequency < time())264			{265				// Time to do a sensor reading266				foreach($this->sensors_to_monitor as &$sensor_object)267				{268					$this->sensor_data_archived[phodevi::sensor_object_name($sensor_object)][] = phodevi::read_sensor($sensor_object);269				}270				$sensor_time_since_last_poll = time();271			}272		}273		putenv('FORCE_TIMES_TO_RUN');274		pts_file_io::delete($this->thread_collection_dir, null, true);275		foreach($this->get_tests_to_run() as $run_request)276		{277			// Remove cache shares278			foreach(pts_file_io::glob($run_request->test_profile->get_install_dir() . 'cache-share-*.pt2so') as $cache_share_file)279			{280				unlink($cache_share_file);281			}282		}283		// Wait for child processes to complete284		//pcntl_waitpid(-1, $status);285		// Restore default handlers286		pcntl_signal(SIGTERM, SIG_DFL);287		pcntl_signal(SIGINT, SIG_DFL);288		pcntl_signal(SIGHUP, SIG_DFL);289		return true;290	}291	protected function skip_test_check(&$test)292	{293		$hw_subsystem_type = $test->test_profile->get_test_hardware_type();294		$subsystem_limit_check = getenv('LIMIT_STRESS_' . strtoupper($hw_subsystem_type) . '_TESTS_COUNT');295		if(isset($this->stress_subsystems_active[$hw_subsystem_type]) && $subsystem_limit_check && $subsystem_limit_check <= $this->stress_subsystems_active[$hw_subsystem_type])296		{297			// e.g. LIMIT_STRESS_GRAPHICS_TESTS_COUNT=2, don't want more than that number per subsystem concurrently298			return true;299		}300		return false;301	}302	public function action_on_stress_log_set($call)303	{304		if(is_callable($call))305		{306			$this->stress_log_event_call = $call;307		}308	}309	protected function stress_print_and_log($msg)310	{311		if($this->stress_logger && $msg != null)312		{313			echo $msg;314			$this->stress_logger->log($msg, false);315		}316		if($this->stress_log_event_call)317		{318			call_user_func($this->stress_log_event_call, $this->stress_logger->get_clean_log());319		}320	}321	public function get_stress_log()322	{323		return $this->stress_logger->get_clean_log();324	}325	public function sig_handler($signo)326	{327		// Time to Quit328		// This halt-testing touch will let tests exit early (i.e. between multiple run steps)329		file_put_contents(PTS_USER_PATH . 'halt-testing', 'stress-run is done... This text really is not important, just checking for file presence.');330		if($this->stress_child_thread == false)331		{332			$this->stress_print_and_log('SIGNAL RECEIVED; QUITTING...' . PHP_EOL);333			// Final report334			$this->stress_print_and_log($this->final_stress_report());335		}336		exit();337	}338	protected function stress_status_report()339	{340		return $this->final_stress_report(false);341	}342	protected function final_stress_report($is_final = true)343	{344		if(!$is_final)345		{346			$report_buffer = PHP_EOL . '###### STRESS RUN INTERIM REPORT ####' . PHP_EOL;347		}348		else349		{350			$report_buffer = PHP_EOL . '###### SUMMARY REPORT ####' . PHP_EOL;351		}352		$report_buffer .= strtoupper(date('F j H:i T')) . PHP_EOL;353		$report_buffer .= pts_client::cli_just_bold('START TIME: ') . date('F j H:i T', $this->multi_test_stress_start_time) . PHP_EOL;354		$report_buffer .= pts_client::cli_just_bold('ELAPSED TIME: ') . pts_strings::format_time(time() - $this->multi_test_stress_start_time) . PHP_EOL;355		if($this->loop_until_time > time())356		{357			$report_buffer .= pts_client::cli_just_bold('TIME REMAINING: ') . pts_strings::format_time($this->loop_until_time - time()) . PHP_EOL;358		}359		else360		{361			$report_buffer .= 'WAITING FOR CURRENT TEST RUN QUEUE TO FINISH.' . PHP_EOL;362		}363		$report_buffer .= pts_client::cli_just_bold('SYSTEM IP: ') . pts_network::get_local_ip() . PHP_EOL;364		$report_buffer .= pts_client::cli_just_bold('HOSTNAME: ') . phodevi::read_property('system', 'hostname') . PHP_EOL;365		$report_buffer .= pts_client::cli_just_bold('# OF CONCURRENT TESTS: ') . $this->multi_test_stress_run . PHP_EOL . PHP_EOL;366		if(!$is_final)367		{368			$report_buffer .= 'TESTS CURRENTLY ACTIVE: ' . PHP_EOL;369			$table = array();370			foreach(pts_file_io::glob($this->thread_collection_dir . '*') as $pid_file)371			{372				$test = pts_file_io::file_get_contents($pid_file);373				$table[] = array($test, '[PID: ' . basename($pid_file) . ']');374			}375			$report_buffer .= pts_user_io::display_text_table($table, '   - ', 2) . PHP_EOL;376		}377		$report_buffer .= PHP_EOL . pts_client::cli_just_bold('TESTS IN RUN QUEUE: ') . PHP_EOL . PHP_EOL;378		$tiq = array();379		foreach($this->get_tests_to_run() as $i => $test)380		{381			$bar = pts_client::cli_colored_text(strtoupper($test->test_profile->get_title()) . ' [' . $test->test_profile->get_identifier() . ']', 'blue', true);382			if(!isset($tiq[$bar]))383			{384				$tiq[$bar] = array();385			}386			array_push($tiq[$bar], $test->get_arguments_description());387		}388		foreach($tiq as $test => $args)389		{390			$report_buffer .= $test;391			foreach($args as $arg)392			{393				if(!empty($arg))...get_tests_to_run
Using AI Code Generation
1require_once('pts-core.php');2$test_run_manager = new pts_test_run_manager();3$tests_to_run = $test_run_manager->get_tests_to_run();4require_once('pts-core.php');5$test_run_manager = pts_test_run_manager::get_test_run_manager_object();6$tests_to_run = $test_run_manager->get_tests_to_run();get_tests_to_run
Using AI Code Generation
1require_once('pts-core.php');2$test_run_manager = new pts_test_run_manager();3$test_run_manager->set_test_profile('test-profile.xml');4$test_run_manager->set_test_arguments('test-arguments.xml');5$test_run_manager->set_test_installation('test-installation.xml');6$test_run_manager->set_test_execution('test-execution.xml');7$test_run_manager->set_test_environment('test-environment.xml');8$test_run_manager->set_test_result('test-result.xml');9$test_run_manager->set_test_result('test-result2.xml');10$test_run_manager->set_test_installation('test-installation2.xml');11$test_run_manager->set_test_execution('test-execution2.xml');12$test_run_manager->set_test_result('test-result3.xml');13$test_run_manager->set_test_result('test-result4.xml');14$test_run_manager->set_test_installation('test-installation3.xml');15$test_run_manager->set_test_execution('test-execution3.xml');16$test_run_manager->set_test_result('test-result5.xml');17$test_run_manager->set_test_result('test-result6.xml');18$test_run_manager->set_test_installation('test-installation4.xml');19$test_run_manager->set_test_execution('test-execution4.xml');20$test_run_manager->set_test_result('test-result7.xml');21$test_run_manager->set_test_result('test-result8.xml');22$test_run_manager->set_test_installation('test-installation5.xml');23$test_run_manager->set_test_execution('test-execution5.xml');24$test_run_manager->set_test_result('test-result9.xml');25$test_run_manager->set_test_result('test-result10.xml');26$test_run_manager->set_test_installation('test-installation6.xml');27$test_run_manager->set_test_execution('test-execution6.xml');28$test_run_manager->set_test_result('test-result11.xml');29$test_run_manager->set_test_result('test-result12.xml');30$test_run_manager->set_test_installation('test-installation7.xml');31$test_run_manager->set_test_execution('test-execution7.xml');32$test_run_manager->set_test_result('test-result13.xml');33$test_run_manager->set_test_result('test-result14.xml');34$test_run_manager->set_test_installation('test-installation8.xml');35$test_run_manager->set_test_execution('test-execution8get_tests_to_run
Using AI Code Generation
1require_once('pts-core/pts-core.php');2$test_run_manager = new pts_test_run_manager();3$test_run_manager->get_tests_to_run('phpbench', 10);4require_once('pts-core/pts-core.php');5$test_run_manager = new pts_test_run_manager();6$test_run_manager->get_tests_to_run('phpbench', 10, 'phpbench');7require_once('pts-core/pts-core.php');8$test_run_manager = new pts_test_run_manager();9$test_run_manager->get_tests_to_run('phpbench', 10, 'phpbench', 'phpbench');10require_once('pts-core/pts-core.php');11$test_run_manager = new pts_test_run_manager();12$test_run_manager->get_tests_to_run('phpbench', 10, 'phpbench', 'phpbench', 'phpbench');13require_once('pts-core/pts-core.php');14$test_run_manager = new pts_test_run_manager();15$test_run_manager->get_tests_to_run('phpbench', 10, 'phpbench', 'phpbench', 'phpbench', 'phpbench');16require_once('pts-core/pts-core.php');17$test_run_manager = new pts_test_run_manager();18$test_run_manager->get_tests_to_run('phpbench', 10, 'phpbench', 'phpbench', 'phpbench', 'phpbench', 'phpbench');19require_once('pts-core/pts-core.php');20$test_run_manager = new pts_test_run_manager();21$test_run_manager->get_tests_to_run('phpbench', 10, 'phpbench', 'phpbench', 'phpbench', 'phpbench', 'phpbench', 'phpbench');get_tests_to_run
Using AI Code Generation
1require_once('pts_test_run_manager.php');2$test_run_manager = new pts_test_run_manager();3$test_run_manager->set_test_profile('test_profile.xml');4$tests_to_run = $test_run_manager->get_tests_to_run();5$result = $test_run_manager->get_test_run_result();6print_r($result);7$result = $test_run_manager->get_test_run_result();8print_r($result);9$result = $test_run_manager->get_test_run_result();10print_r($result);11$result = $test_run_manager->get_test_run_result();12print_r($result);13$result = $test_run_manager->get_test_run_result();14print_r($result);15$result = $test_run_manager->get_test_run_result();16print_r($result);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 get_tests_to_run 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!!
