line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
1
|
|
|
|
|
|
|
package Test2::Plugin::Wasm; |
2
|
|
|
|
|
|
|
|
3
|
11
|
|
|
11
|
|
2465733
|
use strict; |
|
11
|
|
|
|
|
82
|
|
|
11
|
|
|
|
|
376
|
|
4
|
11
|
|
|
11
|
|
62
|
use warnings; |
|
11
|
|
|
|
|
21
|
|
|
11
|
|
|
|
|
249
|
|
5
|
11
|
|
|
11
|
|
305
|
use 5.008004; |
|
11
|
|
|
|
|
39
|
|
6
|
11
|
|
|
11
|
|
70
|
use Test2::API qw( context ); |
|
11
|
|
|
|
|
30
|
|
|
11
|
|
|
|
|
503
|
|
7
|
11
|
|
|
11
|
|
58
|
use Test2::Mock; |
|
11
|
|
|
|
|
27
|
|
|
11
|
|
|
|
|
328
|
|
8
|
11
|
|
|
11
|
|
7034
|
use Data::Dumper (); |
|
11
|
|
|
|
|
71047
|
|
|
11
|
|
|
|
|
368
|
|
9
|
11
|
|
|
11
|
|
5129
|
use FFI::C::Util qw( c_to_perl ); |
|
11
|
|
|
|
|
91218
|
|
|
11
|
|
|
|
|
5536
|
|
10
|
|
|
|
|
|
|
|
11
|
|
|
|
|
|
|
# ABSTRACT: Test2 plugin for WebAssembly extensions |
12
|
|
|
|
|
|
|
our $VERSION = '0.21'; # VERSION |
13
|
|
|
|
|
|
|
|
14
|
|
|
|
|
|
|
|
15
|
|
|
|
|
|
|
sub get_virtual_memory_limit |
16
|
|
|
|
|
|
|
{ |
17
|
11
|
|
|
11
|
0
|
41
|
my $ctx = context(); |
18
|
11
|
50
|
|
|
|
822
|
if($^O eq 'linux') |
19
|
|
|
|
|
|
|
{ |
20
|
11
|
|
|
|
|
7543
|
require FFI::Platypus; |
21
|
11
|
|
|
|
|
84610
|
require FFI::C::StructDef; |
22
|
11
|
|
|
|
|
234566
|
my $ffi = FFI::Platypus->new( api => 1, lib => [undef] ); |
23
|
11
|
|
|
|
|
12931
|
my $rlimit; |
24
|
11
|
50
|
|
|
|
59
|
if($ffi->find_symbol('getrlimit')) |
25
|
|
|
|
|
|
|
{ |
26
|
11
|
50
|
|
|
|
751
|
$ctx->note("linux : found getrlimit") if $ENV{TEST2_PLUGIN_WASM_DEBUG}; |
27
|
11
|
|
|
|
|
100
|
$rlimit = FFI::C::StructDef->new( |
28
|
|
|
|
|
|
|
$ffi, |
29
|
|
|
|
|
|
|
name => 'rlimit', |
30
|
|
|
|
|
|
|
members => [ |
31
|
|
|
|
|
|
|
rlim_cur => 'uint32', |
32
|
|
|
|
|
|
|
rlim_max => 'uint32', |
33
|
|
|
|
|
|
|
], |
34
|
|
|
|
|
|
|
)->create; |
35
|
11
|
|
|
|
|
24456
|
my $ret = $ffi->function( getrlimit => [ 'int', 'rlimit' ] => 'int' )->call(9,$rlimit); |
36
|
11
|
50
|
|
|
|
2014
|
if($ret == -1) |
37
|
|
|
|
|
|
|
{ |
38
|
0
|
0
|
|
|
|
0
|
$ctx->note("getrlimit failed: $!") if $ENV{TEST2_PLUGIN_WASM_DEBUG}; |
39
|
0
|
|
|
|
|
0
|
undef $rlimit; |
40
|
|
|
|
|
|
|
} |
41
|
|
|
|
|
|
|
} |
42
|
11
|
50
|
|
|
|
48
|
if(defined $rlimit) |
43
|
|
|
|
|
|
|
{ |
44
|
11
|
|
|
|
|
118
|
my $cur = $rlimit->rlim_cur; |
45
|
|
|
|
|
|
|
$ctx->note("rlimit = " . Data::Dumper->new( |
46
|
|
|
|
|
|
|
[c_to_perl($rlimit)])->Terse(1)->Indent(0)->Dump |
47
|
11
|
50
|
|
|
|
1725
|
) if $ENV{TEST2_PLUGIN_WASM_DEBUG}; |
48
|
11
|
|
|
|
|
103
|
$ctx->release; |
49
|
11
|
50
|
|
|
|
227
|
$cur = 0 if $cur == 0xffffffff; |
50
|
11
|
|
|
|
|
53
|
return $cur; |
51
|
|
|
|
|
|
|
} |
52
|
|
|
|
|
|
|
} |
53
|
0
|
|
|
|
|
0
|
$ctx->release; |
54
|
0
|
|
|
|
|
0
|
return undef; |
55
|
|
|
|
|
|
|
} |
56
|
|
|
|
|
|
|
|
57
|
|
|
|
|
|
|
our $config_mock; |
58
|
|
|
|
|
|
|
|
59
|
|
|
|
|
|
|
sub import |
60
|
|
|
|
|
|
|
{ |
61
|
11
|
|
|
11
|
|
139
|
my $ctx = context(); |
62
|
11
|
|
|
|
|
63702
|
my $vm_limit = get_virtual_memory_limit(); |
63
|
11
|
50
|
|
|
|
1780
|
if($vm_limit) |
64
|
|
|
|
|
|
|
{ |
65
|
0
|
|
|
|
|
0
|
require Wasm::Wasmtime::Config; |
66
|
|
|
|
|
|
|
$config_mock = Test2::Mock->new( |
67
|
|
|
|
|
|
|
class => 'Wasm::Wasmtime::Config', |
68
|
|
|
|
|
|
|
around => [ |
69
|
|
|
|
|
|
|
new => sub { |
70
|
0
|
|
|
0
|
|
0
|
my $orig = shift; |
71
|
0
|
|
|
|
|
0
|
my $self = shift->$orig(@_); |
72
|
0
|
|
|
|
|
0
|
my $ctx = context(); |
73
|
0
|
|
|
|
|
0
|
$ctx->note("virtual memory address limit detected, try to set limits to zero"); |
74
|
0
|
|
|
|
|
0
|
$self->static_memory_maximum_size(0); |
75
|
0
|
|
|
|
|
0
|
$self->static_memory_guard_size(0); |
76
|
0
|
|
|
|
|
0
|
$self->dynamic_memory_guard_size(0); |
77
|
0
|
|
|
|
|
0
|
$ctx->release; |
78
|
0
|
|
|
|
|
0
|
$self; |
79
|
|
|
|
|
|
|
}, |
80
|
0
|
|
|
|
|
0
|
], |
81
|
|
|
|
|
|
|
); |
82
|
|
|
|
|
|
|
} |
83
|
11
|
|
|
|
|
71
|
$ctx->release; |
84
|
|
|
|
|
|
|
} |
85
|
|
|
|
|
|
|
|
86
|
|
|
|
|
|
|
1; |
87
|
|
|
|
|
|
|
|
88
|
|
|
|
|
|
|
__END__ |