diff options
| author | nsfisis <nsfisis@gmail.com> | 2024-07-10 19:30:09 +0900 |
|---|---|---|
| committer | nsfisis <nsfisis@gmail.com> | 2024-07-10 19:30:20 +0900 |
| commit | 2984d445831ebf0cd8c909f589dc203018ae2b0b (patch) | |
| tree | 465c6e304b85fcd322389dd8b530cea5acabd929 /tests/src/SpecTestsuites/SpecTestsuiteBase.php | |
| parent | 1011da8798ba7370d914dbce9feac1b06ab81ed5 (diff) | |
| download | php-waddiwasi-2984d445831ebf0cd8c909f589dc203018ae2b0b.tar.gz php-waddiwasi-2984d445831ebf0cd8c909f589dc203018ae2b0b.tar.zst php-waddiwasi-2984d445831ebf0cd8c909f589dc203018ae2b0b.zip | |
test: implement "register" action of WAST
Diffstat (limited to 'tests/src/SpecTestsuites/SpecTestsuiteBase.php')
| -rw-r--r-- | tests/src/SpecTestsuites/SpecTestsuiteBase.php | 20 |
1 files changed, 18 insertions, 2 deletions
diff --git a/tests/src/SpecTestsuites/SpecTestsuiteBase.php b/tests/src/SpecTestsuites/SpecTestsuiteBase.php index 65176a5..2d37d2e 100644 --- a/tests/src/SpecTestsuites/SpecTestsuiteBase.php +++ b/tests/src/SpecTestsuites/SpecTestsuiteBase.php @@ -6,6 +6,7 @@ namespace Nsfisis\Waddiwasi\Tests\SpecTestsuites; use Nsfisis\Waddiwasi\BinaryFormat\Decoder; use Nsfisis\Waddiwasi\BinaryFormat\InvalidBinaryFormatException; +use Nsfisis\Waddiwasi\Execution\Extern; use Nsfisis\Waddiwasi\Execution\Ref; use Nsfisis\Waddiwasi\Execution\Refs\RefExtern; use Nsfisis\Waddiwasi\Execution\Refs\RefFunc; @@ -25,6 +26,8 @@ abstract class SpecTestsuiteBase extends TestCase { private static $modules = []; private static $runtimes = []; + private static $registeredModules = []; + private static $registeredRuntimes = []; protected function runModuleCommand( string $filename, @@ -36,7 +39,15 @@ abstract class SpecTestsuiteBase extends TestCase $wasmBinary = file_get_contents($filePath); $module = (new Decoder($wasmBinary))->decode(); self::$modules[$moduleName] = $module; - $runtime = Runtime::instantiate(Store::empty(), $module, []); + $importObj = []; + foreach (self::$registeredModules as $registeredModuleName => $registeredModule) { + $registeredRuntime = self::$registeredRuntimes[$registeredModuleName]; + foreach ($registeredModule->exports as $export) { + $fn = $registeredRuntime->store->funcs[$registeredRuntime->getExport($export->name)->addr]; + $importObj[$registeredModuleName][$export->name] = Extern::Func($fn); + } + } + $runtime = Runtime::instantiate(Store::empty(), $module, $importObj); self::$runtimes[$moduleName] = $runtime; $this->assertTrue(true); } @@ -146,7 +157,12 @@ abstract class SpecTestsuiteBase extends TestCase string $as, int $line, ): void { - $this->assertTrue(false, "register"); + $targetModuleName = $name ?? '_'; + $targetModule = self::$modules[$targetModuleName]; + $runtime = self::$runtimes[$targetModuleName]; + self::$registeredModules[$as] = $targetModule; + self::$registeredRuntimes[$as] = $runtime; + $this->assertTrue(true); } /** |
