public static function client_commands_array()
 {
     $options = array('Test Installation' => array(), 'Testing' => array(), 'Batch Testing' => array(), 'OpenBenchmarking.org' => array(), 'System' => array(), 'Information' => array(), 'Asset Creation' => array(), 'Result Management' => array(), 'Result Analytics' => array(), 'Other' => array());
     foreach (pts_file_io::glob(PTS_COMMAND_PATH . '*.php') as $option_php_file) {
         $option_php = basename($option_php_file, '.php');
         $name = str_replace('_', '-', $option_php);
         if (!in_array(pts_strings::first_in_string($name, '-'), array('dump', 'task'))) {
             include_once $option_php_file;
             $reflect = new ReflectionClass($option_php);
             $constants = $reflect->getConstants();
             $doc_description = isset($constants['doc_description']) ? constant($option_php . '::doc_description') : 'No summary is available.';
             $doc_section = isset($constants['doc_section']) ? constant($option_php . '::doc_section') : 'Other';
             $name = isset($constants['doc_use_alias']) ? constant($option_php . '::doc_use_alias') : $name;
             $skip = isset($constants['doc_skip']) ? constant($option_php . '::doc_skip') : false;
             $doc_args = array();
             if ($skip) {
                 continue;
             }
             if (method_exists($option_php, 'argument_checks')) {
                 $doc_args = call_user_func(array($option_php, 'argument_checks'));
             }
             if (!empty($doc_section) && !isset($options[$doc_section])) {
                 $options[$doc_section] = array();
             }
             array_push($options[$doc_section], array($name, $doc_args, $doc_description));
         }
     }
     return $options;
 }
 public static function run($r)
 {
     pts_client::$display->generic_heading('Available Tests');
     $test_count = 0;
     foreach (pts_openbenchmarking::available_tests(false) as $identifier) {
         $repo = substr($identifier, 0, strpos($identifier, '/'));
         $id = substr($identifier, strlen($repo) + 1);
         $repo_index = pts_openbenchmarking::read_repository_index($repo);
         if (!in_array(phodevi::operating_system(), $repo_index['tests'][$id]['supported_platforms']) || empty($repo_index['tests'][$id]['title'])) {
             // Don't show unsupported tests
             continue;
         }
         echo sprintf('%-30ls - %-35ls %-9ls', $identifier, $repo_index['tests'][$id]['title'], $repo_index['tests'][$id]['test_type']) . PHP_EOL;
         $test_count++;
     }
     foreach (pts_file_io::glob(PTS_TEST_PROFILE_PATH . 'local/*/test-definition.xml') as $path) {
         $test_profile = new pts_test_profile('local/' . basename(dirname($path)));
         if ($test_profile->get_title() != null && $test_profile->is_supported(false)) {
             echo sprintf('%-30ls - %-35ls %-9ls', $test_profile->get_identifier(), $test_profile->get_title(), $test_profile->get_test_hardware_type()) . PHP_EOL;
             $test_count++;
         }
     }
     if ($test_count == 0) {
         echo PHP_EOL . 'No tests found. Please check that you have Internet connectivity to download test profile data from OpenBenchmarking.org. The Phoronix Test Suite has documentation on configuring the network setup, proxy settings, and PHP network options. Please contact Phoronix Media if you continuing to experience problems.' . PHP_EOL . PHP_EOL;
     }
 }
 public static function render_page_process($PATH)
 {
     $suite_dir = phoromatic_server::phoromatic_account_suite_path($_SESSION['AccountID']);
     $main = '<h1>Local Suites</h1><p>These are test suites created by you or another account within your group. Suites are an easy collection of test profiles. New suits can be trivially made via the <a href="/?build_suite">build suite</a> page.</p>';
     $suite_count = 0;
     foreach (pts_file_io::glob($suite_dir . '*/suite-definition.xml') as $xml_path) {
         $suite_count++;
         $id = basename(dirname($xml_path));
         $test_suite = new pts_test_suite($xml_path);
         $main .= '<a name="' . $id . '"></a><h1>' . $test_suite->get_title() . ' [' . $id . ']</h1>';
         $main .= '<p><strong>' . $test_suite->get_maintainer() . '</strong></p>';
         $main .= '<p><em>' . $test_suite->get_description() . '</em></p>';
         $main .= '<div style="max-height: 200px; overflow-y: scroll;">';
         foreach ($test_suite->get_contained_test_result_objects() as $tro) {
             $main .= '<h3>' . $tro->test_profile->get_title() . ' [' . $tro->test_profile->get_identifier() . ']</h3>';
             $main .= '<p>' . $tro->get_arguments_description() . '</p>';
         }
         $main .= '</div>';
         $main .= '<hr />';
     }
     if ($suite_count == 0) {
         $main .= '<h1>No Test Suites Found</h1>';
     }
     echo phoromatic_webui_header_logged_in();
     echo '<div id="pts_phoromatic_main_area">' . $main . '</div>';
     echo phoromatic_webui_footer();
 }
 protected function get_real_path($path, &$pass_arguments = null)
 {
     if ($path == "\$LOG_FILE") {
         return $this->environmental_variables["LOG_FILE"];
     }
     $this->parse_variables_in_string($path, $pass_arguments);
     if (substr($path, 0, 1) == '~') {
         $path = $this->environmental_variables["HOME"] . substr($path, 2);
     }
     if (strpos($path, '*') !== false) {
         $grep_dir = pts_strings::add_trailing_slash(str_replace('"', null, $this->var_current_directory));
         // needed for phodevi::is_windows() specviewperf10
         $glob = pts_file_io::glob($grep_dir . $path);
         return count($glob) > 0 ? array_shift($glob) : $this->var_current_directory;
     } else {
         if (is_file($path)) {
             return $path;
         } else {
             if (is_file($this->var_current_directory . $path)) {
                 return $this->var_current_directory . $path;
             } else {
                 return pts_strings::add_trailing_slash($this->var_current_directory . $path);
             }
         }
     }
 }
 public static function delete($object, $ignore_files = null, $remove_root_directory = false)
 {
     // Delete files and/or directories
     if ($object == false) {
         return false;
     }
     if (is_dir($object)) {
         $object = pts_strings::add_trailing_slash($object);
     }
     foreach (pts_file_io::glob($object . '*') as $to_remove) {
         if (is_file($to_remove) || is_link($to_remove)) {
             if (is_array($ignore_files) && in_array(basename($to_remove), $ignore_files)) {
                 continue;
                 // Don't remove the file
             } else {
                 unlink($to_remove);
             }
         } else {
             if (is_dir($to_remove)) {
                 self::delete($to_remove, $ignore_files, true);
             }
         }
     }
     if ($remove_root_directory && is_dir($object) && count(pts_file_io::glob($object . '/*')) == 0) {
         rmdir($object);
     }
 }
 public function get_vendors_list()
 {
     $package_files = pts_file_io::glob(PTS_EXDEP_PATH . 'xml/*-packages.xml');
     foreach ($package_files as &$file) {
         $file = basename(substr($file, 0, strpos($file, '-packages.xml')));
     }
     return $package_files;
 }
 public static function run($r)
 {
     $identifier = $r[0];
     $test_xml_files = pts_file_io::glob(PTS_SAVE_RESULTS_PATH . $identifier . '/test-*.xml');
     if (count($test_xml_files) == 0) {
         echo PHP_EOL . 'No test XML data was found.' . PHP_EOL;
         return false;
     }
     pts_client::save_test_result($identifier . '/composite.xml', pts_merge::merge_test_results_array($test_xml_files));
     pts_client::regenerate_graphs($identifier, 'The ' . $identifier . ' result file XML has been rebuilt.');
 }
 public static function run($r)
 {
     $options = array();
     foreach (pts_file_io::glob(PTS_COMMAND_PATH . '*.php') as $option_php) {
         $name = str_replace('_', '-', basename($option_php, '.php'));
         if (!in_array(pts_strings::first_in_string($name, '-'), array('dump', 'debug', 'task'))) {
             array_push($options, $name);
         }
     }
     $is_true = isset($r[0]) && $r[0] == 'TRUE';
     echo implode($is_true ? ' ' : PHP_EOL, $options) . ($is_true ? null : PHP_EOL);
 }
 public static function get_supported_devices()
 {
     if (phodevi::is_linux()) {
         $blockdev_dir = '/sys/block/';
         $glob_regex = '{[shvm]d*,nvme*,mmcblk*}';
         $disk_array = pts_file_io::glob($blockdev_dir . $glob_regex, GLOB_BRACE);
         $supported = array();
         foreach ($disk_array as $check_disk) {
             $stat_path = $check_disk . '/stat';
             if (is_file($stat_path) && pts_file_io::file_get_contents($stat_path) != null) {
                 array_push($supported, basename($check_disk));
             }
         }
         return $supported;
     }
     return NULL;
 }
 public static function audio_processor_string()
 {
     $audio = null;
     if (phodevi::is_macosx()) {
         // TODO: implement
     } else {
         if (phodevi::is_bsd()) {
             foreach (array('dev.hdac.0.%desc') as $dev) {
                 $dev = phodevi_bsd_parser::read_sysctl($dev);
                 if (!empty($dev)) {
                     $audio = $dev;
                 }
             }
         } else {
             if (phodevi::is_windows()) {
                 // TODO: implement
             } else {
                 if (phodevi::is_linux()) {
                     foreach (pts_file_io::glob('/sys/class/sound/card*/hwC0D*/vendor_name') as $vendor_name) {
                         $card_dir = dirname($vendor_name) . '/';
                         if (!is_readable($card_dir . 'chip_name')) {
                             continue;
                         }
                         $vendor_name = pts_file_io::file_get_contents($vendor_name);
                         $chip_name = pts_file_io::file_get_contents($card_dir . 'chip_name');
                         $audio = $vendor_name . ' ' . $chip_name;
                         if (strpos($chip_name, 'HDMI') !== false || strpos($chip_name, 'DP') !== false) {
                             // If HDMI is in the audio string, likely the GPU-provided audio, so try to find the mainboard otherwise
                             $audio = null;
                         } else {
                             break;
                         }
                     }
                     if ($audio == null) {
                         $audio = phodevi_linux_parser::read_pci('Multimedia audio controller');
                     }
                     if ($audio == null) {
                         $audio = phodevi_linux_parser::read_pci('Audio device');
                     }
                 }
             }
         }
     }
     return $audio;
 }
 public static function read_sensor()
 {
     // speed in MB/s
     $speed = -1;
     if (phodevi::is_linux()) {
         static $sys_disk = null;
         if ($sys_disk == null) {
             foreach (pts_file_io::glob('/sys/class/block/sd*/stat') as $check_disk) {
                 if (pts_file_io::file_get_contents($check_disk) != null) {
                     $sys_disk = $check_disk;
                     break;
                 }
             }
         }
         $speed = phodevi_linux_parser::read_sys_disk_speed($sys_disk, 'READ');
     }
     return $speed;
 }
Esempio n. 12
0
 public static function read_sensor()
 {
     // Report graphics processor temperature
     $temp_c = -1;
     if (phodevi::is_nvidia_graphics()) {
         $temp_c = phodevi_parser::read_nvidia_extension('GPUCoreTemp');
     } else {
         if (phodevi::is_ati_graphics() && phodevi::is_linux()) {
             $temp_c = phodevi_linux_parser::read_ati_overdrive('Temperature');
         } else {
             foreach (array_merge(array('/sys/class/drm/card0/device/temp1_input'), pts_file_io::glob('/sys/class/drm/card0/device/hwmon/hwmon*/temp1_input')) as $temp_input) {
                 // This works for at least Nouveau driver with Linux 2.6.37 era DRM
                 if (is_readable($temp_input) == false) {
                     continue;
                 }
                 $temp_input = pts_file_io::file_get_contents($temp_input);
                 if (is_numeric($temp_input)) {
                     if ($temp_input > 1000) {
                         $temp_input /= 1000;
                     }
                     $temp_c = $temp_input;
                     break;
                 }
             }
             if ($temp_c == -1 && is_readable('/sys/kernel/debug/dri/0/i915_emon_status')) {
                 // Intel thermal
                 $i915_emon_status = file_get_contents('/sys/kernel/debug/dri/0/i915_emon_status');
                 $temp = strpos($i915_emon_status, 'GMCH temp: ');
                 if ($temp !== false) {
                     $temp = substr($i915_emon_status, $temp + 11);
                     $temp = substr($temp, 0, strpos($temp, PHP_EOL));
                     if (is_numeric($temp) && $temp > 0) {
                         $temp_c = $temp;
                     }
                 }
             }
         }
     }
     if ($temp_c > 1000 || $temp_c < 9) {
         // Invalid data
         return -1;
     }
     return $temp_c;
 }
 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 render_page_process($PATH)
    {
        echo phoromatic_webui_header_logged_in();
        $main = '<h1>Cache Settings</h1>
				<h2>Test Profile Download Cache</h2>
				<p>Below are a list of files for verification/debugging purposes that are currently cached by the Phoromatic Server and available for Phoronix Test Suite client systems to download. These are files that are needed by various test profiles in the Phoronix Test Suite. To add more data to this Phoromatic Server cache, from the server run <strong>phoronix-test-suite make-download-cache</strong> while passing the names of any tests/suites you wish to have download and generate a cache for so they can be made available to the Phoronix Test Suite clients on your network.</p>';
        $dc = pts_strings::add_trailing_slash(pts_strings::parse_for_home_directory(pts_config::read_user_config('PhoronixTestSuite/Options/Installation/CacheDirectory', PTS_DOWNLOAD_CACHE_PATH)));
        $dc_exists = is_file($dc . 'pts-download-cache.json');
        if ($dc_exists) {
            $cache_json = file_get_contents($dc . 'pts-download-cache.json');
            $cache_json = json_decode($cache_json, true);
        }
        if (is_file($dc . 'pts-download-cache.json')) {
            if ($cache_json && isset($cache_json['phoronix-test-suite']['download-cache'])) {
                $total_file_size = 0;
                $main .= '<table style="margin: 0 auto;"><tr><th>File</th><th>Size</th></tr>';
                foreach ($cache_json['phoronix-test-suite']['download-cache'] as $file_name => $inf) {
                    $total_file_size += $cache_json['phoronix-test-suite']['download-cache'][$file_name]['file_size'];
                    $main .= '<tr><td>' . $file_name . '</td><td>' . round(max(0.1, $cache_json['phoronix-test-suite']['download-cache'][$file_name]['file_size'] / 1000000), 1) . 'MB</td></tr>';
                }
                $main .= '</table>';
                $main .= '<p><strong>' . count($cache_json['phoronix-test-suite']['download-cache']) . ' Files / ' . round($total_file_size / 1000000) . ' MB Cache Size</strong></p>';
            }
        } else {
            $main .= '<h3>No download cache file could be found; on the Phoromatic Server you should run <strong>phoronix-test-suite make-download-cache</strong>.</h3>';
            // TODO XXX implement from the GUI
        }
        $main .= '<hr /><h2>OpenBenchmarking.org Cache Data</h2>';
        $main .= '<p>Below is information pertaining to the OpenBenchmarking.org cache present on the Phoromatic Server. To update this cache, run <strong>phoronix-test-suite make-openbenchmarking-cache</strong> from the server.</p>';
        $index_files = pts_file_io::glob(PTS_OPENBENCHMARKING_SCRATCH_PATH . '*.index');
        $main .= '<table style="margin: 0 auto;"><tr><th>Repository</th><th>Last Updated</th></tr>';
        foreach ($index_files as $index_file) {
            $index_data = json_decode(file_get_contents($index_file), true);
            $main .= '<tr><td>' . basename($index_file, '.index') . '</td><td>' . date('d F Y H:i', $index_data['main']['generated']) . '</td></tr>';
        }
        $main .= '</table>';
        echo phoromatic_webui_main($main, phoromatic_webui_right_panel_logged_in());
        echo phoromatic_webui_footer();
    }
 protected static function search_local_test_suites($q)
 {
     $ret = null;
     $suite_dir = phoromatic_server::phoromatic_account_suite_path($_SESSION['AccountID']);
     foreach (pts_file_io::glob($suite_dir . '*/suite-definition.xml') as $xml_path) {
         $id = basename(dirname($xml_path));
         $test_suite = new pts_test_suite($xml_path);
         $match = false;
         if (stripos($test_suite->get_title(), $q) === 0 || stripos($test_suite->get_description(), $q) !== false) {
             $match = true;
         } else {
             foreach ($test_suite->get_contained_test_result_objects() as $tro) {
                 if (stripos($tro->test_profile->get_identifier(), $q) !== false || stripos($tro->test_profile->get_title(), $q) === 0) {
                     $match = true;
                 }
             }
         }
         if ($match) {
             $ret .= '<h3>' . $test_suite->get_title() . '</h3><p>' . $test_suite->get_description() . '<br /><a href="/?local_suites#' . $id . '">More Details</a></p>';
         }
     }
     return $ret;
 }
Esempio n. 16
0
 private static function select_drive_mount()
 {
     $drives = pts_file_io::glob('/dev/sd*');
     if (count($drives) == 0) {
         echo PHP_EOL . 'No Disk Drives Found' . PHP_EOL . PHP_EOL;
     } else {
         array_push($drives, 'No HDD');
         $to_mount = pts_user_io::prompt_text_menu('Select Drive / Partition To Mount', $drives);
         if ($to_mount != 'No HDD') {
             echo PHP_EOL . 'Attempting to mount: ' . $to_mount . PHP_EOL;
             exec('umount /media/pts-auto-mount 2>&1');
             pts_file_io::delete('/media/pts-auto-mount', null, true);
             pts_file_io::mkdir('/media/pts-auto-mount');
             echo exec('mount ' . $to_mount . ' /media/pts-auto-mount');
             putenv('PTS_TEST_INSTALL_ROOT_PATH=/media/pts-auto-mount/');
         } else {
             if (is_dir('/media/pts-auto-mount')) {
                 exec('umount /media/pts-auto-mount');
                 @rmdir('/media/pts-auto-mount');
             }
             putenv('PTS_TEST_INSTALL_ROOT_PATH=');
         }
     }
 }
 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 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)
 {
     $pdf = new pts_pdf_template(pts_title(false), 'Test Client Documentation');
     $html_doc = new pts_html_template(pts_title(false), 'Test Client Documentation');
     $pdf->AddPage();
     $pdf->Image(PTS_CORE_STATIC_PATH . 'images/pts-308x160.png', 69, 85, 73, 38, 'PNG', 'http://www.phoronix-test-suite.com/');
     $pdf->Ln(120);
     $pdf->WriteStatement('www.phoronix-test-suite.com', 'C', 'http://www.phoronix-test-suite.com/');
     $pdf->Ln(15);
     $pdf->WriteBigHeaderCenter(pts_title(true));
     $pdf->WriteHeaderCenter('User Manual');
     //$pdf->WriteText($result_file->get_description());
     $pts_options = pts_documentation::client_commands_array();
     // Write the test options HTML
     $dom = new DOMDocument();
     $html = $dom->createElement('html');
     $dom->appendChild($html);
     $head = $dom->createElement('head');
     $title = $dom->createElement('title', 'User Options');
     $head->appendChild($title);
     $html->appendChild($head);
     $body = $dom->createElement('body');
     $html->appendChild($body);
     $p = $dom->createElement('p', 'The following options are currently supported by the Phoronix Test Suite client. A list of available options can also be found by running ');
     $em = $dom->createElement('em', 'phoronix-test-suite help.');
     $p->appendChild($em);
     $phr = $dom->createElement('hr');
     $p->appendChild($phr);
     $body->appendChild($p);
     foreach ($pts_options as $section => &$contents) {
         if (empty($contents)) {
             continue;
         }
         $header = $dom->createElement('h1', $section);
         $body->appendChild($header);
         sort($contents);
         foreach ($contents as &$option) {
             $sub_header = $dom->createElement('h3', $option[0]);
             $em = $dom->CreateElement('em', '  ' . implode(' ', $option[1]));
             $sub_header->appendChild($em);
             $body->appendChild($sub_header);
             $p = $dom->createElement('p', $option[2]);
             $body->appendChild($p);
         }
     }
     $dom->saveHTMLFile(PTS_PATH . 'documentation/stubs/00_user_options.html');
     // Write the module options HTML
     $dom = new DOMDocument();
     $html = $dom->createElement('html');
     $dom->appendChild($html);
     $head = $dom->createElement('head');
     $title = $dom->createElement('title', 'Module Options');
     $head->appendChild($title);
     $html->appendChild($head);
     $body = $dom->createElement('body');
     $html->appendChild($body);
     $p = $dom->createElement('p', 'The following list is the modules included with the Phoronix Test Suite that are intended to extend the functionality of pts-core. Some of these options have commands that can be run directly in a similiar manner to the other Phoronix Test Suite user commands. Some modules are just meant to be loaded directly by adding the module name to the LoadModules tag in ~/.phoronix-test-suite/user-config.xml or via the PTS_MODULES environmental variable. A list of available modules is also available by running ');
     $em = $dom->createElement('em', 'phoronix-test-suite list-modules.');
     $p->appendChild($em);
     $phr = $dom->createElement('hr');
     $p->appendChild($phr);
     $body->appendChild($p);
     foreach (pts_module_manager::available_modules(true) as $module) {
         pts_module_manager::load_module($module);
         $header = $dom->createElement('h2', pts_module_manager::module_call($module, 'module_name'));
         $body->appendChild($header);
         $desc = $dom->createElement('p', pts_module_manager::module_call($module, 'module_description'));
         $body->appendChild($desc);
         $all_options = pts_module_manager::module_call($module, 'user_commands');
         if (count($all_options) > 0) {
             //	$sub_header = $dom->createElement('h3', 'Module Commands');
             //	$body->appendChild($sub_header);
             foreach ($all_options as $key => $option) {
                 $p = $dom->createElement('p', 'phoronix-test-suite ' . $module . '.' . str_replace('_', '-', $key));
                 $body->appendChild($p);
             }
         }
         $vars = pts_module_manager::module_call($module, 'module_environmental_variables');
         if (is_array($vars) && count($vars) > 0) {
             $p = $dom->createElement('p', 'This module utilizes the following environmental variables: ' . implode(', ', $vars) . '.');
             $body->appendChild($p);
         }
     }
     $dom->saveHTMLFile(PTS_PATH . 'documentation/stubs/00_zmodule_options.html');
     // Write the external dependencies HTML
     $dom = new DOMDocument();
     $html = $dom->createElement('html');
     $dom->appendChild($html);
     $head = $dom->createElement('head');
     $title = $dom->createElement('title', 'External Dependencies');
     $head->appendChild($title);
     $html->appendChild($head);
     $body = $dom->createElement('body');
     $html->appendChild($body);
     $p = $dom->createElement('p', 'The Phoronix Test Suite has a feature known as &quot;External Dependencies&quot; where the Phoronix Test Suite can attempt to automatically install some of the test-specific dependencies on supported distributions. If running on a distribution where there is currently no External Dependencies profile, the needed package name(s) are listed for manual installation.');
     $body->appendChild($p);
     $p = $dom->createElement('p', 'Below are a list of the operating systems that currently have external dependencies support within the Phoronix Test Suite for the automatic installation of needed test files.');
     $body->appendChild($p);
     $phr = $dom->createElement('hr');
     $p->appendChild($phr);
     $exdep_generic_parser = new pts_exdep_generic_parser();
     $vendors = array_merge($exdep_generic_parser->get_vendor_aliases_formatted(), $exdep_generic_parser->get_vendors_list_formatted());
     sort($vendors);
     $ul = $dom->createElement('ul');
     $p->appendChild($ul);
     foreach ($vendors as $vendor) {
         $li = $dom->createElement('li', $vendor);
         $p->appendChild($li);
     }
     $dom->saveHTMLFile(PTS_PATH . 'documentation/stubs/02_external_dependencies.html');
     // Write the virtual suites HTML
     $dom = new DOMDocument();
     $html = $dom->createElement('html');
     $dom->appendChild($html);
     $head = $dom->createElement('head');
     $title = $dom->createElement('title', 'Virtual Test Suites');
     $head->appendChild($title);
     $html->appendChild($head);
     $body = $dom->createElement('body');
     $html->appendChild($body);
     $p = $dom->createElement('p', 'Virtual test suites are not like a traditional test suite defined by the XML suite specification. Virtual test suites are dynamically generated in real-time by the Phoronix Test Suite client based upon the specified test critera. Virtual test suites can automatically consist of all test profiles that are compatible with a particular operating system or test profiles that meet other critera. When running a virtual suite, the OpenBenchmarking.org repository of the test profiles to use for generating the dynamic suite must be prefixed. ');
     $body->appendChild($p);
     $p = $dom->createElement('p', 'Virtual test suites can be installed and run just like a normal XML test suite and shares nearly all of the same capabilities. However, when running a virtual suite, the user will be prompted to input any user-configuration options for needed test profiles just as they would need to do if running the test individually. When running a virtual suite, the user also has the ability to select individual tests within the suite to run or to run all of the contained test profiles. Virtual test suites are also only supported for an OpenBenchmarking.org repository if there is no test profile or test suite of the same name in the repository. Below is a list of common virtual test suites for the main Phoronix Test Suite repository, but the dynamic list of available virtual test suites based upon the enabled repositories is available by running ');
     $em = $dom->createElement('em', 'phoronix-test-suite list-available-virtual-suites.');
     $p->appendChild($em);
     $phr = $dom->createElement('hr');
     $p->appendChild($phr);
     $body->appendChild($p);
     foreach (pts_virtual_test_suite::available_virtual_suites() as $virtual_suite) {
         $sub_header = $dom->createElement('h3', $virtual_suite->get_title());
         $em = $dom->CreateElement('em', '  ' . $virtual_suite->get_identifier());
         $sub_header->appendChild($em);
         $body->appendChild($sub_header);
         $p = $dom->createElement('p', $virtual_suite->get_description());
         $body->appendChild($p);
     }
     $dom->saveHTMLFile(PTS_PATH . 'documentation/stubs/55_virtual_suites.html');
     // Load the HTML documentation
     foreach (pts_file_io::glob(PTS_PATH . 'documentation/stubs/*_*.html') as $html_file) {
         $pdf->html_to_pdf($html_file);
         $html_doc->html_to_html($html_file);
     }
     if (!is_writable(PTS_PATH . 'documentation/')) {
         echo PHP_EOL . 'Not writable: ' . PTS_PATH . 'documentation/';
     } else {
         $pdf_file = PTS_PATH . 'documentation/phoronix-test-suite.pdf';
         $pdf->Output($pdf_file);
         $html_doc->Output(PTS_PATH . 'documentation/phoronix-test-suite.html');
         echo PHP_EOL . 'Saved To: ' . $pdf_file . PHP_EOL . PHP_EOL;
         // Also re-generate the man page
         $man_page = '.TH phoronix-test-suite 1  "www.phoronix-test-suite.com" "' . PTS_VERSION . '"' . PHP_EOL . '.SH NAME' . PHP_EOL;
         $man_page .= 'phoronix-test-suite \\- The Phoronix Test Suite is an extensible open-source platform for performing testing and performance evaluation.' . PHP_EOL;
         $man_page .= '.SH SYNOPSIS' . PHP_EOL . '.B phoronix-test-suite [options]' . PHP_EOL . '.br' . PHP_EOL . '.B phoronix-test-suite benchmark [test | suite]' . PHP_EOL;
         $man_page .= '.SH DESCRIPTION' . PHP_EOL . pts_documentation::basic_description() . PHP_EOL;
         $man_page .= '.SH OPTIONS' . PHP_EOL . '.TP' . PHP_EOL;
         foreach ($pts_options as $section => &$contents) {
             if (empty($contents)) {
                 continue;
             }
             $man_page .= '.SH ' . strtoupper($section) . PHP_EOL;
             sort($contents);
             foreach ($contents as &$option) {
                 $man_page .= '.B ' . trim($option[0] . ' ' . (!empty($option[1]) && is_array($option[1]) ? implode(' ', $option[1]) : null)) . PHP_EOL . $option[2] . PHP_EOL . '.TP' . PHP_EOL;
             }
         }
         $man_page .= '.SH SEE ALSO' . PHP_EOL . '.B Websites:' . PHP_EOL . '.br' . PHP_EOL . 'http://www.phoronix-test-suite.com/' . PHP_EOL . '.br' . PHP_EOL . 'http://commercial.phoronix-test-suite.com/' . PHP_EOL . '.br' . PHP_EOL . 'http://www.openbenchmarking.org/' . PHP_EOL . '.br' . PHP_EOL . 'http://www.phoronix.com/' . PHP_EOL . '.br' . PHP_EOL . 'http://www.phoronix.com/forums/' . PHP_EOL;
         $man_page .= '.SH AUTHORS' . PHP_EOL . 'Copyright 2008 - ' . date('Y') . ' by Phoronix Media, Michael Larabel.' . PHP_EOL . '.TP' . PHP_EOL;
         file_put_contents(PTS_PATH . 'documentation/man-pages/phoronix-test-suite.1', $man_page);
     }
     // simple README
     $readme = '# Phoronix Test Suite ' . PTS_VERSION . PHP_EOL . 'http://www.phoronix-test-suite.com/' . PHP_EOL . PHP_EOL;
     $readme .= pts_documentation::basic_description() . PHP_EOL . PHP_EOL;
     $readme .= pts_file_io::file_get_contents(PTS_PATH . 'documentation/stubs/readme-basics.txt') . PHP_EOL . PHP_EOL;
     $readme = wordwrap($readme, 80, PHP_EOL);
     file_put_contents(PTS_PATH . 'README.md', $readme);
     // Phoromatic Documentation
     $pdf = new pts_pdf_template(pts_title(false), 'Phoromatic Documentation');
     $html_doc = new pts_html_template(pts_title(false), 'Phoromatic Documentation');
     $pdf->AddPage();
     $pdf->Image(PTS_CORE_STATIC_PATH . 'images/pts-308x160.png', 69, 85, 73, 38, 'PNG', 'http://www.phoronix-test-suite.com/');
     $pdf->Ln(120);
     $pdf->WriteStatement('www.phoronix-test-suite.com', 'C', 'http://www.phoronix-test-suite.com/');
     $pdf->Ln(15);
     $pdf->Image(PTS_CORE_STATIC_PATH . 'images/phoromatic-390x56.png', 55, 250, 0, 0, 'PNG', 'http://www.phoronix-test-suite.com/');
     //$pdf->Image(PTS_CORE_STATIC_PATH . 'images/phoromatic-390x56.png', 69, 85, 73, 38, 'PNG', 'http://www.phoromatic.com/');
     $pdf->WriteBigHeaderCenter(pts_title(true));
     $pdf->WriteHeaderCenter('Phoromatic User Manual');
     $pdf->html_to_pdf(PTS_PATH . 'documentation/phoromatic.html');
     $pdf_file = PTS_PATH . 'documentation/phoromatic.pdf';
     $pdf->Output($pdf_file);
     echo PHP_EOL . 'Saved To: ' . $pdf_file . PHP_EOL . PHP_EOL;
 }
 public static function get_screenshots()
 {
     if (!empty(self::$screenshots)) {
         return self::$screenshots;
     } else {
         // Another thread is going on and thread empty so try to query the file-system for differences
         $screenshots = pts_file_io::glob(pts_module::save_dir() . 'screenshot-*.png');
         return array_diff($screenshots, self::$existing_screenshots);
     }
 }
 public static function download_cache_locations()
 {
     static $cache_directories = null;
     if ($cache_directories == null) {
         $cache_directories = array();
         // Phoronix Test Suite System Cache Directories
         $additional_dir_checks = array('/var/cache/phoronix-test-suite/download-cache/', '/var/cache/phoronix-test-suite/');
         foreach ($additional_dir_checks as $dir_check) {
             if (is_dir($dir_check)) {
                 $cache_directories[] = $dir_check;
                 break;
             }
         }
         // User Defined Directory Checking
         $dir_string = ($dir = pts_client::read_env('PTS_DOWNLOAD_CACHE')) != false ? $dir : null;
         foreach (array_merge(self::$extra_caches, pts_strings::colon_explode($dir_string)) as $dir_check) {
             if ($dir_check == null) {
                 continue;
             }
             $dir_check = pts_strings::parse_for_home_directory($dir_check);
             if (pts_strings::is_url($dir_check) == false && !is_dir($dir_check)) {
                 continue;
             }
             $cache_directories[] = pts_strings::add_trailing_slash($dir_check);
         }
         if (pts_config::read_bool_config('PhoronixTestSuite/Options/Installation/SearchMediaForCache', 'TRUE')) {
             $download_cache_dirs = array_merge(pts_file_io::glob('/media/*/download-cache/'), pts_file_io::glob('/media/*/*/download-cache/'), pts_file_io::glob('/run/media/*/*/download-cache/'), pts_file_io::glob('/Volumes/*/download-cache/'));
             foreach ($download_cache_dirs as $dir) {
                 $cache_directories[] = $dir;
             }
         }
     }
     return $cache_directories;
 }
Esempio n. 22
0
 public static function get_network_wol()
 {
     static $wol_support = null;
     if ($wol_support === null) {
         $wol_support = array();
         if (is_dir('/sys/class/net') && pts_client::executable_in_path('ethtool')) {
             foreach (pts_file_io::glob('/sys/class/net/*') as $net_device) {
                 if (is_readable($net_device . '/operstate') && trim(file_get_contents($net_device . '/operstate')) != 'up') {
                     continue;
                 }
                 $net_name = basename($net_device);
                 $ethtool_output = shell_exec('ethtool ' . $net_name . ' 2>&1');
                 if (($x = stripos($ethtool_output, 'Supports Wake-on: ')) !== false) {
                     $ethtool_output = substr($ethtool_output, $x + strlen('Supports Wake-on: '));
                     $ethtool_output = trim(substr($ethtool_output, 0, strpos($ethtool_output, PHP_EOL)));
                     $wol_support[$net_name] = $net_name . ': ' . $ethtool_output;
                 }
             }
         }
     }
     return $wol_support;
 }
Esempio n. 23
0
 public static function test_results_by_date()
 {
     $results = array();
     foreach (pts_file_io::glob(PTS_SAVE_RESULTS_PATH . '*/composite.xml') as $composite) {
         $results[filemtime($composite)] = basename(dirname($composite));
     }
     krsort($results);
     return $results;
 }
Esempio n. 24
0
 public static function saved_test_results()
 {
     $results = array();
     $ignore_ids = array();
     foreach (pts_file_io::glob(PTS_SAVE_RESULTS_PATH . '*/composite.xml') as $result_file) {
         $identifier = basename(dirname($result_file));
         if (!in_array($identifier, $ignore_ids)) {
             array_push($results, $identifier);
         }
     }
     return $results;
 }
 public function multi_test_stress_run_execute($tests_to_run_concurrently = 3, $total_loop_time = false)
 {
     $continue_test_flag = true;
     pts_client::$display->test_run_process_start($this);
     $this->disable_dynamic_run_count();
     $this->multi_test_stress_run = $tests_to_run_concurrently;
     $possible_tests_to_run = $this->get_tests_to_run();
     $tests_pids_active = array();
     $loop_until_time = is_numeric($total_loop_time) && $total_loop_time > 1 ? time() + $total_loop_time : false;
     while (!empty($possible_tests_to_run) || !empty($tests_pids_active)) {
         if ($continue_test_flag == false) {
             break;
         }
         $test_types_active = array();
         foreach ($tests_pids_active as $pid => &$test) {
             $ret = pcntl_waitpid($pid, $status, WNOHANG | WUNTRACED);
             if ($ret) {
                 if (pcntl_wifexited($status) || !posix_getsid($pid)) {
                     unset($tests_pids_active[$pid]);
                     continue;
                 }
             }
             if (!in_array($test->test_profile->get_test_hardware_type(), $test_types_active)) {
                 array_push($test_types_active, $test->test_profile->get_test_hardware_type());
             }
         }
         if (!empty($possible_tests_to_run) && count($tests_pids_active) < $tests_to_run_concurrently && (!$total_loop_time || $loop_until_time > time())) {
             shuffle($possible_tests_to_run);
             $test_to_run = false;
             $test_run_index = -1;
             foreach ($possible_tests_to_run as $i => $test) {
                 if (!in_array($test->test_profile->get_test_hardware_type(), $test_types_active)) {
                     $test_run_index = $i;
                     $test_to_run = $test;
                 }
             }
             if ($test_run_index == -1) {
                 $test_run_index = array_rand(array_keys($possible_tests_to_run));
                 $test_to_run = $possible_tests_to_run[$test_run_index];
             }
             $pid = pcntl_fork();
             if ($pid == -1) {
                 echo 'Forking failure.';
             } else {
                 if ($pid) {
                     $tests_pids_active[$pid] = $test_to_run;
                 } else {
                     $continue_test_flag = $this->process_test_run_request($test_to_run);
                     return false;
                 }
             }
             if ($total_loop_time == false) {
                 unset($possible_tests_to_run[$test_run_index]);
             } else {
                 if ($total_loop_time == 'infinite') {
                     echo 'Continuing to test indefinitely' . PHP_EOL;
                 } else {
                     if ($loop_until_time > time()) {
                         $time_left = ceil(($loop_until_time - time()) / 60);
                         echo 'Continuing to test for ' . $time_left . ' more minutes' . PHP_EOL;
                     } else {
                         echo 'TOTAL_LOOP_TIME elapsed; quitting....' . PHP_EOL;
                         break;
                     }
                 }
             }
         }
         sleep(1);
     }
     foreach ($this->get_tests_to_run() as $run_request) {
         // Remove cache shares
         foreach (pts_file_io::glob($run_request->test_profile->get_install_dir() . 'cache-share-*.pt2so') as $cache_share_file) {
             unlink($cache_share_file);
         }
     }
     return true;
 }
 public static function render_page_process($PATH)
 {
     if ($_SESSION['AdminLevel'] != -40) {
         header('Location: /?main');
     }
     $main = null;
     if (isset($_POST['new_phoromatic_path']) && !empty($_POST['new_phoromatic_path'])) {
         $new_dir = dirname($_POST['new_phoromatic_path']);
         if (!is_dir($new_dir)) {
             $main .= '<h2 style="color: red;"><em>' . $new_dir . '</em> must be a valid directory.</h2>';
         } else {
             if (!is_writable($new_dir)) {
                 $main .= '<h2 style="color: red;"><em>' . $new_dir . '</em> is not a writable location.</h2>';
             } else {
                 if (!is_dir($_POST['new_phoromatic_path'])) {
                     if (mkdir($_POST['new_phoromatic_path']) == false) {
                         $main .= '<h2 style="color: red;">Failed to make directory <em>' . $_POST['new_phoromatic_path'] . '</em>.</h2>';
                     }
                 }
                 if (is_dir($_POST['new_phoromatic_path'])) {
                     $new_phoromatic_dir = pts_strings::add_trailing_slash($_POST['new_phoromatic_path']);
                     $d = glob($new_phoromatic_dir . '*');
                     if (!empty($d)) {
                         $new_phoromatic_dir .= 'phoromatic/';
                         pts_file_io::mkdir($new_phoromatic_dir);
                     }
                     $d = glob($new_phoromatic_dir . '*');
                     if (!empty($d)) {
                         $main .= '<h2 style="color: red;"><em>' . $new_phoromatic_dir . '</em> must be an empty directory.</h2>';
                     } else {
                         if (pts_file_io::copy(phoromatic_server::phoromatic_path(), $new_phoromatic_dir)) {
                             pts_config::user_config_generate(array('PhoromaticStorage' => $new_phoromatic_dir));
                             header('Location: /?admin');
                         } else {
                             $main .= '<h2 style="color: red;"><em>Failed to copy old Phoromatic data to new location.</h2>';
                         }
                     }
                 }
             }
         }
     }
     if (isset($_POST['new_dc_path']) && !empty($_POST['new_dc_path'])) {
         $new_dir = dirname($_POST['new_dc_path']);
         if (!is_dir($new_dir)) {
             $main .= '<h2 style="color: red;"><em>' . $new_dir . '</em> must be a valid directory.</h2>';
         } else {
             if (!is_writable($new_dir)) {
                 $main .= '<h2 style="color: red;"><em>' . $new_dir . '</em> is not a writable location.</h2>';
             } else {
                 if (!is_dir($_POST['new_dc_path'])) {
                     if (mkdir($_POST['new_dc_path']) == false) {
                         $main .= '<h2 style="color: red;">Failed to make directory <em>' . $_POST['new_dc_path'] . '</em>.</h2>';
                     }
                 }
                 if (is_dir($_POST['new_dc_path'])) {
                     $new_dc_dir = pts_strings::add_trailing_slash($_POST['new_dc_path']);
                     if (pts_file_io::copy(pts_strings::add_trailing_slash(pts_client::parse_home_directory(pts_config::read_user_config('PhoronixTestSuite/Options/Installation/CacheDirectory', PTS_DOWNLOAD_CACHE_PATH))), $new_dc_dir)) {
                         pts_config::user_config_generate(array('CacheDirectory' => $new_dc_dir));
                         header('Location: /?admin');
                     } else {
                         $main .= '<h2 style="color: red;"><em>Failed to copy old Phoromatic data to new location.</h2>';
                     }
                 }
             }
         }
     }
     if (isset($_POST['new_proxy_address']) && isset($_POST['new_proxy_port'])) {
         if (pts_network::http_get_contents('http://www.phoronix-test-suite.com/PTS', $_POST['new_proxy_address'], $_POST['new_proxy_port']) == 'PTS') {
             pts_config::user_config_generate(array('PhoronixTestSuite/Options/Networking/ProxyAddress' => $_POST['new_proxy_address'], 'PhoronixTestSuite/Options/Networking/ProxyPort' => $_POST['new_proxy_port']));
         } else {
             $main .= '<h2 style="color: red;">Failed to connect via proxy server.</h2>';
         }
     }
     if (isset($_POST['new_http_port']) && isset($_POST['new_ws_port'])) {
         if (empty($_POST['new_http_port']) || !is_numeric($_POST['new_http_port']) && $_POST['new_http_port'] != 'RANDOM') {
             $main .= '<h2 style="color: red;">The HTTP port must be a valid port number or <em>RANDOM</em>.</h2>';
         }
         if (empty($_POST['new_ws_port']) || !is_numeric($_POST['new_ws_port']) && $_POST['new_ws_port'] != 'RANDOM') {
             $main .= '<h2 style="color: red;">The WebSocket port must be a valid port number or <em>RANDOM</em>.</h2>';
         }
         pts_config::user_config_generate(array('PhoronixTestSuite/Options/Server/RemoteAccessPort' => $_POST['new_http_port'], 'PhoronixTestSuite/Options/Server/WebSocketPort' => $_POST['new_ws_port']));
     }
     if (isset($_POST['add_new_users_to_account'])) {
         if (empty($_POST['add_new_users_to_account'])) {
             phoromatic_server::save_setting('add_new_users_to_account', null);
         } else {
             $stmt = phoromatic_server::$db->prepare('SELECT COUNT(AccountID) AS AccountHitCount FROM phoromatic_accounts WHERE AccountID = :account_id');
             $stmt->bindValue(':account_id', $_POST['add_new_users_to_account']);
             $result = $stmt->execute();
             $row = $result->fetchArray();
             if (empty($row['AccountHitCount'])) {
                 $main .= '<h2 style="color: red;"><em>' . $_POST['add_new_users_to_account'] . '</em> is not a valid account ID.</h2>';
             } else {
                 phoromatic_server::save_setting('add_new_users_to_account', $_POST['add_new_users_to_account']);
             }
         }
     }
     if (isset($_POST['account_creation_alt'])) {
         phoromatic_server::save_setting('account_creation_alt', $_POST['account_creation_alt']);
     }
     if (isset($_POST['main_page_message'])) {
         phoromatic_server::save_setting('main_page_message', $_POST['main_page_message']);
     }
     if (isset($_POST['force_result_sharing'])) {
         phoromatic_server::save_setting('force_result_sharing', $_POST['force_result_sharing']);
     }
     if (isset($_POST['show_local_tests_only'])) {
         phoromatic_server::save_setting('show_local_tests_only', $_POST['show_local_tests_only']);
     }
     if (isset($_POST['new_admin_support_email'])) {
         phoromatic_server::save_setting('admin_support_email', $_POST['new_admin_support_email']);
     }
     if (isset($_POST['rebuild_results_db'])) {
         foreach (pts_file_io::glob(phoromatic_server::phoromatic_path() . 'accounts/*/results/*/composite.xml') as $composite_xml) {
             $account_id = basename(dirname(dirname(dirname($composite_xml))));
             $upload_id = basename(dirname($composite_xml));
             $result_file = new pts_result_file($composite_xml);
             // Validate the XML
             $relative_id = 0;
             foreach ($result_file->get_result_objects() as $result_object) {
                 $relative_id++;
                 $stmt = phoromatic_server::$db->prepare('INSERT INTO phoromatic_results_results (AccountID, UploadID, AbstractID, TestProfile, ComparisonHash) VALUES (:account_id, :upload_id, :abstract_id, :test_profile, :comparison_hash)');
                 $stmt->bindValue(':account_id', $account_id);
                 $stmt->bindValue(':upload_id', $upload_id);
                 $stmt->bindValue(':abstract_id', $relative_id);
                 $stmt->bindValue(':test_profile', $result_object->test_profile->get_identifier());
                 $stmt->bindValue(':comparison_hash', $result_object->get_comparison_hash(true, false));
                 $result = $stmt->execute();
             }
             if ($relative_id > 0) {
                 foreach ($result_file->get_systems() as $s) {
                     $stmt = phoromatic_server::$db->prepare('INSERT INTO phoromatic_results_systems (AccountID, UploadID, SystemIdentifier, Hardware, Software) VALUES (:account_id, :upload_id, :system_identifier, :hardware, :software)');
                     $stmt->bindValue(':account_id', $account_id);
                     $stmt->bindValue(':upload_id', $upload_id);
                     $stmt->bindValue(':system_identifier', $s->get_identifier());
                     $stmt->bindValue(':hardware', $s->get_hardware());
                     $stmt->bindValue(':software', $s->get_software());
                     $result = $stmt->execute();
                 }
             }
         }
     }
     $main .= '<h1>Phoromatic Server Configuration</h1>';
     $main .= '<h2>Phoromatic Storage Location</h2>';
     $main .= '<p>The Phoromatic Storage location is where all Phoromatic-specific test results, account data, and other information is archived. This path is controlled via the <em>' . pts_config::get_config_file_location() . '</em> configuration file with the <em>PhoromaticStorage</em> element. Adjusting the directory from the user configuration XML file is the recommended way to adjust the Phoromatic storage path when the Phoromatic Server is not running, while using the below form is an alternative method to attempt to live migrate the storage path.</p>';
     $main .= '<p><strong>Current Storage Path:</strong> ' . phoromatic_server::phoromatic_path() . '</p>';
     $main .= '<form action="' . $_SERVER['REQUEST_URI'] . '" name="update_phoromatic_path" method="post">';
     $main .= '<p><input type="text" name="new_phoromatic_path" value="' . (isset($_POST['new_phoromatic_path']) ? $_POST['new_phoromatic_path'] : null) . '" /></p>';
     $main .= '<p><input name="submit" value="Update Phoromatic Storage Location" type="submit" /></p>';
     $main .= '</form>';
     $main .= '<hr /><h2>Download Cache Location</h2>';
     $main .= '<p>The download cache is where the Phoronix Test Suite is able to make an archive of files needed by test profiles. The Phoromatic Server is then able to allow Phoronix Test Suite client systems on the intranet. To add test files to this cache on the Phoromatic Server, run <strong>phoronix-test-suite make-download-cache <em>&lt;the test identifers you wish to download and cache&gt;</em></strong>.</p>';
     $main .= '<p><strong>Current Download Cache Path:</strong> ' . pts_strings::add_trailing_slash(pts_client::parse_home_directory(pts_config::read_user_config('PhoronixTestSuite/Options/Installation/CacheDirectory', PTS_DOWNLOAD_CACHE_PATH))) . '</p>';
     $main .= '<form action="' . $_SERVER['REQUEST_URI'] . '" name="update_dc_path" method="post">';
     $main .= '<p><input type="text" name="new_dc_path" value="' . (isset($_POST['new_dc_path']) ? $_POST['new_dc_path'] : null) . '" /></p>';
     $main .= '<p><input name="submit" value="Update Download Cache Location" type="submit" /></p>';
     $main .= '</form>';
     $main .= '<hr /><h2>Network Proxy</h2>';
     $main .= '<p>If a network proxy is needed for the Phoromatic Server to access the open Internet, please provide the IP address and HTTP port address below.</p>';
     $main .= '<form action="' . $_SERVER['REQUEST_URI'] . '" name="update_proxy" method="post">';
     $main .= '<p><strong>Proxy HTTP Port:</strong> <input type="text" name="new_proxy_port" size="4" value="' . (isset($_POST['new_proxy_port']) ? $_POST['new_proxy_port'] : pts_config::read_user_config('PhoronixTestSuite/Options/Networking/ProxyPort')) . '" /></p>';
     $main .= '<p><strong>Proxy IP Address:</strong> <input type="text" name="new_proxy_address" value="' . (isset($_POST['new_proxy_address']) ? $_POST['new_proxy_address'] : pts_config::read_user_config('PhoronixTestSuite/Options/Networking/ProxyAddress')) . '" /></p>';
     $main .= '<p><input name="submit" value="Update Network Proxy" type="submit" /></p>';
     $main .= '</form>';
     $main .= '<hr /><h2>Phoromatic Server Ports</h2>';
     $main .= '<p>The HTTP and WebSocket ports for the Phoromatic Server can be adjusted via this form or the user configuration XML file. The new ports will not go into effect until the Phoromatic Server instance has been restarted.</p>';
     $main .= '<form action="' . $_SERVER['REQUEST_URI'] . '" name="update_ports" method="post">';
     $main .= '<p><strong>HTTP Port:</strong> <input type="text" name="new_http_port" size="4" value="' . (isset($_POST['new_http_port']) ? $_POST['new_http_port'] : pts_config::read_user_config('PhoronixTestSuite/Options/Server/RemoteAccessPort')) . '" /></p>';
     $main .= '<p><strong>WebSocket Port:</strong> <input type="text" name="new_ws_port" size="4" value="' . (isset($_POST['new_ws_port']) ? $_POST['new_ws_port'] : pts_config::read_user_config('PhoronixTestSuite/Options/Server/WebSocketPort')) . '" /></p>';
     $main .= '<p><input name="submit" value="Update Web Ports" type="submit" /></p>';
     $main .= '</form>';
     $main .= '<hr /><h2>Support Email Address</h2>';
     $main .= '<p>This email address will be shown as the sender of emails regarding new account registration and other non-group-related messages. This email address may also be shown as a support email address in case of user problems.</p>';
     $main .= '<form action="' . $_SERVER['REQUEST_URI'] . '" name="support_email" method="post">';
     $main .= '<p><strong>E-Mail:</strong> <input type="text" name="new_admin_support_email" value="' . phoromatic_server::read_setting('admin_support_email') . '" /></p>';
     $main .= '<p><input name="submit" value="Update E-Mail Address" type="submit" /></p>';
     $main .= '</form>';
     $main .= '<hr /><h1>Account Creation</h1>';
     $main .= '<h2>Add To Existing Account</h2><p>Whenever a new account is created via the main log-in page, rather than creating a new group account, you can opt to have the account added as a viewer to an existing group of accounts. To do so, enter the account ID in the field below. The user is added to that account ID with viewer privileges while the main administrator for that account can elevate the privileges from their account\'s Users page. You can find the list of account IDs via the main rootadmin page account listing. Leave this field blank to disable the feature. This option only affects the creation of new accounts.</p>';
     $main .= '<form action="' . $_SERVER['REQUEST_URI'] . '" name="add_accounts_to_one" method="post">';
     $main .= '<p><strong>Main Account ID:</strong> <input type="text" name="add_new_users_to_account" size="6" value="' . phoromatic_server::read_setting('add_new_users_to_account') . '" /></p>';
     $main .= '<p><input name="submit" value="Update Account Handling" type="submit" /></p>';
     $main .= '</form>';
     $main .= '<hr /><h1>Account Creation</h1>';
     $main .= '<p>By default, new accounts can be created at-will from the main page of the Phoromatic Server web interface. <strong>To disable the ability to create new accounts from the main welcome page</strong>, enter a message in the field below -- e.g. account creation disabled, contact XYZ department via email to request a new account, or other string to present to the user in place of the account creation box. Leave this box empty to allow new accounts to be created. HTML input is allowed.</p>';
     $main .= '<form action="' . $_SERVER['REQUEST_URI'] . '" name="account_creation_text" method="post">';
     $main .= '<p><strong>Account Creation String:</strong> <textarea name="account_creation_alt" cols="50" rows="4">' . phoromatic_server::read_setting('account_creation_alt') . '</textarea></p>';
     $main .= '<p><input name="submit" value="Update Account Handling" type="submit" /></p>';
     $main .= '</form>';
     $main .= '<hr /><h1>Main Page Message</h1>';
     $main .= '<p>If you wish to present users with a custom message once logging into their Phoromatic account, set the HTML-allowed string below and it will be shown on the main page once logging in.</p>';
     $main .= '<form action="' . $_SERVER['REQUEST_URI'] . '" name="main_page_message" method="post">';
     $main .= '<p><strong>Main Page Message String:</strong> <textarea name="main_page_message" cols="50" rows="4">' . phoromatic_server::read_setting('main_page_message') . '</textarea></p>';
     $main .= '<p><input name="submit" value="Update Main Page Message" type="submit" /></p>';
     $main .= '</form>';
     $main .= '<hr /><h1>Force Results To Be Shared</h1>';
     $main .= '<p>If you wish to force that all accounts/groups on this Phoromatic Server instance are shared/viewable amongst other groups on this server, set this value to True. Otherwise the result sharing is limited to each group\'s selected option on the account settings page.</p>';
     $main .= '<form action="' . $_SERVER['REQUEST_URI'] . '" name="force_result_share" method="post">';
     $main .= '<p><strong>Force Result Sharing:</strong> <select name="force_result_sharing"><option value="0">False</option><option value="1" ' . (phoromatic_server::read_setting('force_result_sharing') ? 'selected="selected"' : null) . '>True</option></select></p>';
     $main .= '<p><input name="submit" value="Update" type="submit" /></p>';
     $main .= '</form>';
     $main .= '<hr /><h1>Only Advertise Tests With Files Locally Cached</h1>';
     $main .= '<p>Enabling this option will only advertise test profiles on the Phoromatic Server web interface if the needed files for that test are present within the Phoromatic Server\'s PTS download cache. This feature is particularly useful for environments where the client test system lacks direct Internet access.</p>';
     $main .= '<form action="' . $_SERVER['REQUEST_URI'] . '" name="show_local_tests_only" method="post">';
     $main .= '<p><strong>Only Advertise Cached Tests:</strong> <select name="show_local_tests_only"><option value="0">False</option><option value="1" ' . (phoromatic_server::read_setting('show_local_tests_only') ? 'selected="selected"' : null) . '>True</option></select></p>';
     $main .= '<p><input name="submit" value="Update" type="submit" /></p>';
     $main .= '</form>';
     $main .= '<hr /><h1>Rebuild Results/Systems SQLite Tables</h1>';
     $main .= '<p>If you somehow damaged some of your SQLite tables, this option will attempt to rebuild the phoromatic_results_results and phoromatic_results_systems tables.</p>';
     $main .= '<form action="' . $_SERVER['REQUEST_URI'] . '" name="rebuild_results_db" method="post">';
     $main .= '<p><strong>Force Results Table Rebuild:</strong> <select name="rebuild_results_db"><option value="0">False</option><option value="1" ' . (phoromatic_server::read_setting('rebuild_results_db') ? 'selected="selected"' : null) . '>True</option></select></p>';
     $main .= '<p><input name="submit" value="Rebuild Results Table" type="submit" /></p>';
     $main .= '</form>';
     echo phoromatic_webui_header_logged_in();
     echo phoromatic_webui_main($main, phoromatic_webui_right_panel_logged_in());
     echo phoromatic_webui_footer();
 }
// INIT
define('PHOROMATIC_SERVER', true);
//ini_set('memory_limit', '64M');
define('PTS_MODE', 'WEB_CLIENT');
define('PTS_AUTO_LOAD_OBJECTS', true);
//error_reporting(E_ALL);
include '../../pts-core.php';
pts_core::init();
if (isset($_GET['index'])) {
    $requested_repo = str_replace(array('..', '/'), null, $_GET['repo']);
    $repo_index = pts_openbenchmarking::read_repository_index($requested_repo, false);
    echo $repo_index;
    pts_logger::add_to_log($_SERVER['REMOTE_ADDR'] . ' downloaded a copy of the ' . $requested_repo . ' OpenBenchmarking.org repository index');
} else {
    if (isset($_GET['repos'])) {
        $index_files = pts_file_io::glob(PTS_OPENBENCHMARKING_SCRATCH_PATH . '*.index');
        $json_repos = array();
        foreach ($index_files as $index_file) {
            $index_data = json_decode(file_get_contents($index_file), true);
            $json_repos['repos'][basename($index_file, '.index')] = array('title' => basename($index_file, '.index'), 'generated' => $index_data['main']['generated']);
        }
        echo json_encode($json_repos);
    } else {
        if (isset($_GET['test'])) {
            $repo = str_replace(array('..', '/'), null, $_GET['repo']);
            $test = str_replace(array('..', '/'), null, $_GET['test']);
            if (pts_openbenchmarking::is_repository($repo)) {
                pts_logger::add_to_log($_SERVER['REMOTE_ADDR'] . ' requested a copy of the ' . $repo . '/' . $test . ' test profile');
                $realpath_file = realpath(PTS_OPENBENCHMARKING_SCRATCH_PATH . $repo . '/' . $test . '.zip');
                if (is_file($realpath_file) && strpos($realpath_file, PTS_OPENBENCHMARKING_SCRATCH_PATH) === 0) {
                    echo base64_encode(file_get_contents($realpath_file));
 public static function read_sysfs_node($search, $type = 'NUMERIC', $node_dir_check = null, $find_position = 1)
 {
     static $sysfs_file_cache = null;
     $arg_hash = crc32(serialize(func_get_args()));
     if (!isset($sysfs_file_cache[$arg_hash])) {
         $find_count = 0;
         foreach (pts_file_io::glob($search) as $sysfs_file) {
             if (is_array($node_dir_check)) {
                 $skip_to_next = false;
                 $sysfs_dir = dirname($sysfs_file) . '/';
                 foreach ($node_dir_check as $node_check => $value_check) {
                     if (!is_file($sysfs_dir . $node_check)) {
                         $skip_to_next = true;
                         break;
                     } else {
                         if ($value_check !== true) {
                             $value_check_value = pts_file_io::file_get_contents($sysfs_dir . $node_check);
                             foreach (explode(',', $value_check) as $check) {
                                 if (isset($check[0]) && $check[0] == '!') {
                                     if ($value_check_value == substr($check, 1)) {
                                         $skip_to_next = true;
                                         break;
                                     }
                                 } else {
                                     if ($value_check_value != $check) {
                                         $skip_to_next = true;
                                         break;
                                     }
                                 }
                             }
                         }
                     }
                     if ($skip_to_next) {
                         break;
                     }
                 }
                 if ($skip_to_next) {
                     continue;
                 }
             }
             $sysfs_value = pts_file_io::file_get_contents($sysfs_file);
             switch ($type) {
                 case 'NUMERIC':
                     if (is_numeric($sysfs_value)) {
                         $sysfs_file_cache[$arg_hash] = $sysfs_file;
                     }
                     break;
                 case 'POSITIVE_NUMERIC':
                     if (is_numeric($sysfs_value) && $sysfs_value > 0) {
                         $sysfs_file_cache[$arg_hash] = $sysfs_file;
                     }
                     break;
                 case 'NOT_EMPTY':
                     if (!empty($sysfs_value)) {
                         $sysfs_file_cache[$arg_hash] = $sysfs_file;
                     }
                     break;
                 case 'NO_CHECK':
                     $sysfs_file_cache[$arg_hash] = $sysfs_file;
                     break;
             }
             $find_count++;
             if ($find_count < $find_position) {
                 unset($sysfs_file_cache[$arg_hash]);
             }
             if (isset($sysfs_file_cache[$arg_hash])) {
                 break;
             }
         }
         if (!isset($sysfs_file_cache[$arg_hash])) {
             $sysfs_file_cache[$arg_hash] = false;
         }
     }
     return $sysfs_file_cache[$arg_hash] == false ? -1 : pts_file_io::file_get_contents($sysfs_file_cache[$arg_hash]);
 }
 public static function end_compiler_mask(&$test_install_request)
 {
     if ($test_install_request->compiler_mask_dir == false && !is_dir($test_install_request->compiler_mask_dir)) {
         return false;
     }
     $compiler = false;
     foreach (pts_file_io::glob($test_install_request->compiler_mask_dir . '*-options-*') as $compiler_output) {
         $output_name = basename($compiler_output);
         $compiler_type = substr($output_name, 0, strpos($output_name, '-'));
         $compiler_choice = substr($output_name, strrpos($output_name, 'options-') + 8);
         $compiler_lines = explode(PHP_EOL, pts_file_io::file_get_contents($compiler_output));
         // Clean-up / reduce the compiler options that are important
         $compiler_options = null;
         $compiler_backup_line = null;
         foreach ($compiler_lines as $l => $compiler_line) {
             $compiler_line .= ' ';
             // allows for easier/simplified detection in a few checks below
             $o = strpos($compiler_line, '-o ');
             if ($o === false) {
                 unset($compiler_lines[$l]);
                 continue;
             }
             $o = substr($compiler_line, $o + 3, strpos($compiler_line, ' ', $o + 3) - $o - 3);
             $o_l = strlen($o);
             // $o now has whatever is set for the -o output
             if ($o_l > 2 && substr(basename($o), 0, 3) == 'lib' || $o_l > 3 && substr($o, -4) == 'test') {
                 // If it's a lib, probably not what is the actual target
                 unset($compiler_lines[$l]);
                 continue;
             } else {
                 if ($o_l > 2 && substr($o, -2) == '.o') {
                     // If it's outputting to a .o should not be the proper compile command we want
                     // but back it up in case... keep overwriting temp variable to get the last one
                     $compiler_backup_line = $compiler_line;
                     unset($compiler_lines[$l]);
                     continue;
                 }
             }
         }
         if (!empty($compiler_lines)) {
             $compiler_line = array_pop($compiler_lines);
             if (strpos($compiler_line, '-O') === false && strpos($compiler_line, '-f') === false && (strpos($compiler_backup_line, '-f') !== false || strpos($compiler_backup_line, '-O'))) {
                 $compiler_line .= ' ' . $compiler_backup_line;
             }
             $compiler_options = explode(' ', $compiler_line);
             foreach ($compiler_options as $i => $option) {
                 // Decide what to include and what not... D?
                 if (!isset($option[2]) || $option[0] != '-' || $option[1] == 'L' || $option[1] == 'D' || $option[1] == 'I' || $option[1] == 'W' || isset($option[20])) {
                     unset($compiler_options[$i]);
                 }
                 if (isset($option[1]) && $option[1] == 'l') {
                     // If you're linking a library it's also useful for other purposes
                     $library = substr($option, 1);
                     // TODO XXX: scan the external dependencies to make sure $library is covered if not alert test profile maintainer...
                     //unset($compiler_options[$i]);
                 }
             }
             $compiler_options = implode(' ', array_unique($compiler_options));
             //sort($compiler_options);
             // TODO: right now just keep overwriting $compiler to take the last compiler.. so TODO add support for multiple compiler reporting or decide what todo
             $compiler = array('compiler-type' => $compiler_type, 'compiler' => $compiler_choice, 'compiler-options' => $compiler_options);
             //echo PHP_EOL . 'DEBUG: ' . $compiler_type . ' ' . $compiler_choice . ' :: ' . $compiler_options . PHP_EOL;
         }
     }
     pts_file_io::delete($test_install_request->compiler_mask_dir, null, true);
     return $compiler;
 }
        }
        //pts_logger::add_to_log($requested_file . ' to be downloaded from ' . $file_path);
        ob_end_clean();
        if (isset($_GET['m']) && $_GET['m']) {
            header('Content-Description: File Transfer');
            header('Content-Type: application/octet-stream');
            header('Content-Disposition: attachment; filename="' . basename($file_path) . '"');
            header('Expires: 0');
            header('Cache-Control: must-revalidate');
            header('Pragma: public');
            header('Content-Length: ' . filesize($file_path));
        }
        readfile($file_path);
        exit;
    } else {
        echo '<h1>Phoromatic Server Download Cache</h1>';
        $possible_paths = array(pts_strings::parse_for_home_directory(pts_config::read_user_config('PhoronixTestSuite/Options/Installation/CacheDirectory', PTS_DOWNLOAD_CACHE_PATH)), PTS_DOWNLOAD_CACHE_PATH, PTS_SHARE_PATH . 'download-cache/', '/var/cache/phoronix-test-suite/download-cache/');
        $files = array();
        foreach ($possible_paths as $possible_path) {
            foreach (pts_file_io::glob($possible_path . '/*') as $file) {
                if (is_readable($file)) {
                    $basename = basename($file);
                    if (!in_array($basename, $files)) {
                        echo '<p><a href="?m=1&download=' . $basename . '">' . $basename . ' </a></p>' . PHP_EOL;
                        array_push($files, $basename);
                    }
                }
            }
        }
    }
}