mirror of
https://gerrit.wikimedia.org/r/mediawiki/extensions/Scribunto
synced 2024-11-30 19:14:22 +00:00
b68cae904a
* Added tests for the engine classes. * Added some tests that run under Lua. * In the chunk names, fixed truncation of module names at 60 bytes by using an "=" prefix instead of @. * Fixed a bug in mw.clone() which was causing the metatable to be set on the source table instead of the destination. * Put restricted setfenv/getfenv in the cloned environment rather than the base environment, they work better that way. * In setfenv(), check for getfenv() == nil, since that's what our own restricted getfenv returns. * Fixed getfenv() handling of numeric arguments: add one where appropriate. Change-Id: I2b356fd65a3fcb348c4e99a3a4267408fb995739
51 lines
1.6 KiB
PHP
51 lines
1.6 KiB
PHP
<?php
|
|
|
|
if ( php_sapi_name() !== 'cli' ) exit;
|
|
require_once( dirname( __FILE__ ) .'/../LuaCommon/LuaInterpreterTest.php' );
|
|
|
|
class Scribunto_LuaStandaloneInterpreterTest extends Scribunto_LuaInterpreterTest {
|
|
var $stdOpts = array(
|
|
'errorFile' => null,
|
|
'luaPath' => null,
|
|
'memoryLimit' => 50000000,
|
|
'cpuLimit' => 30,
|
|
);
|
|
|
|
function getVsize( $pid ) {
|
|
$size = wfShellExec( wfEscapeShellArg( 'ps', '-p', $pid, '-o', 'vsz', '--no-headers' ) );
|
|
return $size * 1024;
|
|
}
|
|
|
|
function newInterpreter( $opts = array() ) {
|
|
$opts = $opts + $this->stdOpts;
|
|
$engine = new Scribunto_LuaStandaloneEngine( $this->stdOpts );
|
|
return new Scribunto_LuaStandaloneInterpreter( $engine, $opts );
|
|
}
|
|
|
|
function testGetStatus() {
|
|
$startTime = microtime( true );
|
|
if ( php_uname( 's' ) !== 'Linux' ) {
|
|
$this->markTestSkipped( "getStatus() not supported on platforms other than Linux" );
|
|
return;
|
|
}
|
|
$interpreter = $this->newInterpreter();
|
|
$status = $interpreter->getStatus();
|
|
$pid = $status['pid'];
|
|
$this->assertInternalType( 'integer', $status['pid'] );
|
|
$initialVsize = $this->getVsize( $pid );
|
|
$this->assertGreaterThan( 0, $initialVsize, 'Initial vsize' );
|
|
|
|
$chunk = $this->getBusyLoop( $interpreter );
|
|
|
|
while ( microtime( true ) - $startTime < 1 ) {
|
|
$interpreter->callFunction( $chunk, 100 );
|
|
}
|
|
$status = $interpreter->getStatus();
|
|
$vsize = $this->getVsize( $pid );
|
|
$time = $status['time'] / $interpreter->engine->getClockTick();
|
|
$this->assertGreaterThan( 0.1, $time, 'getStatus() time usage' );
|
|
$this->assertLessThan( 1.5, $time, 'getStatus() time usage' );
|
|
$this->assertEquals( $vsize, $status['vsize'], 'vsize', $vsize * 0.1 );
|
|
}
|
|
}
|