ust: Add a LinuxTidAspect using the context._vtid
[deliverable/tracecompass.git] / lttng / org.eclipse.tracecompass.lttng2.ust.core.tests / src / org / eclipse / tracecompass / lttng2 / ust / core / tests / trace / LttngUstTraceTest.java
1 /*******************************************************************************
2 * Copyright (c) 2017 École Polytechnique de Montréal
3 *
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
8 *******************************************************************************/
9
10 package org.eclipse.tracecompass.lttng2.ust.core.tests.trace;
11
12 import static org.junit.Assert.assertNotNull;
13 import static org.junit.Assert.assertNull;
14
15 import java.io.File;
16
17 import org.eclipse.jdt.annotation.NonNull;
18 import org.eclipse.tracecompass.analysis.os.linux.core.event.aspect.LinuxTidAspect;
19 import org.eclipse.tracecompass.lttng2.ust.core.trace.LttngUstTrace;
20 import org.eclipse.tracecompass.testtraces.ctf.CtfTestTrace;
21 import org.eclipse.tracecompass.tmf.core.event.ITmfEvent;
22 import org.eclipse.tracecompass.tmf.core.exceptions.TmfTraceException;
23 import org.eclipse.tracecompass.tmf.core.request.TmfEventRequest;
24 import org.eclipse.tracecompass.tmf.core.timestamp.TmfTimeRange;
25 import org.eclipse.tracecompass.tmf.core.trace.ITmfTrace;
26 import org.eclipse.tracecompass.tmf.core.trace.TmfTraceManager;
27 import org.eclipse.tracecompass.tmf.core.trace.TmfTraceUtils;
28 import org.eclipse.tracecompass.tmf.ctf.core.tests.shared.CtfTmfTestTraceUtils;
29 import org.eclipse.tracecompass.tmf.ctf.core.trace.CtfTmfTrace;
30 import org.junit.After;
31 import org.junit.Before;
32 import org.junit.Test;
33
34 /**
35 * Test the {@link LttngUstTrace} class
36 *
37 * @author Geneviève Bastien
38 */
39 public class LttngUstTraceTest {
40
41 private static final @NonNull CtfTestTrace TEST_TRACE = CtfTestTrace.CYG_PROFILE;
42
43 private ITmfTrace fTrace;
44
45 /**
46 * Perform pre-class initialization.
47 *
48 * @throws TmfTraceException
49 * Exceptions in trace initialization
50 */
51 @Before
52 public void setUp() throws TmfTraceException {
53 CtfTmfTrace ctftrace = CtfTmfTestTraceUtils.getTrace(TEST_TRACE);
54
55 LttngUstTrace trace = new LttngUstTrace();
56 trace.initTrace(null, ctftrace.getPath(), ITmfEvent.class);
57 fTrace = trace;
58
59 }
60
61 /** Empty and delete a directory */
62 private static void deleteDirectory(File dir) {
63 /* Assuming the dir only contains file or empty directories */
64 for (File file : dir.listFiles()) {
65 file.delete();
66 }
67 dir.delete();
68 }
69
70 /**
71 * Perform post-class clean-up.
72 */
73 @After
74 public void tearDown() {
75 ITmfTrace trace = fTrace;
76 if (trace != null) {
77 trace.dispose();
78 File suppDir = new File(TmfTraceManager.getSupplementaryFileDir(trace));
79 deleteDirectory(suppDir);
80 }
81 }
82
83 private static class TestEventRequest extends TmfEventRequest {
84
85 private String errString = null;
86
87 public TestEventRequest() {
88 super(ITmfEvent.class, TmfTimeRange.ETERNITY, 0, 2, ExecutionType.FOREGROUND);
89 }
90
91 @Override
92 public void handleData(@NonNull ITmfEvent event) {
93 super.handleData(event);
94 Integer tid = TmfTraceUtils.resolveIntEventAspectOfClassForEvent(event.getTrace(), LinuxTidAspect.class, event);
95 if (tid == null) {
96 errString = "No TID for event " + event;
97 cancel();
98 return;
99 }
100 if (tid.intValue() != 16073) {
101 errString = "Wrong tid: " + tid + " for event";
102 cancel();
103 return;
104 }
105 }
106
107 public String getErrString() {
108 return errString;
109 }
110
111 }
112
113 /**
114 * Test the LinuxTidAspect for this trace
115 *
116 * @throws InterruptedException
117 * exception thrown in the request
118 */
119 @Test
120 public void testTidAspect() throws InterruptedException {
121 ITmfTrace trace = fTrace;
122 assertNotNull(trace);
123
124 TestEventRequest request = new TestEventRequest();
125 trace.sendRequest(request);
126 request.waitForCompletion();
127 assertNull(request.getErrString());
128 }
129 }
This page took 0.049377 seconds and 5 git commands to generate.