Skip to content

Commit

Permalink
update test case
Browse files Browse the repository at this point in the history
  • Loading branch information
Kraks committed Oct 17, 2024
1 parent 9cc5940 commit 044da0b
Show file tree
Hide file tree
Showing 2 changed files with 37 additions and 32 deletions.
16 changes: 7 additions & 9 deletions benchmarks/wasm/loop_poly.wat
Original file line number Diff line number Diff line change
Expand Up @@ -5,18 +5,16 @@
i32.const 42
i32.const 0
block (param i32 i32) (result i32 i32)
loop (type 1) (param i32) (result i32) ;; label = @1
;; this type use will be ignored for now
loop (type 1) (param i32) (result i32) ;; label = @1
i32.const 1
i32.const 2
br 1 (;@1;)
end
end
end
;; - [return, 0 ]
i32.add
drop
;; this is not a valid wasm program due to the mismatch of stack shape,
;; we only do this for testing purposes.
;; i32.add
;; drop
)

;; (export "main" (func $test_poly_loop))
(start 0)
(start 0)
)
53 changes: 30 additions & 23 deletions src/test/scala/genwasym/TestEval.scala
Original file line number Diff line number Diff line change
Expand Up @@ -14,14 +14,22 @@ import collection.mutable.ArrayBuffer
import org.scalatest.FunSuite

class TestEval extends FunSuite {
def testFile(filename: String, main: Option[String] = None, expected: Option[Int] = None) = {
abstract class ExpResult
case class ExpInt(i: Int) extends ExpResult
case class ExpStack(stack: List[Value]) extends ExpResult
case object Ignore extends ExpResult

implicit def toI32V(i: Int): Value = I32V(i)

def testFile(filename: String, main: Option[String] = None, expected: ExpResult = Ignore) = {
val module = Parser.parseFile(filename)
//println(module)
val haltK: Evaluator.Cont[Unit] = stack => {
println(s"halt cont: $stack")
expected match {
case Some(e) => assert(stack(0) == I32V(e))
case None => ()
case ExpInt(e) => assert(stack(0) == I32V(e))
case ExpStack(e) => assert(stack == e)
case Ignore => ()
}
}
Evaluator.evalTop(module, haltK, main)
Expand All @@ -30,38 +38,37 @@ class TestEval extends FunSuite {
// TODO: the power test can be used to test the stack
// For now: 2^10 works, 2^100 results in 0 (TODO: why?),
// and 2^1000 results in a stack overflow
test("ack") { testFile("./benchmarks/wasm/ack.wat", Some("real_main"), Some(7)) }
test("power") { testFile("./benchmarks/wasm/pow.wat", Some("real_main"), Some(1024)) }
test("ack") { testFile("./benchmarks/wasm/ack.wat", Some("real_main"), ExpInt(7)) }
test("power") { testFile("./benchmarks/wasm/pow.wat", Some("real_main"), ExpInt(1024)) }
test("start") { testFile("./benchmarks/wasm/start.wat") }
test("fact") { testFile("./benchmarks/wasm/fact.wat", None, Some(120)) }
test("loop") { testFile("./benchmarks/wasm/loop.wat", None, Some(10)) }
test("even-odd") { testFile("./benchmarks/wasm/even_odd.wat", None, Some(1)) }
test("load") { testFile("./benchmarks/wasm/load.wat", None, Some(1)) }
test("fact") { testFile("./benchmarks/wasm/fact.wat", None, ExpInt(120)) }
test("loop") { testFile("./benchmarks/wasm/loop.wat", None, ExpInt(10)) }
test("even-odd") { testFile("./benchmarks/wasm/even_odd.wat", None, ExpInt(1)) }
test("load") { testFile("./benchmarks/wasm/load.wat", None, ExpInt(1)) }
test("btree") { testFile("./benchmarks/wasm/btree/2o1u-unlabeled.wat") }
test("fib") { testFile("./benchmarks/wasm/fib.wat", None, Some(144)) }
test("tribonacci") { testFile("./benchmarks/wasm/tribonacci.wat", None, Some(504)) }
test("fib") { testFile("./benchmarks/wasm/fib.wat", None, ExpInt(144)) }
test("tribonacci") { testFile("./benchmarks/wasm/tribonacci.wat", None, ExpInt(504)) }

test("return") {
intercept[gensym.wasm.miniwasm.Trap] {
testFile("./benchmarks/wasm/return.wat", Some("$real_main"), None)
testFile("./benchmarks/wasm/return.wat", Some("$real_main"))
}
}

test("input_block.block") {
testFile("./benchmarks/wasm/block.wat", Some("real_main"), Some(9))
test("block input") {
testFile("./benchmarks/wasm/block.wat", Some("real_main"), ExpInt(9))
}
test("input_block.loop") {
testFile("./benchmarks/wasm/block.wat", Some("test_loop_input"), Some(55))
test("loop block input") {
testFile("./benchmarks/wasm/block.wat", Some("test_loop_input"), ExpInt(55))
}
test("input_block.if") {
testFile("./benchmarks/wasm/block.wat", Some("test_if_input"), Some(25))
test("if block input") {
testFile("./benchmarks/wasm/block.wat", Some("test_if_input"), ExpInt(25))
}
test("input_block.poly_br") {
testFile("./benchmarks/wasm/block.wat", Some("test_poly_br"), Some(0))
test("block input - poly br") {
testFile("./benchmarks/wasm/block.wat", Some("test_poly_br"), ExpInt(0))
}

test("poly loop") {
testFile("./benchmarks/wasm/loop_poly.wat", None , None)
test("loop block - poly br") {
testFile("./benchmarks/wasm/loop_poly.wat", None, ExpStack(List(2, 1)))
}

// FIXME:
Expand Down

0 comments on commit 044da0b

Please sign in to comment.