GitLab will be upgraded on June 2nd 2020 at 2.00 pm (AEDT) to 3.00 pm (AEDT) due to Critical Security Patch Availability. During the update, GitLab and Mattermost services will not be available. If you have any concerns with this, please talk to local Gitlab admin team.

Commit 97e8b94f authored by Kunshan Wang's avatar Kunshan Wang

Fixed basic tests.

parent e05ae891
......@@ -77,7 +77,7 @@ class MicroVM(heapSize: Word = MicroVM.DEFAULT_HEAP_SIZE,
def idOf(name: String): Int = try {
globalBundle.allNs(name).id
} catch {
case e: NoSuchElementException => throw new UvmRefImplException("No Mu entity has name %s.".format(name), e)
case e: NoSuchElementException => throw new UvmRefImplException("No Mu entity has name %s".format(name), e)
}
/**
......@@ -86,7 +86,7 @@ class MicroVM(heapSize: Word = MicroVM.DEFAULT_HEAP_SIZE,
def nameOf(id: Int): String = try {
globalBundle.allNs(id).name.get
} catch {
case e: NoSuchElementException => throw new UvmRefImplException("No Mu entity has ID %d.".format(id), e)
case e: NoSuchElementException => throw new UvmRefImplException("No Mu entity has ID %d".format(id), e)
}
/**
......
......@@ -22,6 +22,7 @@ object MuValue {
case (t: TypeIRef, v: BoxIRef) => MuIRefValue(t, v)
case (t: TypeStruct, v: BoxSeq) => MuStructValue(t, v)
case (t: TypeArray, v: BoxSeq) => MuArrayValue(t, v)
case (t: TypeVector, v: BoxSeq) => MuVectorValue(t, v)
case (t: TypeFuncRef, v: BoxFunc) => MuFuncRefValue(t, v)
case (t: TypeThreadRef, v: BoxThread) => MuThreadRefValue(t, v)
case (t: TypeStackRef, v: BoxStack) => MuStackRefValue(t, v)
......
......@@ -74,7 +74,7 @@ object TypeInferer {
try {
resTys(r.index)
} catch {
case e: ArrayIndexOutOfBoundsException => throw new UvmRefImplException(
case e: IndexOutOfBoundsException => throw new UvmRefImplException(
s"Instruction ${r.inst} produces only ${resTys.size} results, but result index ${r.index} is requested")
}
}
......
......@@ -20,21 +20,24 @@ class ConstantPool(implicit microVM: MicroVM) {
}
def makeBox(g: GlobalVariable): ValueBox = g match {
case ConstInt(ty, num) => BoxInt(OpHelper.unprepare(num, ty.asInstanceOf[TypeInt].length))
case ConstFloat(ty, num) => BoxFloat(num)
case ConstInt(ty, num) => ty match {
case TypeInt(l) => BoxInt(OpHelper.unprepare(num, l))
case _: AbstractPointerType => BoxPointer(num.toLong)
}
case ConstFloat(ty, num) => BoxFloat(num)
case ConstDouble(ty, num) => BoxDouble(num)
case ConstSeq(ty, elems) => BoxSeq(elems.map(maybeMakeBox))
case ConstSeq(ty, elems) => BoxSeq(elems.map(maybeMakeBox))
case ConstNull(ty) => ty match {
case _:TypeRef => BoxRef(0L)
case _:TypeIRef => BoxIRef(0L, 0L)
case _:TypeFuncRef => BoxFunc(None)
case _:TypeThreadRef => BoxThread(None)
case _:TypeStackRef => BoxStack(None)
case _: TypeRef => BoxRef(0L)
case _: TypeIRef => BoxIRef(0L, 0L)
case _: TypeFuncRef => BoxFunc(None)
case _: TypeThreadRef => BoxThread(None)
case _: TypeStackRef => BoxStack(None)
}
case gc:GlobalCell => BoxIRef(0L, microVM.memoryManager.globalMemory.addrForGlobalCell(gc))
case f:Function => BoxFunc(Some(f))
case ef:ExposedFunc => BoxPointer(microVM.nativeCallHelper.getStaticExpFuncAddr(ef))
case gc: GlobalCell => BoxIRef(0L, microVM.memoryManager.globalMemory.addrForGlobalCell(gc))
case f: Function => BoxFunc(Some(f))
case ef: ExposedFunc => BoxPointer(microVM.nativeCallHelper.getStaticExpFuncAddr(ef))
}
def getGlobalVarBox(g: GlobalVariable): ValueBox = globalVarBoxes(g)
}
\ No newline at end of file
......@@ -45,31 +45,33 @@ abstract class UvmBundleTesterBase extends FlatSpec with Matchers {
implicit def nameOf(id: Int): String = microVM.nameOf(id)
def preloadBundles(fileNames: String*): Unit = {
val ca = microVM.newClientAgent()
val ctx = microVM.newContext()
for (fn <- fileNames) {
val r = new FileReader(fn)
ca.loadBundle(r)
ctx.loadBundle(r)
r.close()
}
ca.close()
ctx.closeContext()
}
type TrapHandlerFunction = (ClientAgent, Handle, Handle, Int) => TrapHandlerResult
type TrapHandlerFunction = (MuCtx, MuThreadRefValue, MuStackRefValue, Int) => TrapHandlerResult
class MockTrapHandler(thf: TrapHandlerFunction) extends TrapHandler {
def handleTrap(ca: ClientAgent, thread: Handle, stack: Handle, watchPointID: Int): TrapHandlerResult = {
thf(ca, thread, stack, watchPointID)
def handleTrap(ctx: MuCtx, thread: MuThreadRefValue, stack: MuStackRefValue, watchPointID: Int): TrapHandlerResult = {
thf(ctx, thread, stack, watchPointID)
}
}
def testFunc(ca: ClientAgent, func: Handle, args: Seq[Handle])(handler: TrapHandlerFunction): Unit = {
def testFunc(ctx: MuCtx, func: MuFuncRefValue, args: Seq[MuValue])(handler: TrapHandlerFunction): Unit = {
microVM.trapManager.trapHandler = new MockTrapHandler(handler)
val hStack = ca.newStack(func)
val hThread = ca.newThread(hStack)
val hStack = ctx.newStack(func)
val hThread = ctx.newThread(hStack, HowToResume.PassValues(args))
microVM.execute()
}
implicit def magicalMuValue(mv: MuValue): MagicalBox = MagicalBox(mv.vb)
implicit class MagicalBox(vb: ValueBox) {
def asInt: BigInt = vb.asInstanceOf[BoxInt].value
......@@ -80,7 +82,7 @@ abstract class UvmBundleTesterBase extends FlatSpec with Matchers {
def asRef: Word = vb.asInstanceOf[BoxRef].objRef
def asIRef: (Word, Word) = { val b = vb.asInstanceOf[BoxIRef]; (b.objRef, b.offset) }
def asIRefAddr: Word = { val b = vb.asInstanceOf[BoxIRef]; b.objRef + b.offset }
def asStruct: Seq[ValueBox] = vb.asInstanceOf[BoxStruct].values
def asStruct: Seq[ValueBox] = vb.asInstanceOf[BoxSeq].values
def asFunc: Option[Function] = vb.asInstanceOf[BoxFunc].func
def asThread: Option[InterpreterThread] = vb.asInstanceOf[BoxThread].thread
def asStack: Option[InterpreterStack] = vb.asInstanceOf[BoxStack].stack
......@@ -90,4 +92,10 @@ abstract class UvmBundleTesterBase extends FlatSpec with Matchers {
def asVec: Seq[ValueBox] = vb.asInstanceOf[BoxSeq].values
def asPointer: Word = vb.asInstanceOf[BoxPointer].addr
}
implicit class RichMuCtx(ctx: MuCtx) {
def i32(num: BigInt) = ctx.handleFromInt(num, 32)
def i64(num: BigInt) = ctx.handleFromInt(num, 64)
def func(id: Int) = ctx.handleFromFunc(id)
}
}
\ No newline at end of file
package uvm.refimpl
package uvm.refimpl.osr
import org.scalatest._
import java.io.FileReader
......
This diff is collapsed.
.typedef @i8 = int<8>
.typedef @i16 = int<16>
.typedef @i32 = int<32>
.typedef @i64 = int<64>
.typedef @float = float
.typedef @double = double
.typedef @i1 = int<1>
.typedef @i6 = int<6>
.typedef @i8 = int<8>
.typedef @i16 = int<16>
.typedef @i32 = int<32>
.typedef @i52 = int<52>
.typedef @i64 = int<64>
.typedef @float = float
.typedef @double = double
.typedef @void = void
.typedef @void = void
.funcsig @noparamsnoret = @void ()
.typedef @thread = threadref
.typedef @stack = stackref
.typedef @tagref64 = tagref64
.typedef @thread = threadref
.typedef @stack = stackref
.typedef @tagref64 = tagref64
.typedef @4xi32 = vector <@i32 4>
.typedef @4xfloat = vector <@float 4>
.typedef @2xdouble = vector <@double 2>
// some abnormal vector sizes for trunc/ext tests and select tests
.typedef @4xi1 = vector <@i1 4>
.typedef @4xi16 = vector <@i16 4>
.typedef @4xi64 = vector <@i64 4>
.typedef @2xfloat = vector <@float 2>
.typedef @4xdouble = vector <@double 4>
.typedef @refi64 = ref<@i64>
.typedef @irefi64 = iref<@i64>
.typedef @weakrefi64 = weakref<@i64>
.typedef @refvoid = ref<@void>
.typedef @irefvoid = iref<@void>
.typedef @weakrefvoid = weakref<@void>
.typedef @frv_v = funcref<@v_v>
.typedef @ptrvoid = uptr<@void>
.typedef @ptri8 = uptr<@i8>
.typedef @ptri16 = uptr<@i16>
.typedef @ptri32 = uptr<@i32>
.typedef @ptri64 = uptr<@i64>
.typedef @ptrfloat = uptr<@float>
.typedef @ptrdouble = uptr<@double>
.typedef @ptrptrvoid = uptr<@ptrvoid>
.typedef @ptrfpi_i = uptr<@fpi_i>
.typedef @fpv_v = ufuncptr<@v_v>
.typedef @fpi_i = ufuncptr<@i_i>
.typedef @fpii_i = ufuncptr<@ii_i>
.funcsig @v_v = () -> ()
.funcsig @i_i = (@i64) -> (@i64)
.funcsig @ii_i = (@i64 @i64) -> (@i64)
.const @TRUE <@i64> = 1
.const @FALSE <@i64> = 0
.funcsig @i_i = @i64 (@i64)
.funcsig @i_ii = @i64 (@i64 @i64)
.typedef @refvoid = ref<@void>
.const @NULLREF <@refvoid> = NULL
.const @I32_0 <@i32> = 0
.const @I32_1 <@i32> = 1
.const @I32_2 <@i32> = 2
.const @I32_3 <@i32> = 3
.const @I32_4 <@i32> = 4
.const @I32_5 <@i32> = 5
.const @I32_6 <@i32> = 6
.const @I32_7 <@i32> = 7
.const @I32_8 <@i32> = 8
.const @I32_9 <@i32> = 9
.const @VOID <@void> = NULL
.const @I32_10 <@i32> = 10
.const @I32_20 <@i32> = 20
.const @I32_30 <@i32> = 30
.const @I32_40 <@i32> = 40
.const @I32_50 <@i32> = 50
.const @I32_100 <@i32> = 100
.typedef @refi64 = ref<@i64>
.typedef @irefi64 = iref<@i64>
.typedef @weakrefi64 = weakref<@i64>
.const @I64_0 <@i64> = 0
.const @I64_1 <@i64> = 1
.const @I64_2 <@i64> = 2
.const @I64_3 <@i64> = 3
.const @I64_4 <@i64> = 4
.const @I64_5 <@i64> = 5
.const @I64_6 <@i64> = 6
.const @I64_7 <@i64> = 7
.const @I64_8 <@i64> = 8
.const @I64_9 <@i64> = 9
.const @I64_0 <@i64> = 0
.const @I64_1 <@i64> = 1
.const @I64_2 <@i64> = 2
.const @I64_10 <@i64> = 10
.const @I64_20 <@i64> = 20
.const @I64_30 <@i64> = 30
.const @I64_40 <@i64> = 40
.const @I64_50 <@i64> = 50
.const @I64_100 <@i64> = 100
.const @F_0 <@float> = 0.0f
.const @F_1 <@float> = 1.0f
.const @F_2 <@float> = 2.0f
.const @F_3 <@float> = 3.0f
.const @F_4 <@float> = 4.0f
.const @F_5 <@float> = 5.0f
.const @F_6 <@float> = 6.0f
.const @F_7 <@float> = 7.0f
.const @F_8 <@float> = 8.0f
.const @F_9 <@float> = 9.0f
.const @F_10 <@float> = 10.0f
.const @F_20 <@float> = 20.0f
.const @F_30 <@float> = 30.0f
.const @F_40 <@float> = 40.0f
.const @F_50 <@float> = 50.0f
.const @F_100 <@float> = 100.0f
.const @F_NAN <@float> = nanf
.const @D_0 <@double> = 0.0d
.const @D_1 <@double> = 1.0d
.const @D_2 <@double> = 2.0d
.const @D_3 <@double> = 3.0d
.const @D_4 <@double> = 4.0d
.const @D_5 <@double> = 5.0d
.const @D_6 <@double> = 6.0d
.const @D_7 <@double> = 7.0d
.const @D_8 <@double> = 8.0d
.const @D_9 <@double> = 9.0d
.const @D_10 <@double> = 10.0d
.const @D_20 <@double> = 20.0d
.const @D_30 <@double> = 30.0d
.const @D_40 <@double> = 40.0d
.const @D_50 <@double> = 50.0d
.const @D_100 <@double> = 100.0d
.const @D_NAN <@float> = nand
.const @4xI32_V1 <@4xi32> = {@I32_0 @I32_1 @I32_2 @I32_3}
.const @4xI32_V2 <@4xi32> = {@I32_4 @I32_5 @I32_6 @I32_7}
.const @4xI32_V3 <@4xi32> = {@I32_1 @I32_2 @I32_3 @I32_4}
.const @4xI32_V4 <@4xi32> = {@I32_10 @I32_20 @I32_30 @I32_40}
.const @4xI32_V5 <@4xi32> = {@I32_1 @I32_1 @I32_2 @I32_2}
.const @4xI32_V6 <@4xi32> = {@I32_1 @I32_2 @I32_1 @I32_2}
.const @4xF_V1 <@4xfloat> = {@F_0 @F_1 @F_2 @F_3}
.const @4xF_V2 <@4xfloat> = {@F_4 @F_5 @F_6 @F_7}
.const @4xF_V3 <@4xfloat> = {@F_1 @F_2 @F_3 @F_4}
.const @4xF_V4 <@4xfloat> = {@F_10 @F_20 @F_30 @F_40}
.const @4xF_V5 <@4xfloat> = {@F_1 @F_1 @F_2 @F_2}
.const @4xF_V6 <@4xfloat> = {@F_1 @F_2 @F_1 @F_2}
.const @4xF_V7 <@4xfloat> = {@F_NAN @F_NAN @F_NAN @F_NAN}
.const @2xD_V1 <@2xdouble> = {@D_0 @D_1}
.const @2xD_V2 <@2xdouble> = {@D_2 @D_3}
.const @2xD_V3 <@2xdouble> = {@D_1 @D_2}
.const @2xD_V4 <@2xdouble> = {@D_10 @D_20}
.const @2xD_V5 <@2xdouble> = {@D_1 @D_2}
.const @2xD_V6 <@2xdouble> = {@D_2 @D_2}
.const @2xD_V7 <@2xdouble> = {@D_NAN @D_NAN}
// some abnormal vectors
.const @I32_ABNORMAL0 <@i32> = 0x12345678
.const @I32_ABNORMAL1 <@i32> = 0x9abcdef0
.const @I32_ABNORMAL2 <@i32> = 0xfedcba98
.const @I32_ABNORMAL3 <@i32> = 0x76543210
.const @4xI32_ABNORMALV1 <@4xi32> = {@I32_ABNORMAL0 @I32_ABNORMAL1 @I32_ABNORMAL2 @I32_ABNORMAL3}
.const @F_1P5 <@float> = 1.5f
.const @F_2P5 <@float> = 2.5f
.const @4xF_ABNORMALV1 <@4xfloat> = {@F_1 @F_1P5 @F_2 @F_2P5}
.const @D_1P5 <@double> = 1.5d
.const @2xD_ABNORMALV1 <@2xdouble> = {@D_1 @D_1P5}
.const @NULLREF <@refvoid> = NULL
.const @NULLIREF <@irefvoid> = NULL
.const @NULLFUNC <@frv_v> = NULL
.const @NULLSTACK <@stack> = NULL
.const @NULLREF_I64 <@refi64> = NULL
.const @NULLIREF_I64 <@irefi64> = NULL
.const @PTRVOID_DUMMY1 <@ptrvoid> = 0xdeadbeef13572468
.const @FPI_I_DUMMY2 <@fpi_i> = 0x55aa55aa5a5a5a5a
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment