Skip to main content
aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorMatthew Khouzam2014-08-20 03:08:08 +0000
committerMatthew Khouzam2014-08-22 21:35:11 +0000
commit626784ff5a40ae9b73a996e4e38fd94ecd12bbd7 (patch)
tree80732be62d524f9636fa550b3c06525aff4c66ed
parent524ff9d3eddda6445669fbc998428b31f5d283ed (diff)
downloadorg.eclipse.linuxtools-626784ff5a40ae9b73a996e4e38fd94ecd12bbd7.tar.gz
org.eclipse.linuxtools-626784ff5a40ae9b73a996e4e38fd94ecd12bbd7.tar.xz
org.eclipse.linuxtools-626784ff5a40ae9b73a996e4e38fd94ecd12bbd7.zip
ctf: improve unit tests
There were several recent changes introduced to the ctf parser without fixing the test suite. This patch brings the tests up to date and coverage up to 78% Change-Id: I38b0f09d4005934d7a05d8cc3384ee7767bbd321 Signed-off-by: Matthew Khouzam <matthew.khouzam@ericsson.com> Reviewed-on: https://git.eclipse.org/r/31936 Tested-by: Hudson CI Reviewed-by: Bernd Hufmann <bernd.hufmann@ericsson.com> (cherry picked from commit bab59d91fdeb3fcde45d779bbe655cf02577f1bb) Reviewed-on: https://git.eclipse.org/r/32176
-rw-r--r--lttng/org.eclipse.linuxtools.ctf.core.tests/src/org/eclipse/linuxtools/ctf/core/tests/event/CTFCallsiteTest.java35
-rw-r--r--lttng/org.eclipse.linuxtools.ctf.core.tests/src/org/eclipse/linuxtools/ctf/core/tests/event/CTFEventDefinitionTest.java145
-rw-r--r--lttng/org.eclipse.linuxtools.ctf.core.tests/src/org/eclipse/linuxtools/ctf/core/tests/event/TestAll.java7
-rw-r--r--lttng/org.eclipse.linuxtools.ctf.core.tests/src/org/eclipse/linuxtools/ctf/core/tests/io/BitBufferIntTest.java41
-rw-r--r--lttng/org.eclipse.linuxtools.ctf.core.tests/src/org/eclipse/linuxtools/ctf/core/tests/types/IntegerDeclarationTest.java48
-rw-r--r--lttng/org.eclipse.linuxtools.ctf.core/src/org/eclipse/linuxtools/ctf/core/event/types/IntegerDeclaration.java6
6 files changed, 270 insertions, 12 deletions
diff --git a/lttng/org.eclipse.linuxtools.ctf.core.tests/src/org/eclipse/linuxtools/ctf/core/tests/event/CTFCallsiteTest.java b/lttng/org.eclipse.linuxtools.ctf.core.tests/src/org/eclipse/linuxtools/ctf/core/tests/event/CTFCallsiteTest.java
index b7fbc3501b..be25a3f8d4 100644
--- a/lttng/org.eclipse.linuxtools.ctf.core.tests/src/org/eclipse/linuxtools/ctf/core/tests/event/CTFCallsiteTest.java
+++ b/lttng/org.eclipse.linuxtools.ctf.core.tests/src/org/eclipse/linuxtools/ctf/core/tests/event/CTFCallsiteTest.java
@@ -1,5 +1,5 @@
/*******************************************************************************
- * Copyright (c) 2013 Ericsson
+ * 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
@@ -12,9 +12,13 @@
package org.eclipse.linuxtools.ctf.core.tests.event;
import static org.junit.Assert.assertEquals;
+import static org.junit.Assert.assertFalse;
import static org.junit.Assert.assertNotNull;
+import static org.junit.Assert.assertTrue;
import java.util.Arrays;
+import java.util.HashMap;
+import java.util.Map;
import org.eclipse.linuxtools.ctf.core.event.CTFCallsite;
import org.junit.Test;
@@ -43,6 +47,35 @@ public class CTFCallsiteTest {
}
/**
+ * Test the getters
+ */
+ @Test
+ public void getterTest(){
+ CTFCallsite cs = GenerateCS(0x01);
+ assertEquals("ip", 1, cs.getIp());
+ assertEquals("ip", "event name", cs.getEventName());
+ assertEquals("ip", "file.java", cs.getFileName());
+ assertEquals("ip", "func name", cs.getFunctionName());
+ }
+
+ /**
+ * Test the hash code
+ */
+ @Test
+ public void hashCodeTest(){
+ CTFCallsite cs = GenerateCS(0x01);
+ Map<CTFCallsite, Object> test = new HashMap<>();
+ test.put(cs, new Object());
+ assertTrue(test.containsKey(cs));
+ assertTrue(test.containsKey(GenerateCS(0x01)));
+ assertFalse(test.containsKey(GenerateCS(0x02)));
+ assertFalse(test.containsKey(new CTFCallsite("event nam", "func name", 1, "file.java", 1)));
+ assertFalse(test.containsKey(new CTFCallsite("event name", "func nam", 1, "file.java", 1)));
+ assertFalse(test.containsKey(new CTFCallsite("event name", "func name", 1, "file.jav", 1)));
+ assertFalse(test.containsKey(new CTFCallsite("event name", "func name", 1, "file.java", 2)));
+ }
+
+ /**
* Test the comparator (it should sort using the IP)
*/
@Test
diff --git a/lttng/org.eclipse.linuxtools.ctf.core.tests/src/org/eclipse/linuxtools/ctf/core/tests/event/CTFEventDefinitionTest.java b/lttng/org.eclipse.linuxtools.ctf.core.tests/src/org/eclipse/linuxtools/ctf/core/tests/event/CTFEventDefinitionTest.java
new file mode 100644
index 0000000000..82a14f540f
--- /dev/null
+++ b/lttng/org.eclipse.linuxtools.ctf.core.tests/src/org/eclipse/linuxtools/ctf/core/tests/event/CTFEventDefinitionTest.java
@@ -0,0 +1,145 @@
+/*******************************************************************************
+ * Copyright (c) 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
+ *******************************************************************************/
+
+package org.eclipse.linuxtools.ctf.core.tests.event;
+
+import static org.junit.Assert.assertTrue;
+import static org.junit.Assert.assertEquals;
+import static org.junit.Assert.assertNotNull;
+import static org.junit.Assert.assertNull;
+
+import java.nio.ByteOrder;
+import java.util.ArrayList;
+import java.util.Arrays;
+import java.util.Collections;
+import java.util.List;
+
+import org.eclipse.linuxtools.ctf.core.event.EventDefinition;
+import org.eclipse.linuxtools.ctf.core.event.scope.LexicalScope;
+import org.eclipse.linuxtools.ctf.core.event.types.Definition;
+import org.eclipse.linuxtools.ctf.core.event.types.Encoding;
+import org.eclipse.linuxtools.ctf.core.event.types.IntegerDeclaration;
+import org.eclipse.linuxtools.ctf.core.event.types.IntegerDefinition;
+import org.eclipse.linuxtools.ctf.core.event.types.StructDeclaration;
+import org.eclipse.linuxtools.ctf.core.event.types.StructDefinition;
+import org.eclipse.linuxtools.internal.ctf.core.event.EventDeclaration;
+import org.junit.Before;
+import org.junit.Test;
+
+/**
+ * Test the event definition
+ *
+ * @author Matthew Khouzam
+ *
+ */
+public class CTFEventDefinitionTest {
+ List<EventDefinition> fixture;
+
+ /**
+ * Making a power set of configurations to test the event definition
+ */
+ @Before
+ public void init() {
+ fixture = new ArrayList<>();
+ IntegerDeclaration pidDec = IntegerDeclaration.createDeclaration(5, false, 10, ByteOrder.LITTLE_ENDIAN, Encoding.NONE, "", 8);
+ IntegerDeclaration ctxDec = IntegerDeclaration.createDeclaration(16, false, 10, ByteOrder.LITTLE_ENDIAN, Encoding.NONE, "", 8);
+ IntegerDefinition pid = new IntegerDefinition(pidDec, null, "pid", 3);
+ IntegerDefinition pod = new IntegerDefinition(pidDec, null, "pod", 3);
+ IntegerDefinition ctx = new IntegerDefinition(pidDec, null, "ctx", 3);
+
+ StructDeclaration streamContextDec = new StructDeclaration(8);
+ streamContextDec.addField("pid", pidDec);
+ streamContextDec.addField("ctx", ctxDec);
+ StructDeclaration eventContextDec = new StructDeclaration(8);
+ streamContextDec.addField("pod", pidDec);
+ streamContextDec.addField("ctx", pidDec);
+ StructDeclaration fDec = new StructDeclaration(8);
+ EventDeclaration eventDeclaration = new EventDeclaration();
+
+ fDec.addField("pid", pidDec);
+ fDec.addField("ctx", ctxDec);
+ fDec.addField("pod", pidDec);
+
+ List<String> sFieldNames = Arrays.asList("pid", "ctx");
+ List<String> eFieldNames = Arrays.asList("pod", "ctx");
+ List<String> fieldNames = Arrays.asList("pid", "ctx", "pod");
+
+ Definition[] sDefs = { pid, ctx };
+ Definition[] eDefs = { pod, ctx };
+ Definition[] fDefs = { pid, ctx, pod };
+
+ StructDeclaration pContextDec = new StructDeclaration(8);
+
+ StructDefinition sContext = new StructDefinition(streamContextDec, null, LexicalScope.STREAM_PACKET_CONTEXT.toString(), sFieldNames, sDefs);
+ StructDefinition eContext = new StructDefinition(eventContextDec, null, LexicalScope.STREAM_EVENT_CONTEXT.toString(), eFieldNames, eDefs);
+ StructDefinition pContext = new StructDefinition(pContextDec, null, LexicalScope.FIELDS.toString(), Collections.EMPTY_LIST, new Definition[0]);
+ StructDefinition fields = new StructDefinition(fDec, null, LexicalScope.FIELDS.toString(), fieldNames, fDefs);
+
+ fixture.add(new EventDefinition(eventDeclaration, null, 100, null, null, null, null));
+ fixture.add(new EventDefinition(eventDeclaration, null, 100, null, null, null, fields));
+ fixture.add(new EventDefinition(eventDeclaration, null, 100, null, null, pContext, null));
+ fixture.add(new EventDefinition(eventDeclaration, null, 100, null, null, pContext, fields));
+ fixture.add(new EventDefinition(eventDeclaration, null, 100, null, eContext, null, null));
+ fixture.add(new EventDefinition(eventDeclaration, null, 100, null, eContext, null, fields));
+ fixture.add(new EventDefinition(eventDeclaration, null, 100, null, eContext, pContext, null));
+ fixture.add(new EventDefinition(eventDeclaration, null, 100, null, eContext, pContext, fields));
+ fixture.add(new EventDefinition(eventDeclaration, null, 100, sContext, null, null, null));
+ fixture.add(new EventDefinition(eventDeclaration, null, 100, sContext, null, null, fields));
+ fixture.add(new EventDefinition(eventDeclaration, null, 100, sContext, null, pContext, null));
+ fixture.add(new EventDefinition(eventDeclaration, null, 100, sContext, null, pContext, fields));
+ fixture.add(new EventDefinition(eventDeclaration, null, 100, sContext, eContext, null, null));
+ fixture.add(new EventDefinition(eventDeclaration, null, 100, sContext, eContext, null, fields));
+ fixture.add(new EventDefinition(eventDeclaration, null, 100, sContext, eContext, pContext, null));
+ fixture.add(new EventDefinition(eventDeclaration, null, 100, sContext, eContext, pContext, fields));
+ }
+
+ /**
+ * Test all the events
+ */
+ @Test
+ public void testEvents() {
+ int i = 0;
+ for (EventDefinition ed : fixture) {
+ test(i, ed);
+ i++;
+ }
+ }
+
+ private static void test(int rank, EventDefinition ed) {
+ String title = "event #" + rank;
+ assertEquals(title, 100L, ed.getTimestamp());
+ StructDefinition context = ed.getContext();
+ if (rank >= 4) {
+ assertNotNull(title, context);
+ if (rank >= 12) {
+ assertEquals(title, 3, context.getFieldNames().size());
+ } else {
+ assertEquals(title, 2, context.getFieldNames().size());
+ }
+
+ } else {
+ assertNull(title, context);
+ }
+ if (((rank / 4) % 2) == 1) {
+ assertNotNull(title, ed.getEventContext());
+ }else{
+ assertNull(title, ed.getEventContext());
+ }
+ if (rank % 2 == 1) {
+ assertNotNull(title, ed.getFields());
+ assertEquals(title, 3, ed.getFields().getFieldNames().size());
+ } else {
+ assertNull(title, ed.getFields());
+ }
+ assertTrue(title, ed.toString().startsWith("Event type: null\nTimestamp: 100"));
+ }
+
+}
diff --git a/lttng/org.eclipse.linuxtools.ctf.core.tests/src/org/eclipse/linuxtools/ctf/core/tests/event/TestAll.java b/lttng/org.eclipse.linuxtools.ctf.core.tests/src/org/eclipse/linuxtools/ctf/core/tests/event/TestAll.java
index 18b4ef14a3..e0f0d83f40 100644
--- a/lttng/org.eclipse.linuxtools.ctf.core.tests/src/org/eclipse/linuxtools/ctf/core/tests/event/TestAll.java
+++ b/lttng/org.eclipse.linuxtools.ctf.core.tests/src/org/eclipse/linuxtools/ctf/core/tests/event/TestAll.java
@@ -1,5 +1,5 @@
/*******************************************************************************
- * Copyright (c) 2013 Ericsson
+ * 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
@@ -24,8 +24,9 @@ import org.junit.runners.Suite;
*/
@RunWith(Suite.class)
@Suite.SuiteClasses({
- CTFCallsiteTest.class,
- CTFEventFieldTest.class
+ CTFCallsiteTest.class,
+ CTFEventDefinitionTest.class,
+ CTFEventFieldTest.class
})
public class TestAll {
diff --git a/lttng/org.eclipse.linuxtools.ctf.core.tests/src/org/eclipse/linuxtools/ctf/core/tests/io/BitBufferIntTest.java b/lttng/org.eclipse.linuxtools.ctf.core.tests/src/org/eclipse/linuxtools/ctf/core/tests/io/BitBufferIntTest.java
index 4159ad71b7..f2d607af5a 100644
--- a/lttng/org.eclipse.linuxtools.ctf.core.tests/src/org/eclipse/linuxtools/ctf/core/tests/io/BitBufferIntTest.java
+++ b/lttng/org.eclipse.linuxtools.ctf.core.tests/src/org/eclipse/linuxtools/ctf/core/tests/io/BitBufferIntTest.java
@@ -1,5 +1,5 @@
/*******************************************************************************
- * Copyright (c) 2013 Ericsson
+ * 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
@@ -493,6 +493,45 @@ public class BitBufferIntTest {
}
/**
+ * Test {@link BitBuffer#putInt(int)} Little endian
+ *
+ * @throws CTFReaderException
+ * Not expected
+ */
+ @Test
+ public void testPutIntLe() throws CTFReaderException {
+ fixture.setByteOrder(ByteOrder.LITTLE_ENDIAN);
+ fixture.position(1);
+ fixture.putInt(1);
+ }
+
+ /**
+ * Test {@link BitBuffer#putInt(int, int)} Little endian
+ *
+ * @throws CTFReaderException
+ * Not expected
+ */
+ @Test
+ public void testPutIntLe_length1() throws CTFReaderException {
+ fixture.setByteOrder(ByteOrder.LITTLE_ENDIAN);
+ fixture.position(1);
+ fixture.putInt(1, 1);
+ }
+
+ /**
+ * Test {@link BitBuffer#putInt(int, int)} with length = 0. Little endian
+ *
+ * @throws CTFReaderException
+ * Not expected
+ */
+ @Test
+ public void testPutIntLe_length0() throws CTFReaderException {
+ fixture.setByteOrder(ByteOrder.LITTLE_ENDIAN);
+ fixture.position(1);
+ fixture.putInt(0, 1);
+ }
+
+ /**
* Test writing and reading a value defined in hex format.
*
* @throws CTFReaderException
diff --git a/lttng/org.eclipse.linuxtools.ctf.core.tests/src/org/eclipse/linuxtools/ctf/core/tests/types/IntegerDeclarationTest.java b/lttng/org.eclipse.linuxtools.ctf.core.tests/src/org/eclipse/linuxtools/ctf/core/tests/types/IntegerDeclarationTest.java
index e32600823a..004bbe2d94 100644
--- a/lttng/org.eclipse.linuxtools.ctf.core.tests/src/org/eclipse/linuxtools/ctf/core/tests/types/IntegerDeclarationTest.java
+++ b/lttng/org.eclipse.linuxtools.ctf.core.tests/src/org/eclipse/linuxtools/ctf/core/tests/types/IntegerDeclarationTest.java
@@ -1,5 +1,5 @@
/*******************************************************************************
- * Copyright (c) 2013 Ericsson
+ * 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
@@ -69,7 +69,8 @@ public class IntegerDeclarationTest {
}
/**
- * Test that IntegerDeclaration throws when constructing a signed 1 bit declaration
+ * Test that IntegerDeclaration throws when constructing a signed 1 bit
+ * declaration
*/
@Test(expected = java.lang.IllegalArgumentException.class)
public void testIntegerDeclarationIllegalArgSignedBit() {
@@ -82,7 +83,8 @@ public class IntegerDeclarationTest {
}
/**
- * Test that IntegerDeclaration throws when constructing a invalid length declaration
+ * Test that IntegerDeclaration throws when constructing a invalid length
+ * declaration
*/
@Test(expected = java.lang.IllegalArgumentException.class)
public void testIntegerDeclarationIllegalArgBadLenght() {
@@ -95,6 +97,45 @@ public class IntegerDeclarationTest {
}
/**
+ * Test the factory part more rigorously to make sure there are no
+ * regressions
+ */
+ @Test
+ public void testIntegerDeclarationBruteForce() {
+ ByteOrder[] bos = { ByteOrder.LITTLE_ENDIAN, ByteOrder.BIG_ENDIAN };
+ Encoding[] encodings = { Encoding.ASCII, Encoding.NONE, Encoding.UTF8 };
+ boolean[] signeds = { true, false }; // not a real word
+ String[] clocks = { "something", "" };
+ int[] bases = { 2, 4, 6, 8, 10, 12, 16 };
+ for (int len = 2; len < 65; len++) {
+ for (ByteOrder bo : bos) {
+ for (boolean signed : signeds) {
+ for (int base : bases) {
+ for (Encoding enc : encodings) {
+ for (String clock : clocks) {
+ assertNotNull(enc);
+ assertNotNull(clock);
+ IntegerDeclaration intDec = IntegerDeclaration.createDeclaration(len, signed, base, bo, enc, clock, 8);
+ String title = Integer.toString(len) + " " + bo + " " + signed + " " + base + " " + enc;
+ assertEquals(title, signed, intDec.isSigned());
+ assertEquals(title, base, intDec.getBase());
+ // at len 8 le and be are the same
+ if (len != 8) {
+ assertEquals(title, bo, intDec.getByteOrder());
+ }
+ assertEquals(title, len, intDec.getLength());
+ assertEquals(title, len, intDec.getMaximumSize());
+ assertEquals(title, clock, intDec.getClock());
+ assertEquals(title, !signed && len == 8, intDec.isUnsignedByte());
+ }
+ }
+ }
+ }
+ }
+ }
+ }
+
+ /**
* Run the int getBase() method test.
*/
@Test
@@ -175,7 +216,6 @@ public class IntegerDeclarationTest {
assertEquals(false, result);
}
-
/**
* Run the String toString() method test.
*/
diff --git a/lttng/org.eclipse.linuxtools.ctf.core/src/org/eclipse/linuxtools/ctf/core/event/types/IntegerDeclaration.java b/lttng/org.eclipse.linuxtools.ctf.core/src/org/eclipse/linuxtools/ctf/core/event/types/IntegerDeclaration.java
index 1b4f97ed60..486553f2cb 100644
--- a/lttng/org.eclipse.linuxtools.ctf.core/src/org/eclipse/linuxtools/ctf/core/event/types/IntegerDeclaration.java
+++ b/lttng/org.eclipse.linuxtools.ctf.core/src/org/eclipse/linuxtools/ctf/core/event/types/IntegerDeclaration.java
@@ -1,5 +1,5 @@
/*******************************************************************************
- * Copyright (c) 2011, 2013 Ericsson, Ecole Polytechnique de Montreal and others
+ * Copyright (c) 2011, 2014 Ericsson, Ecole Polytechnique de Montreal and others
*
* All rights reserved. This program and the accompanying materials are made
* available under the terms of the Eclipse Public License v1.0 which
@@ -111,7 +111,7 @@ public class IntegerDeclaration extends Declaration implements ISimpleDatatypeDe
*
* @since 3.1
*/
- public static final IntegerDeclaration UINT_5L_DECL = new IntegerDeclaration(5, false, ByteOrder.BIG_ENDIAN);
+ public static final IntegerDeclaration UINT_5L_DECL = new IntegerDeclaration(5, false, ByteOrder.LITTLE_ENDIAN);
/**
* Unsigned 5 bit int, used for event headers
*
@@ -123,7 +123,7 @@ public class IntegerDeclaration extends Declaration implements ISimpleDatatypeDe
*
* @since 3.1
*/
- public static final IntegerDeclaration UINT_27L_DECL = new IntegerDeclaration(27, false, ByteOrder.BIG_ENDIAN);
+ public static final IntegerDeclaration UINT_27L_DECL = new IntegerDeclaration(27, false, ByteOrder.LITTLE_ENDIAN);
/**
* Unsigned 16 bit int, used for event headers
*

Back to the top