|
| 1 | +--TEST-- |
| 2 | +Test binary operands exposing the same behavior at compile as at run time |
| 3 | +--INI-- |
| 4 | +memory_limit=256M |
| 5 | +--SKIPIF-- |
| 6 | +<?php |
| 7 | +//if (getenv("SKIP_SLOW_TESTS")) die('skip slow test'); |
| 8 | +?> |
| 9 | +--XFAIL-- |
| 10 | +JIT includes outdated temporary test file |
| 11 | +--FILE-- |
| 12 | +<?php |
| 13 | + |
| 14 | +$containers = [ |
| 15 | + null, |
| 16 | + false, |
| 17 | + true, |
| 18 | + '10', |
| 19 | + '25.5', |
| 20 | + 'string', |
| 21 | + [], |
| 22 | + STDERR, |
| 23 | + new stdClass(), |
| 24 | +]; |
| 25 | + |
| 26 | +$offsets = [ |
| 27 | + null, |
| 28 | + false, |
| 29 | + true, |
| 30 | + 4, |
| 31 | + 5.5, |
| 32 | + 6.0, |
| 33 | + //PHP_INT_MAX, |
| 34 | + //PHP_INT_MIN, |
| 35 | + PHP_INT_MAX * 2, |
| 36 | + PHP_INT_MIN * 2, |
| 37 | + INF, |
| 38 | + NAN, |
| 39 | + 'string', |
| 40 | + '7', |
| 41 | + '8.5', |
| 42 | + '9.0', |
| 43 | + '2e3', |
| 44 | + '20a', |
| 45 | + ' 20', |
| 46 | + '20 ', |
| 47 | + //"9179769313486231570814527423731704356798070567525844996598917476803157260780028538760589558632766878171540458953514382464234321326889464182768467546703537516986049910576551282076245490090389328944075868508455133942304583236903222948165808559332123348274797826204144723168738177180919299881250404026184124858368", |
| 48 | + //"-9179769313486231570814527423731704356798070567525844996598917476803157260780028538760589558632766878171540458953514382464234321326889464182768467546703537516986049910576551282076245490090389328944075868508455133942304583236903222948165808559332123348274797826204144723168738177180919299881250404026184124858368", |
| 49 | + "0x14", |
| 50 | + (string) PHP_INT_MAX * 2, |
| 51 | + (string) PHP_INT_MIN * 2, |
| 52 | +]; |
| 53 | + |
| 54 | +function makeContainer($container) { |
| 55 | + if (is_array($container)) { |
| 56 | + return "[]"; |
| 57 | + } |
| 58 | + if (is_resource($container)) { |
| 59 | + return "STDERR"; |
| 60 | + } |
| 61 | + if ($container instanceof stdClass) { |
| 62 | + return "new stdClass()"; |
| 63 | + } |
| 64 | + return var_export($container, true); |
| 65 | +} |
| 66 | +function makeOffset($offset) { |
| 67 | + if ($offset === PHP_INT_MIN) { |
| 68 | + return "PHP_INT_MIN"; |
| 69 | + } |
| 70 | + if ($offset === PHP_INT_MAX) { |
| 71 | + return "PHP_INT_MAX"; |
| 72 | + } |
| 73 | + return var_export($offset, true); |
| 74 | +} |
| 75 | + |
| 76 | +function makeTestFile($container, $offset) { |
| 77 | + $offset_p = makeOffset($offset); |
| 78 | + $container_p = makeContainer($container); |
| 79 | + $fileContent = <<<test |
| 80 | +<?php |
| 81 | +
|
| 82 | +\$container = $container_p; |
| 83 | +
|
| 84 | +// Read before write |
| 85 | +try { |
| 86 | + echo "Read before write:\\n"; |
| 87 | + var_dump(\$container[$offset_p]); |
| 88 | +} catch (\Throwable \$e) { |
| 89 | + echo \$e->getMessage(), "\\n"; |
| 90 | +} |
| 91 | +// Write |
| 92 | +try { |
| 93 | + echo "Write:\\n"; |
| 94 | + \$container[$offset_p] = 'v'; |
| 95 | +} catch (\Throwable \$e) { |
| 96 | + echo \$e->getMessage(), "\\n"; |
| 97 | +} |
| 98 | +// Read |
| 99 | +try { |
| 100 | + echo "Read:\\n"; |
| 101 | + var_dump(\$container[$offset_p]); |
| 102 | +} catch (\Throwable \$e) { |
| 103 | + echo \$e->getMessage(), "\\n"; |
| 104 | +} |
| 105 | +// Read-Write |
| 106 | +try { |
| 107 | + echo "Read-Write:\\n"; |
| 108 | + \$container[$offset_p] .= 'append'; |
| 109 | +} catch (\Throwable \$e) { |
| 110 | + echo \$e->getMessage(), "\\n"; |
| 111 | +} |
| 112 | +// Is |
| 113 | +try { |
| 114 | + echo "isset():\\n"; |
| 115 | + var_dump(isset(\$container[$offset_p])); |
| 116 | +} catch (\Throwable \$e) { |
| 117 | + echo \$e->getMessage(), "\\n"; |
| 118 | +} |
| 119 | +try { |
| 120 | + echo "empty():\\n"; |
| 121 | + var_dump(empty(\$container[$offset_p])); |
| 122 | +} catch (\Throwable \$e) { |
| 123 | + echo \$e->getMessage(), "\\n"; |
| 124 | +} |
| 125 | +try { |
| 126 | + echo "Coalesce():\\n"; |
| 127 | + var_dump(\$container[$offset_p] ?? 'default'); |
| 128 | +} catch (\Throwable \$e) { |
| 129 | + echo \$e->getMessage(), "\\n"; |
| 130 | +} |
| 131 | +test; |
| 132 | + return $fileContent; |
| 133 | +} |
| 134 | + |
| 135 | +$filename = __DIR__ . DIRECTORY_SEPARATOR . 'compare_binary_offsets_temp.php'; |
| 136 | + |
| 137 | +$failures = []; |
| 138 | +$testCasesTotal = 0; |
| 139 | + |
| 140 | +ob_start(); |
| 141 | +foreach ($containers as $container_orig) { |
| 142 | + foreach ($offsets as $offset) { |
| 143 | + $error = makeContainer($container_orig) . '[' . makeOffset($offset) . '] has different outputs' . "\n"; |
| 144 | + file_put_contents($filename, makeTestFile($container_orig, $offset)); |
| 145 | + |
| 146 | + include $filename; |
| 147 | + $constOutput = ob_get_contents(); |
| 148 | + ob_clean(); |
| 149 | + $constOutput = str_replace( |
| 150 | + [$filename], |
| 151 | + ['%s'], |
| 152 | + $constOutput |
| 153 | + ); |
| 154 | + |
| 155 | + $dimension = $offset; |
| 156 | + $container = $container_orig; |
| 157 | + $var_filename = __DIR__ . DIRECTORY_SEPARATOR . 'test_variable_offsets.inc'; |
| 158 | + include $var_filename; |
| 159 | + $varOutput = ob_get_contents(); |
| 160 | + ob_clean(); |
| 161 | + $varOutput = str_replace( |
| 162 | + [$var_filename], |
| 163 | + ['%s'], |
| 164 | + $varOutput |
| 165 | + ); |
| 166 | + |
| 167 | + if ($constOutput !== $varOutput) { |
| 168 | + file_put_contents(__DIR__ . DIRECTORY_SEPARATOR . 'debug_const.txt', $constOutput); |
| 169 | + file_put_contents(__DIR__ . DIRECTORY_SEPARATOR . 'debug_var.txt', $varOutput); |
| 170 | + $failures[] = $error; |
| 171 | + } |
| 172 | + ++$testCasesTotal; |
| 173 | + } |
| 174 | +} |
| 175 | +ob_end_clean(); |
| 176 | + |
| 177 | +echo "Executed $testCasesTotal tests\n"; |
| 178 | +if ($failures !== []) { |
| 179 | + echo "Failures:\n" . implode($failures); |
| 180 | +} |
| 181 | + |
| 182 | +?> |
| 183 | +--CLEAN-- |
| 184 | +<?php |
| 185 | +$fl = __DIR__ . DIRECTORY_SEPARATOR . 'compare_binary_operands_temp.php'; |
| 186 | +@unlink($fl); |
| 187 | +?> |
| 188 | +--EXPECT-- |
| 189 | +Executed 189 tests |
0 commit comments