public function generate_download_object_list($do_file_checks = true) { $download_xml_file = $this->test_profile->get_file_download_spec(); if ($download_xml_file != null) { $xml_parser = new pts_test_downloads_nye_XmlReader($download_xml_file); $package_url = $xml_parser->getXMLArrayValues('PhoronixTestSuite/Downloads/Package/URL'); $package_md5 = $xml_parser->getXMLArrayValues('PhoronixTestSuite/Downloads/Package/MD5'); $package_sha256 = $xml_parser->getXMLArrayValues('PhoronixTestSuite/Downloads/Package/SHA256'); $package_filename = $xml_parser->getXMLArrayValues('PhoronixTestSuite/Downloads/Package/FileName'); $package_filesize = $xml_parser->getXMLArrayValues('PhoronixTestSuite/Downloads/Package/FileSize'); $package_platform = $xml_parser->getXMLArrayValues('PhoronixTestSuite/Downloads/Package/PlatformSpecific'); $package_architecture = $xml_parser->getXMLArrayValues('PhoronixTestSuite/Downloads/Package/ArchitectureSpecific'); foreach (array_keys($package_url) as $i) { if (!empty($package_platform[$i]) && $do_file_checks) { $platforms = pts_strings::comma_explode($package_platform[$i]); if (!in_array(phodevi::operating_system(), $platforms) && !(phodevi::is_bsd() && in_array('Linux', $platforms) && (pts_client::executable_in_path('kldstat') && strpos(shell_exec('kldstat -n linux 2>&1'), 'linux.ko') != false))) { // This download does not match the operating system continue; } } if (!empty($package_architecture[$i]) && $do_file_checks) { $architectures = pts_strings::comma_explode($package_architecture[$i]); if (phodevi::cpu_arch_compatible($architectures) == false) { // This download does not match the CPU architecture continue; } } $this->test_files[] = new pts_test_file_download($package_url[$i], $package_filename[$i], $package_filesize[$i], $package_md5[$i], $package_sha256[$i], $package_platform[$i], $package_architecture[$i]); } } }
public static function network_device_string() { $network = array(); if (phodevi::is_macosx()) { // TODO: implement } else { if (phodevi::is_bsd()) { foreach (array('dev.em.0.%desc', 'dev.wpi.0.%desc', 'dev.mskc.0.%desc') as $controller) { $pci = phodevi_bsd_parser::read_sysctl($controller); if (!empty($pci)) { array_push($network, $pci); } } } else { if (phodevi::is_windows()) { // TODO: implement } else { if (phodevi::is_linux()) { foreach (array('Ethernet controller', 'Network controller') as $controller) { $pci = phodevi_linux_parser::read_pci($controller); if (!empty($pci)) { array_push($network, $pci); } } } } } } return implode(' + ', $network); }
public function read_sensor() { $net_speed = -1; if (phodevi::is_bsd() || phodevi::is_macosx()) { $net_speed = $this->network_usage_bsd(); } return pts_math::set_precision($net_speed, 2); }
private function mem_usage() { if (phodevi::is_linux()) { return self::mem_usage_linux(); } elseif (phodevi::is_macosx() || phodevi::is_bsd()) { return self::mem_usage_bsd('MEMORY', 'USED'); } }
public static function read_sensor() { // Read the processor temperature $temp_c = -1; if (phodevi::is_bsd()) { $cpu_temp = phodevi_bsd_parser::read_sysctl(array('hw.sensors.acpi_tz0.temp0', 'dev.cpu.0.temperature', 'hw.sensors.cpu0.temp0')); if ($cpu_temp != false) { if (($end = strpos($cpu_temp, 'degC')) || ($end = strpos($cpu_temp, 'C')) > 0) { $cpu_temp = substr($cpu_temp, 0, $end); } if (is_numeric($cpu_temp)) { $temp_c = $cpu_temp; } } else { $acpi = phodevi_bsd_parser::read_sysctl('hw.acpi.thermal.tz0.temperature'); if (($end = strpos($acpi, 'C')) > 0) { $acpi = substr($acpi, 0, $end); } if (is_numeric($acpi)) { $temp_c = $acpi; } } } else { if (phodevi::is_linux()) { // Try hwmon interface $raw_temp = phodevi_linux_parser::read_sysfs_node('/sys/class/hwmon/hwmon*/device/temp1_input', 'POSITIVE_NUMERIC', array('name' => 'coretemp')); if ($raw_temp == -1) { $raw_temp = phodevi_linux_parser::read_sysfs_node('/sys/class/hwmon/hwmon*/device/temp1_input', 'POSITIVE_NUMERIC', array('name' => 'k10temp')); } if ($raw_temp == -1) { // Try ACPI thermal // Assuming the system thermal sensor comes 2nd to the ACPI CPU temperature // It appears that way on a ThinkPad T60, but TODO find a better way to validate $raw_temp = phodevi_linux_parser::read_sysfs_node('/sys/class/thermal/thermal_zone*/temp', 'POSITIVE_NUMERIC', null, 2); } if ($raw_temp != -1) { if ($raw_temp > 1000) { $raw_temp = $raw_temp / 1000; } $temp_c = pts_math::set_precision($raw_temp, 2); } if ($temp_c == -1) { // Try LM_Sensors $sensors = phodevi_linux_parser::read_sensors(array('CPU Temp', 'Core 0', 'Core0 Temp', 'Core1 Temp')); if ($sensors != false && is_numeric($sensors) && $sensors > 0) { $temp_c = $sensors; } } if (pts_client::executable_in_path('ipmitool')) { $ipmi = phodevi_linux_parser::read_ipmitool_sensor('Temp 0'); if ($ipmi > 0 && is_numeric($ipmi)) { $temp_c = $ipmi; } } } } return $temp_c; }
public function read_sensor() { $sys_temp = -1; if (phodevi::is_linux()) { $sys_temp = $this->sys_temp_linux(); } elseif (phodevi::is_bsd()) { $sys_temp = $this->sys_temp_bsd(); } return $sys_temp; }
public static function read_sensor() { // Reads the system's temperature $temp_c = -1; if (phodevi::is_linux()) { $raw_temp = phodevi_linux_parser::read_sysfs_node('/sys/class/hwmon/hwmon*/device/temp3_input', 'POSITIVE_NUMERIC', array('name' => '!coretemp,!radeon,!nouveau')); if ($raw_temp == -1) { $raw_temp = phodevi_linux_parser::read_sysfs_node('/sys/class/hwmon/hwmon*/device/temp2_input', 'POSITIVE_NUMERIC', array('name' => '!coretemp,!radeon,!nouveau')); } if ($raw_temp == -1) { $raw_temp = phodevi_linux_parser::read_sysfs_node('/sys/class/hwmon/hwmon*/device/temp1_input', 'POSITIVE_NUMERIC', array('name' => '!coretemp,!radeon,!nouveau')); } if ($raw_temp == -1) { $raw_temp = phodevi_linux_parser::read_sysfs_node('/sys/class/hwmon/hwmon*/temp1_input', 'POSITIVE_NUMERIC'); } if ($raw_temp != -1) { if ($raw_temp > 1000) { $raw_temp = $raw_temp / 1000; } $temp_c = pts_math::set_precision($raw_temp, 2); } if ($temp_c == -1) { $acpi = phodevi_linux_parser::read_acpi(array('/thermal_zone/THM1/temperature', '/thermal_zone/TZ00/temperature', '/thermal_zone/TZ01/temperature'), 'temperature'); if (($end = strpos($acpi, ' ')) > 0) { $temp_c = substr($acpi, 0, $end); } } if ($temp_c == -1) { $sensors = phodevi_linux_parser::read_sensors(array('Sys Temp', 'Board Temp')); if ($sensors != false && is_numeric($sensors)) { $temp_c = $sensors; } } if ($temp_c == -1 && is_file('/sys/class/thermal/thermal_zone0/temp')) { $temp_c = pts_file_io::file_get_contents('/sys/class/thermal/thermal_zone0/temp'); if ($temp_c > 1000) { $temp_c = pts_math::set_precision($temp_c / 1000, 1); } } } else { if (phodevi::is_bsd()) { $acpi = phodevi_bsd_parser::read_sysctl(array('hw.sensors.acpi_tz1.temp0', 'hw.acpi.thermal.tz1.temperature')); if (($end = strpos($acpi, ' degC')) > 0 || ($end = strpos($acpi, 'C')) > 0) { $acpi = substr($acpi, 0, $end); if (is_numeric($acpi)) { $temp_c = $acpi; } } } } return $temp_c; }
public function read_sensor() { // Read the processor temperature $temp_c = -1; if (phodevi::is_bsd()) { $temp_c = $this->cpu_temp_bsd(); } else { if (phodevi::is_linux()) { $temp_c = $this->cpu_temp_linux(); } } return $temp_c; }
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() { // Determine the current processor frequency $cpu_core = 0; // TODO: for now just monitoring the first core $info = 0; if (phodevi::is_linux()) { // First, the ideal way, with modern CPUs using CnQ or EIST and cpuinfo reporting the current if (is_file('/sys/devices/system/cpu/cpu' . $cpu_core . '/cpufreq/scaling_cur_freq')) { $info = pts_file_io::file_get_contents('/sys/devices/system/cpu/cpu' . $cpu_core . '/cpufreq/scaling_cur_freq'); $info = intval($info) / 1000; } else { if (is_file('/proc/cpuinfo')) { $cpu_speeds = phodevi_linux_parser::read_cpuinfo('cpu MHz'); if (isset($cpu_speeds[0])) { $cpu_core = isset($cpu_speeds[$cpu_core]) ? $cpu_core : 0; $info = intval($cpu_speeds[$cpu_core]); } } } } else { if (phodevi::is_solaris()) { $info = shell_exec('psrinfo -v | grep MHz'); $info = substr($info, strrpos($info, 'at') + 3); $info = trim(substr($info, 0, strpos($info, 'MHz'))); } else { if (phodevi::is_bsd()) { $info = phodevi_bsd_parser::read_sysctl('dev.cpu.0.freq'); } else { if (phodevi::is_macosx()) { $info = phodevi_osx_parser::read_osx_system_profiler('SPHardwareDataType', 'ProcessorSpeed'); if (($cut_point = strpos($info, ' ')) > 0) { $info = substr($info, 0, $cut_point); $info = str_replace(',', '.', $info); } if ($info < 100) { $info *= 1000; } } } } } return pts_math::set_precision($info, 2); }
public function read_sensor() { // Determine the current processor frequency $frequency = 0; if (phodevi::is_linux()) { $frequency = $this->cpu_freq_linux(); } else { if (phodevi::is_solaris()) { $frequency = $this->cpu_freq_solaris(); } else { if (phodevi::is_bsd()) { $frequency = $this->cpu_freq_bsd(); } else { if (phodevi::is_macosx()) { $frequency = $this->cpu_freq_macosx(); } } } } return pts_math::set_precision($frequency, 2); }
public function is_test_platform_supported() { // Check if the system's OS is supported by a test $supported = true; $platforms = $this->get_supported_platforms(); if (!empty($platforms) && !in_array(phodevi::operating_system(), $platforms)) { if (phodevi::is_bsd() && in_array('Linux', $platforms) && (pts_client::executable_in_path('kldstat') && strpos(shell_exec('kldstat -n linux 2>&1'), 'linux.ko') != false)) { // The OS is BSD but there is Linux API/ABI compatibility support loaded $supported = true; } else { if (phodevi::is_hurd() && in_array('Linux', $platforms) && in_array('BSD', $platforms)) { // For now until test profiles explicity express Hurd support, just list as supported the tests that work on both BSD and Linux // TODO: fill in Hurd support for test profiles / see what works $supported = true; } else { $supported = false; } } } return $supported; }
public static function cpu_model() { // Returns the processor name / frequency information $info = null; if (isset(phodevi::$vfs->cpuinfo)) { $physical_cpu_ids = phodevi_linux_parser::read_cpuinfo('physical id'); $physical_cpu_count = count(array_unique($physical_cpu_ids)); $cpu_strings = phodevi_linux_parser::read_cpuinfo(array('model name', 'Processor', 'cpu', 'cpu model')); $cpu_strings_unique = array_unique($cpu_strings); if ($physical_cpu_count == 1 || empty($physical_cpu_count)) { // Just one processor if (isset($cpu_strings[0]) && ($cut = strpos($cpu_strings[0], ' (')) !== false) { $cpu_strings[0] = substr($cpu_strings[0], 0, $cut); } $info = isset($cpu_strings[0]) ? $cpu_strings[0] : null; if (strpos($info, 'ARM') !== false) { if (is_dir('/sys/devices/system/exynos-core/') && stripos($info, 'Exynos') === false) { $info = 'Exynos ' . $info; } } } else { if ($physical_cpu_count > 1 && count($cpu_strings_unique) == 1) { // Multiple processors, same model $info = $physical_cpu_count . ' x ' . $cpu_strings[0]; } else { if ($physical_cpu_count > 1 && count($cpu_strings_unique) > 1) { // Multiple processors, different models $current_id = -1; $current_string = $cpu_strings[0]; $current_count = 0; $cpus = array(); for ($i = 0; $i < count($physical_cpu_ids); $i++) { if ($current_string != $cpu_strings[$i] || $i == count($physical_cpu_ids) - 1) { array_push($cpus, $current_count . ' x ' . $current_string); $current_string = $cpu_strings[$i]; $current_count = 0; } if ($physical_cpu_ids[$i] != $current_id) { $current_count++; $current_id = $physical_cpu_ids[$i]; } } $info = implode(', ', $cpus); } } } } else { if (phodevi::is_solaris()) { $dmi_cpu = phodevi_solaris_parser::read_sun_ddu_dmi_info('CPUType', '-C'); if (count($dmi_cpu) == 0) { $dmi_cpu = phodevi_solaris_parser::read_sun_ddu_dmi_info('ProcessorName'); } if (count($dmi_cpu) > 0) { $info = $dmi_cpu[0]; } else { $info = trim(shell_exec('dmesg 2>&1 | grep cpu0')); $info = trim(substr($info, strrpos($info, 'cpu0:') + 6)); if (empty($info)) { $info = array_pop(phodevi_solaris_parser::read_sun_ddu_dmi_info('ProcessorManufacturer')); } } //TODO: Add in proper support for reading multiple CPUs, similar to the code from above $physical_cpu_count = count(phodevi_solaris_parser::read_sun_ddu_dmi_info('ProcessorSocketType')); if ($physical_cpu_count > 1 && !empty($info)) { // TODO: For now assuming when multiple CPUs are installed, that they are of the same type $info = $physical_cpu_count . ' x ' . $info; } } else { if (phodevi::is_bsd()) { $info = phodevi_bsd_parser::read_sysctl('hw.model'); } else { if (phodevi::is_macosx()) { $info = phodevi_osx_parser::read_osx_system_profiler('SPHardwareDataType', 'ProcessorName'); } else { if (phodevi::is_windows()) { $info = phodevi_windows_parser::read_cpuz('Processor 1', 'Name'); if (!$info) { $info = getenv('PROCESSOR_IDENTIFIER'); } } } } } } if (empty($info)) { $info = 'Unknown'; } else { if (($strip_point = strpos($info, '@')) > 0) { $info = trim(substr($info, 0, $strip_point)); // stripping out the reported freq, since the CPU could be overclocked, etc } $info = pts_strings::strip_string($info); // It seems Intel doesn't report its name when reporting Pentium hardware if (strpos($info, 'Pentium') !== false && strpos($info, 'Intel') === false) { $info = 'Intel ' . $info; } if (substr($info, 0, 5) == 'Intel') { $cpu_words = explode(' ', $info); $cpu_words_count = count($cpu_words); // Convert strings like 'Intel Core i7 M 620' -> 'Intel Core i7 620M' and 'Intel Core i7 X 990' -> 'Intel Core i7 990X' to better reflect Intel product marketing names if ($cpu_words_count > 4 && is_numeric($cpu_words[$cpu_words_count - 1]) && strlen($cpu_words[$cpu_words_count - 2]) == 1 && strlen($cpu_words[$cpu_words_count - 3]) == 2) { $cpu_words[$cpu_words_count - 1] .= $cpu_words[$cpu_words_count - 2]; unset($cpu_words[$cpu_words_count - 2]); $info = implode(' ', $cpu_words); } } } return $info; }
private function cpu_load_array() { // CPU load array $load = array(); if (phodevi::is_linux() && is_file('/proc/stat')) { $stat = file_get_contents('/proc/stat'); if ($this->cpu_to_monitor === "summary") { $start_line = 0; } else { if (($l = strpos($stat, $this->cpu_to_monitor)) !== false) { $start_line = $l; } else { return -1; } } $stat_line = substr($stat, $start_line, strpos($stat, "\n")); $stat_break = preg_split('/\\s+/', $stat_line); for ($i = 1; $i < 10; $i++) { array_push($load, $stat_break[$i]); } } else { if (phodevi::is_bsd()) { $load = explode(' ', phodevi_bsd_parser::read_sysctl('kern.cp_time')); } } return $load; }
private static function cpu_load_array($read_core = -1) { // CPU load array $load = array(); if (phodevi::is_linux() && is_file('/proc/stat')) { $stat = file_get_contents('/proc/stat'); if ($read_core > -1 && ($l = strpos($stat, 'cpu' . $read_core)) !== false) { $start_line = $l; } else { $start_line = 0; } $stat = substr($stat, $start_line, strpos($stat, "\n")); $stat_break = explode(' ', $stat); for ($i = 1; $i < 6; $i++) { array_push($load, $stat_break[$i]); } } else { if (phodevi::is_bsd()) { $load = explode(' ', phodevi_bsd_parser::read_sysctl('kern.cp_time')); } } return $load; }
public static function sw_opengl_vendor() { // OpenGL version $info = null; if (pts_client::executable_in_path('glxinfo')) { $info = shell_exec('glxinfo 2>&1 | grep vendor'); if (($pos = strpos($info, 'OpenGL vendor string:')) !== false) { $info = substr($info, $pos + 22); $info = trim(substr($info, 0, strpos($info, "\n"))); } } else { if (is_readable('/dev/nvidia0')) { $info = 'NVIDIA'; } else { if (is_readable('/sys/module/fglrx/initstate') && pts_file_io::file_get_contents('/sys/module/fglrx/initstate') == 'live') { $info = 'ATI'; } else { if (is_readable('/dev/dri/card0')) { $info = 'Mesa'; } else { if (phodevi::is_bsd() && phodevi_bsd_parser::read_sysctl('dev.nvidia.0.%driver')) { $info = 'NVIDIA'; } } } } } return $info; }
public static function motherboard_string() { // Returns the motherboard / system model name or number $info = null; if (phodevi::is_macosx()) { $info = phodevi_osx_parser::read_osx_system_profiler('SPHardwareDataType', 'ModelName'); } else { if (phodevi::is_solaris()) { $manufacturer = phodevi_solaris_parser::read_sun_ddu_dmi_info(array('MotherBoardInformation,Manufacturer', 'SystemInformation,Manufacturer')); $product = phodevi_solaris_parser::read_sun_ddu_dmi_info(array('MotherBoardInformation,Product', 'SystemInformation,Product', 'SystemInformation,Model')); if (count($manufacturer) == 1 && count($product) == 1) { $info = $manufacturer[0] . ' ' . $product[0]; } } else { if (phodevi::is_bsd()) { $vendor = phodevi_bsd_parser::read_kenv('smbios.system.maker'); $product = phodevi_bsd_parser::read_kenv('smbios.system.product'); $version = phodevi_bsd_parser::read_kenv('smbios.system.version'); // for at least Lenovo ThinkPads this is where it displays ThinkPad model if ($vendor != null && ($product != null || $version != null)) { $info = $vendor . ' ' . $product . ' ' . $version; } else { if (($vendor = phodevi_bsd_parser::read_sysctl('hw.vendor')) != false && ($version = phodevi_bsd_parser::read_sysctl(array('hw.version', 'hw.product'))) != false) { $info = trim($vendor . ' ' . $version); } else { if (($acpi = phodevi_bsd_parser::read_sysctl('dev.acpi.0.%desc')) != false) { $info = trim($acpi); } } } } else { if (phodevi::is_linux()) { $vendor = phodevi_linux_parser::read_sys_dmi(array('board_vendor', 'sys_vendor')); $name = phodevi_linux_parser::read_sys_dmi(array('board_name', 'product_name')); $version = phodevi_linux_parser::read_sys_dmi(array('board_version', 'product_version')); if ($vendor != false && $name != false) { $info = strpos($name . ' ', $vendor . ' ') === false ? $vendor . ' ' : null; $info .= $name; if ($version != false && strpos($info, $version) === false && pts_strings::string_only_contains($version, pts_strings::CHAR_NUMERIC | pts_strings::CHAR_DECIMAL)) { $info .= (substr($version, 0, 1) == 'v' ? ' ' : ' v') . $version; } } if (empty($info)) { if ($info == null) { $hw_string = phodevi_linux_parser::read_cpuinfo('Hardware'); if (count($hw_string) == 1) { $info = $hw_string[0]; } } $bios_vendor = phodevi_linux_parser::read_sys_dmi('bios_vendor'); $bios_version = phodevi_linux_parser::read_sys_dmi('bios_version'); if ($bios_vendor != null) { $info = $bios_vendor . ' ' . $bios_version; } if ($info == null) { $hw_string = phodevi_linux_parser::read_cpuinfo('machine'); if (count($hw_string) == 1) { $info = $hw_string[0]; } } } if (empty($info)) { $info = phodevi_linux_parser::read_sys_dmi('product_name'); } if (empty($info) && is_file('/sys/bus/soc/devices/soc0/machine')) { $info = pts_file_io::file_get_contents('/sys/bus/soc/devices/soc0/machine'); } if (empty($info)) { // Works on the MIPS Creator CI20 $hardware = phodevi_linux_parser::read_cpuinfo('Hardware'); if (!empty($hardware)) { $info = array_pop($hardware); } } } else { if (phodevi::is_windows()) { $info = phodevi_windows_parser::read_cpuz('Mainboard Model', null); } } } } } if ((strpos($info, 'Mac ') !== false || strpos($info, 'MacBook') !== false) && strpos($info, 'Apple') === false) { $info = 'Apple ' . $info; } // ensure words aren't repeated (e.g. VMware VMware Virtual and MSI MSI X58M (MS-7593)) $info = implode(' ', array_unique(explode(' ', $info))); return $info; }
public static function memory_capacity() { // Returns physical memory capacity if (isset(phodevi::$vfs->meminfo)) { $info = phodevi::$vfs->meminfo; $info = substr($info, strpos($info, 'MemTotal:') + 9); $info = intval(trim(substr($info, 0, strpos($info, 'kB')))); $info = floor($info / 1024); if (is_numeric($info) && $info > 950) { if ($info > 4608) { $info = ceil($info / 1024) * 1024; } else { if ($info > 1536) { $info = ceil($info / 512) * 512; } else { $info = ceil($info / 256) * 256; } } } } else { if (phodevi::is_solaris()) { $info = shell_exec('prtconf 2>&1 | grep Memory'); $info = substr($info, strpos($info, ':') + 2); $info = substr($info, 0, strpos($info, 'Megabytes')); } else { if (phodevi::is_bsd()) { $mem_size = phodevi_bsd_parser::read_sysctl('hw.physmem'); if ($mem_size == false) { $mem_size = phodevi_bsd_parser::read_sysctl('hw.realmem'); } $info = ceil(floor($mem_size / 1048576) / 256) * 256; } else { if (phodevi::is_macosx()) { $info = phodevi_osx_parser::read_osx_system_profiler('SPHardwareDataType', 'Memory'); $info = explode(' ', $info); $info = isset($info[1]) && $info[1] == 'GB' ? $info[0] * 1024 : $info[0]; } else { if (phodevi::is_windows()) { $info = phodevi_windows_parser::read_cpuz('Memory Size', null); if ($info != null) { if (($e = strpos($info, ' MBytes')) !== false) { $info = substr($info, 0, $e); } $info = trim($info); } } else { $info = null; } } } } } return $info; }
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; }
public static function gpu_model() { // Report graphics processor string $info = phodevi_parser::read_glx_renderer(); $video_ram = phodevi::read_property('gpu', 'memory-capacity'); if (phodevi::is_ati_graphics() && phodevi::is_linux()) { $crossfire_status = phodevi_linux_parser::read_amd_pcsdb('SYSTEM/Crossfire/chain/*,Enable'); $crossfire_status = pts_arrays::to_array($crossfire_status); $crossfire_card_count = 0; for ($i = 0; $i < count($crossfire_status); $i++) { if ($crossfire_status[$i] == '0x00000001') { $crossfire_card_count += 2; // For now assume each chain is 2 cards, but proper way would be NumSlaves + 1 } } $adapters = phodevi_linux_parser::read_amd_graphics_adapters(); if (count($adapters) > 0) { $video_ram = $video_ram > 64 ? ' ' . $video_ram . 'MB' : null; // assume more than 64MB of vRAM if ($crossfire_card_count > 1 && $crossfire_card_count <= count($adapters)) { $unique_adapters = array_unique($adapters); if (count($unique_adapters) == 1) { if (strpos($adapters[0], 'X2') > 0 && $crossfire_card_count > 1) { $crossfire_card_count -= 1; } $info = $crossfire_card_count . ' x ' . $adapters[0] . $video_ram . ' CrossFire'; } else { $info = implode(', ', $unique_adapters) . ' CrossFire'; } } else { $info = $adapters[0] . $video_ram; } } } else { if (phodevi::is_macosx()) { $system_profiler_info = implode(' + ', phodevi_osx_parser::read_osx_system_profiler('SPDisplaysDataType', 'ChipsetModel', true)); if (!empty($system_profiler_info)) { $info = $system_profiler_info; } } else { if (phodevi::is_nvidia_graphics()) { if ($info == null) { if (pts_client::executable_in_path('nvidia-settings')) { $nv_gpus = shell_exec('nvidia-settings -q gpus 2>&1'); // TODO: search for more than one GPU $nv_gpus = substr($nv_gpus, strpos($nv_gpus, '[0]')); $nv_gpus = substr($nv_gpus, strpos($nv_gpus, '(') + 1); $nv_gpus = substr($nv_gpus, 0, strpos($nv_gpus, ')')); if (stripos($nv_gpus, 'GeForce') !== false || stripos($nv_gpus, 'Quadro') !== false) { $info = $nv_gpus; } } } $sli_mode = phodevi_parser::read_nvidia_extension('SLIMode'); if (!empty($sli_mode) && $sli_mode != 'Off') { $info .= ' SLI'; } } else { if (phodevi::is_solaris()) { if (($cut = strpos($info, 'DRI ')) !== false) { $info = substr($info, $cut + 4); } if (($cut = strpos($info, ' Chipset')) !== false) { $info = substr($info, 0, $cut); } if ($info == false && isset(phodevi::$vfs->xorg_log)) { $xorg_log = phodevi::$vfs->xorg_log; if (($x = strpos($xorg_log, '(0): Chipset: ')) !== false) { $xorg_log = substr($xorg_log, $x + 14); $xorg_log = str_replace(array('(R)', '"'), null, substr($xorg_log, 0, strpos($xorg_log, PHP_EOL))); if (($c = strpos($xorg_log, '[')) || ($c = strpos($xorg_log, '('))) { $xorg_log = substr($xorg_log, 0, $c); } if (phodevi::is_product_string($xorg_log)) { $info = $xorg_log; } } } } else { if (phodevi::is_bsd()) { $drm_info = phodevi_bsd_parser::read_sysctl('dev.drm.0.%desc'); if (!$drm_info) { $drm_info = phodevi_bsd_parser::read_sysctl('dev.nvidia.0.%desc'); } if (!$drm_info) { $agp_info = phodevi_bsd_parser::read_sysctl('dev.agp.0.%desc'); if ($agp_info != false) { $info = $agp_info; } } else { $info = $drm_info; } if ($info == null && isset(phodevi::$vfs->xorg_log)) { $xorg_log = phodevi::$vfs->xorg_log; if (($e = strpos($xorg_log, ' at 01@00:00:0')) !== false) { $xorg_log = substr($xorg_log, 0, $e); $info = substr($xorg_log, strrpos($xorg_log, 'Found ') + 6); } } } else { if (phodevi::is_windows()) { $info = phodevi_windows_parser::read_cpuz('Display Adapters', 'Name'); } } } } } } if (empty($info) || strpos($info, 'Mesa ') !== false || strpos($info, 'Gallium ') !== false) { if (phodevi::is_windows() == false) { $info_pci = phodevi_linux_parser::read_pci('VGA compatible controller', false); if (!empty($info_pci)) { $info = $info_pci; if (strpos($info, 'Intel 2nd Generation Core Family') !== false || strpos($info, 'Gen Core') !== false) { // Try to come up with a better non-generic string $was_reset = false; if (isset(phodevi::$vfs->xorg_log)) { /* $ cat /var/log/Xorg.0.log | grep -i Chipset [ 8.421] (II) intel: Driver for Intel Integrated Graphics Chipsets: i810, [ 8.421] (II) VESA: driver for VESA chipsets: vesa [ 8.423] (II) intel(0): Integrated Graphics Chipset: Intel(R) Sandybridge Mobile (GT2+) [ 8.423] (--) intel(0): Chipset: "Sandybridge Mobile (GT2+)" */ $xorg_log = phodevi::$vfs->xorg_log; if (($x = strpos($xorg_log, 'Integrated Graphics Chipset: ')) !== false) { $xorg_log = substr($xorg_log, $x + 29); $xorg_log = str_replace(array('(R)', '"'), null, substr($xorg_log, 0, strpos($xorg_log, PHP_EOL))); if (stripos($xorg_log, 'Intel') === false) { $xorg_log = 'Intel ' . $xorg_log; } // if string is too long, likely not product if (!isset($xorg_log[45])) { $info = $xorg_log; $was_reset = true; } } else { if (($x = strpos($xorg_log, '(0): Chipset: ')) !== false) { $xorg_log = substr($xorg_log, $x + 14); $xorg_log = str_replace(array('(R)', '"'), null, substr($xorg_log, 0, strpos($xorg_log, PHP_EOL))); if (stripos($xorg_log, 'Intel') === false) { $xorg_log = 'Intel ' . $xorg_log; } // if string is too long, likely not product if (!isset($xorg_log[45])) { $info = $xorg_log; $was_reset = true; } } } } if ($was_reset == false && isset(phodevi::$vfs->i915_capabilities)) { $i915_caps = phodevi::$vfs->i915_capabilities; if (($x = strpos($i915_caps, 'gen: ')) !== false) { $gen = substr($i915_caps, $x + 5); $gen = substr($gen, 0, strpos($gen, PHP_EOL)); if (is_numeric($gen)) { $info = 'Intel Gen' . $gen; if (strpos($i915_caps, 'is_mobile: yes') !== false) { $info .= ' Mobile'; } } } } } } } if (($start_pos = strpos($info, ' DRI ')) > 0) { $info = substr($info, $start_pos + 5); } if (empty($info) && isset(phodevi::$vfs->xorg_log)) { $log_parse = phodevi::$vfs->xorg_log; $log_parse = substr($log_parse, strpos($log_parse, 'Chipset') + 8); $log_parse = substr($log_parse, 0, strpos($log_parse, 'found')); if (strpos($log_parse, '(--)') === false && strlen(str_ireplace(array('ATI', 'NVIDIA', 'VIA', 'Intel'), '', $log_parse)) != strlen($log_parse)) { $info = $log_parse; } } if (empty($info) && is_readable('/sys/class/graphics/fb0/name')) { switch (pts_file_io::file_get_contents('/sys/class/graphics/fb0/name')) { case 'omapdrm': $info = 'Texas Instruments OMAP'; // The OMAP DRM driver currently is for OMAP2/3/4 hardware break; case 'exynos': $info = 'Samsung EXYNOS'; // The Exynos DRM driver break; case 'tegra_fb': $info = 'NVIDIA TEGRA'; // The Exynos DRM driver break; default: if (is_file('/dev/mali')) { $info = 'ARM Mali'; // One of the ARM Mali models } break; } } if (substr($info, -1) == ')' && ($open_p = strrpos($info, '(')) != false) { $end_check = strpos($info, ' ', $open_p); $to_check = substr($info, $open_p + 1, $end_check - $open_p - 1); // Don't report card revision from PCI info if ($to_check == 'rev') { $info = substr($info, 0, $open_p - 1); } } } if (($bracket_open = strpos($info, '[')) !== false) { // Report only the information inside the brackets if it's more relevant... // Mainly with Linux systems where the PCI information is reported like 'nVidia GF104 [GeForce GTX 460]' if (($bracket_close = strpos($info, ']', $bracket_open + 1)) !== false) { $inside_bracket = substr($info, $bracket_open + 1, $bracket_close - $bracket_open - 1); if (stripos($inside_bracket, 'Quadro') !== false || stripos($inside_bracket, 'GeForce') !== false) { $info = $inside_bracket . ' ' . substr($info, $bracket_close + 1); } else { if (stripos($inside_bracket, 'Radeon') !== false || stripos($inside_bracket, 'Fire') !== false || stripos($inside_bracket, 'Fusion') !== false) { $info = $inside_bracket . ' ' . substr($info, $bracket_close + 1); } } } } if (stripos($info, 'NVIDIA') === false && (stripos($info, 'Quadro') !== false || stripos($info, 'GeForce') !== false)) { $info = 'NVIDIA' . ' ' . $info; } else { if (stripos($info, 'ATI') === false && stripos($info, 'AMD') === false && (stripos($info, 'Radeon') !== false || stripos($info, 'Fire') !== false || stripos($info, 'Fusion') !== false)) { // Fire would be for FireGL or FirePro hardware $info = 'AMD ' . $info; } } if (phodevi::is_linux() && ($vendor = phodevi_linux_parser::read_pci_subsystem_value('VGA compatible controller')) != null && stripos($info, $vendor) === false && (stripos($info, 'AMD') !== false || stripos($info, 'NVIDIA') !== false)) { $info = $vendor . ' ' . $info; } if ($video_ram > 64 && strpos($info, $video_ram) == false) { $info .= ' ' . $video_ram . 'MB'; } $clean_phrases = array('OpenGL Engine'); $info = str_replace($clean_phrases, null, $info); return $info; }
private static function sys_battery_power() { // Returns power consumption rate in mW $rate = -1; if (phodevi::is_linux()) { $power_now = phodevi_linux_parser::read_sysfs_node('/sys/class/power_supply/*/power_now', 'POSITIVE_NUMERIC', array('status' => 'Discharging')); if ($power_now != -1) { // sysfs power_now seems to be displayed in microWatts $rate = pts_math::set_precision($power_now / 1000, 2); } if ($rate == -1) { $battery = array('/battery/BAT0/state', '/battery/BAT1/state'); $state = phodevi_linux_parser::read_acpi($battery, 'charging state'); $power = phodevi_linux_parser::read_acpi($battery, 'present rate'); $voltage = phodevi_linux_parser::read_acpi($battery, 'present voltage'); if ($state == 'discharging') { $power_unit = substr($power, strrpos($power, ' ') + 1); $power = substr($power, 0, strpos($power, ' ')); if ($power_unit == 'mA') { $voltage_unit = substr($voltage, strrpos($voltage, ' ') + 1); $voltage = substr($voltage, 0, strpos($voltage, ' ')); if ($voltage_unit == 'mV') { $rate = round($power * $voltage / 1000); } } else { if ($power_unit == 'mW') { $rate = $power; } } } } if ($rate == -1 && is_file('/sys/class/power_supply/BAT0/voltage_now') && is_file('/sys/class/power_supply/BAT0/current_now')) { $voltage_now = pts_file_io::file_get_contents('/sys/class/power_supply/BAT0/voltage_now') / 1000; $current_now = pts_file_io::file_get_contents('/sys/class/power_supply/BAT0/current_now') / 1000; $power_now = $voltage_now * $current_now / 1000; if ($power_now > 1) { $rate = $power_now; } } if ($rate == -1 && is_file('/sys/class/power_supply/BAT1/voltage_now') && is_file('/sys/class/power_supply/BAT1/current_now')) { $voltage_now = pts_file_io::file_get_contents('/sys/class/power_supply/BAT1/voltage_now') / 1000; $current_now = pts_file_io::file_get_contents('/sys/class/power_supply/BAT1/current_now') / 1000; $power_now = $voltage_now * $current_now / 1000; if ($power_now > 1) { $rate = $power_now; } } } else { if (phodevi::is_macosx()) { $amperage = abs(phodevi_osx_parser::read_osx_system_profiler('SPPowerDataType', 'Amperage')); // in mA $voltage = phodevi_osx_parser::read_osx_system_profiler('SPPowerDataType', 'Voltage'); // in mV if ($amperage > 0 && $voltage > 0) { $rate = round($amperage * $voltage / 1000); } else { if (pts_client::executable_in_path('ioreg')) { $ioreg = trim(shell_exec("ioreg -l | grep LegacyBatteryInfo | cut -d '{' -f 2 | tr -d \\} | tr ',' '=' | awk -F'=' '{print (\$2*\$10/10^22)}' 2>&1")); if (is_numeric($ioreg) && $ioreg > 0) { $rate = $ioreg; } } } } else { if (phodevi::is_solaris()) { $battery = phodevi_solaris_parser::read_hal_property('/org/freedesktop/Hal/devices/pseudo/acpi_drv_0_battery0_0', 'battery.reporting.rate'); if (is_numeric($battery)) { $rate = $battery; } } else { if (phodevi::is_bsd()) { $battery = phodevi_bsd_parser::read_acpiconf('Present rate'); if ($battery && substr($battery, -2) == 'mW') { $rate = substr($battery, 0, strpos($battery, ' ')); } } } } } return $rate; }
public static function create_compiler_mask(&$test_install_request) { if (phodevi::is_bsd()) { // XXX: Using the compiler-mask causes a number of tests to fail to properly install due to compiler issues with at least PC-BSD 10.0 return false; } // or pass false to $test_install_request to bypass the test checks $compilers = array(); $external_dependencies = $test_install_request != false ? $test_install_request->test_profile->get_external_dependencies() : false; if ($test_install_request === false || in_array('build-utilities', $external_dependencies)) { // Handle C/C++ compilers for this external dependency $compilers['CC'] = array(pts_strings::first_in_string(pts_client::read_env('CC'), ' '), 'gcc', 'clang', 'icc', 'pcc'); $compilers['CXX'] = array(pts_strings::first_in_string(pts_client::read_env('CXX'), ' '), 'g++', 'clang++', 'cpp'); } if ($test_install_request === false || in_array('fortran-compiler', $external_dependencies)) { // Handle Fortran for this external dependency $compilers['F9X'] = array(pts_strings::first_in_string(pts_client::read_env('F9X'), ' '), pts_strings::first_in_string(pts_client::read_env('F95'), ' '), 'gfortran', 'f90', 'f95', 'fortran'); } if (empty($compilers)) { // If the test profile doesn't request a compiler external dependency, probably not compiling anything return false; } foreach ($compilers as $compiler_type => $possible_compilers) { // Compilers to check for, listed in order of priority $compiler_found = false; foreach ($possible_compilers as $i => $possible_compiler) { // first check to ensure not null sent to executable_in_path from env variable if ($possible_compiler && (($compiler_path = is_executable($possible_compiler)) || ($compiler_path = pts_client::executable_in_path($possible_compiler, 'ccache')))) { // Replace the array of possible compilers with a string to the detected compiler executable $compilers[$compiler_type] = $compiler_path; $compiler_found = true; break; } } if ($compiler_found == false) { unset($compilers[$compiler_type]); } } if (!empty($compilers)) { // Create a temporary directory that will be at front of PATH and serve for masking the actual compiler if ($test_install_request instanceof pts_test_install_request) { $mask_dir = pts_client::temporary_directory() . '/pts-compiler-mask-' . $test_install_request->test_profile->get_identifier_base_name() . $test_install_request->test_profile->get_test_profile_version() . '/'; } else { $mask_dir = pts_client::temporary_directory() . '/pts-compiler-mask-' . rand(100, 999) . '/'; } pts_file_io::mkdir($mask_dir); $compiler_extras = array('CC' => array('safeguard-names' => array('gcc', 'cc'), 'environment-variables' => 'CFLAGS'), 'CXX' => array('safeguard-names' => array('g++', 'c++'), 'environment-variables' => 'CXXFLAGS'), 'F9X' => array('safeguard-names' => array('gfortran', 'f95'), 'environment-variables' => 'F9XFLAGS')); foreach ($compilers as $compiler_type => $compiler_path) { $compiler_name = basename($compiler_path); $main_compiler = $mask_dir . $compiler_name; // take advantage of environment-variables to be sure they're found in the string $env_var_check = PHP_EOL; /* foreach(pts_arrays::to_array($compiler_extras[$compiler_type]['environment-variables']) as $env_var) { // since it's a dynamic check in script could probably get rid of this check... if(true || getenv($env_var)) { $env_var_check .= 'if [[ $COMPILER_OPTIONS != "*$' . $env_var . '*" ]]' . PHP_EOL . 'then ' . PHP_EOL . 'COMPILER_OPTIONS="$COMPILER_OPTIONS $' . $env_var . '"' . PHP_EOL . 'fi' . PHP_EOL; } } */ // Write the main mask for the compiler file_put_contents($main_compiler, '#!/bin/bash' . PHP_EOL . 'COMPILER_OPTIONS="$@"' . PHP_EOL . $env_var_check . PHP_EOL . 'echo $COMPILER_OPTIONS >> ' . $mask_dir . $compiler_type . '-options-' . $compiler_name . PHP_EOL . $compiler_path . ' "$@"' . PHP_EOL); // Make executable chmod($main_compiler, 0755); // The two below code chunks ensure the proper compiler is always hit if ($test_install_request instanceof pts_test_install_request && !in_array($compiler_name, pts_arrays::to_array($compiler_extras[$compiler_type]['safeguard-names'])) && getenv($compiler_type) == false) { // So if e.g. clang becomes the default compiler, since it's not GCC, it will ensure CC is also set to clang beyond the masking below $test_install_request->special_environment_vars[$compiler_type] = $compiler_name; } // Just in case any test profile script is statically always calling 'gcc' or anything not CC, try to make sure it hits one of the safeguard-names so it redirects to the intended compiler under test foreach (pts_arrays::to_array($compiler_extras[$compiler_type]['safeguard-names']) as $safe_name) { if (!is_file($mask_dir . $safe_name)) { symlink($main_compiler, $mask_dir . $safe_name); } } } if ($test_install_request instanceof pts_test_install_request) { $test_install_request->compiler_mask_dir = $mask_dir; // Appending the rest of the path will be done automatically within call_test_script $test_install_request->special_environment_vars['PATH'] = $mask_dir; } return $mask_dir; } return false; }
public static function hdd_string() { $disks = array(); if (phodevi::is_macosx()) { // TODO: Support reading non-SATA drives and more than one drive $capacity = phodevi_osx_parser::read_osx_system_profiler('SPSerialATADataType', 'Capacity'); $model = phodevi_osx_parser::read_osx_system_profiler('SPSerialATADataType', 'Model'); if (($cut = strpos($capacity, ' (')) !== false) { $capacity = substr($capacity, 0, $cut); } if (($cut = strpos($capacity, ' ')) !== false) { if (is_numeric(substr($capacity, 0, $cut))) { $capacity = floor(substr($capacity, 0, $cut)) . substr($capacity, $cut); } } $capacity = str_replace(' GB', 'GB', $capacity); if (!empty($capacity) && !empty($model)) { $disks = array($capacity . ' ' . $model); } } else { if (phodevi::is_bsd()) { $i = 0; do { $disk = phodevi_bsd_parser::read_sysctl('dev.ad.' . $i . '.%desc'); if ($disk != false && strpos($disk, 'DVD') === false && strpos($disk, 'ATAPI') === false) { array_push($disks, $disk); } $i++; } while (($disk != false || $i < 9) && $i < 128); // On some systems, the first drive seems to be at dev.ad.8 rather than starting at dev.ad.0 if (empty($disks) && pts_client::executable_in_path('camcontrol')) { $camcontrol = trim(shell_exec('camcontrol devlist 2>&1')); foreach (explode(PHP_EOL, $camcontrol) as $line) { if (substr($line, 0, 1) == '<' && ($model_end = strpos($line, '>')) !== false && strpos($line, 'DVD') === false && strpos($line, 'ATAPI') === false) { $disk = self::prepend_disk_vendor(substr($line, 1, $model_end - 1)); array_push($disks, $disk); } } } } else { if (phodevi::is_solaris()) { if (is_executable('/usr/ddu/bin/i386/hd_detect')) { $hd_detect = explode(PHP_EOL, trim(shell_exec('/usr/ddu/bin/i386/hd_detect -l 2>&1'))); foreach ($hd_detect as $hd_line) { if (isset($hd_line) && ($hd_pos = strpos($hd_line, ':/')) != false) { $disk = trim(substr($hd_line, 0, $hd_pos)); $disk = self::prepend_disk_vendor($disk); if ($disk != 'blkdev') { array_push($disks, $disk); } } } } } else { if (phodevi::is_linux()) { $disks_formatted = array(); $disks = array(); foreach (array_merge(pts_file_io::glob('/sys/block/sd*'), pts_file_io::glob('/sys/block/mmcblk*')) as $sdx) { if (strpos($sdx, 'boot') !== false) { // Don't include devices like /sys/block/mmcblk0boot[0,1] as it's repeat of /sys/block/mmcblk0 continue; } if ((is_file($sdx . '/device/name') || is_file($sdx . '/device/model')) && is_file($sdx . '/size')) { $disk_size = pts_file_io::file_get_contents($sdx . '/size'); $disk_model = pts_file_io::file_get_contents($sdx . (is_file($sdx . '/device/model') ? '/device/model' : '/device/name')); $disk_removable = pts_file_io::file_get_contents($sdx . '/removable'); if ($disk_removable == '1') { // Don't count removable disks continue; } $disk_size = round($disk_size * 512 / 1000000000) . 'GB'; $disk_model = self::prepend_disk_vendor($disk_model); if (strpos($disk_model, $disk_size . ' ') === false && strpos($disk_model, ' ' . $disk_size) === false && $disk_size != '1GB') { $disk_model = $disk_size . ' ' . $disk_model; } if ($disk_size > 0) { array_push($disks_formatted, $disk_model); } } } for ($i = 0; $i < count($disks_formatted); $i++) { if (!empty($disks_formatted[$i])) { $times_found = 1; for ($j = $i + 1; $j < count($disks_formatted); $j++) { if ($disks_formatted[$i] == $disks_formatted[$j]) { $times_found++; $disks_formatted[$j] = ''; } } $disk = ($times_found > 1 ? $times_found . ' x ' : null) . $disks_formatted[$i]; array_push($disks, $disk); } } } } } } if (count($disks) == 0) { $root_disk_size = ceil(disk_total_space('/') / 1073741824); $pts_disk_size = ceil(disk_total_space(pts_client::test_install_root_path()) / 1073741824); if ($pts_disk_size > $root_disk_size) { $root_disk_size = $pts_disk_size; } if ($root_disk_size > 1) { $disks = $root_disk_size . 'GB'; } else { $disks = null; } } else { $disks = implode(' + ', $disks); } return $disks; }