Best Phoronix-test-suite code snippet using pts_test_installer.create_compiler_mask
pts_test_installer.php
Source:pts_test_installer.php
...401 }402 pts_module_manager::module_process('__post_test_download', $identifier);403 return true;404 }405 public static function create_compiler_mask(&$test_install_request)406 {407 if(phodevi::is_bsd() || getenv('PTS_NO_COMPILER_MASK'))408 {409 // 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.0410 return false;411 }412 // or pass false to $test_install_request to bypass the test checks413 $compilers = array();414 $external_dependencies = $test_install_request != false ? $test_install_request->test_profile->get_external_dependencies() : false;415 if($test_install_request === false || in_array('build-utilities', $external_dependencies))416 {417 // Handle C/C++ compilers for this external dependency418 $compilers['CC'] = array(pts_strings::first_in_string(pts_client::read_env('CC'), ' '), 'gcc', 'clang', 'icc', 'pcc');419 $compilers['CXX'] = array(pts_strings::first_in_string(pts_client::read_env('CXX'), ' '), 'g++', 'clang++', 'cpp');420 }421 if($test_install_request === false || in_array('fortran-compiler', $external_dependencies))422 {423 // Handle Fortran for this external dependency424 $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');425 }426 if(empty($compilers))427 {428 // If the test profile doesn't request a compiler external dependency, probably not compiling anything429 return false;430 }431 foreach($compilers as $compiler_type => $possible_compilers)432 {433 // Compilers to check for, listed in order of priority434 $compiler_found = false;435 foreach($possible_compilers as $i => $possible_compiler)436 {437 // first check to ensure not null sent to executable_in_path from env variable438 if($possible_compiler && (($compiler_path = is_executable($possible_compiler)) || ($compiler_path = pts_client::executable_in_path($possible_compiler, 'ccache'))))439 {440 // Replace the array of possible compilers with a string to the detected compiler executable441 $compilers[$compiler_type] = $compiler_path;442 $compiler_found = true;443 break;444 }445 }446 if($compiler_found == false)447 {448 unset($compilers[$compiler_type]);449 }450 }451 if(!empty($compilers))452 {453 // Create a temporary directory that will be at front of PATH and serve for masking the actual compiler454 if($test_install_request instanceof pts_test_install_request)455 {456 $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() . '/';457 }458 else459 {460 $mask_dir = pts_client::temporary_directory() . '/pts-compiler-mask-' . rand(100, 999) . '/';461 }462 pts_file_io::mkdir($mask_dir);463 $compiler_extras = array(464 'CC' => array('safeguard-names' => array('gcc', 'cc'), 'environment-variables' => 'CFLAGS'),465 'CXX' => array('safeguard-names' => array('g++', 'c++'), 'environment-variables' => 'CXXFLAGS'),466 'F9X' => array('safeguard-names' => array('gfortran', 'f95'), 'environment-variables' => 'F9XFLAGS')467 );468 foreach($compilers as $compiler_type => $compiler_path)469 {470 $compiler_name = basename($compiler_path);471 $main_compiler = $mask_dir . $compiler_name;472 // take advantage of environment-variables to be sure they're found in the string473 $env_var_check = PHP_EOL;474 /*475 foreach(pts_arrays::to_array($compiler_extras[$compiler_type]['environment-variables']) as $env_var)476 {477 // since it's a dynamic check in script could probably get rid of this check...478 if(true || getenv($env_var))479 {480 $env_var_check .= 'if [[ $COMPILER_OPTIONS != "*$' . $env_var . '*" ]]' . PHP_EOL . 'then ' . PHP_EOL . 'COMPILER_OPTIONS="$COMPILER_OPTIONS $' . $env_var . '"' . PHP_EOL . 'fi' . PHP_EOL;481 }482 }483 */484 // Write the main mask for the compiler485 file_put_contents($main_compiler,486 '#!/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);487 // Make executable488 chmod($main_compiler, 0755);489 // The two below code chunks ensure the proper compiler is always hit490 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)491 {492 // 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 below493 $test_install_request->special_environment_vars[$compiler_type] = $compiler_name;494 }495 // 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 test496 foreach(pts_arrays::to_array($compiler_extras[$compiler_type]['safeguard-names']) as $safe_name)497 {498 if(!is_file($mask_dir . $safe_name))499 {500 symlink($main_compiler, $mask_dir . $safe_name);501 }502 }503 }504 if($test_install_request instanceof pts_test_install_request)505 {506 $test_install_request->compiler_mask_dir = $mask_dir;507 // Appending the rest of the path will be done automatically within call_test_script508 $test_install_request->special_environment_vars['PATH'] = $mask_dir;509 }510 return $mask_dir;511 }512 return false;513 }514 public static function end_compiler_mask(&$test_install_request)515 {516 if($test_install_request->compiler_mask_dir == false && !is_dir($test_install_request->compiler_mask_dir))517 {518 return false;519 }520 $compiler = false;521 foreach(pts_file_io::glob($test_install_request->compiler_mask_dir . '*-options-*') as $compiler_output)522 {523 $output_name = basename($compiler_output);524 $compiler_type = substr($output_name, 0, strpos($output_name, '-'));525 $compiler_choice = substr($output_name, (strrpos($output_name, 'options-') + 8));526 $compiler_lines = explode(PHP_EOL, pts_file_io::file_get_contents($compiler_output));527 // Clean-up / reduce the compiler options that are important528 $compiler_options = null;529 $compiler_backup_line = null;530 foreach($compiler_lines as $l => $compiler_line)531 {532 $compiler_line .= ' '; // allows for easier/simplified detection in a few checks below533 $o = strpos($compiler_line, '-o ');534 if($o === false)535 {536 unset($compiler_lines[$l]);537 continue;538 }539 $o = substr($compiler_line, ($o + 3), (strpos($compiler_line, ' ', ($o + 3)) - $o - 3));540 $o_l = strlen($o);541 // $o now has whatever is set for the -o output542 if(($o_l > 2 && substr(basename($o), 0, 3) == 'lib') || ($o_l > 3 && substr($o, -4) == 'test'))543 {544 // If it's a lib, probably not what is the actual target545 unset($compiler_lines[$l]);546 continue;547 }548 else if(($o_l > 2 && substr($o, -2) == '.o'))549 {550 // If it's outputting to a .o should not be the proper compile command we want551 // but back it up in case... keep overwriting temp variable to get the last one552 $compiler_backup_line = $compiler_line;553 unset($compiler_lines[$l]);554 continue;555 }556 }557 if(!empty($compiler_lines))558 {559 $compiler_line = array_pop($compiler_lines);560 if(strpos($compiler_line, '-O') === false && strpos($compiler_line, '-f') === false && (strpos($compiler_backup_line, '-f') !== false || strpos($compiler_backup_line, '-O')))561 {562 $compiler_line .= ' ' . $compiler_backup_line;563 }564 $compiler_options = explode(' ', $compiler_line);565 foreach($compiler_options as $i => $option)566 {567 // Decide what to include and what not... D?568 if(!isset($option[2]) || $option[0] != '-' || $option[1] == 'L' || $option[1] == 'D' || $option[1] == 'I' || $option[1] == 'W' || isset($option[20]))569 {570 unset($compiler_options[$i]);571 }572 if(isset($option[1]) && $option[1] == 'l')573 {574 // If you're linking a library it's also useful for other purposes575 $library = substr($option, 1);576 // TODO XXX: scan the external dependencies to make sure $library is covered if not alert test profile maintainer...577 //unset($compiler_options[$i]);578 }579 }580 $compiler_options = implode(' ', array_unique($compiler_options));581 //sort($compiler_options);582 // TODO: right now just keep overwriting $compiler to take the last compiler.. so TODO add support for multiple compiler reporting or decide what todo583 $compiler = array('compiler-type' => $compiler_type, 'compiler' => $compiler_choice, 'compiler-options' => $compiler_options);584 //echo PHP_EOL . 'DEBUG: ' . $compiler_type . ' ' . $compiler_choice . ' :: ' . $compiler_options . PHP_EOL;585 }586 }587 pts_file_io::delete($test_install_request->compiler_mask_dir, null, true);588 return $compiler;589 }590 protected static function install_test_process(&$test_install_request, $no_prompts)591 {592 // Install a test593 $identifier = $test_install_request->test_profile->get_identifier();594 $test_install_directory = $test_install_request->test_profile->get_install_dir();595 pts_file_io::mkdir(dirname($test_install_directory));596 pts_file_io::mkdir($test_install_directory);597 $installed = false;598 if(ceil(disk_free_space($test_install_directory) / 1048576) < ($test_install_request->test_profile->get_download_size() + 128))599 {600 self::test_install_error(null, $test_install_request, 'There is not enough space at ' . $test_install_directory . ' for the test files.');601 }602 else if(ceil(disk_free_space($test_install_directory) / 1048576) < ($test_install_request->test_profile->get_environment_size(false) + 128))603 {604 self::test_install_error(null, $test_install_request, 'There is not enough space at ' . $test_install_directory . ' for this test.');605 }606 else607 {608 pts_test_installer::setup_test_install_directory($test_install_request, true);609 // Download test files610 $download_test_files = pts_test_installer::download_test_files($test_install_request, false, $no_prompts);611 if($download_test_files == false)612 {613 self::test_install_error(null, $test_install_request, 'Downloading of needed test files failed.');614 return false;615 }616 if($test_install_request->test_profile->get_file_installer() != false)617 {618 self::create_compiler_mask($test_install_request);619 pts_module_manager::module_process('__pre_test_install', $identifier);620 pts_client::$display->test_install_begin($test_install_request);621 $pre_install_message = $test_install_request->test_profile->get_pre_install_message();622 $post_install_message = $test_install_request->test_profile->get_post_install_message();623 $install_agreement = $test_install_request->test_profile->get_installation_agreement_message();624 if(!empty($install_agreement))625 {626 if(pts_strings::is_url($install_agreement))627 {628 $install_agreement = pts_network::http_get_contents($install_agreement);629 if(empty($install_agreement))630 {631 self::test_install_error(null, $test_install_request, 'The user agreement could not be found. Test installation aborted.');632 return false;...
create_compiler_mask
Using AI Code Generation
1require_once('pts-test-installer.php');2$test_installer = new pts_test_installer();3$mask = $test_installer->create_compiler_mask();4echo $mask;5Compiler name (GCC, ICC, CLANG, PGI, etc.)6Compiler version (4.8, 5.0, etc.)7Compiler architecture (x86_64, i686, etc.)8Compiler vendor (Ubuntu, Debian, etc.)9Compiler flags (CFLAGS, CXXFLAGS, etc.)
create_compiler_mask
Using AI Code Generation
1$compiler_mask = pts_test_installer::create_compiler_mask('gcc');2$test_profile = new pts_test_profile('x264');3$test_profile->set_test_installation($compiler_mask);4$test_profile->save_profile_to_file();5$compiler_mask = pts_test_installer::create_compiler_mask('gcc');6$test_profile = new pts_test_profile('x264');7$test_profile->set_test_installation($compiler_mask);8$test_profile->save_profile_to_file();9$compiler_mask = pts_test_installer::create_compiler_mask('gcc');10$test_profile = new pts_test_profile('x264');11$test_profile->set_test_installation($compiler_mask);12$test_profile->save_profile_to_file();
create_compiler_mask
Using AI Code Generation
1include_once('pts_test_installer.php');2$test_installer = new pts_test_installer();3$compilers = array('gcc-4.4', 'gcc-4.5', 'gcc-4.6', 'gcc-4.7', 'gcc-4.8', 'gcc-4.9');4$test_profiles = array('pts/ffmpeg-1.2', 'pts/ffmpeg-1.3');5$compiler_mask = $test_installer->create_compiler_mask($compilers, $test_profiles);6print_r($compiler_mask);7 (8 (9 (10 (11 (12 (13 (14 (
create_compiler_mask
Using AI Code Generation
1$mask = pts_test_installer::create_compiler_mask('gcc');2if($mask == 'not installed')3{4echo 'gcc is not installed';5}6{7echo 'gcc is installed, version: ' . $mask;8}9$mask = pts_test_installer::create_compiler_mask('g++');10if($mask == 'not installed')11{12echo 'g++ is not installed';13}14{15echo 'g++ is installed, version: ' . $mask;16}17$mask = pts_test_installer::create_compiler_mask('clang');18if($mask == 'not installed')19{20echo 'clang is not installed';21}22{23echo 'clang is installed, version: ' . $mask;24}25$mask = pts_test_installer::create_compiler_mask('clang++');26if($mask ==
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 create_compiler_mask 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!!