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
.TmfNanoTimestamp
;
22 import org
.eclipse
.tracecompass
.tmf
.core
.timestamp
.TmfTimeRange
;
23 import org
.eclipse
.tracecompass
.tmf
.core
.timestamp
.TmfTimestamp
;
24 import org
.eclipse
.tracecompass
.tmf
.ctf
.core
.event
.CtfTmfEvent
;
25 import org
.eclipse
.tracecompass
.tmf
.ctf
.core
.tests
.shared
.CtfTmfTestTraceUtils
;
26 import org
.eclipse
.tracecompass
.tmf
.ctf
.core
.trace
.CtfTmfTrace
;
27 import org
.junit
.After
;
28 import org
.junit
.Before
;
29 import org
.junit
.Test
;
32 * Tests for reading event contexts from a CtfTmfTrace.
34 * @author Alexandre Montplaisir
36 public class EventContextTest
{
38 // ------------------------------------------------------------------------
40 // ------------------------------------------------------------------------
42 /* We use test trace #2, kernel_vm, which has event contexts */
43 private static final @NonNull CtfTestTrace testTrace
= CtfTestTrace
.KERNEL_VM
;
45 private CtfTmfTrace fixture
;
46 private long startTime
;
49 // ------------------------------------------------------------------------
51 // ------------------------------------------------------------------------
54 * Perform pre-class initialization.
58 fixture
= CtfTmfTestTraceUtils
.getTrace(testTrace
);
59 fixture
.indexTrace(true);
61 startTime
= fixture
.getStartTime().toNanos();
62 endTime
= fixture
.getEndTime().toNanos();
66 * Perform post-class clean-up.
69 public void tearDown() {
70 if (fixture
!= null) {
75 // ------------------------------------------------------------------------
77 // ------------------------------------------------------------------------
80 * Make sure the trace is the correct one, and its timestamps are read
84 public void testTrace() {
85 assertEquals(1363700740555978750L, startTime
);
86 assertEquals(1363700770550261288L, endTime
);
90 * Test the context of the very first event of the trace.
93 public void testContextStart() {
94 CtfTmfEvent firstEvent
= getEventAt(startTime
);
95 long perfPageFault
= (Long
) firstEvent
.getContent().getField("context._perf_page_fault").getValue();
96 String procname
= (String
) firstEvent
.getContent().getField("context._procname").getValue();
97 long tid
= (Long
) firstEvent
.getContent().getField("context._tid").getValue();
99 assertEquals(613, perfPageFault
);
100 assertEquals("lttng-sessiond", procname
);
101 assertEquals(1230, tid
);
105 * Test the context of the event at 1363700745.559739078.
108 public void testContext1() {
109 long time
= startTime
+ 5000000000L; // 1363700745.559739078
110 CtfTmfEvent event
= getEventAt(time
);
111 long perfPageFault
= (Long
) event
.getContent().getField("context._perf_page_fault").getValue();
112 String procname
= (String
) event
.getContent().getField("context._procname").getValue();
113 long tid
= (Long
) event
.getContent().getField("context._tid").getValue();
115 assertEquals(6048, perfPageFault
);
116 assertEquals("swapper/0", procname
);
117 assertEquals(0, tid
);
121 * Test the context of the event at 1363700750.559707062.
124 public void testContext2() {
125 long time
= startTime
+ 2 * 5000000000L; // 1363700750.559707062
126 CtfTmfEvent event
= getEventAt(time
);
127 long perfPageFault
= (Long
) event
.getContent().getField("context._perf_page_fault").getValue();
128 String procname
= (String
) event
.getContent().getField("context._procname").getValue();
129 long tid
= (Long
) event
.getContent().getField("context._tid").getValue();
131 assertEquals(13258, perfPageFault
);
132 assertEquals("swapper/0", procname
);
133 assertEquals(0, tid
);
137 * Test the context of the event at 1363700755.555723128, which is roughly
138 * mid-way through the trace.
141 public void testContextMiddle() {
142 long midTime
= startTime
+ (endTime
- startTime
) / 2L; // 1363700755.555723128
143 CtfTmfEvent midEvent
= getEventAt(midTime
);
144 long perfPageFault
= (Long
) midEvent
.getContent().getField("context._perf_page_fault").getValue();
145 String procname
= (String
) midEvent
.getContent().getField("context._procname").getValue();
146 long tid
= (Long
) midEvent
.getContent().getField("context._tid").getValue();
148 assertEquals(19438, perfPageFault
);
149 assertEquals("swapper/0", procname
);
150 assertEquals(0, tid
);
154 * Test the context of the event at 1363700760.559719724.
157 public void testContext3() {
158 long time
= startTime
+ 4 * 5000000000L; // 1363700760.559719724
159 CtfTmfEvent event
= getEventAt(time
);
160 long perfPageFault
= (Long
) event
.getContent().getField("context._perf_page_fault").getValue();
161 String procname
= (String
) event
.getContent().getField("context._procname").getValue();
162 long tid
= (Long
) event
.getContent().getField("context._tid").getValue();
164 assertEquals(21507, perfPageFault
);
165 assertEquals("swapper/0", procname
);
166 assertEquals(0, tid
);
170 * Test the context of the event at 1363700765.559714634.
173 public void testContext4() {
174 long time
= startTime
+ 5 * 5000000000L; // 1363700765.559714634
175 CtfTmfEvent event
= getEventAt(time
);
176 long perfPageFault
= (Long
) event
.getContent().getField("context._perf_page_fault").getValue();
177 String procname
= (String
) event
.getContent().getField("context._procname").getValue();
178 long tid
= (Long
) event
.getContent().getField("context._tid").getValue();
180 assertEquals(21507, perfPageFault
);
181 assertEquals("swapper/0", procname
);
182 assertEquals(0, tid
);
186 * Test the context of the last event of the trace.
189 public void testContextEnd() {
190 CtfTmfEvent lastEvent
= getEventAt(endTime
);
191 long perfPageFault
= (Long
) lastEvent
.getContent().getField("context._perf_page_fault").getValue();
192 String procname
= (String
) lastEvent
.getContent().getField("context._procname").getValue();
193 long tid
= (Long
) lastEvent
.getContent().getField("context._tid").getValue();
195 assertEquals(22117, perfPageFault
);
196 assertEquals("lttng-sessiond", procname
);
197 assertEquals(1230, tid
);
200 // ------------------------------------------------------------------------
202 // ------------------------------------------------------------------------
204 private synchronized CtfTmfEvent
getEventAt(long timestamp
) {
205 EventContextTestRequest req
= new EventContextTestRequest(timestamp
);
206 fixture
.sendRequest(req
);
208 req
.waitForCompletion();
209 } catch (InterruptedException e
) {
212 return req
.getEvent();
215 private class EventContextTestRequest
extends TmfEventRequest
{
217 private CtfTmfEvent retEvent
= null;
219 public EventContextTestRequest(long timestamp
) {
220 super(CtfTmfEvent
.class,
221 new TmfTimeRange(new TmfNanoTimestamp(timestamp
), TmfTimestamp
.BIG_CRUNCH
),
222 0, 1, ExecutionType
.FOREGROUND
);
226 public void handleData(ITmfEvent event
) {
227 retEvent
= (CtfTmfEvent
) event
;
230 public CtfTmfEvent
getEvent() {