Add a TmfLegacyExperiment for the LTTng 0.x
[deliverable/tracecompass.git] / org.eclipse.linuxtools.lttng.core.tests / src / org / eclipse / linuxtools / lttng / core / 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
6c13869b 13package org.eclipse.linuxtools.lttng.core.tests.trace;
82e04272
FC
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;
5945cec9 24import org.eclipse.linuxtools.internal.lttng.core.event.LttngEvent;
c7e1020d 25import org.eclipse.linuxtools.internal.lttng.core.event.LttngTimestamp;
5945cec9 26import org.eclipse.linuxtools.internal.lttng.core.trace.LTTngTrace;
6c13869b
FC
27import org.eclipse.linuxtools.tmf.core.event.TmfTimeRange;
28import org.eclipse.linuxtools.tmf.core.event.TmfTimestamp;
c32744d6 29import org.eclipse.linuxtools.tmf.core.experiment.TmfLegacyExperiment;
6c13869b 30import org.eclipse.linuxtools.tmf.core.trace.ITmfTrace;
9269df72 31import org.osgi.framework.FrameworkUtil;
82e04272
FC
32
33/**
34 * <b><u>TmfExperimentTest</u></b>
35 * <p>
36 * TODO: Implement me. Please.
37 */
3b38ea61 38@SuppressWarnings("nls")
82e04272
FC
39public class LTTngExperimentTest extends TestCase {
40
41 private static final String DIRECTORY = "traceset";
42 private static final String TEST_STREAM = "trace-15316events_nolost_newformat";
43 private static final String EXPERIMENT = "MyExperiment";
44 private static int NB_EVENTS = 15316;
45
46 // Note: Start/end times are for the LTTng *trace*, not the actual events
c7e1020d
FC
47 private static final TmfTimestamp fStartTime = new LttngTimestamp(13589759412128L);
48 private static final TmfTimestamp fEndTime = new LttngTimestamp(13589906758692L);
82e04272 49
c7e1020d 50 private static ITmfTrace<LttngEvent>[] fTestTraces;
c32744d6 51 private static TmfLegacyExperiment<LttngEvent> fExperiment;
82e04272
FC
52
53 // ------------------------------------------------------------------------
54 // Housekeeping
55 // ------------------------------------------------------------------------
56
12c155f5 57 @SuppressWarnings("unchecked")
25e48683 58 private synchronized static ITmfTrace<LttngEvent>[] setupTrace(final String path) {
c7e1020d
FC
59 if (fTestTraces == null) {
60 fTestTraces = new ITmfTrace[1];
25e48683
FC
61 try {
62 final URL location = FileLocator.find(FrameworkUtil.getBundle(LTTngExperimentTest.class), new Path(path), null);
63 final File testfile = new File(FileLocator.toFileURL(location).toURI());
07671572 64 final LTTngTrace trace = new LTTngTrace(null, testfile.getPath(), true);
c7e1020d 65 fTestTraces[0] = trace;
25e48683
FC
66 } catch (final URISyntaxException e) {
67 e.printStackTrace();
68 } catch (final IOException e) {
69 e.printStackTrace();
70 } catch (final Exception e) {
71 e.printStackTrace();
72 }
73 }
c7e1020d 74 return fTestTraces;
82e04272
FC
75 }
76
77 private synchronized static void setupExperiment() {
c7e1020d
FC
78 if (fExperiment == null) {
79 fExperiment = new TmfLegacyExperiment<LttngEvent>(LttngEvent.class, EXPERIMENT, fTestTraces, TmfTimestamp.ZERO, 1000, true);
80 }
82e04272
FC
81 }
82
25e48683
FC
83 public LTTngExperimentTest(final String name) throws Exception {
84 super(name);
85 }
82e04272 86
25e48683
FC
87 @Override
88 protected void setUp() throws Exception {
89 super.setUp();
90 setupTrace(DIRECTORY + File.separator + TEST_STREAM);
91 setupExperiment();
92 }
82e04272 93
25e48683
FC
94 @Override
95 protected void tearDown() throws Exception {
96 super.tearDown();
97 }
82e04272
FC
98
99 // ------------------------------------------------------------------------
100 // Constructor
101 // ------------------------------------------------------------------------
102
25e48683 103 public void testBasicTmfExperimentConstructor() {
82e04272 104
25e48683 105 assertEquals("GetId", EXPERIMENT, fExperiment.getName());
82e04272
FC
106 assertEquals("GetNbEvents", NB_EVENTS, fExperiment.getNbEvents());
107
25e48683 108 final long nbTraceEvents = fExperiment.getTraces()[0].getNbEvents();
82e04272
FC
109 assertEquals("GetNbEvents", NB_EVENTS, nbTraceEvents);
110
25e48683 111 final TmfTimeRange timeRange = fExperiment.getTimeRange();
c7e1020d
FC
112 assertEquals("getStartTime", fStartTime, timeRange.getStartTime());
113 assertEquals("getEndTime", fEndTime, timeRange.getEndTime());
25e48683 114 }
82e04272
FC
115
116}
This page took 0.035534 seconds and 5 git commands to generate.