Skip to content

Commit

Permalink
test: add unreachable.wasm, only passes on extism a91846a or later
Browse files Browse the repository at this point in the history
  • Loading branch information
G4Vi committed Oct 10, 2024
1 parent 754e681 commit 1e65ae6
Show file tree
Hide file tree
Showing 4 changed files with 37 additions and 2 deletions.
7 changes: 7 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
Extism/host.wasm
Extism/unreachable.wasm
Extism/MYMETA.json
Extism/MYMETA.yml
Extism/Makefile
Expand All @@ -17,3 +18,9 @@ examples/Extism-AudioDecoder/*.wav
examples/Extism-AudioDecoder/*.pcm
examples/Extism-AudioDecoder/.vscode
examples/CountVowels/.vscode
Alien-libextism/MYMETA.json
Alien-libextism/MYMETA.yml
Alien-libextism/Makefile
Alien-libextism/_alien/
Alien-libextism/blib/
Alien-libextism/pm_to_blib
17 changes: 16 additions & 1 deletion Extism/t/02-extism.t
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ use Extism ':all';
use JSON::PP qw(encode_json decode_json);
use File::Temp qw(tempfile);
use Devel::Peek qw(Dump);
plan tests => 40;
plan tests => 44;

# ...
ok(Extism::version());
Expand Down Expand Up @@ -180,3 +180,18 @@ ok($decoded[1]{total} == 6);
# Verify both sets of results are the same
is($highlevel[0], $lowlevel[0]);
is($highlevel[1], $lowlevel[1]);

# test unreachable plugin
my $unreachable = encode_json({
wasm => [
{
path => 'unreachable.wasm',
}
],
});
my $uplugin = Extism::Plugin->new($unreachable, {wasi => 1});
ok($uplugin);
my ($ures, $urc, $uinfo) = $uplugin->call('do_unreachable');
ok(!defined $ures);
ok($urc != 0);
ok($uinfo);
5 changes: 4 additions & 1 deletion Makefile
Original file line number Diff line number Diff line change
@@ -1,9 +1,12 @@
.PHONY: all
all: Extism Extism/host.wasm
all: Extism Extism/host.wasm Extism/unreachable.wasm

Extism/host.wasm: host.c
$(WASI_SDK_PATH)/bin/clang -o $@ $^ -mexec-model=reactor

Extism/unreachable.wasm: unreachable.cpp
$(WASI_SDK_PATH)/bin/clang++ -fno-exceptions -o $@ $^ -mexec-model=reactor

Extism/Makefile: Extism/Makefile.PL
cd Extism && perl Makefile.PL
.PHONY: Extism
Expand Down
10 changes: 10 additions & 0 deletions unreachable.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
// #define EXTISM_IMPLEMENTATION
#include "extism-pdk.h"
#include <stdexcept>
#include <stdint.h>

int32_t EXTISM_EXPORTED_FUNCTION(do_unreachable)
{
std::terminate();
return -1;
}

0 comments on commit 1e65ae6

Please sign in to comment.