2010-11-09 Francois Chouinard <fchouinard@gmail.com> Contribution for Bug315307
[deliverable/tracecompass.git] / org.eclipse.linuxtools.lttng.tests / src / org / eclipse / linuxtools / lttng / tests / trace / LTTngExperimentTest.java
1 /*******************************************************************************
2 * Copyright (c) 2009, 2010 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 * Francois Chouinard - Initial API and implementation
11 *******************************************************************************/
12
13 package org.eclipse.linuxtools.lttng.tests.trace;
14
15 import java.io.File;
16 import java.io.IOException;
17 import java.net.URISyntaxException;
18 import java.net.URL;
19
20 import junit.framework.TestCase;
21
22 import org.eclipse.core.runtime.FileLocator;
23 import org.eclipse.core.runtime.Path;
24 import org.eclipse.linuxtools.lttng.tests.LTTngCoreTestPlugin;
25 import org.eclipse.linuxtools.lttng.trace.LTTngExperiment;
26 import org.eclipse.linuxtools.lttng.trace.LTTngTrace;
27 import org.eclipse.linuxtools.tmf.event.TmfEvent;
28 import org.eclipse.linuxtools.tmf.event.TmfTimeRange;
29 import org.eclipse.linuxtools.tmf.event.TmfTimestamp;
30 import org.eclipse.linuxtools.tmf.trace.ITmfTrace;
31
32 /**
33 * <b><u>TmfExperimentTest</u></b>
34 * <p>
35 * TODO: Implement me. Please.
36 */
37 @SuppressWarnings("nls")
38 public class LTTngExperimentTest extends TestCase {
39
40 private static final String DIRECTORY = "traceset";
41 private static final String TEST_STREAM = "trace-15316events_nolost_newformat";
42 private static final String EXPERIMENT = "MyExperiment";
43 private static int NB_EVENTS = 15316;
44
45 // Note: Start/end times are for the LTTng *trace*, not the actual events
46 private static final TmfTimestamp fStartTime = new TmfTimestamp(13589759412128L, (byte) -9);
47 private static final TmfTimestamp fEndTime = new TmfTimestamp(13589907059242L, (byte) -9);
48
49 private static ITmfTrace[] fTraces;
50 private static LTTngExperiment<TmfEvent> fExperiment;
51
52 // ------------------------------------------------------------------------
53 // Housekeeping
54 // ------------------------------------------------------------------------
55
56 private synchronized static ITmfTrace[] setupTrace(String path) {
57 if (fTraces == null) {
58 fTraces = new ITmfTrace[1];
59 try {
60 URL location = FileLocator.find(LTTngCoreTestPlugin.getPlugin().getBundle(), new Path(path), null);
61 File testfile = new File(FileLocator.toFileURL(location).toURI());
62 LTTngTrace trace = new LTTngTrace(testfile.getPath());
63 fTraces[0] = trace;
64 } catch (URISyntaxException e) {
65 e.printStackTrace();
66 } catch (IOException e) {
67 e.printStackTrace();
68 } catch (Exception e) {
69 e.printStackTrace();
70 }
71 }
72 return fTraces;
73 }
74
75 private synchronized static void setupExperiment() {
76 if (fExperiment == null) {
77 fExperiment = new LTTngExperiment<TmfEvent>(TmfEvent.class, EXPERIMENT, fTraces, TmfTimestamp.Zero, 1000, true);
78 }
79 }
80
81 public LTTngExperimentTest(String name) throws Exception {
82 super(name);
83 }
84
85 @Override
86 protected void setUp() throws Exception {
87 super.setUp();
88 setupTrace(DIRECTORY + File.separator + TEST_STREAM);
89 setupExperiment();
90 }
91
92 @Override
93 protected void tearDown() throws Exception {
94 super.tearDown();
95 }
96
97 // ------------------------------------------------------------------------
98 // Constructor
99 // ------------------------------------------------------------------------
100
101 public void testBasicTmfExperimentConstructor() {
102
103 assertEquals("GetId", EXPERIMENT, fExperiment.getName());
104 assertEquals("GetEpoch", TmfTimestamp.Zero, fExperiment.getEpoch());
105 assertEquals("GetNbEvents", NB_EVENTS, fExperiment.getNbEvents());
106
107 long nbTraceEvents = fExperiment.getTraces()[0].getNbEvents();
108 assertEquals("GetNbEvents", NB_EVENTS, nbTraceEvents);
109
110 TmfTimeRange timeRange = fExperiment.getTimeRange();
111 assertTrue("getStartTime", fStartTime.equals(timeRange.getStartTime()));
112 assertTrue("getEndTime", fEndTime.equals(timeRange.getEndTime()));
113 }
114
115 }
This page took 0.032533 seconds and 5 git commands to generate.