rcp: Move plugins to their own sub-directory
[deliverable/tracecompass.git] / org.eclipse.tracecompass.ctf.core.tests / src / org / eclipse / tracecompass / ctf / core / tests / trace / MetadataTest.java
1 /*******************************************************************************
2 * Copyright (c) 2013, 2014 Ericsson
3 * All rights reserved. This program and the accompanying materials
4 * are made available under the terms of the Eclipse Public License v1.0
5 * which accompanies this distribution, and is available at
6 * http://www.eclipse.org/legal/epl-v10.html
7 *
8 * Contributors:
9 * Matthew Khouzam - Initial API and implementation
10 *******************************************************************************/
11
12 package org.eclipse.tracecompass.ctf.core.tests.trace;
13
14 import static org.junit.Assert.assertEquals;
15 import static org.junit.Assert.assertNotNull;
16 import static org.junit.Assert.assertNull;
17 import static org.junit.Assert.fail;
18 import static org.junit.Assume.assumeTrue;
19
20 import java.nio.ByteOrder;
21 import java.util.ArrayList;
22 import java.util.List;
23 import java.util.UUID;
24
25 import org.eclipse.tracecompass.ctf.core.CTFException;
26 import org.eclipse.tracecompass.ctf.core.event.IEventDeclaration;
27 import org.eclipse.tracecompass.ctf.core.tests.shared.CtfTestTrace;
28 import org.eclipse.tracecompass.ctf.core.trace.CTFStream;
29 import org.eclipse.tracecompass.ctf.core.trace.CTFTrace;
30 import org.eclipse.tracecompass.ctf.core.trace.Metadata;
31 import org.junit.Before;
32 import org.junit.Test;
33
34 /**
35 * The class <code>MetadataTest</code> contains tests for the class
36 * <code>{@link Metadata}</code>.
37 *
38 * @author ematkho
39 * @version $Revision: 1.0 $
40 */
41 @SuppressWarnings("javadoc")
42 public class MetadataTest {
43
44 private static final CtfTestTrace testTrace = CtfTestTrace.KERNEL;
45 private static final String mdStart = "typealias integer { size = 8; align = 8; signed = false; } := uint8_t;\n" +
46 " typealias integer { size = 16; align = 8; signed = false; } := uint16_t;\n" +
47 " typealias integer { size = 32; align = 8; signed = false; } := uint32_t;\n" +
48 " typealias integer { size = 64; align = 8; signed = false; } := uint64_t;\n" +
49 " typealias integer { size = 64; align = 8; signed = false; } := unsigned long;\n" +
50 " typealias integer { size = 5; align = 1; signed = false; } := uint5_t;\n" +
51 " typealias integer { size = 27; align = 1; signed = false; } := uint27_t;\n" +
52 "" +
53 " trace {\n" +
54 " major = 1;\n" +
55 " minor = 8;\n" +
56 " uuid = \"8b1258ba-effb-554b-b779-fbd676746000\";\n" +
57 " byte_order = le;\n" +
58 " packet.header := struct {\n" +
59 " uint32_t magic;\n" +
60 " uint8_t uuid[16];\n" +
61 " uint32_t stream_id;\n" +
62 " };\n" +
63 " };\n" +
64 "" +
65 " env {\n" +
66 " hostname = \"computer\";\n" +
67 " domain = \"kernel\";\n" +
68 " sysname = \"BeOS\";\n" +
69 " kernel_release = \"95\";\n" +
70 " kernel_version = \"BeWare 95\";\n" +
71 " tracer_name = \"BeOS Tracer\";\n" +
72 " tracer_major = 2;\n" +
73 " tracer_minor = 3;\n" +
74 " tracer_patchlevel = 0;\n" +
75 " };\n" +
76 " clock {\n" +
77 " name = monotonic;\n" +
78 " uuid = \"4d737a79-e3f1-4f4d-a649-42015266baf5\";\n" +
79 " description = \"Monotonic Clock\";\n" +
80 " freq = 1000000000; /* Frequency, in Hz */\n" +
81 " /* clock value offset from Epoch is: offset * (1/freq) */\n" +
82 " offset = 1383600210829415521;\n" +
83 " };\n" +
84
85 " typealias integer {\n" +
86 "size = 27; align = 1; signed = false;\n" +
87 " map = clock.monotonic.value;\n" +
88 " } := uint27_clock_monotonic_t;\n" +
89 " \n" +
90 " typealias integer {\n" +
91 " size = 32; align = 8; signed = false;\n" +
92 " map = clock.monotonic.value;\n" +
93 " } := uint32_clock_monotonic_t;\n" +
94 " \n" +
95 " typealias integer {\n" +
96 " size = 64; align = 8; signed = false;\n" +
97 " map = clock.monotonic.value;\n" +
98 " } := uint64_clock_monotonic_t;\n" +
99 " \n" +
100 " struct packet_context {\n" +
101 " uint64_clock_monotonic_t timestamp_begin;\n" +
102 " uint64_clock_monotonic_t timestamp_end;\n" +
103 " uint64_t content_size;\n" +
104 " uint64_t packet_size;\n" +
105 " unsigned long events_discarded;\n" +
106 " uint32_t cpu_id;\n" +
107 " };\n" +
108 " \n" +
109 " struct event_header_compact {\n" +
110 " enum : uint5_t { compact = 0 ... 30, extended = 31 } id;\n" +
111 " variant <id> {\n" +
112 " struct {\n" +
113 " uint27_clock_monotonic_t timestamp;\n" +
114 " } compact;\n" +
115 " struct {\n" +
116 " uint32_t id;\n" +
117 " uint64_clock_monotonic_t timestamp;\n" +
118 " } extended;\n" +
119 " } v;\n" +
120 " } align(8);\n" +
121 " \n" +
122 " struct event_header_large {\n" +
123 " enum : uint16_t { compact = 0 ... 65534, extended = 65535 } id;\n" +
124 " variant <id> {\n" +
125 " struct {\n" +
126 " uint32_clock_monotonic_t timestamp;\n" +
127 " } compact;\n" +
128 " struct {\n" +
129 " uint32_t id;\n" +
130 " uint64_clock_monotonic_t timestamp;\n" +
131 " } extended;\n" +
132 " } v;\n" +
133 " } align(8);\n" +
134 " \n" +
135 " stream {\n" +
136 " id = 0;\n" +
137 " event.header := struct event_header_compact;\n" +
138 " packet.context := struct packet_context;\n" +
139 " };\n" +
140 " \n" +
141 " event {\n" +
142 " name = sched_switch;\n" +
143 " id = 0;\n" +
144 " stream_id = 0;\n" +
145 " fields := struct {\n" +
146 " integer { size = 8; align = 8; signed = 1; encoding = UTF8; base = 10; } _prev_comm[16];\n" +
147 " integer { size = 32; align = 8; signed = 1; encoding = none; base = 10; } _prev_tid;\n" +
148 " integer { size = 32; align = 8; signed = 1; encoding = none; base = 10; } _prev_prio;\n" +
149 " integer { size = 64; align = 8; signed = 1; encoding = none; base = 10; } _prev_state;\n" +
150 " integer { size = 8; align = 8; signed = 1; encoding = UTF8; base = 10; } _next_comm[16];\n" +
151 " integer { size = 32; align = 8; signed = 1; encoding = none; base = 10; } _next_tid;\n" +
152 " integer { size = 32; align = 8; signed = 1; encoding = none; base = 10; } _next_prio;\n" +
153 " };\n" +
154 " };";
155
156 private static final String mdSecond = " event {\n" +
157 " name = bozo_the_clown;\n" +
158 " id = 1;\n" +
159 " stream_id = 0;\n" +
160 " fields := struct {\n" +
161 " integer { size = 32; align = 8; signed = 1; encoding = none; base = 10; } clown_nose;\n" +
162 " };\n" +
163 " };";
164
165 private Metadata fixture;
166
167 /**
168 * Perform pre-test initialization.
169 *
170 * @throws CTFException
171 */
172 @Before
173 public void setUp() throws CTFException {
174 assumeTrue(testTrace.exists());
175 fixture = new Metadata(testTrace.getTrace());
176 }
177
178 /**
179 * Run the Metadata(CTFTrace) constructor test.
180 */
181 @Test
182 public void testMetadata() {
183 assertNotNull(fixture);
184 }
185
186 @Test
187 public void testTextMD() throws CTFException {
188 testSingleFragment();
189 }
190
191 protected CTFTrace testSingleFragment() throws CTFException {
192 fixture = new Metadata();
193 CTFTrace trace = fixture.getTrace();
194 for (CTFStream s : trace.getStreams()) {
195 fail("This should be empty, has" + s.toString());
196 }
197 fixture.parseText(mdStart);
198 int count = 0;
199 for (CTFStream s : trace.getStreams()) {
200 count++;
201 assertNotNull(s);
202 }
203 assertEquals(1, count);
204 assertEquals(1, trace.getEventDeclarations(0L).size());
205 return trace;
206 }
207
208 @Test
209 public void testStreamTextMD() throws CTFException {
210 CTFTrace trace = testSingleFragment();
211 fixture.parseTextFragment(mdSecond);
212 final List<IEventDeclaration> eventDeclarations = new ArrayList<>(trace.getEventDeclarations(0L));
213 assertEquals(2, eventDeclarations.size());
214 assertEquals("bozo_the_clown", eventDeclarations.get(1).getName());
215 }
216
217 /**
218 * Run the ByteOrder getDetectedByteOrder() method test.
219 *
220 * @throws CTFException
221 */
222 @Test
223 public void testGetDetectedByteOrder() throws CTFException {
224 setUp();
225 ByteOrder result = fixture.getDetectedByteOrder();
226 assertNull(result);
227 }
228
229 /**
230 * Test toString
231 *
232 * @throws CTFException
233 */
234 @Test
235 public void testToString() throws CTFException {
236 setUp();
237 String result = fixture.toString();
238 assertNotNull(result);
239 }
240
241 /**
242 * Run the void parse() method test.
243 *
244 * @throws CTFException
245 */
246 @Test
247 public void testParse() throws CTFException {
248 setUp();
249 assertEquals(new UUID(0xd18e637435a1cd42L, 0x8e70a9cffa712793L), testTrace.getTrace().getUUID());
250 assertEquals(1332166405241713920.0, testTrace.getTrace().getClock().getClockOffset(), 200.0);
251 assertEquals(8, testTrace.getTrace().getEnvironment().size());
252 }
253 }
This page took 0.036395 seconds and 5 git commands to generate.