Commit | Line | Data |
---|---|---|
4bd7f2db | 1 | /******************************************************************************* |
60ae41e1 | 2 | * Copyright (c) 2013, 2014 Ericsson |
4bd7f2db AM |
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 | ||
f357bcd4 | 12 | package org.eclipse.tracecompass.ctf.core.tests.trace; |
866e5b51 | 13 | |
58129ff7 | 14 | import static org.junit.Assert.assertEquals; |
866e5b51 FC |
15 | import static org.junit.Assert.assertNotNull; |
16 | import static org.junit.Assert.assertNull; | |
58129ff7 | 17 | import static org.junit.Assert.fail; |
866e5b51 FC |
18 | |
19 | import java.nio.ByteOrder; | |
5f715709 MK |
20 | import java.util.ArrayList; |
21 | import java.util.List; | |
58129ff7 | 22 | import java.util.UUID; |
866e5b51 | 23 | |
680f9173 | 24 | import org.eclipse.tracecompass.ctf.core.CTFException; |
f357bcd4 | 25 | import org.eclipse.tracecompass.ctf.core.event.IEventDeclaration; |
c4d57ac1 | 26 | import org.eclipse.tracecompass.ctf.core.tests.shared.CtfTestTraceUtils; |
f357bcd4 AM |
27 | import org.eclipse.tracecompass.ctf.core.trace.CTFStream; |
28 | import org.eclipse.tracecompass.ctf.core.trace.CTFTrace; | |
29 | import org.eclipse.tracecompass.ctf.core.trace.Metadata; | |
c4d57ac1 | 30 | import org.eclipse.tracecompass.testtraces.ctf.CtfTestTrace; |
866e5b51 FC |
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>. | |
e291b8c8 | 37 | * |
866e5b51 FC |
38 | * @author ematkho |
39 | * @version $Revision: 1.0 $ | |
40 | */ | |
be6df2d8 | 41 | @SuppressWarnings("javadoc") |
866e5b51 FC |
42 | public class MetadataTest { |
43 | ||
9ac63b5b | 44 | private static final CtfTestTrace testTrace = CtfTestTrace.KERNEL; |
58129ff7 MK |
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 | " };"; | |
32bf80d2 | 164 | |
866e5b51 FC |
165 | private Metadata fixture; |
166 | ||
866e5b51 FC |
167 | /** |
168 | * Perform pre-test initialization. | |
be6df2d8 | 169 | * |
680f9173 | 170 | * @throws CTFException |
866e5b51 FC |
171 | */ |
172 | @Before | |
680f9173 | 173 | public void setUp() throws CTFException { |
c4d57ac1 | 174 | fixture = new Metadata(CtfTestTraceUtils.getTrace(testTrace)); |
866e5b51 FC |
175 | } |
176 | ||
866e5b51 FC |
177 | /** |
178 | * Run the Metadata(CTFTrace) constructor test. | |
179 | */ | |
180 | @Test | |
181 | public void testMetadata() { | |
182 | assertNotNull(fixture); | |
183 | } | |
184 | ||
58129ff7 | 185 | @Test |
680f9173 | 186 | public void testTextMD() throws CTFException { |
58129ff7 MK |
187 | testSingleFragment(); |
188 | } | |
189 | ||
680f9173 | 190 | protected CTFTrace testSingleFragment() throws CTFException { |
58129ff7 MK |
191 | fixture = new Metadata(); |
192 | CTFTrace trace = fixture.getTrace(); | |
d84419e1 | 193 | for (CTFStream s : trace.getStreams()) { |
58129ff7 MK |
194 | fail("This should be empty, has" + s.toString()); |
195 | } | |
196 | fixture.parseText(mdStart); | |
197 | int count = 0; | |
d84419e1 | 198 | for (CTFStream s : trace.getStreams()) { |
58129ff7 MK |
199 | count++; |
200 | assertNotNull(s); | |
201 | } | |
202 | assertEquals(1, count); | |
5f715709 | 203 | assertEquals(1, trace.getEventDeclarations(0L).size()); |
58129ff7 MK |
204 | return trace; |
205 | } | |
206 | ||
207 | @Test | |
680f9173 | 208 | public void testStreamTextMD() throws CTFException { |
b562a24f MK |
209 | CTFTrace trace = testSingleFragment(); |
210 | fixture.parseTextFragment(mdSecond); | |
211 | final List<IEventDeclaration> eventDeclarations = new ArrayList<>(trace.getEventDeclarations(0L)); | |
212 | assertEquals(2, eventDeclarations.size()); | |
213 | assertEquals("bozo_the_clown", eventDeclarations.get(1).getName()); | |
58129ff7 MK |
214 | } |
215 | ||
866e5b51 FC |
216 | /** |
217 | * Run the ByteOrder getDetectedByteOrder() method test. | |
58129ff7 | 218 | * |
680f9173 | 219 | * @throws CTFException |
866e5b51 FC |
220 | */ |
221 | @Test | |
680f9173 | 222 | public void testGetDetectedByteOrder() throws CTFException { |
58129ff7 | 223 | setUp(); |
866e5b51 FC |
224 | ByteOrder result = fixture.getDetectedByteOrder(); |
225 | assertNull(result); | |
226 | } | |
227 | ||
e291b8c8 MK |
228 | /** |
229 | * Test toString | |
58129ff7 | 230 | * |
680f9173 | 231 | * @throws CTFException |
e291b8c8 MK |
232 | */ |
233 | @Test | |
680f9173 | 234 | public void testToString() throws CTFException { |
58129ff7 | 235 | setUp(); |
e291b8c8 MK |
236 | String result = fixture.toString(); |
237 | assertNotNull(result); | |
238 | } | |
239 | ||
866e5b51 FC |
240 | /** |
241 | * Run the void parse() method test. | |
e291b8c8 | 242 | * |
680f9173 | 243 | * @throws CTFException |
866e5b51 | 244 | */ |
58129ff7 | 245 | @Test |
680f9173 | 246 | public void testParse() throws CTFException { |
58129ff7 | 247 | setUp(); |
c4d57ac1 AM |
248 | assertEquals(new UUID(0xd18e637435a1cd42L, 0x8e70a9cffa712793L), CtfTestTraceUtils.getTrace(testTrace).getUUID()); |
249 | assertEquals(1332166405241713920.0, CtfTestTraceUtils.getTrace(testTrace).getClock().getClockOffset(), 200.0); | |
250 | assertEquals(8, CtfTestTraceUtils.getTrace(testTrace).getEnvironment().size()); | |
866e5b51 FC |
251 | } |
252 | } |