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.

UvmInterpreterNativeTests.scala 2.62 KB
Newer Older
Kunshan Wang's avatar
Kunshan Wang committed
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
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

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

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

  "The CCALL instruction" should "call the getpid() function" in {
    val ca = microVM.newClientAgent()

    val lib = Library.getDefault()
    val funcAddr = lib.getSymbolAddress("getpid")

    val posix = POSIXFactory.getPOSIX
    val actualPID = posix.getpid

    println("actualPID = %d".format(actualPID))

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

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

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

      fp.vb.asPointer shouldEqual funcAddr
      rv.vb.asSInt(32) shouldEqual actualPID

      TrapRebindPassVoid(st)
    }

    ca.close()
  }

  "The CCALL instruction" should "call the write() function" in {
    val ca = microVM.newClientAgent()

    val lib = Library.getDefault()
    val funcAddr = lib.getSymbolAddress("write")

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

60
    val a0 = ca.putPointer("@write_fp", funcAddr)
Kunshan Wang's avatar
Kunshan Wang committed
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79

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

      fp.vb.asPointer shouldEqual funcAddr
      rv.vb.asSInt(64) shouldEqual 6

      TrapRebindPassVoid(st)
    }

    ca.close()
  }

  "The CCALL instruction" should "call the memcpy() function" in {
    val ca = microVM.newClientAgent()

    val lib = Library.getDefault()
    val funcAddr = lib.getSymbolAddress("memcpy")

80
81
82
    val hgfp = ca.putGlobal("@FP_MEMCPY")
    val hfp = ca.putPointer("@memcpy_fp", funcAddr)
    ca.store(MemoryOrder.NOT_ATOMIC, hgfp, hfp)
Kunshan Wang's avatar
Kunshan Wang committed
83

84
    val func = ca.putFunction("@memcpytest")
Kunshan Wang's avatar
Kunshan Wang committed
85

86
    testFunc(ca, func, Seq()) { (ca, th, st, wp) =>
Kunshan Wang's avatar
Kunshan Wang committed
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
      val Seq(fp, rv, ob, b0, b1, b2, b3, b4, b5) = ca.dumpKeepalives(st, 0)

      fp.vb.asPointer shouldEqual funcAddr
      rv.vb.asPointer shouldEqual ob.vb.asPointer

      b0.vb.asSInt(8) shouldEqual 'H'
      b1.vb.asSInt(8) shouldEqual 'e'
      b2.vb.asSInt(8) shouldEqual 'l'
      b3.vb.asSInt(8) shouldEqual 'l'
      b4.vb.asSInt(8) shouldEqual 'o'
      b5.vb.asSInt(8) shouldEqual '\n'

      TrapRebindPassVoid(st)
    }

    ca.close()
  }
}