Best Phoronix-test-suite code snippet using pts_openbenchmarking
pts_openbenchmarking_client.php
Source:pts_openbenchmarking_client.php
...14 GNU General Public License for more details.15 You should have received a copy of the GNU General Public License16 along with this program. If not, see <http://www.gnu.org/licenses/>.17*/18class pts_openbenchmarking_client19{20 private static $openbenchmarking_account = false;21 private static $client_settings = null;22 public static function upload_test_result(&$object, $return_json_data = false, $prompts = true)23 {24 if($object instanceof pts_test_run_manager)25 {26 $result_file = new pts_result_file($object->get_file_name());27 $local_file_name = $object->get_file_name();28 $results_identifier = $object->get_results_identifier();29 }30 else if($object instanceof pts_result_file)31 {32 $result_file = &$object;33 $local_file_name = $result_file->get_identifier();34 $results_identifier = null;35 }36 // Ensure the results can be shared37 if(self::result_upload_supported($result_file) == false)38 {39 return false;40 }41 if(pts_network::internet_support_available() == false)42 {43 echo PHP_EOL . 'No network support available.' . PHP_EOL;44 return false;45 }46 $composite_xml = $result_file->get_xml();47 $system_log_dir = PTS_SAVE_RESULTS_PATH . $result_file->get_identifier() . '/system-logs/';48 $upload_system_logs = false;49 if(is_dir($system_log_dir))50 {51 if(pts_config::read_bool_config('PhoronixTestSuite/Options/OpenBenchmarking/AlwaysUploadSystemLogs', 'FALSE'))52 {53 $upload_system_logs = true;54 }55 else if(isset(self::$client_settings['UploadSystemLogsByDefault']))56 {57 $upload_system_logs = self::$client_settings['UploadSystemLogsByDefault'];58 }59 else if(is_dir($system_log_dir))60 {61 if($prompts == false)62 {63 $upload_system_logs = true;64 }65 else66 {67 $upload_system_logs = pts_user_io::prompt_bool_input('Would you like to attach the system logs (lspci, dmesg, lsusb, etc) to the test result', true, 'UPLOAD_SYSTEM_LOGS');68 }69 }70 }71 $system_logs = null;72 $system_logs_hash = null;73 if($upload_system_logs)74 {75 $is_valid_log = true;76 $finfo = function_exists('finfo_open') ? finfo_open(FILEINFO_MIME_TYPE) : false;77 foreach(pts_file_io::glob($system_log_dir . '*') as $log_dir)78 {79 if($is_valid_log == false || !is_dir($log_dir))80 {81 $is_valid_log = false;82 break;83 }84 foreach(pts_file_io::glob($log_dir . '/*') as $log_file)85 {86 if(!is_file($log_file))87 {88 $is_valid_log = false;89 break;90 }91 if($finfo && substr(finfo_file($finfo, $log_file), 0, 5) != 'text/')92 {93 $is_valid_log = false;94 break;95 }96 }97 }98 if($is_valid_log)99 {100 $system_logs_zip = pts_client::create_temporary_file('.zip');101 pts_compression::zip_archive_create($system_logs_zip, $system_log_dir);102 if(filesize($system_logs_zip) < 2097152)103 {104 // If it's over 2MB, probably too big105 $system_logs = base64_encode(file_get_contents($system_logs_zip));106 $system_logs_hash = sha1($system_logs);107 }108 else109 {110 trigger_error('The systems log attachment is too large to upload to OpenBenchmarking.org.', E_USER_WARNING);111 }112 unlink($system_logs_zip);113 }114 }115 $composite_xml_hash = sha1($composite_xml);116 $composite_xml_type = 'composite_xml';117 // Compress the result file XML if it's big118 if(isset($composite_xml[50000]) && function_exists('gzdeflate'))119 {120 $composite_xml_gz = gzdeflate($composite_xml);121 if($composite_xml_gz != false)122 {123 $composite_xml = $composite_xml_gz;124 $composite_xml_type = 'composite_xml_gz';125 }126 }127 $to_post = array(128 $composite_xml_type => base64_encode($composite_xml),129 'composite_xml_hash' => $composite_xml_hash,130 'local_file_name' => $local_file_name,131 'this_results_identifier' => $results_identifier,132 'system_logs_zip' => $system_logs,133 'system_logs_hash' => $system_logs_hash134 );135 if(isset(self::$client_settings['ResultUploadsDefaultDisplayStatus']) && is_numeric(self::$client_settings['ResultUploadsDefaultDisplayStatus']))136 {137 $to_post['display_status'] = self::$client_settings['ResultUploadsDefaultDisplayStatus'];138 }139 $json_response = pts_openbenchmarking::make_openbenchmarking_request('upload_test_result', $to_post);140 $json_response = json_decode($json_response, true);141 if(!is_array($json_response))142 {143 trigger_error('Unhandled Exception', E_USER_ERROR);144 return false;145 }146 if(isset($json_response['openbenchmarking']['upload']['error']))147 {148 trigger_error($json_response['openbenchmarking']['upload']['error'], E_USER_ERROR);149 }150 if(isset($json_response['openbenchmarking']['upload']['url']))151 {152 echo PHP_EOL . 'Results Uploaded To: ' . $json_response['openbenchmarking']['upload']['url'] . PHP_EOL;153 pts_module_manager::module_process('__event_openbenchmarking_upload', $json_response);154 }155 //$json['openbenchmarking']['upload']['id']156 if(isset(self::$client_settings['RemoveLocalResultsOnUpload']) && self::$client_settings['RemoveLocalResultsOnUpload'] && $local_file_name != null)157 {158 pts_client::remove_saved_result_file($local_file_name);159 }160 if($return_json_data)161 {162 return isset($json_response['openbenchmarking']['upload']) ? $json_response['openbenchmarking']['upload'] : false;163 }164 return isset($json_response['openbenchmarking']['upload']['url']) ? $json_response['openbenchmarking']['upload']['url'] : false;165 }166 public static function recently_updated_tests($limit = -1)167 {168 $available_tests = array();169 foreach(pts_openbenchmarking::linked_repositories() as $repo)170 {171 $repo_index = pts_openbenchmarking::read_repository_index($repo);172 if(isset($repo_index['tests']) && is_array($repo_index['tests']))173 {174 foreach(array_keys($repo_index['tests']) as $identifier)175 {176 if($repo_index['tests'][$identifier]['title'] == null)177 {178 continue;179 }180 $version = array_shift($repo_index['tests'][$identifier]['versions']);181 $update_time = $repo_index['tests'][$identifier]['last_updated'];182 $available_tests[$update_time] = $repo . '/' . $identifier . '-' . $version;183 }184 }185 }186 krsort($available_tests);187 if($limit > 0)188 {189 $available_tests = array_slice($available_tests, 0, $limit);190 }191 return $available_tests;192 }193 public static function popular_tests($limit = -1, $test_type = null)194 {195 $available_tests = array();196 foreach(pts_openbenchmarking::linked_repositories() as $repo)197 {198 $repo_index = pts_openbenchmarking::read_repository_index($repo);199 if(isset($repo_index['tests']) && is_array($repo_index['tests']))200 {201 foreach(array_keys($repo_index['tests']) as $identifier)202 {203 if($repo_index['tests'][$identifier]['title'] == null)204 {205 continue;206 }207 $popularity = $repo_index['tests'][$identifier]['popularity'];208 if($popularity < 1 || ($test_type != null && $repo_index['tests'][$identifier]['test_type'] != $test_type))209 {210 continue;211 }212 $available_tests[$repo . '/' . $identifier] = $popularity;213 }214 }215 }216 asort($available_tests);217 if($limit > 0)218 {219 $available_tests = array_slice($available_tests, 0, $limit);220 }221 return array_keys($available_tests);222 }223 public static function search_tests($search, $test_titles_only = true)224 {225 $matching_tests = array();226 foreach(pts_openbenchmarking::linked_repositories() as $repo)227 {228 $repo_index = pts_openbenchmarking::read_repository_index($repo);229 if(isset($repo_index['tests']) && is_array($repo_index['tests']))230 {231 foreach(array_keys($repo_index['tests']) as $identifier)232 {233 if(stripos($identifier, $search) !== false || stripos($repo_index['tests'][$identifier]['title'], $search) !== false)234 {235 $matching_tests[] = $repo . '/' . $identifier;236 }237 else if($test_titles_only == false && (stripos(implode(' ', $repo_index['tests'][$identifier]['internal_tags']), $search) !== false || stripos($repo_index['tests'][$identifier]['test_type'], $search) !== false || stripos($repo_index['tests'][$identifier]['description'], $search) !== false))238 {239 $matching_tests[] = $repo . '/' . $identifier;240 }241 }242 }243 }244 return $matching_tests;245 }246 public static function tests_available()247 {248 $test_count = 0;249 foreach(pts_openbenchmarking::linked_repositories() as $repo)250 {251 $repo_index = pts_openbenchmarking::read_repository_index($repo);252 if(isset($repo_index['tests']) && is_array($repo_index['tests']))253 {254 $test_count += count($repo_index['tests']);255 }256 }257 return $test_count;258 }259 public static function init_account($openbenchmarking, $settings)260 {261 if(isset($openbenchmarking['user_name']) && isset($openbenchmarking['communication_id']) && isset($openbenchmarking['sav']))262 {263 if(IS_FIRST_RUN_TODAY && pts_network::internet_support_available())264 {265 // Might as well make sure OpenBenchmarking.org account has the latest system info266 // But don't do it everytime to preserve bandwidth267 $openbenchmarking['s_s'] = base64_encode(phodevi::system_software(true));268 $openbenchmarking['s_h'] = base64_encode(phodevi::system_hardware(true));269 $return_state = pts_openbenchmarking::make_openbenchmarking_request('account_verify', $openbenchmarking);270 $json = json_decode($return_state, true);271 if(isset($json['openbenchmarking']['account']['valid']))272 {273 // The account is valid274 self::$openbenchmarking_account = $openbenchmarking;275 self::$client_settings = $json['openbenchmarking']['account']['settings'];276 pts_storage_object::set_in_file(PTS_CORE_STORAGE, 'openbenchmarking_account_settings', $json['openbenchmarking']['account']['settings']);277 }278 else279 {280 pts_storage_object::set_in_file(PTS_CORE_STORAGE, 'openbenchmarking', false);281 trigger_error('Invalid OpenBenchmarking.org account supplied, please re-login.', E_USER_ERROR);282 }283 }284 else285 {286 self::$openbenchmarking_account = $openbenchmarking;287 self::$client_settings = $settings;288 }289 }290 }291 public static function get_openbenchmarking_account()292 {293 return self::$openbenchmarking_account;294 }295 public static function auto_upload_results()296 {297 return isset(self::$client_settings['AutoUploadResults']) && self::$client_settings['AutoUploadResults'];298 }299 public static function override_client_setting($key, $value)300 {301 self::$client_settings[$key] = $value;302 }303 protected static function result_upload_supported(&$result_file)304 {305 foreach($result_file->get_result_objects() as $result_object)306 {307 $test_profile = new pts_test_profile($result_object->test_profile->get_identifier());308 if($test_profile->allow_results_sharing() == false)309 {310 echo PHP_EOL . $result_object->test_profile->get_identifier() . ' does not allow test results to be uploaded.' . PHP_EOL . PHP_EOL;311 return false;312 }313 }314 return true;315 }316 public static function read_repository_test_profile_attribute($test_profile, $attribute)317 {318 list($repo, $tp) = explode('/', $test_profile);319 $tp = substr($tp, 0, strrpos($tp, '-'));320 $repo_index = pts_openbenchmarking::read_repository_index($repo);321 return isset($repo_index['tests'][$tp][$attribute]) ? $repo_index['tests'][$tp][$attribute] : null;322 }323 public static function popular_openbenchmarking_results()324 {325 $index_file = PTS_OPENBENCHMARKING_SCRATCH_PATH . 'popular.results';326 if(!is_file($index_file) || filemtime($index_file) < (time() - 1800))327 {328 // Refresh the repository change-log just once a day should be fine329 $server_index = pts_openbenchmarking::make_openbenchmarking_request('interesting_results');330 if(json_decode($server_index) != false)331 {332 file_put_contents($index_file, $server_index);333 }334 }335 $results = is_file($index_file) ? json_decode(file_get_contents($index_file), true) : false;336 return $results ? $results['results'] : false;337 }338 public static function fetch_repository_changelog($repo_name)339 {340 $index_file = PTS_OPENBENCHMARKING_SCRATCH_PATH . $repo_name . '.changes';341 if(!is_file($index_file) || filemtime($index_file) < (time() - 86400))342 {343 // Refresh the repository change-log just once a day should be fine344 $server_index = pts_openbenchmarking::make_openbenchmarking_request('repo_changes', array('repo' => $repo_name));345 if(json_decode($server_index) != false)346 {347 file_put_contents($index_file, $server_index);348 }349 }350 return is_file($index_file) ? json_decode(file_get_contents($index_file), true) : false;351 }352 public static function user_name()353 {354 return isset(self::$openbenchmarking_account['user_name']) ? self::$openbenchmarking_account['user_name'] : false;355 }356 public static function upload_usage_data($task, $data)357 {358 if(!pts_network::internet_support_available())359 {360 return false;361 }362 switch($task)363 {364 case 'test_install':365 list($test_install, $time_elapsed) = $data;366 $upload_data = array('test_identifier' => $test_install->test_profile->get_identifier(), 'test_version' => $test_install->test_profile->get_test_profile_version(), 'elapsed_time' => $time_elapsed);367 pts_network::http_upload_via_post(pts_openbenchmarking::openbenchmarking_host() . 'extern/statistics/report-test-install.php', $upload_data);368 break;369 case 'test_complete':370 list($test_result, $time_elapsed) = $data;371 $upload_data = array('test_identifier' => $test_result->test_profile->get_identifier(), 'test_version' => $test_result->test_profile->get_test_profile_version(), 'elapsed_time' => $time_elapsed);372 pts_network::http_upload_via_post(pts_openbenchmarking::openbenchmarking_host() . 'extern/statistics/report-test-completion.php', $upload_data);373 break;374 case 'test_install_failure':375 list($test_install, $error) = $data;376 $upload_data = array('test_identifier' => $test_install->test_profile->get_identifier(), 'error' => $error, 'os' => phodevi::read_property('system', 'vendor-identifier'));377 pts_network::http_upload_via_post(pts_openbenchmarking::openbenchmarking_host() . 'extern/statistics/report-test-install-failure.php', $upload_data);378 break;379 }380 }381 public static function request_gsid()382 {383 if(!pts_network::internet_support_available())384 {385 return false;386 }387 $payload = array(388 'client_version' => PTS_VERSION,389 'client_os' => phodevi::read_property('system', 'vendor-identifier')390 );391 $json = pts_openbenchmarking::make_openbenchmarking_request('request_gsid', $payload);392 $json = json_decode($json, true);393 return isset($json['openbenchmarking']['gsid']) ? $json['openbenchmarking']['gsid'] : false;394 }395 public static function update_gsid()396 {397 if(!pts_network::internet_support_available())398 {399 return false;400 }401 $payload = array(402 'client_version' => PTS_VERSION,403 'client_os' => phodevi::read_property('system', 'vendor-identifier')404 );405 pts_openbenchmarking::make_openbenchmarking_request('update_gsid', $payload);406 }407 public static function retrieve_gsid()408 {409 if(!pts_network::internet_support_available())410 {411 return false;412 }413 // If the GSID_E and GSID_P are not known due to being from an old client414 $json = pts_openbenchmarking::make_openbenchmarking_request('retrieve_gsid', array());415 $json = json_decode($json, true);416 return isset($json['openbenchmarking']['gsid']) ? $json['openbenchmarking']['gsid'] : false;417 }418}419?>...
pts_openbenchmarking
Using AI Code Generation
1require_once('/usr/share/phoronix-test-suite/pts-core/pts_openbenchmarking.php');2require_once('/usr/share/phoronix-test-suite/pts-core/pts_result_file_analyzer.php');3$openbenchmarking = new pts_openbenchmarking();4$analyzer = new pts_result_file_analyzer();5$analyzer->load_result_file($file);6$result = $analyzer->get_result_object(0);7$result->test_result_buffer->get_result(0);8$result->test_result_buffer->get_result(1);9$result->test_result_buffer->get_result(2);10$result->test_result_buffer->get_result(3);11$result->test_result_buffer->get_result(4);12$result->test_result_buffer->get_result(5);13$result->test_result_buffer->get_result(6);14$result->test_result_buffer->get_result(7);15$result->test_result_buffer->get_result(8);16$result->test_result_buffer->get_result(9);17$result->test_result_buffer->get_result(10);18$result->test_result_buffer->get_result(11);19$result->test_result_buffer->get_result(12);20$result->test_result_buffer->get_result(13);21$result->test_result_buffer->get_result(14);22$result->test_result_buffer->get_result(15);
pts_openbenchmarking
Using AI Code Generation
1require_once('pts-core/pts-core.php');2$pts = new pts_openbenchmarking();3$tests = $pts->get_available_tests();4foreach($tests as $test)5{6 echo $test;7}8$profiles = $pts->get_available_test_profiles();9foreach($profiles as $profile)10{11 echo $profile;12}13$suites = $pts->get_available_test_suites();14foreach($suites as $suite)15{16 echo $suite;17}18$results = $pts->get_available_test_results();19foreach($results as $result)20{21 echo $result;22}23$result_files = $pts->get_available_test_result_files();24foreach($result_files as $result_file)25{26 echo $result_file;27}28$test_files = $pts->get_available_test_files();29foreach($test_files as $test_file)30{31 echo $test_file;32}33$test_install_files = $pts->get_available_test_install_files();34foreach($test_install_files as $test_install_file)35{36 echo $test_install_file;37}38$test_install_files = $pts->get_available_test_install_files();39foreach($test_install_files as $test_install_file)40{41 echo $test_install_file;42}
pts_openbenchmarking
Using AI Code Generation
1require_once('pts-core/pts-core.php');2$pts = new pts_openbenchmarking();3$pts->set_download_path('/home/sudhir/Downloads');4$pts->set_extract_path('/home/sudhir/Downloads');5$pts->set_install_path('/home/sudhir/Downloads');6$pts->set_run_path('/home/sudhir/Downloads');7$pts->set_delete_path('/home/sudhir/Downloads');8$pts->get_test_profiles();9$pts->get_test_profiles('System');10$pts->get_test_profiles('System','Operating-Systems');11$pts->get_test_profiles('System','Operating-Systems','Linux');12$pts->get_test_profiles('System','Operating-Systems','Linux','Ubuntu');13$pts->get_test_profile_info('pts/pts-7z-1.0');14$pts->get_test_profile_info('pts/pts-7z-1.0','System');15$pts->get_test_profile_info('pts/pts-7z-1.0','System','Operating-Systems');16$pts->get_test_profile_info('pts/pts-7z-1.0','System','Operating-Systems','Linux');17$pts->get_test_profile_info('pts/pts-7z-1.0','System','Operating-Systems','Linux','
pts_openbenchmarking
Using AI Code Generation
1require_once('pts-core.php');2$pts = new pts_openbenchmarking();3$test_suite = $pts->get_result('test_suite');4$test_profile = $pts->get_result('test_profile');5$test_result = $pts->get_result('test_result');6$test_suite = $pts->get_result('test_suite', '1');7$test_profile = $pts->get_result('test_profile', '1');8$test_result = $pts->get_result('test_result', '1');9$test_suite = $pts->get_result('test_suite', '1', '2');10$test_profile = $pts->get_result('test_profile', '1', '2');11$test_result = $pts->get_result('test_result', '1', '2');12$test_suite = $pts->get_result('test_suite', '1', '2', '3');13$test_profile = $pts->get_result('test_profile', '1', '2', '3');14$test_result = $pts->get_result('test_result', '1', '2', '3');15$test_suite = $pts->get_result('test_suite', '1', '2', '3', '4');16$test_profile = $pts->get_result('test_profile', '1', '2', '3', '4');17$test_result = $pts->get_result('test_result', '1', '2', '3', '4');18$test_suite = $pts->get_result('test_suite', '1', '2', '3', '4', '5');19$test_profile = $pts->get_result('test_profile', '1', '2', '3', '4', '5');20$test_result = $pts->get_result('
pts_openbenchmarking
Using AI Code Generation
1include("pts-core/pts-core.php");2$pts=new pts_openbenchmarking();3$pts->get_latest_result("pts/pts-core");4$pts->get_latest_result("pts/pts-core","result.xml");5$pts->get_latest_result("pts/pts-core","result.xml");6$pts->get_latest_result("pts/pts-core","result.xml","system_name");7$pts->get_latest_result("pts/pts-core","result.xml","system_name","result_identifier");8$pts->get_latest_result("pts/pts-core","result.xml","system_name","result_identifier","test_profile");9$pts->get_latest_result("pts/pts-core","result.xml","system_name","result_identifier","test_profile","test_profile_version");
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.
Trigger Selenium automation tests on a cloud-based Grid of 3000+ real browsers and operating systems.
Test now for FreeGet 100 minutes of automation test minutes FREE!!