php-compiler icon indicating copy to clipboard operation
php-compiler copied to clipboard

Randomly failing string tests

Open PurHur opened this issue 6 years ago • 4 comments

On my windows dev setup (standard git bash+docker) i get random crashes in the string tests... always the same but only in 10% of the runs.

https://gist.github.com/PurHur/4d4bb8548d4adfd5afa093fffc6c8a4b

Is that a problem at all? Or a cygwin/windows thing? I never saw that on debian machines.

PurHur avatar May 05 '19 12:05 PurHur

Nothing was changed between the runs.

Compiling /compiler/lib/JIT.pre
Compiling /compiler/lib/JIT/Helper.pre
Compiling /compiler/lib/JIT/Builtin/Internal.pre
Compiling /compiler/lib/JIT/Builtin/MemoryManager.pre
Compiling /compiler/lib/JIT/Builtin/Output.pre
Compiling /compiler/lib/JIT/Builtin/Refcount.pre
Compiling /compiler/lib/JIT/Builtin/MemoryManager/Native.pre
Compiling /compiler/lib/JIT/Builtin/MemoryManager/PHP.pre
Compiling /compiler/lib/JIT/Builtin/Type/String_.pre
Compiling /compiler/lib/JIT/Builtin/Type/Value.pre
Compiling /compiler/lib/JIT/Call/Native.pre
Updating demo files
docker run -v /c/Users/purhur/php-compiler:/compiler ircmaxell/php-compiler:16.0
4-dev vendor/bin/phpunit
PHPUnit 8.2-g21ee615 by Sebastian Bergmann and contributors.

....................F.......................................      60 / 60 (100%)

Time: 1.07 minutes, Memory: 6.00 MB

There was 1 failure:

1) PHPCompiler\JITTest::testCases with data set #20 ('Basic String Operations',
'<?php\r\n$a = "hello";\r\n$b ...";\r\n', array('Basic String Operations\r\n', '
<?php\r\n$a = "hello";\r\n$b ...";\r\n', 'hello\r\nworld\r\nhello world\r\n'))
Failed asserting that two strings are equal.
--- Expected
+++ Actual
@@ @@
-'hello\n
-world\n
-hello world'
+''

/compiler/test/BaseTest.php:164
/compiler/test/BaseTest.php:145

FAILURES!
Tests: 60, Assertions: 88, Failures: 1.
make: *** [Makefile:70: test] Error 1

purhur@purhur-PC MINGW64 ~/php-compiler (test/str_repeat)
$ make test
docker run -v /c/Users/purhur/php-compiler:/compiler ircmaxell/php-compiler:16.0
4-dev php script/rebuild.php onlyChanged
Compiling /compiler/ext/types/strlen.pre
Compiling /compiler/lib/JIT.pre
Compiling /compiler/lib/JIT/Helper.pre
Compiling /compiler/lib/JIT/Builtin/Internal.pre
Compiling /compiler/lib/JIT/Builtin/MemoryManager.pre
Compiling /compiler/lib/JIT/Builtin/Output.pre
Compiling /compiler/lib/JIT/Builtin/Refcount.pre
Compiling /compiler/lib/JIT/Builtin/MemoryManager/Native.pre
Compiling /compiler/lib/JIT/Builtin/MemoryManager/PHP.pre
Compiling /compiler/lib/JIT/Builtin/Type/String_.pre
Compiling /compiler/lib/JIT/Builtin/Type/Value.pre
Compiling /compiler/lib/JIT/Call/Native.pre
Updating demo files
docker run -v /c/Users/purhur/php-compiler:/compiler ircmaxell/php-compiler:16.0
4-dev vendor/bin/phpunit
PHPUnit 8.2-g21ee615 by Sebastian Bergmann and contributors.

............................................................      60 / 60 (100%)

Time: 1.05 minutes, Memory: 6.00 MB

OK (60 tests, 88 assertions)

PurHur avatar May 05 '19 12:05 PurHur

There exists a memory corruption bug in the string code somewhere. What's happening is every once in a while a segfault is issued (though not often) and when it is the test fails with no output.

ircmaxell avatar May 06 '19 09:05 ircmaxell

Thanks for explaining. I encountered this only on this machine... If a wonder comes by i fix it :P

PurHur avatar May 06 '19 15:05 PurHur

Code like this should be able to reliably segfault (or at least it does for me):

<?php

$test = 'a';

for ($i = 0; $i < 1000; $i++) {
    $test = $test . 'a';
}
echo $test;

echo "\n";

ircmaxell avatar May 06 '19 15:05 ircmaxell