[156247] Preparation work for LTTng/TMF automated testing in Linux Tools build system.
[deliverable/tracecompass.git] / org.eclipse.linuxtools.lttng.tests / src / org / eclipse / linuxtools / lttng / tests / event / LttngEventTest.java
1 package org.eclipse.linuxtools.lttng.tests.event;
2
3 import junit.framework.TestCase;
4
5 import org.eclipse.linuxtools.lttng.event.LttngEvent;
6 import org.eclipse.linuxtools.lttng.event.LttngEventContent;
7 import org.eclipse.linuxtools.lttng.event.LttngEventReference;
8 import org.eclipse.linuxtools.lttng.event.LttngEventType;
9 import org.eclipse.linuxtools.lttng.event.LttngTimestamp;
10 import org.eclipse.linuxtools.lttng.jni.JniEvent;
11 import org.eclipse.linuxtools.lttng.trace.LTTngTextTrace;
12 import org.eclipse.linuxtools.tmf.event.TmfEventSource;
13 import org.eclipse.linuxtools.tmf.trace.TmfTraceContext;
14
15 /*
16 Functions tested here :
17 public LttngEvent(LttngTimestamp timestamp, TmfEventSource source, LttngEventType type, LttngEventContent content, LttngEventReference reference, JniEvent lttEvent)
18 public LttngEvent(LttngEvent oldEvent)
19
20 public String getChannelName()
21 public long getCpuId()
22 public String getMarkerName()
23 public LttngEventType getType()
24 public LttngEventContent getContent()
25
26 public void updateJniEventReference(JniEvent newJniEventReference)
27 public void setContent(LttngEventContent newContent)
28 public void setType(LttngEventType newType)
29
30 public JniEvent convertEventTmfToJni()
31
32 public String toString()
33 */
34
35 public class LttngEventTest extends TestCase {
36 private final static String tracepath1="traceset/trace-15316events_nolost_newformat.txt";
37 private final static boolean skipIndexing=true;
38
39 private final static long eventTimestamp = 13589759412127L;
40 private final static String eventSource = "Kernel Core";
41 private final static String eventType = "metadata/0/core_marker_id";
42 private final static String eventChannel = "metadata";
43 private final static long eventCpu = 0;
44 private final static String eventMarker = "core_marker_id";
45 private final static String eventContent = "alignment:0 size_t:4 int:4 name:vm_map pointer:4 event_id:0 long:4 channel:vm_state ";
46 private final static String eventReference = eventChannel + "_" + eventCpu;
47
48
49 private LttngEvent prepareToTest() {
50 LttngEvent tmpEvent = null;
51
52 try {
53 LTTngTextTrace tmpStream = new LTTngTextTrace(tracepath1, skipIndexing);
54 tmpEvent = (LttngEvent)tmpStream.getNextEvent(new TmfTraceContext(0, new LttngTimestamp(0L), 0) );
55 }
56 catch (Exception e) {
57 System.out.println("ERROR : Could not open " + tracepath1);
58 }
59
60 return tmpEvent;
61 }
62
63 public void testConstructors() {
64 LttngEvent testEvent = null;
65 @SuppressWarnings("unused")
66 LttngEvent testAnotherEvent = null;
67 LttngTimestamp testTime = null;
68 TmfEventSource testSource = null;
69 LttngEventType testType = null;
70 LttngEventContent testContent = null;
71 LttngEventReference testReference = null;
72 JniEvent testJniEvent = null;
73 String[] testMarkerFields = null;
74
75 // This need to work if we want to perform tests
76 try {
77 // In order to test LttngEvent, we need all these constructors/functions to work.
78 // Make sure to run their unit tests first!
79 testMarkerFields = new String[1];
80 testEvent = null;
81 testTime = new LttngTimestamp(0L);
82 testSource = new TmfEventSource("test");
83 testType = new LttngEventType("test", 0L, "test", testMarkerFields);
84 testContent = new LttngEventContent(testEvent);
85 testReference = new LttngEventReference("test", "test");
86 }
87 catch( Exception e) {
88 fail("Cannot allocate an EventStream, junit failed!");
89 }
90
91 // Test constructor with correct information
92 try {
93 testEvent = new LttngEvent( testTime, testSource, testType, testContent, testReference, testJniEvent);
94 }
95 catch( Exception e) {
96 fail("Construction with correct information failed!");
97 }
98
99 // Test about copy constructor
100 // Passing a null to copy constructor should fail
101 try {
102 testAnotherEvent = new LttngEvent(null);
103 fail("Copy constructor with null old event should fail!");
104 }
105 catch( Exception e) {
106 }
107
108 // Copy constructor used properly
109 testEvent = prepareToTest();
110 try {
111 testAnotherEvent = new LttngEvent(testEvent);
112 }
113 catch( Exception e) {
114 fail("Correct utilisation of copy constructor failed!");
115 }
116
117 }
118
119 public void testGetter() {
120 LttngEvent testEvent = prepareToTest();
121
122 // These will test TMF functions but since we are expecting it to work...
123 assertEquals("Timestamp not what expected!",eventTimestamp,testEvent.getTimestamp().getValue());
124 assertEquals("Source not what expected!",eventSource,testEvent.getSource().getSourceId());
125 assertEquals("Reference not what expected!",eventReference,((String)testEvent.getReference().toString()) );
126
127 // These should be overridden functions
128 assertEquals("Type not what expected!",eventType,testEvent.getType().getTypeId());
129 assertEquals("Channel not what expected!",eventChannel,testEvent.getChannelName());
130 assertEquals("CpuId not what expected!",eventCpu,testEvent.getCpuId());
131 assertEquals("Marker not what expected!",eventMarker,testEvent.getMarkerName());
132 assertEquals("Content not what expected!",eventContent,testEvent.getContent().toString());
133 }
134
135 public void testSetter() {
136 LttngEvent testEvent = prepareToTest();
137
138 LttngEventType testType = null;
139 LttngEventContent testContent = null;
140 JniEvent testJniEvent = null;
141
142 String[] testMarkerFields = new String[1];
143 testType = new LttngEventType("test", 0L, "test", testMarkerFields);
144 testContent = new LttngEventContent(testEvent);
145
146 try {
147 // *** FIXME ***
148 // This won't do anything good on a text trace
149 testEvent.updateJniEventReference(testJniEvent);
150
151 testEvent.setContent(testContent);
152 testEvent.setType(testType);
153 }
154 catch( Exception e) {
155 fail("Setters raised an exception!");
156 }
157
158 assertSame("SetType failed : type not what expected!",testType,testEvent.getType());
159 assertSame("SetContent failed : content not what expected!",testContent,testEvent.getContent());
160
161 }
162
163
164 public void testConversion() {
165 @SuppressWarnings("unused")
166 JniEvent tmpJniEvent = null;
167 LttngEvent testEvent = null;
168
169 testEvent = prepareToTest();
170
171 try {
172 tmpJniEvent = testEvent.convertEventTmfToJni();
173 }
174 catch( Exception e) {
175 fail("Conversion raised an exception!");
176 }
177
178 // *** FIXME ***
179 // This test can't work with a text trace, commented for now
180 //assertNotSame("Conversion returned a null event!",null, tmpJniEvent );
181 }
182
183 public void testToString() {
184 LttngEvent tmpEvent = prepareToTest();
185
186 // Just make sure toString() does not return null or the java reference
187 assertNotSame("toString returned null",null, tmpEvent.toString() );
188 assertNotSame("toString is not overridded!", tmpEvent.getClass().getName() + '@' + Integer.toHexString(tmpEvent.hashCode()), tmpEvent.toString() );
189 }
190
191 }
This page took 0.035465 seconds and 6 git commands to generate.