use of il.ac.bgu.cs.bp.bpjs.model.BThreadSyncSnapshot in project BPjs by bThink-BGU.
the class ContinuationProgramStateTest method testEqualityTrue.
@Test
public void testEqualityTrue() throws Exception {
// Generate a continuation
BProgram bprog = new StringBProgram(SRC);
BProgramSyncSnapshot cur = bprog.setup();
cur = cur.start(exSvc);
final BThreadSyncSnapshot snapshot = cur.getBThreadSnapshots().iterator().next();
// Read frame data
NativeContinuation nc = (NativeContinuation) snapshot.getContinuation();
ContinuationProgramState sut1 = new ContinuationProgramState(nc);
ContinuationProgramState sut2 = new ContinuationProgramState(nc);
assertTrue(sut1.equals(sut2));
}
use of il.ac.bgu.cs.bp.bpjs.model.BThreadSyncSnapshot in project BPjs by bThink-BGU.
the class ContinuationProgramStateTest method testInequalityLoop.
@Test
public void testInequalityLoop() throws Exception {
// Generate snapshot 1
BProgram bprog = new StringBProgram(SRC_LOOP_UPDATED_VAR);
BProgramSyncSnapshot cur = bprog.setup();
cur = cur.start(exSvc);
BThreadSyncSnapshot snapshot = cur.getBThreadSnapshots().iterator().next();
NativeContinuation nc = (NativeContinuation) snapshot.getContinuation();
ContinuationProgramState sut1 = new ContinuationProgramState(nc);
assertEquals(1.0, sut1.getVisibleVariables().get("dbl"));
assertEquals("a", sut1.getVisibleVariables().get("str"));
// Generate snapshot 2, pre-loop
cur = cur.triggerEvent(new BEvent("e"), exSvc, emptySet());
snapshot = cur.getBThreadSnapshots().iterator().next();
nc = (NativeContinuation) snapshot.getContinuation();
ContinuationProgramState sut2 = new ContinuationProgramState(nc);
assertEquals("b", sut2.getVisibleVariables().get("str"));
assertEquals(42.0, sut2.getVisibleVariables().get("dbl"));
// Generate snapshot 3, first loop
cur = cur.triggerEvent(new BEvent("e"), exSvc, emptySet());
snapshot = cur.getBThreadSnapshots().iterator().next();
nc = (NativeContinuation) snapshot.getContinuation();
ContinuationProgramState sut3 = new ContinuationProgramState(nc);
assertEquals(47.0, sut3.getVisibleVariables().get("dbl"));
assertEquals("ba", sut3.getVisibleVariables().get("str"));
// Generate snapshot 4, second loop
cur = cur.triggerEvent(new BEvent("e"), exSvc, emptySet());
snapshot = cur.getBThreadSnapshots().iterator().next();
nc = (NativeContinuation) snapshot.getContinuation();
ContinuationProgramState sut4 = new ContinuationProgramState(nc);
assertEquals(52.0, sut4.getVisibleVariables().get("dbl"));
assertEquals("baa", sut4.getVisibleVariables().get("str"));
assertFalse(sut2.equals(sut1));
}
use of il.ac.bgu.cs.bp.bpjs.model.BThreadSyncSnapshot in project BPjs by bThink-BGU.
the class ContinuationProgramStateTest method testEqualityComplexObj.
@Test
public void testEqualityComplexObj() throws Exception {
// Generate continuation 1
BProgram bprog = new StringBProgram(SRC_WITH_COMPOUND_VARS);
BProgramSyncSnapshot cur = bprog.setup();
cur = cur.start(exSvc);
BThreadSyncSnapshot snapshot = cur.getBThreadSnapshots().iterator().next();
NativeContinuation nc = (NativeContinuation) snapshot.getContinuation();
ContinuationProgramState sut1 = new ContinuationProgramState(nc);
// Generate Continuation 2
bprog = new StringBProgram(SRC_WITH_COMPOUND_VARS);
cur = bprog.setup();
cur = cur.start(exSvc);
snapshot = cur.getBThreadSnapshots().iterator().next();
// Read frame data
nc = (NativeContinuation) snapshot.getContinuation();
ContinuationProgramState sut2 = new ContinuationProgramState(nc);
// sanity
assertTrue(sut1.equals(sut1));
assertTrue(sut1.equals(sut2));
assertTrue(sut2.equals(sut1));
}
use of il.ac.bgu.cs.bp.bpjs.model.BThreadSyncSnapshot in project BPjs by bThink-BGU.
the class ContinuationProgramStateTest method testEqualityFalse.
@Test
public void testEqualityFalse() throws Exception {
// Generate a continuation
BProgram bprog = new StringBProgram(SRC);
BProgramSyncSnapshot cur = bprog.setup();
cur = cur.start(exSvc);
final BThreadSyncSnapshot snapshot1 = cur.getBThreadSnapshots().iterator().next();
// Read frame data of P1
NativeContinuation nc1 = (NativeContinuation) snapshot1.getContinuation();
ContinuationProgramState sut1 = new ContinuationProgramState(nc1);
bprog = new StringBProgram(SRC_SHORT);
cur = bprog.setup();
cur = cur.start(exSvc);
final BThreadSyncSnapshot snapshot2 = cur.getBThreadSnapshots().iterator().next();
NativeContinuation nc2 = (NativeContinuation) snapshot2.getContinuation();
ContinuationProgramState sut2 = new ContinuationProgramState(nc2);
assertFalse(sut1.equals(sut2));
assertTrue(sut1.getProgramCounter() > sut2.getProgramCounter());
}
use of il.ac.bgu.cs.bp.bpjs.model.BThreadSyncSnapshot in project BPjs by bThink-BGU.
the class ContinuationProgramStateTest method testLoopSameWhenNoVarChanges.
@Test
public void testLoopSameWhenNoVarChanges() throws Exception {
// Generate snapshot 1
BProgram bprog = new StringBProgram(SRC_LOOP);
BProgramSyncSnapshot cur = bprog.setup();
cur = cur.start(exSvc);
BThreadSyncSnapshot snapshot = cur.getBThreadSnapshots().iterator().next();
NativeContinuation nc = (NativeContinuation) snapshot.getContinuation();
ContinuationProgramState sutPre = new ContinuationProgramState(nc);
cur = cur.triggerEvent(new BEvent("e"), exSvc, emptySet());
snapshot = cur.getBThreadSnapshots().iterator().next();
nc = (NativeContinuation) snapshot.getContinuation();
ContinuationProgramState sutLoop1 = new ContinuationProgramState(nc);
// Generate more snapshots
for (int i = 0; i < 10; i++) {
cur = cur.triggerEvent(new BEvent("e"), exSvc, emptySet());
snapshot = cur.getBThreadSnapshots().iterator().next();
nc = (NativeContinuation) snapshot.getContinuation();
ContinuationProgramState sutCurLoop = new ContinuationProgramState(nc);
assertEquals(sutLoop1, sutCurLoop);
assertNotEquals(sutPre, sutCurLoop);
}
}
Aggregations