public static function run($r)
 {
     foreach (pts_types::identifiers_to_test_profile_objects($r, true, true) as $test_profile) {
         pts_client::$display->generic_heading($test_profile);
         pts_validation::validate_test_profile($test_profile);
     }
 }
 public static function run($r)
 {
     if (($test_suite = pts_types::identifier_to_object($r[0])) != false) {
         pts_client::$display->generic_heading($r[0]);
         pts_validation::validate_test_suite($test_suite);
     }
 }
 public static function run($r)
 {
     if (pts_result_file::is_test_result_file($r[0])) {
         $result_file = new pts_result_file($r[0]);
         pts_client::$display->generic_heading($r[0]);
         $valid = $result_file->validate();
         if ($valid == false) {
             echo PHP_EOL . 'Errors occurred parsing the main XML.' . PHP_EOL;
             pts_validation::process_libxml_errors();
             return false;
         } else {
             echo PHP_EOL . 'The result file is Valid.' . PHP_EOL;
         }
     }
 }
 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 validate_test_profile(&$test_profile)
 {
     if ($test_profile->get_file_location() == null) {
         echo PHP_EOL . 'ERROR: The file location of the XML test profile source could not be determined.' . PHP_EOL;
         return false;
     }
     // Validate the XML against the XSD Schemas
     libxml_clear_errors();
     // Now re-create the pts_test_profile object around the rewritten XML
     $test_profile = new pts_test_profile($test_profile->get_identifier());
     $valid = $test_profile->validate();
     if ($valid == false) {
         echo PHP_EOL . 'Errors occurred parsing the main XML.' . PHP_EOL;
         pts_validation::process_libxml_errors();
         return false;
     }
     // Rewrite the main XML file to ensure it is properly formatted, elements are ordered according to the schema, etc...
     $test_profile_writer = new pts_test_profile_writer();
     $test_profile_writer->rebuild_test_profile($test_profile);
     $test_profile_writer->save_xml($test_profile->get_file_location());
     // Now re-create the pts_test_profile object around the rewritten XML
     $test_profile = new pts_test_profile($test_profile->get_identifier());
     $valid = $test_profile->validate();
     if ($valid == false) {
         echo PHP_EOL . 'Errors occurred parsing the main XML.' . PHP_EOL;
         pts_validation::process_libxml_errors();
         return false;
     } else {
         echo PHP_EOL . 'Test Profile XML Is Valid.' . PHP_EOL;
     }
     // Validate the downloads file
     $download_xml_file = $test_profile->get_file_download_spec();
     if (empty($download_xml_file) == false) {
         $writer = new pts_test_profile_downloads_writer();
         $writer->rebuild_download_file($test_profile);
         $writer->save_xml($download_xml_file);
         $downloads_parser = new pts_test_downloads_nye_XmlReader($download_xml_file);
         $valid = $downloads_parser->validate();
         if ($valid == false) {
             echo PHP_EOL . 'Errors occurred parsing the downloads XML.' . PHP_EOL;
             pts_validation::process_libxml_errors();
             return false;
         } else {
             echo PHP_EOL . 'Test Downloads XML Is Valid.' . PHP_EOL;
         }
         // Validate the individual download files
         echo PHP_EOL . 'Testing File Download URLs.' . PHP_EOL;
         $files_missing = 0;
         $file_count = 0;
         foreach (pts_test_install_request::read_download_object_list($test_profile) as $download) {
             foreach ($download->get_download_url_array() as $url) {
                 $stream_context = pts_network::stream_context_create();
                 stream_context_set_params($stream_context, array('notification' => 'pts_stream_status_callback'));
                 $file_pointer = fopen($url, 'r', false, $stream_context);
                 if ($file_pointer == false) {
                     echo 'File Missing: ' . $download->get_filename() . ' / ' . $url . PHP_EOL;
                     $files_missing++;
                 } else {
                     fclose($file_pointer);
                 }
                 $file_count++;
             }
         }
         if ($files_missing > 0) {
             return false;
         }
     }
     // Validate the parser file
     $parser_file = $test_profile->get_file_parser_spec();
     if (empty($parser_file) == false) {
         $writer = self::rebuild_result_parser_file($parser_file);
         $writer->saveXMLFile($parser_file);
         $parser = new pts_parse_results_nye_XmlReader($parser_file);
         $valid = $parser->validate();
         if ($valid == false) {
             echo PHP_EOL . 'Errors occurred parsing the results parser XML.' . PHP_EOL;
             pts_validation::process_libxml_errors();
             return false;
         } else {
             echo PHP_EOL . 'Test Results Parser XML Is Valid.' . PHP_EOL;
         }
     }
     // Make sure no extra files are in there
     $allowed_files = pts_validation::test_profile_permitted_files();
     foreach (pts_file_io::glob($test_profile->get_resource_dir() . '*') as $tp_file) {
         if (!is_file($tp_file) || !in_array(basename($tp_file), $allowed_files)) {
             echo PHP_EOL . basename($tp_file) . ' is not allowed in the test package.' . PHP_EOL;
             return false;
         }
     }
     return true;
 }