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 download_test_suite($qualified_identifier)
 {
     if (is_file(PTS_TEST_SUITE_PATH . $qualified_identifier . '/suite-definition.xml')) {
         return true;
     }
     $file = PTS_OPENBENCHMARKING_SCRATCH_PATH . $qualified_identifier . '.zip';
     if (pts_network::internet_support_available()) {
         $hash_json = pts_openbenchmarking::make_openbenchmarking_request('suite_hash', array('i' => $qualified_identifier));
         $hash_json = json_decode($hash_json, true);
         $hash_check = isset($hash_json['openbenchmarking']['suite']['hash']) ? $hash_json['openbenchmarking']['suite']['hash'] : null;
         // should also check for ['openbenchmarking']['suite']['error'] problems
     }
     if (!is_file($file)) {
         if (pts_network::internet_support_available()) {
             $test_suite = pts_openbenchmarking::make_openbenchmarking_request('download_suite', array('i' => $qualified_identifier));
             if ($test_suite != null && ($hash_check == null || $hash_check == sha1($test_suite))) {
                 // save it
                 file_put_contents($file, $test_suite);
                 $hash_check = null;
             } else {
                 if (is_file('/var/cache/phoronix-test-suite/openbenchmarking.org/' . $qualified_identifier . '.zip') && ($hash_check == null || sha1_file('/var/cache/phoronix-test-suite/openbenchmarking.org/' . $qualified_identifier . '.zip') == $hash_check)) {
                     copy('/var/cache/phoronix-test-suite/openbenchmarking.org/' . $qualified_identifier . '.zip', $file);
                 }
             }
         }
         if (!is_file($file) && ($test_suite = self::phoromatic_server_ob_cache_request('suite', substr($qualified_identifier, 0, strpos($qualified_identifier, '/')), substr($qualified_identifier, strpos($qualified_identifier, '/') + 1)))) {
             if ($b64 = base64_decode($test_suite)) {
                 $test_suite = $b64;
             }
             file_put_contents($file, $test_suite);
         }
         if (PTS_IS_CLIENT && !is_file($file)) {
             trigger_error('Network support is needed to obtain ' . $qualified_identifier . ' data.' . PHP_EOL, E_USER_ERROR);
             return false;
         }
     }
     if (!is_file(PTS_TEST_SUITE_PATH . $qualified_identifier . '/suite-definition.xml') && is_file($file) && ($hash_check == null || is_file($file) && sha1_file($file) == $hash_check)) {
         // extract it
         pts_file_io::mkdir(PTS_TEST_SUITE_PATH . dirname($qualified_identifier));
         pts_file_io::mkdir(PTS_TEST_SUITE_PATH . $qualified_identifier);
         pts_compression::zip_archive_extract($file, PTS_TEST_SUITE_PATH . $qualified_identifier);
         if (is_file(PTS_TEST_SUITE_PATH . $qualified_identifier . '/suite-definition.xml')) {
             return true;
         } else {
             unlink($file);
             return false;
         }
     }
     return 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. 6
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;
 }
    public static function run($r)
    {
        $render_dir = pts_client::temporary_directory() . '/pts-render-test-310815/';
        if (!is_file($render_dir . 'mega-render-test.tar.bz2')) {
            pts_file_io::mkdir($render_dir);
            pts_network::download_file('http://linuxbenchmarking.com/misc/mega-render-test-310815.tar.bz2', $render_dir . 'mega-render-test.tar.bz2');
            pts_compression::archive_extract($render_dir . 'mega-render-test.tar.bz2');
        }
        define('PATH_TO_EXPORTED_PHOROMATIC_DATA', $render_dir . 'mega-render-test-310815/');
        error_reporting(E_ALL);
        ini_set('memory_limit', '2048M');
        $export_index_json = file_get_contents(PATH_TO_EXPORTED_PHOROMATIC_DATA . 'export-index.json');
        $export_index_json = json_decode($export_index_json, true);
        $dump_size = 0;
        $start = microtime(true);
        foreach (array_keys($export_index_json['phoromatic']) as $REQUESTED) {
            $this_render_test = time();
            $tracker =& $export_index_json['phoromatic'][$REQUESTED];
            $triggers = $tracker['triggers'];
            echo PHP_EOL . 'STARTING RENDER TEST ON: ' . $REQUESTED . ' (' . count($triggers) . ' Triggers)' . PHP_EOL;
            $length = count($tracker['triggers']);
            $result_files = array();
            foreach ($triggers as $trigger) {
                $results_for_trigger = glob(PATH_TO_EXPORTED_PHOROMATIC_DATA . '/' . $REQUESTED . '/' . $trigger . '/*/composite.xml');
                echo '.';
                if ($results_for_trigger == false) {
                    continue;
                }
                foreach ($results_for_trigger as $composite_xml) {
                    // Add to result file
                    $system_name = basename(dirname($composite_xml)) . ': ' . $trigger;
                    array_push($result_files, new pts_result_merge_select($composite_xml, null, $system_name));
                }
            }
            echo 'STARTING MERGE; ';
            $result_file = new pts_result_file(null, true);
            $result_file->merge($result_files);
            echo 'MAKING NEW RESULT FILE; ';
            $extra_attributes = array('reverse_result_buffer' => true, 'force_simple_keys' => true, 'force_line_graph_compact' => true, 'force_tracking_line_graph' => true);
            //$extra_attributes['normalize_result_buffer'] = true;
            $intent = null;
            //$table = new pts_ResultFileTable($result_file, $intent);
            //echo '<p style="text-align: center; overflow: auto;" class="result_object">' . pts_render::render_graph_inline_embed($table, $result_file, $extra_attributes) . '</p>';
            echo 'STARTING RESULT LOOP; ';
            $html_dump = '<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8" />
</head>
<body>';
            foreach ($result_file->get_result_objects(isset($_POST['show_only_changed_results']) ? 'ONLY_CHANGED_RESULTS' : -1) as $i => $result_object) {
                echo $result_object->test_profile->get_title() . ' ';
                $html_dump .= '<h3>' . $result_object->get_arguments_description() . '</h3>';
                $html_dump .= pts_render::render_graph_inline_embed($result_object, $result_file, $extra_attributes);
                unset($result_object);
            }
            $table = new pts_ResultFileSystemsTable($result_file);
            $html_dump .= pts_render::render_graph_inline_embed($table, $result_file, $extra_attributes);
            echo PHP_EOL . PHP_EOL . 'RENDER TEST ON: ' . $REQUESTED . ' TOOK ' . (time() - $this_render_test) . PHP_EOL;
            $dump_size += strlen($html_dump);
            file_put_contents(PATH_TO_EXPORTED_PHOROMATIC_DATA . $REQUESTED . '.html', $html_dump . '</body></html>');
        }
        echo PHP_EOL . 'RENDER TEST TOOK: ' . (time() - $start) . PHP_EOL . PHP_EOL;
        echo PHP_EOL . 'PEAK MEMORY USAGE: ' . round(memory_get_peak_usage(true) / 1048576, 3) . ' MB';
        echo PHP_EOL . 'PEAK MEMORY USAGE (emalloc): ' . round(memory_get_peak_usage() / 1048576, 3) . ' MB';
        echo PHP_EOL . 'TOTAL FILE SIZE: ' . ceil($dump_size / 1000) . ' KB';
        echo PHP_EOL;
    }
 public function execute_script($pass_arguments = null)
 {
     if ($this->script_file == null) {
         return false;
     }
     $script_contents = file_get_contents($this->script_file);
     $prev_exit_status = 0;
     $script_pointer = -1;
     do {
         $exit_status = 0;
         if ($prev_exit_status != 0) {
             $exit_status = $prev_exit_status;
             $prev_exit_status = 0;
         }
         $script_contents = substr($script_contents, $script_pointer + 1);
         $line = $script_contents;
         $prev_script_pointer = $script_pointer;
         if (($script_pointer = strpos($line, "\n")) !== false) {
             $line = substr($line, 0, $script_pointer);
         }
         $line_r = $line != null ? pts_strings::trim_explode(' ', $line) : null;
         switch (isset($line_r[0]) ? $line_r[0] : null) {
             case '':
                 break;
             case 'mv':
                 // TODO: implement folder support better
                 $line_r[1] = $this->get_real_path($line_r[1], $pass_arguments);
                 $line_r[2] = $this->get_real_path($line_r[2], $pass_arguments);
                 //pts_file_io::delete($line_r[2], null, true);
                 //copy($line_r[1], $line_r[2] . (is_dir($line_r[2]) ? basename($line_r[1]) : null));
                 //pts_file_io::delete($line_r[1], null, true);
                 rename($line_r[1], $line_r[2] . (is_dir($line_r[2]) ? basename($line_r[1]) : null));
                 break;
             case 'cp':
                 // TODO: implement folder support better
                 $line_r[1] = $this->get_real_path($line_r[1], $pass_arguments);
                 $line_r[2] = $this->get_real_path($line_r[2], $pass_arguments);
                 copy($line_r[1], $line_r[2] . (is_dir($line_r[2]) ? basename($line_r[1]) : null));
                 break;
             case 'cat':
                 // TODO: implement folder support better
                 $line_r[1] = $this->get_real_path($line_r[1], $pass_arguments);
                 $line_r[3] = $this->get_real_path($line_r[3], $pass_arguments);
                 copy($line_r[1], $line_r[3]);
                 break;
             case 'cd':
                 if ($line_r[1] == '..') {
                     if (substr($this->var_current_directory, -1) == '/') {
                         $this->var_current_directory = substr($this->var_current_directory, 0, -1);
                     }
                     $this->var_current_directory = substr($this->var_current_directory, 0, strrpos($this->var_current_directory, '/') + 1);
                 } else {
                     if ($line_r[1] == '~') {
                         $this->var_current_directory = $this->environmental_variables["HOME"];
                     } else {
                         if (substr($line_r[1], 0, 1) == '"') {
                             // On Windows some directories are encased in quotes for spaces in the directory names
                             array_shift($line_r);
                             $this->var_current_directory = implode(' ', $line_r);
                         } else {
                             if (is_readable($line_r[1])) {
                                 $this->var_current_directory = $line_r[1];
                             } else {
                                 if (is_readable($this->get_real_path($line_r[1], $pass_arguments))) {
                                     $this->var_current_directory = $this->get_real_path($line_r[1], $pass_arguments);
                                 }
                             }
                         }
                     }
                 }
                 break;
             case 'touch':
                 if (!is_file($this->var_current_directory . $line_r[1]) && is_writable($this->var_current_directory)) {
                     touch($this->var_current_directory . $line_r[1]);
                 }
                 break;
             case 'mkdir':
                 pts_file_io::mkdir($this->var_current_directory . $line_r[1]);
                 break;
             case 'rm':
                 for ($i = 1; $i < count($line_r); $i++) {
                     if (is_file($this->var_current_directory . $line_r[$i])) {
                         unlink($this->var_current_directory . $line_r[$i]);
                     } else {
                         if (is_dir($this->var_current_directory . $line_r[$i])) {
                             pts_file_io::delete($this->var_current_directory . $line_r[$i], null, true);
                         }
                     }
                 }
                 break;
             case 'chmod':
                 $chmod_file = self::find_file_in_array($line_r);
                 if ($chmod_file) {
                     chmod($chmod_file, 0755);
                 }
                 break;
             case 'unzip':
                 $zip_file = self::find_file_in_array($line_r);
                 pts_compression::zip_archive_extract($zip_file, $this->var_current_directory);
                 break;
             case 'tar':
                 // TODO: implement
                 break;
             case 'echo':
                 if ($line == "echo \$? > ~/install-exit-status") {
                     file_put_contents($this->var_current_directory . "install-exit-status", $exit_status);
                     break;
                 } else {
                     if ($line == "echo \$? > ~/test-exit-status") {
                         file_put_contents($this->var_current_directory . "test-exit-status", $exit_status);
                         break;
                     }
                 }
                 $start_echo = strpos($script_contents, "\"") + 1;
                 $end_echo = $start_echo - 1;
                 do {
                     $end_echo = strpos($script_contents, "\"", $end_echo + 1);
                 } while ($script_contents[$end_echo - 1] == "\\");
                 $script_pointer = strpos($script_contents, "\n", $end_echo);
                 $line_remainder = substr($script_contents, $end_echo + 1, $script_pointer - $end_echo - 1);
                 $echo_contents = substr($script_contents, $start_echo, $end_echo - $start_echo);
                 $this->parse_variables_in_string($echo_contents, $pass_arguments);
                 $echo_contents = str_replace("\\\$", "\$", $echo_contents);
                 $echo_contents = str_replace("\\\"", "\"", $echo_contents);
                 if (($to_file = strpos($line_remainder, ' > ')) !== false) {
                     $to_file = trim(substr($line_remainder, $to_file + 3));
                     if (($end_file = strpos($to_file, ' ')) !== false) {
                         $to_file = substr($to_file, 0, $end_file);
                     }
                     // TODO: right now it's expecting the file location pipe to be relative location
                     $echo_dir = pts_strings::add_trailing_slash(str_replace('"', null, $this->var_current_directory));
                     // needed for phodevi::is_windows() specviewperf10
                     file_put_contents($echo_dir . $to_file, $echo_contents . "\n");
                 } else {
                     echo $echo_contents;
                 }
                 break;
             case '#!/bin/sh':
             case '#':
             case null:
                 // IGNORE
                 break;
             case 'case':
                 //echo "\nUNHANDLED EVENT\n";
                 return false;
                 // TODO: decide how to handle
                 break;
             default:
                 $exec_output = array();
                 if (phodevi::is_windows() && substr($line, 0, 2) == "./") {
                     $line = substr($line, 2);
                 }
                 $this->parse_variables_in_string($line, $pass_arguments);
                 $cd_dir = $this->var_current_directory;
                 if (phodevi::is_windows() && strpos($cd_dir, ':\\') === 1) {
                     $cd_dir = str_replace('/', '\\', $cd_dir);
                     $cd_dir = str_replace('\\\\', '\\', $cd_dir);
                 }
                 exec("cd " . $cd_dir . " && " . $line . " 2>&1", $exec_output, $prev_exit_status);
                 break;
         }
     } while ($script_contents != false);
 }
Esempio n. 9
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;
 }