Commit | Line | Data |
---|---|---|
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 | ||
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; | |
12c155f5 | 24 | import org.eclipse.linuxtools.lttng.event.LttngEvent; |
82e04272 | 25 | import org.eclipse.linuxtools.lttng.tests.LTTngCoreTestPlugin; |
82e04272 | 26 | import org.eclipse.linuxtools.lttng.trace.LTTngTrace; |
82e04272 FC |
27 | import org.eclipse.linuxtools.tmf.event.TmfTimeRange; |
28 | import org.eclipse.linuxtools.tmf.event.TmfTimestamp; | |
c5b45b39 | 29 | import org.eclipse.linuxtools.tmf.experiment.TmfExperiment; |
82e04272 FC |
30 | import 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 |
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 | |
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 | 49 | private static ITmfTrace<LttngEvent>[] fTraces; |
c5b45b39 | 50 | private static TmfExperiment<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()); | |
c5b45b39 | 63 | LTTngTrace trace = new LTTngTrace(testfile.getPath(), false); |
82e04272 FC |
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) { | |
c5b45b39 | 78 | fExperiment = new TmfExperiment<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 | } |