ss: remove e.printStackTrace()s from HT_IO
[deliverable/tracecompass.git] / org.eclipse.tracecompass.tmf.core.tests / src / org / eclipse / tracecompass / tmf / core / tests / trace / TmfTraceUtilsTest.java
CommitLineData
b8585c7c
AM
1/*******************************************************************************
2 * Copyright (c) 2014 Ericsson
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 * Contributors:
10 * Alexandre Montplaisir - Initial API and implementation
11 *******************************************************************************/
12
13package org.eclipse.tracecompass.tmf.core.tests.trace;
14
15import static org.junit.Assert.assertEquals;
35f39420 16import static org.junit.Assert.assertFalse;
b8585c7c
AM
17import static org.junit.Assert.assertNotNull;
18import static org.junit.Assert.assertTrue;
19import static org.junit.Assert.fail;
20
21import java.io.File;
22import java.io.IOException;
23import java.net.URISyntaxException;
24import java.net.URL;
35f39420
AM
25import java.util.Collection;
26import java.util.Iterator;
b8585c7c
AM
27
28import org.eclipse.core.runtime.FileLocator;
29import org.eclipse.core.runtime.Path;
30import org.eclipse.tracecompass.tmf.core.analysis.IAnalysisModule;
35f39420
AM
31import org.eclipse.tracecompass.tmf.core.event.ITmfEvent;
32import org.eclipse.tracecompass.tmf.core.event.aspect.ITmfEventAspect;
33import org.eclipse.tracecompass.tmf.core.event.aspect.TmfCpuAspect;
b8585c7c
AM
34import org.eclipse.tracecompass.tmf.core.exceptions.TmfTraceException;
35import org.eclipse.tracecompass.tmf.core.signal.TmfSignalManager;
36import org.eclipse.tracecompass.tmf.core.signal.TmfTraceOpenedSignal;
37import org.eclipse.tracecompass.tmf.core.tests.TmfCoreTestPlugin;
38import org.eclipse.tracecompass.tmf.core.tests.analysis.AnalysisManagerTest;
39import org.eclipse.tracecompass.tmf.core.tests.shared.TmfTestTrace;
40import org.eclipse.tracecompass.tmf.core.trace.ITmfTrace;
41import org.eclipse.tracecompass.tmf.core.trace.TmfTrace;
42import org.eclipse.tracecompass.tmf.core.trace.TmfTraceUtils;
43import org.eclipse.tracecompass.tmf.tests.stubs.analysis.TestAnalysis;
44import org.eclipse.tracecompass.tmf.tests.stubs.trace.TmfTraceStub;
45import org.junit.After;
46import org.junit.Before;
47import org.junit.Test;
48
35f39420
AM
49import com.google.common.collect.ImmutableList;
50
b8585c7c
AM
51/**
52 * Test suite for {@link TmfTraceUtils}
53 */
54public class TmfTraceUtilsTest {
55
56 private static final TmfTestTrace TEST_TRACE = TmfTestTrace.A_TEST_10K;
57
58 private TmfTrace fTrace;
59
35f39420
AM
60 // ------------------------------------------------------------------------
61 // Test trace class definition
62 // ------------------------------------------------------------------------
63
64 private static class TmfTraceStubWithAspects extends TmfTraceStub {
65
66 private static final Collection<ITmfEventAspect> EVENT_ASPECTS;
67 static {
68 ImmutableList.Builder<ITmfEventAspect> builder = ImmutableList.builder();
69 builder.add(new TmfCpuAspect() {
70 @Override
71 public String getFilterId() {
72 return null;
73 }
74 @Override
75 public String resolve(ITmfEvent event) {
76 return "1";
77 }
78 });
79 builder.addAll(TmfTrace.BASE_ASPECTS);
80 EVENT_ASPECTS = builder.build();
81 }
82
83 public TmfTraceStubWithAspects(String path) throws TmfTraceException {
84 super(path, ITmfTrace.DEFAULT_TRACE_CACHE_SIZE, false, null);
85 }
86
87 @Override
88 public Iterable<ITmfEventAspect> getEventAspects() {
89 return EVENT_ASPECTS;
90 }
91
92 }
93
b8585c7c
AM
94 // ------------------------------------------------------------------------
95 // Housekeeping
96 // ------------------------------------------------------------------------
97
98 /**
99 * Test setup
100 */
101 @Before
102 public void setUp() {
103 try {
104 final URL location = FileLocator.find(TmfCoreTestPlugin.getDefault().getBundle(), new Path(TEST_TRACE.getFullPath()), null);
105 final File test = new File(FileLocator.toFileURL(location).toURI());
35f39420 106 fTrace = new TmfTraceStubWithAspects(test.toURI().getPath());
b8585c7c
AM
107 TmfSignalManager.deregister(fTrace);
108 fTrace.indexTrace(true);
109 } catch (final TmfTraceException | URISyntaxException | IOException e) {
110 fail(e.getMessage());
111 }
112 }
113
114 /**
115 * Test cleanup
116 */
117 @After
118 public void tearDown() {
119 fTrace.dispose();
120 fTrace = null;
121 }
122
123 // ------------------------------------------------------------------------
124 // Test methods
125 // ------------------------------------------------------------------------
126
127 /**
128 * Test the {@link TmfTraceUtils#getAnalysisModuleOfClass} method.
129 */
130 @Test
131 public void testGetModulesByClass() {
132 /* Open the trace, the modules should be populated */
133 fTrace.traceOpened(new TmfTraceOpenedSignal(this, fTrace, null));
134
135 Iterable<TestAnalysis> testModules = TmfTraceUtils.getAnalysisModulesOfClass(fTrace, TestAnalysis.class);
136 assertTrue(testModules.iterator().hasNext());
137
138 int count = 0;
139 for (TestAnalysis module : testModules) {
140 assertNotNull(module);
141 count++;
142 }
143 /*
144 * FIXME: The exact count depends on the context the test is run (full
145 * test suite or this file only), but there must be at least 2 modules
146 */
147 assertTrue(count >= 2);
148
149 TestAnalysis module = TmfTraceUtils.getAnalysisModuleOfClass(fTrace, TestAnalysis.class, AnalysisManagerTest.MODULE_PARAM);
150 assertNotNull(module);
151 IAnalysisModule traceModule = fTrace.getAnalysisModule(AnalysisManagerTest.MODULE_PARAM);
152 assertNotNull(traceModule);
153 assertEquals(module, traceModule);
154
155 }
35f39420
AM
156
157 /**
158 * Test the {@link TmfTraceUtils#getEventAspectsOfClass} method.
159 */
160 @Test
161 public void testGetEventAspectsOfClass() {
162 /* Our custom trace type adds 1 aspect in addition to the base ones */
163 Iterable<ITmfEventAspect> aspects = TmfTraceUtils.getEventAspectsOfClass(fTrace, ITmfEventAspect.class);
164 Collection<ITmfEventAspect> aspectColl = ImmutableList.copyOf(aspects);
165 assertEquals(TmfTrace.BASE_ASPECTS.size() + 1, aspectColl.size());
166
167 /* Make sure there is one and only one CpuAspect */
168 Iterable<TmfCpuAspect> cpuAspects = TmfTraceUtils.getEventAspectsOfClass(fTrace, TmfCpuAspect.class);
169 Iterator<TmfCpuAspect> iter = cpuAspects.iterator();
170 assertNotNull(iter.next());
171 assertFalse(iter.hasNext());
172 }
b8585c7c 173}
This page took 0.041303 seconds and 5 git commands to generate.