MediaWiki  1.34.4
LuaSandboxInterpreterTest.php
Go to the documentation of this file.
1 <?php
2 
3 if ( !wfIsCLI() ) {
4  exit;
5 }
6 
7 require_once __DIR__ . '/../LuaCommon/LuaInterpreterTest.php';
8 
15  public $stdOpts = [
16  'memoryLimit' => 50000000,
17  'cpuLimit' => 30,
18  ];
19 
20  protected function newInterpreter( $opts = [] ) {
21  $opts = $opts + $this->stdOpts;
22  $engine = new Scribunto_LuaSandboxEngine( $this->stdOpts );
23  return new Scribunto_LuaSandboxInterpreter( $engine, $opts );
24  }
25 
26  public function testGetMemoryUsage() {
27  $interpreter = $this->newInterpreter();
28  $chunk = $interpreter->loadString( 's = string.rep("x", 1000000)', 'mem' );
29  $interpreter->callFunction( $chunk );
30  $mem = $interpreter->getPeakMemoryUsage();
31  $this->assertGreaterThan( 1000000, $mem, 'memory usage' );
32  $this->assertLessThan( 10000000, $mem, 'memory usage' );
33  }
34 }
Scribunto_LuaSandboxInterpreterTest\$stdOpts
$stdOpts
Definition: LuaSandboxInterpreterTest.php:15
Scribunto_LuaSandboxEngine
Definition: Engine.php:3
Scribunto_LuaInterpreterTest
Definition: LuaInterpreterTest.php:3
wfIsCLI
wfIsCLI()
Check if we are running from the commandline.
Definition: GlobalFunctions.php:1912
Scribunto_LuaSandboxInterpreter
Definition: Engine.php:215
Scribunto_LuaSandboxInterpreterTest
@group Lua @group LuaSandbox @covers Scribunto_LuaSandboxInterpreter
Definition: LuaSandboxInterpreterTest.php:14
Scribunto_LuaSandboxInterpreterTest\newInterpreter
newInterpreter( $opts=[])
Definition: LuaSandboxInterpreterTest.php:20
Scribunto_LuaSandboxInterpreterTest\testGetMemoryUsage
testGetMemoryUsage()
Definition: LuaSandboxInterpreterTest.php:26