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