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