public static function upload_test_result(&$object, $return_json_data = false) { if ($object instanceof pts_test_run_manager) { $result_file = new pts_result_file($object->get_file_name()); $local_file_name = $object->get_file_name(); $results_identifier = $object->get_results_identifier(); } else { if ($object instanceof pts_result_file) { $result_file =& $object; $local_file_name = $result_file->get_identifier(); $results_identifier = null; } } // Ensure the results can be shared if (self::result_upload_supported($result_file) == false) { return false; } if (pts_network::internet_support_available() == false) { echo PHP_EOL . 'No network support available.' . PHP_EOL; return false; } $composite_xml = $result_file->getRawXml(); $system_log_dir = PTS_SAVE_RESULTS_PATH . $result_file->get_identifier() . '/system-logs/'; $upload_system_logs = false; if (is_dir($system_log_dir)) { if (pts_config::read_bool_config('PhoronixTestSuite/Options/OpenBenchmarking/AlwaysUploadSystemLogs', 'FALSE')) { $upload_system_logs = true; } else { if (isset(self::$client_settings['UploadSystemLogsByDefault'])) { $upload_system_logs = self::$client_settings['UploadSystemLogsByDefault']; } else { if (is_dir($system_log_dir)) { $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'); } } } } $system_logs = null; $system_logs_hash = null; if ($upload_system_logs) { $is_valid_log = true; $finfo = function_exists('finfo_open') ? finfo_open(FILEINFO_MIME_TYPE) : false; foreach (pts_file_io::glob($system_log_dir . '*') as $log_dir) { if ($is_valid_log == false || !is_dir($log_dir)) { $is_valid_log = false; break; } foreach (pts_file_io::glob($log_dir . '/*') as $log_file) { if (!is_file($log_file)) { $is_valid_log = false; break; } if ($finfo && substr(finfo_file($finfo, $log_file), 0, 5) != 'text/') { $is_valid_log = false; break; } } } if ($is_valid_log) { $system_logs_zip = pts_client::create_temporary_file('.zip'); pts_compression::zip_archive_create($system_logs_zip, $system_log_dir); if (filesize($system_logs_zip) < 2097152) { // If it's over 2MB, probably too big $system_logs = base64_encode(file_get_contents($system_logs_zip)); $system_logs_hash = sha1($system_logs); } else { trigger_error('The systems log attachment is too large to upload to OpenBenchmarking.org.', E_USER_WARNING); } unlink($system_logs_zip); } } $composite_xml_hash = sha1($composite_xml); $composite_xml_type = 'composite_xml'; // Compress the result file XML if it's big if (isset($composite_xml[50000]) && function_exists('gzdeflate')) { $composite_xml_gz = gzdeflate($composite_xml); if ($composite_xml_gz != false) { $composite_xml = $composite_xml_gz; $composite_xml_type = 'composite_xml_gz'; } } $to_post = array($composite_xml_type => base64_encode($composite_xml), 'composite_xml_hash' => $composite_xml_hash, 'local_file_name' => $local_file_name, 'this_results_identifier' => $results_identifier, 'system_logs_zip' => $system_logs, 'system_logs_hash' => $system_logs_hash); if (isset(self::$client_settings['ResultUploadsDefaultDisplayStatus']) && is_numeric(self::$client_settings['ResultUploadsDefaultDisplayStatus'])) { $to_post['display_status'] = self::$client_settings['ResultUploadsDefaultDisplayStatus']; } $json_response = pts_openbenchmarking::make_openbenchmarking_request('upload_test_result', $to_post); $json_response = json_decode($json_response, true); if (!is_array($json_response)) { trigger_error('Unhandled Exception', E_USER_ERROR); return false; } if (isset($json_response['openbenchmarking']['upload']['error'])) { trigger_error($json_response['openbenchmarking']['upload']['error'], E_USER_ERROR); } if (isset($json_response['openbenchmarking']['upload']['url'])) { echo PHP_EOL . 'Results Uploaded To: ' . $json_response['openbenchmarking']['upload']['url'] . PHP_EOL; pts_module_manager::module_process('__event_openbenchmarking_upload', $json_response); } //$json['openbenchmarking']['upload']['id'] if (isset(self::$client_settings['RemoveLocalResultsOnUpload']) && self::$client_settings['RemoveLocalResultsOnUpload'] && $local_file_name != null) { pts_client::remove_saved_result_file($local_file_name); } if ($return_json_data) { return isset($json_response['openbenchmarking']['upload']) ? $json_response['openbenchmarking']['upload'] : false; } return isset($json_response['openbenchmarking']['upload']['url']) ? $json_response['openbenchmarking']['upload']['url'] : false; }