~ubuntu-branches/ubuntu/trusty/eclipse-linuxtools/trusty

« back to all changes in this revision

Viewing changes to lttng/org.eclipse.linuxtools.lttng.core.tests/src/org/eclipse/linuxtools/lttng/core/tests/trace/LTTngExperimentTest.java

  • Committer: Package Import Robot
  • Author(s): Jakub Adam
  • Date: 2012-06-29 12:07:30 UTC
  • Revision ID: package-import@ubuntu.com-20120629120730-bfri1xys1i71dpn6
Tags: upstream-1.0.0
ImportĀ upstreamĀ versionĀ 1.0.0

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
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.core.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.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;
 
32
 
 
33
/**
 
34
 * <b><u>TmfExperimentTest</u></b>
 
35
 * <p>
 
36
 * TODO: Implement me. Please.
 
37
 */
 
38
@SuppressWarnings("nls")
 
39
public 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
 
47
    private static final TmfTimestamp  fStartTime = new LttngTimestamp(13589759412128L);
 
48
    private static final TmfTimestamp  fEndTime   = new LttngTimestamp(13589906758692L);
 
49
 
 
50
    private static ITmfTrace<LttngEvent>[] fTestTraces;
 
51
    private static TestExperiment fExperiment;
 
52
 
 
53
    // ------------------------------------------------------------------------
 
54
    // Helper class
 
55
    // ------------------------------------------------------------------------
 
56
 
 
57
    private static class TestExperiment extends TmfExperiment<LttngEvent> {
 
58
        public TestExperiment() {
 
59
            super(LttngEvent.class, EXPERIMENT, fTestTraces, 1000);
 
60
            getIndexer().buildIndex(0, TmfTimeRange.ETERNITY, true);
 
61
        }
 
62
    }
 
63
 
 
64
    // ------------------------------------------------------------------------
 
65
    // Housekeeping
 
66
    // ------------------------------------------------------------------------
 
67
 
 
68
    @SuppressWarnings("unchecked")
 
69
    private synchronized static ITmfTrace<LttngEvent>[] setupTrace(final String path) {
 
70
        if (fTestTraces == null) {
 
71
            fTestTraces = new ITmfTrace[1];
 
72
            try {
 
73
                final URL location = FileLocator.find(FrameworkUtil.getBundle(LTTngExperimentTest.class), new Path(path), null);
 
74
                final File testfile = new File(FileLocator.toFileURL(location).toURI());
 
75
                final LTTngTrace trace = new LTTngTrace(null, testfile.getPath(), false);
 
76
                fTestTraces[0] = trace;
 
77
            } catch (final URISyntaxException e) {
 
78
                e.printStackTrace();
 
79
            } catch (final IOException e) {
 
80
                e.printStackTrace();
 
81
            } catch (final Exception e) {
 
82
                e.printStackTrace();
 
83
            }
 
84
        }
 
85
        return fTestTraces;
 
86
    }
 
87
 
 
88
    private synchronized static void setupExperiment() {
 
89
        if (fExperiment == null) {
 
90
            fExperiment = new TestExperiment();
 
91
        }
 
92
    }
 
93
 
 
94
    public LTTngExperimentTest(final String name) throws Exception {
 
95
        super(name);
 
96
    }
 
97
 
 
98
    @Override
 
99
    protected void setUp() throws Exception {
 
100
        super.setUp();
 
101
        setupTrace(DIRECTORY + File.separator + TEST_STREAM);
 
102
        setupExperiment();
 
103
    }
 
104
 
 
105
    @Override
 
106
    protected void tearDown() throws Exception {
 
107
        super.tearDown();
 
108
    }
 
109
 
 
110
    // ------------------------------------------------------------------------
 
111
    // Constructor
 
112
    // ------------------------------------------------------------------------
 
113
 
 
114
    public void testBasicTmfExperimentConstructor() {
 
115
 
 
116
        assertEquals("GetId", EXPERIMENT, fExperiment.getName());
 
117
        assertEquals("GetNbEvents", NB_EVENTS, fExperiment.getNbEvents());
 
118
 
 
119
        final long nbTraceEvents = fExperiment.getTraces()[0].getNbEvents();
 
120
        assertEquals("GetNbEvents", NB_EVENTS, nbTraceEvents);
 
121
 
 
122
        final TmfTimeRange timeRange = fExperiment.getTimeRange();
 
123
        assertEquals("getStartTime", fStartTime, timeRange.getStartTime());
 
124
        assertEquals("getEndTime", fEndTime, timeRange.getEndTime());
 
125
    }
 
126
 
 
127
}
 
 
b'\\ No newline at end of file'