2de5d6b7f1c92d0e8068db7daa3326bb2e97d086
[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 public class LTTngExperimentTest extends TestCase {
38
39 private static final String DIRECTORY = "traceset";
40 private static final String TEST_STREAM = "trace-15316events_nolost_newformat";
41 private static final String EXPERIMENT = "MyExperiment";
42 private static int NB_EVENTS = 15316;
43
44 // Note: Start/end times are for the LTTng *trace*, not the actual events
45 private static final TmfTimestamp fStartTime = new TmfTimestamp(13589692331524L, (byte) -9);
46 private static final TmfTimestamp fEndTime = new TmfTimestamp(13589907059242L, (byte) -9);
47
48 private static ITmfTrace[] fTraces;
49 private static LTTngExperiment<TmfEvent> fExperiment;
50
51 // ------------------------------------------------------------------------
52 // Housekeeping
53 // ------------------------------------------------------------------------
54
55 private synchronized static ITmfTrace[] setupTrace(String path) {
56 if (fTraces == null) {
57 fTraces = new ITmfTrace[1];
58 try {
59 URL location = FileLocator.find(LTTngCoreTestPlugin.getPlugin().getBundle(), new Path(path), null);
60 File testfile = new File(FileLocator.toFileURL(location).toURI());
61 LTTngTrace trace = new LTTngTrace(testfile.getPath());
62 fTraces[0] = trace;
63 } catch (URISyntaxException e) {
64 e.printStackTrace();
65 } catch (IOException e) {
66 e.printStackTrace();
67 } catch (Exception e) {
68 e.printStackTrace();
69 }
70 }
71 return fTraces;
72 }
73
74 private synchronized static void setupExperiment() {
75 if (fExperiment == null) {
76 fExperiment = new LTTngExperiment<TmfEvent>(TmfEvent.class, EXPERIMENT, fTraces, TmfTimestamp.Zero, 1000, true);
77 }
78 }
79
80 public LTTngExperimentTest(String name) throws Exception {
81 super(name);
82 }
83
84 @Override
85 protected void setUp() throws Exception {
86 super.setUp();
87 setupTrace(DIRECTORY + File.separator + TEST_STREAM);
88 setupExperiment();
89 }
90
91 @Override
92 protected void tearDown() throws Exception {
93 super.tearDown();
94 }
95
96 // ------------------------------------------------------------------------
97 // Constructor
98 // ------------------------------------------------------------------------
99
100 public void testBasicTmfExperimentConstructor() {
101
102 assertEquals("GetId", EXPERIMENT, fExperiment.getName());
103 assertEquals("GetEpoch", TmfTimestamp.Zero, fExperiment.getEpoch());
104 assertEquals("GetNbEvents", NB_EVENTS, fExperiment.getNbEvents());
105
106 long nbTraceEvents = fExperiment.getTraces()[0].getNbEvents();
107 assertEquals("GetNbEvents", NB_EVENTS, nbTraceEvents);
108
109 TmfTimeRange timeRange = fExperiment.getTimeRange();
110 assertTrue("getStartTime", fStartTime.equals(timeRange.getStartTime()));
111 assertTrue("getEndTime", fEndTime.equals(timeRange.getEndTime()));
112 }
113
114 }
This page took 0.03475 seconds and 4 git commands to generate.