-
Notifications
You must be signed in to change notification settings - Fork 50
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[test] Refactor SsaMarkerTest to use lib/test
- Loading branch information
Showing
1 changed file
with
33 additions
and
31 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,67 +1,69 @@ | ||
def TEST = UnitTest.new("SsaMarker", runAllTests); | ||
def T = UnitTests.register; | ||
def X_ = void( | ||
T("marker:one", testOne(_, SsaInternalMarker.new)), | ||
T("marker:one_ex", testOne(_, SsaExternalMarker.new)), | ||
T("marker:two", testTwo(_, SsaInternalMarker.new)), | ||
T("marker:two_ex", testTwo(_, SsaExternalMarker.new)), | ||
T("marker:alloc", testAlloc(_, SsaInternalMarker.new)), | ||
T("marker:alloc_ex", testAlloc(_, SsaExternalMarker.new)), | ||
() | ||
); | ||
|
||
def p0 = SsaParam.new(0, Int.TYPE); | ||
def p1 = SsaParam.new(1, Int.TYPE); | ||
def g = SsaGraph.new([p0, p1], Int.TYPE); | ||
|
||
def runAllTests() { | ||
for (n in [SsaInternalMarker.new, SsaExternalMarker.new]) { | ||
testOne(n); | ||
testTwo(n); | ||
testAlloc(n); | ||
} | ||
} | ||
|
||
def testOne(n: () -> SsaMarker) { | ||
def testOne(t: Tester, n: () -> SsaMarker) { | ||
var m = n().reset(g); | ||
|
||
def get = m.getMark; | ||
def set = m.setMark; | ||
|
||
TEST.eq(true, get(p0) < 0); | ||
TEST.eq(true, get(p1) < 0); | ||
t.assert_eq(true, get(p0) < 0); | ||
t.assert_eq(true, get(p1) < 0); | ||
|
||
set(p0, 0); | ||
TEST.eq(0, get(p0)); | ||
TEST.eq(true, get(p1) < 0); | ||
t.assert_eq(0, get(p0)); | ||
t.assert_eq(true, get(p1) < 0); | ||
|
||
set(p0, 2); | ||
TEST.eq(2, get(p0)); | ||
TEST.eq(true, get(p1) < 0); | ||
t.assert_eq(2, get(p0)); | ||
t.assert_eq(true, get(p1) < 0); | ||
|
||
set(p1, 33); | ||
TEST.eq(2, get(p0)); | ||
TEST.eq(33, get(p1)); | ||
t.assert_eq(2, get(p0)); | ||
t.assert_eq(33, get(p1)); | ||
|
||
TEST.eq(34, m.countMarks()); | ||
t.assert_eq(34, m.countMarks()); | ||
} | ||
|
||
def testTwo(n: () -> SsaMarker) { | ||
def testTwo(t: Tester, n: () -> SsaMarker) { | ||
var m1 = n().reset(g); | ||
|
||
m1.setMark(p0, 1); | ||
m1.setMark(p1, 2); | ||
|
||
TEST.eq(1, m1.getMark(p0)); | ||
TEST.eq(2, m1.getMark(p1)); | ||
t.assert_eq(1, m1.getMark(p0)); | ||
t.assert_eq(2, m1.getMark(p1)); | ||
|
||
var m2 = n().reset(g); | ||
|
||
TEST.eq(true, m2.getMark(p0) < 0); | ||
TEST.eq(true, m2.getMark(p1) < 0); | ||
t.assert_eq(true, m2.getMark(p0) < 0); | ||
t.assert_eq(true, m2.getMark(p1) < 0); | ||
|
||
TEST.eq(1, m1.getMark(p0)); | ||
TEST.eq(2, m1.getMark(p1)); | ||
t.assert_eq(1, m1.getMark(p0)); | ||
t.assert_eq(2, m1.getMark(p1)); | ||
} | ||
|
||
def testAlloc(n: () -> SsaMarker) { | ||
def testAlloc(t: Tester, n: () -> SsaMarker) { | ||
var m = n().reset(g); | ||
|
||
var m0 = m.allocMark(p0); | ||
var m1 = m.allocMark(p1); | ||
|
||
TEST.eq(0, m0); | ||
TEST.eq(1, m1); | ||
t.assert_eq(0, m0); | ||
t.assert_eq(1, m1); | ||
|
||
TEST.eq(0, m.getMark(p0)); | ||
TEST.eq(1, m.getMark(p1)); | ||
t.assert_eq(0, m.getMark(p0)); | ||
t.assert_eq(1, m.getMark(p1)); | ||
} |