public static function run($r)
 {
     if (pts_openbenchmarking_client::user_name() == false) {
         echo PHP_EOL . 'You must first be logged into an OpenBenchmarking.org account.' . PHP_EOL;
         echo PHP_EOL . 'Create An Account: http://openbenchmarking.org/';
         echo PHP_EOL . 'Log-In Command: phoronix-test-suite openbenchmarking-setup' . PHP_EOL . PHP_EOL;
         return false;
     }
     foreach (pts_types::identifiers_to_test_profile_objects($r, true, true) as $test_profile) {
         // validate_test_profile
         if (pts_validation::validate_test_profile($test_profile)) {
             pts_client::$display->generic_heading($test_profile);
             $zip_file = PTS_OPENBENCHMARKING_SCRATCH_PATH . $test_profile->get_identifier_base_name() . '-' . $test_profile->get_test_profile_version() . '.zip';
             $zip_created = pts_compression::zip_archive_create($zip_file, pts_file_io::glob($test_profile->get_resource_dir() . '*'));
             if ($zip_created == false) {
                 echo PHP_EOL . 'Failed to create zip file.' . PHP_EOL;
                 return false;
             }
             if (filesize($zip_file) > 104857) {
                 echo PHP_EOL . 'The test profile package is too big.' . PHP_EOL;
                 return false;
             }
             $commit_description = pts_user_io::prompt_user_input('Enter a test commit description', false);
             echo PHP_EOL;
             $server_response = pts_openbenchmarking::make_openbenchmarking_request('upload_test_profile', array('tp_identifier' => $test_profile->get_identifier_base_name(), 'tp_sha1' => sha1_file($zip_file), 'tp_zip' => base64_encode(file_get_contents($zip_file)), 'tp_zip_name' => basename($zip_file), 'commit_description' => $commit_description));
             echo PHP_EOL;
             $json = json_decode($server_response, true);
             if (isset($json['openbenchmarking']['upload']['error']) && !empty($json['openbenchmarking']['upload']['error'])) {
                 echo 'ERROR: ' . $json['openbenchmarking']['upload']['error'] . PHP_EOL;
             }
             if (isset($json['openbenchmarking']['upload']['id']) && !empty($json['openbenchmarking']['upload']['id'])) {
                 echo 'Command: phoronix-test-suite benchmark ' . $json['openbenchmarking']['upload']['id'] . PHP_EOL;
             }
             if (isset($json['openbenchmarking']['upload']['url']) && !empty($json['openbenchmarking']['upload']['url'])) {
                 pts_openbenchmarking::refresh_repository_lists(null, true);
                 echo 'URL: ' . $json['openbenchmarking']['upload']['url'] . PHP_EOL;
             }
             echo PHP_EOL;
             // TODO: chmod +x the .sh files, appropriate permissions elsewhere
             unlink($zip_file);
         }
     }
 }
 public static function run($r)
 {
     if (pts_openbenchmarking_client::user_name() == false) {
         echo PHP_EOL . 'You must first be logged into an OpenBenchmarking.org account.' . PHP_EOL;
         echo PHP_EOL . 'Create An Account: http://openbenchmarking.org/';
         echo PHP_EOL . 'Log-In Command: phoronix-test-suite openbenchmarking-setup' . PHP_EOL . PHP_EOL;
         return false;
     }
     if (($test_suite = pts_types::identifier_to_object($r[0])) != false) {
         pts_client::$display->generic_heading($r[0]);
         if (pts_validation::validate_test_suite($test_suite)) {
             $zip_file = PTS_OPENBENCHMARKING_SCRATCH_PATH . $test_suite->get_identifier(false) . '-' . $test_suite->get_version() . '.zip';
             $zip_created = pts_compression::zip_archive_create($zip_file, $test_suite->xml_parser->getFileLocation());
             if ($zip_created == false) {
                 echo PHP_EOL . 'Failed to create zip file.' . PHP_EOL;
                 return false;
             }
             $zip = new ZipArchive();
             $zip->open($zip_file);
             $zip->renameName(basename($test_suite->xml_parser->getFileLocation()), 'suite-definition.xml');
             $zip->close();
             $commit_description = pts_user_io::prompt_user_input('Enter a test commit description', false);
             echo PHP_EOL;
             $server_response = pts_openbenchmarking::make_openbenchmarking_request('upload_test_suite', array('ts_identifier' => $test_suite->get_identifier_base_name(), 'ts_sha1' => sha1_file($zip_file), 'ts_zip' => base64_encode(file_get_contents($zip_file)), 'ts_zip_name' => basename($zip_file), 'commit_description' => $commit_description));
             echo PHP_EOL;
             $json = json_decode($server_response, true);
             if (isset($json['openbenchmarking']['upload']['error']) && !empty($json['openbenchmarking']['upload']['error'])) {
                 echo 'ERROR: ' . $json['openbenchmarking']['upload']['error'] . PHP_EOL;
             }
             if (isset($json['openbenchmarking']['upload']['id']) && !empty($json['openbenchmarking']['upload']['id'])) {
                 echo 'Command: phoronix-test-suite benchmark ' . $json['openbenchmarking']['upload']['id'] . PHP_EOL;
             }
             if (isset($json['openbenchmarking']['upload']['url']) && !empty($json['openbenchmarking']['upload']['url'])) {
                 pts_openbenchmarking::refresh_repository_lists(null, true);
                 echo 'URL: ' . $json['openbenchmarking']['upload']['url'] . PHP_EOL;
             }
             echo PHP_EOL;
             unlink($zip_file);
         }
     }
 }
 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;
 }
 public static function run($r)
 {
     if (pts_openbenchmarking_client::user_name() == false) {
         echo PHP_EOL . 'You must first be logged into an OpenBenchmarking.org account.' . PHP_EOL;
         echo PHP_EOL . 'Create An Account: http://openbenchmarking.org/';
         echo PHP_EOL . 'Log-In Command: phoronix-test-suite openbenchmarking-setup' . PHP_EOL . PHP_EOL;
         return false;
     }
     ini_set('memory_limit', '2048M');
     foreach (pts_types::identifiers_to_test_profile_objects($r, false, true) as $test_profile) {
         $qualified_identifier = $test_profile->get_identifier();
         // First make sure the test profile is already in the OpenBenchmarking.org database...
         $json = pts_openbenchmarking::make_openbenchmarking_request('is_test_profile', array('i' => $qualified_identifier));
         $json = json_decode($json, true);
         if (!isset($json['openbenchmarking']['test']['valid']) || $json['openbenchmarking']['test']['valid'] != 'TRUE') {
             echo PHP_EOL . $qualified_identifier . ' must first be uploaded to OpenBenchmarking.org.' . PHP_EOL;
             //	break;
         }
         // Set some other things...
         pts_client::pts_set_environment_variable('FORCE_TIMES_TO_RUN', 1);
         pts_client::pts_set_environment_variable('TEST_RESULTS_NAME', $test_profile->get_title() . ' Testing ' . date('Y-m-d'));
         pts_client::pts_set_environment_variable('TEST_RESULTS_IDENTIFIER', 'Sample Run');
         pts_client::pts_set_environment_variable('TEST_RESULTS_DESCRIPTION', 1);
         pts_openbenchmarking_client::override_client_setting('AutoUploadResults', true);
         pts_openbenchmarking_client::override_client_setting('UploadSystemLogsByDefault', true);
         // Take screenshots
         pts_client::pts_set_environment_variable('SCREENSHOT_INTERVAL', 9);
         pts_module_manager::attach_module('timed_screenshot');
         $force_ss = true;
         $reference_ss_file = pts_module_manager::module_call('timed_screenshot', 'take_screenshot', $force_ss);
         sleep(2);
         $apitrace = pts_file_io::glob('/usr/local/lib/*/apitrace/wrappers/glxtrace.so');
         if (!empty($apitrace) && pts_client::executable_in_path('apitrace')) {
             $apitrace = array_shift($apitrace);
             putenv('LD_PRELOAD=' . $apitrace);
         } else {
             $apitrace = false;
         }
         // So for any compiling tasks they will try to use the most aggressive instructions possible
         putenv('CFLAGS=-march=native -O3');
         putenv('CXXFLAGS=-march=native -O3');
         pts_test_installer::standard_install($qualified_identifier, true);
         $run_manager = new pts_test_run_manager(false, 2);
         $run_manager->standard_run($qualified_identifier);
         if ($apitrace) {
             putenv('LD_PRELOAD=');
         }
         if ($reference_ss_file) {
             $reference_ss = pts_image::image_file_to_gd($reference_ss_file);
             unlink($reference_ss_file);
             $screenshots_gd = array();
             $screenshots = pts_module_manager::module_call('timed_screenshot', 'get_screenshots');
             var_dump($screenshots);
             foreach ($screenshots as $ss_file) {
                 $screenshots_gd[$ss_file] = pts_image::image_file_to_gd($ss_file);
                 if ($screenshots_gd[$ss_file] == false) {
                     continue;
                 }
                 $ss_delta = pts_image::gd_image_delta_composite($reference_ss, $screenshots_gd[$ss_file], true);
                 if (count($ss_delta) < floor(imagesx($reference_ss) * 0.5600000000000001) || filesize($ss_file) > 2097152) {
                     // If less than 56% of the pixels are changing on X, then likely not much to show off... (CLI only likely)
                     // Or if filesize of image is beyond 2MB
                     //echo 'dropping' . $ss_file . PHP_EOL;
                     unset($screenshots_gd[$ss_file]);
                     pts_file_io::unlink($ss_file);
                 }
             }
             $ss_files = array_keys($screenshots_gd);
             shuffle($ss_files);
             // Don't upload more than 4MB worth of screenshots
             while (pts_file_io::array_filesize($ss_files) > 1048576 * 2) {
                 $f = array_pop($ss_files);
                 unlink($f);
             }
             if (count($ss_files) > 0) {
                 $c = 1;
                 foreach ($ss_files as $i => $file) {
                     $new_file = dirname($file) . '/screenshot-' . $c . '.png';
                     rename($file, $new_file);
                     $ss_files[$i] = $new_file;
                     $c++;
                 }
                 $ss_zip_file = PTS_OPENBENCHMARKING_SCRATCH_PATH . 'screenshots-' . $test_profile->get_identifier_base_name() . '-' . $test_profile->get_test_profile_version() . '.zip';
                 $zip_created = pts_compression::zip_archive_create($ss_zip_file, $ss_files);
                 if ($zip_created) {
                     echo count($ss_files) . ' screenshots captured for use.';
                     //'tp_sha1' => sha1_file($zip_file),
                     //'tp_zip' => base64_encode(file_get_contents($zip_file)),
                 }
                 foreach ($ss_files as $file) {
                     //	pts_file_io::unlink($file);
                 }
             }
         }
         $test_binary = self::locate_test_profile_lead_binary($test_profile);
         $shared_library_dependencies = array();
         $instruction_usage = array();
         $gl_calls = null;
         if (is_executable($test_binary)) {
             if ($apitrace) {
                 // Find the trace...
                 $test_binary_dir = dirname($test_binary);
                 $trace_file = glob($test_binary_dir . '/*.trace');
                 if ($trace_file) {
                     echo 'Analyzing GL traces';
                     $trace_file = array_shift($trace_file);
                     $gl_usage = self::analyze_apitrace_trace_glpop($trace_file);
                     if (!empty($gl_usage)) {
                         $gl_calls = implode(',', $gl_usage);
                     }
                 }
             }
             $ldd = trim(shell_exec('ldd ' . $test_binary));
             foreach (explode(PHP_EOL, $ldd) as $line) {
                 $line = explode(' => ', $line);
                 if (count($line) == 2) {
                     $shared_library_dependencies[] = trim(basename($line[0]));
                 }
             }
             echo PHP_EOL . 'SHARED LIBRARY DEPENDENCIES: ' . PHP_EOL;
             print_r($shared_library_dependencies);
             foreach (array('core-avx-i', 'bdver2') as $march) {
                 // So for any compiling tasks they will try to use the most aggressive instructions possible
                 putenv('CFLAGS=-march=' . $march . ' -O3');
                 putenv('CXXFLAGS=-march=' . $march . ' -O3');
                 pts_test_installer::standard_install($qualified_identifier, true);
                 $instruction_usage[$march] = self::analyze_binary_instruction_usage($test_binary);
                 if ($instruction_usage[$march] == null) {
                     unset($instruction_usage[$march]);
                 }
             }
             if (!empty($instruction_usage) && count(array_unique($instruction_usage)) == 1) {
                 $generic = array_pop($instruction_usage);
                 $instruction_usage = array('generic' => $generic);
             }
             var_dump($instruction_usage);
         } else {
             echo PHP_EOL . $test_binary;
             echo PHP_EOL . 'Test binary could not be found.' . PHP_EOL;
             //		return false;
         }
     }
     sleep(10);
     var_dump($shared_library_dependencies);
     var_dump($instruction_usage);
     var_dump($gl_calls);
     $server_response = pts_openbenchmarking::make_openbenchmarking_request('upload_test_meta', array('i' => $test_profile->get_identifier(), 'screenshots_zip' => $ss_zip_conts = base64_encode(file_get_contents($ss_zip_file)), 'screenshots_zip_sha1' => sha1($ss_zip_conts), 'ldd_libraries' => implode(',', $shared_library_dependencies), 'opengl_calls' => $gl_calls, 'instruction_set_usage' => base64_encode(json_encode($instruction_usage))));
     var_dump($server_response);
     $json = json_decode($server_response, true);
     pts_file_io::unlink($ss_zip_file);
 }
Esempio n. 5
0
 private static function upload_test_result(&$result_file, $upload_system_logs = true, $schedule_id = 0, $save_identifier = null, $trigger = null, $elapsed_time = 0, $benchmark_ticket_id = null)
 {
     $system_logs = null;
     $system_logs_hash = null;
     // TODO: Potentially integrate this code below shared with pts_openbenchmarking_client into a unified function for validating system log files
     $system_log_dir = PTS_SAVE_RESULTS_PATH . $result_file->get_identifier() . '/system-logs/';
     if (is_dir($system_log_dir) && $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) == 0) {
                 pts_client::$pts_logger && pts_client::$pts_logger->log('System log ZIP file failed to generate. Missing PHP ZIP support?');
             } else {
                 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 = $result_file->getRawXml();
     $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';
         }
     }
     // Upload to Phoromatic
     $times_tried = 0;
     do {
         if ($times_tried > 0) {
             sleep(rand(5, 20));
         }
         $res = phoromatic::upload_to_remote_server(array('r' => 'result_upload', 'sched' => $schedule_id, 'bid' => $benchmark_ticket_id, 'o' => $save_identifier, 'ts' => $trigger, 'et' => $elapsed_time, $composite_xml_type => base64_encode($composite_xml), 'composite_xml_hash' => $composite_xml_hash, 'system_logs_zip' => $system_logs, 'system_logs_hash' => $system_logs_hash));
         $times_tried++;
     } while ($res == false && $times_tried < 4);
     return $res;
 }
Esempio n. 6
0
 private static function capture_test_logs($save_identifier)
 {
     $data = array('system-logs' => null, 'test-logs' => null);
     if (is_dir(PTS_SAVE_RESULTS_PATH . $save_identifier . '/system-logs/')) {
         $system_logs_zip = pts_client::create_temporary_file();
         pts_compression::zip_archive_create($system_logs_zip, PTS_SAVE_RESULTS_PATH . $save_identifier . '/system-logs/');
         $data['system-logs'] = base64_encode(file_get_contents($system_logs_zip));
         unlink($system_logs_zip);
     }
     if (is_dir(PTS_SAVE_RESULTS_PATH . $save_identifier . '/test-logs/')) {
         $test_logs_zip = pts_client::create_temporary_file();
         pts_compression::zip_archive_create($test_logs_zip, PTS_SAVE_RESULTS_PATH . $save_identifier . '/test-logs/');
         $data['test-logs'] = base64_encode(file_get_contents($test_logs_zip));
         unlink($test_logs_zip);
     }
     return $data;
 }