| 1 | package Test2::Plugin::Wasm; | ||||||||||
| 2 | |||||||||||
| 3 | 11 | ▶ | use strict; | ||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||
| 4 | 11 | ▶ | use warnings; | ||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||
| 5 | 11 | ▶ | use 5.008004; | ||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||
| 6 | 11 | ▶ | use Test2::API qw( context ); | ||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||
| 7 | 11 | ▶ | use Test2::Mock; | ||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||
| 8 | 11 | ▶ | use Data::Dumper (); | ||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||
| 9 | 11 | ▶ | use FFI::C::Util qw( c_to_perl ); | ||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||
| 10 | |||||||||||
| 11 | # ABSTRACT: Test2 plugin for WebAssembly extensions | ||||||||||
| 12 | 11 | our $VERSION = '0.24'; # VERSION | |||||||||
| 13 | |||||||||||
| 14 | |||||||||||
| 15 | sub get_virtual_memory_limit | ||||||||||
| 16 | 11 | ▶ | { | ||||||||
|
Subroutine
get_virtual_memory_limit: called CC=9 SCAR=25.3
Pod
undocumented
| |||||||||||
| 17 | 11 | my $ctx = context(); | |||||||||
| 18 | 11 | ▶ | if($^O eq 'linux') | ||||||||
|
Branch: 1 branch
| |||||||||||
| 19 | { | ||||||||||
| 20 | 11 | require FFI::Platypus; | |||||||||
| 21 | 11 | require FFI::C::StructDef; | |||||||||
| 22 | 11 | my $ffi = FFI::Platypus->new( api => 2, lib => [undef] ); | |||||||||
| 23 | 11 | my $rlimit; | |||||||||
| 24 | 11 | ▶ | if($ffi->find_symbol('getrlimit')) | ||||||||
|
Branch: 1 branch
| |||||||||||
| 25 | { | ||||||||||
| 26 | 11 | ▶ | $ctx->note("linux : found getrlimit") if $ENV{TEST2_PLUGIN_WASM_DEBUG}; | ||||||||
|
Branch: 1 branch
| |||||||||||
| 27 | 11 | $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 | my $ret = $ffi->function( getrlimit => [ 'int', 'rlimit' ] => 'int' )->call(9,$rlimit); | |||||||||
| 36 | 11 | ▶ | if($ret == -1) | ||||||||
|
Branch: 1 branch
| |||||||||||
| 37 | { | ||||||||||
| 38 | 0 | ▶ | $ctx->note("getrlimit failed: $!") if $ENV{TEST2_PLUGIN_WASM_DEBUG}; | ||||||||
|
Branch: 1 branch
| |||||||||||
| 39 | 0 | undef $rlimit; | |||||||||
| 40 | } | ||||||||||
| 41 | } | ||||||||||
| 42 | 11 | ▶ | if(defined $rlimit) | ||||||||
|
Branch: 1 branch
| |||||||||||
| 43 | { | ||||||||||
| 44 | 11 | my $cur = $rlimit->rlim_cur; | |||||||||
| 45 | $ctx->note("rlimit = " . Data::Dumper->new( | ||||||||||
| 46 | [c_to_perl($rlimit)])->Terse(1)->Indent(0)->Dump | ||||||||||
| 47 | 11 | ▶ | ) if $ENV{TEST2_PLUGIN_WASM_DEBUG}; | ||||||||
|
Branch: 1 branch
| |||||||||||
| 48 | 11 | $ctx->release; | |||||||||
| 49 | 11 | ▶ | $cur = 0 if $cur == 0xffffffff; | ||||||||
|
Branch: 1 branch
| |||||||||||
| 50 | 11 | return $cur; | |||||||||
| 51 | } | ||||||||||
| 52 | } | ||||||||||
| 53 | 0 | $ctx->release; | |||||||||
| 54 | 0 | return undef; | |||||||||
| 55 | } | ||||||||||
| 56 | |||||||||||
| 57 | 11 | our $config_mock; | |||||||||
| 58 | |||||||||||
| 59 | sub import | ||||||||||
| 60 | 11 | ▶ | { | ||||||||
|
Subroutine
import: called CC=2 SCAR=11.9
| |||||||||||
| 61 | 11 | my $ctx = context(); | |||||||||
| 62 | 11 | my $vm_limit = get_virtual_memory_limit(); | |||||||||
| 63 | 11 | ▶ | if($vm_limit) | ||||||||
|
Branch: 1 branch
| |||||||||||
| 64 | { | ||||||||||
| 65 | 0 | require Wasm::Wasmtime::Config; | |||||||||
| 66 | $config_mock = Test2::Mock->new( | ||||||||||
| 67 | class => 'Wasm::Wasmtime::Config', | ||||||||||
| 68 | around => [ | ||||||||||
| 69 | 0 | ▶ | new => sub { | ||||||||
|
Subroutine
__ANON__: not called CC=1 SCAR=6.9
| |||||||||||
| 70 | 0 | my $orig = shift; | |||||||||
| 71 | 0 | my $self = shift->$orig(@_); | |||||||||
| 72 | 0 | my $ctx = context(); | |||||||||
| 73 | 0 | $ctx->note("virtual memory address limit detected, try to set limits to zero"); | |||||||||
| 74 | 0 | $self->memory_reservation(0); | |||||||||
| 75 | 0 | $self->memory_guard_size(0); | |||||||||
| 76 | 0 | $ctx->release; | |||||||||
| 77 | 0 | $self; | |||||||||
| 78 | }, | ||||||||||
| 79 | 0 | ], | |||||||||
| 80 | ); | ||||||||||
| 81 | } | ||||||||||
| 82 | 11 | $ctx->release; | |||||||||
| 83 | } | ||||||||||
| 84 | |||||||||||
| 85 | 11 | 1; | |||||||||
| 86 | |||||||||||
| 87 | __END__ | ||||||||||