1 /*******************************************************************************
2 * Copyright (c) 2013, 2015 Ericsson
4 * All rights reserved. This program and the accompanying materials are
5 * made available under the terms of the Eclipse Public License v1.0 which
6 * accompanies this distribution, and is available at
7 * http://www.eclipse.org/legal/epl-v10.html
10 * Alexandre Montplaisir - Initial API and implementation
11 *******************************************************************************/
13 package org
.eclipse
.tracecompass
.tmf
.ctf
.core
.tests
.event
;
15 import static org
.junit
.Assert
.assertEquals
;
17 import org
.eclipse
.jdt
.annotation
.NonNull
;
18 import org
.eclipse
.tracecompass
.testtraces
.ctf
.CtfTestTrace
;
19 import org
.eclipse
.tracecompass
.tmf
.core
.event
.ITmfEvent
;
20 import org
.eclipse
.tracecompass
.tmf
.core
.request
.TmfEventRequest
;
21 import org
.eclipse
.tracecompass
.tmf
.core
.timestamp
.ITmfTimestamp
;
22 import org
.eclipse
.tracecompass
.tmf
.core
.timestamp
.TmfNanoTimestamp
;
23 import org
.eclipse
.tracecompass
.tmf
.core
.timestamp
.TmfTimeRange
;
24 import org
.eclipse
.tracecompass
.tmf
.core
.timestamp
.TmfTimestamp
;
25 import org
.eclipse
.tracecompass
.tmf
.ctf
.core
.event
.CtfTmfEvent
;
26 import org
.eclipse
.tracecompass
.tmf
.ctf
.core
.tests
.shared
.CtfTmfTestTraceUtils
;
27 import org
.eclipse
.tracecompass
.tmf
.ctf
.core
.trace
.CtfTmfTrace
;
28 import org
.junit
.After
;
29 import org
.junit
.Before
;
30 import org
.junit
.Test
;
33 * Tests for reading event contexts from a CtfTmfTrace.
35 * @author Alexandre Montplaisir
37 public class EventContextTest
{
39 // ------------------------------------------------------------------------
41 // ------------------------------------------------------------------------
43 /* We use test trace #2, kernel_vm, which has event contexts */
44 private static final @NonNull CtfTestTrace testTrace
= CtfTestTrace
.KERNEL_VM
;
46 private CtfTmfTrace fixture
;
47 private long startTime
;
50 // ------------------------------------------------------------------------
52 // ------------------------------------------------------------------------
55 * Perform pre-class initialization.
59 fixture
= CtfTmfTestTraceUtils
.getTrace(testTrace
);
60 fixture
.indexTrace(true);
62 startTime
= fixture
.getStartTime().normalize(0, ITmfTimestamp
.NANOSECOND_SCALE
).getValue();
63 endTime
= fixture
.getEndTime().normalize(0, ITmfTimestamp
.NANOSECOND_SCALE
).getValue();
67 * Perform post-class clean-up.
70 public void tearDown() {
71 if (fixture
!= null) {
76 // ------------------------------------------------------------------------
78 // ------------------------------------------------------------------------
81 * Make sure the trace is the correct one, and its timestamps are read
85 public void testTrace() {
86 assertEquals(1363700740555978750L, startTime
);
87 assertEquals(1363700770550261288L, endTime
);
91 * Test the context of the very first event of the trace.
94 public void testContextStart() {
95 CtfTmfEvent firstEvent
= getEventAt(startTime
);
96 long perfPageFault
= (Long
) firstEvent
.getContent().getField("context._perf_page_fault").getValue();
97 String procname
= (String
) firstEvent
.getContent().getField("context._procname").getValue();
98 long tid
= (Long
) firstEvent
.getContent().getField("context._tid").getValue();
100 assertEquals(613, perfPageFault
);
101 assertEquals("lttng-sessiond", procname
);
102 assertEquals(1230, tid
);
106 * Test the context of the event at 1363700745.559739078.
109 public void testContext1() {
110 long time
= startTime
+ 5000000000L; // 1363700745.559739078
111 CtfTmfEvent event
= getEventAt(time
);
112 long perfPageFault
= (Long
) event
.getContent().getField("context._perf_page_fault").getValue();
113 String procname
= (String
) event
.getContent().getField("context._procname").getValue();
114 long tid
= (Long
) event
.getContent().getField("context._tid").getValue();
116 assertEquals(6048, perfPageFault
);
117 assertEquals("swapper/0", procname
);
118 assertEquals(0, tid
);
122 * Test the context of the event at 1363700750.559707062.
125 public void testContext2() {
126 long time
= startTime
+ 2 * 5000000000L; // 1363700750.559707062
127 CtfTmfEvent event
= getEventAt(time
);
128 long perfPageFault
= (Long
) event
.getContent().getField("context._perf_page_fault").getValue();
129 String procname
= (String
) event
.getContent().getField("context._procname").getValue();
130 long tid
= (Long
) event
.getContent().getField("context._tid").getValue();
132 assertEquals(13258, perfPageFault
);
133 assertEquals("swapper/0", procname
);
134 assertEquals(0, tid
);
138 * Test the context of the event at 1363700755.555723128, which is roughly
139 * mid-way through the trace.
142 public void testContextMiddle() {
143 long midTime
= startTime
+ (endTime
- startTime
) / 2L; // 1363700755.555723128
144 CtfTmfEvent midEvent
= getEventAt(midTime
);
145 long perfPageFault
= (Long
) midEvent
.getContent().getField("context._perf_page_fault").getValue();
146 String procname
= (String
) midEvent
.getContent().getField("context._procname").getValue();
147 long tid
= (Long
) midEvent
.getContent().getField("context._tid").getValue();
149 assertEquals(19438, perfPageFault
);
150 assertEquals("swapper/0", procname
);
151 assertEquals(0, tid
);
155 * Test the context of the event at 1363700760.559719724.
158 public void testContext3() {
159 long time
= startTime
+ 4 * 5000000000L; // 1363700760.559719724
160 CtfTmfEvent event
= getEventAt(time
);
161 long perfPageFault
= (Long
) event
.getContent().getField("context._perf_page_fault").getValue();
162 String procname
= (String
) event
.getContent().getField("context._procname").getValue();
163 long tid
= (Long
) event
.getContent().getField("context._tid").getValue();
165 assertEquals(21507, perfPageFault
);
166 assertEquals("swapper/0", procname
);
167 assertEquals(0, tid
);
171 * Test the context of the event at 1363700765.559714634.
174 public void testContext4() {
175 long time
= startTime
+ 5 * 5000000000L; // 1363700765.559714634
176 CtfTmfEvent event
= getEventAt(time
);
177 long perfPageFault
= (Long
) event
.getContent().getField("context._perf_page_fault").getValue();
178 String procname
= (String
) event
.getContent().getField("context._procname").getValue();
179 long tid
= (Long
) event
.getContent().getField("context._tid").getValue();
181 assertEquals(21507, perfPageFault
);
182 assertEquals("swapper/0", procname
);
183 assertEquals(0, tid
);
187 * Test the context of the last event of the trace.
190 public void testContextEnd() {
191 CtfTmfEvent lastEvent
= getEventAt(endTime
);
192 long perfPageFault
= (Long
) lastEvent
.getContent().getField("context._perf_page_fault").getValue();
193 String procname
= (String
) lastEvent
.getContent().getField("context._procname").getValue();
194 long tid
= (Long
) lastEvent
.getContent().getField("context._tid").getValue();
196 assertEquals(22117, perfPageFault
);
197 assertEquals("lttng-sessiond", procname
);
198 assertEquals(1230, tid
);
201 // ------------------------------------------------------------------------
203 // ------------------------------------------------------------------------
205 private synchronized CtfTmfEvent
getEventAt(long timestamp
) {
206 EventContextTestRequest req
= new EventContextTestRequest(timestamp
);
207 fixture
.sendRequest(req
);
209 req
.waitForCompletion();
210 } catch (InterruptedException e
) {
213 return req
.getEvent();
216 private class EventContextTestRequest
extends TmfEventRequest
{
218 private CtfTmfEvent retEvent
= null;
220 public EventContextTestRequest(long timestamp
) {
221 super(CtfTmfEvent
.class,
222 new TmfTimeRange(new TmfNanoTimestamp(timestamp
), TmfTimestamp
.BIG_CRUNCH
),
223 0, 1, ExecutionType
.FOREGROUND
);
227 public void handleData(ITmfEvent event
) {
228 retEvent
= (CtfTmfEvent
) event
;
231 public CtfTmfEvent
getEvent() {