mirror of
https://gerrit.wikimedia.org/r/mediawiki/extensions/Scribunto
synced 2024-11-27 01:30:00 +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
29 lines
853 B
PHP
29 lines
853 B
PHP
<?php
|
|
|
|
if ( php_sapi_name() !== 'cli' ) exit;
|
|
require_once( dirname( __FILE__ ) .'/../LuaCommon/LuaInterpreterTest.php' );
|
|
|
|
|
|
class Scribunto_LuaSandboxInterpreterTest extends Scribunto_LuaInterpreterTest {
|
|
var $stdOpts = array(
|
|
'memoryLimit' => 50000000,
|
|
'cpuLimit' => 30,
|
|
);
|
|
|
|
function newInterpreter( $opts = array() ) {
|
|
$opts = $opts + $this->stdOpts;
|
|
$engine = new Scribunto_LuaSandboxEngine( $this->stdOpts );
|
|
return new Scribunto_LuaSandboxInterpreter( $engine, $opts );
|
|
}
|
|
|
|
function testGetMemoryUsage() {
|
|
$interpreter = $this->newInterpreter();
|
|
$chunk = $interpreter->loadString( 's = string.rep("x", 1000000)', 'mem' );
|
|
$interpreter->callFunction( $chunk );
|
|
$mem = $interpreter->getMemoryUsage();
|
|
$this->assertGreaterThan( 1000000, $mem, 'memory usage' );
|
|
$this->assertLessThan( 10000000, $mem, 'memory usage' );
|
|
}
|
|
}
|
|
|