mirror of
https://gerrit.wikimedia.org/r/mediawiki/extensions/Scribunto
synced 2024-12-13 16:58:26 +00:00
6f411e3921
Change-Id: Ic81ab852c43e98370097d01c3b6d6cddee7a5850
36 lines
940 B
PHP
36 lines
940 B
PHP
<?php
|
|
|
|
if ( !wfIsCLI() ) {
|
|
exit;
|
|
}
|
|
|
|
require_once __DIR__ . '/../LuaCommon/LuaInterpreterTest.php';
|
|
|
|
/**
|
|
* @group Lua
|
|
* @group LuaSandbox
|
|
* @covers Scribunto_LuaSandboxInterpreter
|
|
*/
|
|
class Scribunto_LuaSandboxInterpreterTest extends Scribunto_LuaInterpreterTest {
|
|
/** @var array */
|
|
public $stdOpts = [
|
|
'memoryLimit' => 50000000,
|
|
'cpuLimit' => 30,
|
|
];
|
|
|
|
protected function newInterpreter( $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' );
|
|
}
|
|
}
|