Best Phoronix-test-suite code snippet using pts_arrays.to_array
phodevi_linux_parser.php
Source: phodevi_linux_parser.php
...21 public static function read_ipmitool_sensor($sensors, $default_value = false)22 {23 $value = $default_value;24 $ipmitool = shell_exec('ipmitool sdr list 2>&1');25 foreach(pts_arrays::to_array($sensors) as $sensor)26 {27 $hit = stripos($ipmitool, $sensor);28 if($hit !== false)29 {30 $trimmed = substr($ipmitool, ($hit + strlen($sensor)));31 $trimmed = substr($trimmed, 0, strpos($trimmed, PHP_EOL));32 $trimmed = explode('|', $trimmed);33 if(count($trimmed) == 3)34 {35 $value = explode(' ', trim($trimmed[1]));36 $value = $value[0];37 break;38 }39 }40 }41 return $value;42 }43 public static function read_ipmitool_dcmi_power()44 {45 $value = false;46 $ipmitool = shell_exec('ipmitool dcmi power reading 2>&1');47 $sensor = "Instantaneous power reading:";48 $hit = stripos($ipmitool, $sensor);49 if($hit !== false)50 {51 $trimmed = substr($ipmitool, ($hit + strlen($sensor)));52 $trimmed = substr($trimmed, 0, strpos($trimmed, PHP_EOL));53 $trimmed = trim($trimmed);54 $trimmed = explode(' ', $trimmed);55 if(count($trimmed) == 2)56 {57 $value = $trimmed[0];58 }59 }60 return $value;61 }62 public static function read_sysfs_node($search, $type = 'NUMERIC', $node_dir_check = null, $find_position = 1)63 {64 static $sysfs_file_cache = null;65 $arg_hash = crc32(serialize(func_get_args()));66 if(!isset($sysfs_file_cache[$arg_hash]))67 {68 $find_count = 0;69 foreach(pts_file_io::glob($search) as $sysfs_file)70 {71 if(is_array($node_dir_check))72 {73 $skip_to_next = false;74 $sysfs_dir = dirname($sysfs_file) . '/';75 foreach($node_dir_check as $node_check => $value_check)76 {77 if(!is_file($sysfs_dir . $node_check))78 {79 $skip_to_next = true;80 break;81 }82 else if($value_check !== true)83 {84 $value_check_value = pts_file_io::file_get_contents($sysfs_dir . $node_check);85 foreach(explode(',', $value_check) as $check)86 {87 if(isset($check[0]) && $check[0] == '!')88 {89 if($value_check_value == substr($check, 1))90 {91 $skip_to_next = true;92 break;93 }94 }95 else if($value_check_value != $check)96 {97 $skip_to_next = true;98 break;99 }100 }101 }102 if($skip_to_next)103 {104 break;105 }106 }107 if($skip_to_next)108 {109 continue;110 }111 }112 $sysfs_value = pts_file_io::file_get_contents($sysfs_file);113 switch($type)114 {115 case 'NUMERIC':116 if(is_numeric($sysfs_value))117 {118 $sysfs_file_cache[$arg_hash] = $sysfs_file;119 }120 break;121 case 'POSITIVE_NUMERIC':122 if(is_numeric($sysfs_value) && $sysfs_value > 0)123 {124 $sysfs_file_cache[$arg_hash] = $sysfs_file;125 }126 break;127 case 'NOT_EMPTY':128 if(!empty($sysfs_value))129 {130 $sysfs_file_cache[$arg_hash] = $sysfs_file;131 }132 break;133 case 'NO_CHECK':134 $sysfs_file_cache[$arg_hash] = $sysfs_file;135 break;136 }137 $find_count++;138 if($find_count < $find_position)139 {140 unset($sysfs_file_cache[$arg_hash]);141 }142 if(isset($sysfs_file_cache[$arg_hash]))143 {144 break;145 }146 }147 if(!isset($sysfs_file_cache[$arg_hash]))148 {149 $sysfs_file_cache[$arg_hash] = false;150 }151 }152 return $sysfs_file_cache[$arg_hash] == false ? -1 : pts_file_io::file_get_contents($sysfs_file_cache[$arg_hash]);153 }154 public static function read_dmidecode($type, $sub_type, $object, $find_once = false, $ignore = null)155 {156 // Read Linux dmidecode157 $value = array();158 if((phodevi::is_root() || is_readable('/dev/mem')) && pts_client::executable_in_path('dmidecode'))159 {160 $ignore = array_map('strtolower', pts_arrays::to_array($ignore));161 $dmidecode = shell_exec('dmidecode --type ' . $type . ' 2>&1');162 $sub_type = "\n" . $sub_type . "\n";163 do164 {165 $sub_type_start = strpos($dmidecode, $sub_type);166 if($sub_type_start !== false)167 {168 $dmidecode = substr($dmidecode, ($sub_type_start + strlen($sub_type)));169 $dmidecode_section = substr($dmidecode, 0, strpos($dmidecode, "\n\n"));170 $dmidecode = substr($dmidecode, strlen($dmidecode_section));171 $dmidecode_elements = explode("\n", $dmidecode_section);172 $found_in_section = false;173 for($i = 0; $i < count($dmidecode_elements) && $found_in_section == false; $i++)174 {175 $dmidecode_r = pts_strings::colon_explode($dmidecode_elements[$i]);176 if($dmidecode_r[0] == $object && isset($dmidecode_r[1]) && !in_array(strtolower($dmidecode_r[1]), $ignore))177 {178 array_push($value, $dmidecode_r[1]);179 $found_in_section = true;180 }181 }182 }183 }184 while($sub_type_start !== false && ($find_once == false || $found_in_section == false));185 }186 if(count($value) == 0)187 {188 $value = false;189 }190 else if($find_once && count($value) == 1)191 {192 $value = $value[0];193 }194 return $value;195 }196 public static function read_sys_disk_speed($path, $to_read)197 {198 $delta_mb = -1; // in MB/s199 $measure_time = 1000000; // microseconds200 if(is_file($path))201 {202 switch($to_read)203 {204 case 'WRITE':205 $sector = 6;206 break;207 case 'READ':208 $sector = 2;209 break;210 default:211 return $delta_mb;212 break;213 }214 $start_stat = pts_strings::trim_spaces(file_get_contents($path));215 usleep($measure_time);216 $end_stat = pts_strings::trim_spaces(file_get_contents($path));217 $start_stat = explode(' ', $start_stat);218 $end_stat = explode(' ', $end_stat);219 $delta_sectors = $end_stat[$sector] - $start_stat[$sector];220 // TODO check sector size instead of hardcoding it221 $delta_mb = $delta_sectors * 512 / 1048576;222 $speed = $delta_mb * 1000000 / $measure_time;223 }224 return pts_math::set_precision($speed, 2);225 }226 public static function read_sys_dmi($identifier)227 {228 $dmi = false;229 if(is_dir('/sys/class/dmi/id/'))230 {231 $ignore_words = phodevi_parser::hardware_values_to_remove();232 foreach(pts_arrays::to_array($identifier) as $id)233 {234 if(is_readable('/sys/class/dmi/id/' . $id))235 {236 $dmi_file = pts_file_io::file_get_contents('/sys/class/dmi/id/' . $id);237 if(!empty($dmi_file) && !in_array(strtolower($dmi_file), $ignore_words))238 {239 $dmi = $dmi_file;240 break;241 }242 }243 }244 }245 return $dmi;246 }247 public static function read_cpuinfo($attribute, $cpuinfo = false)248 {249 // Read CPU information250 $cpuinfo_matches = array();251 if($cpuinfo == false)252 {253 if(is_file('/proc/cpuinfo'))254 {255 $cpuinfo = file_get_contents('/proc/cpuinfo');256 }257 else258 {259 return $cpuinfo_matches;260 }261 }262 foreach(pts_arrays::to_array($attribute) as $attribute_check)263 {264 $cpuinfo_lines = explode("\n", $cpuinfo);265 foreach($cpuinfo_lines as $line)266 {267 $line = pts_strings::trim_explode(': ', $line);268 if(!isset($line[0]))269 {270 continue;271 }272 $this_attribute = $line[0];273 $this_value = (count($line) > 1 ? $line[1] : null);274 if($this_attribute == $attribute_check)275 {276 array_push($cpuinfo_matches, $this_value);277 }278 }279 if(count($cpuinfo_matches) != 0)280 {281 break;282 }283 }284 return $cpuinfo_matches;285 }286 public static function read_cpuinfo_single($attribute, $cpuinfo = false)287 {288 $cpuinfo = self::read_cpuinfo($attribute, $cpuinfo);289 if(!empty($cpuinfo))290 {291 return array_pop($cpuinfo);292 }293 return null;294 }295 public static function read_lsb_distributor_id()296 {297 $vendor = phodevi_linux_parser::read_lsb('Distributor ID');298 // Quirks for derivative distributions that don't know how to handle themselves properly299 if($vendor == 'MandrivaLinux' && phodevi_linux_parser::read_lsb('Description') == 'PCLinuxOS')300 {301 // PC Linux OS only stores its info in /etc/pclinuxos-release302 $vendor = false;303 }304 return $vendor;305 }306 public static function read_lsb($desc)307 {308 // Read LSB Release information, Linux Standards Base309 $info = false;310 if(pts_client::executable_in_path('lsb_release'))311 {312 static $output = null;313 if($output == null)314 {315 $output = shell_exec('lsb_release -a 2>&1');316 }317 if(($pos = strrpos($output, $desc . ':')) !== false)318 {319 $info = substr($output, $pos + strlen($desc) + 1);320 $info = trim(substr($info, 0, strpos($info, "\n")));321 }322 if(strtolower($info) == 'n/a')323 {324 $info = false;325 }326 }327 return $info;328 }329 public static function read_acpi($point, $match)330 {331 // Read ACPI - Advanced Configuration and Power Interface332 $value = false;333 $point = pts_arrays::to_array($point);334 for($i = 0; $i < count($point) && empty($value); $i++)335 {336 if(is_file('/proc/acpi' . $point[$i]))337 {338 $acpi_lines = explode("\n", file_get_contents('/proc/acpi' . $point[$i]));339 for($i = 0; $i < count($acpi_lines) && $value == false; $i++)340 {341 $line = pts_strings::trim_explode(': ', $acpi_lines[$i]);342 if(!isset($line[0]))343 {344 continue;345 }346 $this_attribute = $line[0];347 $this_value = (count($line) > 1 ? $line[1] : null);348 if($this_attribute == $match)349 {350 $value = $this_value;351 }352 }353 }354 }355 return $value;356 }357 public static function read_pci_subsystem_value($desc)358 {359 $lspci = shell_exec('lspci -v 2> /dev/null');360 $subsystem = null;361 foreach(pts_arrays::to_array($desc) as $check)362 {363 if(($hit = strpos($lspci, $check)) !== false)364 {365 $lspci = substr($lspci, $hit);366 if(($hit = strpos($lspci, 'Subsystem: ')) !== false)367 {368 $lspci = substr($lspci, ($hit + strlen('Subsystem: ')));369 $lspci = substr($lspci, 0, strpos($lspci, PHP_EOL));370 $vendors = array(371 'Sapphire Technology' => 'Sapphire',372 'PC Partner' => 'Sapphire',373 'Micro-Star International' => 'MSI',374 'XFX' => 'XFX',375 'ASUS' => 'ASUS',376 'Gigabyte' => 'Gigabyte',377 'Elitegroup' => 'ECS',378 'eVga' => 'eVGA',379 'Hightech Information System' => 'HIS',380 'Zotac' => 'Zotac'381 );382 foreach($vendors as $vendor => $clean_vendor)383 {384 if(stripos($lspci, $vendor) !== false)385 {386 $subsystem = $clean_vendor;387 break;388 }389 }390 }391 }392 }393 return $subsystem;394 }395 public static function read_pci($desc, $clean_string = true)396 {397 // Read PCI bus information398 static $pci_info = null;399 $info = false;400 $desc = pts_arrays::to_array($desc);401 if($pci_info == null)402 {403 if(!is_executable('/usr/bin/lspci') && is_executable('/sbin/lspci'))404 {405 $lspci_cmd = '/sbin/lspci';406 }407 else if(($lspci = pts_client::executable_in_path('lspci')))408 {409 $lspci_cmd = $lspci;410 }411 else412 {413 return false;414 }415 $pci_info = shell_exec($lspci_cmd . ' 2> /dev/null');416 }417 for($i = 0; $i < count($desc) && empty($info); $i++)418 {419 if(substr($desc[$i], -1) != ':')420 {421 $desc[$i] .= ':';422 }423 if(($pos = strpos($pci_info, $desc[$i])) !== false)424 {425 $sub_pci_info = str_replace(array('[AMD]', '[AMD/ATI]', ' Limited'), null, substr($pci_info, $pos + strlen($desc[$i])));426 $EOL = strpos($sub_pci_info, "\n");427 if($clean_string)428 {429 if(($temp = strpos($sub_pci_info, '/')) < $EOL && $temp > 0)430 {431 if(($temp = strpos($sub_pci_info, ' ', ($temp + 2))) < $EOL && $temp > 0)432 {433 $EOL = $temp;434 }435 }436 if(($temp = strpos($sub_pci_info, '(')) < $EOL && $temp > 0)437 {438 $EOL = $temp;439 }440 if(($temp = strpos($sub_pci_info, '[')) < $EOL && $temp > 0)441 {442 $EOL = $temp;443 }444 }445 $sub_pci_info = trim(substr($sub_pci_info, 0, $EOL));446 if(($strlen = strlen($sub_pci_info)) >= 6 && $strlen < 128)447 {448 $info = pts_strings::strip_string($sub_pci_info);449 }450 }451 }452 return $info;453 }454 public static function read_pci_multi($desc, $clean_string = true)455 {456 // Read PCI bus information457 static $pci_info = null;458 $info = array();459 $desc = pts_arrays::to_array($desc);460 if($pci_info == null)461 {462 if(!is_executable('/usr/bin/lspci') && is_executable('/sbin/lspci'))463 {464 $lspci_cmd = '/sbin/lspci';465 }466 else if(($lspci = pts_client::executable_in_path('lspci')))467 {468 $lspci_cmd = $lspci;469 }470 else471 {472 return false;473 }474 $pci_info = shell_exec($lspci_cmd . ' 2> /dev/null');475 }476 for($i = 0; $i < count($desc); $i++)477 {478 if(substr($desc[$i], -1) != ':')479 {480 $desc[$i] .= ':';481 }482 $pos = 0;483 while(($pos = strpos($pci_info, $desc[$i], $pos)) !== false)484 {485 $pos += strlen($desc[$i]);486 $sub_pci_info = str_replace(array('[AMD]', '[AMD/ATI]', ' Limited', ' Connection', ' Gigabit', ' Wireless', '(1)', '(2)', '(3)', '(4)', '(5)', '(6)', '(7)', '(8)', '(9)'), null, substr($pci_info, $pos));487 $EOL = strpos($sub_pci_info, "\n");488 if($clean_string)489 {490 if(($temp = strpos($sub_pci_info, '/')) < $EOL && $temp > 0)491 {492 if(($temp = strpos($sub_pci_info, ' ', ($temp + 2))) < $EOL && $temp > 0)493 {494 $EOL = $temp;495 }496 }497 if(($temp = strpos($sub_pci_info, '(')) < $EOL && $temp > 0)498 {499 $EOL = $temp;500 }501 if(($temp = strpos($sub_pci_info, '[')) < $EOL && $temp > 0)502 {503 $EOL = $temp;504 }505 }506 $sub_pci_info = trim(substr($sub_pci_info, 0, $EOL));507 if(($strlen = strlen($sub_pci_info)) >= 6 && $strlen < 128)508 {509 $info[] = pts_strings::strip_string($sub_pci_info);510 }511 }512 }513 return $info;514 }515 public static function read_sensors($attributes)516 {517 // Read LM_Sensors518 $value = false;519 if(isset(phodevi::$vfs->sensors))520 {521 $sensors = phodevi::$vfs->sensors;522 $sensors_lines = explode("\n", $sensors);523 $attributes = pts_arrays::to_array($attributes);524 for($j = 0; $j < count($attributes) && empty($value); $j++)525 {526 $attribute = $attributes[$j];527 for($i = 0; $i < count($sensors_lines) && $value == false; $i++)528 {529 $line = pts_strings::trim_explode(': ', $sensors_lines[$i]);530 if(!isset($line[0]))531 {532 continue;533 }534 $this_attribute = $line[0];535 if($this_attribute == $attribute)536 {537 $this_remainder = trim(str_replace(array('+', '°'), ' ', $line[1]));...
to_array
Using AI Code Generation
1$my_array = array(1,2,3,4,5,6,7,8,9,10);2$my_array = pts_arrays::to_array($my_array, 2);3print_r($my_array);4 (5 (6 (7 (8 (9$my_array = array(1,2,3,4,5,6,7,8,9,10);10$my_array = pts_arrays::to_array($my_array, 3);11print_r($my_array);12 (13 (14 (15 (16$my_array = array(1,2,3,4,5,6,7,8,9,10);17$my_array = pts_arrays::to_array($my_array, 4);18print_r($my_array);19 (
Check out the latest blogs from LambdaTest on this topic:
Have you ever visited a website that only has plain text and images? Most probably, no. It’s because such websites do not exist now. But there was a time when websites only had plain text and images with almost no styling. For the longest time, websites did not focus on user experience. For instance, this is how eBay’s homepage looked in 1999.
Pair testing can help you complete your testing tasks faster and with higher quality. But who can do pair testing, and when should it be done? And what form of pair testing is best for your circumstance? Check out this blog for more information on how to conduct pair testing to optimize its benefits.
Continuous integration is a coding philosophy and set of practices that encourage development teams to make small code changes and check them into a version control repository regularly. Most modern applications necessitate the development of code across multiple platforms and tools, so teams require a consistent mechanism for integrating and validating changes. Continuous integration creates an automated way for developers to build, package, and test their applications. A consistent integration process encourages developers to commit code changes more frequently, resulting in improved collaboration and code quality.
Greetings folks! With the new year finally upon us, we’re excited to announce a collection of brand-new product updates. At LambdaTest, we strive to provide you with a comprehensive test orchestration and execution platform to ensure the ultimate web and mobile experience.
Development practices are constantly changing and as testers, we need to embrace change. One of the changes that we can experience is the move from monthly or quarterly releases to continuous delivery or continuous deployment. This move to continuous delivery or deployment offers testers the chance to learn new skills.
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.
You could also refer to video tutorials over LambdaTest YouTube channel to get step by step demonstration from industry experts.
Execute automation tests with to_array on a cloud-based Grid of 3000+ real browsers and operating systems for both web and mobile applications.
Test now for FreeGet 100 minutes of automation test minutes FREE!!