| 1 |
#!/usr/bin/php |
|---|
| 2 |
<?php |
|---|
| 3 |
|
|---|
| 4 |
|
|---|
| 5 |
|
|---|
| 6 |
|
|---|
| 7 |
|
|---|
| 8 |
|
|---|
| 9 |
$tmp = "/tmp/"; |
|---|
| 10 |
$web_root = "/var/www/html/ea_test/"; |
|---|
| 11 |
$web_url = "http://localhost/ea_test/"; |
|---|
| 12 |
$test_url = "http://zoeloelip.be/ea/tests/"; |
|---|
| 13 |
|
|---|
| 14 |
/** |
|---|
| 15 |
* Get a file with a given url using curl. |
|---|
| 16 |
*/ |
|---|
| 17 |
function get_remote_file($url) { |
|---|
| 18 |
$ch = curl_init($url); |
|---|
| 19 |
|
|---|
| 20 |
curl_setopt($ch, CURLOPT_HEADER, 0); |
|---|
| 21 |
curl_setopt($ch, CURLOPT_ENCODING, "gzip"); |
|---|
| 22 |
curl_setopt($ch, CURLOPT_FOLLOWLOCATION, 1); |
|---|
| 23 |
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1); |
|---|
| 24 |
curl_setopt($ch, CURLOPT_TIMEOUT, 120); |
|---|
| 25 |
|
|---|
| 26 |
$output = curl_exec($ch); |
|---|
| 27 |
if (curl_errno($ch) != 0) |
|---|
| 28 |
return ''; |
|---|
| 29 |
curl_close($ch); |
|---|
| 30 |
return $output; |
|---|
| 31 |
} |
|---|
| 32 |
|
|---|
| 33 |
|
|---|
| 34 |
|
|---|
| 35 |
|
|---|
| 36 |
function prep_test($url, $sum, $nocache, $noenc) { |
|---|
| 37 |
global $web_root; |
|---|
| 38 |
|
|---|
| 39 |
|
|---|
| 40 |
$file_name = $web_root.basename($url, ".txt").".php"; |
|---|
| 41 |
if (is_file($file_name)) |
|---|
| 42 |
$old_sum = md5(file_get_contents($web_root.basename($url, ".txt").".php")); |
|---|
| 43 |
else |
|---|
| 44 |
$old_sum = ''; |
|---|
| 45 |
|
|---|
| 46 |
if ($old_sum != $sum) { |
|---|
| 47 |
|
|---|
| 48 |
$test = get_remote_file($url); |
|---|
| 49 |
if (strncasecmp($test, "! eAccelerator test", strlen("! eAccelerator test")) != 0) { |
|---|
| 50 |
die("Could not retrieve valid test file. (url=$url)\n"); |
|---|
| 51 |
} |
|---|
| 52 |
|
|---|
| 53 |
|
|---|
| 54 |
$options = parse_header($test); |
|---|
| 55 |
|
|---|
| 56 |
|
|---|
| 57 |
if ($options['cache'] && !$nocache) |
|---|
| 58 |
file_put_contents($file_name, $test); |
|---|
| 59 |
|
|---|
| 60 |
|
|---|
| 61 |
if ($options['encode'] && !$noenc) |
|---|
| 62 |
file_put_contents(dirname($file_name).'/'.basename($file_name, '.php').'.enc.php', |
|---|
| 63 |
"<?php eaccelerator_load('".eaccelerator_encode($file_name)."'); ?>"); |
|---|
| 64 |
} else { |
|---|
| 65 |
touch ($file_name); |
|---|
| 66 |
$options = parse_header(file_get_contents($file_name)); |
|---|
| 67 |
} |
|---|
| 68 |
|
|---|
| 69 |
if ($nocache) |
|---|
| 70 |
$options['cache'] = false; |
|---|
| 71 |
if ($noenc) |
|---|
| 72 |
$options['encode'] = false; |
|---|
| 73 |
return $options; |
|---|
| 74 |
} |
|---|
| 75 |
|
|---|
| 76 |
|
|---|
| 77 |
|
|---|
| 78 |
|
|---|
| 79 |
function parse_header($test) { |
|---|
| 80 |
|
|---|
| 81 |
$lines = explode("\n", $test); |
|---|
| 82 |
$options = array('cache' => true, 'encode' => true); |
|---|
| 83 |
foreach ($lines as $line) { |
|---|
| 84 |
if (ereg('![[:space:]](.*)', $line, $regs)) { |
|---|
| 85 |
switch ($regs[1]) { |
|---|
| 86 |
case 'no-cache': |
|---|
| 87 |
$options['cache'] = false; |
|---|
| 88 |
break; |
|---|
| 89 |
case 'no-encode': |
|---|
| 90 |
$options['encode'] = false; |
|---|
| 91 |
break; |
|---|
| 92 |
default: |
|---|
| 93 |
} |
|---|
| 94 |
} |
|---|
| 95 |
} |
|---|
| 96 |
return $options; |
|---|
| 97 |
} |
|---|
| 98 |
|
|---|
| 99 |
|
|---|
| 100 |
|
|---|
| 101 |
|
|---|
| 102 |
function run_test($url, $cache, $encode) { |
|---|
| 103 |
global $web_url, $debug; |
|---|
| 104 |
|
|---|
| 105 |
$test_file_url = $web_url.basename($url, ".txt").".php"; |
|---|
| 106 |
if ($debug) print "\n url : $test_file_url\n"; |
|---|
| 107 |
|
|---|
| 108 |
$php_output = get_remote_file($test_file_url); |
|---|
| 109 |
if ($debug) echo "php: \n$php_output\n"; |
|---|
| 110 |
|
|---|
| 111 |
|
|---|
| 112 |
if ($cache) |
|---|
| 113 |
$ea_output = get_remote_file($test_file_url); |
|---|
| 114 |
if ($debug) echo "ea: \n$ea_output\n"; |
|---|
| 115 |
|
|---|
| 116 |
|
|---|
| 117 |
if ($encode) |
|---|
| 118 |
$enc_output = get_remote_file(substr($test_file_url, 0, strlen($test_file_url) - 4).".enc.php"); |
|---|
| 119 |
if ($debug) echo "enc: \n$enc_output\n"; |
|---|
| 120 |
|
|---|
| 121 |
if (!$cache) |
|---|
| 122 |
$result['cache'] = 'skipped'; |
|---|
| 123 |
elseif ($php_output == $ea_output) |
|---|
| 124 |
$result['cache'] = 'succes'; |
|---|
| 125 |
else |
|---|
| 126 |
$result['cache'] = 'failed'; |
|---|
| 127 |
|
|---|
| 128 |
if (!$encode) |
|---|
| 129 |
$result['encoded'] = 'skipped'; |
|---|
| 130 |
elseif ($php_output == $enc_output) |
|---|
| 131 |
$result['encoded'] = 'succes'; |
|---|
| 132 |
else |
|---|
| 133 |
$result['encoded'] = 'failed'; |
|---|
| 134 |
|
|---|
| 135 |
return $result; |
|---|
| 136 |
} |
|---|
| 137 |
|
|---|
| 138 |
function show_help() { |
|---|
| 139 |
die("eAccelerator test suite.\n" . |
|---|
| 140 |
"Usage: run-tests [options] command\n" . |
|---|
| 141 |
"commands:\n" . |
|---|
| 142 |
" list List the test sets available.\n" . |
|---|
| 143 |
" run [test set, test] Run the given test set.\n" . |
|---|
| 144 |
" --noenc Don't test encoding\n" . |
|---|
| 145 |
" --nocache Don't test caching\n" . |
|---|
| 146 |
" clean Clean the test directory.\n" |
|---|
| 147 |
); |
|---|
| 148 |
} |
|---|
| 149 |
|
|---|
| 150 |
function list_sets() { |
|---|
| 151 |
global $test_url; |
|---|
| 152 |
$sets = get_remote_file($test_url.'SETLIST'); |
|---|
| 153 |
$sets = explode("\n", $sets); |
|---|
| 154 |
foreach($sets as $set) { |
|---|
| 155 |
$line = explode(':', $set); |
|---|
| 156 |
if (count($line) == 2) { |
|---|
| 157 |
echo $line[0]; |
|---|
| 158 |
echo "\t"; |
|---|
| 159 |
echo $line[1]; |
|---|
| 160 |
echo "\n"; |
|---|
| 161 |
} |
|---|
| 162 |
} |
|---|
| 163 |
} |
|---|
| 164 |
|
|---|
| 165 |
function run_set($test_set, $nocache, $noenc) { |
|---|
| 166 |
global $test_url; |
|---|
| 167 |
|
|---|
| 168 |
|
|---|
| 169 |
$set = get_remote_file("$test_url$test_set"); |
|---|
| 170 |
$tests = explode("\n", $set); |
|---|
| 171 |
|
|---|
| 172 |
if ($tests[0] != "! eAccelerator test set") { |
|---|
| 173 |
echo "Error: $test_url$test_set isn't a valid test set!\n"; |
|---|
| 174 |
exit(1); |
|---|
| 175 |
} |
|---|
| 176 |
|
|---|
| 177 |
|
|---|
| 178 |
the test, the file won't be cached. Run it in two stages. **/ |
|---|
| 179 |
/* prepare each test */ |
|---|
| 180 |
$test_queue = ''; |
|---|
| 181 |
foreach ($tests as $test) { |
|---|
| 182 |
|
|---|
| 183 |
if (ereg('([A-z0-9]{32})[[:space:]]{2}(.+)', $test, $regs)) { |
|---|
| 184 |
$options = prep_test($test_url.$regs[2], $regs[1], $nocache, $noenc); |
|---|
| 185 |
$options['url'] = $regs[2]; |
|---|
| 186 |
$test_queue[] = $options; |
|---|
| 187 |
} else { |
|---|
| 188 |
echo "$test\n"; |
|---|
| 189 |
} |
|---|
| 190 |
} |
|---|
| 191 |
|
|---|
| 192 |
|
|---|
| 193 |
echo "Waiting ..."; |
|---|
| 194 |
for ($i = 5; $i > 0; $i--) { |
|---|
| 195 |
sleep(1); |
|---|
| 196 |
echo " $i ..."; |
|---|
| 197 |
} |
|---|
| 198 |
echo "\n"; |
|---|
| 199 |
|
|---|
| 200 |
|
|---|
| 201 |
foreach ($test_queue as $test) { |
|---|
| 202 |
echo "Test: {$test['url']}\n"; |
|---|
| 203 |
$result = run_test($test_url.$test['url'], $test['cache'], $test['encode']); |
|---|
| 204 |
echo "\t cached: ".$result['cache']."\n"; |
|---|
| 205 |
echo "\t encoded: ".$result['encoded']."\n"; |
|---|
| 206 |
} |
|---|
| 207 |
} |
|---|
| 208 |
|
|---|
| 209 |
|
|---|
| 210 |
|
|---|
| 211 |
$options = ''; |
|---|
| 212 |
$command = ''; |
|---|
| 213 |
|
|---|
| 214 |
|
|---|
| 215 |
if ($_SERVER['argc'] > 1) { |
|---|
| 216 |
$arguments = $_SERVER['argv']; |
|---|
| 217 |
unset($arguments[0]); |
|---|
| 218 |
|
|---|
| 219 |
foreach ($arguments as $arg) { |
|---|
| 220 |
if (strlen($arg) > 2 && $arg{0} == '-' && $arg{1} == '-') { |
|---|
| 221 |
if (strstr($arg, '=')) { |
|---|
| 222 |
$arr = explode('=', $arg); |
|---|
| 223 |
$options[substr($arr[0], 2)] = $arr[1]; |
|---|
| 224 |
} else { |
|---|
| 225 |
$options[substr($arg, 2)] = true; |
|---|
| 226 |
} |
|---|
| 227 |
} else { |
|---|
| 228 |
$command[] = $arg; |
|---|
| 229 |
} |
|---|
| 230 |
} |
|---|
| 231 |
} |
|---|
| 232 |
|
|---|
| 233 |
|
|---|
| 234 |
if (isset($options['help'])) { |
|---|
| 235 |
show_help(); |
|---|
| 236 |
} |
|---|
| 237 |
|
|---|
| 238 |
if (!isset($command[0])) { |
|---|
| 239 |
show_help(); |
|---|
| 240 |
} |
|---|
| 241 |
|
|---|
| 242 |
switch ($command[0]) { |
|---|
| 243 |
case 'list': |
|---|
| 244 |
list_sets(); |
|---|
| 245 |
break; |
|---|
| 246 |
|
|---|
| 247 |
case 'clean': |
|---|
| 248 |
|
|---|
| 249 |
break; |
|---|
| 250 |
|
|---|
| 251 |
case 'run': |
|---|
| 252 |
if (!isset($command[1])) { |
|---|
| 253 |
die("run requires a test set to run!\n"); |
|---|
| 254 |
} |
|---|
| 255 |
run_set($command[1], isset($options['nocache']) ? true:false, isset($options['noenc']) ? true:false); |
|---|
| 256 |
break; |
|---|
| 257 |
} |
|---|
| 258 |
|
|---|
| 259 |
?> |
|---|
| 260 |
|
|---|