From: William Bourque Date: Fri, 22 Jan 2010 19:22:44 +0000 (+0000) Subject: More unit tests and fixes (bug 299715) X-Git-Url: http://drtracing.org/?a=commitdiff_plain;h=a5ec08e572fb6a2417c5625f0fa5ccececa0efda;p=deliverable%2Ftracecompass.git More unit tests and fixes (bug 299715) --- diff --git a/org.eclipse.linuxtools.lttng.tests/src/org/eclipse/linuxtools/lttng/tests/event/AllLttngTests.java b/org.eclipse.linuxtools.lttng.tests/src/org/eclipse/linuxtools/lttng/tests/event/AllLttngTests.java index 23f90e78f1..a14db9a859 100644 --- a/org.eclipse.linuxtools.lttng.tests/src/org/eclipse/linuxtools/lttng/tests/event/AllLttngTests.java +++ b/org.eclipse.linuxtools.lttng.tests/src/org/eclipse/linuxtools/lttng/tests/event/AllLttngTests.java @@ -2,12 +2,11 @@ package org.eclipse.linuxtools.lttng.tests.event; import junit.framework.TestCase; import junit.framework.TestSuite; - -import org.eclipse.linuxtools.lttng.tests.trace.LTTngTextTraceTest; +import org.eclipse.linuxtools.lttng.tests.trace.LTTngTextTraceTest;; public final class AllLttngTests extends TestCase { public static TestSuite suite() { - TestSuite suite = new TestSuite("Testing JNI"); + TestSuite suite = new TestSuite("Testing LTTng (trace in text format)"); suite.addTestSuite(LTTngTextTraceTest.class); suite.addTestSuite(LttngTimestampTest.class); diff --git a/org.eclipse.linuxtools.lttng.tests/src/org/eclipse/linuxtools/lttng/tests/event/LttngEventContentTest.java b/org.eclipse.linuxtools.lttng.tests/src/org/eclipse/linuxtools/lttng/tests/event/LttngEventContentTest.java index 9623811a40..fa15957998 100644 --- a/org.eclipse.linuxtools.lttng.tests/src/org/eclipse/linuxtools/lttng/tests/event/LttngEventContentTest.java +++ b/org.eclipse.linuxtools.lttng.tests/src/org/eclipse/linuxtools/lttng/tests/event/LttngEventContentTest.java @@ -2,28 +2,37 @@ package org.eclipse.linuxtools.lttng.tests.event; import java.io.File; import java.net.URL; +import java.util.HashMap; import junit.framework.TestCase; - import org.eclipse.core.runtime.FileLocator; import org.eclipse.core.runtime.Path; -import org.eclipse.linuxtools.lttng.event.LttngEvent; -import org.eclipse.linuxtools.lttng.event.LttngEventContent; -import org.eclipse.linuxtools.lttng.event.LttngEventField; -import org.eclipse.linuxtools.lttng.event.LttngTimestamp; +import org.eclipse.linuxtools.lttng.event.*; import org.eclipse.linuxtools.lttng.tests.LTTngCoreTestPlugin; import org.eclipse.linuxtools.lttng.trace.LTTngTextTrace; import org.eclipse.linuxtools.tmf.trace.TmfTraceContext; /* Functions tested here : - public LttngEventContent(LttngEventFormat thisFormat) - public LttngEventContent(LttngEventFormat thisFormat, String thisParsedContent, LttngEventField[] thisFields) + + public LttngEventContent() + public LttngEventContent(LttngEvent thisParent) + public LttngEventContent(LttngEvent thisParent, HashMap thisContent) public LttngEventContent(LttngEventContent oldContent) - public TmfEventField[] getFields() - public LttngEventField getField(int id) - public TmfEventField[] getFields(LttngEvent thisEvent) - public LttngEventField getField(int id, LttngEvent thisEvent) + + public void emptyContent() + + public LttngEventField[] getFields() + public LttngEventField getField(int position) + public LttngEventField getField(String name) + public LttngEvent getEvent() + public LttngEventType getType() + public Object[] getContent() + public HashMap getRawContent() + + public void setType(LttngEventType newType) + public void setEvent(LttngEvent newParent) + public String toString() */ @@ -32,16 +41,23 @@ public class LttngEventContentTest extends TestCase { private final static boolean skipIndexing=true; private final static String firstEventContentFirstField = "alignment:0"; - private final static String secondEventContentSecondField = "string:LTT state dump begin"; + private final static String firstEventContentFirstFieldName = "alignment"; + private final static String firstEventContentType = "metadata/0/core_marker_id"; + + private final static String secondEventContentSecondField = "string:LTT state dump begin"; + private final static String secondEventContentSecondFieldName = "string"; + private final static String secondEventContentType = "kernel/0/vprintk"; + private final static long timestampAfterMetadata = 13589760262237L; private static LTTngTextTrace testStream = null; + private LTTngTextTrace initializeEventStream() { - if (testStream == null) { + if (testStream == null) { try { URL location = FileLocator.find(LTTngCoreTestPlugin.getPlugin().getBundle(), new Path(tracepath1), null); File testfile = new File(FileLocator.toFileURL(location).toURI()); - LTTngTextTrace tmpStream = new LTTngTextTrace(testfile.getPath(), skipIndexing); + LTTngTextTrace tmpStream = new LTTngTextTrace(testfile.getPath()); testStream = tmpStream; } catch (Exception e) { @@ -50,13 +66,15 @@ public class LttngEventContentTest extends TestCase { } } return testStream; - } + } + private LttngEventContent prepareToTest() { LttngEventContent tmpEventContent = null; // This trace should be valid try { + testStream = null; LTTngTextTrace tmpStream = initializeEventStream(); tmpEventContent = (LttngEventContent)tmpStream.getNextEvent( new TmfTraceContext(0L, new LttngTimestamp(0L), 0) ).getContent(); } @@ -82,7 +100,7 @@ public class LttngEventContentTest extends TestCase { fail("Construction with format failed!"); } - // Construction with good parameters + // Construction with good parameters (parent event) try { testContent = new LttngEventContent(testEvent); } @@ -90,6 +108,16 @@ public class LttngEventContentTest extends TestCase { fail("Construction with format, content and fields failed!"); } + // Construction with good parameters (parent event and pre-parsed content) + try { + HashMap parsedContent = new HashMap(); + testContent = new LttngEventContent(testEvent, parsedContent); + } + catch( Exception e) { + fail("Construction with format, content and fields failed!"); + } + + // Copy constructor with correct parameters try { testContent = new LttngEventContent(testEvent); @@ -102,44 +130,111 @@ public class LttngEventContentTest extends TestCase { } -// public void testGetter() { -// LttngEventContent testContent = null; -// LTTngTextTrace tmpStream = null; -// LttngEvent tmpEvent = null; -// TmfTraceContext tmpContext = null; -// -// // Require an event -// tmpStream = initializeEventStream(); -// tmpContext = new TmfTraceContext(0L, new LttngTimestamp(0L), 0); -// tmpEvent = (LttngEvent)tmpStream.getNextEvent(tmpContext); -// -// testContent = prepareToTest(); -// // getFieldS() -// assertNotSame("getFields() returned null!",null,testContent.getFields() ); -// // getField(int) -// assertEquals("getField(int) returned unexpected result!",firstEventContentFirstField, testContent.getField(0).toString()); -// -// -// -// //*** To test getFiels with a fields number >0, we need to move to an event that have some more -// tmpStream = initializeEventStream(); -// tmpContext = new TmfTraceContext(0L, new LttngTimestamp(0L), 0); -// // Skip first events and seek to event pass metadata -// tmpContext= tmpStream.seekEvent(new LttngTimestamp(timestampAfterMetadata) ); -// // Skip first one -// tmpEvent = (LttngEvent)tmpStream.getNextEvent(tmpContext); -// -// // Second event past metadata should have more fields -// tmpEvent = (LttngEvent)tmpStream.getNextEvent(tmpContext); -// // Get the content -// testContent = tmpEvent.getContent(); -// -// // getFieldS() -// assertNotSame("getFields() returned null!",null,testContent.getFields() ); -// // getField(int) -// assertEquals("getField(int) returned unexpected result!",secondEventContentSecondField, testContent.getField(1).toString()); -// -// } + public void testGetter() { + LttngEventContent testContent = null; + LTTngTextTrace tmpStream = null; + LttngEvent tmpEvent = null; + TmfTraceContext tmpContext = null; + + // Require an event + tmpStream = initializeEventStream(); + tmpContext = new TmfTraceContext(0L, new LttngTimestamp(0L), 0); + tmpEvent = (LttngEvent)tmpStream.getNextEvent(tmpContext); + testContent = prepareToTest(); + // getFieldS() + assertNotSame("getFields() returned null!",null,testContent.getFields() ); + // getField(int) + assertEquals("getField(int) returned unexpected result!",firstEventContentFirstField, testContent.getField(0).toString()); + // getField(name) + assertEquals("getField(name) returned unexpected result!",firstEventContentFirstField, testContent.getField(firstEventContentFirstFieldName).toString()); + // getRawContent + assertNotSame("getRawContent() returned null!",null, testContent.getRawContent()); + // Test that get event return the correct event + assertTrue("getEvent() returned unexpected result!", tmpEvent.getTimestamp().getValue() == testContent.getEvent().getTimestamp().getValue()); + // getType() + assertEquals("getType() returned unexpected result!",firstEventContentType, testContent.getType().toString()); + + //*** To test getFields with a fields number >0, we need to move to an event that have some more + tmpStream = initializeEventStream(); + tmpContext = new TmfTraceContext(0L, new LttngTimestamp(0L), 0); + // Skip first events and seek to event pass metadata + tmpContext= tmpStream.seekEvent(new LttngTimestamp(timestampAfterMetadata) ); + // Skip first one + tmpEvent = (LttngEvent)tmpStream.getNextEvent(tmpContext); + + // Second event past metadata should have more fields + tmpEvent = (LttngEvent)tmpStream.getNextEvent(tmpContext); + // Get the content + testContent = tmpEvent.getContent(); + + // Test that get event return the correct event + assertTrue("getEvent() returned unexpected result!",tmpEvent.getTimestamp().getValue() == testContent.getEvent().getTimestamp().getValue()); + // getType() + assertEquals("getType() returned unexpected result!",secondEventContentType, testContent.getType().toString()); + + + // getFieldS() + assertNotSame("getFields() returned null!",null,testContent.getFields() ); + // getField(int) + assertEquals("getField(int) returned unexpected result!",secondEventContentSecondField, testContent.getField(1).toString()); + // getField(name) + assertEquals("getField(name) returned unexpected result!",secondEventContentSecondField, testContent.getField(secondEventContentSecondFieldName).toString()); + // getRawContent + assertNotSame("getRawContent() returned null!",null, testContent.getRawContent()); + + } + + public void testSetter() { + // Not much to test here, we will just make sure the set does not fail for any reason. + // It's pointless to test with a getter... + LTTngTextTrace tmpStream = null; + LttngEvent tmpEvent = null; + TmfTraceContext tmpContext = null; + + // Require an event + tmpStream = initializeEventStream(); + tmpContext = new TmfTraceContext(0L, new LttngTimestamp(0L), 0); + tmpEvent = (LttngEvent)tmpStream.getNextEvent(tmpContext); + + LttngEventContent tmpContent = prepareToTest(); + try { + tmpContent.setEvent(tmpEvent); + } + catch( Exception e) { + fail("setEvent(event) failed!"); + } + + + LttngEventType testType = new LttngEventType(); + try { + tmpContent.setType(testType); + } + catch( Exception e) { + fail("setType(type) failed!"); + } + } + + public void testEmptyContent() { + LttngEventContent testContent = null; + LTTngTextTrace tmpStream = null; + LttngEvent tmpEvent = null; + TmfTraceContext tmpContext = null; + + // Require an event + tmpStream = initializeEventStream(); + tmpContext = new TmfTraceContext(0L, new LttngTimestamp(0L), 0); + tmpEvent = (LttngEvent)tmpStream.getNextEvent(tmpContext); + // Get the content + testContent = tmpEvent.getContent(); + // Get all the fields to make sure there is something in the HashMap + testContent.getFields(); + // Just making sure there is something in the HashMap + assertNotSame("HashMap is empty but should not!", 0, testContent.getRawContent().size() ); + + // This is the actual test + testContent.emptyContent(); + assertSame("HashMap is not empty but should be!", 0, testContent.getRawContent().size() ); + } public void testToString() { LttngEventContent tmpContent = prepareToTest(); diff --git a/org.eclipse.linuxtools.lttng.tests/src/org/eclipse/linuxtools/lttng/tests/event/LttngEventReferenceTest.java b/org.eclipse.linuxtools.lttng.tests/src/org/eclipse/linuxtools/lttng/tests/event/LttngEventReferenceTest.java index eaff55faf6..d1b77263da 100644 --- a/org.eclipse.linuxtools.lttng.tests/src/org/eclipse/linuxtools/lttng/tests/event/LttngEventReferenceTest.java +++ b/org.eclipse.linuxtools.lttng.tests/src/org/eclipse/linuxtools/lttng/tests/event/LttngEventReferenceTest.java @@ -4,7 +4,6 @@ import java.io.File; import java.net.URL; import junit.framework.TestCase; - import org.eclipse.core.runtime.FileLocator; import org.eclipse.core.runtime.Path; import org.eclipse.linuxtools.lttng.event.LttngEventReference; @@ -14,11 +13,17 @@ import org.eclipse.linuxtools.tmf.trace.TmfTraceContext; /* Functions tested here : - public LttngEventReference(String newTracefilePath, String newTracePath) - public LttngEventReference(LttngEventReference oldReference) - public String getTracepath() - public void setTracepath(String tracepath) - public String toString() + public LttngEventReference(String newTraceName) + public LttngEventReference(String newTracefilePath, String newTraceName) + public LttngEventReference(LttngEventReference oldReference) + + public String getTracepath() + public String getValue() + + public void setTracepath(String tracename) + public void setValue(String newReference) + + public String toString() */ public class LttngEventReferenceTest extends TestCase { @@ -64,7 +69,15 @@ public class LttngEventReferenceTest extends TestCase { @SuppressWarnings("unused") LttngEventReference testRef2 = null; - // Default construction with good argument + // Default construction with good argument (newTracefilePath) + try { + testRef = new LttngEventReference("test"); + } + catch( Exception e) { + fail("Construction failed!"); + } + + // Default construction with good arguments (newTracefilePath, newTraceName) try { testRef = new LttngEventReference("test", "test"); } @@ -90,6 +103,25 @@ public class LttngEventReferenceTest extends TestCase { assertEquals("Content not what expected!",firstEventReference,tmpRef.getTracepath()); } + public void testSetter() { + // Not much to do here, we will just make sure the setter does not throw + LttngEventReference tmpRef = prepareToTest(); + + try { + tmpRef.setTracepath("test"); + } + catch( Exception e) { + fail("setTracepath(string) failed!"); + } + + try { + tmpRef.setValue("test"); + } + catch( Exception e) { + fail("setTracepath(string) failed!"); + } + } + public void testToString() { LttngEventReference tmpRef = prepareToTest(); diff --git a/org.eclipse.linuxtools.lttng.tests/src/org/eclipse/linuxtools/lttng/tests/event/LttngEventTypeTest.java b/org.eclipse.linuxtools.lttng.tests/src/org/eclipse/linuxtools/lttng/tests/event/LttngEventTypeTest.java index 389b0661d5..f7bfd799b0 100644 --- a/org.eclipse.linuxtools.lttng.tests/src/org/eclipse/linuxtools/lttng/tests/event/LttngEventTypeTest.java +++ b/org.eclipse.linuxtools.lttng.tests/src/org/eclipse/linuxtools/lttng/tests/event/LttngEventTypeTest.java @@ -4,7 +4,6 @@ import java.io.File; import java.net.URL; import junit.framework.TestCase; - import org.eclipse.core.runtime.FileLocator; import org.eclipse.core.runtime.Path; import org.eclipse.linuxtools.lttng.event.LttngEventType; @@ -14,12 +13,15 @@ import org.eclipse.linuxtools.tmf.trace.TmfTraceContext; /* Functions tested here : - public LttngEventType(String thisChannelName, long thisCpuId, String thisMarkerName, LttngEventFormat thisFormat) - public LttngEventType(LttngEventType oldType) - public String getChannelName() - public long getCpuId() - public String getMarkerName() - public String toString() + public LttngEventType() + public LttngEventType(String thisTracefileName, Long thisCpuId, String thisMarkerName, String[] thisMarkerfieldsName) + public LttngEventType(LttngEventType oldType) + + public String getTracefileName() + public Long getCpuId() + public String getMarkerName() + + public String toString() */ public class LttngEventTypeTest extends TestCase { @@ -67,7 +69,15 @@ public class LttngEventTypeTest extends TestCase { @SuppressWarnings("unused") LttngEventType tmpEventType2 = null; - // Default construction with good argument + // Default construction, no argument + try { + tmpEventType = new LttngEventType(); + } + catch( Exception e) { + fail("Construction failed!"); + } + + // Default construction with good arguments try { tmpEventType = new LttngEventType("test", 0L, "test", new String[1]); } @@ -93,7 +103,7 @@ public class LttngEventTypeTest extends TestCase { assertTrue("Cpu Id not what was expected!",firstEventCpu == tmpEventType.getCpuId() ); assertTrue("Marker Name not what was expected!",firstEventMarker.equals((String)tmpEventType.getMarkerName()) ); // Just test the non-nullity of labels - assertNotSame("getFormat returned null",null, tmpEventType.getLabels() ); + assertNotSame("getLabels returned null",null, tmpEventType.getLabels() ); } public void testToString() { diff --git a/org.eclipse.linuxtools.lttng.tests/src/org/eclipse/linuxtools/lttng/tests/event/LttngTimestampTest.java b/org.eclipse.linuxtools.lttng.tests/src/org/eclipse/linuxtools/lttng/tests/event/LttngTimestampTest.java index 926bd8a9a7..b3849d3226 100644 --- a/org.eclipse.linuxtools.lttng.tests/src/org/eclipse/linuxtools/lttng/tests/event/LttngTimestampTest.java +++ b/org.eclipse.linuxtools.lttng.tests/src/org/eclipse/linuxtools/lttng/tests/event/LttngTimestampTest.java @@ -4,7 +4,6 @@ import java.io.File; import java.net.URL; import junit.framework.TestCase; - import org.eclipse.core.runtime.FileLocator; import org.eclipse.core.runtime.Path; import org.eclipse.linuxtools.lttng.event.LttngTimestamp; @@ -14,11 +13,17 @@ import org.eclipse.linuxtools.tmf.trace.TmfTraceContext; /* Functions tested here : - public LttngTimestamp(TmfTimestamp newEventTime) - public LttngTimestamp(long newEventTime) - public String getSeconds() - public String getNanoSeconds() - public String toString() + public LttngTimestamp() + public LttngTimestamp(long newEventTime) + public LttngTimestamp(TmfTimestamp oldEventTime) + + public long getValue() + public String getSeconds() + public String getNanoSeconds() + + public void setValue(long newValue) + + public String toString() */ public class LttngTimestampTest extends TestCase { @@ -66,6 +71,14 @@ public class LttngTimestampTest extends TestCase { @SuppressWarnings("unused") LttngTimestamp tmpTime2 = null; + // Default construction with no argument + try { + tmpTime = new LttngTimestamp(); + } + catch( Exception e) { + fail("Construction failed!"); + } + // Default construction with good argument try { tmpTime = new LttngTimestamp(1); @@ -94,6 +107,14 @@ public class LttngTimestampTest extends TestCase { assertEquals("Full time is wrong", firstEventTimeFull, tmpTime.getValue() ); } + public void testSetter() { + LttngTimestamp tmpTime = prepareToTest(); + + // We will set a time and we will make sure the set is working then + tmpTime.setValue(1); + assertEquals("Full time is wrong after set", 1, tmpTime.getValue() ); + } + public void testToString() { LttngTimestamp tmpTime = prepareToTest(); diff --git a/org.eclipse.linuxtools.lttng.tests/src/org/eclipse/linuxtools/lttng/tests/trace/LTTngTextTraceTest.java b/org.eclipse.linuxtools.lttng.tests/src/org/eclipse/linuxtools/lttng/tests/trace/LTTngTextTraceTest.java index b5c7b99c7b..002d73eae7 100644 --- a/org.eclipse.linuxtools.lttng.tests/src/org/eclipse/linuxtools/lttng/tests/trace/LTTngTextTraceTest.java +++ b/org.eclipse.linuxtools.lttng.tests/src/org/eclipse/linuxtools/lttng/tests/trace/LTTngTextTraceTest.java @@ -1,5 +1,6 @@ package org.eclipse.linuxtools.lttng.tests.trace; +import org.eclipse.linuxtools.tmf.event.TmfEvent; import java.io.File; import java.net.URL; @@ -9,23 +10,24 @@ import org.eclipse.core.runtime.FileLocator; import org.eclipse.core.runtime.Path; import org.eclipse.linuxtools.lttng.tests.LTTngCoreTestPlugin; import org.eclipse.linuxtools.lttng.trace.LTTngTextTrace; -import org.eclipse.linuxtools.tmf.event.TmfEvent; import org.eclipse.linuxtools.tmf.event.TmfTimestamp; import org.eclipse.linuxtools.tmf.trace.TmfTraceContext; /* Functions tested here : - public LTTngTextTrace(String path) throws Exception - - public TmfTraceContext seekLocation(Object location) - public TmfTraceContext seekEvent(TmfTimestamp timestamp) - public TmfTraceContext seekEvent(long position) + public LTTngTextTrace(String path) throws Exception + public LTTngTextTrace(String path, boolean skipIndexing) throws Exception - public TmfEvent getNextEvent(TmfTraceContext context) + public TmfTraceContext seekLocation(Object location) { + public TmfTraceContext seekEvent(TmfTimestamp timestamp) { + public TmfTraceContext seekEvent(long position) { - public Object getCurrentLocation() + public TmfEvent getNextEvent(TmfTraceContext context) { + public Object getCurrentLocation() { - public LttngEvent parseEvent(TmfTraceContext context) + public LttngEvent parseEvent(TmfTraceContext context) { + + public int getCpuNumber() { */ public class LTTngTextTraceTest extends TestCase { @@ -33,6 +35,8 @@ public class LTTngTextTraceTest extends TestCase { private final static String tracepath1="traceset/trace-15316events_nolost_newformat.txt"; private final static String wrongTracePath="/somewhere/that/does/not/exist"; + private final static int traceCpuNumber=1; + private final static boolean skipIndexing=true; private final static long firstEventTimestamp = 13589759412127L; @@ -235,6 +239,8 @@ public class LTTngTextTraceTest extends TestCase { assertNotSame("tmpContext is null after first seekEvent()",null,testStream1.getCurrentLocation() ); assertEquals("tmpContext has wrong timestamp after first seekEvent()",locationAfterFirstEvent,(Long)testStream1.getCurrentLocation() ); + // Test CPU number of the trace + assertSame("getCpuNumber() return wrong number of cpu",traceCpuNumber ,testStream1.getCpuNumber() ); } public void testToString() {