Added tests and fixed bugs
* Added unit tests for the two Lua interpreter classes
* Fixed a bug in checkType()
* Have Scribunto_LuaSandboxInterpreter throw an exception on construct
when the extension doesn't exist, to match the standalone behaviour.
* In Scribunto_LuaSandboxInterpreter, removed debugging statements
accidentally left in.
* Convert LuaSandboxTimeoutError to the appropriate common error
message.
* Moved the option munging from the sandbox engine to the interpreter,
so that the interpreter can be unit tested separately.
* Use /bin/sh instead of bash for lua_ulimit.sh, since dash is smaller
and still supports ulimit.
* Use exec to run the lua binary, so that the vsize of the shell doesn't
add to the memory limit.
* Added a quit function to the standalone interpreter. Unused at present.
* Don't add a comma after the last element of a table in a Lua
expression.
* Make the SIGXCPU detection work: proc_open() runs the command via a
shell, which reports signals in the child via the exit status, so
proc_get_status() will never return a valid termsig element.
* In MWServer:call(), fixed a bug causing the return values to be
wrapped in an array.
* Fixed a misunderstanding of what select() does.
* In MWServer:getStatus(), fixed indexes so that vsize will be correct.
Removed RSS, since it wasn't used anyway and turns out to be measured
in multiples of the page size, and I couldn't be bothered trying to
fetch that from getconf. Return the PID and vsize as numbers rather
than strings.
* Added a simple table dump feature to MWServer:debug().
* Fixed brackets in MWServer:tostring().
* Added missing Linux 32-bit binary.
Change-Id: Ibf5f4656b1c0a9f81287d363184c3fe9d2abdafd
2012-04-16 04:41:08 +00:00
|
|
|
<?php
|
|
|
|
|
2012-04-19 07:40:56 +00:00
|
|
|
if ( php_sapi_name() !== 'cli' ) exit;
|
|
|
|
require_once( dirname( __FILE__ ) .'/../LuaCommon/LuaInterpreterTest.php' );
|
|
|
|
|
|
|
|
class Scribunto_LuaStandaloneInterpreterTest extends Scribunto_LuaInterpreterTest {
|
Added tests and fixed bugs
* Added unit tests for the two Lua interpreter classes
* Fixed a bug in checkType()
* Have Scribunto_LuaSandboxInterpreter throw an exception on construct
when the extension doesn't exist, to match the standalone behaviour.
* In Scribunto_LuaSandboxInterpreter, removed debugging statements
accidentally left in.
* Convert LuaSandboxTimeoutError to the appropriate common error
message.
* Moved the option munging from the sandbox engine to the interpreter,
so that the interpreter can be unit tested separately.
* Use /bin/sh instead of bash for lua_ulimit.sh, since dash is smaller
and still supports ulimit.
* Use exec to run the lua binary, so that the vsize of the shell doesn't
add to the memory limit.
* Added a quit function to the standalone interpreter. Unused at present.
* Don't add a comma after the last element of a table in a Lua
expression.
* Make the SIGXCPU detection work: proc_open() runs the command via a
shell, which reports signals in the child via the exit status, so
proc_get_status() will never return a valid termsig element.
* In MWServer:call(), fixed a bug causing the return values to be
wrapped in an array.
* Fixed a misunderstanding of what select() does.
* In MWServer:getStatus(), fixed indexes so that vsize will be correct.
Removed RSS, since it wasn't used anyway and turns out to be measured
in multiples of the page size, and I couldn't be bothered trying to
fetch that from getconf. Return the PID and vsize as numbers rather
than strings.
* Added a simple table dump feature to MWServer:debug().
* Fixed brackets in MWServer:tostring().
* Added missing Linux 32-bit binary.
Change-Id: Ibf5f4656b1c0a9f81287d363184c3fe9d2abdafd
2012-04-16 04:41:08 +00:00
|
|
|
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 );
|
|
|
|
}
|
|
|
|
}
|