X-Git-Url: http://git.efficios.com/?a=blobdiff_plain;f=org.eclipse.linuxtools.ctf.core.tests%2Fsrc%2Forg%2Feclipse%2Flinuxtools%2Fctf%2Fcore%2Ftests%2Ftrace%2FCTFTraceTest.java;h=7d12edf7f0ae14c24414b18d905886697eba08f6;hb=60ae41e177bc783d3a400742bb4728b94dcf5c97;hp=260b17b569219b92d214d6071065637c264a62d0;hpb=836032241599f09ab801d01d59648675f627deb5;p=deliverable%2Ftracecompass.git diff --git a/org.eclipse.linuxtools.ctf.core.tests/src/org/eclipse/linuxtools/ctf/core/tests/trace/CTFTraceTest.java b/org.eclipse.linuxtools.ctf.core.tests/src/org/eclipse/linuxtools/ctf/core/tests/trace/CTFTraceTest.java index 260b17b569..7d12edf7f0 100644 --- a/org.eclipse.linuxtools.ctf.core.tests/src/org/eclipse/linuxtools/ctf/core/tests/trace/CTFTraceTest.java +++ b/org.eclipse.linuxtools.ctf.core.tests/src/org/eclipse/linuxtools/ctf/core/tests/trace/CTFTraceTest.java @@ -1,3 +1,16 @@ +/******************************************************************************* + * Copyright (c) 2013, 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: + * Matthew Khouzam - Initial API and implementation + * Marc-Andre Laperle - Test in traces directory recursively + * Simon Delisle - Add test for getCallsite(eventName, ip) + *******************************************************************************/ + package org.eclipse.linuxtools.ctf.core.tests.trace; import static org.junit.Assert.assertEquals; @@ -5,21 +18,21 @@ import static org.junit.Assert.assertFalse; import static org.junit.Assert.assertNotNull; import static org.junit.Assert.assertNull; import static org.junit.Assert.assertTrue; +import static org.junit.Assert.fail; +import static org.junit.Assume.assumeTrue; import java.io.File; import java.nio.ByteOrder; -import java.util.Map; import java.util.UUID; import org.eclipse.linuxtools.ctf.core.event.CTFClock; import org.eclipse.linuxtools.ctf.core.event.types.Definition; import org.eclipse.linuxtools.ctf.core.event.types.StructDeclaration; -import org.eclipse.linuxtools.ctf.core.tests.TestParams; +import org.eclipse.linuxtools.ctf.core.tests.shared.CtfTestTrace; import org.eclipse.linuxtools.ctf.core.trace.CTFReaderException; import org.eclipse.linuxtools.ctf.core.trace.CTFTrace; +import org.eclipse.linuxtools.ctf.core.trace.Stream; import org.eclipse.linuxtools.internal.ctf.core.event.metadata.exceptions.ParseException; -import org.eclipse.linuxtools.internal.ctf.core.trace.Stream; -import org.junit.After; import org.junit.Before; import org.junit.Test; @@ -28,28 +41,25 @@ import org.junit.Test; * {@link CTFTrace}. * * @author ematkho - * @version $Revision: 1.0 $ */ public class CTFTraceTest { - private CTFTrace fixture; + private static final CtfTestTrace testTrace = CtfTestTrace.KERNEL; - /** - * Launch the test. - * - * @param args - * the command line arguments - */ - public static void main(String[] args) { - new org.junit.runner.JUnitCore().run(CTFTraceTest.class); - } + private CTFTrace fixture; /** * Perform pre-test initialization. */ @Before public void setUp() { - fixture = TestParams.createTraceFromFile(); + assumeTrue(testTrace.exists()); + try { + fixture = testTrace.getTraceFromFile(); + } catch (CTFReaderException e) { + /* If the assumeTrue() call passed, this should not happen. */ + fail(); + } fixture.setMinor(1L); fixture.setUUID(UUID.randomUUID()); fixture.setPacketHeader(new StructDeclaration(1L)); @@ -57,31 +67,28 @@ public class CTFTraceTest { fixture.setByteOrder(ByteOrder.BIG_ENDIAN); } - /** - * Perform post-test clean-up. - */ - @After - public void tearDown() { - // Add additional tear down code here - } - /** * Run the CTFTrace(File) constructor test with a known existing trace. */ @Test public void testOpen_existing() { - CTFTrace result = TestParams.createTraceFromFile(); - assertNotNull(result.getUUID()); + try { + CTFTrace result = testTrace.getTraceFromFile(); + assertNotNull(result.getUUID()); + } catch (CTFReaderException e) { + fail(); + } } /** * Run the CTFTrace(File) constructor test with an invalid path. * * @throws CTFReaderException + * is expected */ @Test(expected = org.eclipse.linuxtools.ctf.core.trace.CTFReaderException.class) public void testOpen_invalid() throws CTFReaderException { - File path = new File(""); //$NON-NLS-1$ + File path = new File(""); CTFTrace result = new CTFTrace(path); assertNotNull(result); } @@ -91,21 +98,33 @@ public class CTFTraceTest { */ @Test public void testUUIDIsSet() { - boolean result = fixture.UUIDIsSet(); + boolean result = fixture.uuidIsSet(); assertTrue(result); } /** * Run the void addStream(Stream) method test. - * - * @throws ParseException - * @throws CTFReaderException */ @Test - public void testAddStream() throws ParseException, CTFReaderException { - Stream stream = new Stream(TestParams.createTrace()); - stream.setId(1L); - fixture.addStream(stream); + public void testAddStream() { + // test number of streams + int nbStreams = fixture.nbStreams(); + assertEquals(1, nbStreams); + + // Add a stream + try { + Stream stream = new Stream(testTrace.getTrace()); + stream.setId(1234); + fixture.addStream(stream); + } catch (CTFReaderException e) { + fail(); + } catch (ParseException e) { + fail(); + } + + // test number of streams + nbStreams = fixture.nbStreams(); + assertEquals(2, nbStreams); } /** @@ -172,15 +191,6 @@ public class CTFTraceTest { assertNotNull(result); } - /** - * Run the Map getStreams() method test. - */ - @Test - public void testGetStreams() { - Map result = fixture.getStreams(); - assertNotNull(result); - } - /** * Run the File getTraceDirectory() method test. */ @@ -204,17 +214,17 @@ public class CTFTraceTest { */ @Test public void testLookupDefinition() { - String lookupPath = "trace.packet.header"; //$NON-NLS-1$ + String lookupPath = "trace.packet.header"; Definition result = fixture.lookupDefinition(lookupPath); assertNotNull(result); } /** - * Run the boolean majortIsSet() method test. + * Run the boolean majorIsSet() method test. */ @Test - public void testMajortIsSet() { - boolean result = fixture.majortIsSet(); + public void testMajorIsSet() { + boolean result = fixture.majorIsSet(); assertTrue(result); } @@ -227,15 +237,6 @@ public class CTFTraceTest { assertTrue(result); } - /** - * Run the int nbStreams() method test. - */ - @Test - public void testNbStreams() { - int result = fixture.nbStreams(); - assertEquals(2, result); - } - /** * Run the boolean packetHeaderIsSet() method test with a valid header set. */ @@ -251,15 +252,19 @@ public class CTFTraceTest { */ @Test public void testPacketHeaderIsSet_invalid() { - CTFTrace fixture2 = TestParams.createTraceFromFile(); - fixture2.setMinor(1L); - fixture2.setUUID(UUID.randomUUID()); - fixture2.setPacketHeader((StructDeclaration) null); /* it's null here! */ - fixture2.setMajor(1L); - fixture2.setByteOrder(ByteOrder.BIG_ENDIAN); - - boolean result = fixture2.packetHeaderIsSet(); - assertFalse(result); + try { + CTFTrace fixture2 = testTrace.getTraceFromFile(); + fixture2.setMinor(1L); + fixture2.setUUID(UUID.randomUUID()); + fixture2.setPacketHeader((StructDeclaration) null); /* it's null here! */ + fixture2.setMajor(1L); + fixture2.setByteOrder(ByteOrder.BIG_ENDIAN); + + boolean result = fixture2.packetHeaderIsSet(); + assertFalse(result); + } catch (CTFReaderException e) { + fail(); + } } /** @@ -308,41 +313,11 @@ public class CTFTraceTest { } /** - * Run the CTFClock getClock() method test. + * Run the CTFClock getClock/setClock method test. */ @Test - public void testGetClock_1() { - CTFClock result = fixture.getClock(); - assertNull(result); - } - - /** - * Run the CTFClock getClock() method test. - * - */ - @Test - public void testGetClock_2() { - CTFClock result = fixture.getClock("Blabla"); //$NON-NLS-1$ - assertNull(result); - } - - /** - * Run the CTFClock getClock(String) method test. - */ - @Test - public void testGetClock_3() { - String name = ""; //$NON-NLS-1$ - CTFClock result = fixture.getClock(name); - assertNull(result); - } - - - /** - * Run the CTFClock getClock(String) method test. - */ - @Test - public void testSetClock_1() { - String name = ""; //$NON-NLS-1$ + public void testGetSetClock_1() { + String name = "clockyClock"; fixture.addClock(name, new CTFClock()); CTFClock result = fixture.getClock(name); @@ -350,20 +325,20 @@ public class CTFTraceTest { } /** - * Run the CTFClock getClock(String) method test. + * Run the CTFClock getClock/setClock method test. */ @Test - public void testSetClock_2() { - String name = ""; //$NON-NLS-1$ + public void testGetSetClock_2() { + String name = ""; CTFClock ctfClock = new CTFClock(); - ctfClock.addAttribute("name", "Bob"); //$NON-NLS-1$ //$NON-NLS-2$ - ctfClock.addAttribute("pi", new Double(java.lang.Math.PI)); //$NON-NLS-1$ + ctfClock.addAttribute("name", "Bob"); + ctfClock.addAttribute("pi", new Double(java.lang.Math.PI)); fixture.addClock(name, ctfClock); CTFClock result = fixture.getClock(name); assertNotNull(result); - assertTrue( (Double)ctfClock.getProperty("pi")> 3.0); //$NON-NLS-1$ - assertTrue( ctfClock.getName().equals("Bob")); //$NON-NLS-1$ + assertTrue((Double) ctfClock.getProperty("pi") > 3.0); + assertTrue(ctfClock.getName().equals("Bob")); } /** @@ -371,8 +346,8 @@ public class CTFTraceTest { */ @Test public void testLookupEnvironment_1() { - String key = ""; //$NON-NLS-1$ - String result = fixture.lookupEnvironment(key); + String key = ""; + String result = fixture.getEnvironment().get(key); assertNull(result); } @@ -381,8 +356,8 @@ public class CTFTraceTest { */ @Test public void testLookupEnvironment_2() { - String key = "test"; //$NON-NLS-1$ - String result = fixture.lookupEnvironment(key); + String key = "otherTest"; + String result = fixture.getEnvironment().get(key); assertNull(result); } @@ -391,9 +366,9 @@ public class CTFTraceTest { */ @Test public void testLookupEnvironment_3() { - String key = "test"; //$NON-NLS-1$ + String key = "test"; fixture.addEnvironmentVar(key, key); - String result = fixture.lookupEnvironment(key); + String result = fixture.getEnvironment().get(key); assertTrue(result.equals(key)); } @@ -402,11 +377,34 @@ public class CTFTraceTest { */ @Test public void testLookupEnvironment_4() { - String key = "test"; //$NON-NLS-1$ - fixture.addEnvironmentVar(key, "bozo"); //$NON-NLS-1$ - fixture.addEnvironmentVar(key, "the clown"); //$NON-NLS-1$ - String result = fixture.lookupEnvironment(key); + String key = "test"; + fixture.addEnvironmentVar(key, "bozo"); + fixture.addEnvironmentVar(key, "the clown"); + String result = fixture.getEnvironment().get(key); assertNotNull(result); } + /** + * Test for getCallsite(eventName, ip) + * @throws CTFReaderException not expected + */ + @Test + public void callsitePosition() throws CTFReaderException{ + long ip1 = 2; + long ip2 = 5; + long ip3 = 7; + CTFTrace callsiteTest = testTrace.getTraceFromFile(); + callsiteTest.addCallsite("testEvent", null, ip1, null, 23); + callsiteTest.addCallsite("testEvent", null, ip2, null, 50); + callsiteTest.addCallsite("testEvent", null, ip3, null, 15); + + assertEquals(2, (callsiteTest.getCallsite("testEvent", 1)).getIp()); + assertEquals(2, (callsiteTest.getCallsite("testEvent", 2)).getIp()); + assertEquals(5, (callsiteTest.getCallsite("testEvent", 3)).getIp()); + assertEquals(5, (callsiteTest.getCallsite("testEvent", 5)).getIp()); + assertEquals(7, (callsiteTest.getCallsite("testEvent", 6)).getIp()); + assertEquals(7, (callsiteTest.getCallsite("testEvent", 7)).getIp()); + assertEquals(7, (callsiteTest.getCallsite("testEvent", 8)).getIp()); + } + }