diff options
| author | nsfisis <nsfisis@gmail.com> | 2024-03-11 22:44:57 +0900 |
|---|---|---|
| committer | nsfisis <nsfisis@gmail.com> | 2024-03-11 22:44:57 +0900 |
| commit | 75e14575b4ae1a0cc428ccf2944c314b0c908f93 (patch) | |
| tree | 1b3a4a866f833a523c49412df5d180d6ba68180f | |
| parent | 3a667844e177dcc2dd7729df00d7368d4a21b84f (diff) | |
| download | php-waddiwasi-75e14575b4ae1a0cc428ccf2944c314b0c908f93.tar.gz php-waddiwasi-75e14575b4ae1a0cc428ccf2944c314b0c908f93.tar.zst php-waddiwasi-75e14575b4ae1a0cc428ccf2944c314b0c908f93.zip | |
feat: add minimum test
| -rw-r--r-- | .editorconfig | 3 | ||||
| -rw-r--r-- | Makefile | 7 | ||||
| -rw-r--r-- | examples/php-on-wasm/php-wasm.php | 11 | ||||
| -rw-r--r-- | test.sh | 9 |
4 files changed, 25 insertions, 5 deletions
diff --git a/.editorconfig b/.editorconfig index e291365..5c2153d 100644 --- a/.editorconfig +++ b/.editorconfig @@ -7,3 +7,6 @@ indent_size = 4 end_of_line = lf insert_final_newline = true trim_trailing_whitespace = true + +[Makefile] +indent_style = tab diff --git a/Makefile b/Makefile new file mode 100644 index 0000000..db03d11 --- /dev/null +++ b/Makefile @@ -0,0 +1,7 @@ +.PHONY: run +run: + php -d memory_limit=4G -d opcache.enable_cli=on -d opcache.jit=on -d opcache.jit_buffer_size=1G examples/php-on-wasm/php-wasm.php + +.PHONY: test +test: + @bash test.sh diff --git a/examples/php-on-wasm/php-wasm.php b/examples/php-on-wasm/php-wasm.php index 32c375e..f1a26fb 100644 --- a/examples/php-on-wasm/php-wasm.php +++ b/examples/php-on-wasm/php-wasm.php @@ -29,15 +29,16 @@ const PHP_HELLO_WORLD = <<<'EOS' echo "Hello, World!\n"; EOS; -echo "Decoding...\n"; +fprintf(STDERR, "Decoding...\n"); try { $module = (new Decoder($wasmBinary))->decode(); // Debug::printImports($module); } catch (InvalidBinaryFormatException $e) { - echo $e->getMessage() . PHP_EOL; + fprintf(STDERR, $e->getMessage() . "\n"); + exit(1); } -echo "Instantiating...\n"; +fprintf(STDERR, "Instantiating...\n"); $hostFuncs = [ makeHostFunc('(i32, i32, i32) -> (i32)', hostFunc__env__invoke_iii(...)), makeHostFunc('(i32, i32, i32, i32, i32) -> (i32)', hostFunc__env__invoke_iiiii(...)), @@ -142,7 +143,7 @@ foreach ($hostFuncs as $hostFunc) { $runtime = Runtime::instantiate($store, $module, $externVals); $codePtr = allocateStringOnWasmMemory($runtime, PHP_HELLO_WORLD); -echo "Executing...\n"; +fprintf(STDERR, "Executing...\n"); $results = $runtime->invoke("php_wasm_run", [Val::NumI32($codePtr)]); assert(count($results) === 1); $result = $results[0]; @@ -150,7 +151,7 @@ assert($result instanceof Vals\Num); assert($result->inner instanceof Nums\I32); $exitCode = $result->inner->value; -echo "Exit code: $exitCode\n"; +fprintf(STDERR, "Exit code: $exitCode\n"); function allocateStringOnWasmMemory(Runtime $runtime, string $str): int { // Plus 1 for the null terminator in C. @@ -0,0 +1,9 @@ +result=$(php -d memory_limit=4G -d opcache.enable_cli=on -d opcache.jit=on -d opcache.jit_buffer_size=1G examples/php-on-wasm/php-wasm.php 2>/dev/null) +if [[ "$result" == 'Hello, World!' ]]; then + echo "Test passed" + exit 0 +else + echo "Test failed" + echo "$result" + exit 1 +fi |
