mediawiki-extensions-Scribunto/tests/phpunit/engines/LuaSandbox/LuaSandboxInterpreterTest.php
Kunal Mehta 76dbe5d804 Treat phpdbg as being run from the command-line
The two lualib/ustring generation scripts run independently of MediaWiki, so
the new wfIsCLI() isn't usable there.

Bug: T184043
Change-Id: I217657d12e16a7b76dc814be5fed03540c461e7c
2018-01-10 19:47:19 +05:30

35 lines
957 B
PHP

<?php
if ( !wfIsCLI() ) {
exit;
}
require_once __DIR__ . '/../LuaCommon/LuaInterpreterTest.php';
/**
* @group Lua
* @group LuaSandbox
*/
// @codingStandardsIgnoreLine Squiz.Classes.ValidClassName.NotCamelCaps
class Scribunto_LuaSandboxInterpreterTest extends Scribunto_LuaInterpreterTest {
public $stdOpts = [
'memoryLimit' => 50000000,
'cpuLimit' => 30,
];
protected function newInterpreter( $opts = [] ) {
$opts = $opts + $this->stdOpts;
$engine = new Scribunto_LuaSandboxEngine( $this->stdOpts );
return new Scribunto_LuaSandboxInterpreter( $engine, $opts );
}
public 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' );
}
}