mediawiki-extensions-Scribunto/tests/phpunit/engines/LuaSandbox/LuaSandboxInterpreterTest.php
Kunal Mehta d91a8cf8a0 Add @covers tags to all tests
Bug: T195160
Change-Id: I77ce544e9c166fef6c6fb02f67d1de6ddf0c2465
2018-05-29 11:37:27 -07:00

35 lines
928 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 {
public $stdOpts = [
'memoryLimit' => 50000000,
'cpuLimit' => 30,
];
protected function newInterpreter( $opts = [] ) {
$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' );
}
}