org.eclipse.jdt.core.compiler.annotation.nonnull=org.eclipse.jdt.annotation.NonNull
org.eclipse.jdt.core.compiler.annotation.nonnullbydefault=org.eclipse.jdt.annotation.NonNullByDefault
org.eclipse.jdt.core.compiler.annotation.nullable=org.eclipse.jdt.annotation.Nullable
-org.eclipse.jdt.core.compiler.annotation.nullanalysis=disabled
+org.eclipse.jdt.core.compiler.annotation.nullanalysis=enabled
org.eclipse.jdt.core.compiler.codegen.inlineJsrBytecode=enabled
org.eclipse.jdt.core.compiler.codegen.targetPlatform=1.7
org.eclipse.jdt.core.compiler.codegen.unusedLocal=preserve
org.eclipse.linuxtools.ctf.core.tests.event;x-internal:=true,
org.eclipse.linuxtools.ctf.core.tests.headless;x-internal:=true,
org.eclipse.linuxtools.ctf.core.tests.io;x-internal:=true,
+ org.eclipse.linuxtools.ctf.core.tests.scope,
org.eclipse.linuxtools.ctf.core.tests.shared,
org.eclipse.linuxtools.ctf.core.tests.synthetictraces;x-internal:=true,
org.eclipse.linuxtools.ctf.core.tests.trace;x-internal:=true,
org.eclipse.linuxtools.ctf.core.tests.types;x-internal:=true
-Import-Package: org.antlr.runtime;version="3.2.0"
+Import-Package: com.google.common.collect,
+ org.antlr.runtime;version="3.2.0"
plugin.properties,\
traces/get-traces.xml
src.includes = about.html
+additional.bundles = org.eclipse.jdt.annotation
+jars.extra.classpath = platform:/plugin/org.eclipse.jdt.annotation
*/
@RunWith(Suite.class)
@Suite.SuiteClasses({
- CtfCorePluginTest.class,
- org.eclipse.linuxtools.ctf.core.tests.ctftestsuite.TestAll.class,
- org.eclipse.linuxtools.ctf.core.tests.event.TestAll.class,
- org.eclipse.linuxtools.ctf.core.tests.io.TestAll.class,
- org.eclipse.linuxtools.ctf.core.tests.trace.TestAll.class,
- org.eclipse.linuxtools.ctf.core.tests.types.TestAll.class
+ CtfCorePluginTest.class,
+ org.eclipse.linuxtools.ctf.core.tests.ctftestsuite.TestAll.class,
+ org.eclipse.linuxtools.ctf.core.tests.event.TestAll.class,
+ org.eclipse.linuxtools.ctf.core.tests.io.TestAll.class,
+ org.eclipse.linuxtools.ctf.core.tests.scope.TestAll.class,
+ org.eclipse.linuxtools.ctf.core.tests.trace.TestAll.class,
+ org.eclipse.linuxtools.ctf.core.tests.types.TestAll.class
})
public class AllCtfCoreTests {
-
}
import java.nio.ByteBuffer;
import java.nio.ByteOrder;
+import org.eclipse.jdt.annotation.NonNull;
import org.eclipse.linuxtools.ctf.core.event.io.BitBuffer;
-import org.eclipse.linuxtools.ctf.core.event.types.ArrayDeclaration;
-import org.eclipse.linuxtools.ctf.core.event.types.ArrayDefinition;
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.SequenceDeclaration;
-import org.eclipse.linuxtools.ctf.core.event.types.SequenceDefinition;
import org.eclipse.linuxtools.ctf.core.event.types.StringDeclaration;
import org.eclipse.linuxtools.ctf.core.event.types.StringDefinition;
import org.eclipse.linuxtools.ctf.core.event.types.StructDeclaration;
import org.eclipse.linuxtools.ctf.core.trace.CTFReaderException;
import org.junit.Test;
+import com.google.common.collect.ImmutableList;
+
/**
* The class <code>CTFEventFieldTest</code> contains tests for the class
* <code>{@link CTFEventField}</code>.
@SuppressWarnings("javadoc")
public class CTFEventFieldTest {
- private static final String fieldName = "id";
+ @NonNull private static final String fieldName = "id";
/**
* Run the CTFEventField parseField(Definition,String) method test.
+ *
* @throws CTFReaderException
*/
@Test
public void testParseField_complex() throws CTFReaderException {
int len = 32;
- IntegerDeclaration id = new IntegerDeclaration(len, false, len,
- ByteOrder.LITTLE_ENDIAN, Encoding.ASCII, null, 32);
+ IntegerDeclaration id = IntegerDeclaration.createDeclaration(
+ len,
+ false,
+ len,
+ ByteOrder.LITTLE_ENDIAN,
+ Encoding.ASCII,
+ "",
+ len);
String lengthName = "LengthName";
StructDeclaration structDec = new StructDeclaration(0);
structDec.addField(lengthName, id);
- StructDefinition structDef = new StructDefinition(structDec, null,
- lengthName);
+ StructDefinition structDef = new StructDefinition(
+ structDec,
+ null,
+ lengthName,
+ ImmutableList.of(lengthName),
+ new Definition[] {
+ new IntegerDefinition(
+ id,
+ null,
+ lengthName,
+ 32)
+ });
- structDef.lookupInteger(lengthName).setValue(32);
SequenceDeclaration sd = new SequenceDeclaration(lengthName, id);
- Definition fieldDef = new SequenceDefinition(sd, structDef, "TestX");
ByteBuffer byb = ByteBuffer.allocate(1024);
for (int i = 0; i < 1024; i++) {
byb.put((byte) i);
}
BitBuffer bb = new BitBuffer(byb);
- fieldDef.read(bb);
+ Definition fieldDef = sd.createDefinition(structDef, "fff-fffield", bb);
assertNotNull(fieldDef);
}
/**
* Run the CTFEventField parseField(Definition,String) method test.
+ *
* @throws CTFReaderException
*/
@Test
- public void testParseField_simple() {
+ public void testParseField_simple() throws CTFReaderException {
final StringDeclaration elemType = new StringDeclaration();
- Definition fieldDef = elemType.createDefinition(null, fieldName);
+ byte[] bytes = { 'T', 'e', 's', 't', '\0' };
+ ByteBuffer bb = ByteBuffer.wrap(bytes);
+
+ Definition fieldDef = elemType.createDefinition(null, fieldName, new BitBuffer(bb));
assertNotNull(fieldDef);
}
@Test
public void testParseField_simple2() {
IntegerDefinition fieldDef = new IntegerDefinition(
- new IntegerDeclaration(1, false, 1, ByteOrder.BIG_ENDIAN,
- Encoding.ASCII, null, 8), null, fieldName);
- fieldDef.setValue(1L);
+ IntegerDeclaration.createDeclaration(1, false, 1, ByteOrder.BIG_ENDIAN,
+ Encoding.ASCII, "", 8), null, fieldName, 1L);
assertNotNull(fieldDef);
}
@Test
public void testParseField_simple3() {
StringDefinition fieldDef = new StringDefinition(
- new StringDeclaration(), null, fieldName);
- fieldDef.setValue("Hello World");
+ new StringDeclaration(), null, fieldName, "Hello World");
String other = "\"Hello World\"";
assertNotNull(fieldDef);
assertEquals(fieldDef.toString(), other);
}
- /**
- * Run the CTFEventField parseField(Definition,String) method test.
- */
- @Test
- public void testParseField_manual() {
- Definition fieldDef = new ArrayDefinition(new ArrayDeclaration(20,
- new IntegerDeclaration(8, false, 8, null, Encoding.UTF8, null, 8)),
- null, fieldName);
- ((IntegerDefinition) ((ArrayDefinition) fieldDef).getDefinitions()[0]).setValue('H');
- ((IntegerDefinition) ((ArrayDefinition) fieldDef).getDefinitions()[1]).setValue('e');
- ((IntegerDefinition) ((ArrayDefinition) fieldDef).getDefinitions()[2]).setValue('l');
- ((IntegerDefinition) ((ArrayDefinition) fieldDef).getDefinitions()[3]).setValue('l');
- ((IntegerDefinition) ((ArrayDefinition) fieldDef).getDefinitions()[4]).setValue('o');
- ((IntegerDefinition) ((ArrayDefinition) fieldDef).getDefinitions()[5]).setValue(' ');
- ((IntegerDefinition) ((ArrayDefinition) fieldDef).getDefinitions()[6]).setValue('W');
- ((IntegerDefinition) ((ArrayDefinition) fieldDef).getDefinitions()[7]).setValue('o');
- ((IntegerDefinition) ((ArrayDefinition) fieldDef).getDefinitions()[8]).setValue('r');
- ((IntegerDefinition) ((ArrayDefinition) fieldDef).getDefinitions()[9]).setValue('l');
- ((IntegerDefinition) ((ArrayDefinition) fieldDef).getDefinitions()[10]).setValue('d');
- ((IntegerDefinition) ((ArrayDefinition) fieldDef).getDefinitions()[11]).setValue(0);
-
- assertNotNull(fieldDef);
- }
-
- /**
- * Run the CTFEventField parseField(Definition,String) method test.
- */
- @Test
- public void testParseField_manual2() {
- Definition fieldDef = new ArrayDefinition(new ArrayDeclaration(12,
- new IntegerDeclaration(32, false, 32, null, null, null, 8)), null,
- fieldName);
- ((IntegerDefinition) ((ArrayDefinition) fieldDef).getDefinitions()[0]).setValue('H');
- ((IntegerDefinition) ((ArrayDefinition) fieldDef).getDefinitions()[1]).setValue('e');
- ((IntegerDefinition) ((ArrayDefinition) fieldDef).getDefinitions()[2]).setValue('l');
- ((IntegerDefinition) ((ArrayDefinition) fieldDef).getDefinitions()[3]).setValue('l');
- ((IntegerDefinition) ((ArrayDefinition) fieldDef).getDefinitions()[4]).setValue('o');
- ((IntegerDefinition) ((ArrayDefinition) fieldDef).getDefinitions()[5]).setValue(' ');
- ((IntegerDefinition) ((ArrayDefinition) fieldDef).getDefinitions()[6]).setValue('W');
- ((IntegerDefinition) ((ArrayDefinition) fieldDef).getDefinitions()[7]).setValue('o');
- ((IntegerDefinition) ((ArrayDefinition) fieldDef).getDefinitions()[8]).setValue('r');
- ((IntegerDefinition) ((ArrayDefinition) fieldDef).getDefinitions()[9]).setValue('l');
- ((IntegerDefinition) ((ArrayDefinition) fieldDef).getDefinitions()[10]).setValue('d');
- ((IntegerDefinition) ((ArrayDefinition) fieldDef).getDefinitions()[11]).setValue(0);
-
- assertNotNull(fieldDef);
- String other = "[ 72, 101, 108, 108, 111, 32, 87, 111, 114, 108, 100, 0 ]";
- assertEquals(other, fieldDef.toString());
- }
}
\ No newline at end of file
package org.eclipse.linuxtools.ctf.core.tests.headless;
+import java.io.FileNotFoundException;
import java.text.DateFormat;
import java.text.SimpleDateFormat;
import java.util.Date;
/**
* @param args
+ * @throws FileNotFoundException
*/
- public static void main(String[] args) {
+ public static void main(String[] args) throws FileNotFoundException {
final String TRACE_PATH = "traces/kernel";
// Change this to enable text output
final boolean USE_TEXT = false;
- final int LOOP_COUNT = 1;
+ final int LOOP_COUNT = 10;
// Work variables
long nbEvent = 0L;
nbEvent = 0L;
trace = new CTFTrace(TRACE_PATH);
} catch (CTFReaderException e) {
- // do nothing
+ throw new FileNotFoundException(TRACE_PATH);
}
start = System.nanoTime();
if (USE_TEXT) {
System.out.println("Event, " + " Time, " + " type, " + " CPU ");
}
try (CTFTraceReader traceReader = new CTFTraceReader(trace);) {
- if (trace != null) {
- start = System.nanoTime();
+ start = System.nanoTime();
- while (traceReader.hasMoreEvents()) {
- EventDefinition ed = traceReader.getCurrentEventDef();
- nbEvent++;
- if (USE_TEXT) {
- String output = formatDate(ed.getTimestamp()
- + trace.getOffset());
- System.out.println(nbEvent + ", "
- + output + ", " + ed.getDeclaration().getName()
- + ", " + ed.getCPU() + ed.getFields().toString());
- }
- // long endTime = traceReader.getEndTime();
- // long timestamp =
- // traceReader.getCurrentEventDef().getTimestamp();
- traceReader.advance();
+ while (traceReader.hasMoreEvents()) {
+ EventDefinition ed = traceReader.getCurrentEventDef();
+ nbEvent++;
+ if (USE_TEXT) {
+ String output = formatDate(ed.getTimestamp()
+ + trace.getOffset());
+ System.out.println(nbEvent + ", "
+ + output + ", " + ed.getDeclaration().getName()
+ + ", " + ed.getCPU() + ed.getFields().toString());
}
- // Map<Long, Stream> streams =
- // traceReader.getTrace().getStreams();
+
+ traceReader.advance();
}
+
stop = System.nanoTime();
System.out.print('.');
--- /dev/null
+/*******************************************************************************
+ * 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.scope;
+
+import static org.junit.Assert.assertEquals;
+import static org.junit.Assert.assertNotNull;
+
+import org.eclipse.linuxtools.ctf.core.event.scope.LexicalScope;
+import org.junit.Test;
+
+/**
+ * Lexical test
+ *
+ * @author Matthew Khouzam
+ */
+public class LexicalScopeTest {
+
+ /**
+ * Root test
+ */
+ @Test
+ public void testRoot(){
+ LexicalScope scope = LexicalScope.ROOT;
+ assertNotNull(scope);
+ }
+
+ /**
+ * Test a more complex node
+ */
+ @Test
+ public void testComplexNode(){
+ LexicalScope scope = LexicalScope.STREAM_EVENT_CONTEXT;
+ assertEquals("context", scope.getName());
+ assertEquals("stream.event.context", scope.toString());
+ }
+}
--- /dev/null
+/*******************************************************************************
+ * 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.scope;
+
+import org.junit.runner.RunWith;
+import org.junit.runners.Suite;
+
+/**
+ * The class <code>TestAll</code> builds a suite that can be used to run all of
+ * the tests within its package as well as within any subpackages of its
+ * package.
+ *
+ * @author Matthew Khouzam
+ * @version $Revision: 1.0 $
+ */
+@RunWith(Suite.class)
+@Suite.SuiteClasses({
+ LexicalScopeTest.class
+})
+public class TestAll {
+
+}
public void testGrowingLive() throws CTFReaderException, FileNotFoundException, IOException {
try (CTFTraceReader reader = new CTFTraceReader(fFixture);) {
reader.setLive(true);
- assertEquals("0x29", reader.getCurrentEventDef().getFields().getDefinitions().get("f").toString());
+ assertEquals("0x29", reader.getCurrentEventDef().getFields().getDefinition("f").toString());
reader.advance();
try (FileOutputStream fos = new FileOutputStream(fGrowingStream, true)) {
fos.write(fPackets[1]);
}
reader.advance();
assertNotNull(reader.getCurrentEventDef());
- assertEquals("0xbab4face", reader.getCurrentEventDef().getFields().getDefinitions().get("f").toString());
+ assertEquals("0xbab4face", reader.getCurrentEventDef().getFields().getDefinition("f").toString());
}
}
public void testGrowingNotLive() throws CTFReaderException, FileNotFoundException, IOException {
try (CTFTraceReader reader = new CTFTraceReader(fFixture);) {
reader.setLive(false);
- assertEquals("0x29", reader.getCurrentEventDef().getFields().getDefinitions().get("f").toString());
+ assertEquals("0x29", reader.getCurrentEventDef().getFields().getDefinition("f").toString());
reader.advance();
try (FileOutputStream fos = new FileOutputStream(fGrowingStream, true)) {
fos.write(fPackets[1]);
import java.util.Set;
import org.eclipse.linuxtools.ctf.core.event.EventDefinition;
+import org.eclipse.linuxtools.ctf.core.event.types.Definition;
+import org.eclipse.linuxtools.ctf.core.event.types.StringDeclaration;
+import org.eclipse.linuxtools.ctf.core.event.types.StringDefinition;
+import org.eclipse.linuxtools.ctf.core.event.types.StructDeclaration;
import org.eclipse.linuxtools.ctf.core.event.types.StructDefinition;
import org.eclipse.linuxtools.ctf.core.tests.shared.CtfTestTrace;
import org.eclipse.linuxtools.ctf.core.trace.CTFReaderException;
import org.junit.Before;
import org.junit.Test;
+import com.google.common.collect.ImmutableList;
+
/**
* The class <code>StreamInputReaderTest</code> contains tests for the class
* <code>{@link StreamInputReader}</code>.
private StreamInputReader fixture;
+ private static ImmutableList<String> wrap(String s) {
+ return ImmutableList.<String> builder().add(s).build();
+ }
+
/**
* Perform pre-test initialization.
*
fixture = getStreamInputReader();
fixture.setName(1);
fixture.setCurrentEvent(new EventDefinition(new EventDeclaration(),
- getStreamInputReader()));
+ getStreamInputReader(), 0, null, null,
+ new StructDefinition(
+ new StructDeclaration(0),
+ null,
+ "packet",
+ wrap( "field" ),
+ new Definition[] { new StringDefinition(new StringDeclaration(), null, "field", "test") }),
+ null)
+ );
}
private static StreamInputReader getStreamInputReader() throws CTFReaderException {
*/
@Test
public void testGetCurrentPacketContext() {
- StructDefinition result = fixture.getCurrentPacketContext();
+ StructDefinition result = fixture.getCurrentEvent().getPacketContext();
assertNotNull(result);
}
/**
* Run the void goToLastEvent() method test.
- * @throws CTFReaderException error
+ *
+ * @throws CTFReaderException
+ * error
*/
@Test
public void testGoToLastEvent1() throws CTFReaderException {
final long endTimestamp = goToEnd();
final long endTime = 4287422460315L;
- assertEquals(endTime , endTimestamp );
+ assertEquals(endTime, endTimestamp);
}
/**
* Run the void goToLastEvent() method test.
- * @throws CTFReaderException error
+ *
+ * @throws CTFReaderException
+ * error
*/
@Test
public void testGoToLastEvent2() throws CTFReaderException {
long timestamp = -1;
- while(fixture.readNextEvent().equals(CTFResponse.OK)) {
+ while (fixture.readNextEvent().equals(CTFResponse.OK)) {
timestamp = fixture.getCurrentEvent().getTimestamp();
}
long endTimestamp = goToEnd();
- assertEquals(0 , timestamp- endTimestamp );
+ assertEquals(0, timestamp - endTimestamp);
}
private long goToEnd() throws CTFReaderException {
/**
* Run the boolean readNextEvent() method test.
- * @throws CTFReaderException error
+ *
+ * @throws CTFReaderException
+ * error
*/
@Test
public void testReadNextEvent() throws CTFReaderException {
/**
* Run the void seek(long) method test. Seek by direct timestamp
- * @throws CTFReaderException error
+ *
+ * @throws CTFReaderException
+ * error
*/
@Test
public void testSeek_timestamp() throws CTFReaderException {
@Test
public void testSeek_eventDefinition() throws CTFReaderException {
EventDefinition eventDefinition = new EventDefinition(
- new EventDeclaration(), getStreamInputReader());
- eventDefinition.setTimestamp(1L);
+ new EventDeclaration(), getStreamInputReader(), 1L, null, null, null, null);
fixture.setCurrentEvent(eventDefinition);
}
}
\ No newline at end of file
*/
@Test
public void testGetPath() {
- String result = fixture.getPath();
+ String result = fixture.getScopePath().toString();
assertNotNull(result);
}
import static org.junit.Assert.*;
+import java.nio.ByteBuffer;
import java.nio.ByteOrder;
+import org.eclipse.linuxtools.ctf.core.event.io.BitBuffer;
+import org.eclipse.linuxtools.ctf.core.event.scope.IDefinitionScope;
import org.eclipse.linuxtools.ctf.core.event.types.ArrayDeclaration;
import org.eclipse.linuxtools.ctf.core.event.types.ArrayDefinition;
import org.eclipse.linuxtools.ctf.core.event.types.Encoding;
import org.eclipse.linuxtools.ctf.core.event.types.IDeclaration;
-import org.eclipse.linuxtools.ctf.core.event.types.IDefinitionScope;
import org.eclipse.linuxtools.ctf.core.event.types.IntegerDeclaration;
import org.eclipse.linuxtools.ctf.core.event.types.StringDeclaration;
+import org.eclipse.linuxtools.ctf.core.trace.CTFReaderException;
import org.junit.Before;
import org.junit.Test;
/**
* Run the ArrayDefinition createDefinition(DefinitionScope,String) method
* test.
+ *
+ * @throws CTFReaderException
+ * error in the bitbuffer
*/
@Test
- public void testCreateDefinition() {
+ public void testCreateDefinition() throws CTFReaderException {
String fieldName = "";
IDefinitionScope definitionScope = null;
ArrayDefinition result;
- result = fixture.createDefinition(definitionScope, fieldName);
+ byte[] array = { 't', 'e', 's', 't', '\0', 't', 'h', 'i', 's', '\0' };
+ ByteBuffer byb = ByteBuffer.wrap(array);
+ BitBuffer bb = new BitBuffer(byb);
+ result = fixture.createDefinition(definitionScope, fieldName, bb);
assertNotNull(result);
}
*/
@Test
public void testIsString_ownDefs() {
- //it's an array of strings, not a string
+ // it's an array of strings, not a string
assertFalse(fixture.isString());
}
*/
@Test
public void testIsString_complex() {
- final IntegerDeclaration id = new IntegerDeclaration(8, false, 16,
- ByteOrder.LITTLE_ENDIAN, Encoding.UTF8, null, 8);
+ final IntegerDeclaration id = IntegerDeclaration.createDeclaration(8, false, 16,
+ ByteOrder.LITTLE_ENDIAN, Encoding.UTF8, "", 8);
ArrayDeclaration ad = new ArrayDeclaration(0, id);
boolean result = ad.isString();
import java.nio.ByteBuffer;
import java.nio.ByteOrder;
+import java.util.ArrayList;
+import java.util.Arrays;
+import java.util.List;
+import org.eclipse.jdt.annotation.NonNull;
import org.eclipse.linuxtools.ctf.core.event.io.BitBuffer;
+import org.eclipse.linuxtools.ctf.core.event.scope.IDefinitionScope;
+import org.eclipse.linuxtools.ctf.core.event.scope.LexicalScope;
import org.eclipse.linuxtools.ctf.core.event.types.ArrayDeclaration;
import org.eclipse.linuxtools.ctf.core.event.types.ArrayDefinition;
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.IDeclaration;
-import org.eclipse.linuxtools.ctf.core.event.types.IDefinitionScope;
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.StringDeclaration;
*/
public class ArrayDefinitionTest {
- private CTFTrace trace;
+ @NonNull private CTFTrace trace = new CTFTrace();
private ArrayDefinition charArrayFixture;
private ArrayDefinition stringArrayFixture;
private ArrayDefinition longArrayFixture;
}
private ArrayDefinition createLongArray() {
- IntegerDeclaration decl = new IntegerDeclaration(32, false, 10, ByteOrder.BIG_ENDIAN, Encoding.NONE, "none",8);
- IntegerDefinition[] defs = createIntDefs(10, 32);
+ IntegerDeclaration decl = IntegerDeclaration.createDeclaration(32, false, 10, ByteOrder.BIG_ENDIAN, Encoding.NONE, "none", 8);
+ List<Definition> defs = createIntDefs(10, 32);
ArrayDefinition temp = setUpDeclaration(decl, defs);
return temp;
}
private ArrayDefinition createCharArray() {
- IntegerDeclaration decl = new IntegerDeclaration(8, false, 10, ByteOrder.BIG_ENDIAN, Encoding.UTF8, "none",8);
- IntegerDefinition[] defs = createIntDefs(4,8);
+ IntegerDeclaration decl = IntegerDeclaration.createDeclaration(8, false, 10, ByteOrder.BIG_ENDIAN, Encoding.UTF8, "none", 8);
+ List<Definition> defs = createIntDefs(4, 8);
ArrayDefinition temp = setUpDeclaration(decl, defs);
return temp;
}
private ArrayDefinition createStringArray() {
StringDeclaration strDecl = new StringDeclaration();
- StringDefinition[] defs = createDefs();
+ List<Definition> defs = createDefs();
ArrayDefinition temp = setUpDeclaration(strDecl, defs);
return temp;
}
private ArrayDefinition setUpDeclaration(IDeclaration decl,
- Definition[] defs) {
+ @NonNull List<Definition> defs) {
ArrayDeclaration ad = new ArrayDeclaration(0, decl);
- ArrayDefinition temp = new ArrayDefinition(ad , this.trace , "Testx");
- temp.setDefinitions(defs);
+ ArrayDefinition temp = new ArrayDefinition(ad, this.trace, "Testx", defs);
return temp;
}
-
- private static IntegerDefinition[] createIntDefs(int size, int bits) {
- IntegerDefinition[] defs = new IntegerDefinition[size];
+ private @NonNull
+ static List<Definition> createIntDefs(int size, int bits) {
+ List<Definition> defs = new ArrayList<>(size);
for (int i = 0; i < size; i++) {
-
String content = "test" + i;
- defs[i] = new IntegerDefinition(new IntegerDeclaration(bits, false,
- 16, ByteOrder.LITTLE_ENDIAN, Encoding.UTF8, content, 24), null, content);
- defs[i].setValue(i);
+ defs.add(new IntegerDefinition(IntegerDeclaration.createDeclaration(bits, false,
+ 16, ByteOrder.LITTLE_ENDIAN, Encoding.UTF8, content, 24), null, content, i));
}
return defs;
}
- private static StringDefinition[] createDefs() {
+ private @NonNull
+ static List<Definition> createDefs() {
int size = 4;
- StringDefinition[] defs = new StringDefinition[size];
+ List<Definition> defs = new ArrayList<>();
for (int i = 0; i < size; i++) {
-
String content = "test" + i;
- defs[i] = new StringDefinition(
- new StringDeclaration(Encoding.UTF8), null, content);
- defs[i].setValue(content);
+ defs.add(new StringDefinition(
+ new StringDeclaration(Encoding.UTF8), null, content, content));
}
return defs;
}
ArrayDeclaration declaration = charArrayFixture.getDeclaration();
String fieldName = "";
- ArrayDefinition result = new ArrayDefinition(declaration, this.trace, fieldName);
+ @SuppressWarnings("null")
+ ArrayDefinition result = new ArrayDefinition(declaration, this.trace, fieldName, Arrays.asList(new Definition[0]));
assertNotNull(result);
}
public void testArrayDefinition_newDeclaration() {
ArrayDeclaration declaration = new ArrayDeclaration(0,
new StringDeclaration());
- IDefinitionScope definitionScope = null;
- String fieldName = "";
+ IDefinitionScope definitionScope = getDefinitionScope();
- ArrayDefinition result = new ArrayDefinition(declaration, definitionScope, fieldName);
+ String fieldName = "";
+ @SuppressWarnings("null")
+ ArrayDefinition result = new ArrayDefinition(declaration, definitionScope, fieldName , Arrays.asList(new Definition[0]));
assertNotNull(result);
}
*/
@Test
public void testGetDeclaration() {
- charArrayFixture.setDefinitions(new Definition[] {});
ArrayDeclaration result = charArrayFixture.getDeclaration();
assertNotNull(result);
*/
@Test
public void testGetElem_withDefs() {
- Definition defs[] = createDefs();
- charArrayFixture.setDefinitions(defs);
+ List<Definition> defs = createDefs();
+ IDefinitionScope definitionScope = getDefinitionScope();
+ ArrayDefinition ad = new ArrayDefinition(charArrayFixture.getDeclaration(), definitionScope, "test", defs);
int j = 1;
- Definition result = charArrayFixture.getElem(j);
+ Definition result = ad.getElem(j);
assertNotNull(result);
}
- /**
- * Run the void read(BitBuffer) method test.
- * @throws CTFReaderException error
- */
- @Test
- public void testRead_noDefs() throws CTFReaderException {
- BitBuffer input = new BitBuffer(ByteBuffer.allocateDirect(128));
+ @NonNull private static IDefinitionScope getDefinitionScope() {
+ return new IDefinitionScope() {
+
+ @Override
+ public Definition lookupDefinition(String lookupPath) {
+ return null;
+ }
- charArrayFixture.read(input);
+ @Override
+ public LexicalScope getScopePath() {
+ return null;
+ }
+ };
}
/**
* Run the void read(BitBuffer) method test.
- * @throws CTFReaderException error
+ *
+ * @throws CTFReaderException
+ * error
*/
@Test
- public void testRead_withDefs() throws CTFReaderException {
- charArrayFixture.setDefinitions(new Definition[] {});
- BitBuffer input = new BitBuffer(java.nio.ByteBuffer.allocateDirect(128));
-
- charArrayFixture.read(input);
+ public void testRead_noDefs() throws CTFReaderException {
+ BitBuffer input = new BitBuffer(ByteBuffer.allocateDirect(128));
+ charArrayFixture.getDeclaration().createDefinition(null, "test", input);
}
/**
String result = charArrayFixture.toString();
assertNotNull(result);
}
+
/**
* Run the String toString() method test.
*/
String result = stringArrayFixture.toString();
assertNotNull(result);
}
+
/**
* Run the String toString() method test.
*/
assertNotNull(result);
}
+
/**
* Run the String toString() method test.
*/
import static org.junit.Assert.assertNotNull;
-import org.eclipse.linuxtools.ctf.core.event.io.BitBuffer;
+import org.eclipse.jdt.annotation.NonNull;
+import org.eclipse.linuxtools.ctf.core.event.scope.IDefinitionScope;
import org.eclipse.linuxtools.ctf.core.event.types.Definition;
import org.eclipse.linuxtools.ctf.core.event.types.IDeclaration;
-import org.eclipse.linuxtools.ctf.core.event.types.IDefinitionScope;
+import org.eclipse.linuxtools.ctf.core.event.types.StringDeclaration;
import org.junit.Test;
/**
* The class <code>DefinitionTest</code> contains tests for the class
* <code>{@link Definition}</code>.
*
- * @author ematkho
+ * @author Matthew Khouzam
* @version $Revision: 1.0 $
*/
-@SuppressWarnings("javadoc")
public class DefinitionTest {
/**
* Since Definition is abstract, we'll minimally extend it here to
* instantiate it.
*/
- class DefTest extends Definition {
+ static class DefTest extends Definition {
- public DefTest(IDefinitionScope definitionScope, String fieldName) {
- super(definitionScope, fieldName);
- }
+ @NonNull
+ private static final StringDeclaration STRINGDEF = new StringDeclaration();
- @Override
- public void read(BitBuffer input) {
- /* Just a test, no need to implement anything */
+ public DefTest(IDefinitionScope definitionScope, @NonNull String fieldName) {
+ super(DefTest.STRINGDEF, definitionScope, fieldName);
}
@Override
+ @NonNull
public IDeclaration getDeclaration() {
- // TODO Auto-generated method stub
- return null;
+ return DefTest.STRINGDEF;
}
}
+ /**
+ * Test a definition
+ */
@Test
public void testToString() {
Definition fixture = new DefTest(null, "Hello");
import static org.junit.Assert.assertNull;
import static org.junit.Assert.assertTrue;
+import java.nio.ByteBuffer;
import java.nio.ByteOrder;
+import org.eclipse.linuxtools.ctf.core.event.io.BitBuffer;
+import org.eclipse.linuxtools.ctf.core.event.scope.IDefinitionScope;
import org.eclipse.linuxtools.ctf.core.event.types.Encoding;
import org.eclipse.linuxtools.ctf.core.event.types.EnumDeclaration;
import org.eclipse.linuxtools.ctf.core.event.types.EnumDefinition;
-import org.eclipse.linuxtools.ctf.core.event.types.IDefinitionScope;
import org.eclipse.linuxtools.ctf.core.event.types.IntegerDeclaration;
+import org.eclipse.linuxtools.ctf.core.trace.CTFReaderException;
import org.junit.Before;
import org.junit.Test;
*/
@Before
public void setUp() {
- fixture = new EnumDeclaration(new IntegerDeclaration(1, false, 1,
- ByteOrder.BIG_ENDIAN, Encoding.ASCII, null, 8));
+ fixture = new EnumDeclaration(IntegerDeclaration.createDeclaration(1, false, 1,
+ ByteOrder.BIG_ENDIAN, Encoding.ASCII, "", 8));
}
/**
*/
@Test
public void testEnumDeclaration() {
- IntegerDeclaration containerType = new IntegerDeclaration(1, false, 1,
- ByteOrder.BIG_ENDIAN, Encoding.ASCII, null, 8);
+ IntegerDeclaration containerType = IntegerDeclaration.createDeclaration(1, false, 1,
+ ByteOrder.BIG_ENDIAN, Encoding.ASCII, "", 8);
EnumDeclaration result = new EnumDeclaration(containerType);
/**
* Run the EnumDefinition createDefinition(DefinitionScope,String) method
* test.
+ *
+ * @throws CTFReaderException
+ * out of bounds error, won't happen
*/
@Test
- public void testCreateDefinition() {
+ public void testCreateDefinition() throws CTFReaderException {
IDefinitionScope definitionScope = null;
String fieldName = "";
+ byte[] array = { 't', 'e', 's', 't', '\0', 't', 'h', 'i', 's', '\0' };
+ ByteBuffer byb = ByteBuffer.wrap(array);
+ BitBuffer bb = new BitBuffer(byb);
EnumDefinition result = fixture.createDefinition(definitionScope,
- fieldName);
+ fieldName, bb);
assertNotNull(result);
}
import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertNotNull;
-import static org.junit.Assert.assertTrue;
-import java.nio.ByteBuffer;
import java.nio.ByteOrder;
-import org.eclipse.linuxtools.ctf.core.event.io.BitBuffer;
import org.eclipse.linuxtools.ctf.core.event.types.Encoding;
import org.eclipse.linuxtools.ctf.core.event.types.EnumDeclaration;
import org.eclipse.linuxtools.ctf.core.event.types.EnumDefinition;
import org.eclipse.linuxtools.ctf.core.event.types.IntegerDeclaration;
-import org.eclipse.linuxtools.ctf.core.trace.CTFReaderException;
+import org.eclipse.linuxtools.ctf.core.event.types.IntegerDefinition;
import org.junit.Before;
import org.junit.Test;
*/
public class EnumDefinitionTest {
- private EnumDefinition fixture;
+ private EnumDefinition fixtureA;
+ private EnumDefinition fixtureB;
/**
* Perform pre-test initialization.
*/
@Before
public void setUp() {
+ IntegerDeclaration integerDeclaration = IntegerDeclaration.createDeclaration(1, false, 1, ByteOrder.BIG_ENDIAN,
+ Encoding.ASCII, "", 8);
EnumDeclaration declaration = new EnumDeclaration(
- new IntegerDeclaration(1, false, 1, ByteOrder.BIG_ENDIAN,
- Encoding.ASCII, null, 8));
+ integerDeclaration);
declaration.add(0, 10, "a");
declaration.add(11, 20, "b");
String fieldName = "";
- fixture = new EnumDefinition(declaration, null, fieldName);
+ fixtureA = new EnumDefinition(declaration, null, fieldName, new IntegerDefinition(integerDeclaration, null, fieldName, 4));
+ fixtureB = new EnumDefinition(declaration, null, fieldName, new IntegerDefinition(integerDeclaration, null, fieldName, 12));
}
/**
*/
@Test
public void testEnumDefinition() {
- assertNotNull(fixture);
+ assertNotNull(fixtureA);
+ assertNotNull(fixtureB);
}
/**
*/
@Test
public void testGetValue() {
- String result = fixture.getValue();
+ String result = fixtureA.getValue();
assertNotNull(result);
+ assertEquals("a", result);
}
/**
*/
@Test
public void testGetIntegerValue_one() {
- fixture.setIntegerValue(1L);
- long result = fixture.getIntegerValue();
-
- assertEquals(1L, result);
- }
-
- /**
- * Run the String getValue() method test.
- */
- @Test
- public void testGetIntegerValue_zero() {
- fixture.setIntegerValue(0);
- long result = fixture.getIntegerValue();
-
- assertTrue(0 == result);
- }
-
- /**
- * Run the void read(BitBuffer) method test.
- * @throws CTFReaderException error
- */
- @Test
- public void testRead() throws CTFReaderException {
- fixture.setIntegerValue(1L);
- BitBuffer input = new BitBuffer(ByteBuffer.allocateDirect(128));
-
- fixture.read(input);
+ long result = fixtureA.getIntegerValue();
+ assertEquals(4L, result);
}
/**
*/
@Test
public void testToString() {
- fixture.setIntegerValue(16);
- String result = fixture.toString();
+ String result = fixtureB.toString();
- assertEquals("{ value = b, container = 16 }", result);
+ assertEquals("{ value = b, container = 12 }", result);
}
}
\ No newline at end of file
@Test
public void testEventDefinition() throws CTFReaderException {
CTFTrace trace = testTrace.getTrace();
- EventDefinition ed = new EventDefinition(null, null);
+ EventDefinition ed = null;
try (CTFTraceReader tr = new CTFTraceReader(trace);) {
tr.advance();
ed = tr.getCurrentEventDef();
}
assertNotNull(ed);
- assertNotNull(ed.getPath());
+ assertNotNull(ed.getScopePath());
assertNotNull(ed.getDeclaration());
assertNotNull(ed.getFields());
assertNull(ed.getContext());
assertNotNull(ed.getPacketContext());
assertNotNull(ed.getCPU());
- assertNotNull(ed.getPacketContext());
assertNotNull(ed.getStreamInputReader());
assertNull(ed.lookupDefinition("context"));
assertNotNull(ed.lookupDefinition("fields"));
assertNull(ed.lookupDefinition("other"));
assertNotNull(ed.toString());
- ed.setContext(ed.getFields());
- assertNotNull(ed.toString());
}
EventDeclaration e1;
import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertNotNull;
-import static org.junit.Assert.assertTrue;
+import java.nio.ByteBuffer;
import java.nio.ByteOrder;
+import org.eclipse.jdt.annotation.NonNull;
import org.eclipse.linuxtools.ctf.core.event.io.BitBuffer;
import org.eclipse.linuxtools.ctf.core.event.types.FloatDeclaration;
import org.eclipse.linuxtools.ctf.core.event.types.FloatDefinition;
/**
* The class <code>IntegerDefinitionTest</code> contains tests for the class
* <code>{@link IntegerDefinition}</code>.
- *
+ *
* @author ematkho
* @version $Revision: 1.0 $
*/
private FloatDefinition fixture;
private FloatDefinition singleFixture;
- private FloatDefinition doubleFixture; //all the way.
+ private FloatDefinition doubleFixture; // all the way.
private FloatDeclaration parent;
+ @NonNull
private static final String fieldName = "float";
/**
* Perform pre-test initialization.
+ *
+ * @throws CTFReaderException
+ * error creating floats
*/
@Before
- public void setUp(){
+ public void setUp() throws CTFReaderException {
testFloat248();
testFloat5311();
}
@Test
- public void testFloat248() {
+ public void testFloat248() throws CTFReaderException {
parent = new FloatDeclaration(8, 24, ByteOrder.nativeOrder(), 0);
- singleFixture = parent.createDefinition(null, fieldName);
+ BitBuffer bb = create32BitFloatByteBuffer();
+ singleFixture = parent.createDefinition(null, fieldName, bb);
assertNotNull(singleFixture);
}
-
-
@Test
- public void testFloat5311() {
+ public void testFloat5311() throws CTFReaderException {
parent = new FloatDeclaration(11, 53, ByteOrder.nativeOrder(), 0);
- doubleFixture = parent.createDefinition(null, fieldName);
+ BitBuffer bb = create64BitFloatByteBuffer();
+ doubleFixture = parent.createDefinition(null, fieldName, bb);
assertNotNull(doubleFixture);
}
@Test
- public void testFloat32Bit(){
- for(int i = 1; i < 31 ; i++) {
- parent = new FloatDeclaration(i, 32-i, ByteOrder.nativeOrder(), 0);
- fixture = parent.createDefinition(null, fieldName);
+ public void testFloat32Bit() throws CTFReaderException {
+ for (int i = 1; i < 31; i++) {
+ parent = new FloatDeclaration(i, 32 - i, ByteOrder.nativeOrder(), 0);
+
+ fixture = parent.createDefinition(null, fieldName, create32BitFloatByteBuffer());
assertNotNull(fixture);
- fixture.setValue(2.0);
- assertTrue(fixture.toString().contains("2"));
+ assertEquals("test" + i, "2.0", fixture.toString());
}
}
@Test
- public void testFloat64Bit() throws CTFReaderException{
- for(int i = 1; i < 63 ; i++) {
- parent = new FloatDeclaration(i, 64-i, ByteOrder.nativeOrder(), 0);
- fixture = parent.createDefinition(null, fieldName);
+ public void testFloat64Bit() throws CTFReaderException {
+ for (int i = 1; i < 63; i++) {
+ parent = new FloatDeclaration(i, 64 - i, ByteOrder.nativeOrder(), 0);
+ fixture = parent.createDefinition(null, fieldName, create64BitFloatByteBuffer());
assertNotNull(fixture);
- BitBuffer input = new BitBuffer(java.nio.ByteBuffer.allocateDirect(128));
- fixture.read(input);
- fixture.setValue(2.0);
- assertTrue(fixture.toString().contains("2"));
+ if (i <= 32) {
+ assertEquals("test" + i, "2.0", fixture.toString());
+ } else if (i == 33) {
+ assertEquals("test" + i, "1.0", fixture.toString());
+ } else {
+ assertNotNull(fixture.getValue());
+ }
+
}
}
@Test
- public void testFloat48Bit() throws CTFReaderException{
+ public void testFloat48Bit() throws CTFReaderException {
parent = new FloatDeclaration(12, 32, ByteOrder.nativeOrder(), 0);
- fixture = parent.createDefinition(null, fieldName);
+ fixture = parent.createDefinition(null, fieldName, create64BitFloatByteBuffer());
assertNotNull(fixture);
- BitBuffer input = new BitBuffer(java.nio.ByteBuffer.allocateDirect(128));
- fixture.read(input);
-
- assertEquals(Double.NaN ,fixture.getValue(),0.1);
+ assertEquals(Double.NaN, fixture.getValue(), 0.1);
}
/**
*/
@Test
public void testGetDeclaration() {
- singleFixture.setValue(2.0);
FloatDeclaration result = singleFixture.getDeclaration();
assertNotNull(result);
}
*/
@Test
public void testGetValue() {
- singleFixture.setValue(2.0);
double result = singleFixture.getValue();
- assertEquals(2.0, result,0.1);
- }
-
- /**
- * Run the void read(BitBuffer) method test.
- * @throws CTFReaderException error
- */
- @Test
- public void testRead() throws CTFReaderException {
- singleFixture.setValue(2.0);
- BitBuffer input = new BitBuffer(java.nio.ByteBuffer.allocateDirect(128));
- singleFixture.read(input);
+ assertEquals(2.0, result, 0.1);
}
/**
*/
@Test
public void testToString() {
- singleFixture.setValue(222.22);
String result = singleFixture.toString();
assertNotNull(result);
+ assertEquals("2.0", result);
+ }
+
+ @NonNull
+ private static BitBuffer create32BitFloatByteBuffer() {
+ float[] data = new float[2];
+ data[0] = 2.0f;
+ data[1] = 3.14f;
+ ByteBuffer byb = ByteBuffer.allocate(128);
+ byb.mark();
+ byb.putFloat(data[0]);
+ byb.putFloat(data[1]);
+ byb.reset();
+ BitBuffer bb = new BitBuffer(byb);
+ return bb;
+ }
+
+ @NonNull
+ private static BitBuffer create64BitFloatByteBuffer() {
+ double[] data = new double[2];
+ data[0] = 2.0f;
+ data[1] = 3.14f;
+ ByteBuffer byb = ByteBuffer.allocate(128);
+ byb.mark();
+ byb.putDouble(data[0]);
+ byb.putDouble(data[1]);
+ byb.reset();
+ BitBuffer bb = new BitBuffer(byb);
+ return bb;
}
}
*/
@Before
public void setUp() {
- fixture = new IntegerDeclaration(1, false, 1, ByteOrder.BIG_ENDIAN,
- Encoding.ASCII, null, 32);
+ fixture = IntegerDeclaration.createDeclaration(1, false, 1, ByteOrder.BIG_ENDIAN,
+ Encoding.ASCII, "", 32);
}
/**
ByteOrder byteOrder = ByteOrder.BIG_ENDIAN;
Encoding encoding = Encoding.ASCII;
- IntegerDeclaration result = new IntegerDeclaration(len, signed, base,
- byteOrder, encoding, null, 16);
+ IntegerDeclaration result = IntegerDeclaration.createDeclaration(len, signed, base,
+ byteOrder, encoding, "", 16);
assertNotNull(result);
assertEquals(1, result.getBase());
int base = 1;
ByteOrder byteOrder = ByteOrder.BIG_ENDIAN;
Encoding encoding = Encoding.ASCII;
- new IntegerDeclaration(len, signed, base, byteOrder, encoding, null, 16);
+ IntegerDeclaration.createDeclaration(len, signed, base, byteOrder, encoding, "", 16);
}
/**
int base = 1;
ByteOrder byteOrder = ByteOrder.BIG_ENDIAN;
Encoding encoding = Encoding.ASCII;
- new IntegerDeclaration(len, signed, base, byteOrder, encoding, null, 16);
+ IntegerDeclaration.createDeclaration(len, signed, base, byteOrder, encoding, "", 16);
}
/**
*/
@Test
public void testIsCharacter_8bytes() {
- IntegerDeclaration fixture8 = new IntegerDeclaration(8, true, 1,
- ByteOrder.BIG_ENDIAN, Encoding.ASCII, null, 8);
+ IntegerDeclaration fixture8 = IntegerDeclaration.createDeclaration(8, true, 1,
+ ByteOrder.BIG_ENDIAN, Encoding.ASCII, "", 8);
boolean result = fixture8.isCharacter();
assertEquals(true, result);
*/
@Test
public void testIsSigned_signed() {
- IntegerDeclaration fixtureSigned = new IntegerDeclaration(2, true,
- 1, ByteOrder.BIG_ENDIAN, Encoding.ASCII, null, 8);
+ IntegerDeclaration fixtureSigned = IntegerDeclaration.createDeclaration(2, true,
+ 1, ByteOrder.BIG_ENDIAN, Encoding.ASCII, "", 8);
boolean result = fixtureSigned.isSigned();
assertEquals(true, result);
}
public void testMaxValue() {
assertEquals(BigInteger.ONE, fixture.getMaxValue());
- IntegerDeclaration signed8bit = new IntegerDeclaration(8, true, 1, ByteOrder.BIG_ENDIAN, Encoding.ASCII, null, 32);
+ IntegerDeclaration signed8bit = IntegerDeclaration.createDeclaration(8, true, 1, ByteOrder.BIG_ENDIAN, Encoding.ASCII, "", 32);
assertEquals(BigInteger.valueOf(127), signed8bit.getMaxValue());
- IntegerDeclaration unsigned8bit = new IntegerDeclaration(8, false, 1, ByteOrder.BIG_ENDIAN, Encoding.ASCII, null, 32);
+ IntegerDeclaration unsigned8bit = IntegerDeclaration.createDeclaration(8, false, 1, ByteOrder.BIG_ENDIAN, Encoding.ASCII, "", 32);
assertEquals(BigInteger.valueOf(255), unsigned8bit.getMaxValue());
- IntegerDeclaration signed32bit = new IntegerDeclaration(32, true, 1, ByteOrder.BIG_ENDIAN, Encoding.ASCII, null, 32);
+ IntegerDeclaration signed32bit = IntegerDeclaration.createDeclaration(32, true, 1, ByteOrder.BIG_ENDIAN, Encoding.ASCII, "", 32);
assertEquals(BigInteger.valueOf(2147483647), signed32bit.getMaxValue());
- IntegerDeclaration unsigned32bit = new IntegerDeclaration(32, false, 1, ByteOrder.BIG_ENDIAN, Encoding.ASCII, null, 32);
+ IntegerDeclaration unsigned32bit = IntegerDeclaration.createDeclaration(32, false, 1, ByteOrder.BIG_ENDIAN, Encoding.ASCII, "", 32);
assertEquals(BigInteger.valueOf(4294967295l), unsigned32bit.getMaxValue());
- IntegerDeclaration signed64bit = new IntegerDeclaration(64, true, 1, ByteOrder.BIG_ENDIAN, Encoding.ASCII, null, 32);
+ IntegerDeclaration signed64bit = IntegerDeclaration.createDeclaration(64, true, 1, ByteOrder.BIG_ENDIAN, Encoding.ASCII, "", 32);
assertEquals(BigInteger.valueOf(9223372036854775807L), signed64bit.getMaxValue());
- IntegerDeclaration unsigned64bit = new IntegerDeclaration(64, false, 1, ByteOrder.BIG_ENDIAN, Encoding.ASCII, null, 32);
+ IntegerDeclaration unsigned64bit = IntegerDeclaration.createDeclaration(64, false, 1, ByteOrder.BIG_ENDIAN, Encoding.ASCII, "", 32);
assertEquals(BigInteger.valueOf(2).pow(64).subtract(BigInteger.ONE), unsigned64bit.getMaxValue());
}
public void testMinValue() {
assertEquals(BigInteger.ZERO, fixture.getMinValue());
- IntegerDeclaration signed8bit = new IntegerDeclaration(8, true, 1, ByteOrder.BIG_ENDIAN, Encoding.ASCII, null, 32);
+ IntegerDeclaration signed8bit = IntegerDeclaration.createDeclaration(8, true, 1, ByteOrder.BIG_ENDIAN, Encoding.ASCII, "", 32);
assertEquals(BigInteger.valueOf(-128), signed8bit.getMinValue());
- IntegerDeclaration unsigned8bit = new IntegerDeclaration(8, false, 1, ByteOrder.BIG_ENDIAN, Encoding.ASCII, null, 32);
+ IntegerDeclaration unsigned8bit = IntegerDeclaration.createDeclaration(8, false, 1, ByteOrder.BIG_ENDIAN, Encoding.ASCII, "", 32);
assertEquals(BigInteger.ZERO, unsigned8bit.getMinValue());
- IntegerDeclaration signed32bit = new IntegerDeclaration(32, true, 1, ByteOrder.BIG_ENDIAN, Encoding.ASCII, null, 32);
+ IntegerDeclaration signed32bit = IntegerDeclaration.createDeclaration(32, true, 1, ByteOrder.BIG_ENDIAN, Encoding.ASCII, "", 32);
assertEquals(BigInteger.valueOf(-2147483648), signed32bit.getMinValue());
- IntegerDeclaration unsigned32bit = new IntegerDeclaration(32, false, 1, ByteOrder.BIG_ENDIAN, Encoding.ASCII, null, 32);
+ IntegerDeclaration unsigned32bit = IntegerDeclaration.createDeclaration(32, false, 1, ByteOrder.BIG_ENDIAN, Encoding.ASCII, "", 32);
assertEquals(BigInteger.ZERO, unsigned32bit.getMinValue());
- IntegerDeclaration signed64bit = new IntegerDeclaration(64, true, 1, ByteOrder.BIG_ENDIAN, Encoding.ASCII, null, 32);
+ IntegerDeclaration signed64bit = IntegerDeclaration.createDeclaration(64, true, 1, ByteOrder.BIG_ENDIAN, Encoding.ASCII, "", 32);
assertEquals(BigInteger.valueOf(-9223372036854775808L), signed64bit.getMinValue());
- IntegerDeclaration unsigned64bit = new IntegerDeclaration(64, false, 1, ByteOrder.BIG_ENDIAN, Encoding.ASCII, null, 32);
+ IntegerDeclaration unsigned64bit = IntegerDeclaration.createDeclaration(64, false, 1, ByteOrder.BIG_ENDIAN, Encoding.ASCII, "", 32);
assertEquals(BigInteger.ZERO, unsigned64bit.getMinValue());
}
}
\ No newline at end of file
import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertNotNull;
+import java.nio.ByteBuffer;
import java.nio.ByteOrder;
+import org.eclipse.jdt.annotation.NonNull;
import org.eclipse.linuxtools.ctf.core.event.io.BitBuffer;
+import org.eclipse.linuxtools.ctf.core.event.scope.IDefinitionScope;
import org.eclipse.linuxtools.ctf.core.event.types.Encoding;
-import org.eclipse.linuxtools.ctf.core.event.types.IDefinitionScope;
import org.eclipse.linuxtools.ctf.core.event.types.IntegerDeclaration;
import org.eclipse.linuxtools.ctf.core.event.types.IntegerDefinition;
import org.eclipse.linuxtools.ctf.core.trace.CTFReaderException;
public class IntegerDefinitionTest {
private IntegerDefinition fixture;
- String name = "testInt";
- String clockName = "clock";
+ @NonNull private static final String NAME = "testInt";
+ @NonNull private static final String clockName = "clock";
/**
* Perform pre-test initialization.
+ *
+ * @throws CTFReaderException
+ * won't happen
*/
@Before
- public void setUp() {
- IntegerDeclaration id = new IntegerDeclaration(1, false, 1, ByteOrder.BIG_ENDIAN, Encoding.NONE, clockName, 8);
- fixture = id.createDefinition(null, name);
+ public void setUp() throws CTFReaderException {
+ IntegerDeclaration id = IntegerDeclaration.createDeclaration(1, false, 1, ByteOrder.BIG_ENDIAN, Encoding.NONE, clockName, 8);
+ ByteBuffer byb = ByteBuffer.allocate(128);
+ byb.mark();
+ byb.putInt(1);
+ byb.reset();
+ BitBuffer bb = new BitBuffer(byb);
+ fixture = id.createDefinition(null, NAME, bb);
}
/**
*/
@Test
public void testIntegerDefinition() {
- IntegerDeclaration declaration = new IntegerDeclaration(1, false, 1,
- ByteOrder.BIG_ENDIAN, Encoding.ASCII, null, 8);
+ IntegerDeclaration declaration = IntegerDeclaration.createDeclaration(1, false, 1,
+ ByteOrder.BIG_ENDIAN, Encoding.ASCII, "", 8);
IDefinitionScope definitionScope = null;
String fieldName = "";
IntegerDefinition result = new IntegerDefinition(declaration,
- definitionScope, fieldName);
+ definitionScope, fieldName, 1);
assertNotNull(result);
}
*/
@Test
public void testGetDeclaration() {
- fixture.setValue(1L);
-
IntegerDeclaration result = fixture.getDeclaration();
assertNotNull(result);
}
*/
@Test
public void testGetValue() {
- fixture.setValue(1L);
-
long result = fixture.getValue();
- assertEquals(1L, result);
- }
-
- /**
- * Run the void read(BitBuffer) method test.
- * @throws CTFReaderException error
- */
- @Test
- public void testRead() throws CTFReaderException {
- fixture.setValue(1L);
- BitBuffer input = new BitBuffer(java.nio.ByteBuffer.allocateDirect(128));
-
- fixture.read(input);
+ assertEquals(0L, result);
}
/**
*/
@Test
public void testToString() {
- fixture.setValue(1L);
-
String result = fixture.toString();
- assertNotNull(result);
+ assertEquals("0", result);
}
/**
import java.nio.ByteBuffer;
import java.nio.ByteOrder;
+import org.eclipse.jdt.annotation.NonNull;
import org.eclipse.linuxtools.ctf.core.event.io.BitBuffer;
import org.eclipse.linuxtools.ctf.core.event.types.Encoding;
import org.eclipse.linuxtools.ctf.core.event.types.IntegerDeclaration;
*/
public class IntegerEndiannessTest {
- private static String name = "testInt";
- private static String clockName = "clock";
+ @NonNull private static final String name = "testInt";
+ @NonNull private static final String clockName = "clock";
private ByteBuffer bb;
- private BitBuffer input;
+ @NonNull private BitBuffer input = new BitBuffer(java.nio.ByteBuffer.allocate(0));
/**
* Set up the bit-buffer to be used
*/
@Test
public void test32BE() throws CTFReaderException {
- IntegerDeclaration be = new IntegerDeclaration(32, true, 1, ByteOrder.BIG_ENDIAN, Encoding.NONE, clockName, 8);
- IntegerDefinition fixture_be = be.createDefinition(null, name);
- fixture_be.read(input);
+ IntegerDeclaration be = IntegerDeclaration.createDeclaration(32, true, 1, ByteOrder.BIG_ENDIAN, Encoding.NONE, clockName, 8);
+ IntegerDefinition fixture_be = be.createDefinition(null, name, input);
assertEquals(0xabcdef12, fixture_be.getValue());
}
*/
@Test
public void test64BE() throws CTFReaderException {
- IntegerDeclaration be = new IntegerDeclaration(64, true, 1, ByteOrder.BIG_ENDIAN, Encoding.NONE, clockName, 8);
- IntegerDefinition fixture_be = be.createDefinition(null, name);
- fixture_be.read(input);
+ IntegerDeclaration be = IntegerDeclaration.createDeclaration(64, true, 1, ByteOrder.BIG_ENDIAN, Encoding.NONE, clockName, 8);
+ IntegerDefinition fixture_be = be.createDefinition(null, name, input);
assertEquals(0xabcdef123456789aL, fixture_be.getValue());
}
*/
@Test
public void test32LE() throws CTFReaderException {
- IntegerDeclaration le = new IntegerDeclaration(32, true, 1, ByteOrder.LITTLE_ENDIAN, Encoding.NONE, clockName, 8);
- IntegerDefinition fixture_le = le.createDefinition(null, name);
- fixture_le.read(input);
+ IntegerDeclaration le = IntegerDeclaration.createDeclaration(32, true, 1, ByteOrder.LITTLE_ENDIAN, Encoding.NONE, clockName, 8);
+ IntegerDefinition fixture_le = le.createDefinition(null, name, input);
assertEquals(0x12efcdab, fixture_le.getValue());
}
*/
@Test
public void test64LE() throws CTFReaderException {
- IntegerDeclaration le = new IntegerDeclaration(64, true, 1, ByteOrder.LITTLE_ENDIAN, Encoding.NONE, clockName, 8);
- IntegerDefinition fixture_le = le.createDefinition(null, name);
- fixture_le.read(input);
+ IntegerDeclaration le = IntegerDeclaration.createDeclaration(64, true, 1, ByteOrder.LITTLE_ENDIAN, Encoding.NONE, clockName, 8);
+ IntegerDefinition fixture_le = le.createDefinition(null, name, input);
assertEquals(0x9a78563412efcdabL, fixture_le.getValue());
}
}
import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertNotNull;
+import java.nio.ByteBuffer;
import java.nio.ByteOrder;
+import org.eclipse.jdt.annotation.NonNull;
+import org.eclipse.linuxtools.ctf.core.event.io.BitBuffer;
+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.IDeclaration;
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.SequenceDeclaration;
import org.eclipse.linuxtools.ctf.core.event.types.SequenceDefinition;
import org.eclipse.linuxtools.ctf.core.event.types.StringDeclaration;
import org.eclipse.linuxtools.ctf.core.event.types.StructDeclaration;
import org.eclipse.linuxtools.ctf.core.event.types.StructDefinition;
+import org.eclipse.linuxtools.ctf.core.trace.CTFReaderException;
import org.junit.Before;
import org.junit.Test;
+import com.google.common.collect.ImmutableList;
+
/**
* The class <code>SequenceDeclarationTest</code> contains tests for the class
* <code>{@link SequenceDeclaration}</code>.
@SuppressWarnings("javadoc")
public class SequenceDeclarationTest {
- private SequenceDeclaration fixture;
+ @NonNull private static final String FIELD_NAME = "LengthName";
- static final String fieldName = "LengthName";
+ private SequenceDeclaration fixture;
+ @NonNull private BitBuffer input = new BitBuffer();
@Before
public void setUp() {
- fixture = new SequenceDeclaration(fieldName, new StringDeclaration());
+ fixture = new SequenceDeclaration(FIELD_NAME, new StringDeclaration());
+ byte array[] = { 't', 'e', 's', 't', '\0', 't', 'h', 'i', 's', '\0' };
+ ByteBuffer byb = ByteBuffer.wrap(array);
+ input = new BitBuffer(byb);
}
/**
/**
* Run the SequenceDefinition createDefinition(DefinitionScope,String)
* method test.
+ *
+ * @throws CTFReaderException
+ * an error in the bitbuffer
*/
@Test
- public void testCreateDefinition() {
- IntegerDeclaration id = new IntegerDeclaration(8, false, 8,
- ByteOrder.LITTLE_ENDIAN, Encoding.UTF8, null, 32);
-
+ public void testCreateDefinition() throws CTFReaderException {
+ long seqLen = 2;
+ IntegerDeclaration id = IntegerDeclaration.createDeclaration(8, false, 8,
+ ByteOrder.LITTLE_ENDIAN, Encoding.UTF8, "", 32);
StructDeclaration structDec = new StructDeclaration(0);
- structDec.addField(fieldName, id);
- StructDefinition structDef = new StructDefinition(structDec, null, "x");
- long seqLen = 10;
- structDef.lookupInteger(fieldName).setValue(seqLen);
- SequenceDefinition result = this.fixture.createDefinition(structDef, fieldName);
+ structDec.addField(FIELD_NAME, id);
+ StructDefinition structDef = new StructDefinition(
+ structDec,
+ null,
+ "x",
+ ImmutableList.of(FIELD_NAME),
+ new Definition[] {
+ new IntegerDefinition(
+ id,
+ null,
+ FIELD_NAME,
+ seqLen)
+ });
+ SequenceDefinition result = fixture.createDefinition(structDef, FIELD_NAME, input);
assertNotNull(result);
}
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.SequenceDeclaration;
import org.eclipse.linuxtools.ctf.core.event.types.SequenceDefinition;
import org.eclipse.linuxtools.ctf.core.event.types.StructDeclaration;
import org.junit.Before;
import org.junit.Test;
+import com.google.common.collect.ImmutableList;
+
/**
* The class <code>SequenceDefinitionTest</code> contains tests for the class
* <code>{@link SequenceDefinition}</code>.
private SequenceDefinition fixture;
private final static int seqLen = 15;
+ private static ImmutableList<String> wrap(String s) {
+ return ImmutableList.<String> builder().add(s).build();
+ }
+
/**
* Perform pre-test initialization.
+ *
* @throws CTFReaderException
*/
@Before
StructDeclaration structDec;
StructDefinition structDef;
- IntegerDeclaration id = new IntegerDeclaration(8, false, 8,
- ByteOrder.LITTLE_ENDIAN, Encoding.UTF8, null, 8);
+ IntegerDeclaration id = IntegerDeclaration.createDeclaration(8, false, 8,
+ ByteOrder.LITTLE_ENDIAN, Encoding.UTF8, "", 8);
String lengthName = "LengthName";
structDec = new StructDeclaration(0);
structDec.addField(lengthName, id);
- structDef = new StructDefinition(structDec, null, "x");
+ structDef = new StructDefinition(structDec, null, "x",
+ wrap(lengthName),
+ new Definition[] { new IntegerDefinition(id, null, lengthName, seqLen) });
- structDef.lookupInteger(lengthName).setValue(seqLen);
SequenceDeclaration sd = new SequenceDeclaration(lengthName, id);
- fixture = new SequenceDefinition(sd, structDef, "TestX");
BitBuffer input = new BitBuffer(
java.nio.ByteBuffer.allocateDirect(seqLen * 8));
for (int i = 0; i < seqLen; i++) {
input.putInt(i);
}
- fixture.read(input);
+
+ fixture = sd.createDefinition(structDef, "TestX", input);
assert (fixture != null);
}
StructDefinition structDef;
int len = 32;
- IntegerDeclaration id = new IntegerDeclaration(len, false, len,
- ByteOrder.LITTLE_ENDIAN, Encoding.UTF8, null,8);
+ IntegerDeclaration id = IntegerDeclaration.createDeclaration(len, false, len,
+ ByteOrder.LITTLE_ENDIAN, Encoding.UTF8, "", 8);
String lengthName = "LengthName";
structDec = new StructDeclaration(0);
structDec.addField(lengthName, id);
- structDef = new StructDefinition(structDec, null, "x");
- structDef.lookupInteger(lengthName).setValue(seqLen);
+ structDef = new StructDefinition(structDec, null, "x", wrap(lengthName), new Definition[] { new IntegerDefinition(id, null, lengthName, seqLen) });
+
SequenceDeclaration sd = new SequenceDeclaration(lengthName, id);
- SequenceDefinition ret = new SequenceDefinition(sd, structDef, "TestX");
BitBuffer input = new BitBuffer(
java.nio.ByteBuffer.allocateDirect(seqLen * len));
for (int i = 0; i < seqLen; i++) {
input.putInt(i);
}
- ret.read(input);
+
+ SequenceDefinition ret = sd.createDefinition(structDef, "TestX", input);
assertNotNull(ret);
return ret;
}
*/
@Test
public void testIsString() {
- boolean result = fixture.isString();
+ boolean result = fixture.getDeclaration().isString();
assertTrue(result);
}
- /**
- * Run the void read(BitBuffer) method test.
- * @throws CTFReaderException error
- */
- @Test
- public void testRead() throws CTFReaderException {
- BitBuffer input = new BitBuffer(java.nio.ByteBuffer.allocateDirect(128));
- fixture.read(input);
- }
-
/**
* Run the String toString() method test.
*/
import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertNotNull;
+import java.nio.ByteBuffer;
+
+import org.eclipse.linuxtools.ctf.core.event.io.BitBuffer;
+import org.eclipse.linuxtools.ctf.core.event.scope.IDefinitionScope;
import org.eclipse.linuxtools.ctf.core.event.types.Encoding;
-import org.eclipse.linuxtools.ctf.core.event.types.IDefinitionScope;
import org.eclipse.linuxtools.ctf.core.event.types.StringDeclaration;
import org.eclipse.linuxtools.ctf.core.event.types.StringDefinition;
+import org.eclipse.linuxtools.ctf.core.trace.CTFReaderException;
import org.junit.Before;
import org.junit.Test;
/**
* Run the StringDefinition createDefinition(DefinitionScope,String) method
* test.
+ * @throws CTFReaderException out of buffer exception
*/
@Test
- public void testCreateDefinition() {
+ public void testCreateDefinition() throws CTFReaderException {
IDefinitionScope definitionScope = null;
String fieldName = "id";
+ BitBuffer bb = new BitBuffer(ByteBuffer.allocate(100));
StringDefinition result = fixture.createDefinition(definitionScope,
- fieldName);
+ fieldName, bb);
assertNotNull(result);
}
assertEquals(1, result.ordinal());
}
- /**
- * Run the void setEncoding(Encoding) method test.
- */
- @Test
- public void testSetEncoding() {
- Encoding encoding = Encoding.ASCII;
- fixture.setEncoding(encoding);
- }
-
- /**
+ /**
* Run the String toString() method test.
*/
@Test
import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertNotNull;
+import java.nio.ByteBuffer;
+
import org.eclipse.linuxtools.ctf.core.event.io.BitBuffer;
-import org.eclipse.linuxtools.ctf.core.event.types.IDefinitionScope;
+import org.eclipse.linuxtools.ctf.core.event.scope.IDefinitionScope;
import org.eclipse.linuxtools.ctf.core.event.types.StringDeclaration;
import org.eclipse.linuxtools.ctf.core.event.types.StringDefinition;
import org.eclipse.linuxtools.ctf.core.trace.CTFReaderException;
public class StringDefinitionTest {
private StringDefinition fixture;
+ private String testString;
/**
* Perform pre-test initialization.
+ *
+ * @throws CTFReaderException won't happen
*/
@Before
- public void setUp() {
+ public void setUp() throws CTFReaderException {
String name = "testString";
StringDeclaration stringDec = new StringDeclaration();
- fixture = stringDec.createDefinition(null, name);
+ ByteBuffer byteBuffer = ByteBuffer.allocate(100);
+ BitBuffer bb = new BitBuffer(byteBuffer);
+ byteBuffer.mark();
+ testString = new String("testString");
+ byteBuffer.put(testString.getBytes());
+ byteBuffer.reset();
+ fixture = stringDec.createDefinition(null, name, bb);
}
/**
String fieldName = "";
StringDefinition result = new StringDefinition(declaration,
- definitionScope, fieldName);
+ definitionScope, fieldName, "");
assertNotNull(result);
}
*/
@Test
public void testSetValue() {
- fixture.setValue("dummy");
+
String result = fixture.getValue();
assertNotNull(result);
- assertEquals("dummy", result);
- }
-
- /**
- * Run the void read(BitBuffer) method test.
- * @throws CTFReaderException error
- */
- @Test
- public void testRead() throws CTFReaderException {
- BitBuffer input = new BitBuffer(java.nio.ByteBuffer.allocateDirect(128));
- fixture.read(input);
- }
-
- /**
- * Run the void setDeclaration(StringDeclaration) method test.
- */
- @Test
- public void testSetDeclaration() {
- StringDeclaration declaration = new StringDeclaration();
- fixture.setDeclaration(declaration);
+ assertEquals("testString", result);
}
/**
import static org.junit.Assert.assertNotNull;
import static org.junit.Assert.assertTrue;
-import java.util.List;
+import java.nio.ByteBuffer;
import java.util.Map;
+import org.eclipse.linuxtools.ctf.core.event.io.BitBuffer;
import org.eclipse.linuxtools.ctf.core.event.types.IDeclaration;
import org.eclipse.linuxtools.ctf.core.event.types.StringDeclaration;
import org.eclipse.linuxtools.ctf.core.event.types.StructDeclaration;
import org.eclipse.linuxtools.ctf.core.event.types.StructDefinition;
+import org.eclipse.linuxtools.ctf.core.trace.CTFReaderException;
import org.junit.Before;
import org.junit.Test;
/**
* Run the StructDefinition createDefinition(DefinitionScope,String) method
* test.
+ *
+ * @throws CTFReaderException
+ * out of bounds
*/
@Test
- public void testCreateDefinition() {
+ public void testCreateDefinition() throws CTFReaderException {
String fieldName = "";
- StructDefinition result = fixture.createDefinition(null, fieldName);
+ BitBuffer bb = new BitBuffer(ByteBuffer.allocate(100));
+ StructDefinition result = fixture.createDefinition(null, fieldName, bb);
assertNotNull(result);
}
*/
@Test
public void testGetFieldsList() {
- List<String> result = fixture.getFieldsList();
+ Iterable<String> result = fixture.getFieldsList();
assertNotNull(result);
- assertEquals(0, result.size());
+ assertEquals(false, result.iterator().hasNext());
}
/**
import static org.junit.Assert.assertNull;
import java.nio.ByteBuffer;
-import java.nio.ByteOrder;
-import java.util.Map;
+import org.eclipse.jdt.annotation.NonNull;
import org.eclipse.linuxtools.ctf.core.event.io.BitBuffer;
import org.eclipse.linuxtools.ctf.core.event.types.ArrayDefinition;
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.EnumDeclaration;
import org.eclipse.linuxtools.ctf.core.event.types.EnumDefinition;
import org.eclipse.linuxtools.ctf.core.event.types.IntegerDeclaration;
*/
public class StructDefinitionTest {
- private static final String TEST_STRUCT_ID = "testStruct";
- private static final String ENUM_2 = "y";
- private static final String ENUM_1 = "x";
- private static final String TAG_ID = "Tag";
- private static final String INT_ID = "_id";
- private static final String STRING_ID = "_args";
- private static final String ENUM_ID = "_enumArgs";
- private static final String SEQUENCE_ID = "_seq";
- private static final String LENGTH_SEQ = "_len";
+ @NonNull private static final String TEST_STRUCT_ID = "testStruct";
+ @NonNull private static final String ENUM_2 = "y";
+ @NonNull private static final String ENUM_1 = "x";
+ @NonNull private static final String TAG_ID = "Tag";
+ @NonNull private static final String INT_ID = "_id";
+ @NonNull private static final String STRING_ID = "_args";
+ @NonNull private static final String ENUM_ID = "_enumArgs";
+ @NonNull private static final String SEQUENCE_ID = "_seq";
+ @NonNull private static final String LENGTH_SEQ = "_len";
+ @NonNull private static final String VAR_FIELD_NAME = "SomeVariant";
private StructDefinition fixture;
private StructDefinition emptyStruct;
private StructDefinition simpleStruct;
- private static final String VAR_FIELD_NAME = "SomeVariant";
/**
* Perform pre-test initialization.
+ *
+ * @throws CTFReaderException
+ * won't happen
*/
@Before
- public void setUp() {
+ public void setUp() throws CTFReaderException {
StructDeclaration sDec = new StructDeclaration(12);
- IntegerDeclaration id = new IntegerDeclaration(32, false, 32, ByteOrder.BIG_ENDIAN, Encoding.NONE, null, 8);
- IntegerDeclaration lenDec = new IntegerDeclaration(8, false, 8, ByteOrder.BIG_ENDIAN, Encoding.NONE, null, 8);
+ IntegerDeclaration id = IntegerDeclaration.INT_32B_DECL;
+ IntegerDeclaration lenDec = IntegerDeclaration.UINT_8_DECL;
StringDeclaration sd = new StringDeclaration();
EnumDeclaration ed = new EnumDeclaration(id);
SequenceDeclaration seqDec = new SequenceDeclaration(LENGTH_SEQ, id);
sDec.addField(LENGTH_SEQ, lenDec);
sDec.addField(SEQUENCE_ID, seqDec);
sDec.addField(VAR_FIELD_NAME, varDec);
- fixture = sDec.createDefinition(null, TEST_STRUCT_ID);
- EnumDefinition eDef = tagDec.createDefinition(fixture, TAG_ID);
- VariantDefinition vd = varDec.createDefinition(fixture,VAR_FIELD_NAME );
- vd.setTagDefinition(eDef);
-
+ byte bytes[] = new byte[100];
+ bytes[4] = 1;
+ bytes[8] = 2;
+ bytes[13] = 3;
+ ByteBuffer byteBuffer = ByteBuffer.wrap(bytes);
+ BitBuffer bb = new BitBuffer(byteBuffer);
+ fixture = sDec.createDefinition(null, TEST_STRUCT_ID, bb);
+ EnumDefinition eDef = tagDec.createDefinition(fixture, TAG_ID, bb);
+ assertNotNull(eDef);
+ VariantDefinition vd = varDec.createDefinition(fixture, VAR_FIELD_NAME, bb);
+ assertNotNull(vd);
// Create an empty struct
StructDeclaration esDec = new StructDeclaration(32);
- emptyStruct = esDec.createDefinition(null, TEST_STRUCT_ID);
+ emptyStruct = esDec.createDefinition(null, TEST_STRUCT_ID, bb);
// Create a simple struct with two items
StructDeclaration ssDec = new StructDeclaration(32);
ssDec.addField(INT_ID, id);
ssDec.addField(STRING_ID, sd);
- simpleStruct = ssDec.createDefinition(null, TEST_STRUCT_ID);
+ simpleStruct = ssDec.createDefinition(null, TEST_STRUCT_ID, bb);
}
/**
*/
@Test
public void testGetDefinitions_1() {
- Map<String, Definition> result = fixture.getDefinitions();
+ Definition result = fixture.getDefinition("_id");
assertNotNull(result);
}
assertNotNull(result);
}
- /**
- * Run the void read(BitBuffer) method test.
- * @throws CTFReaderException error
- */
- @Test
- public void testRead_() throws CTFReaderException {
- ByteBuffer bb = ByteBuffer.allocateDirect(128);
- bb.put((byte) 20);
- BitBuffer input = new BitBuffer(bb);
-
- fixture.read(input);
- }
-
/**
* Run the String toString() method test.
*/
import static org.junit.Assert.assertNotNull;
import static org.junit.Assume.assumeTrue;
+import java.nio.ByteBuffer;
+
+import org.eclipse.linuxtools.ctf.core.event.io.BitBuffer;
+import org.eclipse.linuxtools.ctf.core.event.scope.IDefinitionScope;
+import org.eclipse.linuxtools.ctf.core.event.types.Definition;
+import org.eclipse.linuxtools.ctf.core.event.types.EnumDeclaration;
+import org.eclipse.linuxtools.ctf.core.event.types.EnumDefinition;
import org.eclipse.linuxtools.ctf.core.event.types.IDeclaration;
-import org.eclipse.linuxtools.ctf.core.event.types.IDefinitionScope;
+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.StringDeclaration;
+import org.eclipse.linuxtools.ctf.core.event.types.StringDefinition;
import org.eclipse.linuxtools.ctf.core.event.types.StructDeclaration;
import org.eclipse.linuxtools.ctf.core.event.types.StructDefinition;
import org.eclipse.linuxtools.ctf.core.event.types.VariantDeclaration;
import org.junit.Before;
import org.junit.Test;
+import com.google.common.collect.ImmutableList;
+
/**
* The class <code>VariantDeclarationTest</code> contains tests for the class
* <code>{@link VariantDeclaration}</code>.
fixture = new VariantDeclaration();
}
+ private static IDefinitionScope createDefinitionScope() throws CTFReaderException {
+ assumeTrue(testTrace.exists());
+ StructDeclaration declaration = new StructDeclaration(8);
+ VariantDeclaration variantDeclaration = new VariantDeclaration();
+ variantDeclaration.addField("a", IntegerDeclaration.INT_32B_DECL);
+ variantDeclaration.addField("b", IntegerDeclaration.INT_32L_DECL);
+ variantDeclaration.setTag("a");
+
+ EnumDeclaration enumDeclaration = new EnumDeclaration(IntegerDeclaration.UINT_8_DECL);
+ enumDeclaration.add(0, 1, "a");
+ enumDeclaration.add(2, 2, "b");
+ declaration.addField("tag", enumDeclaration);
+ declaration.addField("variant", variantDeclaration);
+ EnumDefinition tagDef = new EnumDefinition(
+ enumDeclaration,
+ null,
+ "tag",
+ new IntegerDefinition(
+ IntegerDeclaration.UINT_8_DECL,
+ null,
+ "test",
+ 0)
+ );
+ VariantDefinition variantDefinition = new VariantDefinition(
+ variantDeclaration,
+ testTrace.getTrace(),
+ "tag",
+ "tag",
+ new StringDefinition(
+ new StringDeclaration(),
+ null,
+ "f",
+ "tag"
+ ));
+
+ IDefinitionScope definitionScope = new StructDefinition(
+ declaration,
+ variantDefinition,
+ "",
+ ImmutableList.of("tag", variantDefinition.getCurrentFieldName()),
+ new Definition[] { tagDef, variantDefinition }
+ );
+
+ return definitionScope;
+ }
+
/**
* Run the VariantDeclaration() constructor test.
*/
* Run the VariantDefinition createDefinition(DefinitionScope,String) method
* test.
*
- * @throws CTFReaderException Should not happen
+ * @throws CTFReaderException
+ * Should not happen
*/
@Test
public void testCreateDefinition() throws CTFReaderException {
- fixture.setTag("");
+ fixture.setTag("tag");
+ fixture.addField("a", IntegerDeclaration.UINT_64B_DECL);
IDefinitionScope definitionScope = createDefinitionScope();
String fieldName = "";
- VariantDefinition result = fixture.createDefinition(definitionScope, fieldName);
+ BitBuffer bb = new BitBuffer(ByteBuffer.allocate(100));
+ VariantDefinition result = fixture.createDefinition(definitionScope, fieldName, bb);
assertNotNull(result);
}
- private static IDefinitionScope createDefinitionScope() throws CTFReaderException {
- assumeTrue(testTrace.exists());
- VariantDeclaration declaration = new VariantDeclaration();
- declaration.setTag("");
- VariantDeclaration variantDeclaration = new VariantDeclaration();
- variantDeclaration.setTag("");
- VariantDefinition variantDefinition = new VariantDefinition(
- variantDeclaration, testTrace.getTrace(), "");
- IDefinitionScope definitionScope = new StructDefinition(
- new StructDeclaration(1L), variantDefinition, "");
- String fieldName = "";
-
- VariantDefinition result = new VariantDefinition(declaration,
- definitionScope, fieldName);
- return result;
- }
-
/**
* Run the boolean hasField(String) method test.
*/
import static org.junit.Assert.assertNotNull;
import static org.junit.Assert.assertNull;
+import java.nio.ByteBuffer;
import java.nio.ByteOrder;
-import java.util.HashMap;
-import java.util.Map;
+import org.eclipse.jdt.annotation.NonNull;
+import org.eclipse.linuxtools.ctf.core.event.io.BitBuffer;
+import org.eclipse.linuxtools.ctf.core.event.scope.IDefinitionScope;
import org.eclipse.linuxtools.ctf.core.event.types.ArrayDeclaration;
import org.eclipse.linuxtools.ctf.core.event.types.ArrayDefinition;
import org.eclipse.linuxtools.ctf.core.event.types.Definition;
import org.eclipse.linuxtools.ctf.core.event.types.EnumDeclaration;
import org.eclipse.linuxtools.ctf.core.event.types.EnumDefinition;
import org.eclipse.linuxtools.ctf.core.event.types.FloatDeclaration;
-import org.eclipse.linuxtools.ctf.core.event.types.IDefinitionScope;
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.SequenceDefinition;
import org.eclipse.linuxtools.ctf.core.event.types.StructDefinition;
import org.eclipse.linuxtools.ctf.core.event.types.VariantDeclaration;
import org.eclipse.linuxtools.ctf.core.event.types.VariantDefinition;
+import org.eclipse.linuxtools.ctf.core.trace.CTFReaderException;
import org.junit.Before;
import org.junit.Test;
+import com.google.common.collect.ImmutableList;
+
/**
* The class <code>VariantDefinitionTest</code> contains tests for the class
* <code>{@link VariantDefinition}</code>.
private VariantDefinition fixture;
- StructDefinition structDefinition;
- private static final String TEST_STRUCT_ID = "testStruct";
-
- private static final String ENUM_7 = "g";
- private static final String ENUM_6 = "f";
- private static final String ENUM_5 = "e";
- private static final String ENUM_4 = "d";
- private static final String ENUM_3 = "c";
- private static final String ENUM_2 = "b";
- private static final String ENUM_1 = "a";
+ StructDefinition fStructDefinition;
+ @NonNull private static final String TEST_STRUCT_ID = "testStruct";
- private static final String TAG_ID = "a";
+ @NonNull private static final String ENUM_7 = "g";
+ @NonNull private static final String ENUM_6 = "f";
+ @NonNull private static final String ENUM_5 = "e";
+ @NonNull private static final String ENUM_4 = "d";
+ @NonNull private static final String ENUM_3 = "c";
+ @NonNull private static final String ENUM_2 = "b";
+ @NonNull private static final String ENUM_1 = "a";
-// private static final String INT_ID = "_id";
-// private static final String STRING_ID = "_args";
-// private static final String ENUM_ID = "_enumArgs";
-// private static final String SEQUENCE_ID = "_seq";
+ @NonNull private static final String TAG_ID = "a";
- private static final String LENGTH_SEQ = "_len";
- private static final String VAR_FIELD_NAME = "var";
+ @NonNull private static final String LENGTH_SEQ = "_len";
+ @NonNull private static final String VAR_FIELD_NAME = "var";
private static final String ENUM_8 = null;
/**
* Perform pre-test initialization.
*
* Not sure it needs to be that complicated, oh well...
+ *
+ * @throws CTFReaderException
+ * won't happen
*/
@Before
- public void setUp() {
+ public void setUp() throws CTFReaderException {
StructDeclaration sDec = new StructDeclaration(12);
StructDeclaration smallStruct = new StructDeclaration(8);
- IntegerDeclaration iDec = new IntegerDeclaration(32, false, 32, ByteOrder.BIG_ENDIAN, Encoding.NONE, null, 8);
- IntegerDeclaration lenDec = new IntegerDeclaration(8, false, 8, ByteOrder.BIG_ENDIAN, Encoding.NONE, null, 8);
+ IntegerDeclaration iDec = IntegerDeclaration.createDeclaration(32, false, 32, ByteOrder.BIG_ENDIAN, Encoding.NONE, "", 8);
+ IntegerDeclaration lenDec = IntegerDeclaration.createDeclaration(8, false, 8, ByteOrder.BIG_ENDIAN, Encoding.NONE, "", 8);
StringDeclaration strDec = new StringDeclaration();
EnumDeclaration enDec = new EnumDeclaration(iDec);
-// SequenceDeclaration seqDec = new SequenceDeclaration(LENGTH_SEQ, iDec);
VariantDeclaration varDec = new VariantDeclaration();
EnumDeclaration tagDec = new EnumDeclaration(iDec);
ArrayDeclaration arrDec = new ArrayDeclaration(2, iDec);
tagDec.add(0, 1, ENUM_1);
tagDec.add(2, 3, ENUM_2);
tagDec.add(4, 5, ENUM_3);
- //tagDec.add(6, 7, ENUM_4); // this should not work
tagDec.add(8, 9, ENUM_5);
tagDec.add(10, 11, ENUM_6);
tagDec.add(12, 13, ENUM_7);
varDec.addField(ENUM_7, fDec);
varDec.addField(ENUM_6, smallStruct);
varDec.addField(ENUM_5, enDec);
- //varDec.addField(ENUM_4, seqDec);// this should not work
varDec.addField(ENUM_3, arrDec);
varDec.addField(ENUM_2, iDec);
varDec.addField(ENUM_1, strDec);
sDec.addField(TAG_ID, tagDec);
sDec.addField(LENGTH_SEQ, lenDec);
-// sDec.addField(SEQUENCE_ID, seqDec);
sDec.addField(VAR_FIELD_NAME, varDec);
varDec.setTag(TAG_ID);
- structDefinition = sDec.createDefinition(null, TEST_STRUCT_ID);
- fixture = (VariantDefinition) structDefinition.getDefinitions().get(VAR_FIELD_NAME);
+ ByteBuffer byteBuffer = ByteBuffer.allocate(100);
+ BitBuffer bb = new BitBuffer(byteBuffer);
+ byteBuffer.mark();
+ byteBuffer.putInt(1);
+ byteBuffer.putInt(2);
+ byteBuffer.putInt(3);
+ byteBuffer.reset();
+ fStructDefinition = sDec.createDefinition(null, TEST_STRUCT_ID, bb);
+ fixture = (VariantDefinition) fStructDefinition.getDefinition(VAR_FIELD_NAME);
}
/**
* Run the VariantDefinition(VariantDeclaration,DefinitionScope,String)
+ *
+ * @throws CTFReaderException
+ * should not happen
*/
@Test
- public void testVariantDefinition() {
+ public void testVariantDefinition() throws CTFReaderException {
VariantDeclaration declaration = new VariantDeclaration();
declaration.setTag("");
VariantDeclaration variantDeclaration = new VariantDeclaration();
- variantDeclaration.setTag("");
- VariantDefinition variantDefinition = new VariantDefinition(
- variantDeclaration, structDefinition, "");
+ variantDeclaration.addField("", new EnumDeclaration(IntegerDeclaration.INT_32B_DECL));
+ variantDeclaration.addField("a", IntegerDeclaration.INT_64B_DECL);
+ declaration.addField(ENUM_3, new StringDeclaration());
+ variantDeclaration.setTag("a");
+
+ byte[] bytes = new byte[128];
+ ByteBuffer byb = ByteBuffer.wrap(bytes);
+ byb.mark();
+ byb.putInt(0);
+ byb.putShort((short) 2);
+ byb.put(new String("hello").getBytes());
+ byb.reset();
+ BitBuffer bb = new BitBuffer(byb);
+ VariantDefinition variantDefinition = variantDeclaration.createDefinition(fStructDefinition, "field", bb);
+ EnumDeclaration declaration2 = new EnumDeclaration(IntegerDeclaration.INT_8_DECL);
+ declaration2.add(0, 2, ENUM_3);
+ EnumDefinition enumDefinition = new EnumDefinition(
+ declaration2,
+ null,
+ "a",
+ new IntegerDefinition(
+ IntegerDeclaration.INT_8_DECL,
+ null,
+ "A",
+ 1
+ ));
IDefinitionScope definitionScope = new StructDefinition(
- new StructDeclaration(1L), variantDefinition, "");
+ new StructDeclaration(1L),
+ variantDefinition,
+ "",
+ ImmutableList.<String> of("", "variant"),
+ new Definition[] { enumDefinition, variantDefinition }
+ );
String fieldName = "";
-
- VariantDefinition result = new VariantDefinition(declaration,
- definitionScope, fieldName);
+ declaration.setTag("");
+ VariantDefinition result = declaration.createDefinition(definitionScope, fieldName, bb);
assertNotNull(result);
}
@Test
public void testGetCurrentField() {
Definition result = fixture.getCurrentField();
- assertNull(result);
- fixture.setCurrentField(ENUM_1);
- result = fixture.getCurrentField();
assertNotNull(result);
}
*/
@Test
public void testGetCurrentFieldName() {
- fixture.setCurrentField(ENUM_1);
String result = fixture.getCurrentFieldName();
assertNotNull(result);
}
*/
@Test
public void testGetDefinitions() {
- Map<String, Definition> result = fixture.getDefinitions();
+ Definition result = fixture.getCurrentField();
assertNotNull(result);
}
*/
@Test
public void testGetPath() {
- String result = fixture.getPath();
- assertNotNull(result);
- }
-
- /**
- * Run the EnumDefinition getTagDefinition() method test.
- */
- @Test
- public void testGetTagDefinition() {
- EnumDefinition result = fixture.getTagDefinition();
+ String result = fixture.getScopePath().toString();
assertNotNull(result);
}
@Test
public void testLookupArray() {
ArrayDefinition result = fixture.lookupArray(ENUM_3);
- assertNotNull(result);
+ assertNull(result);
}
/**
public void testLookupDefinition() {
Definition result = fixture.lookupDefinition(ENUM_1);
assertNotNull(result);
+ assertEquals("a", ((EnumDefinition) result).getStringValue());
}
/**
@Test
public void testLookupEnum() {
EnumDefinition result = fixture.lookupEnum(ENUM_5);
- assertNotNull(result);
+ assertNull(result);
}
/**
@Test
public void testLookupInteger() {
IntegerDefinition result = fixture.lookupInteger(ENUM_2);
- assertNotNull(result);
+ assertNull(result);
}
/**
@Test
public void testLookupString() {
StringDefinition result = fixture.lookupString(ENUM_1);
- assertNotNull(result);
+ assertNull(result);
}
/**
@Test
public void testLookupStruct() {
StructDefinition result = fixture.lookupStruct(ENUM_6);
- assertNotNull(result);
+ assertNull(result);
}
/**
assertNull(result);
}
- /**
- * Run the void setCurrentField(String) method test.
- */
- @Test
- public void testSetCurrentField() {
- fixture.setCurrentField(ENUM_1);
- }
-
- /**
- * Run the void setDeclaration(VariantDeclaration) method test.
- */
- @Test
- public void testSetDeclaration() {
- VariantDeclaration declaration = new VariantDeclaration();
- fixture.setDeclaration(declaration);
- }
-
- /**
- * Run the void setDefinitions(HashMap<String,Definition>) method test.
- */
- @Test
- public void testSetDefinitions() {
- HashMap<String, Definition> definitions = new HashMap<>();
- fixture.setDefinitions(definitions);
- }
-
- /**
- * Run the void setTagDefinition(EnumDefinition) method test.
- */
- @Test
- public void testSetTagDefinition(){
- VariantDeclaration vDecl;
- VariantDefinition vDef;
- StructDefinition structDef;
- EnumDefinition tagDefinition;
- String fName = "";
-
- vDecl = new VariantDeclaration();
- vDecl.setTag(fName);
- vDef = new VariantDefinition(vDecl, structDefinition, fName);
- structDef = new StructDefinition(new StructDeclaration(1L), vDef, fName);
- tagDefinition = new EnumDefinition(new EnumDeclaration(
- new IntegerDeclaration(1, false, 1, ByteOrder.BIG_ENDIAN,
- Encoding.ASCII, fName, 8)), structDef, fName);
-
- fixture.setTagDefinition(tagDefinition);
- }
-
/**
* Run the String toString() method test.
*/
@Test
public void testToString() {
String result = fixture.toString();
- assertEquals("{ null = null }", result);
-
- fixture.setCurrentField(ENUM_2);
- result = fixture.toString();
- assertEquals("{ b = 0 }", result);
+ assertEquals("{ a = \"\" }", result);
}
}
Export-Package: org.eclipse.linuxtools.ctf.core,
org.eclipse.linuxtools.ctf.core.event,
org.eclipse.linuxtools.ctf.core.event.io,
+ org.eclipse.linuxtools.ctf.core.event.scope,
org.eclipse.linuxtools.ctf.core.event.types,
org.eclipse.linuxtools.ctf.core.trace,
org.eclipse.linuxtools.internal.ctf.core;x-friends:="org.eclipse.linuxtools.ctf.core.tests",
org.eclipse.linuxtools.internal.ctf.core.event.metadata;x-friends:="org.eclipse.linuxtools.ctf.core.tests",
org.eclipse.linuxtools.internal.ctf.core.event.metadata.exceptions;x-friends:="org.eclipse.linuxtools.ctf.core.tests",
org.eclipse.linuxtools.internal.ctf.core.trace;x-friends:="org.eclipse.linuxtools.ctf.core.tests"
-Import-Package: org.antlr.runtime;version="3.2.0",
+Import-Package: com.google.common.base,
+ com.google.common.collect,
+ org.antlr.runtime;version="3.2.0",
org.antlr.runtime.tree;version="3.2.0"
about.html,\
plugin.properties
src.includes = about.html
+additional.bundles = org.eclipse.jdt.annotation
+jars.extra.classpath = platform:/plugin/org.eclipse.jdt.annotation
\ No newline at end of file
package org.eclipse.linuxtools.ctf.core;
+import org.eclipse.jdt.annotation.NonNullByDefault;
+
/**
* Non-externalized strings for use with the CTF plugin (event names, field
* names, etc.)
* @since 2.2
*/
@SuppressWarnings("nls")
+@NonNullByDefault
public interface CTFStrings {
/** Event name for lost events */
package org.eclipse.linuxtools.ctf.core.event;
+import java.util.ArrayList;
import java.util.List;
-import java.util.Map;
-import java.util.Map.Entry;
+import org.eclipse.jdt.annotation.NonNull;
+import org.eclipse.linuxtools.ctf.core.event.scope.IDefinitionScope;
+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.IDefinitionScope;
import org.eclipse.linuxtools.ctf.core.event.types.StructDeclaration;
import org.eclipse.linuxtools.ctf.core.event.types.StructDefinition;
import org.eclipse.linuxtools.ctf.core.trace.StreamInputReader;
+import org.eclipse.linuxtools.internal.ctf.core.event.EventDeclaration;
+
+import com.google.common.collect.ImmutableList;
+import com.google.common.collect.ImmutableList.Builder;
/**
* Representation of a particular instance of an event.
*/
-public class EventDefinition implements IDefinitionScope {
+public final class EventDefinition implements IDefinitionScope {
// ------------------------------------------------------------------------
// Attributes
// ------------------------------------------------------------------------
+ /**
+ * A null event, can be used for testing or poison pilling
+ *
+ * @since 3.0
+ */
+ @NonNull
+ public static final EventDefinition NULL_EVENT = new EventDefinition(new EventDeclaration(), null, -1L, null, null, null, null);
+
/**
* The corresponding event declaration.
*/
/**
* The timestamp of the current event.
*/
- private long fTimestamp;
+ private final long fTimestamp;
/**
* The event context structure definition.
*/
- private StructDefinition fContext;
+ private final StructDefinition fEventContext;
+
+ private final StructDefinition fStreamContext;
+
+ private final StructDefinition fPacketContext;
/**
* The event fields structure definition.
*/
- private StructDefinition fFields;
+ private final StructDefinition fFields;
/**
* The StreamInputReader that reads this event definition.
* The corresponding event declaration
* @param streamInputReader
* The SIR from where this EventDef was read
- * @since 2.0
+ * @param timestamp
+ * event timestamp
+ * @param eventContext
+ * The event context
+ * @param packetContext
+ * the packet context
+ * @param streamContext
+ * the stream context
+ * @param fields
+ * The event fields
+ * @since 3.0
*/
public EventDefinition(IEventDeclaration declaration,
- StreamInputReader streamInputReader) {
+ StreamInputReader streamInputReader,
+ long timestamp,
+ StructDefinition streamContext,
+ StructDefinition eventContext,
+ StructDefinition packetContext,
+ StructDefinition fields) {
fDeclaration = declaration;
fStreamInputReader = streamInputReader;
+ fTimestamp = timestamp;
+ fFields = fields;
+ fEventContext = eventContext;
+ fPacketContext = packetContext;
+ fStreamContext = streamContext;
}
// ------------------------------------------------------------------------
// Getters/Setters/Predicates
// ------------------------------------------------------------------------
+ /**
+ * @since 3.0
+ */
@Override
- public String getPath() {
- return "event"; //$NON-NLS-1$
+ public LexicalScope getScopePath() {
+ String eventName = fDeclaration.getName();
+ if (eventName == null) {
+ return null;
+ }
+ LexicalScope myScope = LexicalScope.EVENT.getChild(eventName);
+ if (myScope == null) {
+ myScope = new LexicalScope(LexicalScope.EVENT, eventName);
+ }
+ return myScope;
}
/**
* @since 1.2
*/
public StructDefinition getEventContext() {
- return fContext;
+ return fEventContext;
}
/**
* @return the context in struct form
*/
public StructDefinition getContext() {
- final StructDefinition streamContext =
- fStreamInputReader.getPacketReader().getStreamEventContextDef();
/* Most common case so far */
- if (streamContext == null) {
- return fContext;
+ if (fStreamContext == null) {
+ return fEventContext;
}
/* streamContext is not null, but the context of the event is null */
- if (fContext == null) {
- return streamContext;
+ if (fEventContext == null) {
+ return fStreamContext;
}
+ // TODO: cache if this is a performance issue
+
/* The stream context and event context are assigned. */
StructDeclaration mergedDeclaration = new StructDeclaration(1);
- /* Add fields from the stream */
- Map<String, Definition> defs = streamContext.getDefinitions();
- for (Entry<String, Definition> entry : defs.entrySet()) {
- mergedDeclaration.addField(entry.getKey(), entry.getValue().getDeclaration());
- }
+ Builder<String> builder = ImmutableList.<String> builder();
+ List<Definition> fieldValues = new ArrayList<>();
- /* Add fields from the event context, overwrite the stream ones if needed. */
- for (Entry<String, Definition> entry : fContext.getDefinitions().entrySet()) {
- mergedDeclaration.addField(entry.getKey(), entry.getValue().getDeclaration());
+ /* Add fields from the stream */
+ for (String fieldName : fStreamContext.getFieldNames()) {
+ Definition definition = fStreamContext.getDefinition(fieldName);
+ mergedDeclaration.addField(fieldName, definition.getDeclaration());
+ builder.add(fieldName);
+ fieldValues.add(definition);
}
- StructDefinition mergedContext = mergedDeclaration.createDefinition(null, "context"); //$NON-NLS-1$
- for (String key : mergedContext.getDefinitions().keySet()) {
- final Definition lookupDefinition = fContext.lookupDefinition(key);
- /*
- * If the key is in the event context, add it from there, if it is
- * not, then it's in the stream. There is a priority with scoping so
- * if there is a field like "context" in both stream and context,
- * you display the context.
- */
- if (lookupDefinition != null) {
- mergedContext.getDefinitions().put(key, lookupDefinition);
+ ImmutableList<String> fieldNames = builder.build();
+ /*
+ * Add fields from the event context, overwrite the stream ones if
+ * needed.
+ */
+ for (String fieldName : fEventContext.getFieldNames()) {
+ Definition definition = fEventContext.getDefinition(fieldName);
+ mergedDeclaration.addField(fieldName, definition.getDeclaration());
+ if (fieldNames.contains(fieldName)) {
+ fieldValues.set((fieldNames.indexOf(fieldName)), definition);
} else {
- mergedContext.getDefinitions().put(key, streamContext.lookupDefinition(key));
+ builder.add(fieldName);
+ fieldValues.add(definition);
}
}
+ fieldNames = builder.build();
+ StructDefinition mergedContext = new StructDefinition(mergedDeclaration, this, "context", //$NON-NLS-1$
+ fieldNames,
+ fieldValues.toArray(new Definition[fieldValues.size()]));
return mergedContext;
}
* @return the packet context
*/
public StructDefinition getPacketContext() {
- return fStreamInputReader.getCurrentPacketContext();
+ return fPacketContext;
}
/**
return fTimestamp;
}
- /**
- * @param timestamp
- * the timestamp to set
- */
- public void setTimestamp(long timestamp) {
- fTimestamp = timestamp;
- }
-
- /**
- * @param context
- * the context to set
- */
- public void setContext(StructDefinition context) {
- fContext = context;
- }
-
- /**
- * @param fields
- * the fields to set
- */
- public void setFields(StructDefinition fields) {
- fFields = fields;
- }
-
// ------------------------------------------------------------------------
// Operations
// ------------------------------------------------------------------------
@Override
public Definition lookupDefinition(String lookupPath) {
if (lookupPath.equals("context")) { //$NON-NLS-1$
- return fContext;
+ return fEventContext;
} else if (lookupPath.equals("fields")) { //$NON-NLS-1$
return fFields;
} else {
@Override
public String toString() {
- Map<String, Definition> definitions;
- List<String> list;
+ Iterable<String> list;
StringBuilder retString = new StringBuilder();
final String cr = System.getProperty("line.separator");//$NON-NLS-1$
retString.append("Event type: " + fDeclaration.getName() + cr); //$NON-NLS-1$
retString.append("Timestamp: " + Long.toString(fTimestamp) + cr); //$NON-NLS-1$
- if (fContext != null) {
- definitions = fContext.getDefinitions();
- list = fContext.getDeclaration().getFieldsList();
+ if (fEventContext != null) {
+ list = fEventContext.getDeclaration().getFieldsList();
for (String field : list) {
retString.append(field
- + " : " + definitions.get(field).toString() + cr); //$NON-NLS-1$
+ + " : " + fEventContext.getDefinition(field).toString() + cr); //$NON-NLS-1$
}
}
if (fFields != null) {
- definitions = fFields.getDefinitions();
list = fFields.getDeclaration().getFieldsList();
for (String field : list) {
retString.append(field
- + " : " + definitions.get(field).toString() + cr); //$NON-NLS-1$
+ + " : " + fFields.getDefinition(field).toString() + cr); //$NON-NLS-1$
}
}
import java.util.Set;
+import org.eclipse.jdt.annotation.NonNull;
+import org.eclipse.linuxtools.ctf.core.event.io.BitBuffer;
import org.eclipse.linuxtools.ctf.core.event.types.StructDeclaration;
+import org.eclipse.linuxtools.ctf.core.trace.CTFReaderException;
import org.eclipse.linuxtools.ctf.core.trace.Stream;
import org.eclipse.linuxtools.ctf.core.trace.StreamInputReader;
*
* @param streamInputReader
* The StreamInputReader for which this definition is created.
+ * @param input
+ * the bitbuffer input source
+ * @param timestamp
+ * The timestamp when the event was taken
* @return A new EventDefinition.
+ * @throws CTFReaderException
+ * As a bitbuffer is used to read, it could have wrapped
+ * IOExceptions.
+ * @since 3.0
*/
- EventDefinition createDefinition(StreamInputReader streamInputReader);
+ EventDefinition createDefinition(StreamInputReader streamInputReader, @NonNull BitBuffer input, long timestamp) throws CTFReaderException;
/**
* Gets the name of an event declaration
--- /dev/null
+/*******************************************************************************
+ * Copyright (c) 2011, 2013 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
+ * accompanies this distribution, and is available at
+ * http://www.eclipse.org/legal/epl-v10.html
+ *
+ * Contributors: Matthew Khouzam - Initial API and implementation
+ * Contributors: Simon Marchi - Initial API and implementation
+ *******************************************************************************/
+
+package org.eclipse.linuxtools.ctf.core.event.scope;
+
+import org.eclipse.linuxtools.ctf.core.event.types.Definition;
+
+/**
+ * The scope of a CTF definition. Used for compound types.
+ *
+ * @version 1.0
+ * @author Matthew Khouzam
+ * @author Simon Marchi
+ * @since 3.0
+ */
+public interface IDefinitionScope {
+
+ /**
+ * Gets the path in a C style for the scope.
+ *
+ * @return the path
+ * @since 3.0
+ */
+ LexicalScope getScopePath();
+
+ /**
+ * Looks up in this definition scope.
+ *
+ * @param lookupPath
+ * The path to look up
+ * @return The Definition that was read
+ */
+ Definition lookupDefinition(String lookupPath);
+}
--- /dev/null
+/*******************************************************************************
+ * 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.event.scope;
+
+import java.util.Collections;
+import java.util.HashMap;
+import java.util.Map;
+
+import org.eclipse.jdt.annotation.NonNull;
+import org.eclipse.jdt.annotation.NonNullByDefault;
+import org.eclipse.jdt.annotation.Nullable;
+
+import com.google.common.base.Joiner;
+
+/**
+ * A node of a lexical scope
+ *
+ * @author Matthew Khouzam
+ * @since 3.0
+ */
+@NonNullByDefault
+public class LexicalScope implements Comparable<LexicalScope> {
+ /**
+ * Empty string
+ *
+ * @since 3.0
+ */
+ public static final LexicalScope ROOT = new LexicalScope(null, ""); //$NON-NLS-1$
+
+ /**
+ * Trace string
+ *
+ * @since 3.0
+ */
+ public static final LexicalScope TRACE = new LexicalScope(ROOT, "trace"); //$NON-NLS-1$
+
+ /**
+ * Env string
+ *
+ * @since 3.0
+ */
+ public static final LexicalScope ENV = new LexicalScope(ROOT, "env"); //$NON-NLS-1$
+
+ /**
+ * Stream string
+ *
+ * @since 3.0
+ */
+ public static final LexicalScope STREAM = new LexicalScope(ROOT, "stream"); //$NON-NLS-1$
+
+ /**
+ * Event string
+ *
+ * @since 3.0
+ */
+ public static final LexicalScope EVENT = new LexicalScope(ROOT, "event"); //$NON-NLS-1$
+
+ /**
+ * Variant string
+ *
+ * @since 3.0
+ */
+ public static final LexicalScope VARIANT = new LexicalScope(ROOT, "variant"); //$NON-NLS-1$
+
+ /**
+ * packet string
+ *
+ * @since 3.0
+ */
+ public static final LexicalScope PACKET = new LexicalScope(ROOT, "packet"); //$NON-NLS-1$
+
+ /**
+ * Packet header string
+ *
+ * @since 3.0
+ *
+ */
+ public static final LexicalScope PACKET_HEADER = new LexicalScope(PACKET, "header"); //$NON-NLS-1$
+
+ /**
+ * Stream packet scope
+ *
+ * @since 3.0
+ */
+ public static final LexicalScope STREAM_PACKET = new LexicalScope(STREAM, "packet"); //$NON-NLS-1$
+
+ /**
+ * Stream Packet header string
+ *
+ * @since 3.0
+ */
+ public static final LexicalScope STREAM_PACKET_CONTEXT = new LexicalScope(STREAM_PACKET, "context"); //$NON-NLS-1$
+
+ /**
+ * Trace packet scope
+ *
+ * @since 3.0
+ */
+ public static final LexicalScope TRACE_PACKET = new LexicalScope(TRACE, "packet"); //$NON-NLS-1$
+
+ /**
+ * Stream event scope
+ *
+ * @since 3.0
+ */
+ public static final LexicalScope STREAM_EVENT = new LexicalScope(STREAM, "event"); //$NON-NLS-1$
+
+ /**
+ * Trace packet header string
+ *
+ * @since 3.0
+ */
+ public static final LexicalScope TRACE_PACKET_HEADER = new LexicalScope(STREAM_EVENT, "header"); //$NON-NLS-1$
+
+ /**
+ * Stream event context
+ *
+ * @since 3.0
+ */
+ public static final LexicalScope STREAM_EVENT_CONTEXT = new LexicalScope(STREAM_EVENT, "context"); //$NON-NLS-1$
+
+ /**
+ * Stream event header
+ *
+ * @since 3.0
+ */
+ public static final LexicalScope STREAM_EVENT_HEADER = new LexicalScope(TRACE_PACKET, "header"); //$NON-NLS-1$
+
+ /**
+ * Fields in an event
+ *
+ * @since 3.0
+ */
+ public static final LexicalScope FIELDS = new LexicalScope(ROOT, "fields"); //$NON-NLS-1$
+
+ /**
+ * Context of an event
+ *
+ * @since 3.0
+ */
+ public static final LexicalScope CONTEXT = new LexicalScope(ROOT, "context"); //$NON-NLS-1$
+
+ /**
+ * Sorted list of parent paths
+ *
+ * @since 3.0
+ */
+ public static final LexicalScope[] PARENT_PATHS = {
+ ROOT,
+ CONTEXT,
+ FIELDS,
+ PACKET_HEADER,
+ STREAM_EVENT_CONTEXT,
+ STREAM_EVENT_HEADER,
+ STREAM_PACKET_CONTEXT,
+ TRACE_PACKET_HEADER
+ };
+
+ private int hash = 0;
+ private final String fName;
+ private final String fPath;
+ private final Map<String, LexicalScope> fChildren;
+
+ /**
+ * The scope constructor
+ *
+ * @param parent
+ * The parent node, can be null, but shouldn't
+ * @param name
+ * the name of the field
+ */
+ public LexicalScope(@Nullable LexicalScope parent, String name) {
+ fName = name;
+ if (parent != null) {
+ String pathString = Joiner.on('.').skipNulls().join(parent.fPath, parent.getName());
+ if (pathString.startsWith(".")) { //$NON-NLS-1$
+ pathString = pathString.substring(1);
+ }
+ if (pathString == null) {
+ // we should get an NPE on pathString.startsWith before getting this
+ throw new IllegalStateException(
+ "Lexical scope constructor had null pathstring for " + //$NON-NLS-1$
+ parent.toString() + " and " + name); //$NON-NLS-1$
+ }
+ fPath = pathString;
+ parent.addChild(fName, this);
+ } else {
+ fPath = ""; //$NON-NLS-1$
+ }
+
+ @SuppressWarnings("null")
+ @NonNull
+ Map<String, LexicalScope> children =
+ Collections.synchronizedMap(new HashMap<String, LexicalScope>());
+ fChildren = children;
+ }
+
+ /**
+ * Adds a child lexical scope
+ *
+ * @param name
+ * the name of the child
+ * @param child
+ * the child
+ */
+ private void addChild(String name, LexicalScope child) {
+ fChildren.put(name, child);
+ }
+
+ /**
+ * Get the name
+ *
+ * @return the name
+ */
+ public String getName() {
+ return fName;
+ }
+
+ /**
+ * Gets a child of a given name
+ *
+ * @param name
+ * the child
+ * @return the scope, can be null
+ */
+ @Nullable
+ public LexicalScope getChild(String name) {
+ return fChildren.get(name);
+ }
+
+ @Override
+ public String toString() {
+ return fPath + '.' + fName;
+ }
+
+ @Override
+ public int compareTo(@Nullable LexicalScope other) {
+ if (other == null) {
+ throw new IllegalArgumentException();
+ }
+ int comp = fPath.compareTo(other.fPath);
+ if (comp == 0) {
+ return fName.compareTo(other.fName);
+ }
+ return comp;
+ }
+
+ @Override
+ public synchronized int hashCode() {
+ if (hash == 0) {
+ final int prime = 31;
+ hash = prime * (prime + fName.hashCode()) + fPath.hashCode();
+ }
+ return hash;
+ }
+
+ @Override
+ public boolean equals(@Nullable Object obj) {
+ if (this == obj) {
+ return true;
+ }
+ if (obj == null) {
+ return false;
+ }
+ if (getClass() != obj.getClass()) {
+ return false;
+ }
+ LexicalScope other = (LexicalScope) obj;
+ if (!fName.equals(other.fName)) {
+ return false;
+ }
+ return fPath.equals(other.fPath);
+ }
+}
package org.eclipse.linuxtools.ctf.core.event.types;
+import java.util.List;
+
+import org.eclipse.jdt.annotation.NonNull;
+import org.eclipse.linuxtools.ctf.core.event.io.BitBuffer;
+import org.eclipse.linuxtools.ctf.core.event.scope.IDefinitionScope;
+import org.eclipse.linuxtools.ctf.core.trace.CTFReaderException;
+
+import com.google.common.collect.ArrayListMultimap;
+import com.google.common.collect.ImmutableList;
+import com.google.common.collect.ImmutableList.Builder;
+import com.google.common.collect.Multimap;
+
/**
* A CTF array declaration
*
* @author Matthew Khouzam
* @author Simon Marchi
*/
-public class ArrayDeclaration implements IDeclaration {
+public class ArrayDeclaration extends Declaration {
// ------------------------------------------------------------------------
// Attributes
// ------------------------------------------------------------------------
- private final int length;
- private final IDeclaration elemType;
+ private final int fLength;
+ private final IDeclaration fElemType;
+
+ /**
+ * <pre>
+ * Cache where we can pre-generate the children names
+ * Key: parent name
+ * Value: children names
+ * ex: field → {field[0], field[1], … field[n]}
+ * </pre>
+ *
+ * TODO: investigate performance
+ */
+ private final Multimap<String, String> fChildrenNames = ArrayListMultimap.<String, String> create();
// ------------------------------------------------------------------------
// Constructors
* what type of element is in the array
*/
public ArrayDeclaration(int length, IDeclaration elemType) {
- this.length = length;
- this.elemType = elemType;
+ fLength = length;
+ fElemType = elemType;
}
// ------------------------------------------------------------------------
* @return the type of element in the array
*/
public IDeclaration getElementType() {
- return elemType;
+ return fElemType;
}
/**
* @return how many elements in the array
*/
public int getLength() {
- return length;
+ return fLength;
}
/**
* @since 3.0
*/
public boolean isString() {
- if (elemType instanceof IntegerDeclaration) {
+ if (fElemType instanceof IntegerDeclaration) {
/*
* If the first byte is a "character", we'll consider the whole
* array a character string.
*/
- IntegerDeclaration elemInt = (IntegerDeclaration) elemType;
+ IntegerDeclaration elemInt = (IntegerDeclaration) fElemType;
if (elemInt.isCharacter()) {
return true;
}
// Operations
// ------------------------------------------------------------------------
+ /**
+ * @since 3.0
+ */
@Override
public ArrayDefinition createDefinition(IDefinitionScope definitionScope,
- String fieldName) {
- return new ArrayDefinition(this, definitionScope, fieldName);
+ @NonNull String fieldName, BitBuffer input) throws CTFReaderException {
+ alignRead(input);
+ List<Definition> definitions = read(input, definitionScope, fieldName);
+ return new ArrayDefinition(this, definitionScope, fieldName, definitions);
}
@Override
return "[declaration] array[" + Integer.toHexString(hashCode()) + ']'; //$NON-NLS-1$
}
+ @NonNull
+ private List<Definition> read(@NonNull BitBuffer input, IDefinitionScope definitionScope, String fieldName) throws CTFReaderException {
+ Builder<Definition> definitions = new ImmutableList.Builder<>();
+ if (!fChildrenNames.containsKey(fieldName)) {
+ for (int i = 0; i < fLength; i++) {
+ fChildrenNames.put(fieldName, fieldName + '[' + i + ']');
+ }
+ }
+ List<String> elemNames = (List<String>) fChildrenNames.get(fieldName);
+ for (int i = 0; i < fLength; i++) {
+ String name = elemNames.get(i);
+ if (name == null) {
+ throw new IllegalStateException();
+ }
+ definitions.add(fElemType.createDefinition(definitionScope, name, input));
+ }
+ @SuppressWarnings("null")
+ @NonNull ImmutableList<Definition> ret = definitions.build();
+ return ret;
+ }
+
+ /**
+ * @since 3.0
+ */
+ @Override
+ public int getMaximumSize() {
+ long val = (long) fLength * fElemType.getMaximumSize();
+ return (int) Math.min(Integer.MAX_VALUE, val);
+ }
+
}
package org.eclipse.linuxtools.ctf.core.event.types;
-import java.util.Arrays;
+import java.util.List;
-import org.eclipse.linuxtools.ctf.core.event.io.BitBuffer;
-import org.eclipse.linuxtools.ctf.core.trace.CTFReaderException;
+import org.eclipse.jdt.annotation.NonNull;
+import org.eclipse.jdt.annotation.NonNullByDefault;
+import org.eclipse.jdt.annotation.Nullable;
+import org.eclipse.linuxtools.ctf.core.event.scope.IDefinitionScope;
+
+import com.google.common.base.Joiner;
+import com.google.common.collect.ImmutableList;
/**
* A CTF array definition
*
- * Arrays are fixed-length. Their length is declared in the type
- * declaration within the meta-data. They contain an array of "inner type"
- * elements, which can refer to any type not containing the type of the
- * array being declared (no circular dependency). The length is the number
- * of elements in an array.
+ * Arrays are fixed-length. Their length is declared in the type declaration
+ * within the meta-data. They contain an array of "inner type" elements, which
+ * can refer to any type not containing the type of the array being declared (no
+ * circular dependency). The length is the number of elements in an array.
*
* @version 1.0
* @author Matthew Khouzam
* @author Simon Marchi
*/
-public class ArrayDefinition extends Definition {
+@NonNullByDefault
+public final class ArrayDefinition extends Definition {
// ------------------------------------------------------------------------
// Attributes
// ------------------------------------------------------------------------
- private final ArrayDeclaration declaration;
- private Definition definitions[];
+ private final ImmutableList<Definition> fDefinitions;
// ------------------------------------------------------------------------
// Constructors
/**
* Constructor
- * @param declaration the parent declaration
- * @param definitionScope the parent scope
- * @param fieldName the field name
+ *
+ * @param declaration
+ * the parent declaration
+ * @param definitionScope
+ * the parent scope
+ * @param fieldName
+ * the field name
+ * @param definitions
+ * the content of the array
+ * @since 3.0
*/
public ArrayDefinition(ArrayDeclaration declaration,
- IDefinitionScope definitionScope, String fieldName) {
- super(definitionScope, fieldName);
-
- this.declaration = declaration;
-
- definitions = new Definition[declaration.getLength()];
+ @Nullable IDefinitionScope definitionScope,
+ String fieldName,
+ List<Definition> definitions) {
+ super(declaration, definitionScope, fieldName);
+ @SuppressWarnings("null")
+ @NonNull ImmutableList<Definition> list = ImmutableList.copyOf(definitions);
+ fDefinitions = list;
- for (int i = 0; i < declaration.getLength(); i++) {
- definitions[i] = declaration.getElementType().createDefinition(
- definitionScope, fieldName + "[" + i + "]"); //$NON-NLS-1$ //$NON-NLS-2$
- }
}
// ------------------------------------------------------------------------
/**
* @return the definitions
+ * @since 3.0
*/
- public Definition[] getDefinitions() {
- return Arrays.copyOf(definitions, definitions.length);
- }
-
- /**
- * @param definitions
- * the definitions to set
- */
- public void setDefinitions(Definition[] definitions) {
- this.definitions = Arrays.copyOf(definitions, definitions.length);
+ public List<Definition> getDefinitions() {
+ return fDefinitions;
}
/**
* Get the element at i
+ *
* @param i the index (cannot be negative)
* @return The element at I, if I > length, null, if I < 0, the method throws an out of bounds exception
*/
+ @Nullable
public Definition getElem(int i) {
- if (i > definitions.length) {
+ if (i > fDefinitions.size()) {
return null;
}
- return definitions[i];
+ return fDefinitions.get(i);
}
@Override
public ArrayDeclaration getDeclaration() {
- return declaration;
+ return (ArrayDeclaration) super.getDeclaration();
}
// ------------------------------------------------------------------------
// Operations
// ------------------------------------------------------------------------
- @Override
- public void read(BitBuffer input) throws CTFReaderException {
- for (Definition definition : definitions) {
- definition.read(input);
- }
- }
-
@Override
public String toString() {
StringBuilder b = new StringBuilder();
- if (declaration.isString()) {
- for (Definition def : definitions) {
+ if (getDeclaration().isString()) {
+ for (Definition def : fDefinitions) {
IntegerDefinition character = (IntegerDefinition) def;
if (character.getValue() == 0) {
b.append(character.toString());
}
- } else if (definitions == null) {
- b.append("[ ]"); //$NON-NLS-1$
} else {
b.append('[');
- for (int i = 0; i < (definitions.length - 1); i++) {
- b.append(' ');
- b.append(definitions[i].toString());
- b.append(',');
- }
- b.append(' ');
- b.append(definitions[definitions.length - 1].toString());
- b.append(" ]"); //$NON-NLS-1$
+ Joiner joiner = Joiner.on(", ").skipNulls(); //$NON-NLS-1$
+ b.append(joiner.join(fDefinitions));
+ b.append(']');
}
- return b.toString();
+ @SuppressWarnings("null")
+ @NonNull String ret = b.toString();
+ return ret;
}
}
--- /dev/null
+/*******************************************************************************
+ * 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.event.types;
+
+import org.eclipse.jdt.annotation.NonNull;
+import org.eclipse.linuxtools.ctf.core.event.io.BitBuffer;
+import org.eclipse.linuxtools.ctf.core.event.scope.IDefinitionScope;
+import org.eclipse.linuxtools.ctf.core.event.scope.LexicalScope;
+import org.eclipse.linuxtools.ctf.core.trace.CTFReaderException;
+
+/**
+ * Declaration base, it helps for basic functionality that is often called, so
+ * performance is often a high priority in this class
+ *
+ * @author Matthew Khouzam
+ * @since 3.0
+ */
+public abstract class Declaration implements IDeclaration {
+
+ @Override
+ public LexicalScope getPath(IDefinitionScope definitionScope, @NonNull String fieldName) {
+ if (definitionScope != null) {
+ final LexicalScope parentPath = definitionScope.getScopePath();
+ if (parentPath != null) {
+ LexicalScope myScope = parentPath.getChild(fieldName);
+ if (myScope == null) {
+ myScope = new LexicalScope(parentPath, fieldName);
+ }
+ return myScope;
+ }
+ }
+ LexicalScope child = LexicalScope.ROOT.getChild(fieldName);
+ if (child != null) {
+ return child;
+ }
+ return new LexicalScope(LexicalScope.ROOT, fieldName);
+ }
+
+ /**
+ * Offset the buffer position wrt the current alignment.
+ *
+ * @param input
+ * The bitbuffer that is being read
+ * @throws CTFReaderException
+ * Happens when there is an out of bounds exception
+ * @since 3.0
+ */
+ protected final void alignRead(BitBuffer input) throws CTFReaderException {
+ long mask = getAlignment() - 1;
+ /*
+ * The alignment is a power of 2
+ */
+ long pos = input.position();
+ if ((pos & mask) == 0) {
+ return;
+ }
+ pos = (pos + mask) & ~mask;
+ input.position(pos);
+ }
+}
package org.eclipse.linuxtools.ctf.core.event.types;
-import org.eclipse.linuxtools.ctf.core.event.io.BitBuffer;
-import org.eclipse.linuxtools.ctf.core.trace.CTFReaderException;
+import org.eclipse.jdt.annotation.NonNull;
+import org.eclipse.linuxtools.ctf.core.event.scope.IDefinitionScope;
+import org.eclipse.linuxtools.ctf.core.event.scope.LexicalScope;
/**
* A CTF definition
// Attributes
// ------------------------------------------------------------------------
- private final String fieldName;
+ private final String fFieldName;
/** The complete path of this field */
- private final String path;
+ private final LexicalScope fPath;
- private final IDefinitionScope definitionScope;
+ private final IDefinitionScope fDefinitionScope;
+
+ @NonNull
+ private final IDeclaration fDeclaration;
// ------------------------------------------------------------------------
// Constructors
/**
* Constructor
*
+ * @param declaration
+ * the event declaration
+ *
* @param definitionScope
* the definition is in a scope, (normally a struct) what is it?
* @param fieldName
* the name of the definition. (it is a field in the parent
* scope)
+ * @since 3.0
*/
- public Definition(IDefinitionScope definitionScope, String fieldName) {
- this.definitionScope = definitionScope;
- this.fieldName = fieldName;
- if (definitionScope != null) {
- String parentPath = definitionScope.getPath();
- if (parentPath.length() > 0) {
- path = parentPath + "." + fieldName; //$NON-NLS-1$
- } else {
- path = fieldName;
- }
- } else {
- path = fieldName;
- }
+ public Definition(@NonNull IDeclaration declaration, IDefinitionScope definitionScope, @NonNull String fieldName) {
+ fDeclaration = declaration;
+ fDefinitionScope = definitionScope;
+ fFieldName = fieldName;
+ fPath = fDeclaration.getPath(definitionScope, fieldName);
}
// ------------------------------------------------------------------------
* @since 2.0
*/
protected String getFieldName() {
- return fieldName;
+ return fFieldName;
}
/**
* Get the complete path of this field.
*
* @return The path
- * @since 2.0
+ * @since 3.0
*/
- public String getPath() {
- return path;
+ public LexicalScope getScopePath() {
+ return fPath;
}
/**
* scope DOT the name of the definition (name of the field in its container)
*
* @return The definition scope
- * @since 2.0
+ * @since 3.0
*/
protected IDefinitionScope getDefinitionScope() {
- return definitionScope;
+ return fDefinitionScope;
}
// ------------------------------------------------------------------------
* @return gets the declaration of a datatype
*
*/
- public abstract IDeclaration getDeclaration();
-
- /**
- * Read the definition from a bitbuffer
- *
- * @param input
- * the bitbuffer containing the data to read.
- * @throws CTFReaderException
- * An error occurred reading the data. If the buffer is reading
- * beyond its end, this exception will be raised.
- * @since 2.0
- */
- public abstract void read(BitBuffer input) throws CTFReaderException;
-
- /**
- * Offset the buffer position wrt the current alignment.
- *
- * @param input
- * The bitbuffer that is being read
- * @param declaration
- * The declaration which has an alignment
- * @throws CTFReaderException
- * Happens when there is an out of bounds exception
- * @since 2.2
- */
- protected static void alignRead(BitBuffer input, IDeclaration declaration) throws CTFReaderException{
- long mask = declaration.getAlignment() -1;
- /*
- * The alignment is a power of 2
- */
- long pos = input.position();
- if ((pos & mask) == 0) {
- return;
- }
- pos = (pos + mask) & ~mask;
- input.position(pos);
+ @NonNull
+ public IDeclaration getDeclaration() {
+ return fDeclaration;
}
@Override
public String toString() {
- return path + '[' + Integer.toHexString(hashCode()) + ']';
+ return fPath.toString() + '[' + Integer.toHexString(hashCode()) + ']';
}
}
package org.eclipse.linuxtools.ctf.core.event.types;
+import org.eclipse.jdt.annotation.NonNullByDefault;
+
/**
* CTF encoding types
*
* @author Matthew Khouzam
* @author Simon Marchi
*/
+@NonNullByDefault
public enum Encoding {
/** UTF-8 encoding */
UTF8,
import java.util.List;
import java.util.Set;
+import org.eclipse.linuxtools.ctf.core.event.io.BitBuffer;
+import org.eclipse.linuxtools.ctf.core.event.scope.IDefinitionScope;
+import org.eclipse.linuxtools.ctf.core.trace.CTFReaderException;
+
/**
* A CTF enum declaration.
*
* @author Matthew Khouzam
* @author Simon Marchi
*/
-public class EnumDeclaration implements IDeclaration {
+public final class EnumDeclaration extends Declaration {
// ------------------------------------------------------------------------
// Attributes
return this.getContainerType().getAlignment();
}
+ /**
+ * @since 3.0
+ */
+ @Override
+ public int getMaximumSize() {
+ return fContainerType.getMaximumSize();
+ }
+
// ------------------------------------------------------------------------
// Operations
// ------------------------------------------------------------------------
+ /**
+ * @since 3.0
+ */
@Override
- public EnumDefinition createDefinition(IDefinitionScope definitionScope,
- String fieldName) {
- return new EnumDefinition(this, definitionScope, fieldName);
+ public EnumDefinition createDefinition(IDefinitionScope definitionScope, String fieldName, BitBuffer input) throws CTFReaderException {
+ alignRead(input);
+ IntegerDefinition value = getContainerType().createDefinition(definitionScope, fieldName, input);
+ return new EnumDefinition(this, definitionScope, fieldName, value);
}
/**
package org.eclipse.linuxtools.ctf.core.event.types;
-import org.eclipse.linuxtools.ctf.core.event.io.BitBuffer;
-import org.eclipse.linuxtools.ctf.core.trace.CTFReaderException;
+import org.eclipse.jdt.annotation.NonNull;
+import org.eclipse.linuxtools.ctf.core.event.scope.IDefinitionScope;
/**
* A CTF enum definition.
*
- * The definition of a enum point basic data type. It will take the data
- * from a trace and store it (and make it fit) as an integer and a string.
+ * The definition of a enum point basic data type. It will take the data from a
+ * trace and store it (and make it fit) as an integer and a string.
*
* @version 1.0
* @author Matthew Khouzam
* @author Simon Marchi
*/
-public class EnumDefinition extends SimpleDatatypeDefinition {
+public final class EnumDefinition extends SimpleDatatypeDefinition {
// ------------------------------------------------------------------------
// Attributes
// ------------------------------------------------------------------------
- private final EnumDeclaration declaration;
+ private final long fIntegerValue;
- private final IntegerDefinition integerValue;
-
- private String value;
+ private final String fValue;
// ------------------------------------------------------------------------
// Constructors
/**
* Constructor
- * @param declaration the parent declaration
- * @param definitionScope the parent scope
- * @param fieldName the field name
+ *
+ * @param declaration
+ * the parent declaration
+ * @param definitionScope
+ * the parent scope
+ * @param fieldName
+ * the field name
+ * @param intValue
+ * the value of the enum
+ * @since 3.0
*/
- public EnumDefinition(EnumDeclaration declaration,
- IDefinitionScope definitionScope, String fieldName) {
- super(definitionScope, fieldName);
-
- this.declaration = declaration;
+ public EnumDefinition(@NonNull EnumDeclaration declaration,
+ IDefinitionScope definitionScope, @NonNull String fieldName, IntegerDefinition intValue) {
+ super(declaration, definitionScope, fieldName);
- integerValue = declaration.getContainerType().createDefinition(
- definitionScope, fieldName);
- value = declaration.query(integerValue.getValue());
+ fIntegerValue = intValue.getValue();
+ fValue = declaration.query(fIntegerValue);
}
// ------------------------------------------------------------------------
// ------------------------------------------------------------------------
/**
- * Gets the value of the enum in string format so "Enum a{DAY="0", NIGHT="1"}; will return "DAY"
+ * Gets the value of the enum in string format so
+ * "Enum a{DAY="0", NIGHT="1"}; will return "DAY"
+ *
* @return the value of the enum.
*/
public String getValue() {
- return value;
+ return fValue;
}
@Override
- public String getStringValue(){
+ public String getStringValue() {
return getValue();
}
/**
- * Gets the value of the enum in string format so "Enum a{DAY="0", NIGHT="1"}; will return 0
+ * Gets the value of the enum in string format so
+ * "Enum a{DAY="0", NIGHT="1"}; will return 0
+ *
* @return the value of the enum.
*/
@Override
public Long getIntegerValue() {
- return integerValue.getValue();
- }
-
- /**
- * Sets the value of the enum in string format so "Enum a{DAY="0", NIGHT="1"}; will set 0
- * @param value The value of the enum.
- */
- public void setIntegerValue(long value) {
- integerValue.setValue(value);
- this.value = declaration.query(value);
+ return fIntegerValue;
}
@Override
public EnumDeclaration getDeclaration() {
- return declaration;
+ return (EnumDeclaration) super.getDeclaration();
}
// ------------------------------------------------------------------------
// Operations
// ------------------------------------------------------------------------
- @Override
- public void read(BitBuffer input) throws CTFReaderException {
- alignRead(input, this.declaration);
- integerValue.read(input);
- long val = integerValue.getValue();
-
- // TODO: what to do if the integer value maps to no string for this
- // integer ?
- value = declaration.query(val);
- }
-
@Override
public String toString() {
return "{ value = " + getValue() + //$NON-NLS-1$
- ", container = " + integerValue.toString() + //$NON-NLS-1$
+ ", container = " + fIntegerValue + //$NON-NLS-1$
" }"; //$NON-NLS-1$
}
}
import java.nio.ByteOrder;
+import org.eclipse.linuxtools.ctf.core.event.io.BitBuffer;
+import org.eclipse.linuxtools.ctf.core.event.scope.IDefinitionScope;
+import org.eclipse.linuxtools.ctf.core.trace.CTFReaderException;
+
/**
* A CTF float declaration.
*
* @version 1.0
* @author Matthew Khouzam
*/
-public class FloatDeclaration implements IDeclaration {
+public final class FloatDeclaration extends Declaration {
// ------------------------------------------------------------------------
// Attributes
// ------------------------------------------------------------------------
- private final int mant;
- private final int exp;
- private final ByteOrder byteOrder;
- private final long alignment;
+ private final int fMantissa;
+ private final int fExponent;
+ private final ByteOrder fByteOrder;
+ private final long fAlignement;
// ------------------------------------------------------------------------
// Constructors
*/
public FloatDeclaration(int exponent, int mantissa, ByteOrder byteOrder,
long alignment) {
- mant = mantissa;
- exp = exponent;
- this.byteOrder = byteOrder;
- this.alignment = Math.max(alignment, 1);
+ fMantissa = mantissa;
+ fExponent = exponent;
+ fByteOrder = byteOrder;
+ fAlignement = Math.max(alignment, 1);
}
* @return the mant
*/
public int getMantissa() {
- return mant;
+ return fMantissa;
}
/**
* @return the exp
*/
public int getExponent() {
- return exp;
+ return fExponent;
}
/**
* @return the byteOrder
*/
public ByteOrder getByteOrder() {
- return byteOrder;
+ return fByteOrder;
}
@Override
public long getAlignment() {
- return alignment;
+ return fAlignement;
+ }
+
+ /**
+ * @since 3.0
+ */
+ @Override
+ public int getMaximumSize() {
+ return fMantissa + fExponent + 1;
}
// ------------------------------------------------------------------------
// Operations
// ------------------------------------------------------------------------
+ /**
+ * @since 3.0
+ */
@Override
public FloatDefinition createDefinition(IDefinitionScope definitionScope,
- String fieldName) {
- return new FloatDefinition(this, definitionScope, fieldName);
+ String fieldName, BitBuffer input) throws CTFReaderException {
+ alignRead(input);
+ double value = read(input);
+ return new FloatDefinition(this, definitionScope, fieldName, value);
}
@Override
/* Only used for debugging */
return "[declaration] float[" + Integer.toHexString(hashCode()) + ']'; //$NON-NLS-1$
}
+
+ private double read(BitBuffer input) throws CTFReaderException {
+ /* Offset the buffer position wrt the current alignment */
+ alignRead(input);
+ final int exp = getExponent();
+ final int mant = getMantissa();
+ double value = Double.NaN;
+ if ((exp + mant) == 32) {
+ value = readRawFloat32(input, mant, exp);
+ } else if ((exp + mant) == 64) {
+ value = readRawFloat64(input, mant, exp);
+ }
+ return value;
+ }
+
+ private static double readRawFloat32(BitBuffer input, final int manBits,
+ final int expBits) throws CTFReaderException {
+ long temp = input.get(32, false);
+ return createFloat(temp, manBits - 1, expBits);
+ }
+
+ private static double readRawFloat64(BitBuffer input, final int manBits,
+ final int expBits) throws CTFReaderException {
+ long temp = input.get(64, false);
+ return createFloat(temp, manBits - 1, expBits);
+ }
+
+ /**
+ * Create a float from the raw value, Mathematicians beware.
+ *
+ * @param rawValue
+ * The raw value( up to 64 bits)
+ * @param manBits
+ * number of bits in the mantissa
+ * @param expBits
+ * number of bits in the exponent
+ */
+ private static double createFloat(long rawValue, final int manBits,
+ final int expBits) {
+ long manShift = 1L << (manBits);
+ long manMask = manShift - 1;
+ long expMask = (1L << expBits) - 1;
+
+ int exp = (int) ((rawValue >> (manBits)) & expMask) + 1;
+ long man = (rawValue & manMask);
+ final int offsetExponent = exp - (1 << (expBits - 1));
+ double expPow = Math.pow(2.0, offsetExponent);
+ double ret = man * 1.0f;
+ ret /= manShift;
+ ret += 1.0;
+ ret *= expPow;
+ return ret;
+ }
}
package org.eclipse.linuxtools.ctf.core.event.types;
-import org.eclipse.linuxtools.ctf.core.event.io.BitBuffer;
-import org.eclipse.linuxtools.ctf.core.trace.CTFReaderException;
+import org.eclipse.jdt.annotation.NonNull;
+import org.eclipse.linuxtools.ctf.core.event.scope.IDefinitionScope;
/**
* A CTF float definition.
* @author Matthew Khouzam
* @author Simon Marchi
*/
-public class FloatDefinition extends Definition {
+public final class FloatDefinition extends Definition {
// ------------------------------------------------------------------------
// Attributes
// ------------------------------------------------------------------------
- private final FloatDeclaration declaration;
- private double value;
+ private final double fValue;
// ------------------------------------------------------------------------
// Constructors
* the parent scope
* @param fieldName
* the field name
+ * @param value
+ * field value
+ * @since 3.0
*/
- public FloatDefinition(FloatDeclaration declaration,
- IDefinitionScope definitionScope, String fieldName) {
- super(definitionScope, fieldName);
- this.declaration = declaration;
+ public FloatDefinition(@NonNull FloatDeclaration declaration,
+ IDefinitionScope definitionScope, @NonNull String fieldName, double value) {
+ super(declaration, definitionScope, fieldName);
+ fValue = value;
}
// ------------------------------------------------------------------------
* @return the value of the float field fit into a double.
*/
public double getValue() {
- return value;
- }
-
- /**
- * Sets the value of the float
- *
- * @param val
- * the value of the float
- */
- public void setValue(double val) {
- value = val;
+ return fValue;
}
@Override
public FloatDeclaration getDeclaration() {
- return declaration;
+ return (FloatDeclaration) super.getDeclaration();
}
// ------------------------------------------------------------------------
// Operations
// ------------------------------------------------------------------------
- @Override
- public void read(BitBuffer input) throws CTFReaderException {
- /* Offset the buffer position wrt the current alignment */
- alignRead(input, this.declaration);
- final int exp = declaration.getExponent();
- final int mant = declaration.getMantissa();
-
- if ((exp + mant) == 32) {
- value = readRawFloat32(input, mant, exp);
- } else if ((exp + mant) == 64) {
- value = readRawFloat64(input, mant, exp);
- } else {
- value = Double.NaN;
- }
- }
-
- private static double readRawFloat64(BitBuffer input, final int manBits,
- final int expBits) throws CTFReaderException {
- long temp = input.get(64, false);
- return createFloat(temp, manBits - 1, expBits);
- }
-
- /**
- * @param rawValue
- * @param manBits
- * @param expBits
- */
- private static double createFloat(long rawValue, final int manBits,
- final int expBits) {
- long manShift = 1L << (manBits);
- long manMask = manShift - 1;
- long expMask = (1L << expBits) - 1;
-
- int exp = (int) ((rawValue >> (manBits)) & expMask) + 1;
- long man = (rawValue & manMask);
- final int offsetExponent = exp - (1 << (expBits - 1));
- double expPow = Math.pow(2.0, offsetExponent);
- double ret = man * 1.0f;
- ret /= manShift;
- ret += 1.0;
- ret *= expPow;
- return ret;
- }
-
- private static double readRawFloat32(BitBuffer input, final int manBits,
- final int expBits) throws CTFReaderException {
- long temp = input.get(32, false);
- return createFloat(temp, manBits - 1, expBits);
- }
-
@Override
public String toString() {
- return String.valueOf(value);
+ return String.valueOf(fValue);
}
}
package org.eclipse.linuxtools.ctf.core.event.types;
+import org.eclipse.jdt.annotation.NonNull;
+import org.eclipse.linuxtools.ctf.core.event.io.BitBuffer;
+import org.eclipse.linuxtools.ctf.core.event.scope.IDefinitionScope;
+import org.eclipse.linuxtools.ctf.core.event.scope.LexicalScope;
+import org.eclipse.linuxtools.ctf.core.trace.CTFReaderException;
+
/**
* A CTF data type declaration.
*
* placed
* @param fieldName
* the name of the definition
+ * @param input
+ * a bitbuffer to read from
* @return a reference to the definition
+ * @throws CTFReaderException
+ * error in reading
+ * @since 3.0
*/
- Definition createDefinition(IDefinitionScope definitionScope, String fieldName);
+ Definition createDefinition(IDefinitionScope definitionScope, @NonNull String fieldName, @NonNull BitBuffer input) throws CTFReaderException;
+
+ /**
+ * Get the path of a definition
+ *
+ * @param definitionScope
+ * the scope of the definition
+ * @param fieldName
+ * the name of the definition
+ * @return the path of the definition
+ * @since 3.0
+ */
+ public LexicalScope getPath(IDefinitionScope definitionScope, @NonNull String fieldName);
/**
* The minimum alignment. if the field is 32 bits, the definition will pad
* @return the alignment in bits
*/
long getAlignment();
+
+ /**
+ * The MAXIMUM size of this declaration
+ *
+ * @return the maximum size
+ * @since 3.0
+ */
+ int getMaximumSize();
+
}
+++ /dev/null
-/*******************************************************************************
- * Copyright (c) 2011, 2013 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
- * accompanies this distribution, and is available at
- * http://www.eclipse.org/legal/epl-v10.html
- *
- * Contributors: Matthew Khouzam - Initial API and implementation
- * Contributors: Simon Marchi - Initial API and implementation
- *******************************************************************************/
-
-package org.eclipse.linuxtools.ctf.core.event.types;
-
-/**
- * The scope of a CTF definition. Used for compound types.
- *
- * @version 1.0
- * @author Matthew Khouzam
- * @author Simon Marchi
- */
-public interface IDefinitionScope {
-
- /**
- * Gets the path in a C style for the scope.
- * @return the path
- */
- String getPath();
-
- /**
- * Looks up in this definition scope.
- *
- * @param lookupPath
- * The path to look up
- * @return The Definition that was read
- */
- Definition lookupDefinition(String lookupPath);
-}
import java.math.BigInteger;
import java.nio.ByteOrder;
+import org.eclipse.jdt.annotation.NonNull;
+import org.eclipse.jdt.annotation.NonNullByDefault;
+import org.eclipse.jdt.annotation.Nullable;
+import org.eclipse.linuxtools.ctf.core.event.io.BitBuffer;
+import org.eclipse.linuxtools.ctf.core.event.scope.IDefinitionScope;
+import org.eclipse.linuxtools.ctf.core.trace.CTFReaderException;
+
/**
* A CTF integer declaration.
*
* @author Matthew Khouzam
* @author Simon Marchi
*/
-public class IntegerDeclaration implements IDeclaration {
+@NonNullByDefault
+public class IntegerDeclaration extends Declaration {
+
+ // ------------------------------------------------------------------------
+ // Helpers
+ // ------------------------------------------------------------------------
+
+ /**
+ * unsigned int 32 bits big endian
+ *
+ * @since 3.0
+ */
+ public static final IntegerDeclaration UINT_32B_DECL = new IntegerDeclaration(32, false, ByteOrder.BIG_ENDIAN);
+ /**
+ * unsigned int 32 bits little endian
+ *
+ * @since 3.0
+ */
+ public static final IntegerDeclaration UINT_32L_DECL = new IntegerDeclaration(32, false, ByteOrder.LITTLE_ENDIAN);
+ /**
+ * signed int 32 bits big endian
+ *
+ * @since 3.0
+ */
+ public static final IntegerDeclaration INT_32B_DECL = new IntegerDeclaration(32, true, ByteOrder.BIG_ENDIAN);
+ /**
+ * signed int 32 bits little endian
+ *
+ * @since 3.0
+ */
+ public static final IntegerDeclaration INT_32L_DECL = new IntegerDeclaration(32, true, ByteOrder.LITTLE_ENDIAN);
+ /**
+ * unsigned int 32 bits big endian
+ *
+ * @since 3.0
+ */
+ public static final IntegerDeclaration UINT_64B_DECL = new IntegerDeclaration(64, false, ByteOrder.BIG_ENDIAN);
+ /**
+ * unsigned int 64 bits little endian
+ *
+ * @since 3.0
+ */
+ public static final IntegerDeclaration UINT_64L_DECL = new IntegerDeclaration(64, false, ByteOrder.LITTLE_ENDIAN);
+ /**
+ * signed int 64 bits big endian
+ *
+ * @since 3.0
+ */
+ public static final IntegerDeclaration INT_64B_DECL = new IntegerDeclaration(64, true, ByteOrder.BIG_ENDIAN);
+ /**
+ * signed int 64 bits little endian
+ *
+ * @since 3.0
+ */
+ public static final IntegerDeclaration INT_64L_DECL = new IntegerDeclaration(64, true, ByteOrder.LITTLE_ENDIAN);
+ /**
+ * unsigned 8 bit int endianness doesn't matter since it's 8 bits (byte)
+ *
+ * @since 3.0
+ */
+ public static final IntegerDeclaration UINT_8_DECL = new IntegerDeclaration(8, false, ByteOrder.BIG_ENDIAN);
+ /**
+ * signed 8 bit int endianness doesn't matter since it's 8 bits (char)
+ *
+ * @since 3.0
+ */
+ public static final IntegerDeclaration INT_8_DECL = new IntegerDeclaration(8, true, ByteOrder.BIG_ENDIAN);
// ------------------------------------------------------------------------
// Attributes
// ------------------------------------------------------------------------
- private final int length;
- private final boolean signed;
- private final int base;
- private final ByteOrder byteOrder;
- private final Encoding encoding;
- private final long alignment;
- private final String clock;
+ private final int fLength;
+ private final boolean fSigned;
+ private final int fBase;
+ private final ByteOrder fByteOrder;
+ private final Encoding fEncoding;
+ private final long fAlignment;
+ private final String fClock;
// ------------------------------------------------------------------------
// Constructors
// ------------------------------------------------------------------------
+ /**
+ * Factory, some common types cached
+ *
+ * @param len
+ * The length in bits
+ * @param signed
+ * Is the integer signed? false == unsigned
+ * @param base
+ * The base (10-16 are most common)
+ * @param byteOrder
+ * Big-endian little-endian or other
+ * @param encoding
+ * ascii, utf8 or none.
+ * @param clock
+ * The clock path, can be null
+ * @param alignment
+ * The minimum alignment. Should be >= 1
+ * @return the integer declaration
+ * @since 3.0
+ */
+ public static IntegerDeclaration createDeclaration(int len, boolean signed, int base,
+ @Nullable ByteOrder byteOrder, Encoding encoding, String clock, long alignment) {
+ if (encoding.equals(Encoding.NONE) && (alignment == 8) && (clock.equals("")) && base == 10) { //$NON-NLS-1$
+ if (len == 8) {
+ return signed ? INT_8_DECL : UINT_8_DECL;
+ }
+ if (len == 32) {
+ if (signed) {
+ if (byteOrder != null && byteOrder.equals(ByteOrder.BIG_ENDIAN)) {
+ return INT_32B_DECL;
+ }
+ return INT_32L_DECL;
+ }
+ if (byteOrder != null && byteOrder.equals(ByteOrder.BIG_ENDIAN)) {
+ return UINT_32B_DECL;
+ }
+ return UINT_32L_DECL;
+ } else if (len == 64) {
+ if (signed) {
+ if (byteOrder != null && byteOrder.equals(ByteOrder.BIG_ENDIAN)) {
+ return INT_64B_DECL;
+ }
+ return INT_64L_DECL;
+ }
+ if (byteOrder != null && byteOrder.equals(ByteOrder.BIG_ENDIAN)) {
+ return UINT_64B_DECL;
+ }
+ return UINT_64L_DECL;
+ }
+ }
+ return new IntegerDeclaration(len, signed, base, byteOrder, encoding, clock, alignment);
+ }
+
/**
* Constructor
*
* @param alignment
* The minimum alignment. Should be ≥ 1
*/
- public IntegerDeclaration(int len, boolean signed, int base,
- ByteOrder byteOrder, Encoding encoding, String clock, long alignment) {
+ private IntegerDeclaration(int len, boolean signed, int base,
+ @Nullable ByteOrder byteOrder, Encoding encoding, String clock, long alignment) {
if (len <= 0 || len == 1 && signed) {
throw new IllegalArgumentException();
}
- this.length = len;
- this.signed = signed;
- this.base = base;
- this.byteOrder = byteOrder;
- this.encoding = encoding;
- this.clock = clock;
- this.alignment = Math.max(alignment, 1);
+
+ fLength = len;
+ fSigned = signed;
+ fBase = base;
+
+ @SuppressWarnings("null")
+ @NonNull ByteOrder actualByteOrder = (byteOrder == null ? ByteOrder.nativeOrder() : byteOrder);
+ fByteOrder = actualByteOrder;
+
+ fEncoding = encoding;
+ fClock = clock;
+ fAlignment = Math.max(alignment, 1);
+ }
+
+ private IntegerDeclaration(int len, boolean signed, @Nullable ByteOrder byteOrder) {
+ this(len, signed, 10, byteOrder, Encoding.NONE, "", 8); //$NON-NLS-1$
}
// ------------------------------------------------------------------------
* @return the is the integer signed
*/
public boolean isSigned() {
- return signed;
+ return fSigned;
}
/**
* @return the integer base
*/
public int getBase() {
- return base;
+ return fBase;
}
/**
* @return the byte order
*/
public ByteOrder getByteOrder() {
- return byteOrder;
+ return fByteOrder;
}
/**
* @return the encoding
*/
public Encoding getEncoding() {
- return encoding;
+ return fEncoding;
}
/**
* @return is the integer a char
*/
public boolean isCharacter() {
- return (length == 8) && (encoding != Encoding.NONE);
+ return (fLength == 8) && (fEncoding != Encoding.NONE);
}
/**
* @return the length of the integer
*/
public int getLength() {
- return length;
+ return fLength;
}
@Override
public long getAlignment() {
- return alignment;
+ return fAlignment;
}
/**
* @return the integer's clock, can be null. (most often it is)
*/
public String getClock() {
- return clock;
+ return fClock;
+ }
+
+ /**
+ * @since 3.0
+ */
+ @Override
+ public int getMaximumSize() {
+ return fLength;
}
// ------------------------------------------------------------------------
// Operations
// ------------------------------------------------------------------------
+ /**
+ * @since 3.0
+ */
@Override
- public IntegerDefinition createDefinition(IDefinitionScope definitionScope,
- String fieldName) {
- return new IntegerDefinition(this, definitionScope, fieldName);
+ public IntegerDefinition createDefinition(@Nullable IDefinitionScope definitionScope,
+ String fieldName, BitBuffer input) throws CTFReaderException {
+ long value = read(input);
+ return new IntegerDefinition(this, definitionScope, fieldName, value);
}
@Override
}
/**
- * Get the maximum value for this integer declaration
+ * Get the maximum value for this integer declaration.
*
* @return The maximum value for this integer declaration
* @since 2.0
* Compute the number of bits able to represent an unsigned number,
* ignoring sign bit.
*/
- int significant_bits = length - (signed ? 1 : 0);
+ int significantBits = fLength - (fSigned ? 1 : 0);
/*
- * For a given N significant bits, compute the maximal value which is
- * (1 << N) - 1.
+ * For a given N significant bits, compute the maximal value which is (1
+ * << N) - 1.
*/
- return BigInteger.ONE.shiftLeft(significant_bits).subtract(BigInteger.ONE);
+
+ @SuppressWarnings("null")
+ @NonNull BigInteger ret = BigInteger.ONE.shiftLeft(significantBits).subtract(BigInteger.ONE);
+ return ret;
}
/**
- * Get the minimum value for this integer declaration
+ * Get the minimum value for this integer declaration.
*
* @return The minimum value for this integer declaration
* @since 2.0
*/
public BigInteger getMinValue() {
- if (!signed) {
- return BigInteger.ZERO;
+ if (!fSigned) {
+ @SuppressWarnings("null")
+ @NonNull BigInteger ret = BigInteger.ZERO;
+ return ret;
}
/*
* Compute the number of bits able to represent an unsigned number,
* without the sign bit.
*/
- int significant_bits = length - 1;
+ int significantBits = fLength - 1;
+ /*
+ * For a given N significant bits, compute the minimal value which is -
+ * (1 << N).
+ */
+ @SuppressWarnings("null")
+ @NonNull BigInteger ret = BigInteger.ONE.shiftLeft(significantBits).negate();
+ return ret;
+ }
+
+ private long read(BitBuffer input) throws CTFReaderException {
+ /* Offset the buffer position wrt the current alignment */
+ alignRead(input);
+
+ boolean signed = isSigned();
+ int length = getLength();
+ long bits = 0;
+
+ /*
+ * Is the endianness of this field the same as the endianness of the
+ * input buffer? If not, then temporarily set the buffer's endianness to
+ * this field's just to read the data
+ */
+ ByteOrder previousByteOrder = input.getByteOrder();
+ if ((getByteOrder() != input.getByteOrder())) {
+ input.setByteOrder(getByteOrder());
+ }
+
+ if (length > 64) {
+ throw new CTFReaderException("Cannot read an integer with over 64 bits. Length given: " + length); //$NON-NLS-1$
+ }
+
+ bits = input.get(length, signed);
+
/*
- * For a given N significant bits, compute the minimal value which is
- * - (1 << N).
+ * Put the input buffer's endianness back to original if it was changed
*/
- return BigInteger.ONE.shiftLeft(significant_bits).negate();
+ if (previousByteOrder != input.getByteOrder()) {
+ input.setByteOrder(previousByteOrder);
+ }
+
+ return bits;
}
}
package org.eclipse.linuxtools.ctf.core.event.types;
import java.math.BigInteger;
-import java.nio.ByteOrder;
-import org.eclipse.linuxtools.ctf.core.event.io.BitBuffer;
-import org.eclipse.linuxtools.ctf.core.trace.CTFReaderException;
+import org.eclipse.jdt.annotation.NonNull;
+import org.eclipse.linuxtools.ctf.core.event.scope.IDefinitionScope;
/**
* A CTF integer definition.
* @author Matthew Khouzam
* @author Simon Marchi
*/
-public class IntegerDefinition extends SimpleDatatypeDefinition {
+public final class IntegerDefinition extends SimpleDatatypeDefinition {
// ------------------------------------------------------------------------
// Attributes
// ------------------------------------------------------------------------
- private final IntegerDeclaration declaration;
- private long value;
+ private final long fValue;
// ------------------------------------------------------------------------
// Constructors
* the parent scope
* @param fieldName
* the field name
+ * @param value
+ * integer value
+ * @since 3.0
*/
- public IntegerDefinition(IntegerDeclaration declaration,
- IDefinitionScope definitionScope, String fieldName) {
- super(definitionScope, fieldName);
- this.declaration = declaration;
+ public IntegerDefinition(@NonNull IntegerDeclaration declaration,
+ IDefinitionScope definitionScope, @NonNull String fieldName, long value) {
+ super(declaration, definitionScope, fieldName);
+ fValue = value;
}
// ------------------------------------------------------------------------
* @return the value of the integer (in long)
*/
public long getValue() {
- return value;
- }
-
- /**
- * Sets the value of an integer
- *
- * @param val
- * the value
- */
- public void setValue(long val) {
- value = val;
+ return fValue;
}
@Override
public IntegerDeclaration getDeclaration() {
- return declaration;
+ return (IntegerDeclaration) super.getDeclaration();
}
// ------------------------------------------------------------------------
return this.toString();
}
- @Override
- public void read(BitBuffer input) throws CTFReaderException {
- /* Offset the buffer position wrt the current alignment */
- alignRead(input, this.declaration);
-
- boolean signed = declaration.isSigned();
- int length = declaration.getLength();
- long bits = 0;
-
- /*
- * Is the endianness of this field the same as the endianness of the
- * input buffer? If not, then temporarily set the buffer's endianness to
- * this field's just to read the data
- */
- ByteOrder previousByteOrder = input.getByteOrder();
- if ((this.declaration.getByteOrder() != null) &&
- (this.declaration.getByteOrder() != input.getByteOrder())) {
- input.setByteOrder(this.declaration.getByteOrder());
- }
-
- if (length > 64) {
- throw new CTFReaderException("Cannot read an integer with over 64 bits. Length given: " + length); //$NON-NLS-1$
- }
-
- bits = input.get(length, signed);
-
- /*
- * Put the input buffer's endianness back to original if it was changed
- */
- if (previousByteOrder != input.getByteOrder()) {
- input.setByteOrder(previousByteOrder);
- }
-
- value = bits;
- }
-
@Override
public String toString() {
- if (declaration.isCharacter()) {
- char c = (char) value;
+ if (getDeclaration().isCharacter()) {
+ char c = (char) fValue;
return Character.toString(c);
}
- return formatNumber(value, declaration.getBase(), declaration.isSigned());
+ return formatNumber(fValue, getDeclaration().getBase(), getDeclaration().isSigned());
}
/**
package org.eclipse.linuxtools.ctf.core.event.types;
+import java.util.Collection;
+import java.util.List;
+
+import org.eclipse.linuxtools.ctf.core.event.io.BitBuffer;
+import org.eclipse.linuxtools.ctf.core.event.scope.IDefinitionScope;
import org.eclipse.linuxtools.ctf.core.trace.CTFReaderException;
+import com.google.common.collect.ArrayListMultimap;
+import com.google.common.collect.ImmutableList;
+import com.google.common.collect.ImmutableList.Builder;
+import com.google.common.collect.Multimap;
+
/**
* A CTF sequence declaration.
*
* @author Matthew Khouzam
* @author Simon Marchi
*/
-public class SequenceDeclaration implements IDeclaration {
+public class SequenceDeclaration extends Declaration {
// ------------------------------------------------------------------------
// Attributes
// ------------------------------------------------------------------------
- private final IDeclaration elemType;
- private final String lengthName;
+ private final IDeclaration fElemType;
+ private final String fLengthName;
+ private final Multimap<String, String> fPaths = ArrayListMultimap.<String, String>create();
// ------------------------------------------------------------------------
// Constructors
* The element type
*/
public SequenceDeclaration(String lengthName, IDeclaration elemType) {
- this.elemType = elemType;
- this.lengthName = lengthName;
+ fElemType = elemType;
+ fLengthName = lengthName;
}
// ------------------------------------------------------------------------
/**
* Gets the element type
+ *
* @return the element type
*/
public IDeclaration getElementType() {
- return elemType;
+ return fElemType;
}
/**
* Gets the name of the length field
+ *
* @return the name of the length field
*/
public String getLengthName() {
- return lengthName;
+ return fLengthName;
}
@Override
return getElementType().getAlignment();
}
+
// ------------------------------------------------------------------------
// Operations
// ------------------------------------------------------------------------
+ /**
+ * Is the Sequence a string?
+ * @return true, if the elements are chars, false otherwise
+ * @since 3.0
+ */
+ public boolean isString(){
+ IntegerDeclaration elemInt;
+ IDeclaration elementType = getElementType();
+ if (elementType instanceof IntegerDeclaration) {
+ elemInt = (IntegerDeclaration) elementType;
+ if (elemInt.isCharacter()) {
+ return true;
+ }
+ }
+ return false;
+ }
+
+ /**
+ * @since 3.0
+ */
+ @SuppressWarnings("null") // immutablelist
@Override
public SequenceDefinition createDefinition(
- IDefinitionScope definitionScope, String fieldName) {
- SequenceDefinition ret = null;
- try {
- ret = new SequenceDefinition(this, definitionScope, fieldName);
- } catch (CTFReaderException e) {
- // Temporarily catch this here, eventually this should be thrown
- // up the call stack
- e.printStackTrace();
+ IDefinitionScope definitionScope, String fieldName, BitBuffer input) throws CTFReaderException {
+ Definition lenDef = null;
+
+ if (definitionScope != null) {
+ lenDef = definitionScope.lookupDefinition(getLengthName());
+ }
+
+ if (lenDef == null) {
+ throw new CTFReaderException("Sequence length field not found"); //$NON-NLS-1$
}
- return ret;
+
+ if (!(lenDef instanceof IntegerDefinition)) {
+ throw new CTFReaderException("Sequence length field not integer"); //$NON-NLS-1$
+ }
+
+ IntegerDefinition lengthDefinition = (IntegerDefinition) lenDef;
+
+ if (lengthDefinition.getDeclaration().isSigned()) {
+ throw new CTFReaderException("Sequence length must not be signed"); //$NON-NLS-1$
+ }
+
+ long length = lengthDefinition.getValue();
+ if ((length > Integer.MAX_VALUE) || (!input.canRead((int) length * fElemType.getMaximumSize()))) {
+ throw new CTFReaderException("Sequence length too long " + length); //$NON-NLS-1$
+ }
+
+ Collection<String> collection = fPaths.get(fieldName);
+ while (collection.size() < length) {
+ fPaths.put(fieldName, fieldName + '[' + collection.size() + ']');
+ }
+ List<String> paths = (List<String>) fPaths.get(fieldName);
+ Builder<Definition> definitions = new ImmutableList.Builder<>();
+ for (int i = 0; i < length; i++) {
+ definitions.add(fElemType.createDefinition(definitionScope, paths.get(i), input));
+ }
+ return new SequenceDefinition(this, definitionScope, fieldName, definitions.build());
}
@Override
return "[declaration] sequence[" + Integer.toHexString(hashCode()) + ']'; //$NON-NLS-1$
}
+ /**
+ * @since 3.0
+ */
+ @Override
+ public int getMaximumSize() {
+ return Integer.MAX_VALUE;
+ }
+
}
package org.eclipse.linuxtools.ctf.core.event.types;
-import org.eclipse.linuxtools.ctf.core.event.io.BitBuffer;
-import org.eclipse.linuxtools.ctf.core.trace.CTFReaderException;
+import java.util.List;
+
+import org.eclipse.jdt.annotation.NonNull;
+import org.eclipse.linuxtools.ctf.core.event.scope.IDefinitionScope;
+
+import com.google.common.base.Joiner;
+import com.google.common.collect.ImmutableList;
/**
* A CTF sequence definition (a fixed-size array).
* @author Matthew Khouzam
* @author Simon Marchi
*/
-public class SequenceDefinition extends Definition {
+public final class SequenceDefinition extends Definition {
+
+ // TODO: investigate merging with arraydefinition
// ------------------------------------------------------------------------
// Attributes
// ------------------------------------------------------------------------
- private final SequenceDeclaration declaration;
- private final IntegerDefinition lengthDefinition;
- private Definition definitions[];
- private int currentLength;
+ private final ImmutableList<Definition> fDefinitions;
// ------------------------------------------------------------------------
// Constructors
* the parent scope
* @param fieldName
* the field name
- * @throws CTFReaderException
- * If the sequence field was malformatted
+ * @param definitions
+ * Definitions
+ * @since 3.0
*/
- public SequenceDefinition(SequenceDeclaration declaration,
- IDefinitionScope definitionScope, String fieldName)
- throws CTFReaderException {
- super(definitionScope, fieldName);
- Definition lenDef = null;
-
- this.declaration = declaration;
-
- if (definitionScope != null) {
- lenDef = definitionScope.lookupDefinition(declaration
- .getLengthName());
- }
-
- if (lenDef == null) {
- throw new CTFReaderException("Sequence length field not found"); //$NON-NLS-1$
- }
-
- if (!(lenDef instanceof IntegerDefinition)) {
- throw new CTFReaderException("Sequence length field not integer"); //$NON-NLS-1$
- }
-
- lengthDefinition = (IntegerDefinition) lenDef;
-
- if (this.lengthDefinition.getDeclaration().isSigned()) {
- throw new CTFReaderException("Sequence length must not be signed"); //$NON-NLS-1$
- }
+ public SequenceDefinition(@NonNull SequenceDeclaration declaration, IDefinitionScope definitionScope, @NonNull String fieldName, List<Definition> definitions) {
+ super(declaration, definitionScope, fieldName);
+ fDefinitions = ImmutableList.copyOf(definitions);
}
// ------------------------------------------------------------------------
@Override
public SequenceDeclaration getDeclaration() {
- return declaration;
+ return (SequenceDeclaration) super.getDeclaration();
}
/**
* @return the length of the sequence
*/
public int getLength() {
- return currentLength;
+ return fDefinitions.size();
}
/**
* throws an out of bounds exception
*/
public Definition getElem(int i) {
- if (i > definitions.length) {
+ if (i > fDefinitions.size()) {
return null;
}
-
- return definitions[i];
- }
-
- /**
- * Is the sequence a null terminated string?
- * @return true == is a string, false == is not a string
- */
- public boolean isString() {
- IntegerDeclaration elemInt;
-
- if (declaration.getElementType() instanceof IntegerDeclaration) {
- elemInt = (IntegerDeclaration) declaration.getElementType();
- if (elemInt.isCharacter()) {
- return true;
- }
- }
- return false;
+ return fDefinitions.get(i);
}
// ------------------------------------------------------------------------
// Operations
// ------------------------------------------------------------------------
- @Override
- public void read(BitBuffer input) throws CTFReaderException {
- currentLength = (int) lengthDefinition.getValue();
-
- if ((definitions == null) || (definitions.length < currentLength)) {
- Definition newDefinitions[] = new Definition[currentLength];
-
- int i = 0;
-
- if (definitions != null) {
- System.arraycopy(definitions, 0, newDefinitions, 0, definitions.length);
- }
-
- for (; i < currentLength; i++) {
- newDefinitions[i] = declaration.getElementType()
- .createDefinition(getDefinitionScope(),
- getFieldName() + "[" + i + "]"); //$NON-NLS-1$ //$NON-NLS-2$
- }
-
- definitions = newDefinitions;
- }
-
- for (int i = 0; i < currentLength; i++) {
- definitions[i].read(input);
- }
- }
-
@Override
public String toString() {
StringBuilder b = new StringBuilder();
- if (this.isString()) {
- for (int i = 0; i < currentLength; i++) {
- IntegerDefinition character = (IntegerDefinition) definitions[i];
+ if (getDeclaration().isString()) {
+ for (Definition def : fDefinitions) {
+ IntegerDefinition character = (IntegerDefinition) def;
if (character.getValue() == 0) {
break;
}
} else {
b.append('[');
- if (currentLength > 0) {
- for (int i = 0; i < (currentLength - 1); i++) {
- b.append(' ');
- b.append(definitions[i].toString());
- b.append(',');
- }
- b.append(' ');
- b.append(definitions[currentLength - 1].toString());
- }
- b.append(" ]"); //$NON-NLS-1$
-
+ Joiner joiner = Joiner.on(", ").skipNulls(); //$NON-NLS-1$
+ b.append(joiner.join(fDefinitions));
+ b.append(']');
}
return b.toString();
package org.eclipse.linuxtools.ctf.core.event.types;
+import org.eclipse.jdt.annotation.NonNull;
+import org.eclipse.linuxtools.ctf.core.event.scope.IDefinitionScope;
+
/**
* Simple Datatype definition is a datatype that allows the addition of
* getIntegerValue and getStringValue to a class.
/**
* Create a new SimpleDatatypeDefinition
*
+ * @param declaration
+ * definition's declaration
* @param definitionScope
* The scope of this definition
* @param fieldName
* The name of the field matching this definition in the parent
* scope
+ * @since 3.0
*/
- public SimpleDatatypeDefinition(IDefinitionScope definitionScope,
- String fieldName) {
- super(definitionScope, fieldName);
+ public SimpleDatatypeDefinition(@NonNull IDeclaration declaration, IDefinitionScope definitionScope,
+ @NonNull String fieldName) {
+ super(declaration, definitionScope, fieldName);
}
/**
package org.eclipse.linuxtools.ctf.core.event.types;
+import org.eclipse.linuxtools.ctf.core.event.io.BitBuffer;
+import org.eclipse.linuxtools.ctf.core.event.scope.IDefinitionScope;
+import org.eclipse.linuxtools.ctf.core.trace.CTFReaderException;
+
/**
* A CTF string declaration.
*
* @author Matthew Khouzam
* @author Simon Marchi
*/
-public class StringDeclaration implements IDeclaration {
+public class StringDeclaration extends Declaration {
// ------------------------------------------------------------------------
// Attributes
// ------------------------------------------------------------------------
- private Encoding encoding = Encoding.UTF8;
+ private final Encoding fEncoding;
// ------------------------------------------------------------------------
// Constructors
* Generate a UTF8 string declaration
*/
public StringDeclaration() {
+ fEncoding = Encoding.UTF8;
}
/**
* @param encoding the encoding, utf8 or ascii
*/
public StringDeclaration(Encoding encoding) {
- this.encoding = encoding;
+ fEncoding = encoding;
}
// ------------------------------------------------------------------------
* @return the character encoding.
*/
public Encoding getEncoding() {
- return encoding;
- }
-
- /**
- *
- * @param encoding the character encoding to set
- */
- public void setEncoding(Encoding encoding) {
- this.encoding = encoding;
+ return fEncoding;
}
@Override
// See ctf 4.2.5: Strings are always aligned on byte size.
return 8;
}
+
+ /**
+ * @since 3.0
+ */
+ @Override
+ public int getMaximumSize() {
+ return Integer.MAX_VALUE;
+ }
// ------------------------------------------------------------------------
// Operations
// ------------------------------------------------------------------------
+ /**
+ * @since 3.0
+ */
@Override
public StringDefinition createDefinition(IDefinitionScope definitionScope,
- String fieldName) {
- return new StringDefinition(this, definitionScope, fieldName);
+ String fieldName, BitBuffer input) throws CTFReaderException {
+ String value = read(input);
+ return new StringDefinition(this, definitionScope, fieldName, value);
}
+ private String read(BitBuffer input) throws CTFReaderException {
+ /* Offset the buffer position wrt the current alignment */
+ alignRead(input);
+
+ StringBuilder sb = new StringBuilder();
+ char c = (char) input.get(8, false);
+ while (c != 0) {
+ sb.append(c);
+ c = (char) input.get(8, false);
+ }
+ return sb.toString();
+ }
@Override
public String toString() {
/* Only used for debugging */
package org.eclipse.linuxtools.ctf.core.event.types;
-import org.eclipse.linuxtools.ctf.core.event.io.BitBuffer;
-import org.eclipse.linuxtools.ctf.core.trace.CTFReaderException;
+import org.eclipse.jdt.annotation.NonNull;
+import org.eclipse.linuxtools.ctf.core.event.scope.IDefinitionScope;
/**
* A CTF string definition (similar to a C null-terminated byte array).
* @author Matthew Khouzam
* @author Simon Marchi
*/
-public class StringDefinition extends Definition {
+public final class StringDefinition extends Definition {
// ------------------------------------------------------------------------
// Attributes
// ------------------------------------------------------------------------
- private StringDeclaration fDeclaration;
-
- private String fString;
+ private final String fString;
// ------------------------------------------------------------------------
// Constructors
* the parent scope
* @param fieldName
* the field name
+ * @param value
+ * The String value
+ * @since 3.0
*/
- public StringDefinition(StringDeclaration declaration,
- IDefinitionScope definitionScope, String fieldName) {
- super(definitionScope, fieldName);
-
- fDeclaration = declaration;
-
- fString = ""; //$NON-NLS-1$
+ public StringDefinition(@NonNull StringDeclaration declaration,
+ IDefinitionScope definitionScope, @NonNull String fieldName, String value) {
+ super(declaration, definitionScope, fieldName);
+ fString = value;
}
// ------------------------------------------------------------------------
@Override
public StringDeclaration getDeclaration() {
- return fDeclaration;
- }
-
- /**
- * Sets the string declaration
- *
- * @param declaration
- * the declaration
- */
- public void setDeclaration(StringDeclaration declaration) {
- fDeclaration = declaration;
+ return (StringDeclaration) super.getDeclaration();
}
/**
return fString;
}
- /**
- * Sets the string (value)
- *
- * @param str the string
- * @since 3.0
- */
- public void setValue(String str) {
- fString = str;
- }
-
// ------------------------------------------------------------------------
// Operations
// ------------------------------------------------------------------------
- @Override
- public void read(BitBuffer input) throws CTFReaderException {
- /* Offset the buffer position wrt the current alignment */
- alignRead(input, fDeclaration);
-
- StringBuilder sb = new StringBuilder();
- char c = (char) input.get(8, false);
- while (c != 0) {
- sb.append(c);
- c = (char) input.get(8, false);
- }
- fString = sb.toString();
- }
-
@Override
public String toString() {
return '\"' + getValue() + '\"';
package org.eclipse.linuxtools.ctf.core.event.types;
-import java.util.HashMap;
-import java.util.LinkedList;
+import java.util.LinkedHashMap;
import java.util.List;
import java.util.Map;
+import org.eclipse.jdt.annotation.NonNull;
+import org.eclipse.linuxtools.ctf.core.event.io.BitBuffer;
+import org.eclipse.linuxtools.ctf.core.event.scope.IDefinitionScope;
+import org.eclipse.linuxtools.ctf.core.trace.CTFReaderException;
+
+import com.google.common.collect.ImmutableList;
+
/**
* A CTF structure declaration.
*
* @author Matthew Khouzam
* @author Simon Marchi
*/
-public class StructDeclaration implements IDeclaration {
+public class StructDeclaration extends Declaration {
// ------------------------------------------------------------------------
// Attributes
// ------------------------------------------------------------------------
- private final Map<String, IDeclaration> fields = new HashMap<>();
- private final List<String> fieldsList = new LinkedList<>();
- private long maxAlign;
+ /** linked list of field names. So fieldName->fieldValue */
+ private final Map<String, IDeclaration> fFieldMap = new LinkedHashMap<>();
+
+ /** List of strings for acceleration */
+ @NonNull
+ private ImmutableList<String> fFieldNames;
+ /** array declaration for acceleration */
+ private List<IDeclaration> fFieldDeclarations;
+
+ /** maximum bit alignment */
+ private long fMaxAlign;
// ------------------------------------------------------------------------
// Constructors
* aligned and has a 32 bit aligned field, the struct becomes 32
* bit aligned.
*/
+ @SuppressWarnings("null")
+ // ImmutableList.of()
public StructDeclaration(long align) {
- this.maxAlign = Math.max(align, 1);
+ fMaxAlign = Math.max(align, 1);
+ fFieldNames = ImmutableList.of();
+ }
+
+ /**
+ * Struct declaration constructor
+ *
+ * @param names
+ * the names of all the fields
+ * @param declarations
+ * all the fields
+ * @since 3.0
+ */
+ @SuppressWarnings("null")
+ // ImmutableList.of()
+ public StructDeclaration(String[] names, Declaration[] declarations) {
+ fMaxAlign = 1;
+ fFieldNames = ImmutableList.of();
+ for (int i = 0; i < names.length; i++) {
+ addField(names[i], declarations[i]);
+ }
}
// ------------------------------------------------------------------------
/**
* Get current alignment
+ *
* @return the alignment of the struct and all its fields
*/
public long getMaxAlign() {
- return maxAlign;
+ return fMaxAlign;
}
/**
* Query if the struct has a given field
- * @param name the name of the field, scopeless please
+ *
+ * @param name
+ * the name of the field, scopeless please
* @return does the field exist?
*/
public boolean hasField(String name) {
- return this.fields.containsKey(name);
+ return fFieldMap.containsKey(name);
}
/**
* get the fields of the struct in a map. Faster access time than a list.
+ *
* @return a HashMap of the fields (key is the name)
* @since 2.0
*/
public Map<String, IDeclaration> getFields() {
- return this.fields;
+ return fFieldMap;
}
/**
- * Gets the field list. Very important since the map of fields does not retain the order of the fields.
+ * Gets the field list. Very important since the map of fields does not
+ * retain the order of the fields.
+ *
* @return the field list.
+ * @since 3.0
*/
- public List<String> getFieldsList() {
- return this.fieldsList;
+ public Iterable<String> getFieldsList() {
+ return fFieldMap.keySet();
}
@Override
public long getAlignment() {
- return this.maxAlign;
+ return this.fMaxAlign;
+ }
+
+ /**
+ * @since 3.0
+ */
+ @Override
+ public int getMaximumSize() {
+ int maxSize = 0;
+ if (fFieldDeclarations != null) {
+ for (IDeclaration field : fFieldDeclarations) {
+ maxSize += field.getMaximumSize();
+ }
+ }
+ return Math.min(maxSize, Integer.MAX_VALUE);
}
// ------------------------------------------------------------------------
// Operations
// ------------------------------------------------------------------------
+ /**
+ * @since 3.0
+ */
+ @SuppressWarnings("null")
+ // immutablelist
@Override
public StructDefinition createDefinition(IDefinitionScope definitionScope,
- String fieldName) {
- return new StructDefinition(this, definitionScope, fieldName);
+ String fieldName, BitBuffer input) throws CTFReaderException {
+ alignRead(input);
+ final Definition[] myFields = new Definition[fFieldNames.size()];
+ StructDefinition structDefinition = new StructDefinition(this, definitionScope, fieldName, fFieldNames, myFields);
+ for (int i = 0; i < fFieldNames.size(); i++) {
+ myFields[i] = fFieldDeclarations.get(i).createDefinition(structDefinition, fFieldNames.get(i), input);
+ }
+ return structDefinition;
}
/**
* Add a field to the struct
- * @param name the name of the field, scopeless
- * @param declaration the declaration of the field
+ *
+ * @param name
+ * the name of the field, scopeless
+ * @param declaration
+ * the declaration of the field
*/
+ @SuppressWarnings("null")
+ // Immutable list copyof cannot return null
public void addField(String name, IDeclaration declaration) {
- this.fields.put(name, declaration);
- this.fieldsList.add(name);
- maxAlign = Math.max(maxAlign, declaration.getAlignment());
+ fFieldMap.put(name, declaration);
+ fMaxAlign = Math.max(fMaxAlign, declaration.getAlignment());
+ fFieldNames = ImmutableList.copyOf(fFieldMap.keySet());
+ fFieldDeclarations = ImmutableList.<IDeclaration>copyOf(fFieldMap.values());
}
@Override
public int hashCode() {
final int prime = 31;
int result = 1;
- result = (prime * result) + fieldsList.hashCode();
- result = (prime * result) + (int) (maxAlign ^ (maxAlign >>> 32));
+ result = (prime * result) + fFieldMap.entrySet().hashCode();
+ result = (prime * result) + (int) (fMaxAlign ^ (fMaxAlign >>> 32));
return result;
}
return false;
}
StructDeclaration other = (StructDeclaration) obj;
- if (!fieldsList.equals(other.fieldsList)) {
+ if (!fFieldMap.entrySet().equals(other.fFieldMap.entrySet())) {
return false;
}
- if (maxAlign != other.maxAlign) {
+ if (fMaxAlign != other.fMaxAlign) {
return false;
}
return true;
package org.eclipse.linuxtools.ctf.core.event.types;
-import java.util.LinkedHashMap;
+import java.util.Collections;
+import java.util.LinkedList;
import java.util.List;
-import java.util.ListIterator;
import java.util.Map;
-import org.eclipse.linuxtools.ctf.core.event.io.BitBuffer;
-import org.eclipse.linuxtools.ctf.core.trace.CTFReaderException;
+import org.eclipse.jdt.annotation.NonNull;
+import org.eclipse.linuxtools.ctf.core.event.scope.IDefinitionScope;
+
+import com.google.common.base.Joiner;
+import com.google.common.collect.ImmutableList;
+import com.google.common.collect.ImmutableMap;
+import com.google.common.collect.ImmutableMap.Builder;
/**
* A CTF structure definition (similar to a C structure).
* @author Matthew Khouzam
* @author Simon Marchi
*/
-public class StructDefinition extends Definition implements IDefinitionScope {
+public final class StructDefinition extends Definition implements IDefinitionScope {
// ------------------------------------------------------------------------
// Attributes
// ------------------------------------------------------------------------
- private final StructDeclaration declaration;
- private final Map<String, Definition> definitions = new LinkedHashMap<>();
+ private final ImmutableList<String> fFieldNames;
+ private final Definition[] fDefinitions;
+ private Map<String, Definition> fDefinitionsMap = null;
// ------------------------------------------------------------------------
// Constructors
* the parent scope
* @param structFieldName
* the field name
+ * @param fieldNames
+ * the list of fields
+ * @param definitions
+ * the definitions
+ * @since 3.0
*/
- public StructDefinition(StructDeclaration declaration,
- IDefinitionScope definitionScope, String structFieldName) {
- super(definitionScope, structFieldName);
-
- this.declaration = declaration;
-
- for (String fName : declaration.getFieldsList()) {
- IDeclaration fieldDecl = declaration.getFields().get(fName);
- assert (fieldDecl != null);
-
- Definition def = fieldDecl.createDefinition(this, fName);
- definitions.put(fName, def);
+ public StructDefinition(@NonNull StructDeclaration declaration,
+ IDefinitionScope definitionScope, @NonNull String structFieldName, List<String> fieldNames, Definition[] definitions) {
+ super(declaration, definitionScope, structFieldName);
+ fFieldNames = ImmutableList.copyOf(fieldNames);
+ fDefinitions = definitions;
+ if (fFieldNames == null) {
+ fDefinitionsMap = Collections.EMPTY_MAP;
}
}
// ------------------------------------------------------------------------
/**
+ * Gets the definition of the field
+ *
+ * @param fieldName
+ * the fieldname
* @return The definitions of all the fields
- * @since 2.0
+ * @since 3.0
+ */
+ public Definition getDefinition(String fieldName) {
+ if (fDefinitionsMap == null) {
+ buildFieldsMap();
+ }
+ return fDefinitionsMap.get(fieldName);
+ }
+
+ private void buildFieldsMap() {
+ Builder<String, Definition> mapBuilder = new ImmutableMap.Builder<>();
+ for (int i = 0; i < fFieldNames.size(); i++) {
+ if (fDefinitions[i] != null) {
+ mapBuilder.put(fFieldNames.get(i), fDefinitions[i]);
+ }
+ }
+ fDefinitionsMap = mapBuilder.build();
+ }
+
+ /**
+ * Gets an array of the field names
+ *
+ * @return the field names array
+ * @since 3.0
*/
- public Map<String, Definition> getDefinitions() {
- return definitions;
+ public List<String> getFieldNames() {
+ return fFieldNames;
}
@Override
public StructDeclaration getDeclaration() {
- return declaration;
+ return (StructDeclaration) super.getDeclaration();
}
// ------------------------------------------------------------------------
// Operations
// ------------------------------------------------------------------------
- @Override
- public void read(BitBuffer input) throws CTFReaderException {
- alignRead(input, this.declaration);
- final List<String> fieldList = declaration.getFieldsList();
- for (String fName : fieldList) {
- Definition def = definitions.get(fName);
- assert (def != null);
- def.read(input);
- }
- }
-
@Override
public Definition lookupDefinition(String lookupPath) {
/*
* sequence refers to a field that is after it, the field's definition
* will not be there yet in the hashmap.
*/
- Definition retVal = definitions.get(lookupPath);
- if (retVal == null) {
- retVal = definitions.get("_" + lookupPath); //$NON-NLS-1$
+ int val = fFieldNames.indexOf(lookupPath);
+ if (val != -1) {
+ return fDefinitions[val];
}
- return retVal;
+ String lookupUnderscored = "_" + lookupPath; //$NON-NLS-1$
+ val = fFieldNames.indexOf(lookupUnderscored);
+ if (val != -1) {
+ return fDefinitions[val];
+ }
+ return null;
}
/**
}
/**
- * Lookup a string in a struct. If the name returns a non-string (like
- * an int) than the method returns null
+ * Lookup a string in a struct. If the name returns a non-string (like an
+ * int) than the method returns null
*
* @param name
* the name of the string
}
/**
- * Lookup a struct in a struct. If the name returns a non-struct (like
- * an int) than the method returns null
+ * Lookup a struct in a struct. If the name returns a non-struct (like an
+ * int) than the method returns null
*
* @param name
* the name of the struct
}
/**
- * Lookup a variant in a struct. If the name returns a non-variant (like
- * an int) than the method returns null
+ * Lookup a variant in a struct. If the name returns a non-variant (like an
+ * int) than the method returns null
*
* @param name
* the name of the variant
builder.append("{ "); //$NON-NLS-1$
- ListIterator<String> listIterator = this.declaration.getFieldsList()
- .listIterator();
-
- while (listIterator.hasNext()) {
- String field = listIterator.next();
-
- builder.append(field);
- builder.append(" = "); //$NON-NLS-1$
- builder.append(lookupDefinition(field).toString());
-
- if (listIterator.hasNext()) {
- builder.append(", "); //$NON-NLS-1$
+ if (fFieldNames != null) {
+ List<String> fields = new LinkedList<>();
+ for (String field : fFieldNames) {
+ String appendee = field + " = " + lookupDefinition(field).toString(); //$NON-NLS-1$
+ fields.add(appendee);
}
+ Joiner joiner = Joiner.on(", ").skipNulls(); //$NON-NLS-1$
+ builder.append(joiner.join(fields));
}
builder.append(" }"); //$NON-NLS-1$
return builder.toString();
}
+
}
package org.eclipse.linuxtools.ctf.core.event.types;
+import java.util.Collection;
+import java.util.Collections;
import java.util.HashMap;
import java.util.Map;
+import org.eclipse.linuxtools.ctf.core.event.io.BitBuffer;
+import org.eclipse.linuxtools.ctf.core.event.scope.IDefinitionScope;
+import org.eclipse.linuxtools.ctf.core.trace.CTFReaderException;
+
/**
* A CTFC variant declaration.
*
* @author Matthew Khouzam
* @author Simon Marchi
*/
-public class VariantDeclaration implements IDeclaration {
+public class VariantDeclaration extends Declaration {
// ------------------------------------------------------------------------
// Attributes
// ------------------------------------------------------------------------
- private String tag = null;
- private static final long alignment = 1;
- private final Map<String, IDeclaration> fields = new HashMap<>();
+ private String fTag = null;
+ private static final long ALIGNMENT = 1;
+ private final Map<String, IDeclaration> fFields = Collections.synchronizedMap(new HashMap<String, IDeclaration>());
+ private EnumDefinition fTagDef;
+ private IDeclaration fDeclarationToPopulate;
+ private IDefinitionScope fPrevDefinitionScope;
// ------------------------------------------------------------------------
// Constructors
* @return Does the variant have a tag
*/
public boolean isTagged() {
- return tag != null;
+ return fTag != null;
}
/**
* Lookup if a field exists in the variant
- * @param fieldTag the field tag name
+ *
+ * @param fieldTag
+ * the field tag name
* @return true = field tag exists
*/
public boolean hasField(String fieldTag) {
- return fields.containsKey(fieldTag);
+ return fFields.containsKey(fieldTag);
}
/**
* Sets the tag in a variant
- * @param tag the tag
+ *
+ * @param tag
+ * the tag
*/
public void setTag(String tag) {
- this.tag = tag;
+ fTag = tag;
+ fTagDef = null;
}
/**
* Gets current variant tag
+ *
* @return the variant tag.
*/
public String getTag() {
- return this.tag;
+ return fTag;
}
/**
* Gets the fields of the variant
+ *
* @return the fields of the variant
* @since 2.0
*/
public Map<String, IDeclaration> getFields() {
- return this.fields;
+ return this.fFields;
}
@Override
public long getAlignment() {
- return alignment;
+ return ALIGNMENT;
}
+
// ------------------------------------------------------------------------
// Operations
// ------------------------------------------------------------------------
+ /**
+ * @since 3.0
+ */
@Override
public VariantDefinition createDefinition(IDefinitionScope definitionScope,
- String fieldName) {
- return new VariantDefinition(this, definitionScope, fieldName);
+ String fieldName, BitBuffer input) throws CTFReaderException {
+ alignRead(input);
+ if (fPrevDefinitionScope != definitionScope) {
+ fTagDef = null;
+ fPrevDefinitionScope = definitionScope;
+ }
+ EnumDefinition tagDef = fTagDef;
+ if (tagDef == null) {
+ Definition def = definitionScope.lookupDefinition(fTag);
+ tagDef = (EnumDefinition) ((def instanceof EnumDefinition) ? def : null);
+ }
+ if (tagDef == null) {
+ throw new CTFReaderException("Tag is not defined " + fTag); //$NON-NLS-1$
+ }
+ String varFieldName = tagDef.getStringValue();
+ fDeclarationToPopulate = fFields.get(varFieldName);
+ if (fDeclarationToPopulate == null) {
+ throw new CTFReaderException("Unknown enum selector for variant " + //$NON-NLS-1$
+ definitionScope.getScopePath().toString());
+ }
+ Definition fieldValue = fDeclarationToPopulate.createDefinition(definitionScope, fieldName, input);
+ return new VariantDefinition(this, definitionScope, varFieldName, fieldName, fieldValue);
}
-
/**
* Add a field to this CTF Variant
*
* The Declaration of this new field
*/
public void addField(String fieldTag, IDeclaration declaration) {
- fields.put(fieldTag, declaration);
+ fFields.put(fieldTag, declaration);
+ }
+
+ /**
+ * gets the tag definition
+ *
+ * @return the fTagDef
+ * @since 3.0
+ */
+ public EnumDefinition getTagDef() {
+ return fTagDef;
+ }
+
+ /**
+ * @since 3.0
+ */
+ @Override
+ public int getMaximumSize() {
+ Collection<IDeclaration> values = fFields.values();
+ int maxSize = 0;
+ for (IDeclaration field : values) {
+ maxSize = Math.max(maxSize, field.getMaximumSize());
+ }
+ return maxSize;
}
@Override
package org.eclipse.linuxtools.ctf.core.event.types;
-import java.util.HashMap;
-import java.util.Map;
-
-import org.eclipse.linuxtools.ctf.core.event.io.BitBuffer;
-import org.eclipse.linuxtools.ctf.core.trace.CTFReaderException;
+import org.eclipse.jdt.annotation.NonNull;
+import org.eclipse.linuxtools.ctf.core.event.scope.IDefinitionScope;
/**
* A CTF variant definition (similar to a C union).
* @author Matthew Khouzam
* @author Simon Marchi
*/
-public class VariantDefinition extends Definition implements IDefinitionScope {
+public final class VariantDefinition extends Definition implements IDefinitionScope {
// ------------------------------------------------------------------------
// Attributes
// ------------------------------------------------------------------------
- private VariantDeclaration declaration;
-
- private EnumDefinition tagDefinition;
- private Map<String, Definition> definitions = new HashMap<>();
- private String currentField;
+ private final Definition fDefinition;
+ private final String fCurrentField;
+ private final String fFieldName;
// ------------------------------------------------------------------------
// Constructors
/**
* Constructor
- * @param declaration the parent declaration
- * @param definitionScope the parent scope
- * @param fieldName the field name
+ *
+ * @param declaration
+ * the parent declaration
+ * @param definitionScope
+ * the parent scope
+ * @param selectedField
+ * the selected field
+ * @param fieldName
+ * the field name
+ * @param fieldValue
+ * the field value
+ * @since 3.0
*/
- public VariantDefinition(VariantDeclaration declaration,
- IDefinitionScope definitionScope, String fieldName) {
- super(definitionScope, fieldName);
+ public VariantDefinition(@NonNull VariantDeclaration declaration,
+ IDefinitionScope definitionScope, String selectedField, @NonNull String fieldName, Definition fieldValue) {
+ super(declaration, definitionScope, fieldName);
- this.declaration = declaration;
+ fFieldName = fieldName;
+ fCurrentField = selectedField;
+ fDefinition = fieldValue;
- Definition tagDef = definitionScope.lookupDefinition(declaration.getTag());
- this.tagDefinition = (EnumDefinition) tagDef;
-
- for (Map.Entry<String, IDeclaration> field : declaration.getFields().entrySet()) {
- Definition fieldDef = field.getValue().createDefinition(this,
- field.getKey());
- definitions.put(field.getKey(), fieldDef);
- }
}
// ------------------------------------------------------------------------
@Override
public VariantDeclaration getDeclaration() {
- return declaration;
- }
-
- /**
- * Sets the variant declaration
- * @param declaration the variant declaration
- */
- public void setDeclaration(VariantDeclaration declaration) {
- this.declaration = declaration;
- }
-
- /**
- * Gets the tag
- * @return the tag definition
- */
- public EnumDefinition getTagDefinition() {
- return tagDefinition;
- }
-
- /**
- * Sets the tag
- * @param tagDefinition the tag
- */
- public void setTagDefinition(EnumDefinition tagDefinition) {
- this.tagDefinition = tagDefinition;
- }
-
- /**
- * Get the definitions in the variant
- * @return the definitions
- * @since 2.0
- */
- public Map<String, Definition> getDefinitions() {
- return definitions;
- }
-
- /**
- * Set the definitions in a variant
- * @param definitions the definitions
- * @since 2.0
- */
- public void setDefinitions(Map<String, Definition> definitions) {
- this.definitions = definitions;
- }
-
- /**
- * Set the current field
- * @param currentField the current field
- */
- public void setCurrentField(String currentField) {
- this.currentField = currentField;
+ return (VariantDeclaration) super.getDeclaration();
}
/**
* Get the current field name
+ *
* @return the current field name
*/
public String getCurrentFieldName() {
- return currentField;
+ return fCurrentField;
}
/**
* Get the current field
+ *
* @return the current field
*/
public Definition getCurrentField() {
- return definitions.get(currentField);
+ return fDefinition;
}
-
// ------------------------------------------------------------------------
// Operations
// ------------------------------------------------------------------------
- @Override
- public void read(BitBuffer input) throws CTFReaderException {
- currentField = tagDefinition.getValue();
-
- Definition field = definitions.get(currentField);
- if (field == null) {
- throw new CTFReaderException("Variant was not defined for: "+ currentField); //$NON-NLS-1$
- }
- field.read(input);
- }
-
@Override
public Definition lookupDefinition(String lookupPath) {
- return definitions.get(lookupPath);
+ if (lookupPath == null) {
+ return null;
+ }
+ if (lookupPath.equals(fFieldName)) {
+ return fDefinition;
+ }
+ return getDefinitionScope().lookupDefinition(lookupPath);
}
-
/**
* Lookup an array in a struct. if the name returns a non-array (like an
* int) than the method returns null
}
/**
- * Lookup a string in a struct. if the name returns a non-string (like
- * an int) than the method returns null
+ * Lookup a string in a struct. if the name returns a non-string (like an
+ * int) than the method returns null
*
* @param name
* the name of the string
}
/**
- * Lookup a struct in a struct. if the name returns a non-struct (like
- * an int) than the method returns null
+ * Lookup a struct in a struct. if the name returns a non-struct (like an
+ * int) than the method returns null
*
* @param name
* the name of the struct
}
/**
- * Lookup a variant in a struct. if the name returns a non-variant (like
- * an int) than the method returns null
+ * Lookup a variant in a struct. if the name returns a non-variant (like an
+ * int) than the method returns null
*
* @param name
* the name of the variant
import org.eclipse.linuxtools.ctf.core.event.CTFClock;
import org.eclipse.linuxtools.ctf.core.event.IEventDeclaration;
import org.eclipse.linuxtools.ctf.core.event.io.BitBuffer;
+import org.eclipse.linuxtools.ctf.core.event.scope.IDefinitionScope;
+import org.eclipse.linuxtools.ctf.core.event.scope.LexicalScope;
import org.eclipse.linuxtools.ctf.core.event.types.ArrayDefinition;
import org.eclipse.linuxtools.ctf.core.event.types.Definition;
-import org.eclipse.linuxtools.ctf.core.event.types.IDefinitionScope;
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;
*/
public class CTFTrace implements IDefinitionScope, AutoCloseable {
- @SuppressWarnings("nls")
@Override
public String toString() {
/* Only for debugging, shouldn't be externalized */
- return "CTFTrace [path=" + fPath + ", major=" + fMajor + ", minor="
- + fMinor + ", uuid=" + fUuid + "]";
+ return "CTFTrace [path=" + fPath + ", major=" + fMajor + ", minor=" //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$
+ + fMinor + ", uuid=" + fUuid + "]"; //$NON-NLS-1$ //$NON-NLS-2$
}
/**
*/
public CTFTrace() {
fPath = null;
- init();
- }
-
- private void init() {
- /* Create the definitions needed to read things from the files */
- if (fPacketHeaderDecl != null) {
- fPacketHeaderDef = fPacketHeaderDecl.createDefinition(this, "packet.header"); //$NON-NLS-1$
- }
}
private void init(File path) throws CTFReaderException {
- init();
-
/* Open all the trace files */
/* List files not called metadata and not hidden. */
* @return String the path of the trace directory, in string format.
* @see java.io.File#getPath()
*/
- @Override
public String getPath() {
return (fPath != null) ? fPath.getPath() : ""; //$NON-NLS-1$
}
+ /**
+ * @since 3.0
+ */
+ @Override
+ public LexicalScope getScopePath() {
+ return LexicalScope.TRACE;
+ }
+
// ------------------------------------------------------------------------
// Operations
// ------------------------------------------------------------------------
/* Create a BitBuffer with this mapping and the trace byte order */
streamBitBuffer = new BitBuffer(byteBuffer, this.getByteOrder());
- if (fPacketHeaderDef != null) {
+ if (fPacketHeaderDecl != null) {
/* Read the packet header */
- fPacketHeaderDef.read(streamBitBuffer);
+ fPacketHeaderDef = fPacketHeaderDecl.createDefinition(null, LexicalScope.PACKET_HEADER.getName(), streamBitBuffer);
/* Check the magic number */
- IntegerDefinition magicDef = (IntegerDefinition) fPacketHeaderDef
- .lookupDefinition("magic"); //$NON-NLS-1$
+ IntegerDefinition magicDef = (IntegerDefinition) fPacketHeaderDef.lookupDefinition("magic"); //$NON-NLS-1$
int magic = (int) magicDef.getValue();
if (magic != Utils.CTF_MAGIC) {
throw new CTFReaderException("CTF magic mismatch"); //$NON-NLS-1$
}
/* Check UUID */
- ArrayDefinition uuidDef = (ArrayDefinition) fPacketHeaderDef
- .lookupDefinition("uuid"); //$NON-NLS-1$
+ Definition lookupDefinition = fPacketHeaderDef.lookupDefinition("uuid"); //$NON-NLS-1$
+ ArrayDefinition uuidDef = (ArrayDefinition) lookupDefinition;
if (uuidDef != null) {
- byte[] uuidArray = new byte[Utils.UUID_LEN];
-
- for (int i = 0; i < Utils.UUID_LEN; i++) {
- IntegerDefinition uuidByteDef = (IntegerDefinition) uuidDef
- .getElem(i);
- uuidArray[i] = (byte) uuidByteDef.getValue();
- }
-
- UUID otheruuid = Utils.makeUUID(uuidArray);
+ UUID otheruuid = Utils.getUUIDfromDefinition(uuidDef);
if (!fUuid.equals(otheruuid)) {
throw new CTFReaderException("UUID mismatch"); //$NON-NLS-1$
* @param lookupPath
* String
* @return Definition
- * @see org.eclipse.linuxtools.ctf.core.event.types.IDefinitionScope#lookupDefinition(String)
+ * @see org.eclipse.linuxtools.ctf.core.event.scope.IDefinitionScope#lookupDefinition(String)
*/
@Override
public Definition lookupDefinition(String lookupPath) {
* @since 2.0
*/
public void addStream(Stream stream) throws ParseException {
-
- /*
- * Init if not done before
- */
- init();
-
/*
* If there is already a stream without id (the null key), it must be
* the only one
import java.nio.channels.FileChannel.MapMode;
import java.util.UUID;
+import org.eclipse.jdt.annotation.NonNull;
import org.eclipse.linuxtools.ctf.core.event.io.BitBuffer;
+import org.eclipse.linuxtools.ctf.core.event.scope.IDefinitionScope;
+import org.eclipse.linuxtools.ctf.core.event.scope.LexicalScope;
import org.eclipse.linuxtools.ctf.core.event.types.ArrayDefinition;
import org.eclipse.linuxtools.ctf.core.event.types.Definition;
import org.eclipse.linuxtools.ctf.core.event.types.EnumDefinition;
import org.eclipse.linuxtools.ctf.core.event.types.FloatDefinition;
-import org.eclipse.linuxtools.ctf.core.event.types.IDefinitionScope;
import org.eclipse.linuxtools.ctf.core.event.types.IntegerDefinition;
import org.eclipse.linuxtools.ctf.core.event.types.StringDefinition;
+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.trace.StreamInputPacketIndex;
import org.eclipse.linuxtools.internal.ctf.core.trace.StreamInputPacketIndexEntry;
/*
* Definition of trace packet header
*/
- private StructDefinition fTracePacketHeaderDef = null;
+ private StructDeclaration fTracePacketHeaderDecl = null;
/*
* Definition of trace stream packet context
*/
- private StructDefinition fStreamPacketContextDef = null;
+ private StructDeclaration fStreamPacketContextDecl = null;
/*
* Total number of lost events in this stream
/**
* Useless for streaminputs
+ *
+ * @since 3.0
*/
@Override
- public String getPath() {
- return ""; //$NON-NLS-1$
+ public LexicalScope getScopePath() {
+ return LexicalScope.STREAM;
}
// ------------------------------------------------------------------------
* Create the definitions we need to read the packet headers + contexts
*/
if (getStream().getTrace().getPacketHeader() != null) {
- fTracePacketHeaderDef = getStream().getTrace().getPacketHeader()
- .createDefinition(this, "trace.packet.header"); //$NON-NLS-1$
+ fTracePacketHeaderDecl = getStream().getTrace().getPacketHeader();
}
if (getStream().getPacketContextDecl() != null) {
- fStreamPacketContextDef = getStream().getPacketContextDecl()
- .createDefinition(this, "stream.packet.context"); //$NON-NLS-1$
+ fStreamPacketContextDecl = getStream().getPacketContextDecl();
}
}
StreamInputPacketIndexEntry packetIndex = new StreamInputPacketIndexEntry(
currentPos);
createPacketIndexEntry(fileSize, currentPos, packetIndex,
- fTracePacketHeaderDef, fStreamPacketContextDef, bitBuffer);
+ fTracePacketHeaderDecl, fStreamPacketContextDecl, bitBuffer);
fIndex.addEntry(packetIndex);
return true;
}
private long createPacketIndexEntry(long fileSizeBytes,
long packetOffsetBytes, StreamInputPacketIndexEntry packetIndex,
- StructDefinition tracePacketHeaderDef,
- StructDefinition streamPacketContextDef, BitBuffer bitBuffer)
+ StructDeclaration tracePacketHeaderDecl,
+ StructDeclaration streamPacketContextDecl, @NonNull BitBuffer bitBuffer)
throws CTFReaderException {
/*
/*
* Read the trace packet header if it exists.
*/
- if (tracePacketHeaderDef != null) {
- parseTracePacketHeader(tracePacketHeaderDef, bitBuffer);
+ if (tracePacketHeaderDecl != null) {
+ parseTracePacketHeader(tracePacketHeaderDecl, bitBuffer);
}
/*
* Read the stream packet context if it exists.
*/
- if (streamPacketContextDef != null) {
- parsePacketContext(fileSizeBytes, streamPacketContextDef,
+ if (streamPacketContextDecl != null) {
+ parsePacketContext(fileSizeBytes, streamPacketContextDecl,
bitBuffer, packetIndex);
} else {
setPacketContextNull(fileSizeBytes, packetIndex);
return bb;
}
- private void parseTracePacketHeader(StructDefinition tracePacketHeaderDef,
- BitBuffer bitBuffer) throws CTFReaderException {
- tracePacketHeaderDef.read(bitBuffer);
+ private void parseTracePacketHeader(StructDeclaration tracePacketHeaderDecl,
+ @NonNull BitBuffer bitBuffer) throws CTFReaderException {
+ StructDefinition tracePacketHeaderDef = tracePacketHeaderDecl.createDefinition(null, LexicalScope.TRACE_PACKET_HEADER.getName(), bitBuffer);
/*
* Check the CTF magic number
ArrayDefinition uuidDef =
(ArrayDefinition) tracePacketHeaderDef.lookupDefinition("uuid"); //$NON-NLS-1$
if (uuidDef != null) {
- byte[] uuidArray = new byte[16];
-
- for (int i = 0; i < uuidArray.length; i++) {
- IntegerDefinition uuidByteDef = (IntegerDefinition) uuidDef.getElem(i);
- uuidArray[i] = (byte) uuidByteDef.getValue();
- }
-
- UUID uuid = Utils.makeUUID(uuidArray);
+ UUID uuid = Utils.getUUIDfromDefinition(uuidDef);
if (!getStream().getTrace().getUUID().equals(uuid)) {
throw new CTFReaderException("UUID mismatch"); //$NON-NLS-1$
}
private void parsePacketContext(long fileSizeBytes,
- StructDefinition streamPacketContextDef, BitBuffer bitBuffer,
+ StructDeclaration streamPacketContextDecl, @NonNull BitBuffer bitBuffer,
StreamInputPacketIndexEntry packetIndex) throws CTFReaderException {
- streamPacketContextDef.read(bitBuffer);
+ StructDefinition streamPacketContextDef = streamPacketContextDecl.createDefinition(null, LexicalScope.STREAM_PACKET_CONTEXT.getName(), bitBuffer);
for (String field : streamPacketContextDef.getDeclaration()
.getFieldsList()) {
packetIndex.setContentSizeBits((int) (fileSizeBytes * 8));
}
-
/* Read the packet size in bits */
if (packetSize != null) {
packetIndex.setPacketSizeBits(packetSize.intValue());
packetIndex.setPacketSizeBits((int) (fileSizeBytes * 8));
}
-
/* Read the begin timestamp */
if (tsBegin != null) {
packetIndex.setTimestampBegin(tsBegin.longValue());
import java.io.IOException;
import java.nio.ByteBuffer;
+import org.eclipse.jdt.annotation.NonNull;
import org.eclipse.linuxtools.ctf.core.CTFStrings;
import org.eclipse.linuxtools.ctf.core.event.EventDefinition;
+import org.eclipse.linuxtools.ctf.core.event.IEventDeclaration;
import org.eclipse.linuxtools.ctf.core.event.io.BitBuffer;
+import org.eclipse.linuxtools.ctf.core.event.scope.IDefinitionScope;
+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.IDefinitionScope;
+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.SimpleDatatypeDefinition;
import org.eclipse.linuxtools.ctf.core.event.types.StructDeclaration;
import org.eclipse.linuxtools.internal.ctf.core.event.EventDeclaration;
import org.eclipse.linuxtools.internal.ctf.core.trace.StreamInputPacketIndexEntry;
+import com.google.common.collect.ImmutableList;
+
/**
* CTF trace packet reader. Reads the events of a packet of a trace file.
*
// ------------------------------------------------------------------------
/** BitBuffer used to read the trace file. */
+ @NonNull
private final BitBuffer fBitBuffer;
/** StreamInputReader that uses this StreamInputPacketReader. */
private final StreamInputReader fStreamInputReader;
/** Trace packet header. */
- private final StructDefinition fTracePacketHeaderDef;
+ private final StructDeclaration fTracePacketHeaderDecl;
/** Stream packet context definition. */
- private final StructDefinition fStreamPacketContextDef;
+ private final StructDeclaration fStreamPacketContextDecl;
/** Stream event header definition. */
- private final StructDefinition fStreamEventHeaderDef;
+ private final StructDeclaration fStreamEventHeaderDecl;
/** Stream event context definition. */
- private final StructDefinition fStreamEventContextDef;
+ private final StructDeclaration fStreamEventContextDecl;
+ private StructDefinition fCurrentTracePacketHeaderDef;
+ private StructDefinition fCurrentStreamEventHeaderDef;
+ private Definition fCurrentStreamPacketContextDef;
/** Reference to the index entry of the current packet. */
private StreamInputPacketIndexEntry fCurrentPacket = null;
fBitBuffer = new BitBuffer();
fBitBuffer.setByteOrder(streamInputReader.getByteOrder());
- /* Create trace packet header definition. */
final Stream currentStream = streamInputReader.getStreamInput().getStream();
- StructDeclaration tracePacketHeaderDecl = currentStream.getTrace().getPacketHeader();
- if (tracePacketHeaderDecl != null) {
- fTracePacketHeaderDef = tracePacketHeaderDecl.createDefinition(this, "trace.packet.header"); //$NON-NLS-1$
- } else {
- fTracePacketHeaderDef = null;
- }
+ fTracePacketHeaderDecl = currentStream.getTrace().getPacketHeader();
+ fStreamPacketContextDecl = currentStream.getPacketContextDecl();
+ fStreamEventHeaderDecl = currentStream.getEventHeaderDecl();
+ fStreamEventContextDecl = currentStream.getEventContextDecl();
+ }
- /* Create stream packet context definition. */
- StructDeclaration streamPacketContextDecl = currentStream.getPacketContextDecl();
- if (streamPacketContextDecl != null) {
- fStreamPacketContextDef = streamPacketContextDecl.createDefinition(this, "stream.packet.context"); //$NON-NLS-1$
- } else {
- fStreamPacketContextDef = null;
- }
+ /**
+ * Get the event context defintiion
+ *
+ * @param input
+ * the bitbuffer to read from
+ * @return an context definition, can be null
+ * @throws CTFReaderException
+ * out of bounds exception or such
+ * @since 3.0
+ */
+ public StructDefinition getEventContextDefinition(@NonNull BitBuffer input) throws CTFReaderException {
+ return fStreamEventContextDecl.createDefinition(this, LexicalScope.STREAM_EVENT_CONTEXT.getName(), input);
+ }
- /* Create stream event header definition. */
- StructDeclaration streamEventHeaderDecl = currentStream.getEventHeaderDecl();
- if (streamEventHeaderDecl != null) {
- fStreamEventHeaderDef = streamEventHeaderDecl.createDefinition(this, "stream.event.header"); //$NON-NLS-1$
- } else {
- fStreamEventHeaderDef = null;
- }
+ /**
+ * Get the stream context defintiion
+ *
+ * @param input
+ * the bitbuffer to read from
+ * @return an context definition, can be null
+ * @throws CTFReaderException
+ * out of bounds exception or such
+ * @since 3.0
+ */
+ public StructDefinition getStreamEventHeaderDefinition(@NonNull BitBuffer input) throws CTFReaderException {
+ return fStreamEventHeaderDecl.createDefinition(this, LexicalScope.STREAM_EVENT_HEADER.getName(), input);
+ }
- /* Create stream event context definition. */
- StructDeclaration streamEventContextDecl = currentStream.getEventContextDecl();
- if (streamEventContextDecl != null) {
- fStreamEventContextDef = streamEventContextDecl.createDefinition(this, "stream.event.context"); //$NON-NLS-1$
- } else {
- fStreamEventContextDef = null;
- }
+ /**
+ * Get the packet context defintiion
+ *
+ * @param input
+ * the bitbuffer to read from
+ * @return an context definition, can be null
+ * @throws CTFReaderException
+ * out of bounds exception or such
+ * @since 3.0
+ */
+ public StructDefinition getStreamPacketContextDefinition(@NonNull BitBuffer input) throws CTFReaderException {
+ return fStreamPacketContextDecl.createDefinition(this, LexicalScope.STREAM_PACKET_CONTEXT.getName(), input);
+ }
+ /**
+ * Get the event header defintiion
+ *
+ * @param input
+ * the bitbuffer to read from
+ * @return an header definition, can be null
+ * @throws CTFReaderException
+ * out of bounds exception or such
+ * @since 3.0
+ */
+ public StructDefinition getTracePacketHeaderDefinition(@NonNull BitBuffer input) throws CTFReaderException {
+ return fTracePacketHeaderDecl.createDefinition(this, LexicalScope.TRACE_PACKET_HEADER.getName(), input);
}
/**
return fCurrentPacket;
}
- /**
- * Gets the steamPacketContext Definition
- *
- * @return steamPacketContext Definition
- */
- public StructDefinition getStreamPacketContextDef() {
- return fStreamPacketContextDef;
- }
-
- /**
- * Gets the stream's event context definition.
- *
- * @return The streamEventContext definition
- */
- public StructDefinition getStreamEventContextDef() {
- return fStreamEventContextDef;
- }
-
/**
* Gets the CPU (core) number
*
return fCurrentCpu;
}
+ /**
+ * @since 3.0
+ */
@Override
- public String getPath() {
- return ""; //$NON-NLS-1$
+ public LexicalScope getScopePath() {
+ return LexicalScope.PACKET;
}
// ------------------------------------------------------------------------
ByteBuffer bb = null;
try {
bb = fStreamInputReader.getStreamInput().getByteBufferAt(
- fCurrentPacket.getOffsetBytes(),
- (fCurrentPacket.getPacketSizeBits() + 7) / 8);
+ fCurrentPacket.getOffsetBytes(),
+ (fCurrentPacket.getPacketSizeBits() + 7) / 8);
} catch (IOException e) {
throw new CTFReaderException(e.getMessage(), e);
}
/*
* Read trace packet header.
*/
- if (fTracePacketHeaderDef != null) {
- fTracePacketHeaderDef.read(fBitBuffer);
+ if (fTracePacketHeaderDecl != null) {
+ fCurrentTracePacketHeaderDef = getTracePacketHeaderDefinition(fBitBuffer);
}
/*
* Read stream packet context.
*/
- if (getStreamPacketContextDef() != null) {
- getStreamPacketContextDef().read(fBitBuffer);
+ if (fStreamPacketContextDecl != null) {
+ fCurrentStreamPacketContextDef = getStreamPacketContextDefinition(fBitBuffer);
/* Read CPU ID */
if (getCurrentPacket().getTarget() != null) {
long timestamp = 0;
if (fHasLost) {
fHasLost = false;
- EventDefinition eventDef = EventDeclaration.getLostEventDeclaration().createDefinition(fStreamInputReader);
- ((IntegerDefinition) eventDef.getFields().getDefinitions().get(CTFStrings.LOST_EVENTS_FIELD)).setValue(fLostEventsInThisPacket);
- ((IntegerDefinition) eventDef.getFields().getDefinitions().get(CTFStrings.LOST_EVENTS_DURATION)).setValue(fLostEventsDuration);
- eventDef.setTimestamp(fLastTimestamp);
- return eventDef;
+ EventDeclaration lostEventDeclaration = EventDeclaration.getLostEventDeclaration();
+ StructDeclaration lostFields = lostEventDeclaration.getFields();
+ // this is a hard coded map, we know it's not null
+ IntegerDeclaration lostFieldsDecl = (IntegerDeclaration) lostFields.getFields().get(CTFStrings.LOST_EVENTS_FIELD);
+ if (lostFieldsDecl == null)
+ {
+ throw new IllegalStateException("Lost events count not declared!"); //$NON-NLS-1$
+ }
+ IntegerDeclaration lostEventsDurationDecl = (IntegerDeclaration) lostFields.getFields().get(CTFStrings.LOST_EVENTS_DURATION);
+ if (lostEventsDurationDecl == null) {
+ throw new IllegalStateException("Lost events duration not declared!"); //$NON-NLS-1$
+ }
+ IntegerDefinition lostDurationDef = new IntegerDefinition(lostFieldsDecl, null, CTFStrings.LOST_EVENTS_DURATION, fLostEventsDuration);
+ IntegerDefinition lostCountDef = new IntegerDefinition(lostEventsDurationDecl, null, CTFStrings.LOST_EVENTS_FIELD, fLostEventsInThisPacket);
+ IntegerDefinition[] fields = new IntegerDefinition[] { lostCountDef, lostDurationDef };
+ /* this is weird notation, but it's the java notation */
+ final ImmutableList<String> fieldNameList = ImmutableList.<String> builder().add(CTFStrings.LOST_EVENTS_FIELD).add(CTFStrings.LOST_EVENTS_DURATION).build();
+ return new EventDefinition(
+ lostEventDeclaration,
+ fStreamInputReader,
+ fLastTimestamp,
+ null,
+ null,
+ null,
+ new StructDefinition(
+ lostFields,
+ this, "fields", //$NON-NLS-1$
+ fieldNameList,
+ fields
+ ));
+
}
- final StructDefinition sehd = fStreamEventHeaderDef;
final BitBuffer currentBitBuffer = fBitBuffer;
final long posStart = currentBitBuffer.position();
/* Read the stream event header. */
- if (sehd != null) {
- sehd.read(currentBitBuffer);
+ if (fStreamEventHeaderDecl != null) {
+ fCurrentStreamEventHeaderDef = getStreamEventHeaderDefinition(currentBitBuffer);
/* Check for the event id. */
- Definition idDef = sehd.lookupDefinition("id"); //$NON-NLS-1$
+ Definition idDef = fCurrentStreamEventHeaderDef.lookupDefinition("id"); //$NON-NLS-1$
if (idDef instanceof SimpleDatatypeDefinition) {
eventID = ((SimpleDatatypeDefinition) idDef).getIntegerValue();
} else if (idDef != null) {
* Get the timestamp from the event header (may be overridden later
* on)
*/
- IntegerDefinition timestampDef = sehd.lookupInteger("timestamp"); //$NON-NLS-1$
+ IntegerDefinition timestampDef = fCurrentStreamEventHeaderDef.lookupInteger("timestamp"); //$NON-NLS-1$
if (timestampDef != null) {
timestamp = calculateTimestamp(timestampDef);
} // else timestamp remains 0
/* Check for the variant v. */
- Definition variantDef = sehd.lookupDefinition("v"); //$NON-NLS-1$
+ Definition variantDef = fCurrentStreamEventHeaderDef.lookupDefinition("v"); //$NON-NLS-1$
if (variantDef instanceof VariantDefinition) {
/* Get the variant current field */
}
}
- /* Read the stream event context. */
- if (fStreamEventContextDef != null) {
- fStreamEventContextDef.read(currentBitBuffer);
- }
-
/* Get the right event definition using the event id. */
- EventDefinition eventDef = fStreamInputReader.getStreamInput().getStream().getEvents().get(eventID).createDefinition(fStreamInputReader);
- if (eventDef == null) {
+ IEventDeclaration eventDeclaration = fStreamInputReader.getStreamInput().getStream().getEvents().get(eventID);
+ if (eventDeclaration == null) {
throw new CTFReaderException("Incorrect event id : " + eventID); //$NON-NLS-1$
}
-
- /* Read the event context. */
- if (eventDef.getEventContext() != null) {
- eventDef.getEventContext().read(currentBitBuffer);
- }
-
- /* Read the event fields. */
- if (eventDef.getFields() != null) {
- eventDef.getFields().read(currentBitBuffer);
- }
+ EventDefinition eventDef = eventDeclaration.createDefinition(fStreamInputReader, fBitBuffer, timestamp);
/*
* Set the event timestamp using the timestamp calculated by
* updateTimestamp.
*/
- eventDef.setTimestamp(timestamp);
if (posStart == currentBitBuffer.position()) {
throw new CTFReaderException("Empty event not allowed, event: " + eventDef.getDeclaration().getName()); //$NON-NLS-1$
@Override
public Definition lookupDefinition(String lookupPath) {
+ if (lookupPath.equals(LexicalScope.STREAM_PACKET_CONTEXT)) {
+ return fCurrentStreamPacketContextDef;
+ }
+ if (lookupPath.equals(LexicalScope.TRACE_PACKET_HEADER)) {
+ return fCurrentTracePacketHeaderDef;
+ }
return null;
}
+
+ /**
+ * Get stream event header
+ *
+ * @return the stream event header
+ * @since 3.0
+ */
+ public StructDefinition getCurrentStreamEventHeader() {
+ return fCurrentStreamEventHeaderDef;
+ }
+
+ /**
+ * Get the current packet event header
+ *
+ * @return the current packet event header
+ * @since 3.0
+ */
+ public StructDefinition getCurrentPacketEventHeader() {
+ return fCurrentTracePacketHeaderDef;
+ }
}
import java.nio.ByteOrder;
import org.eclipse.linuxtools.ctf.core.event.EventDefinition;
-import org.eclipse.linuxtools.ctf.core.event.types.StructDefinition;
+import org.eclipse.linuxtools.ctf.core.event.types.StructDeclaration;
import org.eclipse.linuxtools.internal.ctf.core.trace.StreamInputPacketIndexEntry;
/**
return fCurrentEvent;
}
- /**
- * Gets the current packet context
- *
- * @return the current packet context (size, lost events and such)
- */
- public StructDefinition getCurrentPacketContext() {
- return fPacketReader.getStreamPacketContextDef();
- }
-
/**
* Gets the byte order for a trace
*
return fLive;
}
+ /**
+ * Get the event context of the stream
+ *
+ * @return the event context declaration of the stream
+ * @since 3.0
+ */
+ public StructDeclaration getStreamEventContextDecl() {
+ return getStreamInput().getStream().getEventContextDecl();
+ }
+
// ------------------------------------------------------------------------
// Operations
// ------------------------------------------------------------------------
if (!fPacketReader.hasMoreEvents()) {
final StreamInputPacketIndexEntry prevPacket = fPacketReader
.getCurrentPacket();
- if (prevPacket != null || fLive ) {
+ if (prevPacket != null || fLive) {
goToNextPacket();
}
import java.util.UUID;
+import org.eclipse.linuxtools.ctf.core.event.types.ArrayDefinition;
+import org.eclipse.linuxtools.ctf.core.event.types.IntegerDefinition;
+
/**
* Various utilities.
*
* @author Matthew Khouzam
* @author Simon Marchi
*/
-public class Utils {
+public final class Utils {
- private Utils() {}
+ private Utils() {
+ }
// ------------------------------------------------------------------------
// Constants
*/
public static int unsignedCompare(long left, long right) {
/*
- * This method assumes that the arithmetic overflow on signed
- * integer wrap on a circular domain (modulo arithmetic in
- * two-complement), which is the defined behavior in Java.
+ * This method assumes that the arithmetic overflow on signed integer
+ * wrap on a circular domain (modulo arithmetic in two-complement),
+ * which is the defined behavior in Java.
*
* This idea is to rotate the domain by the length of the negative
* space, and then use the signed operator.
return 0;
}
+ /**
+ * Gets a UUID from an array defintion
+ *
+ * @param uuidDef
+ * the array defintions, must contain integer bytes
+ * @return the UUID
+ * @throws CTFReaderException
+ * if the definition contains less than 16 elements
+ * @since 3.0
+ */
+ public static UUID getUUIDfromDefinition(ArrayDefinition uuidDef) throws CTFReaderException {
+ byte[] uuidArray = new byte[16];
+
+ for (int i = 0; i < uuidArray.length; i++) {
+ IntegerDefinition uuidByteDef = (IntegerDefinition) uuidDef.getElem(i);
+ if (uuidByteDef == null) {
+ throw new CTFReaderException("UUID incomplete, only " + i + " bytes available"); //$NON-NLS-1$ //$NON-NLS-2$
+ }
+ uuidArray[i] = (byte) uuidByteDef.getValue();
+ }
+
+ UUID uuid = Utils.makeUUID(uuidArray);
+ return uuid;
+ }
+
/**
* Creates a UUID object from an array of 16 bytes.
*
package org.eclipse.linuxtools.internal.ctf.core.event;
-import java.nio.ByteOrder;
import java.util.HashMap;
import java.util.Map;
import java.util.Set;
+import org.eclipse.jdt.annotation.NonNull;
import org.eclipse.linuxtools.ctf.core.CTFStrings;
import org.eclipse.linuxtools.ctf.core.event.EventDefinition;
import org.eclipse.linuxtools.ctf.core.event.IEventDeclaration;
-import org.eclipse.linuxtools.ctf.core.event.types.Encoding;
+import org.eclipse.linuxtools.ctf.core.event.io.BitBuffer;
+import org.eclipse.linuxtools.ctf.core.event.scope.LexicalScope;
+import org.eclipse.linuxtools.ctf.core.event.types.Declaration;
import org.eclipse.linuxtools.ctf.core.event.types.IntegerDeclaration;
import org.eclipse.linuxtools.ctf.core.event.types.StructDeclaration;
+import org.eclipse.linuxtools.ctf.core.event.types.StructDefinition;
+import org.eclipse.linuxtools.ctf.core.trace.CTFReaderException;
import org.eclipse.linuxtools.ctf.core.trace.Stream;
import org.eclipse.linuxtools.ctf.core.trace.StreamInputReader;
*/
public class EventDeclaration implements IEventDeclaration {
+ @NonNull private static final String FIELDS = "fields"; //$NON-NLS-1$
+
+ @NonNull private static final String CONTEXT = "context"; //$NON-NLS-1$
+
/** Id of lost events */
public static final long LOST_EVENT_ID = -1L;
}
@Override
- public EventDefinition createDefinition(StreamInputReader streamInputReader) {
- EventDefinition event = new EventDefinition(this, streamInputReader);
-
- if (fContext != null) {
- event.setContext(fContext.createDefinition(event, "context")); //$NON-NLS-1$
- }
-
- if (fFields != null) {
- event.setFields(fFields.createDefinition(event, "fields")); //$NON-NLS-1$
- }
-
- return event;
+ public EventDefinition createDefinition(StreamInputReader streamInputReader, @NonNull BitBuffer input, long timestamp) throws CTFReaderException {
+ StructDeclaration streamEventContextDecl = streamInputReader.getStreamEventContextDecl();
+ StructDefinition streamEventContext = streamEventContextDecl != null ? streamEventContextDecl.createDefinition(null, LexicalScope.STREAM_EVENT_CONTEXT.toString(), input) : null;
+ StructDefinition packetContext = streamInputReader.getPacketReader().getCurrentPacketEventHeader();
+ StructDefinition eventContext = fContext != null ? fContext.createDefinition(null, CONTEXT, input) : null;
+ StructDefinition eventPayload = fFields != null ? fFields.createDefinition(null, FIELDS, input) : null;
+
+ // a bit lttng specific
+ // CTF doesn't require a timestamp,
+ // but it's passed to us
+ return new EventDefinition(
+ this,
+ streamInputReader,
+ timestamp,
+ streamEventContext,
+ eventContext,
+ packetContext,
+ eventPayload);
}
/**
*/
public static synchronized EventDeclaration getLostEventDeclaration() {
EventDeclaration lostEvent = new EventDeclaration();
- IntegerDeclaration lostEventsDeclaration = new IntegerDeclaration(32, false, 10, ByteOrder.BIG_ENDIAN, Encoding.ASCII, null, 8);
- IntegerDeclaration timestampDeclaration = new IntegerDeclaration(64, false, 10, ByteOrder.BIG_ENDIAN, Encoding.ASCII, null, 8);
-
- lostEvent.fFields = new StructDeclaration(1);
- lostEvent.fFields.addField(CTFStrings.LOST_EVENTS_FIELD, lostEventsDeclaration);
- lostEvent.fFields.addField(CTFStrings.LOST_EVENTS_DURATION, timestampDeclaration);
+ String[] fieldNames = new String[] { CTFStrings.LOST_EVENTS_FIELD, CTFStrings.LOST_EVENTS_DURATION };
+ Declaration[] fieldDeclarations = new Declaration[] { IntegerDeclaration.UINT_32B_DECL, IntegerDeclaration.UINT_64B_DECL };
+ lostEvent.fFields = new StructDeclaration(fieldNames, fieldDeclarations);
lostEvent.fId = LOST_EVENT_ID;
lostEvent.fName = CTFStrings.LOST_EVENT_NAME;
-
return lostEvent;
}
import org.antlr.runtime.tree.CommonTree;
import org.eclipse.core.runtime.IStatus;
+import org.eclipse.jdt.annotation.NonNull;
import org.eclipse.linuxtools.ctf.core.event.CTFClock;
import org.eclipse.linuxtools.ctf.core.event.types.ArrayDeclaration;
import org.eclipse.linuxtools.ctf.core.event.types.Encoding;
final DeclarationScope parentScope, String name,
IntegerDeclaration decl) throws ParseException {
- if (decl.getByteOrder() == null) {
+ if (decl.getByteOrder() != byteOrder) {
IntegerDeclaration newI;
- newI = new IntegerDeclaration(decl.getLength(), decl.isSigned(),
+ newI = IntegerDeclaration.createDeclaration(decl.getLength(), decl.isSigned(),
decl.getBase(), byteOrder, decl.getEncoding(),
decl.getClock(), decl.getAlignment());
parentScope.replaceType(name, newI);
} else if (d instanceof IntegerDeclaration) {
IntegerDeclaration decl = (IntegerDeclaration) d;
- if (decl.getByteOrder() == null) {
+ if (decl.getByteOrder() != byteOrder) {
IntegerDeclaration newI;
- newI = new IntegerDeclaration(decl.getLength(),
+ newI = IntegerDeclaration.createDeclaration(decl.getLength(),
decl.isSigned(), decl.getBase(), byteOrder,
decl.getEncoding(), decl.getClock(),
decl.getAlignment());
} else if (d instanceof IntegerDeclaration) {
IntegerDeclaration decl = (IntegerDeclaration) d;
IntegerDeclaration newI;
- newI = new IntegerDeclaration(decl.getLength(),
+ newI = IntegerDeclaration.createDeclaration(decl.getLength(),
decl.isSigned(), decl.getBase(), byteOrder,
decl.getEncoding(), decl.getClock(),
decl.getAlignment());
long size = 0;
long alignment = 0;
int base = 10;
- String clock = null;
+ @NonNull
+ String clock = ""; //$NON-NLS-1$
Encoding encoding = Encoding.NONE;
}
}
- integerDeclaration = new IntegerDeclaration((int) size, signed, base,
+ integerDeclaration = IntegerDeclaration.createDeclaration((int) size, signed, base,
byteOrder, encoding, clock, alignment);
return integerDeclaration;
}
+ @NonNull
private static String getClock(CommonTree rightNode) {
- return rightNode.getChild(1).getChild(0).getChild(0).getText();
+ String clock = rightNode.getChild(1).getChild(0).getChild(0).getText();
+ return clock == null ? "" : clock; //$NON-NLS-1$
}
private static StringDeclaration parseString(CommonTree string)
* @return The "encoding" value.
* @throws ParseException
*/
+ @NonNull
private static Encoding getEncoding(CommonTree rightNode)
throws ParseException {
/**
* The generic event structure in TMF. In its canonical form, an event has:
* <ul>
- * <li> a parent trace
- * <li> a rank (order within the trace)
- * <li> a timestamp
- * <li> a source (reporting component)
- * <li> a type
- * <li> a content (payload)
+ * <li>a parent trace
+ * <li>a rank (order within the trace)
+ * <li>a timestamp
+ * <li>a source (reporting component)
+ * <li>a type
+ * <li>a content (payload)
* </ul>
* For convenience, a free-form reference field is also provided. It could be
* used as e.g. a location marker (filename:lineno) to indicate where the event
import org.eclipse.linuxtools.ctf.core.event.io.BitBuffer;
import org.eclipse.linuxtools.ctf.core.event.types.ArrayDeclaration;
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.EnumDeclaration;
import org.eclipse.linuxtools.ctf.core.event.types.FloatDeclaration;
import org.eclipse.linuxtools.ctf.core.event.types.FloatDefinition;
* The class <code>CtfTmfEventFieldTest</code> contains tests for the class
* <code>{@link CtfTmfEventField}</code>.
*
- * @author ematkho
+ * @author Matthew Khouzam
* @version 1.0
*/
public class CtfTmfEventFieldTest {
StructDeclaration sDec = new StructDeclaration(1l);
StringDeclaration strDec = new StringDeclaration();
- IntegerDeclaration intDec = new IntegerDeclaration(8, false, 8,
- ByteOrder.BIG_ENDIAN, Encoding.NONE, null, 8);
+ IntegerDeclaration intDec = IntegerDeclaration.UINT_8_DECL;
FloatDeclaration flDec = new FloatDeclaration(8, 24,
ByteOrder.BIG_ENDIAN, 8);
SequenceDeclaration seqDec = new SequenceDeclaration(LEN, intDec);
bb.putFloat(TEST_NUMBER);
}
- fixture = sDec.createDefinition(fixture, ROOT);
+ fixture = sDec.createDefinition(fixture, ROOT, new BitBuffer(bb));
- bb.position(0);
- fixture.read(new BitBuffer(bb));
}
/**
public void testParseField_int() {
Definition fieldDef = fixture.lookupDefinition(INT);
CtfTmfEventField result = CtfTmfEventField.parseField(fieldDef, NAME);
- assertEquals("test=02", result.toString());
+ assertEquals("test=2", result.toString());
}
/**
public void testParseField_array_int() {
Definition fieldDef = fixture.lookupArray(ARRAY_INT);
CtfTmfEventField result = CtfTmfEventField.parseField(fieldDef, NAME);
- assertEquals("test=[02, 02]", result.toString());
+ assertEquals("test=[2, 2]", result.toString());
}
/**
public void testParseField_sequence() {
Definition fieldDef = fixture.lookupDefinition(SEQ);
CtfTmfEventField result = CtfTmfEventField.parseField(fieldDef, NAME);
- assertEquals("test=[02, 02]", result.toString());
+ assertEquals("test=[2, 2]", result.toString());
}
/**
public void testParseField_struct() {
Definition fieldDef = fixture.lookupDefinition(STRUCT);
CtfTmfEventField result = CtfTmfEventField.parseField(fieldDef, NAME);
- assertEquals("test=[str=two, int=02]", result.toString());
+ assertEquals("test=[str=two, int=2]", result.toString());
}
/**
public void testParseField_array_struct() {
Definition fieldDef = fixture.lookupArray(ARRAY_STRUCT);
CtfTmfEventField result = CtfTmfEventField.parseField(fieldDef, NAME);
- assertEquals("test=[[str=two, int=02], [str=two, int=02]]", result.toString());
+ assertEquals("test=[[str=two, int=2], [str=two, int=2]]", result.toString());
}
/**
/**
* Perform pre-test initialization.
- * @throws CTFReaderException error
+ *
+ * @throws CTFReaderException
+ * error
*/
@Before
public void setUp() throws CTFReaderException {
assertNotNull(nullEvent);
assertEquals(-1, nullEvent.getCPU());
assertEquals("Empty CTF event", nullEvent.getType().getName());
- assertEquals("No stream", nullEvent.getReference());
+ assertNull(nullEvent.getReference());
assertArrayEquals(new ITmfEventField[0], nullEvent.getContent().getFields());
assertEquals(-1L, nullEvent.getID());
assertEquals(-1L, nullEvent.getTimestamp().getValue());
package org.eclipse.linuxtools.tmf.ctf.core;
+import java.util.ArrayList;
import java.util.HashSet;
+import java.util.List;
import java.util.Set;
+import org.eclipse.jdt.annotation.NonNull;
import org.eclipse.linuxtools.ctf.core.event.CTFCallsite;
+import org.eclipse.linuxtools.ctf.core.event.EventDefinition;
import org.eclipse.linuxtools.ctf.core.event.IEventDeclaration;
+import org.eclipse.linuxtools.ctf.core.event.types.StructDefinition;
import org.eclipse.linuxtools.ctf.core.trace.CTFTrace;
import org.eclipse.linuxtools.tmf.core.event.ITmfCustomAttributes;
import org.eclipse.linuxtools.tmf.core.event.ITmfEventField;
// Constants
// ------------------------------------------------------------------------
- static final String NO_STREAM = "No stream"; //$NON-NLS-1$
private static final String EMPTY_CTF_EVENT_NAME = "Empty CTF event"; //$NON-NLS-1$
// ------------------------------------------------------------------------
private final int fSourceCPU;
private final long fTypeId;
private final String fEventName;
- private final IEventDeclaration fDeclaration;
+ private final IEventDeclaration fEventDeclaration;
+ @NonNull
+ private final EventDefinition fEvent;
+ private ITmfEventField fContent;
// ------------------------------------------------------------------------
// Constructors
* Constructor used by {@link CtfTmfEventFactory#createEvent}
*/
CtfTmfEvent(CtfTmfTrace trace, long rank, CtfTmfTimestamp timestamp,
- ITmfEventField content, String fileName, int cpu,
- IEventDeclaration declaration) {
+ String fileName, int cpu, IEventDeclaration declaration, @NonNull EventDefinition eventDefinition) {
super(trace,
rank,
timestamp,
String.valueOf(cpu), // Source
- null, // Event type. We don't use TmfEvent's field here, we re-implement getType()
- content,
+ null, // Event type. We don't use TmfEvent's field here, we
+ // re-implement getType()
+ null, // Content handled with a lazy loaded re-implemented in
+ // getContent()
fileName // Reference
);
- fDeclaration = declaration;
+ fEventDeclaration = declaration;
fSourceCPU = cpu;
fTypeId = declaration.getId();
fEventName = declaration.getName();
+ fEvent = eventDefinition;
}
null,
null,
new TmfEventField("", null, new CtfTmfEventField[0]), //$NON-NLS-1$
- NO_STREAM);
+ null);
fSourceCPU = -1;
fTypeId = -1;
fEventName = EMPTY_CTF_EVENT_NAME;
- fDeclaration = null;
+ fEventDeclaration = null;
+ fEvent = EventDefinition.NULL_EVENT;
}
// ------------------------------------------------------------------------
*/
@Override
public Set<String> listCustomAttributes() {
- if (fDeclaration == null) {
+ if (fEventDeclaration == null) {
return new HashSet<>();
}
- return fDeclaration.getCustomAttributes();
+ return fEventDeclaration.getCustomAttributes();
}
/**
*/
@Override
public String getCustomAttribute(String name) {
- if (fDeclaration == null) {
+ if (fEventDeclaration == null) {
return null;
}
- return fDeclaration.getCustomAttribute(name);
+ return fEventDeclaration.getCustomAttribute(name);
}
/**
return getCustomAttribute(CtfConstants.MODEL_URI_KEY);
}
+ @Override
+ public synchronized ITmfEventField getContent() {
+ if (fContent == null) {
+ fContent = new TmfEventField(
+ ITmfEventField.ROOT_FIELD_ID, null, parseFields(fEvent));
+ }
+ return fContent;
+ }
+
+ /**
+ * Extract the field information from the structDefinition haze-inducing
+ * mess, and put them into something ITmfEventField can cope with.
+ */
+ private static CtfTmfEventField[] parseFields(@NonNull EventDefinition eventDef) {
+ List<CtfTmfEventField> fields = new ArrayList<>();
+
+ StructDefinition structFields = eventDef.getFields();
+ if (structFields != null) {
+ if (structFields.getFieldNames() != null) {
+ for (String curFieldName : structFields.getFieldNames()) {
+ fields.add(CtfTmfEventField.parseField(structFields.getDefinition(curFieldName), curFieldName));
+ }
+ }
+ }
+ /* Add context information as CtfTmfEventField */
+ StructDefinition structContext = eventDef.getContext();
+ if (structContext != null) {
+ for (String contextName : structContext.getFieldNames()) {
+ /* Prefix field name */
+ String curContextName = CtfConstants.CONTEXT_FIELD_PREFIX + contextName;
+ fields.add(CtfTmfEventField.parseField(structContext.getDefinition(contextName), curContextName));
+ }
+ }
+
+ return fields.toArray(new CtfTmfEventField[fields.size()]);
+ }
+
}
package org.eclipse.linuxtools.tmf.ctf.core;
-import java.util.ArrayList;
-import java.util.List;
-import java.util.Map;
-
import org.eclipse.linuxtools.ctf.core.CTFStrings;
import org.eclipse.linuxtools.ctf.core.event.EventDefinition;
import org.eclipse.linuxtools.ctf.core.event.IEventDeclaration;
import org.eclipse.linuxtools.ctf.core.event.types.Definition;
import org.eclipse.linuxtools.ctf.core.event.types.IntegerDefinition;
-import org.eclipse.linuxtools.ctf.core.event.types.StructDefinition;
-import org.eclipse.linuxtools.tmf.core.event.ITmfEventField;
-import org.eclipse.linuxtools.tmf.core.event.TmfEventField;
import org.eclipse.linuxtools.tmf.core.timestamp.TmfTimeRange;
import org.eclipse.linuxtools.tmf.core.trace.ITmfContext;
*/
public final class CtfTmfEventFactory {
+ private static final String NO_STREAM = "No stream"; //$NON-NLS-1$
+
/**
* Don't let anyone instantiate this class.
*/
int sourceCPU = eventDef.getCPU();
- ITmfEventField content = new TmfEventField(
- ITmfEventField.ROOT_FIELD_ID, null, parseFields(eventDef));
-
- String reference = fileName == null ? CtfTmfEvent.NO_STREAM : fileName;
+ String reference = fileName == null ? NO_STREAM : fileName;
/* Handle the special case of lost events */
if (eventDecl.getName().equals(CTFStrings.LOST_EVENT_NAME)) {
- Definition nbLostEventsDef = eventDef.getFields().getDefinitions().get(CTFStrings.LOST_EVENTS_FIELD);
- Definition durationDef = eventDef.getFields().getDefinitions().get(CTFStrings.LOST_EVENTS_DURATION);
+ Definition nbLostEventsDef = eventDef.getFields().getDefinition(CTFStrings.LOST_EVENTS_FIELD);
+ Definition durationDef = eventDef.getFields().getDefinition(CTFStrings.LOST_EVENTS_DURATION);
if (!(nbLostEventsDef instanceof IntegerDefinition) || !(durationDef instanceof IntegerDefinition)) {
/*
* One or both of these fields doesn't exist, or is not of the
CtfTmfLostEvent lostEvent = new CtfTmfLostEvent(originTrace,
ITmfContext.UNKNOWN_RANK,
- content,
reference, // filename
sourceCPU,
eventDecl,
new TmfTimeRange(timestamp, timestampEnd),
- nbLostEvents);
+ nbLostEvents,
+ eventDef);
return lostEvent;
}
originTrace,
ITmfContext.UNKNOWN_RANK,
timestamp,
- content,
reference, // filename
sourceCPU,
- eventDecl);
+ eventDecl,
+ eventDef);
return event;
}
return nullEvent;
}
- /**
- * Extract the field information from the structDefinition haze-inducing
- * mess, and put them into something ITmfEventField can cope with.
- */
- private static CtfTmfEventField[] parseFields(EventDefinition eventDef) {
- List<CtfTmfEventField> fields = new ArrayList<>();
-
- StructDefinition structFields = eventDef.getFields();
- for (Map.Entry<String, Definition> entry : structFields.getDefinitions().entrySet()) {
- String curFieldName = entry.getKey();
- Definition curFieldDef = entry.getValue();
- CtfTmfEventField curField = CtfTmfEventField.parseField(curFieldDef, curFieldName);
- fields.add(curField);
- }
-
- /* Add context information as CtfTmfEventField */
- StructDefinition structContext = eventDef.getContext();
- if (structContext != null) {
- for (Map.Entry<String, Definition> entry : structContext.getDefinitions().entrySet()) {
- /* Prefix field name */
- String curContextName = CtfConstants.CONTEXT_FIELD_PREFIX + entry.getKey();
- Definition curContextDef = entry.getValue();
- CtfTmfEventField curContext = CtfTmfEventField.parseField(curContextDef, curContextName);
- fields.add(curContext);
- }
- }
- return fields.toArray(new CtfTmfEventField[fields.size()]);
- }
}
import java.util.ArrayList;
import java.util.Arrays;
import java.util.List;
-import java.util.Map.Entry;
import org.eclipse.linuxtools.ctf.core.event.types.ArrayDefinition;
import org.eclipse.linuxtools.ctf.core.event.types.Definition;
} else {
/* Arrays of elements of any other type */
- Definition[] definitions = arrayDef.getDefinitions();
- CtfTmfEventField[] elements = new CtfTmfEventField[definitions.length];
+ List<Definition> definitions = arrayDef.getDefinitions();
+ CtfTmfEventField[] elements = new CtfTmfEventField[definitions.size()];
/* Parse the elements of the array. */
- for (int i = 0; i < definitions.length; i++) {
+ for (int i = 0; i < definitions.size(); i++) {
CtfTmfEventField curField = CtfTmfEventField.parseField(
- definitions[i], fieldName + '[' + i + ']');
+ definitions.get(i), fieldName + '[' + i + ']');
elements[i] = curField;
}
if (seqDef.getLength() == 0) {
/* Some sequences have length = 0. Simply use an empty string */
field = new CTFStringField(fieldName, ""); //$NON-NLS-1$
- } else if (seqDef.isString()) {
+ } else if (seqDecl.isString()) {
/* Interpret this sequence as a String */
field = new CTFStringField(fieldName, seqDef.toString());
} else if (seqDecl.getElementType() instanceof IntegerDeclaration) {
} else if (fieldDef instanceof StructDefinition) {
StructDefinition strDef = (StructDefinition) fieldDef;
- String curFieldName = null;
- Definition curFieldDef;
- CtfTmfEventField curField;
List<ITmfEventField> list = new ArrayList<>();
/* Recursively parse the fields */
- for (Entry<String, Definition> entry : strDef.getDefinitions().entrySet()) {
- curFieldName = entry.getKey();
- curFieldDef = entry.getValue();
- curField = CtfTmfEventField.parseField(curFieldDef, curFieldName);
- list.add(curField);
+ for (String curFieldName : strDef.getFieldNames()) {
+ list.add(CtfTmfEventField.parseField(strDef.getDefinition(curFieldName), curFieldName));
}
field = new CTFStructField(fieldName, list.toArray(new CtfTmfEventField[list.size()]));
VariantDefinition varDef = (VariantDefinition) fieldDef;
String curFieldName = varDef.getCurrentFieldName();
- Definition curFieldDef = varDef.getDefinitions().get(curFieldName);
+ Definition curFieldDef = varDef.getCurrentField();
if (curFieldDef != null) {
CtfTmfEventField subField = CtfTmfEventField.parseField(curFieldDef, curFieldName);
field = new CTFVariantField(fieldName, subField);
package org.eclipse.linuxtools.tmf.ctf.core;
+import org.eclipse.jdt.annotation.NonNull;
+import org.eclipse.linuxtools.ctf.core.event.EventDefinition;
import org.eclipse.linuxtools.ctf.core.event.IEventDeclaration;
-import org.eclipse.linuxtools.tmf.core.event.ITmfEventField;
import org.eclipse.linuxtools.tmf.core.event.ITmfLostEvent;
import org.eclipse.linuxtools.tmf.core.timestamp.TmfTimeRange;
*/
CtfTmfLostEvent(CtfTmfTrace trace,
long rank,
- ITmfEventField content,
String fileName,
int cpu,
IEventDeclaration declaration,
TmfTimeRange timeRange,
- long nbLost) {
+ long nbLost,
+ @NonNull EventDefinition def) {
/*
* Only the factory should call this method, the case to
* (CtfTmfTimestamp) should be safe.
*/
- super(trace, rank, (CtfTmfTimestamp) timeRange.getStartTime(), content, fileName, cpu, declaration);
+ super(trace, rank, (CtfTmfTimestamp) timeRange.getStartTime(), fileName, cpu, declaration, def);
fTimeRange = timeRange;
fNbLost = nbLost;
}