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

BootImageWriterTest.scala 2.92 KB
Newer Older
1
2
3
4
5
6
7
8
9
package uvm.refimpl.bootimg

import uvm.refimpl.MicroVM
import uvm.refimpl.VMConf
import uvm.refimpl.UvmBundleTesterBase
import uvm.ir.textinput.ExtraMatchers
import uvm.ir.textinput.TestingBundlesValidators.MagicalOur
import uvm.refimpl.mem.HeaderUtils
import uvm.types.Type
10
import uvm.refimpl.Word
Kunshan Wang's avatar
Kunshan Wang committed
11
12
13
14
import uvm.utils.WithUtils._
import uvm.ssavariables.MemoryOrder
import uvm.refimpl.MuUPtrValue
import uvm.refimpl.MuUFPValue
15
16
17
18
19
20

class BootImageWriterTest extends UvmBundleTesterBase with ExtraMatchers {
  override def makeMicroVM = new MicroVM(new VMConf())

  preloadBundles("tests/uvm-refimpl-test/transitive-closure.uir")
  preloadHails("tests/uvm-refimpl-test/transitive-closure.hail")
Kunshan Wang's avatar
Kunshan Wang committed
21
22
23
24
25
26
27
28
29
30
31
32
  
  {
    tryWithResource(microVM.newContext()) { ctx => 
      val h_gs = ctx.handleFromGlobal("@gs")
      val h_gs_2 = ctx.getFieldIRef(h_gs, 2)
      val h_gs_2_ptr = ctx.getAddr(h_gs_2)
      val h_gs3 = ctx.handleFromGlobal("@gs3")
      val h_gs3_2 = ctx.getFieldIRef(h_gs3, 2)
      
      ctx.store(MemoryOrder.NOT_ATOMIC, h_gs3_2, h_gs_2_ptr)
    }
  }
33
34
35
36

  val our = new MagicalOur(microVM.globalBundle)

  behavior of "BootImageWriter"
Kunshan Wang's avatar
Kunshan Wang committed
37
  
38
39
40
  it should "write everything to files" in {
    val everything = microVM.globalBundle.allTopLevels()
    
Kunshan Wang's avatar
Kunshan Wang committed
41
    val tcb = new TransitiveClosureBuilder(everything, PrimordialInfo.NO_PRIMORDIAL)(microVM)
42
43
    tcb.doTransitiveClosure()

Kunshan Wang's avatar
Kunshan Wang committed
44
    val biw = new BootImageWriter(tcb, Seq(), Seq(), "target/boot-image-writer-test.muref")(microVM)
45
46
    biw.writeFile()
  }
Kunshan Wang's avatar
Kunshan Wang committed
47
48
49
50
51
  
  it should "write everything to files and read back" in {
    val filename = "target/boot-image-read-write-test.muref"
    val everything = microVM.globalBundle.allTopLevels()

Kunshan Wang's avatar
Kunshan Wang committed
52
53
54
55
56
    tryWithResource(microVM.newContext()) { ctx =>
      val h_gs3 = ctx.handleFromGlobal("@gs3")
      val h_gs3_3 = ctx.getFieldIRef(h_gs3, 3)
      ctx.makeBootImage(everything.map(_.id), None, None, None, Seq(), Seq(), Seq(h_gs3_3), Seq("getchar"), filename)
    }
Kunshan Wang's avatar
Kunshan Wang committed
57
58
59
60
61
    
    val anotherMicroVM = MicroVM()
    anotherMicroVM.loadBootImage(filename)
    
    microVM.globalBundle.allNs("@gd").id shouldEqual anotherMicroVM.globalBundle.allNs("@gd").id
Kunshan Wang's avatar
Kunshan Wang committed
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81

    tryWithResource(anotherMicroVM.newContext()) { ctx => 
      val h_gs = ctx.handleFromGlobal("@gs")
      val h_gs_2 = ctx.getFieldIRef(h_gs, 2)
      val h_gs_2_ptr = ctx.getAddr(h_gs_2)
      val h_gs3 = ctx.handleFromGlobal("@gs3")
      val h_gs3_2 = ctx.getFieldIRef(h_gs3, 2)
      val h_gs3_2_val = ctx.load(MemoryOrder.NOT_ATOMIC, h_gs3_2).asInstanceOf[MuUPtrValue]
      val h_gs3_3 = ctx.getFieldIRef(h_gs3, 3)
      val h_gs3_3_val = ctx.load(MemoryOrder.NOT_ATOMIC, h_gs3_3).asInstanceOf[MuUFPValue]
      
      val gs_2_ptr = ctx.handleToPtr(h_gs_2_ptr)
      val gs3_2_val = ctx.handleToPtr(h_gs3_2_val)
      val gs3_3_val = ctx.handleToFP(h_gs3_3_val)
      
      gs3_2_val shouldEqual gs_2_ptr
      
      val getchar_val = anotherMicroVM.nativeLibraryHolder.getSymbolAddress("getchar")
      gs3_3_val shouldEqual getchar_val
    }
Kunshan Wang's avatar
Kunshan Wang committed
82
  }
83
}