Skip to content

Commit

Permalink
ctf.core: Update integer and blob declarations to have a role field
Browse files Browse the repository at this point in the history
The CTF2 role field was added in the declaration class and new
constructors were made for the type declarations that can have roles:
integers and blobs. Tests for blobs and methods using roles were
updated. A new method was also added to determine whether a trace is
CTF2. Since the IntegerDeclaration constructor was deprecated, all of
the tests & files that use it were also updated.

[added] roles for CTF events

Change-Id: I54bce6150539bbb2ff380cb12c4b39c7045e661e
Signed-off-by: Sehr Moosabhoy <sehr.moosabhoy@ericsson.com>
Reviewed-on: https://git.eclipse.org/r/c/tracecompass/org.eclipse.tracecompass/+/203774
Tested-by: Matthew Khouzam <matthew.khouzam@ericsson.com>
Tested-by: Trace Compass Bot <tracecompass-bot@eclipse.org>
Reviewed-by: Matthew Khouzam <matthew.khouzam@ericsson.com>
Reviewed-by: Bernd Hufmann <bernd.hufmann@ericsson.com>
  • Loading branch information
Sehr Moosabhoy authored and bhufmann committed Sep 1, 2023
1 parent b26495e commit 9b758df
Show file tree
Hide file tree
Showing 33 changed files with 395 additions and 148 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -51,8 +51,8 @@ public class CTFEventDefinitionTest {
@Before
public void init() {
fixture = new ArrayList<>();
IntegerDeclaration pidDec = IntegerDeclaration.createDeclaration(5, false, 10, ByteOrder.LITTLE_ENDIAN, Encoding.NONE, "", 8);
IntegerDeclaration ctxDec = IntegerDeclaration.createDeclaration(16, false, 10, ByteOrder.LITTLE_ENDIAN, Encoding.NONE, "", 8);
IntegerDeclaration pidDec = IntegerDeclaration.createDeclaration(5, false, 10, ByteOrder.LITTLE_ENDIAN, Encoding.NONE, "", 8, null);
IntegerDeclaration ctxDec = IntegerDeclaration.createDeclaration(16, false, 10, ByteOrder.LITTLE_ENDIAN, Encoding.NONE, "", 8, null);
IntegerDefinition pid = new IntegerDefinition(pidDec, null, "pid", 3);
IntegerDefinition pod = new IntegerDefinition(pidDec, null, "pod", 3);
IntegerDefinition ctx = new IntegerDefinition(pidDec, null, "ctx", 3);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,8 @@ public void testParseField_complex() throws CTFException {
ByteOrder.LITTLE_ENDIAN,
Encoding.ASCII,
"",
len);
len,
null);
String lengthName = "LengthName";
StructDeclaration structDec = new StructDeclaration(0);
structDec.addField(lengthName, id);
Expand Down Expand Up @@ -119,7 +120,7 @@ public void testParseField_simple() throws CTFException {
public void testParseField_simple2() {
IntegerDefinition fieldDef = new IntegerDefinition(
IntegerDeclaration.createDeclaration(1, false, 1, ByteOrder.BIG_ENDIAN,
Encoding.ASCII, "", 8), null, fieldName, 1L);
Encoding.ASCII, "", 8, null), null, fieldName, 1L);

assertNotNull(fieldDef);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -262,7 +262,7 @@ public void testStreamInputPacketIndexEntryConstructor7() throws CTFException {
StructDeclaration sd = new StructDeclaration(8);
sd.addField("timestamp_end", IntegerDeclaration.INT_32B_DECL);
sd.addField("content_size", IntegerDeclaration.INT_32B_DECL);
final EnumDeclaration declaration = new EnumDeclaration(IntegerDeclaration.createDeclaration(16, false, 10, ByteOrder.BIG_ENDIAN, Encoding.NONE, "", 8));
final EnumDeclaration declaration = new EnumDeclaration(IntegerDeclaration.createDeclaration(16, false, 10, ByteOrder.BIG_ENDIAN, Encoding.NONE, "", 8, null));
declaration.add(313, 315, "CPU-PI");
sd.addField("device", declaration);
BitBuffer bb = new BitBuffer(ByteBuffer.allocate(128));
Expand All @@ -288,7 +288,7 @@ public void testStreamInputPacketIndexEntryConstructor8() throws CTFException {
StructDeclaration sd = new StructDeclaration(8);
sd.addField("timestamp_end", IntegerDeclaration.INT_32B_DECL);
sd.addField("content_size", IntegerDeclaration.INT_32B_DECL);
final IDeclaration declaration = IntegerDeclaration.createDeclaration(16, false, 10, ByteOrder.BIG_ENDIAN, Encoding.NONE, "", 8);
final IDeclaration declaration = IntegerDeclaration.createDeclaration(16, false, 10, ByteOrder.BIG_ENDIAN, Encoding.NONE, "", 8, null);
sd.addField("device", declaration);
BitBuffer bb = new BitBuffer(ByteBuffer.allocate(128));
bb.getByteBuffer().putInt(-1);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -123,7 +123,7 @@ public void testIsString_ownDefs() {
@Test
public void testIsString_complex() {
final IntegerDeclaration id = IntegerDeclaration.createDeclaration(8, false, 16,
ByteOrder.LITTLE_ENDIAN, Encoding.UTF8, "", 8);
ByteOrder.LITTLE_ENDIAN, Encoding.UTF8, "", 8, null);
CompoundDeclaration ad = new ArrayDeclaration(0, id);

boolean result = ad.isString();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -68,14 +68,14 @@ public void setUp() {
}

private ArrayDefinition createLongArray() {
IntegerDeclaration decl = IntegerDeclaration.createDeclaration(32, false, 10, ByteOrder.BIG_ENDIAN, Encoding.NONE, "none", 8);
IntegerDeclaration decl = IntegerDeclaration.createDeclaration(32, false, 10, ByteOrder.BIG_ENDIAN, Encoding.NONE, "none", 8, null);
List<@NonNull Definition> defs = createIntDefs(10, 32);
ArrayDefinition temp = setUpDeclaration(decl, defs);
return temp;
}

private ArrayDefinition createCharArray() {
IntegerDeclaration decl = IntegerDeclaration.createDeclaration(8, false, 10, ByteOrder.BIG_ENDIAN, Encoding.UTF8, "none", 8);
IntegerDeclaration decl = IntegerDeclaration.createDeclaration(8, false, 10, ByteOrder.BIG_ENDIAN, Encoding.UTF8, "none", 8, null);
List<@NonNull Definition> defs = createIntDefs(4, 8);
ArrayDefinition temp = setUpDeclaration(decl, defs);
return temp;
Expand All @@ -100,7 +100,7 @@ private ArrayDefinition setUpDeclaration(@NonNull IDeclaration decl,
for (int i = 0; i < size; i++) {
String content = "test" + i;
defs.add(new IntegerDefinition(IntegerDeclaration.createDeclaration(bits, false,
16, ByteOrder.LITTLE_ENDIAN, Encoding.UTF8, content, 24), null, content, i));
16, ByteOrder.LITTLE_ENDIAN, Encoding.UTF8, content, 24, null), null, content, i));
}
return defs;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,7 @@ public class BlobDeclarationTest {

private BlobDeclaration fixture;
private static final int LENGTH = 16;
private static final String ROLE = "metadata-uuid";
@NonNull private static final String MEDIA_TYPE = "\"application/octet-stream\"";
private static final byte[] UUID_ARRAY = new byte[] { 0x2a, 0x64, 0x22, (byte) 0xd0, 0x6c, (byte) 0xee, 0x11, (byte) 0xe0, (byte) 0x8c, 0x08, (byte) 0xcb, 0x07, (byte) 0xd7, (byte) 0xb3, (byte) 0xa5, 0x64 };

Expand All @@ -44,15 +45,15 @@ public class BlobDeclarationTest {
*/
@Before
public void setUp() {
fixture = new BlobDeclaration(LENGTH, MEDIA_TYPE);
fixture = new BlobDeclaration(LENGTH, MEDIA_TYPE, ROLE);
}

/**
* Run the BlobDeclaration() constructor test.
*/
@Test
public void testBlobDeclaration() {
BlobDeclaration result = new BlobDeclaration(LENGTH, MEDIA_TYPE);
BlobDeclaration result = new BlobDeclaration(LENGTH, MEDIA_TYPE, ROLE);

assertNotNull(result);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,7 @@ public class BlobDefinitionTest {

private BlobDefinition fixture;
private static final int LENGTH = 16;
private static final String ROLE = "metadata-uuid";
@NonNull private static final String MEDIA_TYPE = "\"application/octet-stream\"";
private static final byte[] UUID_ARRAY = new byte[] { 0x2a, 0x64, 0x22, (byte) 0xd0, 0x6c, (byte) 0xee, 0x11, (byte) 0xe0, (byte) 0x8c, 0x08, (byte) 0xcb, 0x07, (byte) 0xd7, (byte) 0xb3, (byte) 0xa5, 0x64 };

Expand All @@ -48,7 +49,7 @@ public class BlobDefinitionTest {
@Before
public void setUp() throws CTFException {
String name = "testBlob";
BlobDeclaration blobDec = new BlobDeclaration(LENGTH, MEDIA_TYPE);
BlobDeclaration blobDec = new BlobDeclaration(LENGTH, MEDIA_TYPE, ROLE);
ByteBuffer byteBuffer = ByteBuffer.allocate(16);
BitBuffer bb = new BitBuffer(byteBuffer);
byteBuffer.mark();
Expand All @@ -62,7 +63,7 @@ public void setUp() throws CTFException {
*/
@Test
public void testBlobDefinition() {
BlobDeclaration declaration = new BlobDeclaration(LENGTH, MEDIA_TYPE);
BlobDeclaration declaration = new BlobDeclaration(LENGTH, MEDIA_TYPE, ROLE);
IDefinitionScope definitionScope = null;
String fieldName = "";

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,7 @@ public class EnumDeclarationTest {
@Before
public void setUp() {
fixture = new EnumDeclaration(IntegerDeclaration.createDeclaration(1, false, 1,
ByteOrder.BIG_ENDIAN, Encoding.ASCII, "", 8));
ByteOrder.BIG_ENDIAN, Encoding.ASCII, "", 8, null));
}

/**
Expand All @@ -61,7 +61,7 @@ public void setUp() {
@Test
public void testEnumDeclaration() {
IntegerDeclaration containerType = IntegerDeclaration.createDeclaration(1, false, 1,
ByteOrder.BIG_ENDIAN, Encoding.ASCII, "", 8);
ByteOrder.BIG_ENDIAN, Encoding.ASCII, "", 8, null);

EnumDeclaration result = new EnumDeclaration(containerType);

Expand Down Expand Up @@ -246,7 +246,7 @@ public void testToString() {
@Test
public void hashcodeTest() {
EnumDeclaration b = new EnumDeclaration(IntegerDeclaration.createDeclaration(1, false, 1,
ByteOrder.BIG_ENDIAN, Encoding.ASCII, "", 8));
ByteOrder.BIG_ENDIAN, Encoding.ASCII, "", 8, null));
assertEquals(b.hashCode(), fixture.hashCode());
fixture.add(0, 1, "hello");
fixture.add(2, 3, "kitty");
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@ public class EnumDefinitionTest {
@Before
public void setUp() {
IntegerDeclaration integerDeclaration = IntegerDeclaration.createDeclaration(1, false, 1, ByteOrder.BIG_ENDIAN,
Encoding.ASCII, "", 8);
Encoding.ASCII, "", 8, null);
EnumDeclaration declaration = new EnumDeclaration(
integerDeclaration);
declaration.add(0, 10, "a");
Expand Down Expand Up @@ -102,7 +102,7 @@ public void testToString() {
@Test
public void testUnknownEnum() {
IntegerDeclaration integerDeclaration = IntegerDeclaration.createDeclaration(1, false, 1, ByteOrder.BIG_ENDIAN,
Encoding.ASCII, "", 8);
Encoding.ASCII, "", 8, null);
EnumDeclaration declaration = new EnumDeclaration(
integerDeclaration);
declaration.add(0, 10, "a");
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -78,13 +78,13 @@ public void init() {
*/

StructDeclaration base = new StructDeclaration(8);
EnumDeclaration enumDec = new EnumDeclaration(IntegerDeclaration.createDeclaration(5, false, 10, ByteOrder.BIG_ENDIAN, Encoding.NONE, "", 1));
EnumDeclaration enumDec = new EnumDeclaration(IntegerDeclaration.createDeclaration(5, false, 10, ByteOrder.BIG_ENDIAN, Encoding.NONE, "", 1, null));
enumDec.add(0, 30, "compact");
enumDec.add(31, 31, "extended");
base.addField("id", enumDec);
VariantDeclaration variantV = new VariantDeclaration();
StructDeclaration compact = new StructDeclaration(1);
compact.addField("timestamp", IntegerDeclaration.createDeclaration(27, false, 10, ByteOrder.BIG_ENDIAN, Encoding.NONE, "", 1));
compact.addField("timestamp", IntegerDeclaration.createDeclaration(27, false, 10, ByteOrder.BIG_ENDIAN, Encoding.NONE, "", 1, null));
variantV.addField("compact", compact);
StructDeclaration large = new StructDeclaration(1);
large.addField("id", IntegerDeclaration.UINT_32B_DECL);
Expand Down Expand Up @@ -113,7 +113,7 @@ public void init() {
*/

base = new StructDeclaration(8);
enumDec = new EnumDeclaration(IntegerDeclaration.createDeclaration(16, false, 10, ByteOrder.BIG_ENDIAN, Encoding.NONE, "", 1));
enumDec = new EnumDeclaration(IntegerDeclaration.createDeclaration(16, false, 10, ByteOrder.BIG_ENDIAN, Encoding.NONE, "", 1, null));
enumDec.add(0, 65534, "compact");
enumDec.add(65535, 65535, "extended");
base.addField("id", enumDec);
Expand All @@ -130,13 +130,13 @@ public void init() {

// bad - misnamed enum
base = new StructDeclaration(8);
enumDec = new EnumDeclaration(IntegerDeclaration.createDeclaration(5, false, 10, ByteOrder.BIG_ENDIAN, Encoding.NONE, "", 1));
enumDec = new EnumDeclaration(IntegerDeclaration.createDeclaration(5, false, 10, ByteOrder.BIG_ENDIAN, Encoding.NONE, "", 1, null));
enumDec.add(0, 30, "compact");
enumDec.add(31, 31, "large");
base.addField("id", enumDec);
variantV = new VariantDeclaration();
compact = new StructDeclaration(1);
compact.addField("timestamp", IntegerDeclaration.createDeclaration(27, false, 10, ByteOrder.BIG_ENDIAN, Encoding.NONE, "", 1));
compact.addField("timestamp", IntegerDeclaration.createDeclaration(27, false, 10, ByteOrder.BIG_ENDIAN, Encoding.NONE, "", 1, null));
variantV.addField("compact", compact);
large = new StructDeclaration(1);
large.addField("id", IntegerDeclaration.UINT_32B_DECL);
Expand All @@ -147,12 +147,12 @@ public void init() {

// bad - missing enum
base = new StructDeclaration(8);
enumDec = new EnumDeclaration(IntegerDeclaration.createDeclaration(5, false, 10, ByteOrder.BIG_ENDIAN, Encoding.NONE, "", 1));
enumDec = new EnumDeclaration(IntegerDeclaration.createDeclaration(5, false, 10, ByteOrder.BIG_ENDIAN, Encoding.NONE, "", 1, null));
enumDec.add(0, 30, "compact");
base.addField("id", enumDec);
variantV = new VariantDeclaration();
compact = new StructDeclaration(1);
compact.addField("timestamp", IntegerDeclaration.createDeclaration(27, false, 10, ByteOrder.BIG_ENDIAN, Encoding.NONE, "", 1));
compact.addField("timestamp", IntegerDeclaration.createDeclaration(27, false, 10, ByteOrder.BIG_ENDIAN, Encoding.NONE, "", 1, null));
variantV.addField("compact", compact);
large = new StructDeclaration(1);
large.addField("id", IntegerDeclaration.UINT_32B_DECL);
Expand All @@ -163,13 +163,13 @@ public void init() {

// bad - int 5 alignment 8 bit
base = new StructDeclaration(8);
enumDec = new EnumDeclaration(IntegerDeclaration.createDeclaration(5, false, 10, ByteOrder.BIG_ENDIAN, Encoding.NONE, "", 8));
enumDec = new EnumDeclaration(IntegerDeclaration.createDeclaration(5, false, 10, ByteOrder.BIG_ENDIAN, Encoding.NONE, "", 8, null));
enumDec.add(0, 30, "compact");
enumDec.add(31, 31, "extended");
base.addField("id", enumDec);
variantV = new VariantDeclaration();
compact = new StructDeclaration(1);
compact.addField("timestamp", IntegerDeclaration.createDeclaration(27, false, 10, ByteOrder.BIG_ENDIAN, Encoding.NONE, "", 1));
compact.addField("timestamp", IntegerDeclaration.createDeclaration(27, false, 10, ByteOrder.BIG_ENDIAN, Encoding.NONE, "", 1, null));
variantV.addField("compact", compact);
large = new StructDeclaration(1);
large.addField("id", IntegerDeclaration.UINT_32B_DECL);
Expand Down
Loading

0 comments on commit 9b758df

Please sign in to comment.