aboutsummaryrefslogtreecommitdiffhomepage
diff options
context:
space:
mode:
authornsfisis <nsfisis@gmail.com>2024-07-10 19:45:51 +0900
committernsfisis <nsfisis@gmail.com>2024-07-10 19:45:51 +0900
commit5a07cfb8f4eab8c63bdedb73cd3dbce270444d24 (patch)
tree65fd2c64cb1a64099b5538a45b6e170bef9eb6b8
parent2984d445831ebf0cd8c909f589dc203018ae2b0b (diff)
downloadphp-waddiwasi-5a07cfb8f4eab8c63bdedb73cd3dbce270444d24.tar.gz
php-waddiwasi-5a07cfb8f4eab8c63bdedb73cd3dbce270444d24.tar.zst
php-waddiwasi-5a07cfb8f4eab8c63bdedb73cd3dbce270444d24.zip
test: partly implement spectest module
-rw-r--r--tests/src/SpecTestsuites/SpecTestsuiteBase.php32
1 files changed, 31 insertions, 1 deletions
diff --git a/tests/src/SpecTestsuites/SpecTestsuiteBase.php b/tests/src/SpecTestsuites/SpecTestsuiteBase.php
index 2d37d2e..2e6234c 100644
--- a/tests/src/SpecTestsuites/SpecTestsuiteBase.php
+++ b/tests/src/SpecTestsuites/SpecTestsuiteBase.php
@@ -7,6 +7,8 @@ namespace Nsfisis\Waddiwasi\Tests\SpecTestsuites;
use Nsfisis\Waddiwasi\BinaryFormat\Decoder;
use Nsfisis\Waddiwasi\BinaryFormat\InvalidBinaryFormatException;
use Nsfisis\Waddiwasi\Execution\Extern;
+use Nsfisis\Waddiwasi\Execution\GlobalInst;
+use Nsfisis\Waddiwasi\Execution\MemInst;
use Nsfisis\Waddiwasi\Execution\Ref;
use Nsfisis\Waddiwasi\Execution\Refs\RefExtern;
use Nsfisis\Waddiwasi\Execution\Refs\RefFunc;
@@ -14,9 +16,17 @@ use Nsfisis\Waddiwasi\Execution\Refs\RefNull;
use Nsfisis\Waddiwasi\Execution\Runtime;
use Nsfisis\Waddiwasi\Execution\StackOverflowException;
use Nsfisis\Waddiwasi\Execution\Store;
+use Nsfisis\Waddiwasi\Execution\TableInst;
use Nsfisis\Waddiwasi\Execution\TrapException;
use Nsfisis\Waddiwasi\Execution\TrapKind;
+use Nsfisis\Waddiwasi\Structure\Types\GlobalType;
+use Nsfisis\Waddiwasi\Structure\Types\Limits;
+use Nsfisis\Waddiwasi\Structure\Types\MemType;
+use Nsfisis\Waddiwasi\Structure\Types\Mut;
+use Nsfisis\Waddiwasi\Structure\Types\NumType;
use Nsfisis\Waddiwasi\Structure\Types\RefType;
+use Nsfisis\Waddiwasi\Structure\Types\TableType;
+use Nsfisis\Waddiwasi\Structure\Types\ValType;
use PHPUnit\Framework\TestCase;
use RuntimeException;
use function count;
@@ -39,7 +49,27 @@ abstract class SpecTestsuiteBase extends TestCase
$wasmBinary = file_get_contents($filePath);
$module = (new Decoder($wasmBinary))->decode();
self::$modules[$moduleName] = $module;
- $importObj = [];
+ $importObj = [
+ 'spectest' => [
+ 'memory' => Extern::Mem(new MemInst(new MemType(new Limits(1, 2)))),
+ 'table' => Extern::Table(new TableInst(new TableType(new Limits(10, 20), RefType::FuncRef), [
+ Ref::RefNull(RefType::FuncRef),
+ Ref::RefNull(RefType::FuncRef),
+ Ref::RefNull(RefType::FuncRef),
+ Ref::RefNull(RefType::FuncRef),
+ Ref::RefNull(RefType::FuncRef),
+ Ref::RefNull(RefType::FuncRef),
+ Ref::RefNull(RefType::FuncRef),
+ Ref::RefNull(RefType::FuncRef),
+ Ref::RefNull(RefType::FuncRef),
+ Ref::RefNull(RefType::FuncRef),
+ ])),
+ 'global_i32' => Extern::Global_(new GlobalInst(new GlobalType(Mut::Const, ValType::NumType(NumType::I32)), 666)),
+ 'global_i64' => Extern::Global_(new GlobalInst(new GlobalType(Mut::Const, ValType::NumType(NumType::I64)), 666)),
+ 'global_f32' => Extern::Global_(new GlobalInst(new GlobalType(Mut::Const, ValType::NumType(NumType::F32)), 666.6)),
+ 'global_f64' => Extern::Global_(new GlobalInst(new GlobalType(Mut::Const, ValType::NumType(NumType::F64)), 666.6)),
+ ],
+ ];
foreach (self::$registeredModules as $registeredModuleName => $registeredModule) {
$registeredRuntime = self::$registeredRuntimes[$registeredModuleName];
foreach ($registeredModule->exports as $export) {