Skip to content

Commit

Permalink
[test] Refactor SsaMarkerTest to use lib/test
Browse files Browse the repository at this point in the history
  • Loading branch information
titzer committed Sep 4, 2024
1 parent 4725e87 commit 540fbb9
Showing 1 changed file with 33 additions and 31 deletions.
64 changes: 33 additions & 31 deletions aeneas/test/SsaMarkerTest.v3
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));
}

0 comments on commit 540fbb9

Please sign in to comment.