Debian Codegraph @

extensions/Scribunto/tests/phpunit/Engines/LuaSandbox/SandboxInterpreterTest.php

raw symbols SCIP
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 * @group Lua
16 * @group LuaSandbox
17 * @covers \MediaWiki\Extension\Scribunto\Engines\LuaSandbox\LuaSandboxInterpreter
18 */
19 class SandboxInterpreterTest extends LuaInterpreterTestBase {
20 /** @var array */
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 }