Commit | Line | Data |
---|---|---|
ff71e543 MK |
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 | *******************************************************************************/ | |
7ce90559 | 12 | package org.eclipse.tracecompass.btf.core.tests.trace; |
ff71e543 MK |
13 | |
14 | import static org.junit.Assert.*; | |
15 | ||
ff71e543 MK |
16 | import java.util.Map; |
17 | ||
7ce90559 AM |
18 | import org.eclipse.tracecompass.btf.core.tests.utils.BtfTestTrace; |
19 | import org.eclipse.tracecompass.btf.core.trace.BtfTrace; | |
2bdf0193 AM |
20 | import org.eclipse.tracecompass.tmf.core.event.ITmfEvent; |
21 | import org.eclipse.tracecompass.tmf.core.trace.ITmfContext; | |
22 | import org.eclipse.tracecompass.tmf.core.trace.TraceValidationStatus; | |
ff71e543 MK |
23 | import org.junit.After; |
24 | import org.junit.Before; | |
25 | import org.junit.Test; | |
26 | ||
27 | /** | |
28 | * Best trace format test cases | |
29 | * | |
30 | * @author Matthew Khouzam | |
31 | */ | |
32 | public class BtfTraceTest { | |
33 | ||
34 | private static final long START_TIME = 1392809960000000000L; | |
35 | ||
36 | private BtfTrace fixture; | |
37 | ||
38 | /** | |
39 | * Does the trace exist? | |
40 | */ | |
41 | @Before | |
42 | public void setup() { | |
43 | fixture = BtfTestTrace.BTF_TEST.getTrace(); | |
44 | assertNotNull(fixture); | |
45 | } | |
46 | ||
47 | /** | |
48 | * Cleanup | |
49 | */ | |
50 | @After | |
51 | public void cleanup() { | |
d9aa847c | 52 | fixture.dispose(); |
ff71e543 MK |
53 | } |
54 | ||
55 | /** | |
56 | * Tests validation | |
57 | */ | |
58 | @Test | |
59 | public void testValidate(){ | |
60 | TraceValidationStatus status = (TraceValidationStatus) fixture.validate(null, fixture.getPath()); | |
61 | assertNotNull(status); | |
62 | assertTrue(status.isOK()); | |
63 | assertEquals(100, status.getConfidence()); | |
64 | ||
65 | } | |
66 | ||
67 | /** | |
68 | * Seek the first event | |
69 | */ | |
70 | @Test | |
71 | public void testSeek1stEvent() { | |
72 | ITmfContext ctx = fixture.seekEvent(0); | |
73 | assertNotNull(ctx); | |
74 | assertEquals(0, ctx.getRank()); | |
75 | assertEquals(499L, ctx.getLocation().getLocationInfo()); | |
76 | } | |
77 | ||
78 | /** | |
79 | * Read the first event | |
80 | */ | |
81 | @Test | |
82 | public void testRead1stEvent() { | |
83 | ITmfContext ctx = fixture.seekEvent(0); | |
84 | ITmfEvent event = fixture.getNext(ctx); | |
85 | assertNotNull(event); | |
86 | assertEquals(START_TIME, event.getTimestamp().getValue()); | |
87 | } | |
88 | ||
89 | /** | |
90 | * Read the tenth event | |
91 | */ | |
92 | @Test | |
93 | public void testRead10thEvent1() { | |
94 | ITmfContext ctx = fixture.seekEvent(10); | |
95 | ITmfEvent event = fixture.getNext(ctx); | |
96 | assertNotNull(event); | |
97 | assertEquals(START_TIME, event.getTimestamp().getValue()); | |
98 | } | |
99 | ||
100 | /** | |
101 | * Read the tenth event without seeking | |
102 | */ | |
103 | @Test | |
104 | public void testRead10thEvent2() { | |
105 | ITmfContext ctx = fixture.seekEvent(0); | |
106 | ITmfEvent event = null; | |
107 | for (int i = 0; i < 10; i++) { | |
108 | event = fixture.getNext(ctx); | |
109 | } | |
110 | assertNotNull(event); | |
111 | assertEquals(START_TIME, event.getTimestamp().getValue()); | |
112 | } | |
113 | ||
114 | /** | |
115 | * Read the trace properties | |
116 | */ | |
117 | @Test | |
118 | public void testReadProperties() { | |
119 | Map<String, String> data = fixture.getTraceProperties(); | |
120 | assertNotNull(data); | |
121 | assertEquals("ns", data.get("#timeScale")); | |
122 | assertEquals("2.1.0", data.get("#version")); | |
123 | } | |
124 | ||
125 | /** | |
126 | * Read two contexts | |
127 | */ | |
128 | @Test | |
129 | public void testTwoContexts() { | |
130 | ITmfContext ctx0 = fixture.seekEvent(0); | |
131 | ITmfContext ctx1 = fixture.seekEvent(10); | |
132 | ITmfEvent event = null; | |
133 | for (int i = 0; i < 11; i++) { | |
134 | event = fixture.getNext(ctx0); | |
135 | } | |
136 | ITmfEvent event1 = fixture.getNext(ctx1); | |
137 | assertNotNull(event); | |
138 | assertNotNull(event1); | |
139 | assertEquals(event, event1); | |
140 | } | |
141 | } |