Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
19 changes: 18 additions & 1 deletion .github/workflows/main.yml
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,8 @@ jobs:
- '3.4.5'
wasm_tools:
- '1.236.0'
wabt:
- '1.0.37'

steps:
- uses: actions/checkout@v4
Expand All @@ -28,7 +30,7 @@ jobs:
bundler-cache: true
- name: Install wasm-tools
run: |
mkdir .bin
mkdir -p .bin
curl -L https://github.com/bytecodealliance/wasm-tools/releases/download/v${{ matrix.wasm_tools }}/wasm-tools-${{ matrix.wasm_tools }}-x86_64-linux.tar.gz -o wasm-tools.tar.gz
tar xvzf wasm-tools.tar.gz
mv wasm-tools-*-x86_64-linux/wasm-tools .bin/wasm-tools
Expand All @@ -37,6 +39,17 @@ jobs:
run: |
export PATH=`pwd`/.bin:$PATH
wasm-tools --version
- name: Install wast2json
run: |
mkdir -p .bin
curl -L https://github.com/WebAssembly/wabt/releases/download/${{ matrix.wabt }}/wabt-${{ matrix.wabt }}-ubuntu-20.04.tar.gz -o wabt.tar.gz
tar xvzf wabt.tar.gz
mv wabt-*/bin/wast2json .bin/wast2json
chmod a+x .bin/wast2json
- name: Version wast2json
run: |
export PATH=`pwd`/.bin:$PATH
wast2json --version
- name: Run the check task
run: |
export PATH=`pwd`/.bin:$PATH
Expand All @@ -45,3 +58,7 @@ jobs:
run: |
export PATH=`pwd`/.bin:$PATH
bundle exec rake test
- name: Run the official spec
run: |
export PATH=`pwd`/.bin:$PATH
bundle exec rake 'spec[i32]'
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -9,3 +9,4 @@
.ruby-version
.gem_rbs_collection
ruby-wasm32-wasi
spec/skip.txt
17 changes: 17 additions & 0 deletions Rakefile
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,23 @@ task :wasm, [:name] do |t, args|
end
end

desc "Run the official spec"
task :spec, [:name] do |t, args|
sh "which git && git clean -f spec/ || true"

Dir.chdir "spec" do
sh "curl -L -o ./#{args.name}.wast https://raw.githubusercontent.com/WebAssembly/spec/refs/tags/wg-1.0/test/core/#{args.name}.wast"
sh "wast2json ./#{args.name}.wast"
sh "env JSON_PATH=./#{args.name}.json ruby ./runner.rb -v"

if File.exist?("./skip.txt")
puts
puts "\e[1;36mSkipped tests:\e[0m"
puts IO.read("./skip.txt")
end
end
end

desc "Generate codes"
task :generate do
require_relative "scripts/gen_alu"
Expand Down
19 changes: 14 additions & 5 deletions spec/runner.rb
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,8 @@
require "wardite"
require "test-unit"

testcase = JSON.load_file("spec/i32.json", symbolize_names: true)
json_path = ENV['JSON_PATH'] || File.expand_path("../i32.json", __FILE__)
testcase = JSON.load_file(json_path, symbolize_names: true)

$commands = testcase[:commands]

Expand All @@ -28,6 +29,10 @@ def parse_result(arg)
end
end

BEGIN {
File.delete(File.expand_path("../skip.txt", __FILE__)) if File.exist?(File.expand_path("../skip.txt", __FILE__))
}

class WarditeI32Test < Test::Unit::TestCase
extend Wardite::ValueHelper
current_wasm = nil
Expand All @@ -52,7 +57,7 @@ class WarditeI32Test < Test::Unit::TestCase
expected_ = expected.map{|v| parse_result(v)}

test "#{command_type}: (#{"%4d" % line}) #{field}(#{args_.inspect}) -> #{expected_.inspect}" do
instance = instance = Wardite::new(path: "spec/" + current_wasm)
instance = instance = Wardite::new(path: File.expand_path("../#{current_wasm}", __FILE__))
ret = instance.runtime.call(field, args_)

assert { ret == expected_[0] }
Expand All @@ -72,7 +77,7 @@ class WarditeI32Test < Test::Unit::TestCase
expected_ = expected.map{|v| parse_result(v)}

test "#{command_type}: (#{"%4d" % line}) #{field}(#{args_.inspect})" do
instance = instance = Wardite::new(path: "spec/" + current_wasm)
instance = instance = Wardite::new(path: File.expand_path("../#{current_wasm}", __FILE__))
command => {text:}
trapped = false
begin
Expand All @@ -87,8 +92,12 @@ class WarditeI32Test < Test::Unit::TestCase
end
end
when "assert_invalid", "assert_malformed"
test "#{command_type}: #{command.inspect}" do
omit "skip #{command_type}"
if ENV['VERBOSE']
test "#{command_type}: #{command.inspect}" do
omit "skip #{command_type}"
end
else
IO.write(File.expand_path("../skip.txt", __FILE__), "#{command_type}: #{command.inspect}\n", mode: "a")
end
end
end
Expand Down