Anomie has uploaded a new change for review.
https://gerrit.wikimedia.org/r/270023
Change subject: Waste CPU cycles, not wall clock time
......................................................................
Waste CPU cycles, not wall clock time
Apparently microtime is a bit unreliable for this test for some reason,
so let's use getrusage() to measure actual CPU time instead.
Bug: T125045
Change-Id: Ia1ab6b043b99abb4fc6c2989ad09a24d97dd09c3
---
M tests/engines/LuaSandbox/SandboxTest.php
1 file changed, 20 insertions(+), 5 deletions(-)
git pull ssh://gerrit.wikimedia.org:29418/mediawiki/extensions/Scribunto
refs/changes/23/270023/1
diff --git a/tests/engines/LuaSandbox/SandboxTest.php
b/tests/engines/LuaSandbox/SandboxTest.php
index a5d2ba6..4c70413 100644
--- a/tests/engines/LuaSandbox/SandboxTest.php
+++ b/tests/engines/LuaSandbox/SandboxTest.php
@@ -14,6 +14,16 @@
}
public function testArgumentParsingTime() {
+ if ( !function_exists( 'getrusage' ) ) {
+ $this->markTestSkipped( "getrusage is not available" );
+ }
+
+ if ( defined( 'HHVM_VERSION' ) && PHP_OS === 'Linux' ) {
+ $who = 2; // RUSAGE_THREAD
+ } else {
+ $who = 0; // RUSAGE_SELF
+ }
+
$engine = $this->getEngine();
if ( !is_callable( array( $engine->getInterpreter()->sandbox,
'pauseUsageTimer' ) ) ) {
$this->markTestSkipped( "LuaSandbox::pauseUsageTimer is
not available" );
@@ -23,11 +33,16 @@
$pp = $parser->getPreprocessor();
$frame = $pp->newFrame();
- $parser->setHook( 'scribuntodelay', function () {
- $t = microtime( 1 ) + 0.5;
- while ( microtime( 1 ) < $t ) {
- # Waste CPU cycles
- }
+ $parser->setHook( 'scribuntodelay', function () use ( $who ) {
+ $ru = getrusage( $who );
+ $endTime = $ru['ru_utime.tv_sec'] +
$ru['ru_utime.tv_usec'] / 1e6 + 0.5;
+
+ // Waste CPU cycles
+ do {
+ $ru = getrusage( $who );
+ $t = $ru['ru_utime.tv_sec'] +
$ru['ru_utime.tv_usec'] / 1e6;
+ } while ( $t < $endTime );
+
return "ok";
} );
$this->extraModules['Module:TestArgumentParsingTime'] = '
--
To view, visit https://gerrit.wikimedia.org/r/270023
To unsubscribe, visit https://gerrit.wikimedia.org/r/settings
Gerrit-MessageType: newchange
Gerrit-Change-Id: Ia1ab6b043b99abb4fc6c2989ad09a24d97dd09c3
Gerrit-PatchSet: 1
Gerrit-Project: mediawiki/extensions/Scribunto
Gerrit-Branch: master
Gerrit-Owner: Anomie <[email protected]>
_______________________________________________
MediaWiki-commits mailing list
[email protected]
https://lists.wikimedia.org/mailman/listinfo/mediawiki-commits