X-Git-Url: http://git.efficios.com/?a=blobdiff_plain;f=org.eclipse.linuxtools.lttng2.kernel.core.tests%2Fsrc%2Forg%2Feclipse%2Flinuxtools%2Flttng2%2Fkernel%2Fcore%2Ftests%2Fstateprovider%2FStateSystemFullHistoryTest.java;h=a8a0f62db7a5805bd7fa397460588c19c3683ffa;hb=374cd3cd1bbe4f765b84b3032ddcfecc4e65f71c;hp=41e9a1dc4c9e399eb28bfaf5c9f7a8a957d36d69;hpb=6b78e55bae3827497518c2533167390228f920ef;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 41e9a1dc4c..a8a0f62db7 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 @@ -1,393 +1,180 @@ /******************************************************************************* - * Copyright (c) 2012 Ericsson - * Copyright (c) 2010, 2011 École Polytechnique de Montréal - * Copyright (c) 2010, 2011 Alexandre Montplaisir - * + * Copyright (c) 2012, 2014 Ericsson + * * 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 - * - *******************************************************************************/ + * + * Contributors: + * Alexandre Montplaisir - Initial API and implementation + * Bernd Hufmann - Use state system analysis module instead of factory + ******************************************************************************/ 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 static org.junit.Assert.fail; import java.io.File; -import java.io.FileNotFoundException; -import java.io.IOException; -import java.io.PrintWriter; -import java.util.List; -import org.eclipse.linuxtools.tmf.core.interval.ITmfStateInterval; -import org.eclipse.linuxtools.tmf.core.statesystem.AttributeNotFoundException; -import org.eclipse.linuxtools.tmf.core.statesystem.StateHistorySystem; -import org.eclipse.linuxtools.tmf.core.statesystem.TimeRangeException; -import org.eclipse.linuxtools.tmf.core.statesystem.backend.historytree.HistoryTreeBackend; -import org.eclipse.linuxtools.tmf.core.statesystem.helpers.HistoryBuilder; -import org.eclipse.linuxtools.tmf.core.statesystem.helpers.IStateChangeInput; -import org.eclipse.linuxtools.tmf.core.statesystem.helpers.IStateHistoryBackend; -import org.eclipse.linuxtools.tmf.core.statevalue.StateValueTypeException; -import org.eclipse.linuxtools.internal.lttng2.kernel.core.stateprovider.CtfKernelStateInput; -import org.eclipse.linuxtools.lttng2.kernel.core.trace.Attributes; -import org.junit.*; +import org.eclipse.jdt.annotation.NonNull; +import org.eclipse.jdt.annotation.NonNullByDefault; +import org.eclipse.jdt.annotation.Nullable; +import org.eclipse.linuxtools.internal.lttng2.kernel.core.stateprovider.LttngKernelStateProvider; +import org.eclipse.linuxtools.statesystem.core.ITmfStateSystem; +import org.eclipse.linuxtools.tmf.core.exceptions.TmfAnalysisException; +import org.eclipse.linuxtools.tmf.core.statesystem.ITmfStateProvider; +import org.eclipse.linuxtools.tmf.core.statesystem.TmfStateSystemAnalysisModule; +import org.eclipse.linuxtools.tmf.core.trace.ITmfTrace; +import org.eclipse.linuxtools.tmf.core.trace.TmfTraceManager; +import org.eclipse.linuxtools.tmf.ctf.core.CtfTmfTrace; +import org.junit.After; +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 - * + * State system tests using a full history back-end and the LTTng kernel state + * input. + * + * @author Alexandre Montplaisir */ -@SuppressWarnings("nls") -public class StateSystemFullHistoryTest { +public class StateSystemFullHistoryTest extends StateSystemTest { - static File stateFile; - static File stateFileBenchmark; + private static final @NonNull String TEST_FILE_NAME = "test.ht"; + private static final @NonNull String BENCHMARK_FILE_NAME = "test.benchmark.ht"; - static HistoryBuilder builder; - static IStateChangeInput input; - static IStateHistoryBackend hp; - static StateHistorySystem shs; + private File stateFile; + private File stateFileBenchmark; + private TestLttngKernelAnalysisModule module; - /* Offset in the trace + start time of the trace */ - private final static long interestingTimestamp1 = 18670067372290L + 1331649577946812237L; + @Override + protected ITmfStateSystem initialize() { + stateFile = createStateFile(TEST_FILE_NAME); + stateFileBenchmark = createStateFile(BENCHMARK_FILE_NAME); - protected static String getTestFileName() { - return "/tmp/statefile.ht"; //$NON-NLS-1$ - } - - @BeforeClass - public static void initialize() { - stateFile = new File(getTestFileName()); - stateFileBenchmark = new File(getTestFileName() + ".benchmark"); //$NON-NLS-1$ + module = new TestLttngKernelAnalysisModule(TEST_FILE_NAME); try { - input = new CtfKernelStateInput(CtfTestFiles.getTestTrace()); - hp = new HistoryTreeBackend(stateFile, input.getStartTime()); - builder = new HistoryBuilder(input, hp); - } catch (Exception e) { - e.printStackTrace(); - } - builder.run(); - shs = (StateHistorySystem) builder.getSS(); - builder.close(); /* Waits for the construction to finish */ - } - - @AfterClass - public static void cleanup() { - boolean ret1, ret2; - ret1 = stateFile.delete(); - ret2 = stateFileBenchmark.delete(); - if ( !(ret1 && ret2) ) { - System.err.println("Error cleaning up during unit testing, " + //$NON-NLS-1$ - "you might have leftovers state history files in /tmp"); //$NON-NLS-1$ + module.setTrace(testTrace.getTrace()); + } catch (TmfAnalysisException e) { + fail(); } + module.schedule(); + assertTrue(module.waitForCompletion()); + return module.getStateSystem(); } /** - * Rebuild independently so we can benchmark it. Too bad JUnit doesn't allow - * us to @Test the @BeforeClass... + * Clean-up */ - @Test - public void testBuild() { - HistoryBuilder zebuilder; - IStateChangeInput zeinput; - IStateHistoryBackend zehp; - - try { - zeinput = new CtfKernelStateInput(CtfTestFiles.getTestTrace()); - zehp = new HistoryTreeBackend(stateFileBenchmark, - zeinput.getStartTime()); - zebuilder = new HistoryBuilder(zeinput, zehp); - zebuilder.run(); - } catch (Exception e) { - e.printStackTrace(); + @After + public void cleanup() { + if (module != null) { + module.close(); } - } - - @Test - public void testOpenExistingStateFile() { - IStateHistoryBackend hp2 = null; - StateHistorySystem shs2 = null; - try { - /* 'newStateFile' should have already been created */ - hp2 = new HistoryTreeBackend(stateFile); - shs2 = new StateHistorySystem(hp2, false); - } catch (IOException e) { - e.printStackTrace(); + if (stateFile != null) { + stateFile.delete(); + } + if (stateFileBenchmark != null) { + stateFileBenchmark.delete(); } - assertTrue(shs2 != null); - } - - @Test - public void testFullQuery1() throws StateValueTypeException, - AttributeNotFoundException, TimeRangeException { - - List list; - ITmfStateInterval interval; - int quark, quark2, valueInt; - String valueStr; - - list = shs.loadStateAtTime(interestingTimestamp1); - - quark = shs.getQuarkAbsolute(Attributes.CPUS, "0", Attributes.CURRENT_THREAD); - interval = list.get(quark); - valueInt = interval.getStateValue().unboxInt(); - assertEquals(1397, valueInt); - - quark = shs.getQuarkAbsolute(Attributes.THREADS, "1432", Attributes.EXEC_NAME); - interval = list.get(quark); - valueStr = interval.getStateValue().unboxStr(); - assertEquals("gdbus", valueStr); - - /* Query a stack attribute, has to be done in two passes */ - quark = shs.getQuarkAbsolute(Attributes.THREADS, "1432", Attributes.EXEC_MODE_STACK); - interval = list.get(quark); - valueInt = interval.getStateValue().unboxInt(); /* The stack depth */ - quark2 = shs.getQuarkRelative(quark, Integer.toString(valueInt)); - interval = list.get(quark2); - valueStr = interval.getStateValue().unboxStr(); - assertTrue(valueStr.equals("sys_poll")); - } - - @Test - public void testFullQuery2() { - // - } - - @Test - public void testFullQuery3() { - // - } - - @Test - public void testSingleQuery1() throws AttributeNotFoundException, - TimeRangeException, StateValueTypeException { - - long timestamp = interestingTimestamp1; - int quark; - ITmfStateInterval interval; - String valueStr; - - quark = shs.getQuarkAbsolute(Attributes.THREADS, "1432", Attributes.EXEC_NAME); - interval = shs.querySingleState(timestamp, quark); - valueStr = interval.getStateValue().unboxStr(); - assertEquals("gdbus", valueStr); } - @Test - public void testSingleQuery2() { - // - } - - @Test - public void testSingleQuery3() { - // - } + // ------------------------------------------------------------------------ + // Tests specific to a full-history + // ------------------------------------------------------------------------ /** - * Test a range query (with no resolution parameter, so all intervals) - */ - @Test - public void testRangeQuery1() throws AttributeNotFoundException, - TimeRangeException, StateValueTypeException { - - long time1 = interestingTimestamp1; - long time2 = time1 + 1L * CtfTestFiles.NANOSECS_PER_SEC; - int quark; - List intervals; - - quark = shs.getQuarkAbsolute(Attributes.CPUS, "0", Attributes.CURRENT_THREAD); - intervals = shs.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()); - } - - /** - * Range query, but with a t2 far off the end of the trace. - * The result should still be valid. + * Rebuild independently so we can benchmark it. Too bad JUnit doesn't allow + * us to @Test the @BeforeClass... */ @Test - public void testRangeQuery2() throws TimeRangeException, - AttributeNotFoundException { - - List intervals; - - int quark = shs.getQuarkAbsolute(Attributes.CPUS, "0", Attributes.IRQ_STACK); - long ts1 = shs.getHistoryBackend().getStartTime(); /* start of the trace */ - long ts2 = CtfTestFiles.startTime + 20L * CtfTestFiles.NANOSECS_PER_SEC; /* invalid, but ignored */ - - intervals = shs.queryHistoryRange(quark, ts1, ts2); - - /* Nb of IRQs on CPU 0 during the whole trace */ - assertEquals(1653, intervals.size()); + public void testBuild() { + try (TestLttngKernelAnalysisModule module2 = + new TestLttngKernelAnalysisModule(BENCHMARK_FILE_NAME);) { + try { + module2.setTrace(testTrace.getTrace()); + } catch (TmfAnalysisException e) { + fail(); + } + module2.schedule(); + assertTrue(module2.waitForCompletion()); + ITmfStateSystem ssb2 = module2.getStateSystem(); + + assertNotNull(ssb2); + assertEquals(startTime, ssb2.getStartTime()); + assertEquals(endTime, ssb2.getCurrentEndTime()); + } } /** - * Test a range query with a resolution + * Test re-opening the existing file. */ @Test - public void testRangeQuery3() throws AttributeNotFoundException, - TimeRangeException, StateValueTypeException { - - long time1 = interestingTimestamp1; - long time2 = time1 + 1L * CtfTestFiles.NANOSECS_PER_SEC; - long resolution = 1000000; /* One query every millisecond */ - int quark; - List intervals; - - quark = shs.getQuarkAbsolute(Attributes.CPUS, "0", Attributes.CURRENT_THREAD); - intervals = shs.queryHistoryRange(quark, time1, time2, resolution); - assertEquals(129, intervals.size()); /* Number of context switches! */ - assertEquals(1452, intervals.get(50).getStateValue().unboxInt()); - assertEquals(1331668248784789238L, intervals.get(100).getEndTime()); - } - - /** - * 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; - shs.loadStateAtTime(ts); - - } - - @Test(expected = TimeRangeException.class) - public void testFullQueryInvalidTime2() throws TimeRangeException { - long ts = CtfTestFiles.startTime - 20L * CtfTestFiles.NANOSECS_PER_SEC; - shs.loadStateAtTime(ts); - - } - - @Test(expected = TimeRangeException.class) - public void testSingleQueryInvalidTime1() - throws AttributeNotFoundException, TimeRangeException { - - int quark = shs.getQuarkAbsolute(Attributes.CPUS, "0", Attributes.CURRENT_THREAD); - long ts = CtfTestFiles.startTime + 20L * CtfTestFiles.NANOSECS_PER_SEC; - shs.querySingleState(ts, quark); - } - - @Test(expected = TimeRangeException.class) - public void testSingleQueryInvalidTime2() - throws AttributeNotFoundException, TimeRangeException { - - int quark = shs.getQuarkAbsolute(Attributes.CPUS, "0", Attributes.CURRENT_THREAD); - long ts = CtfTestFiles.startTime - 20L * CtfTestFiles.NANOSECS_PER_SEC; - shs.querySingleState(ts, quark); - } - - @Test(expected = TimeRangeException.class) - public void testRangeQueryInvalidTime1() throws AttributeNotFoundException, - TimeRangeException { - - int quark = shs.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 */ - - shs.queryHistoryRange(quark, ts1, ts2); - } - - @Test(expected = TimeRangeException.class) - public void testRangeQueryInvalidTime2() throws TimeRangeException, - AttributeNotFoundException { - - int quark = shs.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 */ - - shs.queryHistoryRange(quark, ts1, ts2); - } - - /** - * Ask for a non-existing attribute - * - * @throws AttributeNotFoundException - */ - @Test(expected = AttributeNotFoundException.class) - public void testQueryInvalidAttribute() throws AttributeNotFoundException { - - shs.getQuarkAbsolute("There", "is", "no", "cow", "level"); - } - - /** - * Query but with the wrong State Value type - * - * @throws StateValueTypeException - * @throws AttributeNotFoundException - * @throws TimeRangeException - */ - @Test(expected = StateValueTypeException.class) - public void testQueryInvalidValuetype1() throws StateValueTypeException, - AttributeNotFoundException, TimeRangeException { - List list; - ITmfStateInterval interval; - int quark; - - list = shs.loadStateAtTime(interestingTimestamp1); - quark = shs.getQuarkAbsolute(Attributes.CPUS, "0", Attributes.CURRENT_THREAD); - interval = list.get(quark); - - /* This is supposed to be an int value */ - interval.getStateValue().unboxStr(); + public void testOpenExistingStateFile() { + /* 'newStateFile' should have already been created */ + try (TestLttngKernelAnalysisModule module2 = new TestLttngKernelAnalysisModule(TEST_FILE_NAME);) { + try { + module2.setTrace(testTrace.getTrace()); + } catch (TmfAnalysisException e) { + fail(); + } + module2.schedule(); + assertTrue(module2.waitForCompletion()); + ITmfStateSystem ssb2 = module2.getStateSystem(); + + assertNotNull(ssb2); + assertEquals(startTime, ssb2.getStartTime()); + assertEquals(endTime, ssb2.getCurrentEndTime()); + } } - @Test(expected = StateValueTypeException.class) - public void testQueryInvalidValuetype2() throws StateValueTypeException, - AttributeNotFoundException, TimeRangeException { - List list; - ITmfStateInterval interval; - int quark; + @NonNullByDefault + private static class TestLttngKernelAnalysisModule extends TmfStateSystemAnalysisModule { - list = shs.loadStateAtTime(interestingTimestamp1); - quark = shs.getQuarkAbsolute(Attributes.THREADS, "1432", Attributes.EXEC_NAME); - interval = list.get(quark); + private final String htFileName; - /* This is supposed to be a String value */ - interval.getStateValue().unboxInt(); - } - - @Test - public void testFullAttributeName() throws AttributeNotFoundException { - int quark = shs.getQuarkAbsolute(Attributes.CPUS, "0", Attributes.CURRENT_THREAD); - String name = shs.getFullAttributePath(quark); - assertEquals(name, "CPUs/0/Current_thread"); - } + /** + * Constructor adding the views to the analysis + * @param htFileName + * The History File Name + */ + public TestLttngKernelAnalysisModule(String htFileName) { + super(); + this.htFileName = htFileName; + } - @Test - public void testGetQuarks_begin() { - List list = shs.getQuarks("*", "1577", Attributes.EXEC_NAME); + @Override + public void setTrace(@Nullable ITmfTrace trace) throws TmfAnalysisException { + if (!(trace instanceof CtfTmfTrace)) { + throw new IllegalStateException("TestLttngKernelAnalysisModule: trace should be of type CtfTmfTrace"); //$NON-NLS-1$ + } + super.setTrace(trace); + } - assertEquals(1, list.size()); - assertEquals(Integer.valueOf(398), list.get(0)); - } + @Override + protected ITmfStateProvider createStateProvider() { + return new LttngKernelStateProvider(getTrace()); + } - @Test - public void testGetQuarks_middle() { - List list = shs.getQuarks(Attributes.THREADS, "*", Attributes.EXEC_NAME); + @Override + protected StateSystemBackendType getBackendType() { + return StateSystemBackendType.FULL; + } - assertEquals(Integer.valueOf(18), list.get(4)); - assertEquals(Integer.valueOf(54), list.get(10)); - assertEquals(Integer.valueOf(64), list.get(12)); + @Override + protected String getSsFileName() { + return htFileName; + } } - @Test - public void testGetQuarks_end() { - List list = shs.getQuarks(Attributes.THREADS, "1577", "*"); - - assertEquals(3, list.size()); - assertEquals(Integer.valueOf(398), list.get(1)); + private static File createStateFile(String name) { + File file = new File(TmfTraceManager.getSupplementaryFileDir(testTrace.getTrace()) + name); + if (file.exists()) { + file.delete(); + } + return file; } - @Test - public void testDebugPrinting() throws FileNotFoundException { - PrintWriter pw = new PrintWriter(new File("/dev/null")); - shs.debugPrint(pw); - pw.close(); - } }