X-Git-Url: http://drtracing.org/?a=blobdiff_plain;f=org.eclipse.linuxtools.lttng2.kernel.core.tests%2Fsrc%2Forg%2Feclipse%2Flinuxtools%2Flttng2%2Fkernel%2Fcore%2Ftests%2Fstateprovider%2FStateSystemFullHistoryTest.java;h=f3919ff60835e93ab07cd08fcf7e54842eaf8616;hb=f1f86dfb492c7e41eb81a62c651b26e7b4fdb406;hp=55d60b824706a7bc4137b1ea958b7fb3f980a474;hpb=3e97fbfa6156dec95a4ce6c400233be5d56fd140;p=deliverable%2Ftracecompass.git diff --git a/org.eclipse.linuxtools.lttng2.kernel.core.tests/src/org/eclipse/linuxtools/lttng2/kernel/core/tests/stateprovider/StateSystemFullHistoryTest.java b/org.eclipse.linuxtools.lttng2.kernel.core.tests/src/org/eclipse/linuxtools/lttng2/kernel/core/tests/stateprovider/StateSystemFullHistoryTest.java index 55d60b8247..f3919ff608 100644 --- a/org.eclipse.linuxtools.lttng2.kernel.core.tests/src/org/eclipse/linuxtools/lttng2/kernel/core/tests/stateprovider/StateSystemFullHistoryTest.java +++ b/org.eclipse.linuxtools.lttng2.kernel.core.tests/src/org/eclipse/linuxtools/lttng2/kernel/core/tests/stateprovider/StateSystemFullHistoryTest.java @@ -2,53 +2,52 @@ * Copyright (c) 2012 Ericsson * Copyright (c) 2010, 2011 École Polytechnique de Montréal * Copyright (c) 2010, 2011 Alexandre Montplaisir - * + * * All rights reserved. This program and the accompanying materials are * made available under the terms of the Eclipse Public License v1.0 which * accompanies this distribution, and is available at * http://www.eclipse.org/legal/epl-v10.html - * + * *******************************************************************************/ package org.eclipse.linuxtools.lttng2.kernel.core.tests.stateprovider; -import static org.junit.Assert.*; +import static org.junit.Assert.assertEquals; +import static org.junit.Assert.assertNotNull; +import static org.junit.Assert.assertTrue; import java.io.File; -import java.io.IOException; import java.util.List; +import org.eclipse.linuxtools.internal.lttng2.kernel.core.Attributes; +import org.eclipse.linuxtools.internal.lttng2.kernel.core.stateprovider.CtfKernelStateInput; import org.eclipse.linuxtools.tmf.core.exceptions.AttributeNotFoundException; import org.eclipse.linuxtools.tmf.core.exceptions.StateValueTypeException; import org.eclipse.linuxtools.tmf.core.exceptions.TimeRangeException; import org.eclipse.linuxtools.tmf.core.exceptions.TmfTraceException; import org.eclipse.linuxtools.tmf.core.interval.ITmfStateInterval; -import org.eclipse.linuxtools.tmf.core.statesystem.HistoryBuilder; import org.eclipse.linuxtools.tmf.core.statesystem.IStateChangeInput; -import org.eclipse.linuxtools.tmf.core.statesystem.IStateHistoryBackend; -import org.eclipse.linuxtools.tmf.core.statesystem.IStateSystemBuilder; -import org.eclipse.linuxtools.tmf.core.statesystem.backend.historytree.HistoryTreeBackend; -import org.eclipse.linuxtools.internal.lttng2.kernel.core.Attributes; -import org.eclipse.linuxtools.internal.lttng2.kernel.core.stateprovider.CtfKernelStateInput; -import org.junit.*; +import org.eclipse.linuxtools.tmf.core.statesystem.ITmfStateSystem; +import org.eclipse.linuxtools.tmf.core.statesystem.StateSystemManager; +import org.junit.AfterClass; +import org.junit.BeforeClass; +import org.junit.Test; /** * Unit tests for the StateHistorySystem, which uses a full (non-partial) * history and the non-threaded CTF kernel handler. - * + * * @author alexmont - * + * */ -@SuppressWarnings("nls") +@SuppressWarnings({"nls", "javadoc"}) public class StateSystemFullHistoryTest { static File stateFile; static File stateFileBenchmark; - static HistoryBuilder builder; static IStateChangeInput input; - static IStateHistoryBackend hp; - static IStateSystemBuilder ssb; + static ITmfStateSystem ssq; /* Offset in the trace + start time of the trace */ private final static long interestingTimestamp1 = 18670067372290L + 1331649577946812237L; @@ -63,13 +62,10 @@ public class StateSystemFullHistoryTest { stateFileBenchmark = new File(getTestFileName() + ".benchmark"); //$NON-NLS-1$ try { input = new CtfKernelStateInput(CtfTestFiles.getTestTrace()); - hp = new HistoryTreeBackend(stateFile, input.getStartTime()); - builder = new HistoryBuilder(input, hp); + ssq = StateSystemManager.loadStateHistory(stateFile, input, true); } catch (Exception e) { e.printStackTrace(); } - builder.startBuilding(null); - ssb = builder.getStateSystemBuilder(); } @AfterClass @@ -86,37 +82,32 @@ public class StateSystemFullHistoryTest { /** * Rebuild independently so we can benchmark it. Too bad JUnit doesn't allow * us to @Test the @BeforeClass... - * - * @throws IOException - * @throws TmfTraceException + * + * @throws IOException + * @throws TmfTraceException */ @Test - public void testBuild() throws IOException, TmfTraceException { - HistoryBuilder zebuilder; - IStateChangeInput zeinput; - IStateHistoryBackend zehp = null; - - zeinput = new CtfKernelStateInput(CtfTestFiles.getTestTrace()); - zehp = new HistoryTreeBackend(stateFileBenchmark, zeinput.getStartTime()); - zebuilder = new HistoryBuilder(zeinput, zehp); - zebuilder.startBuilding(null); - - assertEquals(CtfTestFiles.startTime, zehp.getStartTime()); - assertEquals(CtfTestFiles.endTime, zehp.getEndTime()); + public void testBuild() throws TmfTraceException { + IStateChangeInput input2; + ITmfStateSystem ssb2; + + input2 = new CtfKernelStateInput(CtfTestFiles.getTestTrace()); + ssb2 = StateSystemManager.loadStateHistory(stateFileBenchmark, input2, true); + + assertEquals(CtfTestFiles.startTime, ssb2.getStartTime()); + assertEquals(CtfTestFiles.endTime, ssb2.getCurrentEndTime()); } @Test - public void testOpenExistingStateFile() throws IOException { - IStateHistoryBackend hp2 = null; - IStateSystemBuilder ssb2 = null; + public void testOpenExistingStateFile() throws TmfTraceException { + ITmfStateSystem ssb2; /* 'newStateFile' should have already been created */ - hp2 = new HistoryTreeBackend(stateFile); - ssb2 = HistoryBuilder.openExistingHistory(hp2); + ssb2 = StateSystemManager.loadStateHistory(stateFile, null, true); assertNotNull(ssb2); - assertEquals(CtfTestFiles.startTime, hp2.getStartTime()); - assertEquals(CtfTestFiles.endTime, hp2.getEndTime()); + assertEquals(CtfTestFiles.startTime, ssb2.getStartTime()); + assertEquals(CtfTestFiles.endTime, ssb2.getCurrentEndTime()); } @Test @@ -128,19 +119,19 @@ public class StateSystemFullHistoryTest { int quark, valueInt; String valueStr; - list = ssb.queryFullState(interestingTimestamp1); + list = ssq.queryFullState(interestingTimestamp1); - quark = ssb.getQuarkAbsolute(Attributes.CPUS, "0", Attributes.CURRENT_THREAD); + quark = ssq.getQuarkAbsolute(Attributes.CPUS, "0", Attributes.CURRENT_THREAD); interval = list.get(quark); valueInt = interval.getStateValue().unboxInt(); assertEquals(1397, valueInt); - quark = ssb.getQuarkAbsolute(Attributes.THREADS, "1432", Attributes.EXEC_NAME); + quark = ssq.getQuarkAbsolute(Attributes.THREADS, "1432", Attributes.EXEC_NAME); interval = list.get(quark); valueStr = interval.getStateValue().unboxStr(); assertEquals("gdbus", valueStr); - quark = ssb.getQuarkAbsolute(Attributes.THREADS, "1432", Attributes.SYSTEM_CALL); + quark = ssq.getQuarkAbsolute(Attributes.THREADS, "1432", Attributes.SYSTEM_CALL); interval = list.get(quark); valueStr = interval.getStateValue().unboxStr(); assertTrue(valueStr.equals("sys_poll")); @@ -165,8 +156,8 @@ public class StateSystemFullHistoryTest { ITmfStateInterval interval; String valueStr; - quark = ssb.getQuarkAbsolute(Attributes.THREADS, "1432", Attributes.EXEC_NAME); - interval = ssb.querySingleState(timestamp, quark); + quark = ssq.getQuarkAbsolute(Attributes.THREADS, "1432", Attributes.EXEC_NAME); + interval = ssq.querySingleState(timestamp, quark); valueStr = interval.getStateValue().unboxStr(); assertEquals("gdbus", valueStr); } @@ -193,8 +184,8 @@ public class StateSystemFullHistoryTest { int quark; List intervals; - quark = ssb.getQuarkAbsolute(Attributes.CPUS, "0", Attributes.CURRENT_THREAD); - intervals = ssb.queryHistoryRange(quark, time1, time2); + quark = ssq.getQuarkAbsolute(Attributes.CPUS, "0", Attributes.CURRENT_THREAD); + intervals = ssq.queryHistoryRange(quark, time1, time2); assertEquals(487, intervals.size()); /* Number of context switches! */ assertEquals(1685, intervals.get(100).getStateValue().unboxInt()); assertEquals(1331668248427681372L, intervals.get(205).getEndTime()); @@ -209,12 +200,12 @@ public class StateSystemFullHistoryTest { AttributeNotFoundException { List intervals; - - int quark = ssb.getQuarkAbsolute(Attributes.RESOURCES, Attributes.IRQS, "1"); - long ts1 = ssb.getStartTime(); /* start of the trace */ + + int quark = ssq.getQuarkAbsolute(Attributes.RESOURCES, Attributes.IRQS, "1"); + long ts1 = ssq.getStartTime(); /* start of the trace */ long ts2 = CtfTestFiles.startTime + 20L * CtfTestFiles.NANOSECS_PER_SEC; /* invalid, but ignored */ - intervals = ssb.queryHistoryRange(quark, ts1, ts2); + intervals = ssq.queryHistoryRange(quark, ts1, ts2); /* Activity of IRQ 1 over the whole trace */ assertEquals(65, intervals.size()); @@ -233,8 +224,8 @@ public class StateSystemFullHistoryTest { int quark; List intervals; - quark = ssb.getQuarkAbsolute(Attributes.CPUS, "0", Attributes.CURRENT_THREAD); - intervals = ssb.queryHistoryRange(quark, time1, time2, resolution); + quark = ssq.getQuarkAbsolute(Attributes.CPUS, "0", Attributes.CURRENT_THREAD); + intervals = ssq.queryHistoryRange(quark, time1, time2, resolution, null); assertEquals(126, intervals.size()); /* Number of context switches! */ assertEquals(1452, intervals.get(50).getStateValue().unboxInt()); assertEquals(1331668248815698779L, intervals.get(100).getEndTime()); @@ -242,20 +233,20 @@ public class StateSystemFullHistoryTest { /** * Ask for a time range outside of the trace's range - * + * * @throws TimeRangeException */ @Test(expected = TimeRangeException.class) public void testFullQueryInvalidTime1() throws TimeRangeException { long ts = CtfTestFiles.startTime + 20L * CtfTestFiles.NANOSECS_PER_SEC; - ssb.queryFullState(ts); + ssq.queryFullState(ts); } @Test(expected = TimeRangeException.class) public void testFullQueryInvalidTime2() throws TimeRangeException { long ts = CtfTestFiles.startTime - 20L * CtfTestFiles.NANOSECS_PER_SEC; - ssb.queryFullState(ts); + ssq.queryFullState(ts); } @@ -263,56 +254,56 @@ public class StateSystemFullHistoryTest { public void testSingleQueryInvalidTime1() throws AttributeNotFoundException, TimeRangeException { - int quark = ssb.getQuarkAbsolute(Attributes.CPUS, "0", Attributes.CURRENT_THREAD); + int quark = ssq.getQuarkAbsolute(Attributes.CPUS, "0", Attributes.CURRENT_THREAD); long ts = CtfTestFiles.startTime + 20L * CtfTestFiles.NANOSECS_PER_SEC; - ssb.querySingleState(ts, quark); + ssq.querySingleState(ts, quark); } @Test(expected = TimeRangeException.class) public void testSingleQueryInvalidTime2() throws AttributeNotFoundException, TimeRangeException { - int quark = ssb.getQuarkAbsolute(Attributes.CPUS, "0", Attributes.CURRENT_THREAD); + int quark = ssq.getQuarkAbsolute(Attributes.CPUS, "0", Attributes.CURRENT_THREAD); long ts = CtfTestFiles.startTime - 20L * CtfTestFiles.NANOSECS_PER_SEC; - ssb.querySingleState(ts, quark); + ssq.querySingleState(ts, quark); } @Test(expected = TimeRangeException.class) public void testRangeQueryInvalidTime1() throws AttributeNotFoundException, TimeRangeException { - int quark = ssb.getQuarkAbsolute(Attributes.CPUS, "0", Attributes.CURRENT_THREAD); + int quark = ssq.getQuarkAbsolute(Attributes.CPUS, "0", Attributes.CURRENT_THREAD); long ts1 = CtfTestFiles.startTime - 20L * CtfTestFiles.NANOSECS_PER_SEC; /* invalid */ long ts2 = CtfTestFiles.startTime + 1L * CtfTestFiles.NANOSECS_PER_SEC; /* valid */ - ssb.queryHistoryRange(quark, ts1, ts2); + ssq.queryHistoryRange(quark, ts1, ts2); } @Test(expected = TimeRangeException.class) public void testRangeQueryInvalidTime2() throws TimeRangeException, AttributeNotFoundException { - int quark = ssb.getQuarkAbsolute(Attributes.CPUS, "0", Attributes.CURRENT_THREAD); + int quark = ssq.getQuarkAbsolute(Attributes.CPUS, "0", Attributes.CURRENT_THREAD); long ts1 = CtfTestFiles.startTime - 1L * CtfTestFiles.NANOSECS_PER_SEC; /* invalid */ long ts2 = CtfTestFiles.startTime + 20L * CtfTestFiles.NANOSECS_PER_SEC; /* invalid */ - ssb.queryHistoryRange(quark, ts1, ts2); + ssq.queryHistoryRange(quark, ts1, ts2); } /** * Ask for a non-existing attribute - * + * * @throws AttributeNotFoundException */ @Test(expected = AttributeNotFoundException.class) public void testQueryInvalidAttribute() throws AttributeNotFoundException { - ssb.getQuarkAbsolute("There", "is", "no", "cow", "level"); + ssq.getQuarkAbsolute("There", "is", "no", "cow", "level"); } /** * Query but with the wrong State Value type - * + * * @throws StateValueTypeException * @throws AttributeNotFoundException * @throws TimeRangeException @@ -324,8 +315,8 @@ public class StateSystemFullHistoryTest { ITmfStateInterval interval; int quark; - list = ssb.queryFullState(interestingTimestamp1); - quark = ssb.getQuarkAbsolute(Attributes.CPUS, "0", Attributes.CURRENT_THREAD); + list = ssq.queryFullState(interestingTimestamp1); + quark = ssq.getQuarkAbsolute(Attributes.CPUS, "0", Attributes.CURRENT_THREAD); interval = list.get(quark); /* This is supposed to be an int value */ @@ -339,8 +330,8 @@ public class StateSystemFullHistoryTest { ITmfStateInterval interval; int quark; - list = ssb.queryFullState(interestingTimestamp1); - quark = ssb.getQuarkAbsolute(Attributes.THREADS, "1432", Attributes.EXEC_NAME); + list = ssq.queryFullState(interestingTimestamp1); + quark = ssq.getQuarkAbsolute(Attributes.THREADS, "1432", Attributes.EXEC_NAME); interval = list.get(quark); /* This is supposed to be a String value */ @@ -349,21 +340,21 @@ public class StateSystemFullHistoryTest { @Test public void testFullAttributeName() throws AttributeNotFoundException { - int quark = ssb.getQuarkAbsolute(Attributes.CPUS, "0", Attributes.CURRENT_THREAD); - String name = ssb.getFullAttributePath(quark); + int quark = ssq.getQuarkAbsolute(Attributes.CPUS, "0", Attributes.CURRENT_THREAD); + String name = ssq.getFullAttributePath(quark); assertEquals(name, "CPUs/0/Current_thread"); } @Test public void testGetQuarks_begin() { - List list = ssb.getQuarks("*", "1577", Attributes.EXEC_NAME); + List list = ssq.getQuarks("*", "1577", Attributes.EXEC_NAME); assertEquals(1, list.size()); } @Test public void testGetQuarks_middle() { - List list = ssb.getQuarks(Attributes.THREADS, "*", Attributes.EXEC_NAME); + List list = ssq.getQuarks(Attributes.THREADS, "*", Attributes.EXEC_NAME); /* Number of different kernel threads in the trace */ assertEquals(168, list.size()); @@ -371,7 +362,7 @@ public class StateSystemFullHistoryTest { @Test public void testGetQuarks_end() { - List list = ssb.getQuarks(Attributes.THREADS, "1577", "*"); + List list = ssq.getQuarks(Attributes.THREADS, "1577", "*"); /* There should be 4 sub-attributes for each Thread node */ assertEquals(4, list.size());