File: runtime_compile_time_offset_access.phpt

package info (click to toggle)
php8.4 8.4.16-1
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid
  • size: 211,276 kB
  • sloc: ansic: 1,176,142; php: 35,419; sh: 11,964; cpp: 7,208; pascal: 4,951; javascript: 3,091; asm: 2,817; yacc: 2,411; makefile: 696; xml: 446; python: 301; awk: 148
file content (82 lines) | stat: -rw-r--r-- 2,634 bytes parent folder | download | duplicates (2)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
--TEST--
Test binary operands exposing the same behavior at compile as at run time
--INI--
memory_limit=256M
opcache.file_update_protection=1
--SKIPIF--
<?php
if (getenv("SKIP_SLOW_TESTS")) die('skip slow test');
?>
--FILE--
<?php

require_once __DIR__ . DIRECTORY_SEPARATOR . 'test_offset_helpers.inc';

function makeTestFile($container, $offset) {
    $offset_p = zend_test_var_export($offset);
    $container_p = zend_test_var_export($container);
    $fileContent = file_get_contents(__DIR__ . '/test_variable_offsets.inc');
    $fileContent = str_replace('$dimension', $offset_p, $fileContent);
    return str_replace('//$container var declaration in const generated file', "\$container = $container_p;", $fileContent);
}

function normalize_output(string $output, string $filename): string {
    $output = str_replace(
        [$filename],
        ['%s'],
        $output
    );

    $output = preg_replace('/\)#\d+ \(/', ')#99 (', $output);

    return $output;
}

$const_dim_filename = __DIR__ . DIRECTORY_SEPARATOR . 'compare_binary_offsets_temp.php';

ob_start();
foreach ($containers as $container_orig) {
    foreach ($offsets as $offset) {
        $error = zend_test_var_export($container_orig) . '[' . zend_test_var_export($offset) . '] has different outputs' . "\n";
        file_put_contents($const_dim_filename, makeTestFile($container_orig, $offset));

        include $const_dim_filename;
        $constOutput = ob_get_contents();
        ob_clean();
        $constOutput = normalize_output($constOutput, $const_dim_filename);

        $dimension = $offset;
        $container = $container_orig;
        if (is_object($container_orig)) {
            $container = clone $container_orig;
        }
        include $var_dim_filename;
        $varOutput = ob_get_contents();
        ob_clean();
        $varOutput = normalize_output($varOutput, $var_dim_filename);

        if ($constOutput !== $varOutput) {
            file_put_contents(__DIR__ . DIRECTORY_SEPARATOR . "debug_{$failuresNb}_const.txt", $constOutput);
            file_put_contents(__DIR__ . DIRECTORY_SEPARATOR . "debug_{$failuresNb}_var.txt", $varOutput);
            file_put_contents(__DIR__ . DIRECTORY_SEPARATOR . "debug_{$failuresNb}_test_case.txt", makeTestFile($container_orig, $offset));
            ++$failuresNb;
            $failures[] = $error;
        }
        ++$testCasesTotal;
    }
}
ob_end_clean();

echo "Executed tests\n";
if ($failures !== []) {
    echo "Failures:\n" . implode($failures);
}

?>
--CLEAN--
<?php
$fl = __DIR__ . DIRECTORY_SEPARATOR . 'compare_binary_offsets_temp.php';
@unlink($fl);
?>
--EXPECT--
Executed tests