public function __get($name) { // This assumes that isset() has been called on $name prior to actually trying to get it... if (isset($this->cache[$name])) { return PHP_EOL . $this->cache[$name] . PHP_EOL; } else { if (PTS_IS_CLIENT && isset($this->options[$name])) { if (isset($this->options[$name]['type'])) { $tries = array($this->options[$name]); } else { $tries = $this->options[$name]; } $contents = null; foreach ($tries as &$try) { if ($try['type'] == 'F' && isset($try['F'][4]) && substr($try['F'], 0, 2) == '~/') { // Set the home directory $try['F'] = str_replace('~/', pts_core::user_home_directory(), $try['F']); } if ($try['type'] == 'F' && is_file($try['F'])) { $contents = file_get_contents($try['F']); } else { if ($try['type'] == 'C') { $command = pts_client::executable_in_path(pts_strings::first_in_string($try['C'])); if ($command != null) { $descriptor_spec = array(0 => array('pipe', 'r'), 1 => array('pipe', 'w'), 2 => array('pipe', 'w')); $proc = proc_open($try['C'], $descriptor_spec, $pipes, null, null); $contents = stream_get_contents($pipes[1]); fclose($pipes[1]); $return_value = proc_close($proc); } } } if (isset($try['remove_timestamps']) && $try['remove_timestamps']) { // remove leading timestamps such as from dmesg and Xorg.0.log $contents = pts_strings::remove_line_timestamps($contents); } if ($contents != null) { if ($try['cacheable']) { $this->cache[$name] = $contents; } return PHP_EOL . $contents . PHP_EOL; } } } } return false; }
public static function save_test_result($save_to = null, $save_results = null, $render_graphs = true, $result_identifier = null) { // Saves PTS result file if (substr($save_to, -4) != '.xml') { $save_to .= '.xml'; } $save_to = str_replace(PTS_SAVE_RESULTS_PATH, null, $save_to); $save_to_dir = pts_client::setup_test_result_directory($save_to); if ($save_to == null || $save_results == null) { $bool = false; } else { $save_name = basename($save_to, '.xml'); if ($save_name == 'composite' && $render_graphs) { pts_client::generate_result_file_graphs($save_results, $save_to_dir); } $bool = file_put_contents(PTS_SAVE_RESULTS_PATH . $save_to, $save_results); if ($result_identifier != null && pts_config::read_bool_config('PhoronixTestSuite/Options/Testing/SaveSystemLogs', 'TRUE')) { // Save verbose system information here $system_log_dir = $save_to_dir . '/system-logs/' . $result_identifier . '/'; pts_file_io::mkdir($system_log_dir, 0777, true); // Backup system files // TODO: move out these files/commands to log out to respective Phodevi components so only what's relevant will be logged $system_log_files = array('/var/log/Xorg.0.log', '/proc/cpuinfo', '/proc/meminfo', '/proc/modules', '/proc/mounts', '/proc/cmdline', '/proc/version', '/proc/mdstat', '/etc/X11/xorg.conf', '/sys/kernel/debug/dri/0/radeon_pm_info', '/sys/kernel/debug/dri/0/i915_capabilities', '/sys/kernel/debug/dri/0/i915_cur_delayinfo', '/sys/kernel/debug/dri/0/i915_drpc_info', '/sys/devices/system/cpu/cpu0/cpufreq/scaling_available_frequencies'); /* if(phodevi::is_linux()) { // the kernel config file might just be too large to upload for now array_push($system_log_files, '/boot/config-' . php_uname('r')); } */ foreach ($system_log_files as $file) { if (is_file($file) && is_readable($file)) { // copy() can't be used in this case since it will result in a blank file for /proc/ file-system $file_contents = file_get_contents($file); $file_contents = pts_strings::remove_line_timestamps($file_contents); file_put_contents($system_log_dir . basename($file), $file_contents); } } // Generate logs from system commands to backup $system_log_commands = array('lspci -mmkvvvnn', 'lscpu', 'cc -v', 'lsusb', 'lsmod', 'sensors', 'dmesg', 'vdpauinfo', 'cpufreq-info', 'glxinfo', 'clinfo', 'uname -a', 'upower --dump'); if (phodevi::is_bsd()) { array_push($system_log_commands, 'sysctl -a'); array_push($system_log_commands, 'kenv'); } if (is_readable('/dev/mem')) { array_push($system_log_commands, 'dmidecode'); } foreach ($system_log_commands as $command_string) { $command = explode(' ', $command_string); if ($command_bin = pts_client::executable_in_path($command[0])) { $cmd_output = shell_exec('cd ' . dirname($command_bin) . ' && ./' . $command_string . ' 2>&1'); // Try to filter out any serial numbers, etc. phodevi_vfs::cleanse_file($cmd_output, $command[0]); $cmd_output = pts_strings::remove_line_timestamps($cmd_output); file_put_contents($system_log_dir . $command[0], $cmd_output); } } // Dump some common / important environmental variables $environment_variables = array('PATH' => null, 'CFLAGS' => null, 'CXXFLAGS' => null, 'LD_LIBRARY_PATH' => null, 'CC' => null, 'CXX' => null, 'LIBGL_DRIVERS_PATH' => null); foreach ($environment_variables as $variable => &$value) { $v = getenv($variable); if ($v != null) { $value = $v; } else { unset($environment_variables[$variable]); } } if (!empty($environment_variables)) { $variable_dump = null; foreach ($environment_variables as $variable => $value) { $variable_dump .= $variable . '=' . $value . PHP_EOL; } file_put_contents($system_log_dir . 'environment-variables', $variable_dump); } } } return $bool; }