1 /*******************************************************************************
2 * Copyright (c) 2009, 2010 Ericsson
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
10 * Francois Chouinard - Initial API and implementation
11 *******************************************************************************/
13 package org
.eclipse
.linuxtools
.lttng
.core
.tests
.trace
;
16 import java
.io
.IOException
;
17 import java
.net
.URISyntaxException
;
20 import junit
.framework
.TestCase
;
22 import org
.eclipse
.core
.runtime
.FileLocator
;
23 import org
.eclipse
.core
.runtime
.Path
;
24 import org
.eclipse
.linuxtools
.internal
.lttng
.core
.event
.LttngEvent
;
25 import org
.eclipse
.linuxtools
.internal
.lttng
.core
.event
.LttngTimestamp
;
26 import org
.eclipse
.linuxtools
.internal
.lttng
.core
.trace
.LTTngTrace
;
27 import org
.eclipse
.linuxtools
.tmf
.core
.event
.TmfTimeRange
;
28 import org
.eclipse
.linuxtools
.tmf
.core
.event
.TmfTimestamp
;
29 import org
.eclipse
.linuxtools
.tmf
.core
.trace
.ITmfTrace
;
30 import org
.eclipse
.linuxtools
.tmf
.core
.trace
.TmfExperiment
;
31 import org
.osgi
.framework
.FrameworkUtil
;
34 * <b><u>TmfExperimentTest</u></b>
36 * TODO: Implement me. Please.
38 @SuppressWarnings("nls")
39 public class LTTngExperimentTest
extends TestCase
{
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;
46 // Note: Start/end times are for the LTTng *trace*, not the actual events
47 private static final TmfTimestamp fStartTime
= new LttngTimestamp(13589759412128L);
48 private static final TmfTimestamp fEndTime
= new LttngTimestamp(13589906758692L);
50 private static ITmfTrace
[] fTestTraces
;
51 private static TestExperiment fExperiment
;
53 // ------------------------------------------------------------------------
55 // ------------------------------------------------------------------------
57 private static class TestExperiment
extends TmfExperiment
{
58 public TestExperiment() {
59 super(LttngEvent
.class, EXPERIMENT
, fTestTraces
, 1000);
60 getIndexer().buildIndex(0, TmfTimeRange
.ETERNITY
, true);
64 // ------------------------------------------------------------------------
66 // ------------------------------------------------------------------------
68 private synchronized static ITmfTrace
[] setupTrace(final String path
) {
69 if (fTestTraces
== null) {
70 fTestTraces
= new ITmfTrace
[1];
72 final URL location
= FileLocator
.find(FrameworkUtil
.getBundle(LTTngExperimentTest
.class), new Path(path
), null);
73 final File testfile
= new File(FileLocator
.toFileURL(location
).toURI());
74 final LTTngTrace trace
= new LTTngTrace(null, testfile
.getPath(), false);
75 fTestTraces
[0] = trace
;
76 } catch (final URISyntaxException e
) {
78 } catch (final IOException e
) {
80 } catch (final Exception e
) {
87 private synchronized static void setupExperiment() {
88 if (fExperiment
== null) {
89 fExperiment
= new TestExperiment();
93 public LTTngExperimentTest(final String name
) throws Exception
{
98 protected void setUp() throws Exception
{
100 setupTrace(DIRECTORY
+ File
.separator
+ TEST_STREAM
);
105 protected void tearDown() throws Exception
{
109 // ------------------------------------------------------------------------
111 // ------------------------------------------------------------------------
113 public void testBasicTmfExperimentConstructor() {
115 assertEquals("GetId", EXPERIMENT
, fExperiment
.getName());
116 assertEquals("GetNbEvents", NB_EVENTS
, fExperiment
.getNbEvents());
118 final long nbTraceEvents
= fExperiment
.getTraces()[0].getNbEvents();
119 assertEquals("GetNbEvents", NB_EVENTS
, nbTraceEvents
);
121 final TmfTimeRange timeRange
= fExperiment
.getTimeRange();
122 assertEquals("getStartTime", fStartTime
, timeRange
.getStartTime());
123 assertEquals("getEndTime", fEndTime
, timeRange
.getEndTime());