public function get_download_size($include_extensions = true, $divider = 1048576)
 {
     $estimated_size = 0;
     foreach (pts_test_install_request::read_download_object_list($this->identifier) as $download_object) {
         $estimated_size += $download_object->get_filesize();
     }
     if ($include_extensions) {
         $extends = $this->get_test_extension();
         if (!empty($extends)) {
             $test_profile = new pts_test_profile($extends);
             $estimated_size += $test_profile->get_download_size(true, 1);
         }
     }
     $estimated_size = $estimated_size > 0 && $divider > 1 ? round($estimated_size / $divider, 2) : 0;
     return $estimated_size;
 }
 public static function run($r)
 {
     foreach (pts_types::identifiers_to_test_profile_objects($r, true, true) as $test_profile) {
         echo 'Checking: ' . $test_profile . PHP_EOL;
         foreach (pts_test_install_request::read_download_object_list($test_profile) as $test_file_download) {
             foreach ($test_file_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);
                 //fread($file_pointer, 1024);
                 if ($file_pointer == false) {
                     echo PHP_EOL . 'BAD URL: ' . $test_file_download->get_filename() . ' / ' . $url . PHP_EOL;
                 } else {
                     @fclose($file_pointer);
                 }
             }
         }
     }
 }
 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;
 }
 public function rebuild_download_file(&$test_profile)
 {
     foreach (pts_test_install_request::read_download_object_list($test_profile, false) as $file) {
         $this->add_download($file->get_download_url_string(), $file->get_md5(), $file->get_sha256(), $file->get_filename(), $file->get_filesize(), $file->get_platform_string(), $file->get_architecture_string());
     }
 }
 public static function run($r)
 {
     // Force refresh of OB repository to ensure the latest profiles
     pts_openbenchmarking::refresh_repository_lists(null, true);
     // Determine cache location
     $dc_write_directory = pts_strings::add_trailing_slash(pts_strings::parse_for_home_directory(pts_config::read_user_config('PhoronixTestSuite/Options/Installation/CacheDirectory', PTS_DOWNLOAD_CACHE_PATH)));
     echo PHP_EOL . 'Download Cache Directory: ' . $dc_write_directory . PHP_EOL;
     if ($dc_write_directory == null || !is_writable($dc_write_directory)) {
         echo 'No writable download cache directory was found. A download cache cannot be created.' . PHP_EOL . PHP_EOL;
         return false;
     }
     if (!empty($r)) {
         $test_profiles = pts_types::identifiers_to_test_profile_objects($r, true, true);
         if (count($test_profiles) > 0) {
             echo PHP_EOL . 'Downloading Test Files For: ' . implode(' ', $test_profiles);
             pts_test_installer::only_download_test_files($test_profiles, $dc_write_directory);
         }
     }
     $json_download_cache = array('phoronix-test-suite' => array('main' => array('generated' => time()), 'download-cache' => array()));
     foreach (pts_tests::partially_installed_tests() as $test) {
         $test_profile = new pts_test_profile($test);
         echo PHP_EOL . 'Checking Downloads For: ' . $test . PHP_EOL;
         foreach (pts_test_install_request::read_download_object_list($test_profile, false) as $file) {
             $cached_valid = false;
             if (is_file($dc_write_directory . $file->get_filename()) && $file->check_file_hash($dc_write_directory . $file->get_filename())) {
                 echo '   Previously Cached: ' . $file->get_filename() . PHP_EOL;
                 $cached_valid = true;
             } else {
                 if (is_dir($test_profile->get_install_dir())) {
                     if (is_file($test_profile->get_install_dir() . $file->get_filename()) && $file->check_file_hash($test_profile->get_install_dir() . $file->get_filename())) {
                         echo '   Caching: ' . $file->get_filename() . PHP_EOL;
                         if (copy($test_profile->get_install_dir() . $file->get_filename(), $dc_write_directory . $file->get_filename())) {
                             $cached_valid = true;
                         }
                     }
                 }
             }
             if ($cached_valid) {
                 if (!isset($json_download_cache['phoronix-test-suite']['download-cache'][$file->get_filename()])) {
                     $json_download_cache['phoronix-test-suite']['download-cache'][$file->get_filename()] = array('file_name' => $file->get_filename(), 'file_size' => $file->get_filesize(), 'associated_tests' => array($test_profile->get_identifier()), 'md5' => $file->get_md5(), 'sha256' => $file->get_sha256());
                 } else {
                     if ($file->get_md5() == $json_download_cache['phoronix-test-suite']['download-cache'][$file->get_filename()]['md5'] && $file->get_sha256() == $json_download_cache['phoronix-test-suite']['download-cache'][$file->get_filename()]['sha256']) {
                         array_push($json_download_cache['phoronix-test-suite']['download-cache'][$file->get_filename()]['associated_tests'], $test_profile->get_identifier());
                     }
                 }
             }
         }
     }
     // Find files in download-cache/ that weren't part of an installed test (but could have just been tossed in there) to cache
     foreach (glob($dc_write_directory . '/*') as $cached_file) {
         $file_name = basename($cached_file);
         if (!isset($json_download_cache['phoronix-test-suite']['download-cache'][$file_name]) && $file_name != 'pts-download-cache.json') {
             $json_download_cache['phoronix-test-suite']['download-cache'][$file_name] = array('file_name' => $file_name, 'file_size' => filesize($cached_file), 'associated_tests' => array(), 'md5' => md5_file($cached_file), 'sha256' => hash_file('sha256', $cached_file));
         }
     }
     $cached_tests = array();
     foreach (pts_openbenchmarking::available_tests(true, true) as $test) {
         if (pts_test_install_request::test_files_in_cache($test, true, true) == false) {
             continue;
         }
         array_push($cached_tests, $test);
     }
     $json_download_cache['phoronix-test-suite']['cached-tests'] = $cached_tests;
     file_put_contents($dc_write_directory . 'pts-download-cache.json', json_encode($json_download_cache, defined('JSON_PRETTY_PRINT') ? JSON_PRETTY_PRINT : 0));
     echo PHP_EOL;
 }
 public static function render_page_process($PATH)
 {
     $test_version = self::$test_profile->get_app_version();
     $test_title = self::$test_profile->get_title() . ($test_version != null ? ' ' . $test_version : null);
     echo '<h1>' . $test_title . '</h1>';
     echo '<div id="test_main_area">';
     echo '<p>' . self::$test_profile->get_description() . '</p>';
     echo '<h4 style="margin-top: 60px;">Run This Test</h4>';
     echo '<div id="pts_add_test_area">';
     $test_settings = array();
     $test_options = self::$test_profile->get_test_option_objects();
     $identifiers = array();
     for ($i = 0; $i < count($test_options); $i++) {
         $o = $test_options[$i];
         $option_count = $o->option_count();
         $test_prefix = 'test_option_';
         $option_name = $o->get_name();
         if ($option_count == 0) {
             $option_value = '<input type="text" id="' . $test_prefix . $o->get_identifier() . '" />';
         } else {
             $option_value = '<select id="' . $test_prefix . $o->get_identifier() . '">';
             for ($j = 0; $j < $option_count; $j++) {
                 $option_value .= '<option value="' . $o->format_option_value_from_input($o->get_option_value($j)) . '">' . $o->get_option_name($j) . '</option>';
             }
             $option_value .= '</select>';
         }
         $identifiers[] = $o->get_identifier();
         echo '<input id="' . $test_prefix . $o->get_identifier() . '_title" type="hidden" value="' . $option_name . '" />';
         $test_settings[] = array($option_name, $option_value);
     }
     $test_settings[] = array('<input type="Submit" value="Add Test To Run Queue" onclick="test_add_to_queue(\'' . (isset($test_prefix) ? $test_prefix : "") . '\', \'' . implode(':', $identifiers) . '\', \'' . self::$test_profile->get_identifier() . '\', \'' . base64_encode(json_encode(self::$test_profile->to_json())) . '\'); return false;" />');
     echo pts_webui::r2d_array_to_table($test_settings);
     echo '</div>';
     echo '</div>';
     echo '<div id="test_side_area">';
     $tabular_info = array(array('Test Profile', self::$test_profile->get_identifier()), array('Maintainer', self::$test_profile->get_maintainer()), array('Test Type', self::$test_profile->get_test_hardware_type()), array('Software Type', self::$test_profile->get_test_software_type()), array('License Type', self::$test_profile->get_license()), array('Test Status', self::$test_profile->get_status()));
     $project_url = self::$test_profile->get_project_url();
     $project_url = parse_url($project_url);
     if ($project_url != null && isset($project_url['host'])) {
         $tabular_info[] = array('Project Site', '<a href="' . self::$test_profile->get_project_url() . '" target="_blank">' . $project_url['host'] . '</a>');
     }
     echo '<h4>Test Profile Information</h4>';
     echo pts_webui::r2d_array_to_table($tabular_info);
     $tabular_info = array();
     if (self::$test_profile->get_estimated_run_time() > 1) {
         $tabular_info[] = array('Estimated Test Run-Time', pts_strings::plural_handler(ceil(self::$test_profile->get_estimated_run_time() / 60), 'Minute'));
     }
     $download_size = self::$test_profile->get_download_size();
     if (!empty($download_size)) {
         $tabular_info[] = array('Download Size', $download_size . ' MB');
     }
     $environment_size = self::$test_profile->get_environment_size();
     if (!empty($environment_size)) {
         $tabular_info[] = array('Environment Size', $environment_size . ' MB');
     }
     if (self::$test_profile->test_installation != false) {
         $last_run = self::$test_profile->test_installation->get_last_run_date();
         $last_run = $last_run == '0000-00-00' ? 'Never' : date('j F Y', strtotime($last_run));
         $avg_time = self::$test_profile->test_installation->get_average_run_time();
         $avg_time = !empty($avg_time) ? pts_strings::format_time($avg_time, 'SECONDS') : null;
         $latest_time = self::$test_profile->test_installation->get_latest_run_time();
         $latest_time = !empty($latest_time) ? pts_strings::format_time($latest_time, 'SECONDS') : 'N/A';
         $tabular_info[] = array('Last Local Run', $last_run);
         if ($last_run != 'Never') {
             if (self::$test_profile->test_installation->get_run_count() > 1) {
                 $tabular_info[] = array('Average Local Run-Time', $avg_time);
             }
             if ($latest_time != null) {
                 $tabular_info[] = array('Latest Local Run-Time', $latest_time);
             }
             if (self::$test_profile->test_installation->get_run_count() > 0) {
                 $tabular_info[] = array('Times Run Locally', self::$test_profile->test_installation->get_run_count());
             }
         }
     }
     echo '<h4>Installation Data</h4>';
     echo pts_webui::r2d_array_to_table($tabular_info);
     $dependencies = self::$test_profile->get_dependency_names();
     if (!empty($dependencies) && !empty($dependencies[0])) {
         array_unshift($dependencies, 'Test Dependencies');
         pts_webui::r1d_array_to_table($dependencies);
     }
     if (self::$test_profile->test_installation == false) {
         $files = pts_test_install_request::read_download_object_list(self::$test_profile);
         if (count($files) > 0) {
             $download_files = array('Test Files');
             foreach ($files as &$file) {
                 $download_files[] = $file->get_filename() . ' [' . max(0.1, round($file->get_filesize() / 1048576, 1)) . 'MB]';
             }
             pts_webui::r1d_array_to_table($download_files);
         }
     }
     echo '</div>';
 }