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.

To protect your data, the CISO officer has suggested users to enable 2FA as soon as possible.
Currently 2.7% of users enabled 2FA.

UvmInterpreterNativeTestsExtra.scala 3.64 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
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
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 com.kenai.jffi.Library
import jnr.posix.POSIXFactory
import jnr.ffi.LibraryLoader
import uvm.utils.HexDump

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

  val fileName = "tests/c-snippets/structtest.so"
  if (!new java.io.File(fileName).isFile()) {
    throw new RuntimeException("Need to compile the structtest.so library. cd into tests/c-snippets and invoke 'make'.")
  }

  preloadBundles("tests/uvm-refimpl-test/native-tests.uir")

  "The CCALL instruction" should "handle struct parameters in foo" in {
    val ca = microVM.newClientAgent()

    val lib = Library.openLibrary(fileName, Library.NOW)
    val funcAddr = lib.getSymbolAddress("foo_func")

    val func = ca.putFunction("@foo_func_test")

    val a0 = ca.putInt("@i64", funcAddr)

    testFunc(ca, func, Seq(a0)) { (ca, th, st, wp) =>
      val Seq(fp, rv, a, b, c, d) = ca.dumpKeepalives(st, 0)

      fp.vb.asPointer shouldEqual funcAddr

      // println("%x".format(a.vb.asUInt(64).toLong))

      a.vb.asUInt(64) shouldEqual 0x55aa55aa55aa55aaL
      b.vb.asUInt(32) shouldEqual 0x5a5a5a5a
      c.vb.asUInt(16) shouldEqual 0xa5a5
      d.vb.asUInt(8) shouldEqual 0x61

      TrapRebindPassVoid(st)
    }

    ca.close()
  }

  "The CCALL instruction" should "handle struct parameters in bar involving pointers" in {
    val ca = microVM.newClientAgent()

    val lib = Library.openLibrary(fileName, Library.NOW)
    val funcAddr = lib.getSymbolAddress("bar_func")

    val func = ca.putFunction("@bar_func_test")

    val a0 = ca.putInt("@i64", funcAddr)

    testFunc(ca, func, Seq(a0)) { (ca, th, st, wp) =>
      val Seq(fp, rv, a, b) = ca.dumpKeepalives(st, 0)

      fp.vb.asPointer shouldEqual funcAddr

      // println("%x".format(a.vb.asUInt(64).toLong))

      a.vb.asPointer shouldEqual 0x123456789abcdef0L
      b.vb.asPointer shouldEqual 0xfedcba9876543210L

      TrapRebindPassVoid(st)
    }

    ca.close()
  }

  "The CCALL instruction" should "handle struct parameters and return value in baz" in {
    val ca = microVM.newClientAgent()

    val lib = Library.openLibrary(fileName, Library.NOW)
    val funcAddr = lib.getSymbolAddress("baz_func")

    val func = ca.putFunction("@baz_func_test")

    val a0 = ca.putInt("@i64", funcAddr)

    testFunc(ca, func, Seq(a0)) { (ca, th, st, wp) =>
      val Seq(fp, rv, a, b, c, pextra, aextra) = ca.dumpKeepalives(st, 0)

      fp.vb.asPointer shouldEqual funcAddr

      val Seq(rab, rbb) = rv.vb.asStruct
      val Seq(raxb, rayb) = rab.asStruct

      raxb.asFloat shouldEqual 4.0f
      rayb.asSInt(32) shouldEqual 5
      rbb.asDouble shouldEqual 6.0

      // println("%x".format(a.vb.asUInt(64).toLong))

      a.vb.asFloat shouldEqual 1.0f
      b.vb.asSInt(32) shouldEqual 2
      c.vb.asDouble shouldEqual 3.0
      
      val ptr = pextra.vb.asPointer
      println("ptr is 0x%x".format(ptr))
      
      val (oref, off) = aextra.vb.asIRef
      
      println("oref, off is 0x%x 0x%x".format(oref, off))
      
      print(HexDump.dumpMemory(ptr-32, 16+64))

      val m = microVM.memoryManager.memorySupport.theMemory
      m.getFloat(ptr) shouldEqual 4.0f
      m.getInt(ptr+4) shouldEqual 5
      m.getDouble(ptr+8) shouldEqual 6.0
      
      TrapRebindPassVoid(st)
    }

    ca.close()
  }
}