mirror of
https://github.com/vlang/v.git
synced 2025-09-13 14:32:26 +03:00
ci: add test jobs for the wasm
module, for macos, linux and windows (#17972)
This commit is contained in:
parent
a49cecc2b4
commit
bf749b3559
8 changed files with 172 additions and 88 deletions
|
@ -1,26 +1,6 @@
|
|||
module main
|
||||
|
||||
import wasm
|
||||
import os
|
||||
|
||||
const exe = os.find_abs_path_of_executable('wasm-validate') or { exit(0) }
|
||||
|
||||
fn validate(mod []u8) ! {
|
||||
mut proc := os.new_process(exe)
|
||||
proc.set_args(['-'])
|
||||
proc.set_redirect_stdio()
|
||||
proc.run()
|
||||
{
|
||||
os.fd_write(proc.stdio_fd[0], mod.bytestr())
|
||||
os.fd_close(proc.stdio_fd[0])
|
||||
}
|
||||
proc.wait()
|
||||
if proc.status != .exited {
|
||||
return error('wasm-validate exited abormally')
|
||||
}
|
||||
if proc.code != 0 {
|
||||
return error('wasm-validate exited with a non zero exit code')
|
||||
}
|
||||
proc.close()
|
||||
}
|
||||
|
||||
fn test_add() {
|
||||
mut m := wasm.Module{}
|
||||
|
|
|
@ -1,26 +1,6 @@
|
|||
module main
|
||||
|
||||
import wasm
|
||||
import os
|
||||
|
||||
const exe = os.find_abs_path_of_executable('wasm-validate') or { exit(0) }
|
||||
|
||||
fn validate(mod []u8) ! {
|
||||
mut proc := os.new_process(exe)
|
||||
proc.set_args(['-'])
|
||||
proc.set_redirect_stdio()
|
||||
proc.run()
|
||||
{
|
||||
os.fd_write(proc.stdio_fd[0], mod.bytestr())
|
||||
os.fd_close(proc.stdio_fd[0])
|
||||
}
|
||||
proc.wait()
|
||||
if proc.status != .exited {
|
||||
return error('wasm-validate exited abormally')
|
||||
}
|
||||
if proc.code != 0 {
|
||||
return error('wasm-validate exited with a non zero exit code')
|
||||
}
|
||||
proc.close()
|
||||
}
|
||||
|
||||
fn test_block() {
|
||||
mut m := wasm.Module{}
|
||||
|
|
|
@ -1,26 +1,6 @@
|
|||
module main
|
||||
|
||||
import wasm
|
||||
import os
|
||||
|
||||
const exe = os.find_abs_path_of_executable('wasm-validate') or { exit(0) }
|
||||
|
||||
fn validate(mod []u8) ! {
|
||||
mut proc := os.new_process(exe)
|
||||
proc.set_args(['-'])
|
||||
proc.set_redirect_stdio()
|
||||
proc.run()
|
||||
{
|
||||
os.fd_write(proc.stdio_fd[0], mod.bytestr())
|
||||
os.fd_close(proc.stdio_fd[0])
|
||||
}
|
||||
proc.wait()
|
||||
if proc.status != .exited {
|
||||
return error('wasm-validate exited abormally')
|
||||
}
|
||||
if proc.code != 0 {
|
||||
return error('wasm-validate exited with a non zero exit code')
|
||||
}
|
||||
proc.close()
|
||||
}
|
||||
|
||||
fn test_call() {
|
||||
mut m := wasm.Module{}
|
||||
|
|
38
vlib/wasm/tests/common.v
Normal file
38
vlib/wasm/tests/common.v
Normal file
|
@ -0,0 +1,38 @@
|
|||
module main
|
||||
|
||||
import os
|
||||
|
||||
const pid = os.getpid()
|
||||
|
||||
const wasm_validate_exe = find_wasm_validate() or {
|
||||
println('>>> Skipping test, since wasm-validate could not be found, error: ${err}')
|
||||
exit(0)
|
||||
}
|
||||
|
||||
fn find_wasm_validate() !string {
|
||||
// Prefer to find our own version first, if it was installed already
|
||||
// through install_wabt.vsh, since it is more likely to be known, recent, and stable:
|
||||
thirdpart_wasm_validate_folder := os.join_path(@VROOT, 'thirdparty', 'wabt', 'bin')
|
||||
extension := $if windows { '.exe' } $else { '' }
|
||||
wasm_validate_executable := os.join_path(thirdpart_wasm_validate_folder, 'wasm-validate${extension}')
|
||||
if os.exists(wasm_validate_executable) {
|
||||
return wasm_validate_executable
|
||||
}
|
||||
if path := os.find_abs_path_of_executable('wasm-validate') {
|
||||
return path
|
||||
}
|
||||
return error('could not find wasm-validate executable in thirdparty/ as well, try first `v run cmd/tools/install_wabt.vsh`')
|
||||
}
|
||||
|
||||
pub fn validate(code []u8) ! {
|
||||
println('validating using: ${wasm_validate_exe}')
|
||||
outfile := os.join_path(os.temp_dir(), 'code_${pid}.wasm')
|
||||
os.write_file(outfile, code.bytestr())!
|
||||
validation_cmd := '${os.quoted_path(wasm_validate_exe)} ${os.quoted_path(outfile)}'
|
||||
res := os.execute(validation_cmd)
|
||||
if res.exit_code != 0 {
|
||||
eprintln('failed exit code: ${res.exit_code} | command:\n${validation_cmd}')
|
||||
return error('wasm-validate exited with a non zero exit code: ${res.exit_code}')
|
||||
}
|
||||
os.rm(outfile)!
|
||||
}
|
|
@ -1,26 +1,6 @@
|
|||
module main
|
||||
|
||||
import wasm
|
||||
import os
|
||||
|
||||
const exe = os.find_abs_path_of_executable('wasm-validate') or { exit(0) }
|
||||
|
||||
fn validate(mod []u8) ! {
|
||||
mut proc := os.new_process(exe)
|
||||
proc.set_args(['-'])
|
||||
proc.set_redirect_stdio()
|
||||
proc.run()
|
||||
{
|
||||
os.fd_write(proc.stdio_fd[0], mod.bytestr())
|
||||
os.fd_close(proc.stdio_fd[0])
|
||||
}
|
||||
proc.wait()
|
||||
if proc.status != .exited {
|
||||
return error('wasm-validate exited abormally')
|
||||
}
|
||||
if proc.code != 0 {
|
||||
return error('wasm-validate exited with a non zero exit code')
|
||||
}
|
||||
proc.close()
|
||||
}
|
||||
|
||||
fn test_globals() {
|
||||
mut m := wasm.Module{}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue