1 /*******************************************************************************
2 * Copyright (c) 2014 Ericsson
3 * All rights reserved. This program and the accompanying materials
4 * are made available under the terms of the Eclipse Public License v1.0
5 * which accompanies this distribution, and is available at
6 * http://www.eclipse.org/legal/epl-v10.html
9 * Matthew Khouzam - Initial API and implementation
10 *******************************************************************************/
12 package org
.eclipse
.tracecompass
.ctf
.core
.tests
.event
;
14 import static org
.junit
.Assert
.assertEquals
;
15 import static org
.junit
.Assert
.assertNotNull
;
16 import static org
.junit
.Assert
.assertNull
;
17 import static org
.junit
.Assert
.assertTrue
;
19 import java
.nio
.ByteOrder
;
20 import java
.util
.ArrayList
;
21 import java
.util
.List
;
23 import org
.eclipse
.tracecompass
.ctf
.core
.event
.EventDefinition
;
24 import org
.eclipse
.tracecompass
.ctf
.core
.event
.scope
.ILexicalScope
;
25 import org
.eclipse
.tracecompass
.ctf
.core
.event
.types
.Definition
;
26 import org
.eclipse
.tracecompass
.ctf
.core
.event
.types
.Encoding
;
27 import org
.eclipse
.tracecompass
.ctf
.core
.event
.types
.ICompositeDefinition
;
28 import org
.eclipse
.tracecompass
.ctf
.core
.event
.types
.IntegerDeclaration
;
29 import org
.eclipse
.tracecompass
.ctf
.core
.event
.types
.IntegerDefinition
;
30 import org
.eclipse
.tracecompass
.ctf
.core
.event
.types
.StructDeclaration
;
31 import org
.eclipse
.tracecompass
.ctf
.core
.event
.types
.StructDefinition
;
32 import org
.eclipse
.tracecompass
.internal
.ctf
.core
.event
.EventDeclaration
;
33 import org
.junit
.Before
;
34 import org
.junit
.Test
;
37 * Test the event definition
39 * @author Matthew Khouzam
42 public class CTFEventDefinitionTest
{
43 List
<EventDefinition
> fixture
;
46 * Making a power set of configurations to test the event definition
50 fixture
= new ArrayList
<>();
51 IntegerDeclaration pidDec
= IntegerDeclaration
.createDeclaration(5, false, 10, ByteOrder
.LITTLE_ENDIAN
, Encoding
.NONE
, "", 8);
52 IntegerDeclaration ctxDec
= IntegerDeclaration
.createDeclaration(16, false, 10, ByteOrder
.LITTLE_ENDIAN
, Encoding
.NONE
, "", 8);
53 IntegerDefinition pid
= new IntegerDefinition(pidDec
, null, "pid", 3);
54 IntegerDefinition pod
= new IntegerDefinition(pidDec
, null, "pod", 3);
55 IntegerDefinition ctx
= new IntegerDefinition(pidDec
, null, "ctx", 3);
57 StructDeclaration streamContextDec
= new StructDeclaration(8);
58 streamContextDec
.addField("pid", pidDec
);
59 streamContextDec
.addField("ctx", ctxDec
);
60 StructDeclaration eventContextDec
= new StructDeclaration(8);
61 eventContextDec
.addField("pod", pidDec
);
62 eventContextDec
.addField("ctx", pidDec
);
63 StructDeclaration fDec
= new StructDeclaration(8);
64 EventDeclaration eventDeclaration
= new EventDeclaration();
66 fDec
.addField("pid", pidDec
);
67 fDec
.addField("ctx", ctxDec
);
68 fDec
.addField("pod", pidDec
);
70 Definition
[] sDefs
= { pid
, ctx
};
71 Definition
[] eDefs
= { pod
, ctx
};
72 Definition
[] fDefs
= { pid
, ctx
, pod
};
74 StructDeclaration pContextDec
= new StructDeclaration(8);
76 StructDefinition sContext
= new StructDefinition(streamContextDec
, null, ILexicalScope
.STREAM_PACKET_CONTEXT
.getPath(), sDefs
);
77 StructDefinition eContext
= new StructDefinition(eventContextDec
, null, ILexicalScope
.STREAM_EVENT_CONTEXT
.getPath(), eDefs
);
78 StructDefinition pContext
= new StructDefinition(pContextDec
, null, ILexicalScope
.FIELDS
.getPath(), new Definition
[0]);
79 StructDefinition fields
= new StructDefinition(fDec
, null, ILexicalScope
.FIELDS
.getPath(), fDefs
);
81 int cpu
= EventDefinition
.UNKNOWN_CPU
;
83 fixture
.add(new EventDefinition(eventDeclaration
, cpu
, 100, null, null, null, null, null, null));
84 fixture
.add(new EventDefinition(eventDeclaration
, cpu
, 100, null, null, null, null, fields
, null));
85 fixture
.add(new EventDefinition(eventDeclaration
, cpu
, 100, null, null, null, pContext
, null, null));
86 fixture
.add(new EventDefinition(eventDeclaration
, cpu
, 100, null, null, null, pContext
, fields
, null));
87 fixture
.add(new EventDefinition(eventDeclaration
, cpu
, 100, null, null, eContext
, null, null, null));
88 fixture
.add(new EventDefinition(eventDeclaration
, cpu
, 100, null, null, eContext
, null, fields
, null));
89 fixture
.add(new EventDefinition(eventDeclaration
, cpu
, 100, null, null, eContext
, pContext
, null, null));
90 fixture
.add(new EventDefinition(eventDeclaration
, cpu
, 100, null, null, eContext
, pContext
, fields
, null));
91 fixture
.add(new EventDefinition(eventDeclaration
, cpu
, 100, null, sContext
, null, null, null, null));
92 fixture
.add(new EventDefinition(eventDeclaration
, cpu
, 100, null, sContext
, null, null, fields
, null));
93 fixture
.add(new EventDefinition(eventDeclaration
, cpu
, 100, null, sContext
, null, pContext
, null, null));
94 fixture
.add(new EventDefinition(eventDeclaration
, cpu
, 100, null, sContext
, null, pContext
, fields
, null));
95 fixture
.add(new EventDefinition(eventDeclaration
, cpu
, 100, null, sContext
, eContext
, null, null, null));
96 fixture
.add(new EventDefinition(eventDeclaration
, cpu
, 100, null, sContext
, eContext
, null, fields
, null));
97 fixture
.add(new EventDefinition(eventDeclaration
, cpu
, 100, null, sContext
, eContext
, pContext
, null, null));
98 fixture
.add(new EventDefinition(eventDeclaration
, cpu
, 100, null, sContext
, eContext
, pContext
, fields
, null));
102 * Test all the events
105 public void testEvents() {
107 for (EventDefinition ed
: fixture
) {
113 private static void test(int rank
, EventDefinition ed
) {
114 String title
= "event #" + rank
;
115 assertEquals(title
, 100L, ed
.getTimestamp());
116 ICompositeDefinition context
= ed
.getContext();
118 assertNotNull(title
, context
);
120 assertEquals(title
, 3, context
.getFieldNames().size());
122 assertEquals(title
, 2, context
.getFieldNames().size());
126 assertNull(title
, context
);
128 if (((rank
/ 4) % 2) == 1) {
129 assertNotNull(title
, ed
.getEventContext());
131 assertNull(title
, ed
.getEventContext());
134 assertNotNull(title
, ed
.getFields());
135 assertEquals(title
, 3, ed
.getFields().getFieldNames().size());
137 assertNull(title
, ed
.getFields());
139 assertTrue(title
, ed
.toString().startsWith("Event type: null" + System
.getProperty("line.separator") + "Timestamp: 100"));