mediawiki-extensions-Scribunto/tests/engines/LuaSandbox/LuaSandboxInterpreterTest.php
Tim Starling c9c0aa6fce Peak memory usage, debug.traceback
* Use LuaSandbox::getPeakMemoryUsage() from r115086
* Fixed the debug.traceback function from da06273e, was nil

Change-Id: Iae4b195ffe25a522d4c37f9c8341e1d6ea3ae106
2012-04-30 16:37:41 +10:00

29 lines
857 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->getPeakMemoryUsage();
$this->assertGreaterThan( 1000000, $mem, 'memory usage' );
$this->assertLessThan( 10000000, $mem, 'memory usage' );
}
}