MediaWiki REL1_34
LuaSandboxInterpreterTest.php
Go to the documentation of this file.
1<?php
2
3if ( !wfIsCLI() ) {
4 exit;
5}
6
7require_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}
wfIsCLI()
Check if we are running from the commandline.
@group Lua @group LuaSandbox @covers Scribunto_LuaSandboxInterpreter