btf: Initial Best Trace Format commit
[deliverable/tracecompass.git] / org.eclipse.linuxtools.btf.core.tests / src / org / eclipse / linuxtools / btf / core / tests / trace / BtfTraceTest.java
1 /*******************************************************************************
2 * Copyright (c) 2014 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 * Matthew Khouzam - Initial API and implementation
11 *******************************************************************************/
12 package org.eclipse.linuxtools.btf.core.tests.trace;
13
14 import static org.junit.Assert.*;
15
16 import java.io.IOException;
17 import java.util.Map;
18
19 import org.eclipse.linuxtools.btf.core.tests.utils.BtfTestTrace;
20 import org.eclipse.linuxtools.btf.core.trace.BtfTrace;
21 import org.eclipse.linuxtools.tmf.core.event.ITmfEvent;
22 import org.eclipse.linuxtools.tmf.core.trace.ITmfContext;
23 import org.eclipse.linuxtools.tmf.core.trace.TraceValidationStatus;
24 import org.junit.After;
25 import org.junit.Before;
26 import org.junit.Test;
27
28 /**
29 * Best trace format test cases
30 *
31 * @author Matthew Khouzam
32 */
33 public class BtfTraceTest {
34
35 private static final long START_TIME = 1392809960000000000L;
36
37 private BtfTrace fixture;
38
39 /**
40 * Does the trace exist?
41 */
42 @Before
43 public void setup() {
44 fixture = BtfTestTrace.BTF_TEST.getTrace();
45 assertNotNull(fixture);
46 }
47
48 /**
49 * Cleanup
50 */
51 @After
52 public void cleanup() {
53 try {
54 fixture.close();
55 } catch (IOException e) {}
56 }
57
58 /**
59 * Tests validation
60 */
61 @Test
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());
67
68 }
69
70 /**
71 * Seek the first event
72 */
73 @Test
74 public void testSeek1stEvent() {
75 ITmfContext ctx = fixture.seekEvent(0);
76 assertNotNull(ctx);
77 assertEquals(0, ctx.getRank());
78 assertEquals(499L, ctx.getLocation().getLocationInfo());
79 }
80
81 /**
82 * Read the first event
83 */
84 @Test
85 public void testRead1stEvent() {
86 ITmfContext ctx = fixture.seekEvent(0);
87 ITmfEvent event = fixture.getNext(ctx);
88 assertNotNull(event);
89 assertEquals(START_TIME, event.getTimestamp().getValue());
90 }
91
92 /**
93 * Read the tenth event
94 */
95 @Test
96 public void testRead10thEvent1() {
97 ITmfContext ctx = fixture.seekEvent(10);
98 ITmfEvent event = fixture.getNext(ctx);
99 assertNotNull(event);
100 assertEquals(START_TIME, event.getTimestamp().getValue());
101 }
102
103 /**
104 * Read the tenth event without seeking
105 */
106 @Test
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);
112 }
113 assertNotNull(event);
114 assertEquals(START_TIME, event.getTimestamp().getValue());
115 }
116
117 /**
118 * Read the trace properties
119 */
120 @Test
121 public void testReadProperties() {
122 Map<String, String> data = fixture.getTraceProperties();
123 assertNotNull(data);
124 assertEquals("ns", data.get("#timeScale"));
125 assertEquals("2.1.0", data.get("#version"));
126 }
127
128 /**
129 * Read two contexts
130 */
131 @Test
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);
138 }
139 ITmfEvent event1 = fixture.getNext(ctx1);
140 assertNotNull(event);
141 assertNotNull(event1);
142 assertEquals(event, event1);
143 }
144 }
This page took 0.040173 seconds and 5 git commands to generate.