Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Support
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
M
mu-impl-ref2
Project overview
Project overview
Details
Activity
Releases
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Issues
5
Issues
5
List
Boards
Labels
Milestones
Merge Requests
2
Merge Requests
2
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Analytics
Analytics
CI / CD
Repository
Value Stream
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
mu
mu-impl-ref2
Commits
22b19464
Commit
22b19464
authored
Sep 02, 2015
by
Kunshan Wang
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Test MemorySupport
parent
e4fdc4b2
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
85 additions
and
0 deletions
+85
-0
src/test/scala/uvm/refimpl/mem/NativeMemoryAccessTest.scala
src/test/scala/uvm/refimpl/mem/NativeMemoryAccessTest.scala
+85
-0
No files found.
src/test/scala/uvm/refimpl/mem/NativeMemoryAccessTest.scala
0 → 100644
View file @
22b19464
package
uvm.refimpl.mem
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._
class
NativeMemoryAccessTest
extends
FlatSpec
with
Matchers
{
behavior
of
"The JNR-FFI-based native memory support"
it
should
"Allocate memory and do basic access"
in
{
val
ms
=
new
MemorySupport
(
1024L
)
val
begin
=
ms
.
muMemoryBegin
ms
.
storeI128
(
begin
,
(
0x55555555aaaaaaaa
L
,
0xaaaaaaaa55555555
L
))
ms
.
storeLong
(
begin
+
16
,
0x55aa55aa55aa55aa
L
)
ms
.
storeInt
(
begin
+
24
,
0x5a5a5a5a
)
ms
.
storeShort
(
begin
+
28
,
0x55a5
)
ms
.
storeByte
(
begin
+
30
,
0x5a
)
ms
.
storeDouble
(
begin
+
32
,
3.14
)
ms
.
storeFloat
(
begin
+
40
,
6.28F
)
ms
.
loadDouble
(
begin
+
32
)
shouldBe
3.14
ms
.
loadFloat
(
begin
+
40
)
shouldBe
6.28F
ms
.
loadByte
(
begin
+
30
)
shouldBe
0x5a
ms
.
loadShort
(
begin
+
28
)
shouldBe
0x55a5
ms
.
loadInt
(
begin
+
24
)
shouldBe
0x5a5a5a5a
ms
.
loadLong
(
begin
+
16
)
shouldBe
0x55aa55aa55aa55aa
L
ms
.
loadI128
(
begin
)
shouldBe
(
0x55555555aaaaaaaa
L
,
0xaaaaaaaa55555555
L
)
}
it
should
"Refuse out-of-bound access when the in-mu-memory checking is enabled"
in
{
val
ms
=
new
MemorySupport
(
1024L
)
val
begin
=
ms
.
muMemoryBegin
val
end
=
ms
.
muMemoryEnd
an
[
UvmIllegalMemoryAccessException
]
should
be
thrownBy
ms
.
storeI128
(
end
+
1024L
,
(
0x55555555aaaaaaaa
L
,
0xaaaaaaaa55555555
L
))
an
[
UvmIllegalMemoryAccessException
]
should
be
thrownBy
ms
.
storeLong
(
end
+
1024L
,
0x55aa55aa55aa55aa
L
)
an
[
UvmIllegalMemoryAccessException
]
should
be
thrownBy
ms
.
storeInt
(
end
+
1024L
,
0x5a5a5a5a
)
an
[
UvmIllegalMemoryAccessException
]
should
be
thrownBy
ms
.
storeShort
(
end
+
1024L
,
0x55a5
)
an
[
UvmIllegalMemoryAccessException
]
should
be
thrownBy
ms
.
storeByte
(
end
+
1024L
,
0x5a
)
an
[
UvmIllegalMemoryAccessException
]
should
be
thrownBy
ms
.
storeDouble
(
end
+
1024L
,
3.14
)
an
[
UvmIllegalMemoryAccessException
]
should
be
thrownBy
ms
.
storeFloat
(
end
+
1024L
,
6.28F
)
an
[
UvmIllegalMemoryAccessException
]
should
be
thrownBy
ms
.
loadDouble
(
end
+
1024L
)
an
[
UvmIllegalMemoryAccessException
]
should
be
thrownBy
ms
.
loadFloat
(
end
+
1024L
)
an
[
UvmIllegalMemoryAccessException
]
should
be
thrownBy
ms
.
loadByte
(
end
+
1024L
)
an
[
UvmIllegalMemoryAccessException
]
should
be
thrownBy
ms
.
loadShort
(
end
+
1024L
)
an
[
UvmIllegalMemoryAccessException
]
should
be
thrownBy
ms
.
loadInt
(
end
+
1024L
)
an
[
UvmIllegalMemoryAccessException
]
should
be
thrownBy
ms
.
loadLong
(
end
+
1024L
)
an
[
UvmIllegalMemoryAccessException
]
should
be
thrownBy
ms
.
loadI128
(
end
+
1024L
)
}
it
should
"allow out-of-bound access when the in-mu-memory checking is disabled"
in
{
val
ms1
=
new
MemorySupport
(
1024L
)
val
ms2
=
new
MemorySupport
(
1024L
)
// Use ms1 to access ms2.
val
begin
=
ms2
.
muMemoryBegin
ms1
.
storeI128
(
begin
,
(
0x55555555aaaaaaaa
L
,
0xaaaaaaaa55555555
L
),
inMu
=
false
)
ms1
.
storeLong
(
begin
+
16
,
0x55aa55aa55aa55aa
L
,
inMu
=
false
)
ms1
.
storeInt
(
begin
+
24
,
0x5a5a5a5a
,
inMu
=
false
)
ms1
.
storeShort
(
begin
+
28
,
0x55a5
,
inMu
=
false
)
ms1
.
storeByte
(
begin
+
30
,
0x5a
,
inMu
=
false
)
ms1
.
storeDouble
(
begin
+
32
,
3.14
,
inMu
=
false
)
ms1
.
storeFloat
(
begin
+
40
,
6.28F
,
inMu
=
false
)
ms1
.
loadDouble
(
begin
+
32
,
inMu
=
false
)
shouldBe
3.14
ms1
.
loadFloat
(
begin
+
40
,
inMu
=
false
)
shouldBe
6.28F
ms1
.
loadByte
(
begin
+
30
,
inMu
=
false
)
shouldBe
0x5a
ms1
.
loadShort
(
begin
+
28
,
inMu
=
false
)
shouldBe
0x55a5
ms1
.
loadInt
(
begin
+
24
,
inMu
=
false
)
shouldBe
0x5a5a5a5a
ms1
.
loadLong
(
begin
+
16
,
inMu
=
false
)
shouldBe
0x55aa55aa55aa55aa
L
ms1
.
loadI128
(
begin
,
inMu
=
false
)
shouldBe
(
0x55555555aaaaaaaa
L
,
0xaaaaaaaa55555555
L
)
}
}
\ No newline at end of file
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment