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 current_user()
 {
     // Current system user
     return ($pts_user = pts_openbenchmarking_client::user_name()) != null ? $pts_user : phodevi::read_property('system', 'username');
 }
 public static function linked_repositories()
 {
     $repos = array('local', 'pts');
     if (PTS_IS_CLIENT && pts_openbenchmarking_client::user_name() != false) {
         array_push($repos, pts_openbenchmarking_client::user_name());
     }
     return $repos;
 }
 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);
 }
Example #6
0
 public static function user_start()
 {
     if (pts_client::create_lock(PTS_USER_PATH . 'ekofisk_lock') == false) {
         trigger_error('Ekofisk is already running.', E_USER_ERROR);
         return false;
     }
     if (pts_openbenchmarking_client::user_name() == null) {
         trigger_error('You must be logged into your OpenBenchmarking.org account.', E_USER_ERROR);
         return false;
     }
     $last_communication_minute = null;
     $communication_attempts = 0;
     do {
         $exit_loop = false;
         if ($last_communication_minute != date('i')) {
             echo PHP_EOL . 'Checking State From Server @ ' . date('H:i:s');
         }
         if ($last_communication_minute == date('i') && $communication_attempts > 3) {
             // Something is wrong, Phoromatic shouldn't be communicating with server more than three times a minute
             $response = M_PHOROMATIC_RESPONSE_IDLE;
         } else {
             $server_response = self::make_server_request(array('ekofisk_task' => 'status_check'));
             $json = json_decode($server_response, true);
             $response = $json['openbenchmarking']['response']['ekofisk'];
             if (date('i') != $last_communication_minute) {
                 $last_communication_minute = date('i');
                 $communication_attempts = 0;
             }
             $communication_attempts++;
         }
         echo ' [' . $response . ']' . PHP_EOL;
         switch ($response) {
             case M_PHOROMATIC_RESPONSE_RUN_TEST:
                 $test_flags = pts_c::auto_mode | pts_c::recovery_mode;
                 do {
                     $suite_identifier = 'phoromatic-' . rand(1000, 9999);
                 } while (is_file(PTS_TEST_SUITE_PATH . 'local/' . $suite_identifier . '/suite-definition.xml'));
                 file_put_contents(PTS_TEST_SUITE_PATH . 'local/' . $suite_identifier . '/suite-definition.xml', $server_response);
                 $phoromatic_schedule_id = $xml_parser->getXMLValue(M_PHOROMATIC_ID);
                 $phoromatic_results_identifier = $xml_parser->getXMLValue(M_PHOROMATIC_SYS_NAME);
                 $phoromatic_trigger = $xml_parser->getXMLValue(M_PHOROMATIC_TRIGGER);
                 if (pts_strings::string_bool($xml_parser->getXMLValue(M_PHOROMATIC_RUN_INSTALL_COMMAND, M_PHOROMATIC_RESPONSE_TRUE))) {
                     phoromatic::set_user_context($xml_parser->getXMLValue(M_PHOROMATIC_SET_CONTEXT_PRE_INSTALL), $phoromatic_trigger, $phoromatic_schedule_id, 'INSTALL');
                     pts_client::set_test_flags($test_flags);
                     pts_test_installer::standard_install($suite_identifier);
                 }
                 phoromatic::set_user_context($xml_parser->getXMLValue(M_PHOROMATIC_SET_CONTEXT_PRE_RUN), $phoromatic_trigger, $phoromatic_schedule_id, 'INSTALL');
                 // Do the actual running
                 if (pts_test_run_manager::initial_checks($suite_identifier)) {
                     $test_run_manager = new pts_test_run_manager($test_flags);
                     // Load the tests to run
                     if ($test_run_manager->load_tests_to_run($suite_identifier)) {
                         if (pts_strings::string_bool($xml_parser->getXMLValue(M_PHOROMATIC_UPLOAD_TO_GLOBAL, 'FALSE'))) {
                             $test_run_manager->auto_upload_to_openbenchmarking();
                         }
                         // Save results?
                         $test_run_manager->auto_save_results(date('Y-m-d H:i:s'), $phoromatic_results_identifier, 'A Phoromatic run.');
                         // Run the actual tests
                         $test_run_manager->pre_execution_process();
                         $test_run_manager->call_test_runs();
                         $test_run_manager->post_execution_process();
                         // Upload to Phoromatic
                         pts_file_io::unlink(PTS_TEST_SUITE_PATH . 'local/' . $suite_identifier . '/suite-definition.xml');
                         // Upload test results
                         if (is_file(PTS_SAVE_RESULTS_PATH . $save_identifier . '/composite.xml')) {
                             phoromatic::update_system_status('Uploading Test Results');
                             $times_tried = 0;
                             do {
                                 if ($times_tried > 0) {
                                     echo PHP_EOL . 'Connection to server failed. Trying again in 60 seconds...' . PHP_EOL;
                                     sleep(60);
                                 }
                                 $uploaded_test_results = phoromatic::upload_test_results($save_identifier, $phoromatic_schedule_id, $phoromatic_results_identifier, $phoromatic_trigger);
                                 $times_tried++;
                             } while ($uploaded_test_results == false && $times_tried < 5);
                             if ($uploaded_test_results == false) {
                                 echo 'Server connection failed. Exiting...' . PHP_EOL;
                                 return false;
                             }
                             if (pts_strings::string_bool($xml_parser->getXMLValue(M_PHOROMATIC_ARCHIVE_RESULTS_LOCALLY, M_PHOROMATIC_RESPONSE_TRUE)) == false) {
                                 pts_client::remove_saved_result_file($save_identifier);
                             }
                         }
                     }
                 }
                 break;
             case M_PHOROMATIC_RESPONSE_EXIT:
                 echo PHP_EOL . 'Phoromatic received a remote command to exit.' . PHP_EOL;
                 phoromatic::update_system_status('Exiting Phoromatic');
                 pts_client::release_lock(PTS_USER_PATH . 'phoromatic_lock');
                 $exit_loop = true;
                 break;
             case M_PHOROMATIC_RESPONSE_SERVER_MAINTENANCE:
                 // The Phoromatic server is down for maintenance, so don't bother updating system status and wait longer before checking back
                 echo PHP_EOL . 'The Phoromatic server is currently down for maintenance. Waiting for service to be restored.' . PHP_EOL;
                 sleep((15 - date('i') % 15) * 60);
                 break;
             case M_PHOROMATIC_RESPONSE_SHUTDOWN:
                 echo PHP_EOL . 'Shutting down the system.' . PHP_EOL;
                 $exit_loop = true;
                 shell_exec('poweroff');
                 // Currently assuming root
                 break;
             case M_PHOROMATIC_RESPONSE_REBOOT:
                 echo PHP_EOL . 'Rebooting the system.' . PHP_EOL;
                 $exit_loop = true;
                 shell_exec('reboot');
                 // Currently assuming root
                 break;
             case M_PHOROMATIC_RESPONSE_IDLE:
             default:
                 phoromatic::update_system_status('Idling, Waiting For Task');
                 sleep((10 - date('i') % 10) * 60);
                 // Check with server every 10 minutes
                 break;
         }
         if (phodevi::system_hardware(true) != $current_hw || phodevi::system_software(true) != $current_sw) {
             // Hardware and/or software has changed while PTS/Phoromatic has been running, update the Phoromatic Server
             echo 'Updating Installed Hardware / Software With Phoromatic Server' . PHP_EOL;
             phoromatic::update_system_details();
             $current_hw = phodevi::system_hardware(true);
             $current_sw = phodevi::system_software(true);
         }
     } while ($exit_loop == false);
     phoromatic::update_system_status('Offline');
 }