use of org.eclipse.tracecompass.statesystem.core.interval.ITmfStateInterval in project tracecompass by tracecompass.
the class StateSystemUtilsTest method testIteratorOverQuarkEndTime.
/**
* Test that getIteratorOverQuark returns the correct intervals for a range
* included in the state system range
*/
@Test
public void testIteratorOverQuarkEndTime() {
ITmfStateSystem ss = fStateSystem;
assertNotNull(ss);
int quark;
try {
quark = ss.getQuarkAbsolute(DUMMY_STRING);
QuarkIterator iterator = new QuarkIterator(ss, quark, Long.MIN_VALUE, 1199);
/* There should be one interval ranging from 1000L to 1199L */
assertTrue(iterator.hasNext());
ITmfStateInterval interval = iterator.next();
assertNotNull(interval);
assertEquals(1000L, interval.getStartTime());
assertEquals(1199L, interval.getEndTime());
/* There should not be a next interval */
assertFalse(iterator.hasNext());
iterator = new QuarkIterator(ss, quark, Long.MIN_VALUE, 1200);
/* There should be 2 intervals ranging from 1000L to 1199L and 1200L to 1499L */
assertTrue(iterator.hasNext());
interval = iterator.next();
assertNotNull(interval);
assertEquals(1000L, interval.getStartTime());
assertEquals(1199L, interval.getEndTime());
assertTrue(iterator.hasNext());
interval = iterator.next();
assertNotNull(interval);
assertEquals(1200L, interval.getStartTime());
assertEquals(1499L, interval.getEndTime());
/* There should not be a next interval */
assertFalse(iterator.hasNext());
iterator = new QuarkIterator(ss, quark, 1800, 5000);
/* There should be one interval ranging from 1500L to 2000L */
assertTrue(iterator.hasNext());
interval = iterator.next();
assertNotNull(interval);
assertEquals(1500L, interval.getStartTime());
assertEquals(2000L, interval.getEndTime());
} catch (AttributeNotFoundException e) {
fail(e.getMessage());
}
}
use of org.eclipse.tracecompass.statesystem.core.interval.ITmfStateInterval in project tracecompass by tracecompass.
the class StateSystemUtilsTest method testIteratorOverQuarkResolution.
/**
* Test that the QuarkIterator returns the correct intervals for a range
* included in the state system range and a resolution
*/
@Test
public void testIteratorOverQuarkResolution() {
IStateHistoryBackend backend = StateHistoryBackendFactory.createInMemoryBackend(DUMMY_STRING, 1L);
ITmfStateSystemBuilder ss = StateSystemFactory.newStateSystem(backend);
try {
// Create a small state system with intervals for a resolution
int quark = ss.getQuarkAbsoluteAndAdd(DUMMY_STRING);
/**
* Here follows the state system, with each dash representing a nanosecond and
* vertical line a change of state. The time are the times that are expected to
* be queried
*
* <pre>
*
* resolution of 4: 2 6 10
* resolution of 3: 2 5 8 11
* ------|-|-|----
* </pre>
*/
ss.modifyAttribute(1L, 1, quark);
ss.modifyAttribute(7L, 2, quark);
ss.modifyAttribute(8L, 1, quark);
ss.modifyAttribute(9L, 2, quark);
ss.closeHistory(12L);
// Verify a resolution of 4
QuarkIterator iterator = new QuarkIterator(ss, quark, 2, 14, 4);
/*
* With steps of 4, there should be 2 intervals and they should be the same
* forward and backward
*/
assertTrue(iterator.hasNext());
ITmfStateInterval interval = iterator.next();
assertNotNull(interval);
assertEquals(1L, interval.getStartTime());
assertEquals(6L, interval.getEndTime());
// Check second interval forward
assertTrue(iterator.hasNext());
interval = iterator.next();
assertNotNull(interval);
assertEquals(9L, interval.getStartTime());
assertEquals(12L, interval.getEndTime());
/* There should not be a next interval */
assertFalse(iterator.hasNext());
// Check the interval backward
assertTrue(iterator.hasPrevious());
interval = iterator.previous();
assertNotNull(interval);
assertEquals(1L, interval.getStartTime());
assertEquals(6L, interval.getEndTime());
assertFalse(iterator.hasPrevious());
// Verify a resolution of 3
iterator = new QuarkIterator(ss, quark, 2, 14, 3);
/*
* With steps of 3, there should be 3 intervals and they should be the same
* forward and backward
*/
assertTrue(iterator.hasNext());
interval = iterator.next();
assertNotNull(interval);
assertEquals(1L, interval.getStartTime());
assertEquals(6L, interval.getEndTime());
// Check second interval forward
assertTrue(iterator.hasNext());
interval = iterator.next();
assertNotNull(interval);
assertEquals(8L, interval.getStartTime());
assertEquals(8L, interval.getEndTime());
// Check the interval forward
assertTrue(iterator.hasNext());
interval = iterator.next();
assertNotNull(interval);
assertEquals(9L, interval.getStartTime());
assertEquals(12L, interval.getEndTime());
/* There should not be a next interval */
assertFalse(iterator.hasNext());
// Check the first interval backward
assertTrue(iterator.hasPrevious());
interval = iterator.previous();
assertNotNull(interval);
assertEquals(8L, interval.getStartTime());
assertEquals(8L, interval.getEndTime());
// Check the second interval backward
assertTrue(iterator.hasPrevious());
interval = iterator.previous();
assertNotNull(interval);
assertEquals(1L, interval.getStartTime());
assertEquals(6L, interval.getEndTime());
assertFalse(iterator.hasPrevious());
} catch (StateValueTypeException e) {
fail(e.getMessage());
} finally {
ss.dispose();
}
}
use of org.eclipse.tracecompass.statesystem.core.interval.ITmfStateInterval in project tracecompass by tracecompass.
the class StateSystemUtilsTest method testIteratorOverQuarkReversed.
/**
* Test that the reverse iterator returns the correct intervals:
* <ul>
* <li>intervals for the correct quark</li>
* <li>ordered intervals</li>
* <li>intervals covering the correct time range</li>
* </ul>
*/
@Test
public void testIteratorOverQuarkReversed() {
ITmfStateSystem ss = fStateSystem;
assertNotNull(ss);
for (int quark = 0; quark < ss.getNbAttributes(); quark++) {
QuarkIterator iterator = new QuarkIterator(ss, quark, Long.MAX_VALUE);
ITmfStateInterval prevInterval = null;
ITmfStateInterval currInterval = null;
while (iterator.hasPrevious()) {
currInterval = iterator.previous();
assertEquals(quark, currInterval.getAttribute());
if (prevInterval == null) {
/* This is the first interval for this attribute */
assertEquals(currInterval.getEndTime(), ss.getCurrentEndTime());
} else {
assertEquals(prevInterval.getStartTime() - 1, currInterval.getEndTime());
}
prevInterval = currInterval;
}
assertNotNull("Iterator should have returned at least one interval", currInterval);
assertEquals(ss.getStartTime(), currInterval.getStartTime());
}
}
use of org.eclipse.tracecompass.statesystem.core.interval.ITmfStateInterval in project tracecompass by tracecompass.
the class StateSystemUtilsTest method testIteratorOverQuark.
/**
* Test that iterator returns the correct intervals:
* <ul>
* <li>intervals for the correct quark</li>
* <li>ordered intervals</li>
* <li>intervals covering the correct time range</li>
* </ul>
*/
@Test
public void testIteratorOverQuark() {
ITmfStateSystem ss = fStateSystem;
assertNotNull(ss);
for (int quark = 0; quark < ss.getNbAttributes(); quark++) {
QuarkIterator iterator = new QuarkIterator(ss, quark, Long.MIN_VALUE);
ITmfStateInterval prevInterval = null;
ITmfStateInterval currInterval = null;
while (iterator.hasNext()) {
currInterval = iterator.next();
assertEquals(quark, currInterval.getAttribute());
if (prevInterval == null) {
/* This is the first interval for this attribute */
assertEquals(currInterval.getStartTime(), ss.getStartTime());
} else {
assertEquals(prevInterval.getEndTime() + 1, currInterval.getStartTime());
}
prevInterval = currInterval;
}
assertNotNull("Iterator should have returned at least one interval", currInterval);
assertEquals(ss.getCurrentEndTime(), currInterval.getEndTime());
}
}
use of org.eclipse.tracecompass.statesystem.core.interval.ITmfStateInterval in project tracecompass by tracecompass.
the class InMemoryBackendTest method testDoQuery.
/**
* Query the state system
*/
@Test
public void testDoQuery() {
List<@Nullable ITmfStateInterval> interval = new ArrayList<>(NUMBER_OF_ATTRIBUTES);
for (int i = 0; i < NUMBER_OF_ATTRIBUTES; i++) {
interval.add(null);
}
IStateHistoryBackend backend = fixture;
assertNotNull(backend);
try {
backend.doQuery(interval, 950);
} catch (TimeRangeException | StateSystemDisposedException e) {
fail(e.getMessage());
}
assertEquals(NUMBER_OF_ATTRIBUTES, interval.size());
testInterval(interval.get(0), 900, 990, 9);
testInterval(interval.get(1), 901, 991, 9);
testInterval(interval.get(2), 902, 992, 9);
testInterval(interval.get(3), 903, 993, 9);
testInterval(interval.get(4), 904, 994, 9);
testInterval(interval.get(5), 905, 995, 9);
testInterval(interval.get(6), 906, 996, 9);
testInterval(interval.get(7), 907, 997, 9);
testInterval(interval.get(8), 908, 998, 9);
testInterval(interval.get(9), 909, 999, 9);
}
Aggregations