| 1 |
<?php |
| 2 |
|
| 3 |
namespace MediaWiki\Extension\Scribunto\Tests\Engines\LuaSandbox; |
| 4 |
|
| 5 |
use MediaWiki\Extension\Scribunto\Engines\LuaSandbox\LuaSandboxEngine; |
| 6 |
use MediaWiki\Extension\Scribunto\Engines\LuaSandbox\LuaSandboxInterpreter; |
| 7 |
use MediaWiki\Extension\Scribunto\Tests\Engines\LuaCommon\LuaInterpreterTestBase; |
| 8 |
use MediaWiki\Title\Title; |
| 9 |
|
| 10 |
if ( !wfIsCLI() ) { |
| 11 |
exit; |
| 12 |
} |
| 13 |
|
| 14 |
|
| 15 |
|
| 16 |
|
| 17 |
|
| 18 |
|
| 19 |
class SandboxInterpreterTest extends LuaInterpreterTestBase { |
| 20 |
|
| 21 |
public $stdOpts = [ |
| 22 |
'memoryLimit' => 50000000, |
| 23 |
'cpuLimit' => 30, |
| 24 |
]; |
| 25 |
|
| 26 |
protected function newInterpreter( $opts = [] ) { |
| 27 |
$opts += $this->stdOpts; |
| 28 |
$engine = new LuaSandboxEngine( $this->stdOpts + [ |
| 29 |
'title' => Title::makeTitle( NS_MAIN, 'Dummy' ), |
| 30 |
] ); |
| 31 |
return new LuaSandboxInterpreter( $engine, $opts ); |
| 32 |
} |
| 33 |
|
| 34 |
public function testGetMemoryUsage() { |
| 35 |
$interpreter = $this->newInterpreter(); |
| 36 |
$chunk = $interpreter->loadString( 's = string.rep("x", 1000000)', 'mem' ); |
| 37 |
$interpreter->callFunction( $chunk ); |
| 38 |
$mem = $interpreter->getPeakMemoryUsage(); |
| 39 |
$this->assertGreaterThan( 1000000, $mem, 'memory usage' ); |
| 40 |
$this->assertLessThan( 10000000, $mem, 'memory usage' ); |
| 41 |
} |
| 42 |
} |