Skip to content

run-tests: capture Windows-specific error exit codes #6722

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
wants to merge 2 commits into from
Closed

run-tests: capture Windows-specific error exit codes #6722

wants to merge 2 commits into from

Conversation

dktapps
Copy link
Contributor

@dktapps dktapps commented Feb 23, 2021

the lack of such a check leads to false-passes of tests on Windows, because if a segfault occurs, there's no indication from run-tests. This means that a test which crashed after emitting all of its expected output (or not producing any output) would still be seen as passed, even though it actually crashed.

I discovered this problem because of bad tests in an extension I maintain which had empty --EXPECT-- sections, which led to segfaulting tests passing.

This PR makes run-tests capture ERROR severity statuses, as described here: https://docs.microsoft.com/en-us/openspecs/windows_protocols/ms-erref/87fba13e-bf06-450e-83b1-9241dc81e781

the lack of such a check leads to false-passes of tests on Windows which expect no output, but produce a segfault or similar issue.
I discovered this a while ago due to bad tests in an extension I maintain.
@nikic
Copy link
Member

nikic commented Feb 23, 2021

There are two test failures on Appveyor, with Termsig -1 and -2.

@dktapps
Copy link
Contributor Author

dktapps commented Feb 23, 2021

I had a feeling that it might show up some issues in php-src own tests.

My intent was only to capture 0xC error codes like 0xC0000005 since those are the ones produced for segfault, illegal instruction etc. I'm not sure if these tests are problematic or not.

The broken tests are these:
ext\opcache\tests\log_verbosity_bug.phpt (intended to crash, shouldn't be reported as failure)
sapi\tests\test005.phpt (failure reason not obvious)

this is sufficient to capture segfaults and such, but won't capture signals produced by TerminateProcess and similar.
@dktapps
Copy link
Contributor Author

dktapps commented Feb 23, 2021

Some heap corruption errors are showing up on the second run. I won't take blame for those. 😅

@@ -1188,6 +1188,9 @@ function system_with_timeout($commandline, $env = null, $stdin = null, $captureS
}
if ($stat["exitcode"] > 128 && $stat["exitcode"] < 160) {
$data .= "\nTermsig=" . ($stat["exitcode"] - 128) . "\n";
} else if (defined('PHP_WINDOWS_VERSION_MAJOR') && (($stat["exitcode"] >> 28) & 0b1111) === 0b1100) {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Use IS_WINDOWS.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It's not available prior to 8.0.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It's defined above :)

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

ctrl+f here: https://github.com/php/php-src/blob/992960e38eca2fd46601a6f286ef1908ca802e84/run-tests.php
This PR targets 7.3, IS_WINDOWS is not defined here. It's only defined in 8.0+'s version of run-tests.php: https://github.com/php/php-src/blob/PHP-8.0/run-tests.php#L155

@nikic
Copy link
Member

nikic commented Feb 24, 2021

Maybe @cmb69 can take a look at the failing ext\dba\tests\bug65708.phpt test?

This change should probably target PHP-7.4.

@cmb69
Copy link
Member

cmb69 commented Feb 24, 2021

I have been able to get a segfault (not the heap corruption reported by AppVeyor) when running ext\dba\tests\bug65708.php, but only on rare occassions, and only with PHP-7.3. That looks like a UAF (backtrace). I'm going to rebuild (for reference the fail happend with https://ci.appveyor.com/project/php/php-src/builds/37917434).

This change should probably target PHP-7.4.

ACK. While I very much appreciate to catch segfaults in tests on Windows, I think this is more suitable for 7.4+. Since the patch applies cleanly there, there is no need to rebase/change the target branch, though.

Thanks for the PR, Dylan!

@cmb69
Copy link
Member

cmb69 commented Feb 25, 2021

This time AppVeyor passed, so I think it's best to merge this PR, and to see whether the issue reproduces.

@php-pulls php-pulls closed this in a480bf8 Feb 25, 2021
@cmb69
Copy link
Member

cmb69 commented Mar 1, 2021

This time AppVeyor passed, so I think it's best to merge this PR, and to see whether the issue reproduces.

Just for the record, it just reproduced for https://ci.appveyor.com/project/php/php-src/builds/38000695 (this time in the 2nd job). There appears to be something wrong, but it is not related to this PR.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants