function handle_result($resultid) { $r = BoincResult::lookup_id($resultid); $w = BoincWorkunit::lookup_id($r->workunitid); $rs = BoincResult::enum("workunitid={$r->workunitid} and validate_state=1"); $app_version_ids = array(); foreach ($rs as $r) { show_result($r, $w); $app_version_ids[] = $r->app_version_id; } $app_version_ids = array_unique($app_version_ids); foreach ($app_version_ids as $avid) { show_av($avid); } }
function run_test($php, $file, $env) { global $log_format, $info_params, $ini_overwrites, $cwd, $PHP_FAILED_TESTS; global $pass_options, $DETAILED, $IN_REDIRECT, $test_cnt, $test_idx; global $leak_check, $temp_source, $temp_target, $cfg, $environment; global $no_clean; global $valgrind_version; $temp_filenames = null; $org_file = $file; if (isset($env['TEST_PHP_CGI_EXECUTABLE'])) { $php_cgi = $env['TEST_PHP_CGI_EXECUTABLE']; } if (is_array($file)) { $file = $file[0]; } if ($DETAILED) { echo "\n=================\nTEST {$file}\n"; } // Load the sections of the test file. $section_text = array('TEST' => ''); $fp = fopen($file, "rt") or error("Cannot open test file: {$file}"); $borked = false; $bork_info = ''; if (!feof($fp)) { $line = fgets($fp); if ($line === false) { $bork_info = "cannot read test"; $borked = true; } } else { $bork_info = "empty test [{$file}]"; $borked = true; } if (!$borked && strncmp('--TEST--', $line, 8)) { $bork_info = "tests must start with --TEST-- [{$file}]"; $borked = true; } $section = 'TEST'; $secfile = false; $secdone = false; while (!feof($fp)) { $line = fgets($fp); // Match the beginning of a section. if (preg_match('/^--([_A-Z]+)--/', $line, $r)) { $section = $r[1]; if (isset($section_text[$section])) { $bork_info = "duplicated {$section} section"; $borked = true; } $section_text[$section] = ''; $secfile = $section == 'FILE' || $section == 'FILEEOF' || $section == 'FILE_EXTERNAL'; $secdone = false; continue; } // Add to the section text. if (!$secdone) { $section_text[$section] .= $line; } // End of actual test? if ($secfile && preg_match('/^===DONE===\\s*$/', $line)) { $secdone = true; } } // the redirect section allows a set of tests to be reused outside of // a given test dir if (!$borked) { if (@count($section_text['REDIRECTTEST']) == 1) { if ($IN_REDIRECT) { $borked = true; $bork_info = "Can't redirect a test from within a redirected test"; } else { $borked = false; } } else { if (@count($section_text['FILE']) + @count($section_text['FILEEOF']) + @count($section_text['FILE_EXTERNAL']) != 1) { $bork_info = "missing section --FILE--"; $borked = true; } if (@count($section_text['FILEEOF']) == 1) { $section_text['FILE'] = preg_replace("/[\r\n]+\$/", '', $section_text['FILEEOF']); unset($section_text['FILEEOF']); } if (@count($section_text['FILE_EXTERNAL']) == 1) { // don't allow tests to retrieve files from anywhere but this subdirectory $section_text['FILE_EXTERNAL'] = dirname($file) . '/' . trim(str_replace('..', '', $section_text['FILE_EXTERNAL'])); if (file_exists($section_text['FILE_EXTERNAL'])) { $section_text['FILE'] = file_get_contents($section_text['FILE_EXTERNAL']); unset($section_text['FILE_EXTERNAL']); } else { $bork_info = "could not load --FILE_EXTERNAL-- " . dirname($file) . '/' . trim($section_text['FILE_EXTERNAL']); $borked = true; } } if (@count($section_text['EXPECT']) + @count($section_text['EXPECTF']) + @count($section_text['EXPECTREGEX']) != 1) { $bork_info = "missing section --EXPECT--, --EXPECTF-- or --EXPECTREGEX--"; $borked = true; } } } fclose($fp); $shortname = str_replace($cwd . '/', '', $file); $tested_file = $shortname; if ($borked) { show_result("BORK", $bork_info, $tested_file); $PHP_FAILED_TESTS['BORKED'][] = array('name' => $file, 'test_name' => '', 'output' => '', 'diff' => '', 'info' => "{$bork_info} [{$file}]"); return 'BORKED'; } $tested = trim($section_text['TEST']); /* For GET/POST tests, check if cgi sapi is available and if it is, use it. */ if (!empty($section_text['GET']) || !empty($section_text['POST']) || !empty($section_text['POST_RAW']) || !empty($section_text['COOKIE']) || !empty($section_text['EXPECTHEADERS'])) { if (isset($php_cgi)) { $old_php = $php; $php = $php_cgi . ' -C '; } else { if (!strncasecmp(PHP_OS, "win", 3) && file_exists(dirname($php) . "/php-cgi.exe")) { $old_php = $php; $php = realpath(dirname($php) . "/php-cgi.exe") . ' -C '; } else { if (file_exists(dirname($php) . "/../../sapi/cgi/php-cgi")) { $old_php = $php; $php = realpath(dirname($php) . "/../../sapi/cgi/php-cgi") . ' -C '; } else { if (file_exists("./sapi/cgi/php-cgi")) { $old_php = $php; $php = realpath("./sapi/cgi/php-cgi") . ' -C '; } else { show_result('SKIP', $tested, $tested_file, "reason: CGI not available"); return 'SKIPPED'; } } } } } show_test($test_idx, $shortname); if (is_array($IN_REDIRECT)) { $temp_dir = $test_dir = $IN_REDIRECT['dir']; } else { $temp_dir = $test_dir = realpath(dirname($file)); } if ($temp_source && $temp_target) { $temp_dir = str_replace($temp_source, $temp_target, $temp_dir); } $main_file_name = basename($file, 'phpt'); $diff_filename = $temp_dir . DIRECTORY_SEPARATOR . $main_file_name . 'diff'; $log_filename = $temp_dir . DIRECTORY_SEPARATOR . $main_file_name . 'log'; $exp_filename = $temp_dir . DIRECTORY_SEPARATOR . $main_file_name . 'exp'; $output_filename = $temp_dir . DIRECTORY_SEPARATOR . $main_file_name . 'out'; $memcheck_filename = $temp_dir . DIRECTORY_SEPARATOR . $main_file_name . 'mem'; $temp_file = $temp_dir . DIRECTORY_SEPARATOR . $main_file_name . 'php'; $test_file = $test_dir . DIRECTORY_SEPARATOR . $main_file_name . 'php'; $temp_skipif = $temp_dir . DIRECTORY_SEPARATOR . $main_file_name . 'skip.php'; $test_skipif = $test_dir . DIRECTORY_SEPARATOR . $main_file_name . 'skip.php'; $temp_clean = $temp_dir . DIRECTORY_SEPARATOR . $main_file_name . 'clean.php'; $test_clean = $test_dir . DIRECTORY_SEPARATOR . $main_file_name . 'clean.php'; $tmp_post = $temp_dir . DIRECTORY_SEPARATOR . uniqid('/phpt.'); $tmp_relative_file = str_replace(realpath(dirname(__FILE__)) . DIRECTORY_SEPARATOR, '', $test_file) . 't'; if ($temp_source && $temp_target) { $temp_skipif .= 's'; $temp_file .= 's'; $temp_clean .= 's'; $copy_file = $temp_dir . DIRECTORY_SEPARATOR . basename(is_array($file) ? $file[1] : $file) . '.phps'; if (!is_dir(dirname($copy_file))) { mkdir(dirname($copy_file), 0777, true) or error("Cannot create output directory - " . dirname($copy_file)); } if (isset($section_text['FILE'])) { save_text($copy_file, $section_text['FILE']); } $temp_filenames = array('file' => $copy_file, 'diff' => $diff_filename, 'log' => $log_filename, 'exp' => $exp_filename, 'out' => $output_filename, 'mem' => $memcheck_filename, 'php' => $temp_file, 'skip' => $temp_skipif, 'clean' => $temp_clean); } if (is_array($IN_REDIRECT)) { $tested = $IN_REDIRECT['prefix'] . ' ' . trim($section_text['TEST']); $tested_file = $tmp_relative_file; $section_text['FILE'] = "# original source file: {$shortname}\n" . $section_text['FILE']; } // unlink old test results @unlink($diff_filename); @unlink($log_filename); @unlink($exp_filename); @unlink($output_filename); @unlink($memcheck_filename); @unlink($temp_file); @unlink($test_file); @unlink($temp_skipif); @unlink($test_skipif); @unlink($tmp_post); @unlink($temp_clean); @unlink($test_clean); // Reset environment from any previous test. $env['REDIRECT_STATUS'] = ''; $env['QUERY_STRING'] = ''; $env['PATH_TRANSLATED'] = ''; $env['SCRIPT_FILENAME'] = ''; $env['REQUEST_METHOD'] = ''; $env['CONTENT_TYPE'] = ''; $env['CONTENT_LENGTH'] = ''; if (!empty($section_text['ENV'])) { foreach (explode("\n", trim($section_text['ENV'])) as $e) { $e = explode('=', trim($e), 2); if (!empty($e[0]) && isset($e[1])) { $env[$e[0]] = $e[1]; } } } // Default ini settings $ini_settings = array(); // additional ini overwrites //$ini_overwrites[] = 'setting=value'; settings2array($ini_overwrites, $ini_settings); // Any special ini settings // these may overwrite the test defaults... if (array_key_exists('INI', $section_text)) { if (strpos($section_text['INI'], '{PWD}') !== false) { $section_text['INI'] = str_replace('{PWD}', dirname($file), $section_text['INI']); } settings2array(preg_split("/[\n\r]+/", $section_text['INI']), $ini_settings); } settings2params($ini_settings); // Check if test should be skipped. $info = ''; $warn = false; if (array_key_exists('SKIPIF', $section_text)) { if (trim($section_text['SKIPIF'])) { show_file_block('skip', $section_text['SKIPIF']); save_text($test_skipif, $section_text['SKIPIF'], $temp_skipif); $extra = substr(PHP_OS, 0, 3) !== "WIN" ? "unset REQUEST_METHOD; unset QUERY_STRING; unset PATH_TRANSLATED; unset SCRIPT_FILENAME; unset REQUEST_METHOD;" : ""; if ($leak_check) { $env['USE_ZEND_ALLOC'] = '0'; } else { $env['USE_ZEND_ALLOC'] = '1'; } $output = system_with_timeout("{$extra} {$php} {$pass_options} -q {$ini_settings} {$test_skipif}", $env); if (!$cfg['keep']['skip']) { @unlink($test_skipif); } if (!strncasecmp('skip', ltrim($output), 4)) { if (preg_match('/^\\s*skip\\s*(.+)\\s*/i', $output, $m)) { show_result('SKIP', $tested, $tested_file, "reason: {$m['1']}", $temp_filenames); } else { show_result('SKIP', $tested, $tested_file, '', $temp_filenames); } if (isset($old_php)) { $php = $old_php; } if (!$cfg['keep']['skip']) { @unlink($test_skipif); } return 'SKIPPED'; } if (!strncasecmp('info', ltrim($output), 4)) { if (preg_match('/^\\s*info\\s*(.+)\\s*/i', $output, $m)) { $info = " (info: {$m['1']})"; } } if (!strncasecmp('warn', ltrim($output), 4)) { if (preg_match('/^\\s*warn\\s*(.+)\\s*/i', $output, $m)) { $warn = true; /* only if there is a reason */ $info = " (warn: {$m['1']})"; } } } } if (@count($section_text['REDIRECTTEST']) == 1) { $test_files = array(); $IN_REDIRECT = eval($section_text['REDIRECTTEST']); $IN_REDIRECT['via'] = "via [{$shortname}]\n\t"; $IN_REDIRECT['dir'] = realpath(dirname($file)); $IN_REDIRECT['prefix'] = trim($section_text['TEST']); if (count($IN_REDIRECT['TESTS']) == 1) { if (is_array($org_file)) { $test_files[] = $org_file[1]; } else { $GLOBALS['test_files'] = $test_files; find_files($IN_REDIRECT['TESTS']); foreach ($GLOBALS['test_files'] as $f) { $test_files[] = array($f, $file); } } $test_cnt += @count($test_files) - 1; $test_idx--; show_redirect_start($IN_REDIRECT['TESTS'], $tested, $tested_file); // set up environment $redirenv = array_merge($environment, $IN_REDIRECT['ENV']); $redirenv['REDIR_TEST_DIR'] = realpath($IN_REDIRECT['TESTS']) . DIRECTORY_SEPARATOR; usort($test_files, "test_sort"); run_all_tests($test_files, $redirenv, $tested); show_redirect_ends($IN_REDIRECT['TESTS'], $tested, $tested_file); // a redirected test never fails $IN_REDIRECT = false; return 'REDIR'; } else { $bork_info = "Redirect info must contain exactly one TEST string to be used as redirect directory."; show_result("BORK", $bork_info, '', $temp_filenames); $PHP_FAILED_TESTS['BORKED'][] = array('name' => $file, 'test_name' => '', 'output' => '', 'diff' => '', 'info' => "{$bork_info} [{$file}]"); } } if (is_array($org_file) || @count($section_text['REDIRECTTEST']) == 1) { if (is_array($org_file)) { $file = $org_file[0]; } $bork_info = "Redirected test did not contain redirection info"; show_result("BORK", $bork_info, '', $temp_filenames); $PHP_FAILED_TESTS['BORKED'][] = array('name' => $file, 'test_name' => '', 'output' => '', 'diff' => '', 'info' => "{$bork_info} [{$file}]"); return 'BORKED'; } // We've satisfied the preconditions - run the test! show_file_block('php', $section_text['FILE'], 'TEST'); save_text($test_file, $section_text['FILE'], $temp_file); if (array_key_exists('GET', $section_text)) { $query_string = trim($section_text['GET']); } else { $query_string = ''; } $env['REDIRECT_STATUS'] = '1'; $env['QUERY_STRING'] = $query_string; $env['PATH_TRANSLATED'] = $test_file; $env['SCRIPT_FILENAME'] = $test_file; if (array_key_exists('COOKIE', $section_text)) { $env['HTTP_COOKIE'] = trim($section_text['COOKIE']); } else { $env['HTTP_COOKIE'] = ''; } $args = isset($section_text['ARGS']) ? ' -- ' . $section_text['ARGS'] : ''; if (array_key_exists('POST_RAW', $section_text) && !empty($section_text['POST_RAW'])) { $post = trim($section_text['POST_RAW']); $raw_lines = explode("\n", $post); $request = ''; $started = false; foreach ($raw_lines as $line) { if (empty($env['CONTENT_TYPE']) && preg_match('/^Content-Type:(.*)/i', $line, $res)) { $env['CONTENT_TYPE'] = trim(str_replace("\r", '', $res[1])); continue; } if ($started) { $request .= "\n"; } $started = true; $request .= $line; } $env['CONTENT_LENGTH'] = strlen($request); $env['REQUEST_METHOD'] = 'POST'; if (empty($request)) { return 'BORKED'; } save_text($tmp_post, $request); $cmd = "{$php} {$pass_options} {$ini_settings} -f \"{$test_file}\" 2>&1 < {$tmp_post}"; } else { if (array_key_exists('POST', $section_text) && !empty($section_text['POST'])) { $post = trim($section_text['POST']); if (array_key_exists('GZIP_POST', $section_text) && function_exists('gzencode')) { $post = gzencode($post, 9, FORCE_GZIP); $env['HTTP_CONTENT_ENCODING'] = 'gzip'; } else { if (array_key_exists('DEFLATE_POST', $section_text) && function_exists('gzcompress')) { $post = gzcompress($post, 9); $env['HTTP_CONTENT_ENCODING'] = 'deflate'; } } save_text($tmp_post, $post); $content_length = strlen($post); $env['REQUEST_METHOD'] = 'POST'; $env['CONTENT_TYPE'] = 'application/x-www-form-urlencoded'; $env['CONTENT_LENGTH'] = $content_length; $cmd = "{$php} {$pass_options} {$ini_settings} -f \"{$test_file}\" 2>&1 < {$tmp_post}"; } else { $env['REQUEST_METHOD'] = 'GET'; $env['CONTENT_TYPE'] = ''; $env['CONTENT_LENGTH'] = ''; $cmd = "{$php} {$pass_options} {$ini_settings} -f \"{$test_file}\" {$args} 2>&1"; } } if ($leak_check) { $env['USE_ZEND_ALLOC'] = '0'; if ($valgrind_version >= 330) { /* valgrind 3.3.0+ doesn't have --log-file-exactly option */ $cmd = "valgrind -q --tool=memcheck --trace-children=yes --log-file={$memcheck_filename} {$cmd}"; } else { $cmd = "valgrind -q --tool=memcheck --trace-children=yes --log-file-exactly={$memcheck_filename} {$cmd}"; } } else { $env['USE_ZEND_ALLOC'] = '1'; } if ($DETAILED) { echo "\nCONTENT_LENGTH = " . $env['CONTENT_LENGTH'] . "\nCONTENT_TYPE = " . $env['CONTENT_TYPE'] . "\nPATH_TRANSLATED = " . $env['PATH_TRANSLATED'] . "\nQUERY_STRING = " . $env['QUERY_STRING'] . "\nREDIRECT_STATUS = " . $env['REDIRECT_STATUS'] . "\nREQUEST_METHOD = " . $env['REQUEST_METHOD'] . "\nSCRIPT_FILENAME = " . $env['SCRIPT_FILENAME'] . "\nHTTP_COOKIE = " . $env['HTTP_COOKIE'] . "\nCOMMAND {$cmd}\n"; } $out = system_with_timeout($cmd, $env, isset($section_text['STDIN']) ? $section_text['STDIN'] : null); if (array_key_exists('CLEAN', $section_text) && (!$no_clean || $cfg['keep']['clean'])) { if (trim($section_text['CLEAN'])) { show_file_block('clean', $section_text['CLEAN']); save_text($test_clean, trim($section_text['CLEAN']), $temp_clean); if (!$no_clean) { $clean_params = array(); settings2array($ini_overwrites, $clean_params); settings2params($clean_params); $extra = substr(PHP_OS, 0, 3) !== "WIN" ? "unset REQUEST_METHOD; unset QUERY_STRING; unset PATH_TRANSLATED; unset SCRIPT_FILENAME; unset REQUEST_METHOD;" : ""; system_with_timeout("{$extra} {$php} {$pass_options} -q {$clean_params} {$test_clean}", $env); } if (!$cfg['keep']['clean']) { @unlink($test_clean); } } } @unlink($tmp_post); $leaked = false; $passed = false; if ($leak_check) { // leak check $leaked = filesize($memcheck_filename) > 0; if (!$leaked) { @unlink($memcheck_filename); } } // Does the output match what is expected? $output = preg_replace("/\r\n/", "\n", trim($out)); /* when using CGI, strip the headers from the output */ $headers = ""; if (isset($old_php) && preg_match("/^(.*?)\r?\n\r?\n(.*)/s", $out, $match)) { $output = trim($match[2]); $rh = preg_split("/[\n\r]+/", $match[1]); $headers = array(); foreach ($rh as $line) { if (strpos($line, ':') !== false) { $line = explode(':', $line, 2); $headers[trim($line[0])] = trim($line[1]); } } } $failed_headers = false; if (isset($section_text['EXPECTHEADERS'])) { $want = array(); $wanted_headers = array(); $lines = preg_split("/[\n\r]+/", $section_text['EXPECTHEADERS']); foreach ($lines as $line) { if (strpos($line, ':') !== false) { $line = explode(':', $line, 2); $want[trim($line[0])] = trim($line[1]); $wanted_headers[] = trim($line[0]) . ': ' . trim($line[1]); } } $org_headers = $headers; $headers = array(); $output_headers = array(); foreach ($want as $k => $v) { if (isset($org_headers[$k])) { $headers = $org_headers[$k]; $output_headers[] = $k . ': ' . $org_headers[$k]; } if (!isset($org_headers[$k]) || $org_headers[$k] != $v) { $failed_headers = true; } } ksort($wanted_headers); $wanted_headers = join("\n", $wanted_headers); ksort($output_headers); $output_headers = join("\n", $output_headers); } show_file_block('out', $output); if (isset($section_text['EXPECTF']) || isset($section_text['EXPECTREGEX'])) { if (isset($section_text['EXPECTF'])) { $wanted = trim($section_text['EXPECTF']); } else { $wanted = trim($section_text['EXPECTREGEX']); } show_file_block('exp', $wanted); $wanted_re = preg_replace('/\\r\\n/', "\n", $wanted); if (isset($section_text['EXPECTF'])) { $wanted_re = preg_quote($wanted_re, '/'); $wanted_re = str_replace(array('%unicode_string_optional%'), version_compare(PHP_VERSION, '6.0.0-dev') == -1 ? 'string' : 'Unicode string', $wanted_re); $wanted_re = str_replace(array('%unicode\\|string%', '%string\\|unicode%'), version_compare(PHP_VERSION, '6.0.0-dev') == -1 ? 'string' : 'unicode', $wanted_re); $wanted_re = str_replace(array('%u\\|b%', '%b\\|u%'), version_compare(PHP_VERSION, '6.0.0-dev') == -1 ? '' : 'u', $wanted_re); // Stick to basics $wanted_re = str_replace('%e', '\\' . DIRECTORY_SEPARATOR, $wanted_re); $wanted_re = str_replace('%s', '[^\\r\\n]+', $wanted_re); $wanted_re = str_replace('%a', '.+', $wanted_re); $wanted_re = str_replace('%w', '\\s*', $wanted_re); $wanted_re = str_replace('%i', '[+-]?\\d+', $wanted_re); $wanted_re = str_replace('%d', '\\d+', $wanted_re); $wanted_re = str_replace('%x', '[0-9a-fA-F]+', $wanted_re); $wanted_re = str_replace('%f', '[+-]?\\.?\\d+\\.?\\d*(?:[Ee][+-]?\\d+)?', $wanted_re); $wanted_re = str_replace('%c', '.', $wanted_re); // %f allows two points "-.0.0" but that is the best *simple* expression } /* DEBUG YOUR REGEX HERE var_dump($wanted_re); print(str_repeat('=', 80) . "\n"); var_dump($output); */ if (preg_match((string) "/^{$wanted_re}\$/s", $output)) { $passed = true; if (!$cfg['keep']['php']) { @unlink($test_file); } if (isset($old_php)) { $php = $old_php; } if (!$leaked && !$failed_headers) { show_result("PASS", $tested, $tested_file, '', $temp_filenames); return 'PASSED'; } } } else { $wanted = trim($section_text['EXPECT']); $wanted = preg_replace('/\\r\\n/', "\n", $wanted); show_file_block('exp', $wanted); // compare and leave on success if (!strcmp($output, $wanted)) { $passed = true; if (!$cfg['keep']['php']) { @unlink($test_file); } if (isset($old_php)) { $php = $old_php; } if (!$leaked && !$failed_headers) { show_result("PASS", $tested, $tested_file, '', $temp_filenames); return 'PASSED'; } } $wanted_re = null; } // Test failed so we need to report details. if ($failed_headers) { $passed = false; $wanted = $wanted_headers . "\n--HEADERS--\n" . $wanted; $output = $output_headers . "\n--HEADERS--\n" . $output; if (isset($wanted_re)) { $wanted_re = preg_quote($wanted_headers . "\n--HEADERS--\n", '/') . $wanted_re; } } if ($leaked) { $restype[] = 'LEAK'; } if ($warn) { $restype[] = 'WARN'; } if (!$passed) { if (isset($section_text['XFAIL'])) { $restype[] = 'XFAIL'; } else { $restype[] = 'FAIL'; } } if (!$passed) { // write .exp if (strpos($log_format, 'E') !== false && file_put_contents($exp_filename, (string) $wanted, FILE_BINARY) === false) { error("Cannot create expected test output - {$exp_filename}"); } // write .out if (strpos($log_format, 'O') !== false && file_put_contents($output_filename, (string) $output, FILE_BINARY) === false) { error("Cannot create test output - {$output_filename}"); } // write .diff $diff = generate_diff($wanted, $wanted_re, $output); show_file_block('diff', $diff); if (strpos($log_format, 'D') !== false && file_put_contents($diff_filename, (string) $diff, FILE_BINARY) === false) { error("Cannot create test diff - {$diff_filename}"); } // write .log if (strpos($log_format, 'L') !== false && file_put_contents($log_filename, "\n---- EXPECTED OUTPUT\n{$wanted}\n---- ACTUAL OUTPUT\n{$output}\n---- FAILED\n", FILE_BINARY) === false) { error("Cannot create test log - {$log_filename}"); error_report($file, $log_filename, $tested); } } show_result(implode('&', $restype), $tested, $tested_file, $info, $temp_filenames); foreach ($restype as $type) { $PHP_FAILED_TESTS[$type . 'ED'][] = array('name' => $file, 'test_name' => (is_array($IN_REDIRECT) ? $IN_REDIRECT['via'] : '') . $tested . " [{$tested_file}]", 'output' => $output_filename, 'diff' => $diff_filename, 'info' => $info); } if (isset($old_php)) { $php = $old_php; } return $restype[0] . 'ED'; }
show_platform($res); break; case "app": show_app($res); break; case "app_version": show_app_version($res); break; case "host": show_host($res); break; case "workunit": show_workunit($res); break; case "result": show_result($res); break; case "team": show_team($res); break; case "user": show_user($res); break; } } } if ($detail == "low" || $table == "profile") { end_table(); } mysql_free_result($result); } else {
function run_test($php, $file, $env) { global $log_format, $ini_overwrites, $cwd, $PHP_FAILED_TESTS; global $pass_options, $DETAILED, $IN_REDIRECT, $test_cnt, $test_idx; global $leak_check, $temp_source, $temp_target, $cfg, $environment; global $no_clean; global $valgrind_version; global $SHOW_ONLY_GROUPS; global $no_file_cache; $temp_filenames = null; $org_file = $file; if (isset($env['TEST_PHP_CGI_EXECUTABLE'])) { $php_cgi = $env['TEST_PHP_CGI_EXECUTABLE']; } if (isset($env['TEST_PHPDBG_EXECUTABLE'])) { $phpdbg = $env['TEST_PHPDBG_EXECUTABLE']; } if (is_array($file)) { $file = $file[0]; } if ($DETAILED) { echo "\n=================\nTEST {$file}\n"; } // Load the sections of the test file. $section_text = array('TEST' => ''); $fp = fopen($file, "rb") or error("Cannot open test file: {$file}"); $borked = false; $bork_info = ''; if (!feof($fp)) { $line = fgets($fp); if ($line === false) { $bork_info = "cannot read test"; $borked = true; } } else { $bork_info = "empty test [{$file}]"; $borked = true; } if (!$borked && strncmp('--TEST--', $line, 8)) { $bork_info = "tests must start with --TEST-- [{$file}]"; $borked = true; } $section = 'TEST'; $secfile = false; $secdone = false; while (!feof($fp)) { $line = fgets($fp); if ($line === false) { break; } // Match the beginning of a section. if (preg_match('/^--([_A-Z]+)--/', $line, $r)) { $section = $r[1]; settype($section, 'string'); if (isset($section_text[$section])) { $bork_info = "duplicated {$section} section"; $borked = true; } $section_text[$section] = ''; $secfile = $section == 'FILE' || $section == 'FILEEOF' || $section == 'FILE_EXTERNAL'; $secdone = false; continue; } // Add to the section text. if (!$secdone) { $section_text[$section] .= $line; } // End of actual test? if ($secfile && preg_match('/^===DONE===\\s*$/', $line)) { $secdone = true; } } // the redirect section allows a set of tests to be reused outside of // a given test dir if (!$borked) { if (@count($section_text['REDIRECTTEST']) == 1) { if ($IN_REDIRECT) { $borked = true; $bork_info = "Can't redirect a test from within a redirected test"; } else { $borked = false; } } else { if (!isset($section_text['PHPDBG']) && @count($section_text['FILE']) + @count($section_text['FILEEOF']) + @count($section_text['FILE_EXTERNAL']) != 1) { $bork_info = "missing section --FILE--"; $borked = true; } if (@count($section_text['FILEEOF']) == 1) { $section_text['FILE'] = preg_replace("/[\r\n]+\$/", '', $section_text['FILEEOF']); unset($section_text['FILEEOF']); } foreach (array('FILE', 'EXPECT', 'EXPECTF', 'EXPECTREGEX') as $prefix) { $key = $prefix . '_EXTERNAL'; if (@count($section_text[$key]) == 1) { // don't allow tests to retrieve files from anywhere but this subdirectory $section_text[$key] = dirname($file) . '/' . trim(str_replace('..', '', $section_text[$key])); if (file_exists($section_text[$key])) { $section_text[$prefix] = file_get_contents($section_text[$key], FILE_BINARY); unset($section_text[$key]); } else { $bork_info = "could not load --" . $key . "-- " . dirname($file) . '/' . trim($section_text[$key]); $borked = true; } } } if (@count($section_text['EXPECT']) + @count($section_text['EXPECTF']) + @count($section_text['EXPECTREGEX']) != 1) { $bork_info = "missing section --EXPECT--, --EXPECTF-- or --EXPECTREGEX--"; $borked = true; } } } fclose($fp); $shortname = str_replace($cwd . '/', '', $file); $tested_file = $shortname; if ($borked) { show_result("BORK", $bork_info, $tested_file); $PHP_FAILED_TESTS['BORKED'][] = array('name' => $file, 'test_name' => '', 'output' => '', 'diff' => '', 'info' => "{$bork_info} [{$file}]"); junit_mark_test_as('BORK', $shortname, $tested_file, 0, $bork_info); return 'BORKED'; } if (isset($section_text['CAPTURE_STDIO'])) { $captureStdIn = stripos($section_text['CAPTURE_STDIO'], 'STDIN') !== false; $captureStdOut = stripos($section_text['CAPTURE_STDIO'], 'STDOUT') !== false; $captureStdErr = stripos($section_text['CAPTURE_STDIO'], 'STDERR') !== false; } else { $captureStdIn = true; $captureStdOut = true; $captureStdErr = true; } if ($captureStdOut && $captureStdErr) { $cmdRedirect = ' 2>&1'; } else { $cmdRedirect = ''; } $tested = trim($section_text['TEST']); /* For GET/POST/PUT tests, check if cgi sapi is available and if it is, use it. */ if (!empty($section_text['GET']) || !empty($section_text['POST']) || !empty($section_text['GZIP_POST']) || !empty($section_text['DEFLATE_POST']) || !empty($section_text['POST_RAW']) || !empty($section_text['PUT']) || !empty($section_text['COOKIE']) || !empty($section_text['EXPECTHEADERS'])) { if (isset($php_cgi)) { $old_php = $php; $php = $php_cgi . ' -C '; } else { if (!strncasecmp(PHP_OS, "win", 3) && file_exists(dirname($php) . "/php-cgi.exe")) { $old_php = $php; $php = realpath(dirname($php) . "/php-cgi.exe") . ' -C '; } else { if (file_exists(dirname($php) . "/../../sapi/cgi/php-cgi")) { $old_php = $php; $php = realpath(dirname($php) . "/../../sapi/cgi/php-cgi") . ' -C '; } else { if (file_exists("./sapi/cgi/php-cgi")) { $old_php = $php; $php = realpath("./sapi/cgi/php-cgi") . ' -C '; } else { if (file_exists(dirname($php) . "/php-cgi")) { $old_php = $php; $php = realpath(dirname($php) . "/php-cgi") . ' -C '; } else { show_result('SKIP', $tested, $tested_file, "reason: CGI not available"); junit_init_suite(junit_get_suitename_for($shortname)); junit_mark_test_as('SKIP', $shortname, $tested, 0, 'CGI not available'); return 'SKIPPED'; } } } } } $uses_cgi = true; } /* For phpdbg tests, check if phpdbg sapi is available and if it is, use it. */ if (array_key_exists('PHPDBG', $section_text)) { if (!isset($section_text['STDIN'])) { $section_text['STDIN'] = $section_text['PHPDBG'] . "\n"; } if (isset($phpdbg)) { $old_php = $php; $php = $phpdbg . ' -qIb'; } else { show_result('SKIP', $tested, $tested_file, "reason: phpdbg not available"); junit_init_suite(junit_get_suitename_for($shortname)); junit_mark_test_as('SKIP', $shortname, $tested, 0, 'phpdbg not available'); return 'SKIPPED'; } } if (!$SHOW_ONLY_GROUPS) { show_test($test_idx, $shortname); } if (is_array($IN_REDIRECT)) { $temp_dir = $test_dir = $IN_REDIRECT['dir']; } else { $temp_dir = $test_dir = realpath(dirname($file)); } if ($temp_source && $temp_target) { $temp_dir = str_replace($temp_source, $temp_target, $temp_dir); } $main_file_name = basename($file, 'phpt'); $diff_filename = $temp_dir . DIRECTORY_SEPARATOR . $main_file_name . 'diff'; $log_filename = $temp_dir . DIRECTORY_SEPARATOR . $main_file_name . 'log'; $exp_filename = $temp_dir . DIRECTORY_SEPARATOR . $main_file_name . 'exp'; $output_filename = $temp_dir . DIRECTORY_SEPARATOR . $main_file_name . 'out'; $memcheck_filename = $temp_dir . DIRECTORY_SEPARATOR . $main_file_name . 'mem'; $sh_filename = $temp_dir . DIRECTORY_SEPARATOR . $main_file_name . 'sh'; $temp_file = $temp_dir . DIRECTORY_SEPARATOR . $main_file_name . 'php'; $test_file = $test_dir . DIRECTORY_SEPARATOR . $main_file_name . 'php'; $temp_skipif = $temp_dir . DIRECTORY_SEPARATOR . $main_file_name . 'skip.php'; $test_skipif = $test_dir . DIRECTORY_SEPARATOR . $main_file_name . 'skip.php'; $temp_clean = $temp_dir . DIRECTORY_SEPARATOR . $main_file_name . 'clean.php'; $test_clean = $test_dir . DIRECTORY_SEPARATOR . $main_file_name . 'clean.php'; $tmp_post = $temp_dir . DIRECTORY_SEPARATOR . uniqid('/phpt.'); $tmp_relative_file = str_replace(__DIR__ . DIRECTORY_SEPARATOR, '', $test_file) . 't'; if ($temp_source && $temp_target) { $temp_skipif .= 's'; $temp_file .= 's'; $temp_clean .= 's'; $copy_file = $temp_dir . DIRECTORY_SEPARATOR . basename(is_array($file) ? $file[1] : $file) . '.phps'; if (!is_dir(dirname($copy_file))) { mkdir(dirname($copy_file), 0777, true) or error("Cannot create output directory - " . dirname($copy_file)); } if (isset($section_text['FILE'])) { save_text($copy_file, $section_text['FILE']); } $temp_filenames = array('file' => $copy_file, 'diff' => $diff_filename, 'log' => $log_filename, 'exp' => $exp_filename, 'out' => $output_filename, 'mem' => $memcheck_filename, 'sh' => $sh_filename, 'php' => $temp_file, 'skip' => $temp_skipif, 'clean' => $temp_clean); } if (is_array($IN_REDIRECT)) { $tested = $IN_REDIRECT['prefix'] . ' ' . trim($section_text['TEST']); $tested_file = $tmp_relative_file; } // unlink old test results @unlink($diff_filename); @unlink($log_filename); @unlink($exp_filename); @unlink($output_filename); @unlink($memcheck_filename); @unlink($sh_filename); @unlink($temp_file); @unlink($test_file); @unlink($temp_skipif); @unlink($test_skipif); @unlink($tmp_post); @unlink($temp_clean); @unlink($test_clean); // Reset environment from any previous test. $env['REDIRECT_STATUS'] = ''; $env['QUERY_STRING'] = ''; $env['PATH_TRANSLATED'] = ''; $env['SCRIPT_FILENAME'] = ''; $env['REQUEST_METHOD'] = ''; $env['CONTENT_TYPE'] = ''; $env['CONTENT_LENGTH'] = ''; $env['TZ'] = ''; if (!empty($section_text['ENV'])) { foreach (explode("\n", trim($section_text['ENV'])) as $e) { $e = explode('=', trim($e), 2); if (!empty($e[0]) && isset($e[1])) { $env[$e[0]] = $e[1]; } } } // Default ini settings $ini_settings = array(); // Additional required extensions if (array_key_exists('EXTENSIONS', $section_text)) { $ext_dir = `{$php} -r 'echo ini_get("extension_dir");'`; $extensions = preg_split("/[\n\r]+/", trim($section_text['EXTENSIONS'])); $loaded = explode(",", `{$php} -n -r 'echo implode(",", get_loaded_extensions());'`); foreach ($extensions as $req_ext) { if (!in_array($req_ext, $loaded)) { if ($req_ext == 'opcache') { $ini_settings['zend_extension'][] = $ext_dir . DIRECTORY_SEPARATOR . $req_ext . '.' . PHP_SHLIB_SUFFIX; } else { $ini_settings['extension'][] = $ext_dir . DIRECTORY_SEPARATOR . $req_ext . '.' . PHP_SHLIB_SUFFIX; } } } } // additional ini overwrites //$ini_overwrites[] = 'setting=value'; settings2array($ini_overwrites, $ini_settings); // Any special ini settings // these may overwrite the test defaults... if (array_key_exists('INI', $section_text)) { if (strpos($section_text['INI'], '{PWD}') !== false) { $section_text['INI'] = str_replace('{PWD}', dirname($file), $section_text['INI']); } settings2array(preg_split("/[\n\r]+/", $section_text['INI']), $ini_settings); } settings2params($ini_settings); // Check if test should be skipped. $info = ''; $warn = false; if (array_key_exists('SKIPIF', $section_text)) { if (trim($section_text['SKIPIF'])) { show_file_block('skip', $section_text['SKIPIF']); save_text($test_skipif, $section_text['SKIPIF'], $temp_skipif); $extra = substr(PHP_OS, 0, 3) !== "WIN" ? "unset REQUEST_METHOD; unset QUERY_STRING; unset PATH_TRANSLATED; unset SCRIPT_FILENAME; unset REQUEST_METHOD;" : ""; if ($leak_check) { $env['USE_ZEND_ALLOC'] = '0'; $env['ZEND_DONT_UNLOAD_MODULES'] = 1; } else { $env['USE_ZEND_ALLOC'] = '1'; $env['ZEND_DONT_UNLOAD_MODULES'] = 0; } junit_start_timer($shortname); $output = system_with_timeout("{$extra} {$php} {$pass_options} -q {$ini_settings} {$no_file_cache} -d display_errors=0 \"{$test_skipif}\"", $env); junit_finish_timer($shortname); if (!$cfg['keep']['skip']) { @unlink($test_skipif); } if (!strncasecmp('skip', ltrim($output), 4)) { if (preg_match('/^\\s*skip\\s*(.+)\\s*/i', $output, $m)) { show_result('SKIP', $tested, $tested_file, "reason: {$m['1']}", $temp_filenames); } else { show_result('SKIP', $tested, $tested_file, '', $temp_filenames); } if (!$cfg['keep']['skip']) { @unlink($test_skipif); } $message = !empty($m[1]) ? $m[1] : ''; junit_mark_test_as('SKIP', $shortname, $tested, null, $message); return 'SKIPPED'; } if (!strncasecmp('info', ltrim($output), 4)) { if (preg_match('/^\\s*info\\s*(.+)\\s*/i', $output, $m)) { $info = " (info: {$m['1']})"; } } if (!strncasecmp('warn', ltrim($output), 4)) { if (preg_match('/^\\s*warn\\s*(.+)\\s*/i', $output, $m)) { $warn = true; /* only if there is a reason */ $info = " (warn: {$m['1']})"; } } } } if (!extension_loaded("zlib") && (array_key_exists("GZIP_POST", $section_text) || array_key_exists("DEFLATE_POST", $section_text))) { $message = "ext/zlib required"; show_result('SKIP', $tested, $tested_file, "reason: {$message}", $temp_filenames); junit_mark_test_as('SKIP', $shortname, $tested, null, $message); return 'SKIPPED'; } if (@count($section_text['REDIRECTTEST']) == 1) { $test_files = array(); $IN_REDIRECT = eval($section_text['REDIRECTTEST']); $IN_REDIRECT['via'] = "via [{$shortname}]\n\t"; $IN_REDIRECT['dir'] = realpath(dirname($file)); $IN_REDIRECT['prefix'] = trim($section_text['TEST']); if (!empty($IN_REDIRECT['TESTS'])) { if (is_array($org_file)) { $test_files[] = $org_file[1]; } else { $GLOBALS['test_files'] = $test_files; find_files($IN_REDIRECT['TESTS']); foreach ($GLOBALS['test_files'] as $f) { $test_files[] = array($f, $file); } } $test_cnt += @count($test_files) - 1; $test_idx--; show_redirect_start($IN_REDIRECT['TESTS'], $tested, $tested_file); // set up environment $redirenv = array_merge($environment, $IN_REDIRECT['ENV']); $redirenv['REDIR_TEST_DIR'] = realpath($IN_REDIRECT['TESTS']) . DIRECTORY_SEPARATOR; usort($test_files, "test_sort"); run_all_tests($test_files, $redirenv, $tested); show_redirect_ends($IN_REDIRECT['TESTS'], $tested, $tested_file); // a redirected test never fails $IN_REDIRECT = false; junit_mark_test_as('PASS', $shortname, $tested); return 'REDIR'; } else { $bork_info = "Redirect info must contain exactly one TEST string to be used as redirect directory."; show_result("BORK", $bork_info, '', $temp_filenames); $PHP_FAILED_TESTS['BORKED'][] = array('name' => $file, 'test_name' => '', 'output' => '', 'diff' => '', 'info' => "{$bork_info} [{$file}]"); } } if (is_array($org_file) || @count($section_text['REDIRECTTEST']) == 1) { if (is_array($org_file)) { $file = $org_file[0]; } $bork_info = "Redirected test did not contain redirection info"; show_result("BORK", $bork_info, '', $temp_filenames); $PHP_FAILED_TESTS['BORKED'][] = array('name' => $file, 'test_name' => '', 'output' => '', 'diff' => '', 'info' => "{$bork_info} [{$file}]"); junit_mark_test_as('BORK', $shortname, $tested, null, $bork_info); return 'BORKED'; } // We've satisfied the preconditions - run the test! if (isset($section_text['FILE'])) { show_file_block('php', $section_text['FILE'], 'TEST'); save_text($test_file, $section_text['FILE'], $temp_file); } else { $test_file = $temp_file = ""; } if (array_key_exists('GET', $section_text)) { $query_string = trim($section_text['GET']); } else { $query_string = ''; } $env['REDIRECT_STATUS'] = '1'; if (empty($env['QUERY_STRING'])) { $env['QUERY_STRING'] = $query_string; } if (empty($env['PATH_TRANSLATED'])) { $env['PATH_TRANSLATED'] = $test_file; } if (empty($env['SCRIPT_FILENAME'])) { $env['SCRIPT_FILENAME'] = $test_file; } if (array_key_exists('COOKIE', $section_text)) { $env['HTTP_COOKIE'] = trim($section_text['COOKIE']); } else { $env['HTTP_COOKIE'] = ''; } $args = isset($section_text['ARGS']) ? ' -- ' . $section_text['ARGS'] : ''; if (array_key_exists('POST_RAW', $section_text) && !empty($section_text['POST_RAW'])) { $post = trim($section_text['POST_RAW']); $raw_lines = explode("\n", $post); $request = ''; $started = false; foreach ($raw_lines as $line) { if (empty($env['CONTENT_TYPE']) && preg_match('/^Content-Type:(.*)/i', $line, $res)) { $env['CONTENT_TYPE'] = trim(str_replace("\r", '', $res[1])); continue; } if ($started) { $request .= "\n"; } $started = true; $request .= $line; } $env['CONTENT_LENGTH'] = strlen($request); $env['REQUEST_METHOD'] = 'POST'; if (empty($request)) { junit_mark_test_as('BORK', $shortname, $tested, null, 'empty $request'); return 'BORKED'; } save_text($tmp_post, $request); $cmd = "{$php} {$pass_options} {$ini_settings} -f \"{$test_file}\"{$cmdRedirect} < \"{$tmp_post}\""; } elseif (array_key_exists('PUT', $section_text) && !empty($section_text['PUT'])) { $post = trim($section_text['PUT']); $raw_lines = explode("\n", $post); $request = ''; $started = false; foreach ($raw_lines as $line) { if (empty($env['CONTENT_TYPE']) && preg_match('/^Content-Type:(.*)/i', $line, $res)) { $env['CONTENT_TYPE'] = trim(str_replace("\r", '', $res[1])); continue; } if ($started) { $request .= "\n"; } $started = true; $request .= $line; } $env['CONTENT_LENGTH'] = strlen($request); $env['REQUEST_METHOD'] = 'PUT'; if (empty($request)) { junit_mark_test_as('BORK', $shortname, $tested, null, 'empty $request'); return 'BORKED'; } save_text($tmp_post, $request); $cmd = "{$php} {$pass_options} {$ini_settings} -f \"{$test_file}\"{$cmdRedirect} < \"{$tmp_post}\""; } else { if (array_key_exists('POST', $section_text) && !empty($section_text['POST'])) { $post = trim($section_text['POST']); $content_length = strlen($post); save_text($tmp_post, $post); $env['REQUEST_METHOD'] = 'POST'; if (empty($env['CONTENT_TYPE'])) { $env['CONTENT_TYPE'] = 'application/x-www-form-urlencoded'; } if (empty($env['CONTENT_LENGTH'])) { $env['CONTENT_LENGTH'] = $content_length; } $cmd = "{$php} {$pass_options} {$ini_settings} -f \"{$test_file}\"{$cmdRedirect} < \"{$tmp_post}\""; } else { if (array_key_exists('GZIP_POST', $section_text) && !empty($section_text['GZIP_POST'])) { $post = trim($section_text['GZIP_POST']); $post = gzencode($post, 9, FORCE_GZIP); $env['HTTP_CONTENT_ENCODING'] = 'gzip'; save_text($tmp_post, $post); $content_length = strlen($post); $env['REQUEST_METHOD'] = 'POST'; $env['CONTENT_TYPE'] = 'application/x-www-form-urlencoded'; $env['CONTENT_LENGTH'] = $content_length; $cmd = "{$php} {$pass_options} {$ini_settings} -f \"{$test_file}\"{$cmdRedirect} < \"{$tmp_post}\""; } else { if (array_key_exists('DEFLATE_POST', $section_text) && !empty($section_text['DEFLATE_POST'])) { $post = trim($section_text['DEFLATE_POST']); $post = gzcompress($post, 9); $env['HTTP_CONTENT_ENCODING'] = 'deflate'; save_text($tmp_post, $post); $content_length = strlen($post); $env['REQUEST_METHOD'] = 'POST'; $env['CONTENT_TYPE'] = 'application/x-www-form-urlencoded'; $env['CONTENT_LENGTH'] = $content_length; $cmd = "{$php} {$pass_options} {$ini_settings} -f \"{$test_file}\"{$cmdRedirect} < \"{$tmp_post}\""; } else { $env['REQUEST_METHOD'] = 'GET'; $env['CONTENT_TYPE'] = ''; $env['CONTENT_LENGTH'] = ''; $cmd = "{$php} {$pass_options} {$ini_settings} -f \"{$test_file}\" {$args}{$cmdRedirect}"; } } } } if ($leak_check) { $env['USE_ZEND_ALLOC'] = '0'; $env['ZEND_DONT_UNLOAD_MODULES'] = 1; /* --vex-iropt-register-updates=allregs-at-mem-access is necessary for phpdbg watchpoint tests */ if (version_compare($valgrind_version, '3.8.0', '>=')) { /* valgrind 3.3.0+ doesn't have --log-file-exactly option */ $cmd = "valgrind -q --tool=memcheck --trace-children=yes --vex-iropt-register-updates=allregs-at-mem-access --log-file={$memcheck_filename} {$cmd}"; } elseif (version_compare($valgrind_version, '3.3.0', '>=')) { $cmd = "valgrind -q --tool=memcheck --trace-children=yes --vex-iropt-precise-memory-exns=yes --log-file={$memcheck_filename} {$cmd}"; } else { $cmd = "valgrind -q --tool=memcheck --trace-children=yes --vex-iropt-precise-memory-exns=yes --log-file-exactly={$memcheck_filename} {$cmd}"; } } else { $env['USE_ZEND_ALLOC'] = '1'; $env['ZEND_DONT_UNLOAD_MODULES'] = 0; } if ($DETAILED) { echo "\nCONTENT_LENGTH = " . $env['CONTENT_LENGTH'] . "\nCONTENT_TYPE = " . $env['CONTENT_TYPE'] . "\nPATH_TRANSLATED = " . $env['PATH_TRANSLATED'] . "\nQUERY_STRING = " . $env['QUERY_STRING'] . "\nREDIRECT_STATUS = " . $env['REDIRECT_STATUS'] . "\nREQUEST_METHOD = " . $env['REQUEST_METHOD'] . "\nSCRIPT_FILENAME = " . $env['SCRIPT_FILENAME'] . "\nHTTP_COOKIE = " . $env['HTTP_COOKIE'] . "\nCOMMAND {$cmd}\n"; } junit_start_timer($shortname); $out = system_with_timeout($cmd, $env, isset($section_text['STDIN']) ? $section_text['STDIN'] : null, $captureStdIn, $captureStdOut, $captureStdErr); junit_finish_timer($shortname); if (array_key_exists('CLEAN', $section_text) && (!$no_clean || $cfg['keep']['clean'])) { if (trim($section_text['CLEAN'])) { show_file_block('clean', $section_text['CLEAN']); save_text($test_clean, trim($section_text['CLEAN']), $temp_clean); if (!$no_clean) { $clean_params = array(); settings2array($ini_overwrites, $clean_params); settings2params($clean_params); $extra = substr(PHP_OS, 0, 3) !== "WIN" ? "unset REQUEST_METHOD; unset QUERY_STRING; unset PATH_TRANSLATED; unset SCRIPT_FILENAME; unset REQUEST_METHOD;" : ""; system_with_timeout("{$extra} {$php} {$pass_options} -q {$clean_params} {$no_file_cache} \"{$test_clean}\"", $env); } if (!$cfg['keep']['clean']) { @unlink($test_clean); } } } @unlink($tmp_post); $leaked = false; $passed = false; if ($leak_check) { // leak check $leaked = filesize($memcheck_filename) > 0; if (!$leaked) { @unlink($memcheck_filename); } } // Does the output match what is expected? $output = preg_replace("/\r\n/", "\n", trim($out)); /* when using CGI, strip the headers from the output */ $headers = array(); if (!empty($uses_cgi) && preg_match("/^(.*?)\r?\n\r?\n(.*)/s", $out, $match)) { $output = trim($match[2]); $rh = preg_split("/[\n\r]+/", $match[1]); foreach ($rh as $line) { if (strpos($line, ':') !== false) { $line = explode(':', $line, 2); $headers[trim($line[0])] = trim($line[1]); } } } $failed_headers = false; if (isset($section_text['EXPECTHEADERS'])) { $want = array(); $wanted_headers = array(); $lines = preg_split("/[\n\r]+/", $section_text['EXPECTHEADERS']); foreach ($lines as $line) { if (strpos($line, ':') !== false) { $line = explode(':', $line, 2); $want[trim($line[0])] = trim($line[1]); $wanted_headers[] = trim($line[0]) . ': ' . trim($line[1]); } } $output_headers = array(); foreach ($want as $k => $v) { if (isset($headers[$k])) { $output_headers[] = $k . ': ' . $headers[$k]; } if (!isset($headers[$k]) || $headers[$k] != $v) { $failed_headers = true; } } ksort($wanted_headers); $wanted_headers = implode("\n", $wanted_headers); ksort($output_headers); $output_headers = implode("\n", $output_headers); } show_file_block('out', $output); if (isset($section_text['EXPECTF']) || isset($section_text['EXPECTREGEX'])) { if (isset($section_text['EXPECTF'])) { $wanted = trim($section_text['EXPECTF']); } else { $wanted = trim($section_text['EXPECTREGEX']); } show_file_block('exp', $wanted); $wanted_re = preg_replace('/\\r\\n/', "\n", $wanted); if (isset($section_text['EXPECTF'])) { // do preg_quote, but miss out any %r delimited sections $temp = ""; $r = "%r"; $startOffset = 0; $length = strlen($wanted_re); while ($startOffset < $length) { $start = strpos($wanted_re, $r, $startOffset); if ($start !== false) { // we have found a start tag $end = strpos($wanted_re, $r, $start + 2); if ($end === false) { // unbalanced tag, ignore it. $end = $start = $length; } } else { // no more %r sections $start = $end = $length; } // quote a non re portion of the string $temp = $temp . preg_quote(substr($wanted_re, $startOffset, $start - $startOffset), '/'); // add the re unquoted. if ($end > $start) { $temp = $temp . '(' . substr($wanted_re, $start + 2, $end - $start - 2) . ')'; } $startOffset = $end + 2; } $wanted_re = $temp; $wanted_re = str_replace(array('%binary_string_optional%'), 'string', $wanted_re); $wanted_re = str_replace(array('%unicode_string_optional%'), 'string', $wanted_re); $wanted_re = str_replace(array('%unicode\\|string%', '%string\\|unicode%'), 'string', $wanted_re); $wanted_re = str_replace(array('%u\\|b%', '%b\\|u%'), '', $wanted_re); // Stick to basics $wanted_re = str_replace('%e', '\\' . DIRECTORY_SEPARATOR, $wanted_re); $wanted_re = str_replace('%s', '[^\\r\\n]+', $wanted_re); $wanted_re = str_replace('%S', '[^\\r\\n]*', $wanted_re); $wanted_re = str_replace('%a', '.+', $wanted_re); $wanted_re = str_replace('%A', '.*', $wanted_re); $wanted_re = str_replace('%w', '\\s*', $wanted_re); $wanted_re = str_replace('%i', '[+-]?\\d+', $wanted_re); $wanted_re = str_replace('%d', '\\d+', $wanted_re); $wanted_re = str_replace('%x', '[0-9a-fA-F]+', $wanted_re); $wanted_re = str_replace('%f', '[+-]?\\.?\\d+\\.?\\d*(?:[Ee][+-]?\\d+)?', $wanted_re); $wanted_re = str_replace('%c', '.', $wanted_re); // %f allows two points "-.0.0" but that is the best *simple* expression } /* DEBUG YOUR REGEX HERE var_dump($wanted_re); print(str_repeat('=', 80) . "\n"); var_dump($output); */ if (preg_match("/^{$wanted_re}\$/s", $output)) { $passed = true; if (!$cfg['keep']['php']) { @unlink($test_file); } if (!$leaked && !$failed_headers) { if (isset($section_text['XFAIL'])) { $warn = true; $info = " (warn: XFAIL section but test passes)"; } else { show_result("PASS", $tested, $tested_file, '', $temp_filenames); junit_mark_test_as('PASS', $shortname, $tested); return 'PASSED'; } } } } else { $wanted = trim($section_text['EXPECT']); $wanted = preg_replace('/\\r\\n/', "\n", $wanted); show_file_block('exp', $wanted); // compare and leave on success if (!strcmp($output, $wanted)) { $passed = true; if (!$cfg['keep']['php']) { @unlink($test_file); } if (!$leaked && !$failed_headers) { if (isset($section_text['XFAIL'])) { $warn = true; $info = " (warn: XFAIL section but test passes)"; } else { show_result("PASS", $tested, $tested_file, '', $temp_filenames); junit_mark_test_as('PASS', $shortname, $tested); return 'PASSED'; } } } $wanted_re = null; } // Test failed so we need to report details. if ($failed_headers) { $passed = false; $wanted = $wanted_headers . "\n--HEADERS--\n" . $wanted; $output = $output_headers . "\n--HEADERS--\n" . $output; if (isset($wanted_re)) { $wanted_re = preg_quote($wanted_headers . "\n--HEADERS--\n", '/') . $wanted_re; } } if ($leaked) { $restype[] = 'LEAK'; } if ($warn) { $restype[] = 'WARN'; } if (!$passed) { if (isset($section_text['XFAIL'])) { $restype[] = 'XFAIL'; $info = ' XFAIL REASON: ' . rtrim($section_text['XFAIL']); } else { $restype[] = 'FAIL'; } } if (!$passed) { // write .exp if (strpos($log_format, 'E') !== false && file_put_contents($exp_filename, $wanted, FILE_BINARY) === false) { error("Cannot create expected test output - {$exp_filename}"); } // write .out if (strpos($log_format, 'O') !== false && file_put_contents($output_filename, $output, FILE_BINARY) === false) { error("Cannot create test output - {$output_filename}"); } // write .diff $diff = generate_diff($wanted, $wanted_re, $output); if (is_array($IN_REDIRECT)) { $diff = "# original source file: {$shortname}\n" . $diff; } show_file_block('diff', $diff); if (strpos($log_format, 'D') !== false && file_put_contents($diff_filename, $diff, FILE_BINARY) === false) { error("Cannot create test diff - {$diff_filename}"); } // write .sh if (strpos($log_format, 'S') !== false && file_put_contents($sh_filename, "#!/bin/sh\n\n{$cmd}\n", FILE_BINARY) === false) { error("Cannot create test shell script - {$sh_filename}"); } chmod($sh_filename, 0755); // write .log if (strpos($log_format, 'L') !== false && file_put_contents($log_filename, "\n---- EXPECTED OUTPUT\n{$wanted}\n---- ACTUAL OUTPUT\n{$output}\n---- FAILED\n", FILE_BINARY) === false) { error("Cannot create test log - {$log_filename}"); error_report($file, $log_filename, $tested); } } show_result(implode('&', $restype), $tested, $tested_file, $info, $temp_filenames); foreach ($restype as $type) { $PHP_FAILED_TESTS[$type . 'ED'][] = array('name' => $file, 'test_name' => (is_array($IN_REDIRECT) ? $IN_REDIRECT['via'] : '') . $tested . " [{$tested_file}]", 'output' => $output_filename, 'diff' => $diff_filename, 'info' => $info); } $diff = empty($diff) ? '' : preg_replace('/\\e/', '<esc>', $diff); junit_mark_test_as($restype, str_replace($cwd . '/', '', $tested_file), $tested, null, $info, $diff); return $restype[0] . 'ED'; }
// Copyright (C) 2008 University of California // // BOINC is free software; you can redistribute it and/or modify it // under the terms of the GNU Lesser General Public License // as published by the Free Software Foundation, // either version 3 of the License, or (at your option) any later version. // // BOINC is distributed in the hope that it will be useful, // but WITHOUT ANY WARRANTY; without even the implied warranty of // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. // See the GNU Lesser General Public License for more details. // // You should have received a copy of the GNU Lesser General Public License // along with BOINC. If not, see <http://www.gnu.org/licenses/>. // show a result require_once "../inc/util.inc"; require_once "../inc/result.inc"; $x = get_int("resultid", true); if ($x) { $result = BoincResult::lookup_id($x); } else { $x = get_str("result_name"); $result = BoincResult::lookup_name($x); } if (!$result) { error_page(tra("No such task:") . " " . htmlspecialchars($x)); // the htmlspecialchars prevents XSS } page_head(tra("Task") . " " . htmlspecialchars($x)); show_result($result); page_tail();
while (list($brgy_id, $brgy_name) = mysql_fetch_array($q_brgy)) { if ($brgy_name == $_GET["brgy"]) { echo "<option value='{$brgy_id}' SELECTED>{$brgy_name}</option>"; } else { echo "<option value='{$brgy_id}'>{$brgy_name}</option>"; } } echo "</select>"; echo "</td>"; echo "</tr>"; echo "<tr><td colspan='2' align='center'>"; echo "<input type='submit' name='submit_search' value='Search Relatives'></input>"; echo "</td></tr>"; echo "</table>"; echo "</form>"; show_result(); insert_select_patient(); } else { echo "<font color='red'>Please login to access the Mobile Midwife Synchronization interfaces</font>"; } function show_result() { $arr_family_id = array(); if ($_POST["submit_search"] == "Search Relatives") { //print_r($_POST); $q_family = mysql_query("SELECT DISTINCT a.family_id FROM m_family_members a, m_patient b, m_family_address c, m_lib_barangay d WHERE a.patient_id=b.patient_id AND b.patient_lastname='{$_POST['txt_lname']}' AND b.patient_id!='{$_GET['pxid']}'") or die("Cannot query 57: " . mysql_error()); if (mysql_num_rows($q_family) == 0) { echo "<script language='Javascript'>"; echo "if(window.confirm('No family with the surname " . strtoupper($_POST[txt_lname]) . " was found. Do you wish to return to the previous window? Otherwise, press Cancel and search another surname.')){"; echo "window.close()"; echo "}";
<table width="100%" border="0" cellspacing="0" cellpadding="0"> <tr> <td class="messageStackSuccess"> <font size="1"> '; if ($import) { show_result($result, 'prod_new', TEXT_RESULT_P_NEW); if ($not_is_customers) { show_result($result, 'prod_upd', TEXT_RESULT_P_CHANGED); show_result($result, 'cat_new', TEXT_RESULT_C_NEW); show_result($result, 'cat_upd', TEXT_RESULT_C_UPDATED); show_result($result, 'cat_touched', TEXT_RESULT_C_CHANGED); } } else { if ($export) { show_result($result, 'prod_exp', TEXT_RESULT_P_EXPORTED); } } if (isset($time)) { $main_content .= $time; } $main_content .= HTML_BR . HTML_BR . ' </font> </td> </tr> </table>'; if ($import) { $n = count($import->result[1]); if ($n) { $main_content .= ' <table width="100%" border="0" cellspacing="0" cellpadding="0">
<?php $id = $_POST["id"]; $refer_db_name = $_POST["refer_name"]; $cond_values_str = $_POST["cond_values_str"]; include "../user_conf/query_conf.php"; include "../user_conf/db_conf.php"; include "../user_conf/func_result_conf.php"; include "../user_conf/convert_func_list.php"; show_result($id, $refer_db_name, $cond_values_str); function build_schema_file($sub_arr) { global $conf_list; $host = $sub_arr["db_host"]; $port = $sub_arr["db_port"]; $db_name = $sub_arr["db_name"]; $table_name = $sub_arr["table_name"]; list($username, $passwd) = $conf_list[$host . ":" . $port]; $schema_file = "schema-list/{$host}-{$port}-{$db_name}-{$table_name}.php"; if (!file_exists($schema_file)) { $conn = mysql_connect("{$host}:{$port}", $username, $passwd) or die("Could not connect: " . mysql_error()); mysql_select_db($db_name, $conn); $result = mysql_query("DESC {$table_name}", $conn) or die("无效的查询条件: " . mysql_error()); $handle = fopen($schema_file, "w"); fwrite($handle, "<?php\n"); fwrite($handle, "\$schema_arr = Array(\n"); while ($row = mysql_fetch_assoc($result)) { $user_name = $row["Field"]; $type = $row["Type"]; fwrite($handle, "\t\"{$user_name}\" => \"{$type}\",\n") or die("不能写入到文件 {$schema_file}"); }
?> <li class="tbody"> <span style="width:90px;" class="text-center"><?php echo show_step_type($item["step"]); ?> </span> <span style="width:90px;" class="text-center"><?php echo $item["user_name"]; ?> </span> <span style="width:90px;" class="text-center"><?php echo todate($item["create_time"], 'Y-m-d'); ?> </span> <span style="width:90px;" class="text-center"><?php echo show_result($item["result"]); ?> </span> <span class="auto"> <div style="overflow:hidden"> <?php echo $item["comment"]; ?> </div> </span> </li><?php } } } else { echo ""; } ?>
<li> <div class="checkbox"> <input type="checkbox" name="cincoEstrella" value="1"> <span class="glyphicon glyphicon-star" aria-hidden="true"></span> <span class="glyphicon glyphicon-star" aria-hidden="true"></span> <span class="glyphicon glyphicon-star" aria-hidden="true"></span> <span class="glyphicon glyphicon-star" aria-hidden="true"></span> <span class="glyphicon glyphicon-star" aria-hidden="true"></span> </div> </li> </ul> </div> </div> </div> <div id="resultados" class="col-md-9" style="text-align: left"> <?php if (count($results) != 0) { foreach ($results as $result) { echo show_result($result); } } else { echo '<h3>No se encontraron resultados</h3>'; } ?> </div> </div> </div> </div> </div> </section>
<div class="tab-content"> <div id="home" class="tab-pane fade in active"> <h3 style="text-align: left;">Actividades</h3> <?php echo '<a href="' . $createActivity . '" style="text-align: right;">'; echo $OUTPUT->pix_icon('t/addfile', 'Crear una actividad'); echo ' Crear una actividad</a>'; if ($countActivities == 1) { echo show_result($activities); } elseif ($countActivities > 1) { foreach ($activities as $activity) { echo show_result($activity); } } else { echo "<h3>Aún no has creado actividades...</h3>"; } ?> </div> <div id="menu1" class="tab-pane fade"> <h3 style="text-align: left;">Rúbricas</h3> <?php if ($countRubrics == 1) { $rubric = $DB->get_record('grading_definitions', array('usercreated' => $USER->id)); echo '<div class="panel panel-default">';
function run_test($file, $www) { // parse the test '$file' $section_text = parse_file($file); // setup environment if (EndsWith($www, '.php')) { $www = dirname($www); } if (!EndsWith($www, '/')) { $www .= '/'; } $phpfile = replace_extension($file, 'php'); $tested = trim($section_text['TEST']); $env = array('HTTP_CONTENT_ENCODING' => ''); $opts = array('http' => array('method' => "GET", 'header' => '')); if (!empty($section_text['ENV'])) { foreach (explode("\n", trim($section_text['ENV'])) as $e) { $e = explode('=', trim($e), 2); if (!empty($e[0]) && isset($e[1])) { $env[$e[0]] = $e[1]; } } } // Default ini settings $ini_settings = array(); // put additional INI settings here // Any special ini settings, these may overwrite the test defaults... if (array_key_exists('INI', $section_text)) { if (strpos($section_text['INI'], '{PWD}') !== false) { $section_text['INI'] = str_replace('{PWD}', dirname(realpath($file)), $section_text['INI']); } settings2array(preg_split("/[\n\r]+/", $section_text['INI']), $ini_settings); } // prepend custom ini settings if (count($ini_settings) > 0) { $section_text['FILE'] = get_ini_code($ini_settings) . $section_text['FILE']; } // skip this test ? try_skip($file, $www, $section_text); // redirect test ? try_redirect($file, $www, $section_text); // request .php script save_text($phpfile, $section_text['FILE']); if (array_key_exists('GET', $section_text)) { $query_string = trim($section_text['GET']); } else { $query_string = ''; } $env['QUERY_STRING'] = $query_string; if (array_key_exists('COOKIE', $section_text)) { $env['HTTP_COOKIE'] = trim($section_text['COOKIE']); $opts["http"]["header"] .= "Cookie: " . $env['HTTP_COOKIE'] . "\r\n"; } else { $env['HTTP_COOKIE'] = ''; } $args = isset($section_text['ARGS']) ? ' -- ' . $section_text['ARGS'] : ''; if (array_key_exists('POST_RAW', $section_text) && !empty($section_text['POST_RAW'])) { $post = trim($section_text['POST_RAW']); $raw_lines = explode("\n", $post); $request = ''; $started = false; foreach ($raw_lines as $line) { if (empty($env['CONTENT_TYPE']) && preg_match('/^Content-Type:(.*)/i', $line, $res)) { $env['CONTENT_TYPE'] = trim(str_replace("\r", '', $res[1])); continue; } if ($started) { $request .= "\n"; } $started = true; $request .= $line; } $env['CONTENT_LENGTH'] = strlen($request); $env['REQUEST_METHOD'] = 'POST'; $opts["http"]["method"] = "POST"; $opts["http"]["header"] .= "Content-type: " . $env['CONTENT_TYPE'] . "\r\n"; $opts["http"]["content"] = $request; if (empty($request)) { error("POST empty in '{$file}'"); } } else { if (array_key_exists('POST', $section_text) && !empty($section_text['POST'])) { $post = trim($section_text['POST']); if (array_key_exists('GZIP_POST', $section_text) && function_exists('gzencode')) { $post = gzencode($post, 9, FORCE_GZIP); $env['HTTP_CONTENT_ENCODING'] = 'gzip'; } else { if (array_key_exists('DEFLATE_POST', $section_text) && function_exists('gzcompress')) { $post = gzcompress($post, 9); $env['HTTP_CONTENT_ENCODING'] = 'deflate'; } } //save_text($tmp_post, $post); $content_length = strlen($post); $env['REQUEST_METHOD'] = 'POST'; $env['CONTENT_TYPE'] = 'application/x-www-form-urlencoded'; $env['CONTENT_LENGTH'] = $content_length; $opts["http"]["method"] = "POST"; $opts["http"]["header"] .= "Content-type: " . $env['CONTENT_TYPE'] . "\r\n"; $opts["http"]["header"] .= "Content-encoding: " . $env['HTTP_CONTENT_ENCODING'] . "\r\n"; $opts["http"]["header"] .= "Content-length: " . $content_length . "\r\n"; $opts["http"]["content"] = $post; } else { $env['REQUEST_METHOD'] = 'GET'; $env['CONTENT_TYPE'] = ''; $env['CONTENT_LENGTH'] = ''; } } $context = stream_context_create($opts); $out = _file_get_contents($www . $phpfile, false, $context, &$headers); if ($out === FALSE) { echo '<br/>'; error("See <a target='_blank' href='{$phpfile}'>{$phpfile}</a>, exception "); } if (StartsWith($out, "\r\nCompileError") || StartsWith($out, "\r\nCompileWarning")) { show_result("<span class='skip'>SKIP</span>", $file, ", Script generates <b>CompileError</b> or <b>CompileWarning</b>, so it cannot be compared with PHP. <a href='{$phpfile}' target='_blank'>Try the script</a><pre>{$out}</pre>"); } // perform clean try_clean($file, $www, $section_text); // compare .php response with expected output // Does the output match what is expected? $output = preg_replace("/\r\n/", "\n", trim($out)); $output = str_replace("string[binary](", "string(", $output); $failed_headers = false; if (isset($section_text['EXPECTHEADERS'])) { $want = array(); $wanted_headers = array(); $lines = preg_split("/[\n\r]+/", (string) $section_text['EXPECTHEADERS']); foreach ($lines as $line) { if (strpos($line, ':') !== false) { $line = explode(':', $line, 2); $want[trim($line[0])] = trim($line[1]); $wanted_headers[] = trim($line[0]) . ': ' . trim($line[1]); } } $org_headers = $headers; $headers = array(); $output_headers = array(); foreach ($want as $k => $v) { if (isset($org_headers[$k])) { $headers = $org_headers[$k]; $output_headers[] = $k . ': ' . $org_headers[$k]; } if (!isset($org_headers[$k]) || $org_headers[$k] != $v) { $failed_headers = true; } } ksort($wanted_headers); $wanted_headers = join("\n", $wanted_headers); ksort($output_headers); $output_headers = join("\n", $output_headers); } if (isset($section_text['EXPECTF']) || isset($section_text['EXPECTREGEX'])) { if (isset($section_text['EXPECTF'])) { $wanted = trim($section_text['EXPECTF']); } else { $wanted = trim($section_text['EXPECTREGEX']); } $wanted_re = preg_replace('/\\r\\n/', "\n", $wanted); if (isset($section_text['EXPECTF'])) { // do preg_quote, but miss out any %r delimited sections $temp = ""; $r = "%r"; $startOffset = 0; $length = strlen($wanted_re); while ($startOffset < $length) { $start = strpos($wanted_re, $r, $startOffset); if ($start !== false) { // we have found a start tag $end = strpos($wanted_re, $r, $start + 2); if ($end === false) { // unbalanced tag, ignore it. $end = $start = $length; } } else { // no more %r sections $start = $end = $length; } // quote a non re portion of the string $temp = $temp . preg_quote(substr($wanted_re, $startOffset, $start - $startOffset), '/'); // add the re unquoted. if ($end > $start) { $temp = $temp . '(' . substr($wanted_re, $start + 2, $end - $start - 2) . ')'; } $startOffset = $end + 2; } $wanted_re = $temp; $wanted_re = str_replace(array('%binary_string_optional%'), version_compare(PHP_VERSION, '6.0.0-dev') == -1 ? 'string' : 'binary string', $wanted_re); $wanted_re = str_replace(array('%unicode_string_optional%'), version_compare(PHP_VERSION, '6.0.0-dev') == -1 ? 'string' : 'Unicode string', $wanted_re); $wanted_re = str_replace(array('%unicode\\|string%', '%string\\|unicode%'), version_compare(PHP_VERSION, '6.0.0-dev') == -1 ? 'string' : 'unicode', $wanted_re); $wanted_re = str_replace(array('%u\\|b%', '%b\\|u%'), version_compare(PHP_VERSION, '6.0.0-dev') == -1 ? '' : 'u', $wanted_re); // Stick to basics $wanted_re = str_replace('%e', '\\' . '\\', $wanted_re); $wanted_re = str_replace('%s', '[^\\r\\n]+', $wanted_re); $wanted_re = str_replace('%S', '[^\\r\\n]*', $wanted_re); $wanted_re = str_replace('%a', '.+', $wanted_re); $wanted_re = str_replace('%A', '.*', $wanted_re); $wanted_re = str_replace('%w', '\\s*', $wanted_re); $wanted_re = str_replace('%i', '[+-]?\\d+', $wanted_re); $wanted_re = str_replace('%d', '\\d+', $wanted_re); $wanted_re = str_replace('%x', '[0-9a-fA-F]+', $wanted_re); $wanted_re = str_replace('%f', '[+-]?\\.?\\d+\\.?\\d*(?:[Ee][+-]?\\d+)?', $wanted_re); $wanted_re = str_replace('%c', '.', $wanted_re); // %f allows two points "-.0.0" but that is the best *simple* expression } /* DEBUG YOUR REGEX HERE var_dump($wanted_re); print(str_repeat('=', 80) . "\n"); var_dump($output); */ if (preg_match("/^{$wanted_re}\$/s", $output)) { @unlink($phpfile); show_result("<span class='pass'>PASS</span>", "{$file}", ''); } } else { $wanted = (string) trim($section_text['EXPECT']); $wanted = preg_replace('/\\r\\n/', "\n", $wanted); // compare and leave on success if (!strcmp($output, $wanted)) { @unlink($phpfile); show_result("<span class='pass'>PASS</span>", $file, ''); } $wanted_re = null; } // Test failed so we need to report details. if ($failed_headers) { $passed = false; $wanted = (string) $wanted_headers . "\n--HEADERS--\n" . (string) $wanted; $output = (string) $output_headers . "\n--HEADERS--\n" . (string) $output; if (isset($wanted_re)) { $wanted_re = preg_quote($wanted_headers . "\n--HEADERS--\n", '/') . $wanted_re; } } // write .exp if (file_put_contents($file . '.exp', (string) $wanted, FILE_BINARY) === false) { error("Cannot create expected test output '{$file}.exp'"); } // write .out if (file_put_contents($file . '.out', (string) $output, FILE_BINARY) === false) { error("Cannot create test output - '{$file}.out'"); } // write .diff $diff = generate_diff($wanted, $wanted_re, $output); if (file_put_contents($file . '.diff', (string) $diff, FILE_BINARY) === false) { error("Cannot create test diff - '{$file}.diff'"); } $resultid = "result_" . strlen($phpfile) . '_' . crc32($phpfile); $sourceid = "source_" . strlen($phpfile) . '_' . crc32($phpfile); show_result("<span class='fail'>FAIL</span>", $file, ", <a href='{$phpfile}' target='_blank'>Try the script</a>" . ", <a href='#' onclick='\$(\"#{$sourceid}\").slideToggle();return false;'>source</a>" . ", <a href='#' onclick='\$(\"#{$resultid}\").slideToggle();return false;'>details</a>" . "<div id='{$sourceid}' style='display:none;background:#eee;border:1px dashed #888;'><pre>" . htmlspecialchars(trim(_file_get_contents($file, false, null, &$dummyheaders))) . "</pre></div>" . "<div id='{$resultid}' style='display:none;'><table border='1'><tr><td><b>Output</b><br/><pre style='background:#fee;font-size:8px;'>" . htmlspecialchars($output) . "</pre></td><td><b>Expected</b><br/><pre style='background:#efe;font-size:8px;'>" . htmlspecialchars($wanted) . "</pre></td></tr></table></div>"); // write .sh //if (strpos($log_format, 'S') !== false && file_put_contents($sh_filename, b"#!/bin/sh{$cmd}", FILE_BINARY) === false) { //error("Cannot create test shell script - $sh_filename"); //} //chmod($sh_filename, 0755); /*foreach ($restype as $type) { $PHP_FAILED_TESTS[$type.'ED'][] = array ( 'name' => $file, 'test_name' => (is_array($IN_REDIRECT) ? $IN_REDIRECT['via'] : '') . $tested . " [$tested_file]", 'output' => $output_filename, 'diff' => $diff_filename, 'info' => $info, ); }*/ }
<?php function show_result($a, $b) { $result = $a + $b; echo "{$a} + {$b} = <b>{$result}</b><br>"; echo '<a href=sum.php>Еще разок</a>'; } if (isset($_POST['a']) && isset($_POST['b'])) { show_result($_POST['a'], $_POST['b']); } else { include 'form_sum.php'; }
function run_test($php, $file, $env) { global $log_format, $info_params, $ini_overwrites, $cwd, $PHP_FAILED_TESTS; global $pass_options, $DETAILED, $IN_REDIRECT, $test_cnt, $test_idx; global $leak_check, $temp_source, $temp_target, $cfg, $environment; global $no_clean; $temp_filenames = null; $org_file = $file; if (isset($env['TEST_PHP_CGI_EXECUTABLE'])) { $php_cgi = $env['TEST_PHP_CGI_EXECUTABLE']; } if (is_array($file)) { $file = $file[0]; } if ($DETAILED) { echo "\n=================\nTEST {$file}\n"; } // Load the sections of the test file. $section_text = array('TEST' => '', 'SKIPIF' => '', 'GET' => '', 'POST_RAW' => '', 'POST' => '', 'UPLOAD' => '', 'ARGS' => ''); $fp = @fopen($file, "rt") or error("Cannot open test file: {$file}"); $borked = false; $bork_info = ''; if (!feof($fp)) { $line = fgets($fp); } else { $bork_info = "empty test [{$file}]"; $borked = true; } if (!ereg('^--TEST--', $line, $r)) { $bork_info = "tests must start with --TEST-- [{$file}]"; $borked = true; } $section = 'TEST'; $secfile = false; $secdone = false; while (!feof($fp)) { $line = fgets($fp); // Match the beginning of a section. if (preg_match('/^--([A-Z_]+)--/', $line, $r)) { $section = $r[1]; $section_text[$section] = ''; $secfile = $section == 'FILE' || $section == 'FILEEOF'; $secdone = false; continue; } // Add to the section text. if (!$secdone) { $section_text[$section] .= $line; } // End of actual test? if ($secfile && preg_match('/^===DONE===/', $line, $r)) { $secdone = true; } } // the redirect section allows a set of tests to be reused outside of // a given test dir if (@count($section_text['REDIRECTTEST']) == 1) { if ($IN_REDIRECT) { $borked = true; $bork_info = "Can't redirect a test from within a redirected test"; } else { $borked = false; } } else { if (@count($section_text['FILE']) + @count($section_text['FILEEOF']) != 1) { $bork_info = "missing section --FILE--"; $borked = true; } if (@count($section_text['FILEEOF']) == 1) { $section_text['FILE'] = preg_replace("/[\r\n]+\$/", '', $section_text['FILEEOF']); unset($section_text['FILEEOF']); } if (@count($section_text['EXPECT']) + @count($section_text['EXPECTF']) + @count($section_text['EXPECTREGEX']) != 1) { $bork_info = "missing section --EXPECT--, --EXPECTF-- or --EXPECTREGEX--"; $borked = true; } } fclose($fp); $shortname = str_replace($cwd . '/', '', $file); $tested_file = $shortname; if ($borked) { show_result("BORK", $bork_info, $tested_file); $PHP_FAILED_TESTS['BORKED'][] = array('name' => $file, 'test_name' => '', 'output' => '', 'diff' => '', 'info' => "{$bork_info} [{$file}]"); return 'BORKED'; } $tested = trim($section_text['TEST']); /* For GET/POST tests, check if cgi sapi is available and if it is, use it. */ if (!empty($section_text['GET']) || !empty($section_text['POST']) || !empty($section_text['POST_RAW'])) { if (isset($php_cgi)) { $old_php = $php; $php = $php_cgi . ' -C '; } elseif (!strncasecmp(PHP_OS, "win", 3) && file_exists(dirname($php) . "/php-cgi.exe")) { $old_php = $php; $php = realpath(dirname($php) . "/php-cgi.exe") . ' -C '; } elseif (file_exists("./sapi/cgi/php")) { $old_php = $php; $php = realpath("./sapi/cgi/php") . ' -C '; } else { show_result("SKIP", $tested, $tested_file, "reason: CGI not available"); return 'SKIPPED'; } } show_test($test_idx, $shortname); if (is_array($IN_REDIRECT)) { $temp_dir = $test_dir = $IN_REDIRECT['dir']; } else { $temp_dir = $test_dir = realpath(dirname($file)); } if ($temp_source && $temp_target) { $temp_dir = str_replace($temp_source, $temp_target, $temp_dir); } $main_file_name = basename($file, 'phpt'); $diff_filename = $temp_dir . DIRECTORY_SEPARATOR . $main_file_name . 'diff'; $log_filename = $temp_dir . DIRECTORY_SEPARATOR . $main_file_name . 'log'; $exp_filename = $temp_dir . DIRECTORY_SEPARATOR . $main_file_name . 'exp'; $output_filename = $temp_dir . DIRECTORY_SEPARATOR . $main_file_name . 'out'; $memcheck_filename = $temp_dir . DIRECTORY_SEPARATOR . $main_file_name . 'mem'; $temp_file = $temp_dir . DIRECTORY_SEPARATOR . $main_file_name . 'php'; $test_file = $test_dir . DIRECTORY_SEPARATOR . $main_file_name . 'php'; $temp_skipif = $temp_dir . DIRECTORY_SEPARATOR . $main_file_name . 'skip.php'; $test_skipif = $test_dir . DIRECTORY_SEPARATOR . $main_file_name . 'skip.php'; $temp_clean = $temp_dir . DIRECTORY_SEPARATOR . $main_file_name . 'clean.php'; $test_clean = $test_dir . DIRECTORY_SEPARATOR . $main_file_name . 'clean.php'; $tmp_post = $temp_dir . DIRECTORY_SEPARATOR . uniqid('/phpt.'); $tmp_relative_file = str_replace(dirname(__FILE__) . DIRECTORY_SEPARATOR, '', $test_file) . 't'; if ($temp_source && $temp_target) { $temp_skipif .= 's'; $temp_file .= 's'; $temp_clean .= 's'; $copy_file = $temp_dir . DIRECTORY_SEPARATOR . basename(is_array($file) ? $file[1] : $file) . '.phps'; if (!is_dir(dirname($copy_file))) { @mkdir(dirname($copy_file), 0777, true) or error("Cannot create output directory - " . dirname($copy_file)); } if (isset($section_text['FILE'])) { save_text($copy_file, $section_text['FILE']); } $temp_filenames = array('file' => $copy_file, 'diff' => $diff_filename, 'log' => $log_filename, 'exp' => $exp_filename, 'out' => $output_filename, 'mem' => $memcheck_filename, 'php' => $temp_file, 'skip' => $temp_skipif, 'clean' => $temp_clean); } if (is_array($IN_REDIRECT)) { $tested = $IN_REDIRECT['prefix'] . ' ' . trim($section_text['TEST']); $tested_file = $tmp_relative_file; $section_text['FILE'] = "# original source file: {$shortname}\n" . $section_text['FILE']; } // unlink old test results @unlink($diff_filename); @unlink($log_filename); @unlink($exp_filename); @unlink($output_filename); @unlink($memcheck_filename); @unlink($temp_file); @unlink($test_file); @unlink($temp_skipif); @unlink($test_skipif); @unlink($tmp_post); @unlink($temp_clean); @unlink($test_clean); // Reset environment from any previous test. $env['REDIRECT_STATUS'] = ''; $env['QUERY_STRING'] = ''; $env['PATH_TRANSLATED'] = ''; $env['SCRIPT_FILENAME'] = ''; $env['REQUEST_METHOD'] = ''; $env['CONTENT_TYPE'] = ''; $env['CONTENT_LENGTH'] = ''; if (!empty($section_text['ENV'])) { foreach (explode("\n", $section_text['ENV']) as $e) { $e = explode('=', trim($e)); if (count($e) == 2) { $env[$e[0]] = $e[1]; } } } // Default ini settings $ini_settings = array(); // additional ini overwrites //$ini_overwrites[] = 'setting=value'; settings2array($ini_overwrites, $ini_settings); // Any special ini settings // these may overwrite the test defaults... if (array_key_exists('INI', $section_text)) { if (strpos($section_text['INI'], '{PWD}') !== false) { $section_text['INI'] = str_replace('{PWD}', dirname($file), $section_text['INI']); } settings2array(preg_split("/[\n\r]+/", $section_text['INI']), $ini_settings); } settings2params($ini_settings); // Check if test should be skipped. $info = ''; $warn = false; if (array_key_exists('SKIPIF', $section_text)) { if (trim($section_text['SKIPIF'])) { if ($cfg['show']['skip']) { echo "\n========SKIP========\n"; echo $section_text['SKIPIF']; echo "========DONE========\n"; } save_text($test_skipif, $section_text['SKIPIF'], $temp_skipif); $extra = substr(PHP_OS, 0, 3) !== "WIN" ? "unset REQUEST_METHOD; unset QUERY_STRING; unset PATH_TRANSLATED; unset SCRIPT_FILENAME; unset REQUEST_METHOD;" : ""; $output = system_with_timeout("{$extra} {$php} -q {$ini_settings} {$test_skipif}", $env); if (!$cfg['keep']['skip']) { @unlink($test_skipif); } if (!strncasecmp('skip', trim($output), 4)) { $reason = eregi("^skip[[:space:]]*(.+)\$", trim($output)) ? eregi_replace("^skip[[:space:]]*(.+)\$", "\\1", trim($output)) : FALSE; if ($reason) { show_result("SKIP", $tested, $tested_file, "reason: {$reason}", $temp_filenames); } else { show_result("SKIP", $tested, $tested_file, '', $temp_filenames); } if (isset($old_php)) { $php = $old_php; } if (!$cfg['keep']['skip']) { @unlink($test_skipif); } return 'SKIPPED'; } if (!strncasecmp('info', trim($output), 4)) { $reason = ereg("^info[[:space:]]*(.+)\$", trim($output)) ? ereg_replace("^info[[:space:]]*(.+)\$", "\\1", trim($output)) : FALSE; if ($reason) { $info = " (info: {$reason})"; } } if (!strncasecmp('warn', trim($output), 4)) { $reason = ereg("^warn[[:space:]]*(.+)\$", trim($output)) ? ereg_replace("^warn[[:space:]]*(.+)\$", "\\1", trim($output)) : FALSE; if ($reason) { $warn = true; /* only if there is a reason */ $info = " (warn: {$reason})"; } } } } if (@count($section_text['REDIRECTTEST']) == 1) { $test_files = array(); $IN_REDIRECT = eval($section_text['REDIRECTTEST']); $IN_REDIRECT['via'] = "via [{$shortname}]\n\t"; $IN_REDIRECT['dir'] = realpath(dirname($file)); $IN_REDIRECT['prefix'] = trim($section_text['TEST']); if (@count($IN_REDIRECT['TESTS']) == 1) { if (is_array($org_file)) { $test_files[] = $org_file[1]; } else { $GLOBALS['test_files'] = $test_files; find_files($IN_REDIRECT['TESTS']); foreach ($GLOBALS['test_files'] as $f) { $test_files[] = array($f, $file); } } $test_cnt += count($test_files) - 1; $test_idx--; show_redirect_start($IN_REDIRECT['TESTS'], $tested, $tested_file); // set up environment $redirenv = array_merge($environment, $IN_REDIRECT['ENV']); $redirenv['REDIR_TEST_DIR'] = realpath($IN_REDIRECT['TESTS']) . DIRECTORY_SEPARATOR; usort($test_files, "test_sort"); run_all_tests($test_files, $redirenv, $tested); show_redirect_ends($IN_REDIRECT['TESTS'], $tested, $tested_file); // a redirected test never fails $IN_REDIRECT = false; return 'REDIR'; } } if (is_array($org_file) || @count($section_text['REDIRECTTEST']) == 1) { if (is_array($org_file)) { $file = $org_file[0]; } $bork_info = "Redirected test did not contain redirection info"; show_result("BORK", $bork_info, '', $temp_filenames); $PHP_FAILED_TESTS['BORKED'][] = array('name' => $file, 'test_name' => '', 'output' => '', 'diff' => '', 'info' => "{$bork_info} [{$file}]"); //$test_cnt -= 1; // Only if is_array($org_file) ? //$test_idx--; return 'BORKED'; } // We've satisfied the preconditions - run the test! if ($cfg['show']['php']) { echo "\n========TEST========\n"; echo $section_text['FILE']; echo "========DONE========\n"; } save_text($test_file, $section_text['FILE'], $temp_file); if (array_key_exists('GET', $section_text)) { $query_string = trim($section_text['GET']); } else { $query_string = ''; } $env['REDIRECT_STATUS'] = '1'; $env['QUERY_STRING'] = $query_string; $env['PATH_TRANSLATED'] = $test_file; $env['SCRIPT_FILENAME'] = $test_file; $args = $section_text['ARGS'] ? ' -- ' . $section_text['ARGS'] : ''; if (array_key_exists('POST_RAW', $section_text) && !empty($section_text['POST_RAW'])) { $post = trim($section_text['POST_RAW']); $raw_lines = explode("\n", $post); $request = ''; foreach ($raw_lines as $line) { if (empty($env['CONTENT_TYPE']) && eregi('^(Content-Type:)(.*)', $line, $res)) { $env['CONTENT_TYPE'] = trim(str_replace("\r", '', $res[2])); continue; } $request .= $line . "\n"; } $env['CONTENT_LENGTH'] = strlen($request); $env['REQUEST_METHOD'] = 'POST'; if (empty($request)) { return 'BORKED'; } save_text($tmp_post, $request); $cmd = "{$php}{$pass_options}{$ini_settings} -f \"{$test_file}\" 2>&1 < {$tmp_post}"; } elseif (array_key_exists('POST', $section_text) && !empty($section_text['POST'])) { $post = trim($section_text['POST']); save_text($tmp_post, $post); $content_length = strlen($post); $env['REQUEST_METHOD'] = 'POST'; $env['CONTENT_TYPE'] = 'application/x-www-form-urlencoded'; $env['CONTENT_LENGTH'] = $content_length; $cmd = "{$php}{$pass_options}{$ini_settings} -f \"{$test_file}\" 2>&1 < {$tmp_post}"; } else { $env['REQUEST_METHOD'] = 'GET'; $env['CONTENT_TYPE'] = ''; $env['CONTENT_LENGTH'] = ''; $cmd = "{$php}{$pass_options}{$ini_settings} -f \"{$test_file}\" {$args} 2>&1"; } if ($leak_check) { $cmd = "valgrind -q --tool=memcheck --log-file-exactly={$memcheck_filename} {$cmd}"; } if ($DETAILED) { echo "\nCONTENT_LENGTH = " . $env['CONTENT_LENGTH'] . "\nCONTENT_TYPE = " . $env['CONTENT_TYPE'] . "\nPATH_TRANSLATED = " . $env['PATH_TRANSLATED'] . "\nQUERY_STRING = " . $env['QUERY_STRING'] . "\nREDIRECT_STATUS = " . $env['REDIRECT_STATUS'] . "\nREQUEST_METHOD = " . $env['REQUEST_METHOD'] . "\nSCRIPT_FILENAME = " . $env['SCRIPT_FILENAME'] . "\nCOMMAND {$cmd}\n"; } $out = system_with_timeout($cmd, $env); if (array_key_exists('CLEAN', $section_text) && (!$no_clean || $cfg['keep']['clean'])) { if (trim($section_text['CLEAN'])) { if ($cfg['show']['clean']) { echo "\n========CLEAN=======\n"; echo $section_text['CLEAN']; echo "========DONE========\n"; } save_text($test_clean, trim($section_text['CLEAN']), $temp_clean); if (!$no_clean) { $clean_params = array(); settings2array($ini_overwrites, $clean_params); settings2params($clean_params); $extra = substr(PHP_OS, 0, 3) !== "WIN" ? "unset REQUEST_METHOD; unset QUERY_STRING; unset PATH_TRANSLATED; unset SCRIPT_FILENAME; unset REQUEST_METHOD;" : ""; system_with_timeout("{$extra} {$php} -q {$clean_params} {$test_clean}", $env); } if (!$cfg['keep']['clean']) { @unlink($test_clean); } } } @unlink($tmp_post); $leaked = false; $passed = false; if ($leak_check) { // leak check $leaked = @filesize($memcheck_filename) > 0; if (!$leaked) { @unlink($memcheck_filename); } } // Does the output match what is expected? $output = str_replace("\r\n", "\n", trim($out)); /* when using CGI, strip the headers from the output */ if (isset($old_php) && ($pos = strpos($output, "\n\n")) !== FALSE) { $output = substr($output, $pos + 2); } if (isset($section_text['EXPECTF']) || isset($section_text['EXPECTREGEX'])) { if (isset($section_text['EXPECTF'])) { $wanted = trim($section_text['EXPECTF']); } else { $wanted = trim($section_text['EXPECTREGEX']); } $wanted_re = preg_replace('/\\r\\n/', "\n", $wanted); if (isset($section_text['EXPECTF'])) { $wanted_re = preg_quote($wanted_re, '/'); // Stick to basics $wanted_re = str_replace("%e", '\\' . DIRECTORY_SEPARATOR, $wanted_re); $wanted_re = str_replace("%s", ".+?", $wanted_re); //not greedy $wanted_re = str_replace("%w", "\\s*", $wanted_re); $wanted_re = str_replace("%i", "[+\\-]?[0-9]+", $wanted_re); $wanted_re = str_replace("%d", "[0-9]+", $wanted_re); $wanted_re = str_replace("%x", "[0-9a-fA-F]+", $wanted_re); $wanted_re = str_replace("%f", "[+\\-]?\\.?[0-9]+\\.?[0-9]*(E-?[0-9]+)?", $wanted_re); $wanted_re = str_replace("%c", ".", $wanted_re); // %f allows two points "-.0.0" but that is the best *simple* expression } /* DEBUG YOUR REGEX HERE var_dump($wanted_re); print(str_repeat('=', 80) . "\n"); var_dump($output); */ if (preg_match("/^{$wanted_re}\$/s", $output)) { $passed = true; if (!$cfg['keep']['php']) { @unlink($test_file); } if (isset($old_php)) { $php = $old_php; } if (!$leaked) { show_result("PASS", $tested, $tested_file, '', $temp_filenames); return 'PASSED'; } } } else { $wanted = trim($section_text['EXPECT']); $wanted = preg_replace('/\\r\\n/', "\n", $wanted); // compare and leave on success if (!strcmp($output, $wanted)) { $passed = true; if (!$cfg['keep']['php']) { @unlink($test_file); } if (isset($old_php)) { $php = $old_php; } if (!$leaked) { show_result("PASS", $tested, $tested_file, '', $temp_filenames); return 'PASSED'; } } $wanted_re = NULL; } // Test failed so we need to report details. if ($leaked) { $restype = 'LEAK'; } else { if ($warn) { $restype = 'WARN'; } else { $restype = 'FAIL'; } } if (!$passed) { // write .exp if (strpos($log_format, 'E') !== FALSE && file_put_contents($exp_filename, $wanted) === FALSE) { error("Cannot create expected test output - {$exp_filename}"); } // write .out if (strpos($log_format, 'O') !== FALSE && file_put_contents($output_filename, $output) === FALSE) { error("Cannot create test output - {$output_filename}"); } // write .diff if (strpos($log_format, 'D') !== FALSE && file_put_contents($diff_filename, generate_diff($wanted, $wanted_re, $output)) === FALSE) { error("Cannot create test diff - {$diff_filename}"); } // write .log if (strpos($log_format, 'L') !== FALSE && file_put_contents($log_filename, "\n---- EXPECTED OUTPUT\n{$wanted}\n---- ACTUAL OUTPUT\n{$output}\n---- FAILED\n") === FALSE) { error("Cannot create test log - {$log_filename}"); error_report($file, $log_filename, $tested); } } show_result($restype, $tested, $tested_file, $info, $temp_filenames); $PHP_FAILED_TESTS[$restype . 'ED'][] = array('name' => $file, 'test_name' => (is_array($IN_REDIRECT) ? $IN_REDIRECT['via'] : '') . $tested . " [{$tested_file}]", 'output' => $output_filename, 'diff' => $diff_filename, 'info' => $info); if (isset($old_php)) { $php = $old_php; } return $restype . 'ED'; }
function flow_todo($flow_type) { //我的待办流程 $uid = get_user_id(); $str = ""; $where['type'] = array('in', $flow_type); $flow_todo_list = M("Flow")->where($where)->getField('id name,id'); $where_log['result'] = array("in", "3"); // 未完成 $where_log['user_id'] = $uid; $where_log['flow_id'] = array('in', $flow_todo_list); $flow_list = M("FlowLog")->where($where_log)->order('id desc')->select(); $count = M("FlowLog")->where($where_log)->count(); for ($i = 0; $i < $count; $i++) { $flow = M("Flow")->where('id=' . $flow_list[$i]['flow_id'])->find(); $str = $str . "\n\t\t\t\t\t<li> <a href=" . __APP__ . "/flow/read?id=" . $flow_list[$i]['flow_id'] . " title=>【" . $flow_list[$i]['user_name'] . "】 " . $flow['name'] . " " . show_result($flow_list[$i]['result']) . " </a></li>"; } return $str; }