예제 #1
0
 public static function execute_command($command, $pass_args = null)
 {
     if (!class_exists($command, false) && is_file(PTS_COMMAND_PATH . $command . '.php')) {
         include PTS_COMMAND_PATH . $command . '.php';
     }
     if (is_file(PTS_COMMAND_PATH . $command . '.php') && method_exists($command, 'argument_checks')) {
         $argument_checks = call_user_func(array($command, 'argument_checks'));
         foreach ($argument_checks as &$argument_check) {
             $function_check = $argument_check->get_function_check();
             $method_check = false;
             if (is_array($function_check) && count($function_check) == 2) {
                 $method_check = $function_check[0];
                 $function_check = $function_check[1];
             }
             if (substr($function_check, 0, 1) == '!') {
                 $function_check = substr($function_check, 1);
                 $return_fails_on = true;
             } else {
                 $return_fails_on = false;
             }
             if ($method_check != false) {
                 if (!method_exists($method_check, $function_check)) {
                     echo PHP_EOL . 'Method check fails.' . PHP_EOL;
                     continue;
                 }
                 $function_check = array($method_check, $function_check);
             } else {
                 if (!function_exists($function_check)) {
                     continue;
                 }
             }
             if ($argument_check->get_argument_index() == 'VARIABLE_LENGTH') {
                 $return_value = null;
                 foreach ($pass_args as $arg) {
                     $return_value = call_user_func_array($function_check, array($arg));
                     if ($return_value == true) {
                         break;
                     }
                 }
             } else {
                 $return_value = call_user_func_array($function_check, array(isset($pass_args[$argument_check->get_argument_index()]) ? $pass_args[$argument_check->get_argument_index()] : null));
             }
             if ($return_value == $return_fails_on) {
                 $command_alias = defined($command . '::doc_use_alias') ? constant($command . '::doc_use_alias') : $command;
                 if (isset($pass_args[$argument_check->get_argument_index()]) && !empty($pass_args[$argument_check->get_argument_index()]) || $argument_check->get_argument_index() == 'VARIABLE_LENGTH' && !empty($pass_args)) {
                     trigger_error('Invalid Argument: ' . implode(' ', $pass_args), E_USER_ERROR);
                 } else {
                     trigger_error('Phoronix Test Suite Argument Missing.', E_USER_ERROR);
                 }
                 echo PHP_EOL . 'CORRECT SYNTAX:' . PHP_EOL . 'phoronix-test-suite ' . str_replace('_', '-', $command_alias) . ' ' . implode(' ', $argument_checks) . PHP_EOL . PHP_EOL;
                 if (method_exists($command, 'invalid_command')) {
                     call_user_func_array(array($command, 'invalid_command'), $pass_args);
                     echo PHP_EOL;
                 }
                 return false;
             } else {
                 if ($argument_check->get_function_return_key() != null && !isset($pass_args[$argument_check->get_function_return_key()])) {
                     $pass_args[$argument_check->get_function_return_key()] = $return_value;
                 }
             }
         }
     }
     pts_module_manager::module_process('__pre_option_process', $command);
     if (is_file(PTS_COMMAND_PATH . $command . '.php')) {
         self::$current_command = $command;
         if (method_exists($command, 'run')) {
             call_user_func(array($command, 'run'), $pass_args);
         } else {
             echo PHP_EOL . 'There is an error in the requested command: ' . $command . PHP_EOL . PHP_EOL;
         }
     } else {
         if (($t = pts_module::valid_run_command($command)) != false) {
             list($module, $module_command) = $t;
             pts_module_manager::set_current_module($module);
             pts_module_manager::run_command($module, $module_command, $pass_args);
             pts_module_manager::set_current_module(null);
         }
     }
     echo PHP_EOL;
     pts_module_manager::module_process('__post_option_process', $command);
 }
// Default to C locale
setlocale(LC_ALL, 'C');
// Needed for shutdown functions
// declare(ticks = 1);
$sent_command = strtolower(str_replace('-', '_', isset($argv[1]) ? $argv[1] : null));
$quick_start_options = array('dump_possible_options');
pts_define('QUICK_START', in_array($sent_command, $quick_start_options));
if (QUICK_START == false) {
    pts_client::program_requirement_checks(true);
}
pts_client::init();
// Initalize the Phoronix Test Suite (pts-core) client
$pass_args = array();
if (is_file(PTS_PATH . 'pts-core/commands/' . $sent_command . '.php') == false) {
    $replaced = false;
    if (pts_module::valid_run_command($sent_command)) {
        $replaced = true;
    } else {
        if (isset($argv[1]) && strpos($argv[1], '.openbenchmarking') !== false && is_readable($argv[1])) {
            $sent_command = 'openbenchmarking_launcher';
            $argv[2] = $argv[1];
            $argc = 3;
            $replaced = true;
        } else {
            $aliases = pts_storage_object::read_from_file(PTS_TEMP_STORAGE, 'command_alias_list');
            if ($aliases == null) {
                $aliases = pts_documentation::client_commands_aliases();
            }
            if (isset($aliases[$sent_command])) {
                $sent_command = $aliases[$sent_command];
                $replaced = true;