function generate_support_file($subject) { // get the output $command = $this->get_command_line($subject); list($out, $err, $exit) = complete_exec($command); if ($exit == 0) { $this->write_support_file($out, $subject); $this->mark_success($subject); } else { $this->mark_skipped($subject, "Non zero exit code ({$exit})"); } }
function get_pass_list() { global $phc; static $cache = false; // we only need to call this once if ($cache === false) { list($out, $err, $exit) = complete_exec("{$phc} --list-passes"); assert($out and $err === "" and $exit === 0); preg_match_all("/([a-zA-Z-_0-9]+)\\s+\\((enabled|disabled)\\s+- (AST|HIR|MIR|LIR)\\)\\s+.+/", $out, $matches); $cache = $matches[1]; } return $cache; }
function test($str) { list($out, $err, $exit) = complete_exec("echo '<?php \$x = {$str} ?>' | php"); if ($exit || $out) { global $bad; $bad[] = array($str, $out, $err, $exit); return false; // indicate we dont want to test this again } else { global $good; $good[] = "var_dump ({$str});"; return true; } }
function insert_results(PDO $DB, $filename, $flags, $flow_context) { print "{$filename}\n"; list($output, $err, $exit_code) = complete_exec("ulimit -t 2400 && ulimit -v 8000000 && src/phc --stats -O2 {$filename} {$flags}", NULL, 0); if ($err or $exit_code) { print "exit: {$exit_code}\n"; print $err; } $output = split("\n", $output); $date = date("c"); print_r($output); foreach ($output as $o) { $fields = split("\\|", $o); if (count($fields) == 3) { $DB->exec("\n\t\t\t\t\tINSERT INTO results\n\t\t\t\t\tVALUES ('{$date}',\n\t\t\t\t\t\t'{$filename}',\n\t\t\t\t\t\t'{$flow_context}',\n\t\t\t\t\t\t'" . $fields[0] . "',\n\t\t\t\t\t\t'" . $fields[2] . "',\n\t\t\t\t\t\t'" . $fields[1] . "')\n\t\t\t\t\t"); } } return $exit_code; }
function _exec($command) { // 20 seconds, max list($output) = complete_exec($command, NULL, 20); return $output; }
function myrun($command, $stdin = NULL) { if ($stdin === NULL) { mydebug(2, "Running command: {$command}"); } else { mydebug(2, "Running command with stdin: {$command}"); } # complete_exec prints commands at opt_verbose = 1, but we want it at 2 global $opt_verbose; $old = $opt_verbose; $opt_verbose = false; $result = complete_exec($command, $stdin); $opt_verbose = $old; if ($result[0] == "Timeout") { mydebug(2, "Command timed out"); } return $result; }
function finish($bundle) { global $opt_debug; $expected_final_xml = $bundle->outs[0]; $final_xml = $bundle->outs[1]; if ($final_xml === $expected_final_xml) { $this->async_success($bundle); } else { $pass_string = ""; if ($opt_debug) { $last_pass = end(get_pass_list()); // find the failing part foreach (get_pass_list() as $pass) { $command1 = $this->get_command_line($pass, $bundle->subject); $command2 = $this->get_long_command_line($bundle->subject, $pass); if (($result1 = complete_exec($command1)) !== ($result2 = complete_exec($command2))) { $bundle->commands[2] = $command1; list($bundle->outs[2], $bundle->errs[2], $bundle->exits[2]) = $result1; $bundle->commands[3] = $command2; list($bundle->outs[3], $bundle->errs[3], $bundle->exits[3]) = $result2; $pass_string = " in pass '{$pass}'"; break; } } } $this->async_failure("Final output doesnt match expected{$pass_string}", $bundle); } }
function reduce_run_function($command, $stdin) { $result = complete_exec($command, $stdin, 3); if ($result[0] == "Timeout") { return array("", "", 0); } return $result; }
function run_test($subject) { global $phc, $plugin_dir; //print "testing script $subject\n"; $command = "{$phc} --run {$plugin_dir}/tests/line_numbers.la {$subject}"; list($out, $err, $exit) = complete_exec($command); if (strlen($out) == 0) { $this->mark_skipped(); } else { // we'll need to read the file $contents = file($subject); $ok = true; $test_output = ""; // TODO convert both the token and the line into an equivalent format // (note that toekns are pre-escaped, and that you need to look at // things like \100 and \x40 // The output is in the form "token:line_number--!!--!!--". Newlines, // if they are there, are part of the token. This is to avoid // confusion over newlines in regex. $lines = explode("--!!--!!--", rtrim($out)); foreach ($lines as $line) { if ($line == "") { continue; } # skip blank lines $match = preg_match("/^(.*):(\\d+)\$/ms", $line, $matches); $token = $matches[1]; $line_number = $matches[2]; //print "trying to match '$line'\n"; //print "matched $token on $line_number\n"; // our plugin should only print out things that can be non-zero if ($line_number == 0 or !$match or !isset($token) or !isset($line_number)) { $error = "Got line 0 for '{$token}'\n"; $test_output .= $error; $ok = false; continue; } // get the line from the file if (count($contents) <= $line_number - 1) { $file_size = count($contents); $error = "Expected (line {$line_number}): '{$token}'\nOnly {$file_size} lines\n"; $test_output .= $error; $ok = false; } else { $actual_line = $contents[$line_number - 1]; # arrays index from 0, but phc uses 1 if (@strpos($actual_line, $token) !== False) { // print "Found $token in $actual_line\n"; } else { $error = "Expected (line {$line_number}): '{$token}'\nActual line:'{$actual_line}'\n"; // print $error; $test_output .= $error; $ok = false; } } } if ($ok) { $this->mark_success($subject); } else { $this->mark_failure($subject, $command, 0, $test_output); } } }