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
|
|
|
|
|
2018-01-10 14:16:00 +00:00
|
|
|
if ( !wfIsCLI() ) {
|
2016-05-17 14:52:05 +00:00
|
|
|
exit;
|
|
|
|
}
|
|
|
|
|
|
|
|
require_once __DIR__ . '/../LuaCommon/LuaInterpreterTest.php';
|
2012-04-19 07:40:56 +00:00
|
|
|
|
2013-11-01 15:53:56 +00:00
|
|
|
/**
|
|
|
|
* @group Lua
|
|
|
|
* @group LuaStandalone
|
2018-05-27 00:50:43 +00:00
|
|
|
* @covers Scribunto_LuaStandaloneInterpreter
|
2013-11-01 15:53:56 +00:00
|
|
|
*/
|
2012-04-19 07:40:56 +00:00
|
|
|
class Scribunto_LuaStandaloneInterpreterTest extends Scribunto_LuaInterpreterTest {
|
2017-06-15 17:19:00 +00:00
|
|
|
public $stdOpts = [
|
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
|
|
|
'errorFile' => null,
|
|
|
|
'luaPath' => null,
|
|
|
|
'memoryLimit' => 50000000,
|
|
|
|
'cpuLimit' => 30,
|
2017-06-15 17:19:00 +00:00
|
|
|
];
|
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
|
|
|
|
2014-11-12 11:43:44 +00:00
|
|
|
private function getVsize( $pid ) {
|
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
|
|
|
$size = wfShellExec( wfEscapeShellArg( 'ps', '-p', $pid, '-o', 'vsz', '--no-headers' ) );
|
2018-02-02 05:08:32 +00:00
|
|
|
return trim( $size ) * 1024;
|
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
|
|
|
}
|
|
|
|
|
2017-06-15 17:19:00 +00:00
|
|
|
protected function newInterpreter( $opts = [] ) {
|
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
|
|
|
$opts = $opts + $this->stdOpts;
|
|
|
|
$engine = new Scribunto_LuaStandaloneEngine( $this->stdOpts );
|
|
|
|
return new Scribunto_LuaStandaloneInterpreter( $engine, $opts );
|
|
|
|
}
|
|
|
|
|
2017-02-06 19:55:24 +00:00
|
|
|
public function testIOErrorExit() {
|
|
|
|
$interpreter = $this->newInterpreter();
|
|
|
|
try {
|
|
|
|
$interpreter->testquit();
|
|
|
|
$this->fail( 'Expected exception not thrown' );
|
|
|
|
} catch ( ScribuntoException $ex ) {
|
|
|
|
$this->assertSame( 'scribunto-luastandalone-exited', $ex->getMessageName() );
|
|
|
|
$this->assertSame( [ '[UNKNOWN]', 42 ], $ex->messageArgs );
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
public function testIOErrorSignal() {
|
|
|
|
$interpreter = $this->newInterpreter();
|
|
|
|
try {
|
|
|
|
proc_terminate( $interpreter->proc, 15 );
|
|
|
|
// Some dummy protocol interaction to make it see the interpreter went away
|
|
|
|
$interpreter->loadString( 'return ...', 'test' );
|
|
|
|
$this->fail( 'Expected exception not thrown' );
|
|
|
|
} catch ( ScribuntoException $ex ) {
|
|
|
|
$this->assertSame( 'scribunto-luastandalone-signal', $ex->getMessageName() );
|
|
|
|
$this->assertSame( [ '[UNKNOWN]', 15 ], $ex->messageArgs );
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2014-11-12 11:43:44 +00:00
|
|
|
public function testGetStatus() {
|
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
|
|
|
$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 );
|
|
|
|
}
|
2013-11-01 00:04:12 +00:00
|
|
|
|
2018-02-06 21:03:11 +00:00
|
|
|
/**
|
|
|
|
* @dataProvider providePhpToLuaArrayKeyConversion
|
|
|
|
*/
|
|
|
|
public function testPhpToLuaArrayKeyConversion( $array, $expect ) {
|
|
|
|
$interpreter = $this->newInterpreter();
|
|
|
|
|
|
|
|
$ret = $interpreter->callFunction(
|
|
|
|
$interpreter->loadString(
|
|
|
|
'local t, r = ..., {}; for k, v in pairs( t ) do r[v] = type(k) end return r', 'test'
|
|
|
|
),
|
|
|
|
$array
|
|
|
|
);
|
|
|
|
ksort( $ret[0], SORT_STRING );
|
|
|
|
$this->assertSame( $expect, $ret[0] );
|
|
|
|
}
|
|
|
|
|
|
|
|
public static function providePhpToLuaArrayKeyConversion() {
|
|
|
|
if ( PHP_INT_MAX > 9007199254740992 ) {
|
|
|
|
$a = [
|
|
|
|
'9007199254740992' => 'max', '9007199254740993' => 'max+1',
|
|
|
|
'-9007199254740992' => 'min', '-9007199254740993' => 'min-1',
|
|
|
|
];
|
|
|
|
} else {
|
|
|
|
$a = [
|
|
|
|
'2147483647' => 'max', '2147483648' => 'max+1',
|
|
|
|
'-2147483648' => 'min', '-2147483649' => 'min-1',
|
|
|
|
];
|
|
|
|
}
|
|
|
|
|
|
|
|
return [
|
|
|
|
'simple integers' => [
|
|
|
|
[ -10 => 'minus ten', 0 => 'zero', 10 => 'ten' ],
|
|
|
|
[ 'minus ten' => 'number', 'ten' => 'number', 'zero' => 'number' ],
|
|
|
|
],
|
|
|
|
'maximal values' => [
|
|
|
|
$a,
|
|
|
|
[ 'max' => 'number', 'max+1' => 'string', 'min' => 'number', 'min-1' => 'string' ],
|
|
|
|
],
|
|
|
|
];
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* @dataProvider provideLuaToPhpArrayKeyConversion
|
|
|
|
*/
|
|
|
|
public function testLuaToPhpArrayKeyConversion( $lua, $expect ) {
|
|
|
|
if ( $expect instanceof Exception ) {
|
|
|
|
$this->setExpectedException( Scribunto_LuaError::class, $expect->getMessage() );
|
|
|
|
}
|
|
|
|
|
|
|
|
$interpreter = $this->newInterpreter();
|
|
|
|
$ret = $interpreter->callFunction(
|
|
|
|
$interpreter->loadString( "return { $lua }", 'test' )
|
|
|
|
);
|
|
|
|
if ( $expect instanceof Exception ) {
|
|
|
|
$this->fail( 'Expected exception not thrown' );
|
|
|
|
}
|
|
|
|
ksort( $ret[0], SORT_STRING );
|
|
|
|
$this->assertSame( $expect, $ret[0] );
|
|
|
|
}
|
|
|
|
|
|
|
|
public static function provideLuaToPhpArrayKeyConversion() {
|
|
|
|
if ( PHP_INT_MAX > 9007199254740992 ) {
|
|
|
|
$max = '9223372036854774784';
|
|
|
|
$max2 = '9223372036854775808';
|
|
|
|
$min = '-9223372036854775808';
|
|
|
|
$min2 = '-9223372036854775809';
|
|
|
|
} else {
|
|
|
|
$max = '2147483647';
|
|
|
|
$max2 = '2147483648';
|
|
|
|
$min = '-2147483648';
|
|
|
|
$min2 = '-2147483649';
|
|
|
|
}
|
|
|
|
|
|
|
|
return [
|
|
|
|
'simple integers' => [
|
|
|
|
'[-10] = "minus ten", [0] = "zero", [10] = "ten"',
|
|
|
|
[ -10 => 'minus ten', 0 => 'zero', 10 => 'ten' ],
|
|
|
|
],
|
|
|
|
'stringified integers' => [
|
|
|
|
'["-10"] = "minus ten", ["0"] = "zero", ["10"] = "ten"',
|
|
|
|
[ -10 => 'minus ten', 0 => 'zero', 10 => 'ten' ],
|
|
|
|
],
|
|
|
|
'maximal integers' => [
|
|
|
|
"['$max'] = 'near max', ['$max2'] = 'max+1', ['$min'] = 'min', ['$min2'] = 'min-1'",
|
|
|
|
[ $min => 'min', $min2 => 'min-1', $max => 'near max', $max2 => 'max+1' ],
|
|
|
|
],
|
|
|
|
'collision (0)' => [
|
|
|
|
'[0] = "number zero", ["0"] = "string zero"',
|
|
|
|
new Exception( 'Collision for array key 0 when passing data from Lua to PHP.' ),
|
|
|
|
],
|
|
|
|
'collision (float)' => [
|
|
|
|
'[1.5] = "number 1.5", ["1.5"] = "string 1.5"',
|
|
|
|
new Exception( 'Collision for array key 1.5 when passing data from Lua to PHP.' ),
|
|
|
|
],
|
|
|
|
'collision (inf)' => [
|
|
|
|
'[1/0] = "number inf", ["inf"] = "string inf"',
|
|
|
|
new Exception( 'Collision for array key inf when passing data from Lua to PHP.' ),
|
|
|
|
],
|
|
|
|
];
|
|
|
|
}
|
|
|
|
|
2014-11-12 11:43:44 +00:00
|
|
|
public function testFreeFunctions() {
|
2013-11-01 00:04:12 +00:00
|
|
|
$interpreter = $this->newInterpreter();
|
|
|
|
|
|
|
|
// Test #1: Make sure freeing actually works
|
|
|
|
$ret = $interpreter->callFunction(
|
|
|
|
$interpreter->loadString( 'return function() return "testFreeFunction #1" end', 'test' )
|
|
|
|
);
|
|
|
|
$id = $ret[0]->id;
|
|
|
|
$interpreter->cleanupLuaChunks();
|
|
|
|
$this->assertEquals(
|
2017-06-15 17:19:00 +00:00
|
|
|
[ 'testFreeFunction #1' ], $interpreter->callFunction( $ret[0] ),
|
2013-11-01 00:04:12 +00:00
|
|
|
'Test that function #1 was not freed while a reference exists'
|
|
|
|
);
|
|
|
|
$ret = null;
|
|
|
|
$interpreter->cleanupLuaChunks();
|
|
|
|
$testfunc = new Scribunto_LuaStandaloneInterpreterFunction( $interpreter->id, $id );
|
|
|
|
try {
|
|
|
|
$interpreter->callFunction( $testfunc );
|
|
|
|
$this->fail( "Expected exception because function #1 should have been freed" );
|
|
|
|
} catch ( Scribunto_LuaError $e ) {
|
|
|
|
$this->assertEquals(
|
2015-02-19 22:12:49 +00:00
|
|
|
"function id $id does not exist", $e->messageArgs[1],
|
2013-11-01 00:04:12 +00:00
|
|
|
'Testing for expected error when calling a freed function #1'
|
|
|
|
);
|
|
|
|
}
|
|
|
|
|
|
|
|
// Test #2: Make sure constructing a new copy of the function works
|
|
|
|
$ret = $interpreter->callFunction(
|
|
|
|
$interpreter->loadString( 'return function() return "testFreeFunction #2" end', 'test' )
|
|
|
|
);
|
|
|
|
$id = $ret[0]->id;
|
|
|
|
$func = new Scribunto_LuaStandaloneInterpreterFunction( $interpreter->id, $id );
|
|
|
|
$ret = null;
|
|
|
|
$interpreter->cleanupLuaChunks();
|
|
|
|
$this->assertEquals(
|
2017-06-15 17:19:00 +00:00
|
|
|
[ 'testFreeFunction #2' ], $interpreter->callFunction( $func ),
|
2013-11-01 00:04:12 +00:00
|
|
|
'Test that function #2 was not freed while a reference exists'
|
|
|
|
);
|
|
|
|
$func = null;
|
|
|
|
$interpreter->cleanupLuaChunks();
|
|
|
|
$testfunc = new Scribunto_LuaStandaloneInterpreterFunction( $interpreter->id, $id );
|
|
|
|
try {
|
|
|
|
$interpreter->callFunction( $testfunc );
|
|
|
|
$this->fail( "Expected exception because function #2 should have been freed" );
|
|
|
|
} catch ( Scribunto_LuaError $e ) {
|
|
|
|
$this->assertEquals(
|
2015-02-19 22:12:49 +00:00
|
|
|
"function id $id does not exist", $e->messageArgs[1],
|
2013-11-01 00:04:12 +00:00
|
|
|
'Testing for expected error when calling a freed function #2'
|
|
|
|
);
|
|
|
|
}
|
|
|
|
|
|
|
|
// Test #3: Make sure cloning works
|
|
|
|
$ret = $interpreter->callFunction(
|
|
|
|
$interpreter->loadString( 'return function() return "testFreeFunction #3" end', 'test' )
|
|
|
|
);
|
|
|
|
$id = $ret[0]->id;
|
|
|
|
$func = clone $ret[0];
|
|
|
|
$ret = null;
|
|
|
|
$interpreter->cleanupLuaChunks();
|
|
|
|
$this->assertEquals(
|
2017-06-15 17:19:00 +00:00
|
|
|
[ 'testFreeFunction #3' ], $interpreter->callFunction( $func ),
|
2013-11-01 00:04:12 +00:00
|
|
|
'Test that function #3 was not freed while a reference exists'
|
|
|
|
);
|
|
|
|
$func = null;
|
|
|
|
$interpreter->cleanupLuaChunks();
|
|
|
|
$testfunc = new Scribunto_LuaStandaloneInterpreterFunction( $interpreter->id, $id );
|
|
|
|
try {
|
|
|
|
$interpreter->callFunction( $testfunc );
|
|
|
|
$this->fail( "Expected exception because function #3 should have been freed" );
|
|
|
|
} catch ( Scribunto_LuaError $e ) {
|
|
|
|
$this->assertEquals(
|
2015-02-19 22:12:49 +00:00
|
|
|
"function id $id does not exist", $e->messageArgs[1],
|
2013-11-01 00:04:12 +00:00
|
|
|
'Testing for expected error when calling a freed function #3'
|
|
|
|
);
|
|
|
|
}
|
|
|
|
}
|
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
|
|
|
}
|