How to use is_linux method of phodevi class

Best Phoronix-test-suite code snippet using phodevi.is_linux

phodevi_motherboard.php

Source:phodevi_motherboard.php Github

copy

Full Screen

...42 }43 public static function usb_devices()44 {45 $usb = array();46 if(phodevi::is_linux())47 {48 foreach(pts_file_io::glob('/sys/bus/usb/devices/*-*/manufacturer') as $usb_dir)49 {50 $usb_dir = dirname($usb_dir) . '/';51 if(!is_file($usb_dir . 'product') || !is_file($usb_dir . 'idProduct') || !is_file($usb_dir . 'idVendor'))52 {53 continue;54 }55 $vendor = pts_strings::trim_search_query(pts_strings::strip_string(pts_file_io::file_get_contents($usb_dir . 'manufacturer')));56 $device = pts_strings::trim_search_query(pts_strings::strip_string(str_replace($vendor, null, pts_file_io::file_get_contents($usb_dir . 'product'))));57 $device = pts_strings::keep_in_string($device, pts_strings::CHAR_LETTER | pts_strings::CHAR_NUMERIC | pts_strings::CHAR_DECIMAL | pts_strings::CHAR_SPACE | pts_strings::CHAR_DASH | pts_strings::CHAR_UNDERSCORE | pts_strings::CHAR_COLON | pts_strings::CHAR_COMMA);58 if($vendor == null || $device == null || $vendor == 'Generic')59 {60 continue;61 }62 array_push($usb, array(63 'Class' => pts_file_io::file_get_contents($usb_dir . 'bDeviceClass'),64 'Vendor' => $vendor,65 'Device' => $device,66 'VendorID' => pts_file_io::file_get_contents($usb_dir . 'idVendor'),67 'DeviceID' => pts_file_io::file_get_contents($usb_dir . 'idProduct')68 ));69 }70 }71 return $usb;72 }73 public static function is_genuine($mobo)74 {75 return strpos($mobo, ' ') > 1 && !pts_strings::has_in_istring($mobo, array('Virtual', 'Bochs', '440BX', 'Megatrends', 'Award ', 'Software', 'Xen', 'HVM ', 'Notebook', 'OEM ', ' KVM', 'unknown')) && !is_numeric(substr($mobo, 0, strpos($mobo, ' ')));76 // pts_strings::string_contains($mobo, pts_strings::CHAR_NUMERIC);77 }78 public static function pci_devices()79 {80 $pci_devices = array();81 if(phodevi::is_linux() && isset(phodevi::$vfs->lspci))82 {83 $lspci = phodevi::$vfs->lspci;84 $lspci = explode("\n\n", $lspci);85 foreach($lspci as $o => &$lspci_section)86 {87 $lspci_section = explode("\n", $lspci_section);88 $formatted_section = array();89 foreach($lspci_section as $i => &$line)90 {91 $line = explode(':', $line);92 if(count($line) == 2 && in_array($line[0], array('Class', 'Vendor', 'Device', 'Driver', 'Rev', 'Module')))93 {94 $line[1] = trim($line[1]);95 if(($c = strrpos($line[1], ' [')) !== false)96 {97 $id = substr($line[1], ($c + 2));98 $id = '0x' . substr($id, 0, strpos($id, ']'));99 switch($line[0])100 {101 case 'Vendor':102 $formatted_section['VendorID'] = $id;103 break;104 case 'Device':105 $formatted_section['DeviceID'] = $id;106 break;107 }108 $line[1] = substr($line[1], 0, $c);109 }110 if($line[0] == 'Class')111 {112 switch($line[1])113 {114 case 'Ethernet controller':115 case 'Network controller':116 $line[1] = 'Network';117 break;118 case 'VGA compatible controller':119 $line[1] = 'GPU';120 break;121 case 'Audio device':122 case 'Multimedia audio controller':123 $line[1] = 'Audio';124 break;125 // case 'RAM memory':126 // case 'Host bridge':127 // $line[1] = 'Chipset';128 // break;129 default:130 $line[1] = null;131 break;132 }133 }134 else if($line[0] == 'Device' || $line[0] == 'Vendor')135 {136 $line[1] = pts_strings::trim_search_query(pts_strings::strip_string($line[1]));137 $line[1] = pts_strings::keep_in_string($line[1], pts_strings::CHAR_LETTER | pts_strings::CHAR_NUMERIC | pts_strings::CHAR_DECIMAL | pts_strings::CHAR_SPACE | pts_strings::CHAR_DASH | pts_strings::CHAR_UNDERSCORE | pts_strings::CHAR_COLON | pts_strings::CHAR_COMMA);138 }139 $formatted_section[$line[0]] = $line[1];140 }141 }142 if(count($formatted_section) > 0 && $formatted_section['Class'] != null)143 {144 array_push($pci_devices, $formatted_section);145 }146 }147 }148 return $pci_devices;149 }150 public static function parse_pci_device_data(&$lspci, &$dmesg, $ignore_external_pci_devices = false)151 {152 $pci_devices = explode(PHP_EOL . PHP_EOL, $lspci);153 $sanitized_devices = array();154 foreach($pci_devices as &$device)155 {156 $device .= PHP_EOL;157 $location = substr($device, 0, strpos($device, ' '));158 if(!strpos($location, ':') || !strpos($location, '.'))159 {160 // If it's not a valid PCI bus location (i.e. XX:YY.Z), it's probably not formatted well or wrong161 continue;162 }163 $class = substr($device, ($s = (strpos($device, '[') + 1)), (strpos($device, ']', $s) - $s));164 if(!(isset($class[3]) && !isset($class[4])))165 {166 // class must be 4 characters: 2 for class, 2 for sub-class167 continue;168 }169 // 0300 is GPUs170 if($ignore_external_pci_devices && in_array($class, array('0300')))171 {172 // Don't report external PCI devices173 continue;174 }175 $device_class = substr($class, 0, 2);176 $sub_class = substr($class, 2, 2);177 $device_name = substr($device, ($l = strpos($device, ']:') + 3), ($s = strpos($device, ':', $l)) - $l);178 $device_name = substr($device_name, 0, strrpos($device_name, ' ['));179 $device_name = str_replace('/', '-', str_replace(array('[AMD]', '[SiS]'), null, $device_name));180 $device_name = pts_strings::strip_string($device_name);181 if($device_name == null || strpos($device_name, ' ') === false)182 {183 // it must be junk not worth reporting184 continue;185 }186 $temp = substr($device, $s - 5);187 if($temp[0] != '[' || $temp[10] != ']')188 {189 continue;190 }191 $vendor_id = substr($temp, 1, 4);192 $device_id = substr($temp, 6, 4);193 $drivers = array();194 if(($s = strpos($device, 'Kernel driver in use:')) !== false)195 {196 $temp = substr($device, ($s = $s + 22), (strpos($device, PHP_EOL, $s) - $s));197 if($temp != null)198 {199 array_push($drivers, $temp);200 }201 }202 if(($s = strpos($device, 'Kernel modules:')) !== false)203 {204 $temp = substr($device, ($s = $s + 16), (strpos($device, PHP_EOL, $s) - $s));205 if($temp != null)206 {207 foreach(explode(' ', trim($temp)) as $temp)208 {209 $temp = str_replace(',', null, $temp);210 if($temp != null && !in_array($temp, $drivers))211 {212 array_push($drivers, $temp);213 }214 }215 }216 }217 if(empty($drivers))218 {219 // If there's no drivers, nothing to report220 continue;221 }222 if(!in_array($vendor_id . ':' . $device_id, array_keys($sanitized_devices)))223 {224 $dmesg_example = array();225 if($dmesg != null)226 {227 foreach($drivers as $driver)228 {229 $offset = 1;230 while($offset != false && ($offset = strpos($dmesg, $driver, $offset)) !== false)231 {232 $line = substr($dmesg, 0, strpos($dmesg, "\n", $offset));233 $line = substr($line, strrpos($line, "\n"));234 $line = trim(substr($line, strpos($line, '] ') + 2));235 if($line != null && !isset($line[128]))236 {237 array_push($dmesg_example, $line);238 }239 $offset = strpos($dmesg, "\n", ($offset + 1));240 }241 }242 }243 $sanitized_devices[$vendor_id . ':' . $device_id] = array(244 $vendor_id,245 $device_id,246 $device_name,247 $device_class,248 $sub_class,249 $drivers,250 trim($device),251 implode(PHP_EOL, $dmesg_example)252 );253 }254 }255 return $sanitized_devices;256 }257 public static function power_mode()258 {259 // Returns the power mode260 $return_status = null;261 if(phodevi::is_linux())262 {263 $sysfs_checked = false;264 foreach(pts_file_io::glob('/sys/class/power_supply/AC*/online') as $online)265 {266 if(pts_file_io::file_get_contents($online) == '0')267 {268 $return_status = 'This computer was running on battery power';269 break;270 }271 $sysfs_checked = true;272 }273 if(!$sysfs_checked)274 {275 // There likely was no sysfs power_supply support for that power adapter276 $power_state = phodevi_linux_parser::read_acpi('/ac_adapter/AC/state', 'state');277 if($power_state == 'off-line')278 {279 $return_status = 'This computer was running on battery power';280 }281 }282 }283 return $return_status;284 }285 public static function serial_number()286 {287 $serial = null;288 if(phodevi::is_linux())289 {290 $serial = phodevi_linux_parser::read_dmidecode('system', 'System Information', 'Serial Number', true, array());291 }292 return $serial;293 }294 public static function motherboard_string()295 {296 // Returns the motherboard / system model name or number297 $info = null;298 if(phodevi::is_macosx())299 {300 $info = phodevi_osx_parser::read_osx_system_profiler('SPHardwareDataType', 'ModelName');301 }302 else if(phodevi::is_solaris())303 {304 $manufacturer = phodevi_solaris_parser::read_sun_ddu_dmi_info(array('MotherBoardInformation,Manufacturer', 'SystemInformation,Manufacturer'));305 $product = phodevi_solaris_parser::read_sun_ddu_dmi_info(array('MotherBoardInformation,Product', 'SystemInformation,Product', 'SystemInformation,Model'));306 if(count($manufacturer) == 1 && count($product) == 1)307 {308 $info = $manufacturer[0] . ' ' . $product[0];309 }310 }311 else if(phodevi::is_bsd())312 {313 $vendor = phodevi_bsd_parser::read_kenv('smbios.system.maker');314 $product = phodevi_bsd_parser::read_kenv('smbios.system.product');315 $version = phodevi_bsd_parser::read_kenv('smbios.system.version'); // for at least Lenovo ThinkPads this is where it displays ThinkPad model316 if($vendor != null && ($product != null || $version != null))317 {318 $info = $vendor . ' ' . $product . ' ' . $version;319 }320 else if(($vendor = phodevi_bsd_parser::read_sysctl('hw.vendor')) != false && ($version = phodevi_bsd_parser::read_sysctl(array('hw.version', 'hw.product'))) != false)321 {322 $info = trim($vendor . ' ' . $version);323 }324 else if(($acpi = phodevi_bsd_parser::read_sysctl('dev.acpi.0.%desc')) != false)325 {326 $info = trim($acpi);327 }328 }329 else if(phodevi::is_linux())330 {331 $vendor = phodevi_linux_parser::read_sys_dmi(array('board_vendor', 'sys_vendor'));332 $name = phodevi_linux_parser::read_sys_dmi(array('board_name', 'product_name'));333 $version = phodevi_linux_parser::read_sys_dmi(array('board_version', 'product_version'));334 if($vendor != false && $name != false)335 {336 $info = strpos($name . ' ', $vendor . ' ') === false ? $vendor . ' ' : null;337 $info .= $name;338 if($version != false && strpos($info, $version) === false && pts_strings::string_only_contains($version, pts_strings::CHAR_NUMERIC | pts_strings::CHAR_DECIMAL))339 {340 $info .= (substr($version, 0, 1) == 'v' ? ' ' : ' v') . $version;341 }342 }343 if(empty($info))...

Full Screen

Full Screen

cpu_usage.php

Source:cpu_usage.php Github

copy

Full Screen

...55 }56 }57 public static function get_supported_devices()58 {59 if(phodevi::is_linux())60 {61 $cpu_list = shell_exec("cat /proc/stat | grep cpu | awk '{print $1}'");62 $cpu_array = explode("\n", $cpu_list);63 $supported = array_slice($cpu_array, 1, count($cpu_array) - 2);64 array_push($supported, 'summary');65 return $supported;66 }67 // Currently per-CPU monitoring is supported on Linux only.68 return NULL;69 }70 public function read_sensor()71 {72 // Determine current percentage for core usage73 // Default core to read is the first one (number 0)74 if(phodevi::is_linux() || phodevi::is_bsd())75 {76 $percent = $this->cpu_usage_linux_bsd();77 }78 else if(phodevi::is_solaris())79 {80 $percent = $this->cpu_usage_solaris();81 }82 else if(phodevi::is_macosx())83 {84 $percent = $this->cpu_usage_macosx();85 }86 if(!isset($percent) || !is_numeric($percent) || $percent < 0 || $percent > 100)87 {88 $percent = -1;89 }90 return pts_math::set_precision($percent, 2);91 }92 private function cpu_usage_linux_bsd()93 {94 $start_load = self::cpu_load_array($this->cpu_to_monitor);95 //TODO make sleep duration configurable by envvar96 usleep(500000);97 $end_load = self::cpu_load_array($this->cpu_to_monitor);98 for($i = 0; $i < count($end_load); $i++)99 {100 $end_load[$i] -= $start_load[$i];101 }102 $percent = (($sum = array_sum($end_load)) == 0 ? 0 : 100 - (($end_load[self::PROC_STAT_IDLE_COL] * 100) / $sum));103 return $percent;104 }105 private function cpu_usage_solaris()106 {107 //TODO test this on Solaris108 //TODO: Add support for monitoring load on a per-core basis (through mpstat maybe?)109 $info = explode(' ', pts_strings::trim_spaces(pts_arrays::last_element(explode("\n", trim(shell_exec('sar -u 1 1 2>&1'))))));110 $percent = $info[1] + $info[2];111 return $percent;112 }113 private function cpu_usage_macosx()114 {115 //TODO test this on OSX116 // CPU usage for user117 $top = shell_exec('top -n 1 -l 1 2>&1');118 $usage = substr($top, strpos($top, 'CPU usage: ') + 11);119 $percent = substr($usage, 0, strpos($usage, '%'));120 return $percent;121 }122 private function cpu_load_array()123 {124 // CPU load array125 $load = array();126 if(phodevi::is_linux() && is_file('/proc/stat'))127 {128 $stat = file_get_contents('/proc/stat');129 if($this->cpu_to_monitor === 'summary')130 {131 $start_line = 0;132 }133 else if(($l = strpos($stat, $this->cpu_to_monitor)) !== false)134 {135 $start_line = $l;136 }137 else138 {139 return -1;140 }...

Full Screen

Full Screen

is_linux

Using AI Code Generation

copy

Full Screen

1require_once 'phodevi.php';2echo phodevi::is_linux();3require_once 'phodevi.php';4echo phodevi::is_linux();5require_once 'phodevi.php';6echo phodevi::is_linux();7require_once 'phodevi.php';8echo phodevi::is_linux();9require_once 'phodevi.php';10echo phodevi::is_linux();11require_once 'phodevi.php';12echo phodevi::is_linux();13require_once 'phodevi.php';14echo phodevi::is_linux();15require_once 'phodevi.php';16echo phodevi::is_linux();17require_once 'phodevi.php';18echo phodevi::is_linux();19require_once 'phodevi.php';20echo phodevi::is_linux();21require_once 'phodevi.php';22echo phodevi::is_linux();23require_once 'phodevi.php';24echo phodevi::is_linux();25require_once 'phodevi.php';26echo phodevi::is_linux();27require_once 'phodevi.php';28echo phodevi::is_linux();

Full Screen

Full Screen

is_linux

Using AI Code Generation

copy

Full Screen

1$phodevi = new phodevi();2if($phodevi->is_linux()){3 echo "This is a Linux OS";4}5else{6 echo "This is not a Linux OS";7}8$phodevi = new phodevi();9if($phodevi->is_linux()){10 echo "This is a Linux OS";11}12else{13 echo "This is not a Linux OS";14}15$phodevi = new phodevi();16if($phodevi->is_linux()){17 echo "This is a Linux OS";18}19else{20 echo "This is not a Linux OS";21}22$phodevi = new phodevi();23if($phodevi->is_linux()){24 echo "This is a Linux OS";25}26else{27 echo "This is not a Linux OS";28}29$phodevi = new phodevi();30if($phodevi->is_linux()){31 echo "This is a Linux OS";32}33else{34 echo "This is not a Linux OS";35}36$phodevi = new phodevi();37if($phodevi->is_linux()){38 echo "This is a Linux OS";39}40else{41 echo "This is not a Linux OS";42}43$phodevi = new phodevi();44if($phodevi->is_linux()){45 echo "This is a Linux OS";46}47else{48 echo "This is not a Linux OS";49}50$phodevi = new phodevi();51if($phodevi->is_linux()){52 echo "This is a Linux OS";53}54else{55 echo "This is not a Linux OS";56}

Full Screen

Full Screen

is_linux

Using AI Code Generation

copy

Full Screen

1require_once('phodevi.php');2if(phodevi::is_linux())3{4 echo 'This is Linux';5}6{7 echo 'This is not Linux';8}9require_once('phodevi.php');10if(phodevi::is_windows())11{12 echo 'This is Windows';13}14{15 echo 'This is not Windows';16}17require_once('phodevi.php');18if(phodevi::is_macos())19{20 echo 'This is MacOS';21}22{23 echo 'This is not MacOS';24}25require_once('phodevi.php');26if(phodevi::is_freebsd())27{28 echo 'This is FreeBSD';29}30{31 echo 'This is not FreeBSD';32}33require_once('phodevi.php');34if(phodevi::is_netbsd())35{36 echo 'This is NetBSD';37}38{39 echo 'This is not NetBSD';40}41require_once('phodevi.php');42if(phodevi::is_openbsd())43{44 echo 'This is OpenBSD';45}46{47 echo 'This is not OpenBSD';48}49require_once('phodevi.php');50if(phodevi::is_solaris())51{52 echo 'This is Solaris';53}54{55 echo 'This is not Solaris';56}57require_once('phodevi.php');58if(phodevi::is_android())59{60 echo 'This is Android';61}62{63 echo 'This is not Android';64}65require_once('phodevi.php');66if(phodevi::is_ios())67{68 echo 'This is iOS';69}70{71 echo 'This is not iOS';72}

Full Screen

Full Screen

is_linux

Using AI Code Generation

copy

Full Screen

1require_once('phodevi.php');2if(phodevi::is_linux())3{4echo "This is a linux system";5}6require_once('phodevi.php');7if(phodevi::is_windows())8{9echo "This is a windows system";10}11require_once('phodevi.php');12if(phodevi::is_mac())13{14echo "This is a mac system";15}16require_once('phodevi.php');17if(phodevi::is_bsd())18{19echo "This is a bsd system";20}21require_once('phodevi.php');22if(phodevi::is_solaris())23{24echo "This is a solaris system";25}26require_once('phodevi.php');27if(phodevi::is_freebsd())28{29echo "This is a freebsd system";30}31require_once('phodevi.php');32if(phodevi::is_netbsd())33{34echo "This is a netbsd system";35}36require_once('phodevi.php');37if(phodevi::is_openbsd())38{39echo "This is a openbsd system";40}41require_once('phodevi.php');42if(phodevi::is_linux())43{44echo "This is a linux system";45}46require_once('phodevi.php');47if(phodevi::is_linux())48{49echo "This is a linux system";50}

Full Screen

Full Screen

is_linux

Using AI Code Generation

copy

Full Screen

1require 'phodevi.php';2if (phodevi::is_linux())3{4 echo "This is a Linux system";5}6require 'phodevi.php';7if (phodevi::is_windows())8{9 echo "This is a Windows system";10}11require 'phodevi.php';12if (phodevi::is_macos())13{14 echo "This is a Mac OS system";15}16require 'phodevi.php';17if (phodevi::is_freebsd())18{19 echo "This is a FreeBSD system";20}21require 'phodevi.php';22if (phodevi::is_bsd())23{24 echo "This is a BSD system";25}26require 'phodevi.php';27if (phodevi::is_solaris())28{29 echo "This is a Solaris system";30}31require 'phodevi.php';32if (phodevi::is_android())33{34 echo "This is an Android system";35}36require 'phodevi.php';37if (phodevi::is_ios())38{39 echo "This is an iOS system";40}41require 'phodevi.php';42if (phodevi::is_raspbian())43{44 echo "This is a Raspbian system";45}46require 'phodevi.php';47if (phodevi::is_windows_10())48{49 echo "This is a Windows 10 system";50}

Full Screen

Full Screen

is_linux

Using AI Code Generation

copy

Full Screen

1if(phodevi::is_linux())2{3echo "System is Linux";4}5{6echo "System is not Linux";7}8if(phodevi::is_windows())9{10echo "System is Windows";11}12{13echo "System is not Windows";14}15if(phodevi::is_mac())16{17echo "System is Mac";18}19{20echo "System is not Mac";21}22if(phodevi::is_bsd())23{24echo "System is BSD";25}26{27echo "System is not BSD";28}29if(phodevi::is_solaris())30{31echo "System is Solaris";32}33{34echo "System is not Solaris";35}36if(phodevi::is_android())37{38echo "System is Android";39}40{41echo "System is not Android";42}43if(phodevi::is_ios())44{45echo "System is IOS";46}47{48echo "System is not IOS";49}50if(phodevi::is_unix())51{52echo "System is Unix";53}54{55echo "System is not Unix";56}57if(phodevi::is_posix())58{

Full Screen

Full Screen

is_linux

Using AI Code Generation

copy

Full Screen

1include_once('phodevi.php');2if(phodevi::is_linux())3{4 echo "Current OS is Linux";5}6{7 echo "Current OS is not Linux";8}

Full Screen

Full Screen

is_linux

Using AI Code Generation

copy

Full Screen

1if(phodevi::is_linux())2{3echo "The system is running linux";4}5{6echo "The system is not running linux";7}8if(phodevi::is_windows())9{10echo "The system is running windows";11}12{13echo "The system is not running windows";14}15if(phodevi::is_osx())16{17echo "The system is running osx";18}19{20echo "The system is not running osx";21}22if(phodevi::is_bsd())23{24echo "The system is running bsd";25}26{27echo "The system is not running bsd";28}29if(phodevi::is_solaris())30{31echo "The system is running solaris";32}33{34echo "The system is not running solaris";35}

Full Screen

Full Screen

Automation Testing Tutorials

Learn to execute automation testing from scratch with LambdaTest Learning Hub. Right from setting up the prerequisites to run your first automation test, to following best practices and diving deeper into advanced test scenarios. LambdaTest Learning Hubs compile a list of step-by-step guides to help you be proficient with different test automation frameworks i.e. Selenium, Cypress, TestNG etc.

LambdaTest Learning Hubs:

YouTube

You could also refer to video tutorials over LambdaTest YouTube channel to get step by step demonstration from industry experts.

Try LambdaTest Now !!

Get 100 minutes of automation test minutes FREE!!

Next-Gen App & Browser Testing Cloud

Was this article helpful?

Helpful

NotHelpful