mirror of
https://gerrit.wikimedia.org/r/mediawiki/extensions/Scribunto
synced 2024-12-22 21:02:52 +00:00
83d0f76301
- Avoid defining abstract test classes (ending in "Test") Bug: T342110 Change-Id: I729df8d3cd5071826b5e035813102148a0f47520
40 lines
1.1 KiB
PHP
40 lines
1.1 KiB
PHP
<?php
|
|
|
|
namespace MediaWiki\Extension\Scribunto\Tests\Engines\LuaSandbox;
|
|
|
|
use MediaWiki\Extension\Scribunto\Engines\LuaSandbox\LuaSandboxEngine;
|
|
use MediaWiki\Extension\Scribunto\Engines\LuaSandbox\LuaSandboxInterpreter;
|
|
use MediaWiki\Extension\Scribunto\Tests\Engines\LuaCommon\LuaInterpreterTestBase;
|
|
|
|
if ( !wfIsCLI() ) {
|
|
exit;
|
|
}
|
|
|
|
/**
|
|
* @group Lua
|
|
* @group LuaSandbox
|
|
* @covers \MediaWiki\Extension\Scribunto\Engines\LuaSandbox\LuaSandboxInterpreter
|
|
*/
|
|
class SandboxInterpreterTest extends LuaInterpreterTestBase {
|
|
/** @var array */
|
|
public $stdOpts = [
|
|
'memoryLimit' => 50000000,
|
|
'cpuLimit' => 30,
|
|
];
|
|
|
|
protected function newInterpreter( $opts = [] ) {
|
|
$opts += $this->stdOpts;
|
|
$engine = new LuaSandboxEngine( $this->stdOpts );
|
|
return new 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' );
|
|
}
|
|
}
|