1 /*******************************************************************************
2 * Copyright (c) 2014 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 * Matthew Khouzam - Initial API and implementation
11 *******************************************************************************/
12 package org
.eclipse
.tracecompass
.btf
.core
.tests
.trace
;
14 import static org
.junit
.Assert
.*;
16 import java
.io
.IOException
;
19 import org
.eclipse
.tracecompass
.btf
.core
.tests
.utils
.BtfTestTrace
;
20 import org
.eclipse
.tracecompass
.btf
.core
.trace
.BtfTrace
;
21 import org
.eclipse
.tracecompass
.tmf
.core
.event
.ITmfEvent
;
22 import org
.eclipse
.tracecompass
.tmf
.core
.trace
.ITmfContext
;
23 import org
.eclipse
.tracecompass
.tmf
.core
.trace
.TraceValidationStatus
;
24 import org
.junit
.After
;
25 import org
.junit
.Before
;
26 import org
.junit
.Test
;
29 * Best trace format test cases
31 * @author Matthew Khouzam
33 public class BtfTraceTest
{
35 private static final long START_TIME
= 1392809960000000000L;
37 private BtfTrace fixture
;
40 * Does the trace exist?
44 fixture
= BtfTestTrace
.BTF_TEST
.getTrace();
45 assertNotNull(fixture
);
52 public void cleanup() {
55 } catch (IOException e
) {}
62 public void testValidate(){
63 TraceValidationStatus status
= (TraceValidationStatus
) fixture
.validate(null, fixture
.getPath());
64 assertNotNull(status
);
65 assertTrue(status
.isOK());
66 assertEquals(100, status
.getConfidence());
71 * Seek the first event
74 public void testSeek1stEvent() {
75 ITmfContext ctx
= fixture
.seekEvent(0);
77 assertEquals(0, ctx
.getRank());
78 assertEquals(499L, ctx
.getLocation().getLocationInfo());
82 * Read the first event
85 public void testRead1stEvent() {
86 ITmfContext ctx
= fixture
.seekEvent(0);
87 ITmfEvent event
= fixture
.getNext(ctx
);
89 assertEquals(START_TIME
, event
.getTimestamp().getValue());
93 * Read the tenth event
96 public void testRead10thEvent1() {
97 ITmfContext ctx
= fixture
.seekEvent(10);
98 ITmfEvent event
= fixture
.getNext(ctx
);
100 assertEquals(START_TIME
, event
.getTimestamp().getValue());
104 * Read the tenth event without seeking
107 public void testRead10thEvent2() {
108 ITmfContext ctx
= fixture
.seekEvent(0);
109 ITmfEvent event
= null;
110 for (int i
= 0; i
< 10; i
++) {
111 event
= fixture
.getNext(ctx
);
113 assertNotNull(event
);
114 assertEquals(START_TIME
, event
.getTimestamp().getValue());
118 * Read the trace properties
121 public void testReadProperties() {
122 Map
<String
, String
> data
= fixture
.getTraceProperties();
124 assertEquals("ns", data
.get("#timeScale"));
125 assertEquals("2.1.0", data
.get("#version"));
132 public void testTwoContexts() {
133 ITmfContext ctx0
= fixture
.seekEvent(0);
134 ITmfContext ctx1
= fixture
.seekEvent(10);
135 ITmfEvent event
= null;
136 for (int i
= 0; i
< 11; i
++) {
137 event
= fixture
.getNext(ctx0
);
139 ITmfEvent event1
= fixture
.getNext(ctx1
);
140 assertNotNull(event
);
141 assertNotNull(event1
);
142 assertEquals(event
, event1
);