1<?php 2 3/* 4 Phoronix Test Suite 5 URLs: http://www.phoronix.com, http://www.phoronix-test-suite.com/ 6 Copyright (C) 2008 - 2021, Phoronix Media 7 Copyright (C) 2008 - 2021, Michael Larabel 8 phoronix-test-suite.php: The main code for initalizing the Phoronix Test Suite 9 10 This program is free software; you can redistribute it and/or modify 11 it under the terms of the GNU General Public License as published by 12 the Free Software Foundation; either version 3 of the License, or 13 (at your option) any later version. 14 15 This program is distributed in the hope that it will be useful, 16 but WITHOUT ANY WARRANTY; without even the implied warranty of 17 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 18 GNU General Public License for more details. 19 20 You should have received a copy of the GNU General Public License 21 along with this program. If not, see <http://www.gnu.org/licenses/>. 22*/ 23 24setlocale(LC_NUMERIC, 'C'); 25define('PTS_PATH', dirname(dirname(__FILE__)) . '/'); 26 27// PTS_MODE types 28// CLIENT = Standard Phoronix Test Suite Client 29// LIB = Only load select PTS files 30// SILENT = Load all normal pts-core files, but don't run client code 31if(!defined('PTS_MODE')) 32{ 33 define('PTS_MODE', in_array(($m = getenv('PTS_MODE')), array('CLIENT', 'LIB', 'WEB_CLIENT', 'SILENT')) ? $m : 'CLIENT'); 34} 35 36// Any PHP default memory limit should be fine for PTS, until you run image quality comparison tests that begins to consume memory 37ini_set('memory_limit', '1024M'); 38 39if(getenv('PTS_MODE') == 'CLIENT' && ini_get('open_basedir') != false) 40{ 41 $passes = true; 42 $open_basedir = ini_get('open_basedir'); 43 44 if($open_basedir != false) 45 { 46 $is_in_allowed_dir = false; 47 foreach(explode(':', $open_basedir) as $allowed_dir) 48 { 49 if(strpos(PTS_PATH, $allowed_dir) === 0) 50 { 51 $is_in_allowed_dir = true; 52 break; 53 } 54 } 55 56 if($is_in_allowed_dir == false) 57 { 58 $passes = false; 59 } 60 } 61 62 63 if($passes == false) 64 { 65 echo PHP_EOL . 'ERROR: The php.ini configuration open_basedir directive is preventing ' . PTS_PATH . ' from loading.' . PHP_EOL; 66 return false; 67 } 68 else 69 { 70 echo PHP_EOL . 'NOTICE: The php.ini configuration is using the "open_basedir" directive, which may prevent some parts of the Phoronix Test Suite from working. See the Phoronix Test Suite documentation for more details and to disable this setting.' . PHP_EOL; 71 sleep(1); 72 } 73} 74 75require(PTS_PATH . 'pts-core/pts-core.php'); 76 77if(!PTS_IS_CLIENT) 78{ 79 // pts-core is acting as a library, return now since no need to run client code 80 return; 81} 82 83// Default to C locale 84setlocale(LC_ALL, 'C'); 85 86// Needed for shutdown functions 87// declare(ticks = 1); 88 89$sent_command = strtolower(str_replace('-', '_', (isset($argv[1]) ? $argv[1] : null))); 90$quick_start_options = array('dump_possible_options'); 91pts_define('QUICK_START', in_array($sent_command, $quick_start_options)); 92 93if(QUICK_START == false) 94{ 95 pts_client::program_requirement_checks(true); 96} 97 98pts_client::init(); // Initalize the Phoronix Test Suite (pts-core) client 99$pass_args = array(); 100 101pts_client::handle_sent_command($sent_command, $argv, $argc); 102 103 104pts_define('PTS_USER_LOCK', function_exists('posix_getpid') ? PTS_USER_PATH . 'run-lock-' . posix_getpid() : tempnam(PTS_USER_PATH, 'run-lock-')); 105 106if(QUICK_START == false) 107{ 108 // Cleanup old / expired runlocks XXX expire if this can eventually be removed 109 foreach(pts_file_io::glob(PTS_USER_PATH . 'run-lock-*') as $possible_run_lock) 110 { 111 if(!pts_client::is_locked($possible_run_lock)) 112 { 113 pts_file_io::unlink($possible_run_lock); 114 } 115 } 116 if(pts_client::create_lock(PTS_USER_LOCK) == false) 117 { 118 //trigger_error('It appears that the Phoronix Test Suite is already running.' . PHP_EOL . 'For proper results, only run one instance at a time.', E_USER_WARNING); 119 } 120 121 register_shutdown_function(array('pts_client', 'process_shutdown_tasks')); 122 //pcntl_signal(SIGTERM, array('pts_client', 'exit_client')); 123 124 if(pts_client::read_env('PTS_IGNORE_MODULES') == false) 125 { 126 pts_client::module_framework_init(); // Initialize the PTS module system 127 } 128} 129 130// Read passed arguments 131for($i = 2; $i < $argc && isset($argv[$i]); $i++) 132{ 133 if(($x = strpos($argv[$i], '=')) !== false && substr($argv[$i], 0, $x) == strtoupper(substr($argv[$i], 0, $x))) 134 { 135 // Likely trying to pass an environment variable, so just go ahead and set it... 136 putenv($argv[$i]); 137 } 138 else 139 { 140 $pass_args[] = $argv[$i]; 141 } 142} 143 144if(QUICK_START == false) 145{ 146 pts_client::user_agreement_check($sent_command); 147 148 // OpenBenchmarking.org 149 pts_openbenchmarking::refresh_repository_lists(); 150} 151 152pts_client::execute_command($sent_command, $pass_args); // Run command 153 154if(QUICK_START == false) 155{ 156 pts_client::release_lock(PTS_USER_LOCK); 157} 158 159?> 160