To protect your data, the CISO officer has suggested users to enable GitLab 2FA as soon as possible.

UvmInterpreterTestBigFunc.scala 1.91 KB
Newer Older
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
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
import java.io.StringReader

class UvmInterpreterTestBigFunc extends UvmBundleTesterBase {
  setLogLevels(
    ROOT_LOGGER_NAME -> INFO,
    "uvm.refimpl.itpr" -> DEBUG)

  preloadBundles("tests/uvm-refimpl-test/extra-big-func.uir")

  "The extra big function" should "execute properly" in {
Kunshan Wang's avatar
Kunshan Wang committed
25
    val ctx = microVM.newContext()
26

Kunshan Wang's avatar
Kunshan Wang committed
27
28
    val func = ctx.handleFromFunc("@big")
    val hParam = ctx.handleFromInt64(0)
29

Kunshan Wang's avatar
Kunshan Wang committed
30
31
    testFunc(ctx, func, Seq(hParam)) { (ctx, th, st, wp) =>
      val Seq(i) = ctx.dumpKeepalives(st, 0)
32

Kunshan Wang's avatar
Kunshan Wang committed
33
      ctx.handleToSInt(i.asInstanceOf[MuIntValue]) shouldEqual 200
34

Kunshan Wang's avatar
Kunshan Wang committed
35
      returnFromTrap(st)
36
37
    }

Kunshan Wang's avatar
Kunshan Wang committed
38
    ctx.closeContext()
39
  }
Kunshan Wang's avatar
Kunshan Wang committed
40

41
  "The Micro VM" should "sustain frequent bundle loading" in {
Kunshan Wang's avatar
Kunshan Wang committed
42
43
44
    val ctx = microVM.newContext()

    for (i <- 0 until 1000) {
45
      val miniBundle = s".global @h${i} <@i64>"
Kunshan Wang's avatar
Kunshan Wang committed
46
      ctx.loadBundle(miniBundle)
47
    }
Kunshan Wang's avatar
Kunshan Wang committed
48

49
    val sb = new StringBuilder()
50
51
    sb ++= ".funcdef @bigger VERSION @bigger.v1 <@big.sig> {\n"
    sb ++= "     %entry(<@i64> %p):\n"
Kunshan Wang's avatar
Kunshan Wang committed
52
53
    for (i <- 0 until 1000) {
      sb ++= s"        [%s${i}] STORE <@i64> @h${i} %p\n"
54
    }
Kunshan Wang's avatar
Kunshan Wang committed
55
    sb ++= "        TRAP <>\n"
56
57
    sb ++= "        COMMINST @uvm.thread_exit\n"
    sb ++= "}"
Kunshan Wang's avatar
Kunshan Wang committed
58
59
60
61
62
63
64
65
66
67
68

    ctx.loadBundle(sb.toString())

    val func = ctx.handleFromFunc("@bigger")
    val hParam = ctx.handleFromInt64(42)

    testFunc(ctx, func, Seq(hParam)) { (ctx, th, st, wp) =>
      val hr = ctx.handleFromGlobal("@h12")
      val hv = ctx.load(MemoryOrder.NOT_ATOMIC, hr)
      val v = ctx.handleToSInt(hv.asInstanceOf[MuIntValue]).toInt

69
70
      v shouldEqual 42

Kunshan Wang's avatar
Kunshan Wang committed
71
      returnFromTrap(st)
72
73
    }

Kunshan Wang's avatar
Kunshan Wang committed
74
    ctx.closeContext()
75
76
  }
}