This repository was archived by the owner on Mar 29, 2024. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 14
/
Copy pathIsolate_limit_time.phpt
88 lines (70 loc) · 2.33 KB
/
Isolate_limit_time.phpt
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
--TEST--
V8\Isolate - time limit
--SKIPIF--
<?php if (!extension_loaded("v8")) print "skip"; ?>
--FILE--
<?php
/** @var \Phpv8Testsuite $helper */
$helper = require '.testsuite.php';
require '.v8-helpers.php';
$v8_helper = new PhpV8Helpers($helper);
// Tests:
$isolate = new V8\Isolate();
$context = new V8\Context($isolate);
$source = '
var i = 0;
while(true) { i++};
';
$file_name = 'test.js';
$script = new V8\Script($context, new \V8\StringValue($isolate, $source), new \V8\ScriptOrigin($file_name));
if ($helper->need_more_time()) {
// On travis when valgrind active it takes more time to complete all operations so we just increase initial limits
$time_limit = 5.0;
$low_range = $time_limit/2;
$high_range = $time_limit*20;
} else {
$time_limit = 1.5;
$low_range = 1.45;
$high_range = 1.65;
}
$helper->assert('Time limit accessor report no hit', false === $isolate->isTimeLimitHit());
$helper->assert('Get time limit default value is zero', 0.0 === $isolate->getTimeLimit());
$isolate->setTimeLimit($time_limit);
$helper->assert('Get time limit returns valid value', $time_limit === $isolate->getTimeLimit());
$helper->dump($isolate);
$helper->line();
$t = microtime(true);
try {
$res = $script->run($context);
} catch(\V8\Exceptions\TimeLimitException $e) {
$helper->exception_export($e);
echo 'script execution terminated', PHP_EOL;
} finally {
$helper->line();
$t = microtime(true) - $t;
$helper->dump(round($t, 9));
$helper->assert("Script execution time is within specified range ({$low_range}, {$high_range})", $t >= $low_range && $t < $high_range);
}
$helper->assert('Get time limit returns valid value', $time_limit === $isolate->getTimeLimit());
$helper->assert('Time limit accessor report hit', true === $isolate->isTimeLimitHit());
$helper->line();
$helper->dump($isolate);
// EXPECTF: ---/float\(.+\)/
// EXPECTF: +++float(%f)
// EXPECTF: ---/range \(.+, .+\)/
// EXPECTF: +++range (%f, %f)
?>
--EXPECTF--
Time limit accessor report no hit: ok
Get time limit default value is zero: ok
Get time limit returns valid value: ok
object(V8\Isolate)#3 (0) {
}
V8\Exceptions\TimeLimitException: Time limit exceeded
script execution terminated
float(%f)
Script execution time is within specified range (%f, %f): ok
Get time limit returns valid value: ok
Time limit accessor report hit: ok
object(V8\Isolate)#3 (0) {
}