Best Phoronix-test-suite code snippet using pts_test_result_parser.gen_result_active_handle
pts_test_result_parser.php
Source:pts_test_result_parser.php
...17*/18class pts_test_result_parser19{20 private static $monitoring_sensors = array();21 protected static function gen_result_active_handle(&$root_result, $test_result = null)22 {23 if($test_result == null)24 {25 $test_result = clone $root_result;26 }27 $tr_hash = $test_result->get_comparison_hash(true, false);28 if(!isset($root_result->generated_result_buffers[$tr_hash]))29 {30 $test_result->active = new pts_test_result_buffer_active();31 $root_result->generated_result_buffers[$tr_hash] = $test_result;32 }33 return $root_result->generated_result_buffers[$tr_hash]->active;34 }35 public static function system_monitor_task_check(&$test_run_request)36 {37 $definitions = $test_run_request->test_profile->get_results_definition('SystemMonitor');38 self::$monitoring_sensors = array();39 $test_directory = $test_run_request->test_profile->get_install_dir();40 foreach($definitions->get_system_monitor_definitions() as $sys_monitor)41 {42 $sensor = $sys_monitor->get_sensor();43 $polling_freq = $sys_monitor->get_polling_frequency();44 $report_as = $sys_monitor->get_report();45 // TODO: Right now we are looping through SystemMonitor tags, but right now pts-core only supports providing one monitor sensor as the result46 $sensor = explode('.', $sensor);47 if($sensor == array('sys', 'time'))48 {49 // sys.time is a special case since we are just timing the test length and thus don't need to fork the thread50 $start_time = microtime(true);51 self::$monitoring_sensors[] = array(0, $sensor, null, $start_time);52 continue;53 }54 if(count($sensor) != 2 || !phodevi::is_sensor_supported($sensor))55 {56 // Not a sensor or it's not supported57 pts_test_result_parser::debug_message('No supported sensor found');58 continue;59 }60 if(!is_numeric($polling_freq) || $polling_freq < 0.5)61 {62 pts_test_result_parser::debug_message('No polling frequency defined, defaulting to 2 seconds');63 $polling_freq = 2;64 }65 $polling_freq *= 1000000; // Convert from seconds to micro-seconds66 if(!in_array($report_as, array('ALL', 'MAX', 'MIN', 'AVG')))67 {68 // Not a valid reporting type69 pts_test_result_parser::debug_message('No valid Report entry found.');70 continue;71 }72 if(!function_exists('pcntl_fork'))73 {74 pts_client::$display->test_run_instance_error('PHP with PCNTL support enabled is required for this test.');75 return false;76 }77 $monitor_file = tempnam($test_directory, '.monitor');78 $pid = pcntl_fork();79 if($pid != -1)80 {81 if($pid)82 {83 // Main process still84 self::$monitoring_sensors[] = array($pid, $sensor, $report_as, $monitor_file);85 continue;86 }87 else88 {89 $sensor_values = array();90 while(is_file($monitor_file)) // when test ends, it will remove file in case the posix_kill doesn't happen91 {92 $sensor_values[] = phodevi::read_sensor($sensor);93 file_put_contents($monitor_file, implode("\n", $sensor_values));94 usleep($polling_freq);95 }96 exit(0);97 }98 }99 }100 return count(self::$monitoring_sensors) > 0;101 }102 public static function system_monitor_task_post_test(&$test_run_request, $exit_status_pass = true)103 {104 $test_directory = $test_run_request->test_profile->get_install_dir();105 $did_post_result = false;106 foreach(self::$monitoring_sensors as $sensor_r)107 {108 if($sensor_r[1] == array('sys', 'time'))109 {110 // sys.time is a special case111 $end_time = microtime(true);112 // Delta time113 $result_value = round($end_time - $sensor_r[3], 3);114 $minimal_test_time = pts_config::read_user_config('PhoronixTestSuite/Options/TestResultValidation/MinimalTestTime', 2);115 if($result_value < $minimal_test_time)116 {117 // The test ended too fast118 pts_test_result_parser::debug_message('Test Run-Time Too Short: ' . $result_value);119 $result_value = null;120 }121 }122 else123 {124 // Kill the sensor monitoring thread125 if(function_exists('posix_kill') == false)126 {127 pts_client::$display->test_run_error('The PHP POSIX extension is required for this test.');128 return $did_post_result;129 }130 posix_kill($sensor_r[0], SIGTERM);131 $sensor_values = explode("\n", pts_file_io::file_get_contents($sensor_r[3]));132 pts_file_io::unlink($sensor_r[3]);133 if(count($sensor_values) == 0)134 {135 continue;136 }137 switch($sensor_r[2])138 {139 case 'MAX':140 $result_value = max($sensor_values);141 break;142 case 'MIN':143 $result_value = min($sensor_values);144 break;145 case 'AVG':146 $result_value = pts_math::arithmetic_mean($sensor_values);147 break;148 case 'ALL':149 $result_value = implode(',', $sensor_values);150 break;151 default:152 $result_value = null;153 break;154 }155 }156 if($result_value != null && $result_value > 0 && $exit_status_pass)157 {158 // For now it's only possible to return one result per test XXX actually with PTS7 this can be changed....159 // TODO XXX for some sensors may make sense for min/max values?160 pts_test_result_parser::debug_message('Test Result Montioring Process Returning: ' . $result_value);161 self::gen_result_active_handle($test_run_request)->add_trial_run_result($result_value);162 $did_post_result = true;163 }164 }165 return $did_post_result;166 }167 public static function parse_result(&$test_run_request, $test_log_file)168 {169 $produced_result = false;170 if($test_run_request->test_profile->get_file_parser_spec() == false)171 {172 return $produced_result;173 }174 $extra_arguments = $test_run_request->get_arguments();175 $pts_test_arguments = trim($test_run_request->test_profile->get_default_arguments() . ' ' . str_replace($test_run_request->test_profile->get_default_arguments(), '', $extra_arguments) . ' ' . $test_run_request->test_profile->get_default_post_arguments());176 switch($test_run_request->test_profile->get_display_format())177 {178 case 'IMAGE_COMPARISON':179 $produced_result = self::parse_iqc_result($test_run_request, $test_log_file, $pts_test_arguments, $extra_arguments);180 break;181 case 'PASS_FAIL':182 case 'MULTI_PASS_FAIL':183 case 'BAR_GRAPH':184 default:185 $produced_result = self::parse_result_process($test_run_request, $test_log_file, $pts_test_arguments, $extra_arguments);186 break;187 }188 return $produced_result;189 }190 public static function generate_extra_data(&$test_result, &$test_log_file = null)191 {192 $definitions = $test_result->test_profile->get_results_definition('ExtraData');193 foreach($definitions->get_system_monitor_definitions() as $entry)194 {195 $frame_all_times = array();196 switch(($eid = $entry->get_identifier()))197 {198 case 'libframetime-output':199 case 'libframetime-output-no-limit':200 // libframetime output201 $line_values = explode(PHP_EOL, file_get_contents($test_log_file));202 if(!empty($line_values) && isset($line_values[3]))203 {204 foreach($line_values as &$v)205 {206 if(substr($v, -3) == ' us' && substr($v, 0, 10) == 'Frametime ')207 {208 $frametime = substr($v, 10);209 $frametime = substr($frametime, 0, -3);210 if($eid == 'libframetime-output-no-limit' || $frametime > 2000)211 {212 $frametime = $frametime / 1000;213 $frame_all_times[] = $frametime;214 }215 }216 }217 $frame_all_times = pts_math::remove_outliers($frame_all_times);218 }219 break;220 case 'csv-dump-frame-latencies':221 // Civ Beyond Earth222 $csv_values = explode(',', pts_file_io::file_get_contents($test_log_file));223 if(!isset($csv_values[10]))224 {225 $csv_values = explode(PHP_EOL, pts_file_io::file_get_contents($test_log_file));226 }227 if(!empty($csv_values) && isset($csv_values[3]))228 {229 foreach($csv_values as $i => &$v)230 {231 if(!is_numeric($v))232 {233 unset($csv_values[$i]);234 continue;235 }236 $frame_all_times[] = $v;237 }238 }239 break;240 case 'com-speeds-frame-latency-totals':241 // id Tech Games242 $log_file = pts_file_io::file_get_contents($test_log_file);243 $frame_all_times = array();244 while(($log_file = strstr($log_file, 'frame:')))245 {246 if(($a = strpos($log_file, ' all: ')) !== false && $a < strpos($log_file, "\n"))247 {248 $all = ltrim(substr($log_file, $a + 6));249 $all = substr($all, 0, strpos($all, ' '));250 if(is_numeric($all) && $all > 0)251 {252 $frame_all_times[] = $all;253 }254 }255 $log_file = strstr($log_file, 'bk:');256 }257 break;258 case 'cpu-frames-space-delimited':259 // HITMAN on Linux uses at least this method260 $log_file = pts_file_io::file_get_contents($test_log_file);261 $frame_all_times = array();262 if(($x = strpos($log_file, '---- CPU FRAMES ----')) !== false)263 {264 $log_file = trim(str_replace(PHP_EOL, ' ', substr($log_file, $x + strlen('---- CPU FRAMES ----'))));265 foreach(explode(' ', $log_file) as $inp)266 {267 if(is_numeric($inp) && $inp > 0)268 {269 $frame_all_times[] = round(1000 / $inp, 3); // since its reporting current frame270 }271 }272 }273 break;274 case 'gpu-frames-space-delimited':275 // HITMAN 2 uses at least this method276 $log_file = pts_file_io::file_get_contents($test_log_file);277 $frame_all_times = array();278 if(($x = strpos($log_file, '---- GPU FRAMES ----')) !== false)279 {280 $log_file = trim(str_replace(PHP_EOL, ' ', substr($log_file, $x + strlen('---- GPU FRAMES ----'))));281 foreach(explode(' ', $log_file) as $inp)282 {283 if(is_numeric($inp) && $inp > 0)284 {285 $frame_all_times[] = round(1000 / $inp, 3); // since its reporting current frame286 }287 }288 }289 break;290 case 'valve-source-frame-times':291 // Counter-Strike: GO At least292 $log_file = pts_file_io::file_get_contents($test_log_file);293 $frame_all_times = array();294 if(($x = strpos($log_file, 'demo tick,frame start time,frame start delta')) !== false)295 {296 $log_file = substr($log_file, $x);297 foreach(explode(PHP_EOL, $log_file) as $line)298 {299 $line = explode(',', $line);300 if(isset($line[2]) && is_numeric($line[2]) && $line[2] > 0)301 {302 $frame_all_times[] = $line[2] * 1000;303 }304 }305 }306 break;307 case 'csv-f1-frame-times':308 // F1 2018309 $log_file = pts_file_io::file_get_contents($test_log_file);310 $frame_all_times = array();311 if(($x = strpos($log_file, 'Frame,Time (ms)')) !== false)312 {313 $log_file = substr($log_file, $x);314 foreach(explode(PHP_EOL, $log_file) as $line)315 {316 $line = explode(',', $line);317 if(isset($line[1]) && is_numeric($line[1]) && $line[1] > 0)318 {319 $frame_all_times[] = $line[1];320 }321 }322 }323 break;324 case 'csv-individual-frame-times':325 // Thrones of Britannia on Linux uses at least this method326 $log_file = pts_file_io::file_get_contents($test_log_file);327 $frame_all_times = array();328 if(($x = strpos($log_file, 'individual frame times (ms):')) !== false)329 {330 $log_file = trim(str_replace(PHP_EOL, ' ', substr($log_file, $x + strlen('individual frame times (ms): '))));331 foreach(explode(', ', $log_file) as $inp)332 {333 if(is_numeric($inp) && $inp > 0)334 {335 $frame_all_times[] = $inp;336 }337 else338 {339 // hitting the end340 break;341 }342 }343 }344 break;345 }346 if(isset($frame_all_times[60]))347 {348 // Take off the first frame as it's likely to have taken much longer when game just starting off...349 // array_shift($frame_all_times);350 $tp = clone $test_result->test_profile;351 $tp->set_result_scale('Milliseconds');352 $tp->set_result_proportion('LIB');353 $tp->set_display_format('LINE_GRAPH');354 $tp->set_identifier(null);355 $extra_result = new pts_test_result($tp);356 $extra_result->active = new pts_test_result_buffer_active();357 $extra_result->set_used_arguments_description($test_result->get_arguments_description() . ' - Total Frame Time');358 $extra_result->set_used_arguments($test_result->get_arguments() . ' - ' . $extra_result->get_arguments_description()); // this formatting is weird but to preserve pre-PTS7 comparsions of extra results359 $extra_result->active->set_result(implode(',', $frame_all_times));360 self::gen_result_active_handle($test_result, $extra_result)->add_trial_run_result(implode(',', $frame_all_times));361 //$extra_result->set_used_arguments(phodevi::sensor_name($sensor) . ' ' . $test_result->get_arguments());362 }363 }364 }365 protected static function parse_iqc_result(&$test_run_request, $log_file, $pts_test_arguments, $extra_arguments)366 {367 if(!extension_loaded('gd'))368 {369 // Needs GD library to work370 return false;371 }372 $returns = false;373 $definitions = $test_run_request->test_profile->get_results_definition('ImageParser');374 foreach($definitions->get_system_monitor_definitions() as $entry)375 {376 $match_test_arguments = $entry->get_match_to_image_args();377 if(!empty($match_test_arguments) && strpos($pts_test_arguments, $match_test_arguments) === false)378 {379 // This is not the ResultsParser XML section to use as the MatchToTestArguments does not match the PTS test arguments380 continue;381 }382 $iqc_source_file = $entry->get_source_image();383 if(is_file($test_run_request->test_profile->get_install_dir() . $iqc_source_file))384 {385 $iqc_source_file = $test_run_request->test_profile->get_install_dir() . $iqc_source_file;386 }387 else388 {389 // No image file found390 continue;391 }392 $img = pts_image::image_file_to_gd($iqc_source_file);393 if($img == false)394 {395 return;396 }397 $img_sliced = imagecreatetruecolor($entry->get_image_width(), $entry->get_image_height());398 imagecopyresampled($img_sliced, $img, 0, 0, $entry->get_image_x(), $entry->get_image_y(), $entry->get_image_width(), $entry->get_image_height(), $entry->get_image_width(), $entry->get_image_height());399 $test_result = $test_run_request->test_profile->get_install_dir() . 'iqc.png';400 imagepng($img_sliced, $test_result);401 if($test_result != false)402 {403 self::gen_result_active_handle($test_run_request)->add_trial_run_result($test_result);404 $returns = true;405 }406 }407 return $returns;408 }409 protected static function parse_result_process(&$test_run_request, $log_file, $pts_test_arguments, $extra_arguments, $prefix = null)410 {411 $produced_result = false;412 if($prefix != null && substr($prefix, -1) != '_')413 {414 $prefix .= '_';415 }416 $definitions = $test_run_request->test_profile->get_results_definition('ResultsParser');417 $all_parser_entries = $definitions->get_result_parser_definitions();418 $avoid_duplicates = array();419 foreach($all_parser_entries as $entry)420 {421 $tr = clone $test_run_request;422 if($entry->get_display_format() != null)423 {424 $tr->test_profile->set_display_format($entry->get_display_format());425 }426 $is_pass_fail_test = in_array($tr->test_profile->get_display_format(), array('PASS_FAIL', 'MULTI_PASS_FAIL'));427 $is_numeric_check = !$is_pass_fail_test;428 $min_result = null;429 $max_result = null;430 $min_test_result = false;431 $max_test_result = false;432 $test_result = self::parse_result_process_entry($tr, $log_file, $pts_test_arguments, $extra_arguments, $prefix, $entry, $is_pass_fail_test, $is_numeric_check, $all_parser_entries, $min_test_result, $max_test_result);433 if($test_result != false)434 {435 // Result found436 if(in_array($test_result, $avoid_duplicates))437 {438 // Workaround for some tests like FIO that have test result parsers that could generate duplicates in handling old PTS versions while newer ones have K conversion, etc439 continue;440 }441 $avoid_duplicates[] = $test_result;442 if($is_numeric_check)443 {444 // Check if this test reports a min result value445 $min_result = $min_test_result !== false && is_numeric($min_test_result) ? $min_test_result : self::parse_result_process_entry($tr, $log_file, $pts_test_arguments, $extra_arguments, 'MIN_', $entry, $is_pass_fail_test, $is_numeric_check, $all_parser_entries);446 // Check if this test reports a max result value447 $max_result = $max_test_result !== false && is_numeric($max_test_result) ? $max_test_result : self::parse_result_process_entry($tr, $log_file, $pts_test_arguments, $extra_arguments, 'MAX_', $entry, $is_pass_fail_test, $is_numeric_check, $all_parser_entries);448 }449 self::gen_result_active_handle($test_run_request, $tr)->add_trial_run_result($test_result, $min_result, $max_result);450 $produced_result = true;451 }452 }453 return $produced_result;454 }455 protected static function parse_result_process_entry(&$test_run_request, $log_file, $pts_test_arguments, $extra_arguments, $prefix, &$e, $is_pass_fail_test, $is_numeric_check, &$all_parser_entries, &$min_test_result = false, &$max_test_result = false)456 {457 $test_result = false;458 $match_test_arguments = $e->get_match_to_test_args();459 $template = $e->get_output_template();460 $multi_match = $e->get_multi_match();461 if(!empty($match_test_arguments) && strpos($pts_test_arguments, $match_test_arguments) === false)462 {463 // This is not the ResultsParser XML section to use as the MatchToTestArguments does not match the PTS test arguments...
gen_result_active_handle
Using AI Code Generation
1require_once('pts_test_result_parser.php');2$result_file = 'result_file.xml';3$parser = new pts_test_result_parser();4$parser->gen_result_active_handle($result_file);5$parser->parse_result_file();6$test_results = $parser->get_test_results();7$test_profile = $parser->get_test_profile();8$test_env = $parser->get_test_environment();9$test_sys = $parser->get_test_system();10$test_hw = $parser->get_test_hardware();11$test_sw = $parser->get_test_software();12$test_status = $parser->get_test_status();13$test_identifier = $parser->get_test_identifier();14$test_title = $parser->get_test_title();15$test_version = $parser->get_test_version();16$test_description = $parser->get_test_description();17$test_notes = $parser->get_test_notes();18$test_result_scale = $parser->get_test_result_scale();19$test_result_units = $parser->get_test_result_units();20$test_result_precision = $parser->get_test_result_precision();21$test_result_display_format = $parser->get_test_result_display_format();22$test_result_buffer_size = $parser->get_test_result_buffer_size();23$test_result_buffer_type = $parser->get_test_result_buffer_type();24$test_result_buffer_mode = $parser->get_test_result_buffer_mode();25$test_result_buffer = $parser->get_test_result_buffer();26$test_result_buffer_min = $parser->get_test_result_buffer_min();27$test_result_buffer_max = $parser->get_test_result_buffer_max();28$test_result_buffer_mean = $parser->get_test_result_buffer_mean();
gen_result_active_handle
Using AI Code Generation
1$active_handle = pts_test_result_parser::gen_result_active_handle('test_result_file');2$result_object = pts_test_result_parser::get_result_object($active_handle);3$result_file_version = pts_test_result_parser::get_result_file_version($active_handle);4$result_file_title = pts_test_result_parser::get_result_file_title($active_handle);5$result_file_description = pts_test_result_parser::get_result_file_description($active_handle);6$result_file_app_version = pts_test_result_parser::get_result_file_app_version($active_handle);7$test_profile = pts_test_result_parser::get_result_file_app_version($active_handle);8$test_profile = pts_test_result_parser::get_result_file_app_version($active_handle);9$test_profile = pts_test_result_parser::get_result_file_app_version($active_handle);10$test_profile = pts_test_result_parser::get_result_file_app_version($active_handle);11$test_profile = pts_test_result_parser::get_result_file_app_version($active_handle);
gen_result_active_handle
Using AI Code Generation
1$handle=pts_test_result_parser::gen_result_active_handle($result_file);2$result_array=pts_test_result_parser::parse_result_file($handle);3$test_profile=pts_test_result_parser::parse_result_profile($handle);4$test_title=pts_test_result_parser::parse_result_title($handle);5$test_version=pts_test_result_parser::parse_result_version($handle);6$test_arguments=pts_test_result_parser::parse_result_arguments($handle);7$test_environment=pts_test_result_parser::parse_result_environment($handle);8$test_description=pts_test_result_parser::parse_result_description($handle);9$test_timestamp=pts_test_result_parser::parse_result_timestamp($handle);10$test_result_scale=pts_test_result_parser::parse_result_scale($handle);11$test_result_data=pts_test_result_parser::parse_result_data($handle);12$test_result_data_obj=pts_test_result_parser::parse_result_data_object($handle);13$test_result_data_obj=pts_test_result_parser::parse_result_data_object($handle);14$test_result_data_obj=pts_test_result_parser::parse_result_data_object($handle);15$test_result_data_obj=pts_test_result_parser::parse_result_data_object($handle);16$test_result_data_obj=pts_test_result_parser::parse_result_data_object($handle);17$test_result_data_obj=pts_test_result_parser::parse_result_data_object($handle
gen_result_active_handle
Using AI Code Generation
1$result = pts_test_result_parser::gen_result_active_handle();2$result = pts_test_result_parser::gen_result_active_handle($test_profile_name, $test_identifier);3$result = pts_test_result_parser::gen_result_active_handle($test_profile_name, $test_identifier, $test_result_file);4$result = pts_test_result_parser::gen_result_active_handle($test_profile_name, $test_identifier, $test_result_file, $test_result_index);5$result = pts_test_result_parser::gen_result_active_handle($test_profile_name, $test_identifier, $test_result_file, $test_result_index, $test_result_index);6$result = pts_test_result_parser::gen_result_active_handle($test_profile_name, $test_identifier, $test_result_file, $test_result_index, $test_result_index, $test_result_index);7$result = pts_test_result_parser::gen_result_active_handle($test_profile_name, $test_identifier, $test_result_file, $test_result_index, $test_result_index, $
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 gen_result_active_handle 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!!