WARNING! Access to this system is limited to authorised users only.
Unauthorised users may be subject to prosecution.
Unauthorised access to this system is a criminal offence under Australian law (Federal Crimes Act 1914 Part VIA)
It is a criminal offence to:
(1) Obtain access to data without authority. -Penalty 2 years imprisonment.
(2) Damage, delete, alter or insert data without authority. -Penalty 10 years imprisonment.
User activity is monitored and recorded. Anyone using this system expressly consents to such monitoring and recording.

Commit 544b3598 authored by Kunshan Wang's avatar Kunshan Wang
Browse files

Summing test.

parent fd391284
package uvm.refimpl.itpr
import org.scalatest._
import java.io.FileReader
import uvm._
import uvm.types._
import uvm.ssavariables._
import uvm.refimpl._
import uvm.refimpl.itpr._
import MemoryOrder._
import AtomicRMWOptr._
import uvm.refimpl.mem.TypeSizes.Word
import ch.qos.logback.classic.Level._
import uvm.refimpl.UvmBundleTesterBase
class UvmInterpreterSimpleTests extends UvmBundleTesterBase {
setLogLevels(
ROOT_LOGGER_NAME -> INFO,
"uvm.refimpl.itpr" -> DEBUG)
preloadBundles("tests/uvm-refimpl-test/primitives.uir",
"tests/uvm-refimpl-test/simple-tests.uir")
"Factorial functions" should "work" in {
val ca = microVM.newClientAgent()
val func = ca.putFunction("@test_fac")
testFunc(ca, func, Seq()) { (ca, th, st, wp) =>
val Seq(r1, r2, r3) = ca.dumpKeepalives(st, 0)
r1.vb.asInt shouldEqual 3628800
r2.vb.asInt shouldEqual 3628800
r3.vb.asInt shouldEqual 3628800
TrapRebindPassVoid(st)
}
ca.close()
}
"Fibonacci functions" should "work" in {
val ca = microVM.newClientAgent()
val func = ca.putFunction("@test_fib")
val watch = true
testFunc(ca, func, Seq()) { (ca, th, st, wp) =>
val trapName = nameOf(ca.currentInstruction(st, 0))
trapName match {
case "@fibonacci_mat_v1.watch" => {
if (watch) {
val vhs = ca.dumpKeepalives(st, 0)
val vs = vhs.map(_.vb.asInt)
println("watch " + vs)
}
TrapRebindPassVoid(st)
}
case "@test_fib_v1.checktrap" => {
val Seq(r1, r2) = ca.dumpKeepalives(st, 0)
r1.vb.asInt shouldEqual 55
r2.vb.asInt shouldEqual 55
TrapRebindPassVoid(st)
}
case _ => fail("Should not hit " + trapName)
}
}
ca.close()
}
"Coroutine test" should "work" in {
val ca = microVM.newClientAgent()
val func = ca.putFunction("@test_coroutine")
testFunc(ca, func, Seq()) { (ca, th, st, wp) =>
val trapName = nameOf(ca.currentInstruction(st, 0))
trapName match {
case "@test_coroutine_v1.trap_body" => {
val Seq(v) = ca.dumpKeepalives(st, 0)
println(v.vb.asSInt(64))
TrapRebindPassVoid(st)
}
case "@test_coroutine_v1.trap_exit" => {
val Seq(exc) = ca.dumpKeepalives(st, 0)
val hsi = ca.putGlobal("@StopIteration")
val hrsi = ca.load(MemoryOrder.NOT_ATOMIC, hsi)
exc.vb.asRef shouldEqual hrsi.vb.asRef
TrapRebindPassVoid(st)
}
case _ => fail("Should not hit " + trapName)
}
}
ca.close()
}
"Multi-threading test" should "work" in {
val ca = microVM.newClientAgent()
val func = ca.putFunction("@test_multithreading")
testFunc(ca, func, Seq()) { (ca, th, st, wp) =>
val trapName = nameOf(ca.currentInstruction(st, 0))
trapName match {
case "@test_multithreading_v1.trap_result" => {
val Seq(v) = ca.dumpKeepalives(st, 0)
v.vb.asSInt(64) shouldEqual 4950
TrapRebindPassVoid(st)
}
case _ => fail("Should not hit " + trapName)
}
}
ca.close()
}
}
\ No newline at end of file
......@@ -13,119 +13,50 @@ import uvm.refimpl.mem.TypeSizes.Word
import ch.qos.logback.classic.Level._
import uvm.refimpl.UvmBundleTesterBase
class UvmInterpreterSimpleTests extends UvmBundleTesterBase {
class UvmInterpreterSimpleSumTest extends UvmBundleTesterBase {
setLogLevels(
ROOT_LOGGER_NAME -> INFO,
"uvm.refimpl.itpr" -> DEBUG)
"uvm.refimpl.itpr" -> INFO)
preloadBundles("tests/uvm-refimpl-test/primitives.uir",
"tests/uvm-refimpl-test/simple-tests.uir")
"tests/uvm-refimpl-test/simple-sum.uir")
"Factorial functions" should "work" in {
"Simple sum" should "work" in {
val ca = microVM.newClientAgent()
val func = ca.putFunction("@test_fac")
val from = 1L
val to = 1000000L
val expectedSum = (from + to) * (to - from + 1L) / 2L
testFunc(ca, func, Seq()) { (ca, th, st, wp) =>
val Seq(r1, r2, r3) = ca.dumpKeepalives(st, 0)
val hFrom = ca.putInt("@i64", from)
val hTo = ca.putInt("@i64", to)
r1.vb.asInt shouldEqual 3628800
r2.vb.asInt shouldEqual 3628800
r3.vb.asInt shouldEqual 3628800
val func = ca.putFunction("@simplesum")
TrapRebindPassVoid(st)
}
ca.close()
}
"Fibonacci functions" should "work" in {
val ca = microVM.newClientAgent()
val func = ca.putFunction("@test_fib")
val watch = true
testFunc(ca, func, Seq()) { (ca, th, st, wp) =>
val trapName = nameOf(ca.currentInstruction(st, 0))
trapName match {
case "@fibonacci_mat_v1.watch" => {
if (watch) {
val vhs = ca.dumpKeepalives(st, 0)
val vs = vhs.map(_.vb.asInt)
println("watch " + vs)
}
TrapRebindPassVoid(st)
}
case "@test_fib_v1.checktrap" => {
val Seq(r1, r2) = ca.dumpKeepalives(st, 0)
r1.vb.asInt shouldEqual 55
r2.vb.asInt shouldEqual 55
var t1: Long = 0L
var t2: Long = 0L
testFunc(ca, func, Seq(hFrom, hTo)) { (ca, th, st, wp) =>
nameOf(ca.currentInstruction(st, 0)) match {
case "@simplesum_v1.starttrap" => {
t1 = System.currentTimeMillis()
TrapRebindPassVoid(st)
}
case _ => fail("Should not hit " + trapName)
}
}
ca.close()
}
"Coroutine test" should "work" in {
val ca = microVM.newClientAgent()
case "@simplesum_v1.exittrap" => {
t2 = System.currentTimeMillis()
val func = ca.putFunction("@test_coroutine")
val Seq(sum) = ca.dumpKeepalives(st, 0)
testFunc(ca, func, Seq()) { (ca, th, st, wp) =>
val trapName = nameOf(ca.currentInstruction(st, 0))
trapName match {
case "@test_coroutine_v1.trap_body" => {
val Seq(v) = ca.dumpKeepalives(st, 0)
println(v.vb.asSInt(64))
TrapRebindPassVoid(st)
}
case "@test_coroutine_v1.trap_exit" => {
val Seq(exc) = ca.dumpKeepalives(st, 0)
val hsi = ca.putGlobal("@StopIteration")
val hrsi = ca.load(MemoryOrder.NOT_ATOMIC, hsi)
exc.vb.asRef shouldEqual hrsi.vb.asRef
sum.vb.asSInt(64) shouldBe expectedSum
TrapRebindPassVoid(st)
}
case _ => fail("Should not hit " + trapName)
}
}
ca.close()
}
"Multi-threading test" should "work" in {
val ca = microVM.newClientAgent()
val func = ca.putFunction("@test_multithreading")
testFunc(ca, func, Seq()) { (ca, th, st, wp) =>
val trapName = nameOf(ca.currentInstruction(st, 0))
trapName match {
case "@test_multithreading_v1.trap_result" => {
val Seq(v) = ca.dumpKeepalives(st, 0)
v.vb.asSInt(64) shouldEqual 4950
TrapRebindPassVoid(st)
}
case _ => fail("Should not hit " + trapName)
}
}
ca.close()
val timeDiff = t2 - t1
printf("Time: %d ms".format(timeDiff))
}
}
\ No newline at end of file
......@@ -828,28 +828,4 @@
%i_is_f %i_is_i %i_is_r %r_is_f %r_is_i %r_is_r %fb %ib %rb %rt)
COMMINST @uvm.thread_exit
}
// ///////////////////////// Simple sum
//
// .funcsig @simplesum_sig = @void (@i64 @i64)
// .funcdef @simplesum VERSION @simplesum_v1 <@simplesum_sig> (%from %to) {
// %entry:
// //BRANCH %head
// %starttrap = TRAP <@void> %head %head KEEPALIVE ()
//
// %head:
// %sum = PHI <@i64> { %entry: 0; %body: %sum2; }
// %i = PHI <@i64> { %entry: %from; %body: %i2; }
// %le = SLE <@i64> %i %to
// BRANCH2 %le %body %exit
//
// %body:
// %sum2 = ADD <@i64> %sum %i
// %i2 = ADD <@i64> %i 1
// BRANCH %head
// //%montrap = TRAP <@void> %head %head KEEPALIVE (%from %to %sum %i %le %sum2 %i2)
//
// %exit:
// %exittrap = TRAP <@void> KEEPALIVE (%sum) // should stop thread
// COMMINST @uvm.thread_exit
// }
// require "primitives.uir"
.funcsig @simplesum_sig = @void (@i64 @i64)
.funcdef @simplesum VERSION @simplesum_v1 <@simplesum_sig> (%from %to) {
%entry:
%starttrap = TRAP <@void>
BRANCH %head
%head:
%sum = PHI <@i64> { %entry: @I64_0; %body: %sum2; }
%i = PHI <@i64> { %entry: %from; %body: %i2; }
%le = SLE <@i64> %i %to
BRANCH2 %le %body %exit
%body:
%sum2 = ADD <@i64> %sum %i
%i2 = ADD <@i64> %i @I64_1
BRANCH %head
//%montrap = TRAP <@void> %head %head KEEPALIVE (%from %to %sum %i %le %sum2 %i2)
%exit:
%exittrap = TRAP <@void> KEEPALIVE (%sum)
COMMINST @uvm.thread_exit
}
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