mediawiki-extensions-Scribunto/tests/engines/LuaSandbox/LuaSandboxInterpreterTest.php
Ori Livneh b2d340bf71 (Bug 37957) php_sapi_name() => PHP_SAPI
Change-Id: I8ccb645fa11f001fc1ca1c95f4e9476f84870714
2013-02-04 20:27:01 -08:00

29 lines
850 B
PHP

<?php
if ( PHP_SAPI !== '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' );
}
}