Best Phoronix-test-suite code snippet using pts_result_file.get_result_dir
pts_result_file.php
Source:pts_result_file.php
...137 {138 return PTS_SAVE_RESULTS_PATH . $this->save_identifier . '/composite.xml';139 }140 }141 public function get_result_dir()142 {143 $composite_xml_dir = dirname($this->get_file_location());144 return empty($composite_xml_dir) || !is_dir($composite_xml_dir) ? false : $composite_xml_dir . '/';145 }146 public function get_system_log_dir($result_identifier = null, $dir_check = true)147 {148 $log_dir = dirname($this->get_file_location());149 if(empty($log_dir) || !is_dir($log_dir))150 {151 return false;152 }153 $sdir = $log_dir . '/system-logs/';154 if($result_identifier == null)155 {156 return $sdir;157 }158 else159 {160 $sdir = $sdir . pts_strings::simplify_string_for_file_handling($result_identifier) . '/';161 return !$dir_check || is_dir($sdir) ? $sdir : false;162 }163 }164 public function get_test_log_dir(&$result_object = null)165 {166 $log_dir = !empty($this->get_file_location()) ? dirname($this->get_file_location()) : '';167 if(empty($log_dir) || !is_dir($log_dir))168 {169 return false;170 }171 return $log_dir . '/test-logs/' . ($result_object != null ? $result_object->get_comparison_hash(true, false) . '/' : null);172 }173 public function get_test_installation_log_dir()174 {175 $log_dir = dirname($this->get_file_location());176 if(empty($log_dir) || !is_dir($log_dir))177 {178 return false;179 }180 return $log_dir . '/installation-logs/';181 }182 public function save()183 {184 if($this->get_file_location() && is_file($this->get_file_location()))185 {186 return file_put_contents($this->get_file_location(), $this->get_xml());187 }188 }189 public function get_last_modified()190 {191 return $this->last_modified;192 }193 public function validate()194 {195 $dom = new DOMDocument();196 $dom->loadXML($this->get_xml());197 return $dom->schemaValidate(pts_openbenchmarking::openbenchmarking_standards_path() . 'schemas/result-file.xsd');198 }199 public function __toString()200 {201 return $this->get_identifier();202 }203 protected static function clean_input($value)204 {205 return strip_tags($value);206 /*207 if(is_array($value))208 {209 return array_map(array($this, 'clean_input'), $value);210 }211 else212 {213 return strip_tags($value);214 }215 */216 }217 public function get_identifier()218 {219 return $this->save_identifier;220 }221 public function add_system($system)222 {223 if(!in_array($system, $this->systems))224 {225 $this->systems[] = $system;226 }227 }228 public function get_systems()229 {230 return $this->systems;231 }232 public function get_system_hardware()233 {234 // XXX this is deprecated235 $hw = array();236 foreach($this->systems as &$s)237 {238 $hw[] = $s->get_hardware();239 }240 return $hw;241 }242 public function get_system_software()243 {244 // XXX this is deprecated245 $sw = array();246 foreach($this->systems as &$s)247 {248 $sw[] = $s->get_software();249 }250 return $sw;251 }252 public function get_system_identifiers()253 {254 // XXX this is deprecated255 $ids = array();256 foreach($this->systems as &$s)257 {258 $ids[] = $s->get_identifier();259 }260 return $ids;261 }262 public function get_system_identifiers_by_date()263 {264 $by_date = array();265 foreach($this->get_systems() as $s)266 {267 $by_date[$s->get_identifier()] = strtotime($s->get_timestamp());268 }269 asort($by_date);270 return array_keys($by_date);271 }272 public function is_system_identifier_in_result_file($identifier)273 {274 foreach($this->systems as &$s)275 {276 if($s->get_identifier() == $identifier)277 {278 return true;279 }280 }281 return false;282 }283 public function system_logs_available()284 {285 $has_system_logs = false;286 $system_log_dir_or_zip = is_dir($this->get_system_log_dir(null, true)) || is_file($this->get_result_dir() . 'system-logs.zip');287 if($system_log_dir_or_zip)288 {289 if($this->get_system_count() == 1)290 {291 // If just one system in result file and there is a log, safe to assume it's for the associated run...292 $has_system_logs = true;293 }294 else295 {296 foreach($this->systems as &$s)297 {298 if($s->has_log_files())299 {300 $has_system_logs = true;301 break;302 }303 }304 }305 }306 return $has_system_logs;307 }308 public function identifiers_with_system_logs()309 {310 $identifiers = array();311 $system_log_dir = $this->get_system_log_dir(null, true);312 if($system_log_dir && is_dir($system_log_dir))313 {314 foreach(pts_file_io::glob($system_log_dir . '/*') as $identifier_dir)315 {316 $identifiers[] = basename($identifier_dir);317 }318 }319 else if($this->get_result_dir() && is_file($this->get_result_dir() . 'system-logs.zip'))320 {321 $zip = new ZipArchive();322 $res = $zip->open($this->get_result_dir() . 'system-logs.zip');323 if($res === true)324 {325 for($i = 0; $i < $zip->numFiles; $i++)326 {327 $index = explode('/', $zip->getNameIndex($i));328 if(!empty($index[1]) && !in_array($index[1], $identifiers))329 {330 $identifiers[] = $index[1];331 }332 }333 $zip->close();334 }335 }336 return $identifiers;337 }338 public function get_system_count()339 {340 return count($this->systems);341 }342 public function set_title($new_title)343 {344 if($new_title != null)345 {346 $this->title = $new_title;347 }348 }349 public function get_title()350 {351 return $this->title;352 }353 public function append_description($append_description)354 {355 if($append_description != null && strpos($this->description, $append_description) === false)356 {357 $this->description .= PHP_EOL . $append_description;358 }359 }360 public function set_description($new_description)361 {362 if($new_description != null)363 {364 $this->description = $new_description;365 }366 }367 public function get_description()368 {369 return $this->description;370 }371 public function set_notes($notes)372 {373 if($notes != null)374 {375 $this->notes = $notes;376 }377 }378 public function get_notes()379 {380 return $this->notes;381 }382 public function set_internal_tags($tags)383 {384 if($tags != null)385 {386 $this->internal_tags = $tags;387 }388 }389 public function get_internal_tags()390 {391 return $this->internal_tags;392 }393 public function set_reference_id($new_reference_id)394 {395 if($new_reference_id != null)396 {397 $this->reference_id = $new_reference_id;398 }399 }400 public function get_reference_id()401 {402 return $this->reference_id;403 }404 public function set_preset_environment_variables($env)405 {406 if($env != null)407 {408 $this->preset_environment_variables = $env;409 }410 }411 public function get_preset_environment_variables()412 {413 return $this->preset_environment_variables;414 }415 public function get_test_count()416 {417 return count($this->get_result_objects());418 }419 public function get_qualified_test_count()420 {421 $q_count = 0;422 foreach($this->get_result_objects() as $ro)423 {424 if($ro->test_profile->get_identifier() != null)425 {426 $q_count++;427 }428 }429 return $q_count;430 }431 public function has_matching_test_and_run_identifier(&$test_result, $run_identifier_to_check)432 {433 $found_match = false;434 $hash_to_check = $test_result->get_comparison_hash();435 foreach($this->get_result_objects() as $result_object)436 {437 if($hash_to_check == $result_object->get_comparison_hash())438 {439 if(in_array($run_identifier_to_check, $result_object->test_result_buffer->get_identifiers()) && $result_object->test_result_buffer->get_result_from_identifier($run_identifier_to_check) != '')440 {441 $found_match = true;442 }443 break;444 }445 }446 return $found_match;447 }448 public function get_contained_tests_hash($raw_output = true)449 {450 $result_object_hashes = $this->get_result_object_hashes();451 sort($result_object_hashes);452 return sha1(implode(',', $result_object_hashes), $raw_output);453 }454 public function get_result_object_hashes()455 {456 $object_hashes = array();457 foreach($this->get_result_objects() as $result_object)458 {459 $object_hashes[] = $result_object->get_comparison_hash();460 }461 return $object_hashes;462 }463 public function is_results_tracker()464 {465 // If there are more than five results and the only changes in the system identifier names are numeric changes, assume it's a tracker466 // i.e. different dates or different versions of a package being tested467 if($this->is_tracker === -1)468 {469 $identifiers = $this->get_system_identifiers();470 if(isset($identifiers[5]))471 {472 // dirty SHA1 hash check473 $is_sha1_hash = strlen($identifiers[0]) == 40 && strpos($identifiers[0], ' ') === false;474 $has_sha1_shorthash = false;475 foreach($identifiers as $i => &$identifier)476 {477 $has_sha1_shorthash = ($i == 0 || $has_sha1_shorthash) && isset($identifier[7]) && pts_strings::string_only_contains(substr($identifier, -8), pts_strings::CHAR_NUMERIC | pts_strings::CHAR_LETTER) && strpos($identifier, ' ') === false;478 $identifier = pts_strings::remove_from_string($identifier, pts_strings::CHAR_NUMERIC | pts_strings::CHAR_DASH | pts_strings::CHAR_DECIMAL);479 }480 $this->is_tracker = count(array_unique($identifiers)) <= 1 || $is_sha1_hash || $has_sha1_shorthash;481 if($this->is_tracker)482 {483 $hw = $this->get_system_hardware();484 if(isset($hw[1]) && count($hw) == count(array_unique($hw)))485 {486 // it can't be a results tracker if the hardware is always different487 $this->is_tracker = false;488 }489 }490 if($this->is_tracker == false)491 {492 // See if only numbers are changing between runs493 foreach($identifiers as $i => &$identifier)494 {495 if(($x = strpos($identifier, ': ')) !== false)496 {497 $identifier = substr($identifier, ($x + 2));498 }499 if($i > 0 && pts_strings::remove_from_string($identifier, pts_strings::CHAR_NUMERIC | pts_strings::CHAR_DECIMAL) != pts_strings::remove_from_string($identifiers[($i - 1)], pts_strings::CHAR_NUMERIC | pts_strings::CHAR_DECIMAL))500 {501 return false;502 }503 }504 $this->is_tracker = true;505 }506 }507 else508 {509 // Definitely not a tracker as not over 5 results510 $this->is_tracker = false;511 }512 }513 return $this->is_tracker;514 }515 public function is_multi_way_comparison($identifiers = false, $extra_attributes = null)516 {517 if(isset($extra_attributes['force_tracking_line_graph']))518 {519 // Phoromatic result tracker520 $is_multi_way = true;521 $this->is_multi_way_inverted = true;522 }523 else524 {525 $hw = null; // XXX: this isn't used anymore at least for now on system hardware526 if($identifiers == false)527 {528 $identifiers = $this->get_system_identifiers();529 }530 $is_multi_way = count($identifiers) < 2 ? false : pts_render::multi_way_identifier_check($identifiers, $hw, $this);531 $this->is_multi_way_inverted = $is_multi_way && $is_multi_way[1];532 }533 return $is_multi_way;534 }535 public function is_multi_way_inverted()536 {537 return $this->is_multi_way_inverted;538 }539 public function get_contained_test_profiles($unique = false)540 {541 $test_profiles = array();542 foreach($this->get_result_objects() as $object)543 {544 $test_profiles[] = $object->test_profile;545 }546 if($unique)547 {548 $test_profiles = array_unique($test_profiles);549 }550 return $test_profiles;551 }552 public function override_result_objects($result_objects)553 {554 $this->result_objects = $result_objects;555 }556 public function get_result($ch)557 {558 return isset($this->result_objects[$ch]) ? $this->result_objects[$ch] : false;559 }560 public function remove_result_object_by_id($index_or_indexes, $delete_child_objects = true)561 {562 $did_remove = false;563 foreach(pts_arrays::to_array($index_or_indexes) as $index)564 {565 if(isset($this->result_objects[$index]))566 {567 unset($this->result_objects[$index]);568 $did_remove = true;569 if($delete_child_objects)570 {571 foreach($this->get_relation_map($index) as $child_ro)572 {573 if(isset($this->result_objects[$child_ro]))574 {575 unset($this->result_objects[$child_ro]);576 }577 }578 }579 }580 }581 return $did_remove;582 }583 public function remove_noisy_results($noise_level_percent = 6)584 {585 foreach($this->result_objects as $i => &$ro)586 {587 if($ro->has_noisy_result($noise_level_percent))588 {589 $this->remove_result_object_by_id($i);590 }591 }592 }593 public function reduce_precision()594 {595 foreach($this->result_objects as $i => &$ro)596 {597 $ro->test_result_buffer->reduce_precision();598 }599 }600 public function update_annotation_for_result_object_by_id($index, $annotation)601 {602 if(isset($this->result_objects[$index]))603 {604 $this->result_objects[$index]->set_annotation($annotation);605 return true;606 }607 return false;608 }609 public function get_result_object_by_hash($h)610 {611 return isset($this->result_objects[$h]) ? $this->result_objects[$h] : false;612 }613 public function get_result_objects($select_indexes = -1)614 {615 if($select_indexes != -1 && $select_indexes !== null)616 {617 $objects = array();618 if($select_indexes == 'ONLY_CHANGED_RESULTS')619 {620 foreach($this->result_objects as &$result)621 {622 // Only show results where the variation was greater than or equal to 1%623 if(abs($result->largest_result_variation(0.01)) >= 0.01)624 {625 $objects[] = $result;626 }627 }628 }629 else630 {631 foreach(pts_arrays::to_array($select_indexes) as $index)632 {633 if(isset($this->result_objects[$index]))634 {635 $objects[] = $this->result_objects[$index];636 }637 }638 }639 return $objects;640 }641 $skip_objects = defined('SKIP_RESULT_OBJECTS') ? explode(',', SKIP_RESULT_OBJECTS) : false;642 if($skip_objects)643 {644 $ros = $this->result_objects;645 foreach($ros as $index => $ro)646 {647 foreach($skip_objects as $skip)648 {649 if(stripos($ro->test_profile->get_identifier(), $skip) !== false || stripos($ro->get_arguments_description(), $skip) !== false)650 {651 unset($ros[$index]);652 break;653 }654 }655 }656 return $ros;657 }658 return $this->result_objects;659 }660 public function to_json()661 {662 $file = $this->get_xml();663 $file = str_replace(array("\n", "\r", "\t"), '', $file);664 $file = trim(str_replace('"', "'", $file));665 $simple_xml = simplexml_load_string($file);666 return json_encode($simple_xml);667 }668 public function avoid_duplicate_identifiers()669 {670 // avoid duplicate test identifiers671 $identifiers = $this->get_system_identifiers();672 if(count($identifiers) < 2)673 {674 return;675 }676 foreach(pts_arrays::duplicates_in_array($identifiers) as $duplicate)677 {678 while($this->is_system_identifier_in_result_file($duplicate))679 {680 $i = 0;681 do682 {683 $i++;684 $new_identifier = $duplicate . ' #' . $i;685 }686 while($this->is_system_identifier_in_result_file($new_identifier));687 $this->rename_run($duplicate, $new_identifier, false);688 }689 }690 }691 public function rename_run($from, $to, $rename_logs = true)692 {693 $renamed = false;694 if($from == 'PREFIX')695 {696 foreach($this->systems as &$s)697 {698 $s->set_identifier($to . ': ' . $s->get_identifier());699 $renamed = true;700 }701 }702 else if($from == null)703 {704 if(count($this->systems) == 1)705 {706 foreach($this->systems as &$s)707 {708 $s->set_identifier($to);709 $renamed = true;710 break;711 }712 }713 }714 else715 {716 $found = false;717 foreach($this->systems as &$s)718 {719 if($s->get_identifier() == $from)720 {721 $found = true;722 $s->set_identifier($to);723 $renamed = true;724 break;725 }726 }727 if($found && $rename_logs && ($d = $this->get_system_log_dir($from, true)))728 {729 $d = dirname(dirname($d)) . '/';730 foreach(array('test-logs', 'system-logs', 'installation-logs') as $dir_name)731 {732 if(is_dir($d . $dir_name . '/' . $from))733 {734 rename($d . $dir_name . '/' . $from, $d . $dir_name . '/' . $to);735 }736 }737 }738 }739 foreach($this->result_objects as &$result)740 {741 $result->test_result_buffer->rename($from, $to);742 }743 return $renamed;744 }745 public function reorder_runs($new_order)746 {747 foreach($new_order as $identifier)748 {749 foreach($this->systems as $i => $s)750 {751 if($s->get_identifier() == $identifier)752 {753 $c = $s;754 unset($this->systems[$i]);755 $this->systems[] = $c;756 break;757 }758 }759 }760 foreach($this->result_objects as &$result)761 {762 $result->test_result_buffer->reorder($new_order);763 }764 }765 public function remove_run($remove)766 {767 $did_remove = false;768 $remove = pts_arrays::to_array($remove);769 foreach($this->systems as $i => &$s)770 {771 if(in_array($s->get_identifier(), $remove))772 {773 unset($this->systems[$i]);774 $did_remove = true;775 }776 }777 foreach($this->result_objects as &$result)778 {779 $result->test_result_buffer->remove($remove);780 }781 return $did_remove;782 }783 public function add_to_result_file(&$result_file, $only_merge_results_already_present = false)784 {785 foreach($result_file->get_systems() as $s)786 {787 if(!in_array($s, $this->systems))788 {789 $this->systems[] = $s;790 }791 }792 foreach($result_file->get_result_objects() as $result)793 {794 $this->add_result($result, $only_merge_results_already_present);795 }796 }797 public function result_hash_exists(&$result_object)798 {799 $ch = $result_object->get_comparison_hash(true, false);800 return isset($this->result_objects[$ch]) && isset($this->result_objects[$ch]->test_result_buffer);801 }802 public function add_result(&$result_object, $only_if_result_already_present = false)803 {804 if($result_object == null)805 {806 return false;807 }808 $ch = $result_object->get_comparison_hash(true, false);809 if(isset($this->result_objects[$ch]) && isset($this->result_objects[$ch]->test_result_buffer))810 {811 if($result_object->get_annotation() != null)812 {813 $this->result_objects[$ch]->append_annotation($result_object->get_annotation());814 }815 foreach($result_object->test_result_buffer->get_buffer_items() as $bi)816 {817 if($bi->get_result_value() === null)818 {819 continue;820 }821 $this->result_objects[$ch]->test_result_buffer->add_buffer_item($bi);822 }823 }824 else if($only_if_result_already_present == false)825 {826 $this->result_objects[$ch] = $result_object;827 }828 $parent = $result_object->get_parent_hash();829 if($parent)830 {831 if(!isset($this->ro_relation_map[$parent]))832 {833 $this->ro_relation_map[$parent] = array();834 }835 $this->ro_relation_map[$parent][] = $ch;836 }837 return $ch;838 }839 public function add_result_return_object(&$result_object, $only_if_result_already_present = false)840 {841 $ch = $this->add_result($result_object, $only_if_result_already_present);842 return isset($this->result_objects[$ch]) ? $this->result_objects[$ch] : false;843 }844 public function get_xml($to = null, $force_nice_formatting = false)845 {846 $xml_writer = new nye_XmlWriter(null, $force_nice_formatting);847 $xml_writer->addXmlNode('PhoronixTestSuite/Generated/Title', $this->get_title());848 $xml_writer->addXmlNode('PhoronixTestSuite/Generated/LastModified', date('Y-m-d H:i:s', pts_client::current_time()));849 $xml_writer->addXmlNode('PhoronixTestSuite/Generated/TestClient', pts_core::program_title());850 $xml_writer->addXmlNode('PhoronixTestSuite/Generated/Description', $this->get_description());851 $xml_writer->addXmlNodeWNE('PhoronixTestSuite/Generated/Notes', $this->get_notes());852 $xml_writer->addXmlNodeWNE('PhoronixTestSuite/Generated/InternalTags', $this->get_internal_tags());853 $xml_writer->addXmlNodeWNE('PhoronixTestSuite/Generated/ReferenceID', $this->get_reference_id());854 $xml_writer->addXmlNodeWNE('PhoronixTestSuite/Generated/PreSetEnvironmentVariables', $this->get_preset_environment_variables());855 // Write the system hardware/software information856 foreach($this->get_systems() as $s)857 {858 $xml_writer->addXmlNode('PhoronixTestSuite/System/Identifier', $s->get_identifier());859 $xml_writer->addXmlNode('PhoronixTestSuite/System/Hardware', $s->get_hardware());860 $xml_writer->addXmlNode('PhoronixTestSuite/System/Software', $s->get_software());861 $xml_writer->addXmlNode('PhoronixTestSuite/System/User', $s->get_username());862 $xml_writer->addXmlNode('PhoronixTestSuite/System/TimeStamp', $s->get_timestamp());863 $xml_writer->addXmlNode('PhoronixTestSuite/System/TestClientVersion', $s->get_client_version());864 $xml_writer->addXmlNode('PhoronixTestSuite/System/Notes', $s->get_notes());865 if(!defined('USER_PTS_CORE_VERSION') || USER_PTS_CORE_VERSION > 3722)866 {867 // Ensure that a supported result file schema is being written...868 // USER_PTS_CORE_VERSION is set by OpenBenchmarking.org so if the requested client is old, don't write this data to send back to their version869 $xml_writer->addXmlNodeWNE('PhoronixTestSuite/System/JSON', ($s->get_json() ? json_encode($s->get_json()) : null));870 }871 }872 // Write the results873 foreach($this->get_result_objects() as $result_object)874 {875 $buffer_items = $result_object->test_result_buffer->get_buffer_items();876 if(count($buffer_items) == 0)877 {878 continue;879 }880 $xml_writer->addXmlNode('PhoronixTestSuite/Result/Identifier', $result_object->test_profile->get_identifier());881 $xml_writer->addXmlNode('PhoronixTestSuite/Result/Title', $result_object->test_profile->get_title());882 $xml_writer->addXmlNode('PhoronixTestSuite/Result/AppVersion', $result_object->test_profile->get_app_version());883 $xml_writer->addXmlNode('PhoronixTestSuite/Result/Arguments', $result_object->get_arguments());884 $xml_writer->addXmlNode('PhoronixTestSuite/Result/Description', $result_object->get_arguments_description());885 $xml_writer->addXmlNode('PhoronixTestSuite/Result/Scale', $result_object->test_profile->get_result_scale());886 $xml_writer->addXmlNode('PhoronixTestSuite/Result/Proportion', $result_object->test_profile->get_result_proportion());887 $xml_writer->addXmlNode('PhoronixTestSuite/Result/DisplayFormat', $result_object->test_profile->get_display_format());888 $xml_writer->addXmlNodeWNE('PhoronixTestSuite/Result/Annotation', $result_object->get_annotation());889 $xml_writer->addXmlNodeWNE('PhoronixTestSuite/Result/Parent', $result_object->get_parent_hash());890 foreach($buffer_items as $i => &$buffer_item)891 {892 $xml_writer->addXmlNode('PhoronixTestSuite/Result/Data/Entry/Identifier', $buffer_item->get_result_identifier());893 $xml_writer->addXmlNode('PhoronixTestSuite/Result/Data/Entry/Value', $buffer_item->get_result_value());894 $xml_writer->addXmlNode('PhoronixTestSuite/Result/Data/Entry/RawString', $buffer_item->get_result_raw());895 if(!defined('USER_PTS_CORE_VERSION') || USER_PTS_CORE_VERSION > 3722)896 {897 // Ensure that a supported result file schema is being written...898 // USER_PTS_CORE_VERSION is set by OpenBenchmarking.org so if the requested client is old, don't write this data to send back to their version899 $xml_writer->addXmlNodeWNE('PhoronixTestSuite/Result/Data/Entry/JSON', ($buffer_item->get_result_json() ? json_encode($buffer_item->get_result_json()) : null));900 }901 }902 }903 return $to == null ? $xml_writer->getXML() : $xml_writer->saveXMLFile($to);904 }905 public function merge($result_merges_to_combine, $pass_attributes = 0, $add_prefix = null, $merge_meta = false, $only_prefix_on_collision = false)906 {907 if(!is_array($result_merges_to_combine) || empty($result_merges_to_combine))908 {909 return false;910 }911 foreach($result_merges_to_combine as &$result_file)912 {913 if(!($result_file instanceof pts_result_file))914 {915 if(defined('PTS_SAVE_RESULTS_PATH') && is_file(PTS_SAVE_RESULTS_PATH . $result_file . '/composite.xml'))916 {917 $result_file = new pts_result_file(PTS_SAVE_RESULTS_PATH . $result_file . '/composite.xml', true);918 }919 else920 {921 continue;922 }923 }924 if($add_prefix)925 {926 if($only_prefix_on_collision)927 {928 $this_identifiers = $this->get_system_identifiers();929 foreach($result_file->systems as &$s)930 {931 if(in_array($s->get_identifier(), $this_identifiers))932 {933 $s->set_identifier($add_prefix . ': ' . $s->get_identifier());934 }935 }936 }937 else938 {939 $result_file->rename_run('PREFIX', $add_prefix);940 }941 }942 if($this->get_title() == null && $result_file->get_title() != null)943 {944 $this->set_title($result_file->get_title());945 }946 if($this->get_description() == null && $result_file->get_description() != null)947 {948 $this->set_description($result_file->get_description());949 }950 $this->add_to_result_file($result_file);951 if($merge_meta)952 {953 if($result_file->get_title() != null && stripos($this->get_title(), $result_file->get_title()) === false)954 {955 $this->set_title($this->get_title() . ', ' . $result_file->get_title());956 }957 if($result_file->get_description() != null && stripos($this->get_description(), $result_file->get_description()) === false)958 {959 $this->set_description($this->get_description() . PHP_EOL . PHP_EOL . $result_file->get_title() . ': ' . $result_file->get_description());960 }961 }962 unset($result_file);963 }964 }965 public function contains_system_hardware($search)966 {967 foreach($this->get_system_hardware() as $h)968 {969 if(stripos($h, $search) !== false)970 {971 return true;972 }973 }974 return false;975 }976 public function contains_system_software($search)977 {978 foreach($this->get_system_software() as $s)979 {980 if(stripos($s, $search) !== false)981 {982 return true;983 }984 }985 return false;986 }987 public function contains_test($search)988 {989 foreach($this->get_contained_test_profiles() as $test_profile)990 {991 if(stripos($test_profile->get_identifier(), $search) !== false || stripos($test_profile->get_title(), $search) !== false)992 {993 return true;994 }995 }996 return false;997 }998 public function sort_result_object_order_by_spread($asc = false)999 {1000 uasort($this->result_objects, array('pts_result_file', 'result_spread_comparison'));1001 if($asc == false)1002 {1003 $this->result_objects = array_reverse($this->result_objects, true);1004 }1005 }1006 public static function result_spread_comparison($a, $b)1007 {1008 return strcmp($a->get_spread(), $b->get_spread());1009 }1010 public function sort_result_object_order_by_title($asc = true)1011 {1012 uasort($this->result_objects, array('pts_result_file', 'result_title_comparison'));1013 if($asc == false)1014 {1015 $this->result_objects = array_reverse($this->result_objects, true);1016 }1017 }1018 public static function result_title_comparison($a, $b)1019 {1020 return strcmp(strtolower($a->test_profile->get_title()) . ' ' . $a->test_profile->get_app_version(), strtolower($b->test_profile->get_title()) . ' ' . $b->test_profile->get_app_version());1021 }1022 public function sort_result_object_order_by_result_scale($asc = true)1023 {1024 uasort($this->result_objects, array('pts_result_file', 'result_scale_comparison'));1025 if($asc == false)1026 {1027 $this->result_objects = array_reverse($this->result_objects, true);1028 }1029 }1030 public static function result_scale_comparison($a, $b)1031 {1032 return strcmp($a->test_profile->get_result_proportion() . ' ' . strtolower($a->test_profile->get_result_scale()) . ' ' . $a->test_profile->get_identifier(), $b->test_profile->get_result_proportion() . ' ' . strtolower($b->test_profile->get_result_scale()) . ' ' . $a->test_profile->get_identifier());1033 }1034 public function get_test_run_times()1035 {1036 $run_times = array();1037 foreach($this->get_system_identifiers() as $si)1038 {1039 $run_times[$si] = 0;1040 }1041 foreach($this->result_objects as &$ro)1042 {1043 foreach($ro->get_run_times() as $si => $elapsed_time)1044 {1045 $run_times[$si] += $elapsed_time;1046 }1047 }1048 return $run_times;1049 }1050 public function sort_result_object_order_by_run_time($asc = false)1051 {1052 uasort($this->result_objects, array('pts_result_file', 'result_run_time_comparison'));1053 if($asc == false)1054 {1055 $this->result_objects = array_reverse($this->result_objects, true);1056 }1057 }1058 public static function result_run_time_comparison($a, $b)1059 {1060 $a = $a->get_run_time_avg();1061 $b = $b->get_run_time_avg();1062 if($a == $b)1063 {1064 return 0;1065 }1066 return $a < $b ? -1 : 1;1067 }1068 public function get_install_log_for_test(&$test_profile, $read_file = false, $cleanse_file = true)1069 {1070 // if $read_file is false, index will be returned. if $read_file is -2, will return whether log files simply exist1071 $files = array();1072 static $logs_exist_for_test; // caching helper1073 $test_file_name_chunk = $test_profile->get_identifier_simplified() . '.log';1074 if($read_file == -2 && isset($logs_exist_for_test[$test_file_name_chunk]))1075 {1076 return $logs_exist_for_test[$test_file_name_chunk];1077 }1078 if($this->get_test_installation_log_dir() && count($d = pts_file_io::glob($this->get_test_installation_log_dir() . '*/' . $test_file_name_chunk)) > 0)1079 {1080 $logs_exist_for_test[$test_file_name_chunk] = true;1081 if($read_file == -2)1082 {1083 return true;1084 }1085 foreach($d as $file)1086 {1087 $basename_file = basename(dirname($file));1088 if($read_file !== false && $basename_file == $read_file)1089 {1090 $file = file_get_contents($file);1091 return $cleanse_file ? phodevi_vfs::cleanse_file($file, $basename_file) : $file;1092 }1093 $files[] = $basename_file;1094 }1095 }1096 else if($this->get_result_dir() && is_file($this->get_result_dir() . 'installation-logs.zip') && extension_loaded('zip'))1097 {1098 $logs_exist_for_test[$test_file_name_chunk] = true;1099 if($read_file == -2)1100 {1101 // TODO: could make this more accurate to ensure a precise match, but could become expensive1102 return true;1103 }1104 $zip = new ZipArchive();1105 $res = $zip->open($this->get_result_dir() . 'installation-logs.zip');1106 if($res === true)1107 {1108 $search_for_file_name_length = strlen($test_file_name_chunk);1109 for($i = 0; $i < $zip->numFiles; $i++)1110 {1111 $index = $zip->getNameIndex($i);1112 if(isset($index[$search_for_file_name_length]) && substr($index, (0 - $search_for_file_name_length)) == $test_file_name_chunk)1113 {1114 $basename_file = basename(dirname($index));1115 if($basename_file != null)1116 {1117 if($read_file !== false && $basename_file == $read_file)1118 {1119 $c = $zip->getFromName($index);1120 $contents = $cleanse_file ? phodevi_vfs::cleanse_file($c, $basename_file) : $c;1121 $zip->close();1122 return $contents;1123 }1124 $files[] = $basename_file;1125 }1126 }1127 }1128 $zip->close();1129 }1130 }1131 $logs_exist_for_test[$test_file_name_chunk] = !empty($files);1132 if($read_file == -2)1133 {1134 return false;1135 }1136 return $read_file !== false ? false : $files;1137 }1138 public function get_test_run_log_for_result(&$result_object, $read_file = false, $cleanse_file = true)1139 {1140 // if $read_file is false, index will be returned. if $read_file is -2, will return whether log files simply exist1141 $files = array();1142 static $logs_exist_for_test; // caching helper1143 $ro_hash = $result_object->get_comparison_hash(true, false);1144 if($read_file == -2 && isset($logs_exist_for_test[$ro_hash]))1145 {1146 return $logs_exist_for_test[$ro_hash];1147 }1148 if(($test_log_dir = $this->get_test_log_dir($result_object)) && count($d = pts_file_io::glob($test_log_dir . '*.log')) > 0)1149 {1150 $logs_exist_for_test[$ro_hash] = true;1151 if($read_file == -2)1152 {1153 return true;1154 }1155 foreach($d as $file)1156 {1157 $basename_file = basename($file);1158 if($read_file !== false && $basename_file == $read_file)1159 {1160 $file = file_get_contents($file);1161 return $cleanse_file ? phodevi_vfs::cleanse_file($file, $basename_file) : $file;1162 }1163 $files[] = $basename_file;1164 }1165 }1166 else if($this->get_result_dir() && is_file($this->get_result_dir() . 'test-logs.zip') && extension_loaded('zip'))1167 {1168 $logs_exist_for_test[$ro_hash] = true;1169 if($read_file == -2)1170 {1171 // TODO: could make this more accurate to ensure a precise match, but could become expensive1172 return true;1173 }1174 $zip = new ZipArchive();1175 $res = $zip->open($this->get_result_dir() . 'test-logs.zip');1176 if($res === true)1177 {1178 $log_path = 'test-logs/' . $ro_hash . '/';1179 $log_path_l = strlen($log_path);1180 for($i = 0; $i < $zip->numFiles; $i++)1181 {1182 $index = $zip->getNameIndex($i);1183 if(isset($index[$log_path_l]) && substr($index, 0, $log_path_l) == $log_path)1184 {1185 $basename_file = substr($index, $log_path_l);1186 if($basename_file != null)1187 {1188 if($read_file !== false && $basename_file == $read_file)1189 {...
get_result_dir
Using AI Code Generation
1require_once('pts_result_file.php');2$result_file = new pts_result_file();3$dir = $result_file->get_result_dir();4echo $dir;5require_once('pts_result_file.php');6$result_file = new pts_result_file();7$dir = $result_file->get_result_dir();8echo $dir;9require_once('pts_result_file.php');10$result_file = new pts_result_file();11$dir = $result_file->get_result_dir();12echo $dir;13require_once('pts_result_file.php');14$result_file = new pts_result_file();15$dir = $result_file->get_result_dir();16echo $dir;17require_once('pts_result_file.php');18$result_file = new pts_result_file();19$dir = $result_file->get_result_dir();20echo $dir;21require_once('pts_result_file.php');22$result_file = new pts_result_file();23$dir = $result_file->get_result_dir();24echo $dir;25require_once('pts_result_file.php');26$result_file = new pts_result_file();27$dir = $result_file->get_result_dir();28echo $dir;29require_once('pts_result_file.php');30$result_file = new pts_result_file();31$dir = $result_file->get_result_dir();32echo $dir;33require_once('pts_result_file.php');34$result_file = new pts_result_file();35$dir = $result_file->get_result_dir();36echo $dir;37require_once('pts_result_file.php');38$result_file = new pts_result_file();39$dir = $result_file->get_result_dir();
get_result_dir
Using AI Code Generation
1include 'pts_result_file.php';2$rf = new pts_result_file('result_file.xml');3echo $rf->get_result_dir();4include 'pts_result_file.php';5$rf = new pts_result_file('result_file.xml');6echo $rf->get_result_dir();7include 'pts_result_file.php';8$rf = new pts_result_file('result_file.xml');9echo $rf->get_result_dir();10include 'pts_result_file.php';11$rf = new pts_result_file('result_file.xml');12echo $rf->get_result_dir();13include 'pts_result_file.php';14$rf = new pts_result_file('result_file.xml');15echo $rf->get_result_dir();16include 'pts_result_file.php';17$rf = new pts_result_file('result_file.xml');18echo $rf->get_result_dir();19include 'pts_result_file.php';20$rf = new pts_result_file('result_file.xml');21echo $rf->get_result_dir();22include 'pts_result_file.php';23$rf = new pts_result_file('result_file.xml');24echo $rf->get_result_dir();25include 'pts_result_file.php';26$rf = new pts_result_file('result_file.xml');27echo $rf->get_result_dir();28include 'pts_result_file.php';29$rf = new pts_result_file('result_file.xml');30echo $rf->get_result_dir();31include 'pts_result_file.php';32$rf = new pts_result_file('result_file.xml
get_result_dir
Using AI Code Generation
1require_once('pts-core.php');2$rf = new pts_result_file("result_file.xml");3print_r($rf->get_result_dir());4require_once('pts-core.php');5$rf = new pts_result_file("result_file.xml");6print_r($rf->get_result_dir());7require_once('pts-core.php');8$rf = new pts_result_file("result_file.xml");9print_r($rf->get_result_dir());10require_once('pts-core.php');11$rf = new pts_result_file("result_file.xml");12print_r($rf->get_result_dir());13require_once('pts-core.php');14$rf = new pts_result_file("result_file.xml");15print_r($rf->get_result_dir());16require_once('pts-core.php');17$rf = new pts_result_file("result_file.xml");18print_r($rf->get_result_dir());19require_once('pts-core.php');20$rf = new pts_result_file("result_file.xml");21print_r($rf->get_result_dir());22require_once('pts-core.php');23$rf = new pts_result_file("result_file.xml");24print_r($rf->get_result_dir());25require_once('pts-core.php');26$rf = new pts_result_file("result_file.xml");27print_r($rf->get_result_dir());28require_once('pts-core.php');29$rf = new pts_result_file("result_file.xml
get_result_dir
Using AI Code Generation
1require_once('pts-core.php');2$result_file = new pts_result_file('result_file.xml');3echo $result_file->get_result_dir();4require_once('pts-core.php');5$result_file = new pts_result_file('result_file.xml');6echo $result_file->get_result_dir();7require_once('pts-core.php');8$result_file = new pts_result_file('result_file.xml');9echo $result_file->get_result_dir();10require_once('pts-core.php');11$result_file = new pts_result_file('result_file.xml');12echo $result_file->get_result_dir();13require_once('pts-core.php');14$result_file = new pts_result_file('result_file.xml');15echo $result_file->get_result_dir();16require_once('pts-core.php');17$result_file = new pts_result_file('result_file.xml');18echo $result_file->get_result_dir();
get_result_dir
Using AI Code Generation
1require_once('pts-core.php');2$rf = new pts_result_file('result_file_name');3$result_dir = $rf->get_result_dir();4echo $result_dir;5require_once('pts-core.php');6$rf = new pts_result_file('result_file_name');7$result_file = $rf->get_result_file();8echo $result_file;9require_once('pts-core.php');10$rf = new pts_result_file('result_file_name');11$result_file_name = $rf->get_result_file_name();12echo $result_file_name;13require_once('pts-core.php');14$rf = new pts_result_file('result_file_name');15$result_file_name = $rf->get_result_file_name();16echo $result_file_name;17require_once('pts-core.php');18$rf = new pts_result_file('result_file_name');19$result_file_name = $rf->get_result_file_name();20echo $result_file_name;21require_once('pts-core.php');22$rf = new pts_result_file('result_file_name');23$result_file_name = $rf->get_result_file_name();24echo $result_file_name;25require_once('pts-core.php');26$rf = new pts_result_file('result_file_name');27$result_file_name = $rf->get_result_file_name();28echo $result_file_name;
get_result_dir
Using AI Code Generation
1require_once('pts_result_file.php');2$rf = new pts_result_file();3echo $rf->get_result_dir();4require_once('pts_result_file.php');5$rf = new pts_result_file();6echo $rf->get_result_dir();7require_once('pts_result_file.php');8$rf = new pts_result_file();9$rf->get_result_dir();10define('RESULT_DIR', 'results');11define('RESULT_DIR', 'test_results');12define('RESULT_DIR', 'results');13define('RESULT_DIR', 'test_results');14define('RESULT_DIR', 'results');15define('RESULT_DIR', 'test_results');
get_result_dir
Using AI Code Generation
1require_once('pts-core.php');2$result_file = new pts_result_file('result_file.xml');3echo $result_file->get_result_dir();4require_once('pts-core.php');5$result_file = new pts_result_file('result_file.xml');6echo $result_file->get_result_dir();7require_once('pts-core.php');8$result_file = new pts_result_file('result_file.xml');9echo $result_file->get_result_dir();10require_once('pts-core.php');11$result_file = new pts_result_file('result_file.xml');12echo $result_file->get_result_dir();13require_once('pts-core.php');14$result_file = new pts_result_file('result_file.xml');15echo $result_file->get_result_dir();16require_once('pts-core.php');17$result_file = new pts_result_file('result_file.xml');18echo $result_file->get_result_dir();
get_result_dir
Using AI Code Generation
1include_once('phoronix_test_suite.php');2$test = pts_result_file::get_result_dir('pts/test');3foreach($test as $test_result)4{5echo $test_result->get_title();6}
get_result_dir
Using AI Code Generation
1include_once('phoronix_test_suite.php');2$test = pts_result_file::get_result_dir('pts/test');3foreach($test as $test_result)4{5echo $test_result->get_title();6}
get_result_dir
Using AI Code Generation
1require_once('pts-core.php');2$result_file = new pts_result_file('result_file.xml');3echo $result_file->get_result_dir();4require_once('pts-core.php');5$result_file = new pts_result_file('result_file.xml');6echo $result_file->get_result_dir();7require_once('pts-core.php');8$result_file = new pts_result_file('result_file.xml');9echo $result_file->get_result_dir();10require_once('pts-core.php');11$result_file = new pts_result_file('result_file.xml');12echo $result_file->get_result_dir();13require_once('pts-core.php');14$result_file = new pts_result_file('result_file.xml');15echo $result_file->get_result_dir();16require_once('pts-core.php');17$result_file = new pts_result_file('result_file.xml');18echo $result_file->get_result_dir();
get_result_dir
Using AI Code Generation
1require_once('pts_result_file.php');2$rf = new pts_result_file();3echo $rf->get_result_dir();4require_once('pts_result_file.php');5$rf = new pts_result_file();6echo $rf->get_result_dir();7require_once('pts_result_file.php');8$rf = new pts_result_file();9$rf->get_result_dir();10define('RESULT_DIR', 'results');11define('RESULT_DIR', 'test_results');12define('RESULT_DIR', 'results');13define('RESULT_DIR', 'test_results');14define('RESULT_DIR', 'results');15define('RESULT_DIR', 'test_results');
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_result_dir 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!!