Commit | Line | Data |
---|---|---|
95bf10e7 | 1 | /******************************************************************************* |
97de0bca | 2 | * Copyright (c) 2012, 2015 Ericsson |
95bf10e7 AM |
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 generation with CodePro tools | |
11 | * Alexandre Montplaisir - Clean up, consolidate redundant tests | |
97de0bca | 12 | * Patrick Tasse - Remove getSubField |
95bf10e7 AM |
13 | *******************************************************************************/ |
14 | ||
9722e5d7 | 15 | package org.eclipse.tracecompass.tmf.ctf.core.tests.event; |
a3fc8213 | 16 | |
b4f71e4a FC |
17 | import static org.junit.Assert.assertEquals; |
18 | import static org.junit.Assert.assertNotNull; | |
8e964be1 | 19 | import static org.junit.Assert.assertNull; |
6cfa0200 | 20 | import static org.junit.Assert.assertSame; |
5dd1fa65 | 21 | import static org.junit.Assume.assumeTrue; |
8e964be1 | 22 | |
b742c196 | 23 | import java.util.Collection; |
8e964be1 | 24 | import java.util.Set; |
a3fc8213 | 25 | |
fe71057b | 26 | import org.eclipse.tracecompass.internal.tmf.ctf.core.trace.iterator.CtfIterator; |
2bdf0193 AM |
27 | import org.eclipse.tracecompass.tmf.core.event.ITmfEventField; |
28 | import org.eclipse.tracecompass.tmf.core.event.ITmfEventType; | |
29 | import org.eclipse.tracecompass.tmf.core.trace.ITmfContext; | |
9722e5d7 AM |
30 | import org.eclipse.tracecompass.tmf.ctf.core.event.CtfTmfEvent; |
31 | import org.eclipse.tracecompass.tmf.ctf.core.event.CtfTmfEventFactory; | |
2bdf0193 | 32 | import org.eclipse.tracecompass.tmf.ctf.core.tests.shared.CtfTmfTestTrace; |
9722e5d7 | 33 | import org.eclipse.tracecompass.tmf.ctf.core.trace.CtfTmfTrace; |
a3fc8213 AM |
34 | import org.junit.Before; |
35 | import org.junit.Test; | |
36 | ||
37 | /** | |
95bf10e7 AM |
38 | * The class <code>CtfTmfEventTest</code> contains tests for the class |
39 | * <code>{@link CtfTmfEvent}</code>. | |
a3fc8213 AM |
40 | * |
41 | * @author ematkho | |
42 | * @version $Revision: 1.0 $ | |
43 | */ | |
44 | public class CtfTmfEventTest { | |
45 | ||
9ac63b5b | 46 | private static final CtfTmfTestTrace testTrace = CtfTmfTestTrace.KERNEL; |
5dd1fa65 | 47 | |
6cfa0200 | 48 | private static CtfTmfEvent nullEvent; |
a3fc8213 AM |
49 | private CtfTmfEvent fixture; |
50 | ||
a3fc8213 AM |
51 | /** |
52 | * Perform pre-test initialization. | |
a3fc8213 AM |
53 | */ |
54 | @Before | |
fe71057b | 55 | public void setUp() { |
9ac63b5b | 56 | assumeTrue(testTrace.exists()); |
090c006e | 57 | try (CtfTmfTrace trace = testTrace.getTrace(); |
fe71057b | 58 | CtfIterator tr = (CtfIterator) trace.createIterator();) { |
dd9752d5 AM |
59 | tr.advance(); |
60 | fixture = tr.getCurrentEvent(); | |
ca5b04ad | 61 | nullEvent = CtfTmfEventFactory.getNullEvent(trace); |
dd9752d5 | 62 | } |
a3fc8213 AM |
63 | } |
64 | ||
a3fc8213 AM |
65 | /** |
66 | * Run the CTFEvent(EventDefinition,StreamInputReader) constructor test. | |
67 | */ | |
68 | @Test | |
69 | public void testCTFEvent_read() { | |
70 | assertNotNull(fixture); | |
71 | } | |
72 | ||
73 | /** | |
74 | * Run the int getCPU() method test. | |
75 | */ | |
76 | @Test | |
77 | public void testGetCPU() { | |
a3fc8213 | 78 | int result = nullEvent.getCPU(); |
a3fc8213 AM |
79 | assertEquals(-1, result); |
80 | } | |
81 | ||
a3fc8213 AM |
82 | /** |
83 | * Run the String getEventName() method test. | |
84 | */ | |
85 | @Test | |
86 | public void testGetEventName() { | |
33803b9b | 87 | String result = nullEvent.getType().getName(); |
cad06250 | 88 | assertEquals("Empty CTF event", result); |
a3fc8213 AM |
89 | } |
90 | ||
91 | /** | |
92 | * Run the ArrayList<String> getFieldNames() method test. | |
93 | */ | |
94 | @Test | |
95 | public void testGetFieldNames() { | |
b742c196 | 96 | Collection<String> result = fixture.getContent().getFieldNames(); |
a3fc8213 AM |
97 | assertNotNull(result); |
98 | } | |
99 | ||
100 | /** | |
101 | * Run the Object getFieldValue(String) method test. | |
102 | */ | |
103 | @Test | |
104 | public void testGetFieldValue() { | |
cad06250 | 105 | String fieldName = "pid"; |
788ddcbc | 106 | ITmfEventField result = fixture.getContent().getField(fieldName); |
a3fc8213 AM |
107 | |
108 | assertNotNull(result); | |
788ddcbc | 109 | assertNotNull(result.getValue()); |
a3fc8213 AM |
110 | } |
111 | ||
112 | /** | |
113 | * Run the HashMap<String, CTFEventField> getFields() method test. | |
114 | */ | |
115 | @Test | |
116 | public void testGetFields() { | |
b742c196 AM |
117 | Collection<? extends ITmfEventField> fields = nullEvent.getContent().getFields(); |
118 | assertEquals(0, fields.size()); | |
a3fc8213 AM |
119 | } |
120 | ||
6c204912 GB |
121 | /** |
122 | * Run the ITmfEventField getSubFieldValue(String[]) method test. | |
123 | */ | |
124 | @Test | |
125 | public void testGetSubFieldValue() { | |
126 | /* Field exists */ | |
127 | String[] names = { "pid" }; | |
97de0bca | 128 | assertNotNull(fixture.getContent().getField(names)); |
6c204912 GB |
129 | |
130 | /* First field exists, not the second */ | |
131 | String[] names2 = { "pid", "abcd" }; | |
97de0bca | 132 | assertNull(fixture.getContent().getField(names2)); |
6c204912 GB |
133 | |
134 | /* Both field do not exist */ | |
135 | String[] names3 = { "pfid", "abcd" }; | |
97de0bca | 136 | assertNull(fixture.getContent().getField(names3)); |
6c204912 GB |
137 | |
138 | /* TODO Missing case of embedded field, need event for it */ | |
139 | } | |
140 | ||
a3fc8213 AM |
141 | /** |
142 | * Run the long getID() method test. | |
143 | */ | |
144 | @Test | |
145 | public void testGetID() { | |
a3fc8213 | 146 | long result = nullEvent.getID(); |
a3fc8213 AM |
147 | assertEquals(-1L, result); |
148 | } | |
149 | ||
a3fc8213 AM |
150 | /** |
151 | * Run the long getTimestamp() method test. | |
a3fc8213 AM |
152 | */ |
153 | @Test | |
154 | public void testGetTimestamp() { | |
58f3bc52 | 155 | long result = nullEvent.getTimestamp().getValue(); |
a3fc8213 AM |
156 | assertEquals(-1L, result); |
157 | } | |
81c8e6f7 | 158 | |
95bf10e7 | 159 | /** |
6cfa0200 | 160 | * Test the getters for the reference, source and type. |
95bf10e7 | 161 | */ |
81c8e6f7 | 162 | @Test |
95bf10e7 | 163 | public void testGetters() { |
81c8e6f7 | 164 | long rank = fixture.getRank(); |
090c006e AM |
165 | try (CtfTmfTrace trace = fixture.getTrace();) { |
166 | assertEquals("kernel", trace.getName()); | |
167 | } | |
81c8e6f7 | 168 | String reference = fixture.getReference(); |
f9ff7d40 | 169 | int cpu = fixture.getCPU(); |
81c8e6f7 | 170 | ITmfEventType type = fixture.getType(); |
5dd1fa65 | 171 | assertEquals(ITmfContext.UNKNOWN_RANK, rank); |
090c006e | 172 | |
cad06250 | 173 | assertEquals("channel0_1", reference); |
f9ff7d40 | 174 | assertEquals(1, cpu); |
cad06250 | 175 | assertEquals("lttng_statedump_vm_map", type.toString()); |
81c8e6f7 MK |
176 | } |
177 | ||
8e964be1 MK |
178 | /** |
179 | * Test the custom CTF attributes methods. The test trace doesn't have any, | |
180 | * so the list of attributes should be empty. | |
181 | */ | |
182 | @Test | |
183 | public void testCustomAttributes() { | |
184 | Set<String> attributes = fixture.listCustomAttributes(); | |
185 | assertEquals(0, attributes.size()); | |
186 | ||
cad06250 | 187 | String attrib = fixture.getCustomAttribute("bozo"); |
8e964be1 MK |
188 | assertNull(attrib); |
189 | } | |
190 | ||
95bf10e7 AM |
191 | /** |
192 | * Test the toString() method | |
193 | */ | |
81c8e6f7 | 194 | @Test |
0879b6b9 | 195 | public void testToString() { |
81c8e6f7 | 196 | String s = fixture.getContent().toString(); |
cad06250 | 197 | assertEquals("pid=1922, start=0xb73ea000, end=0xb73ec000, flags=0x8000075, inode=917738, pgoff=0", s); |
81c8e6f7 | 198 | } |
6cfa0200 AM |
199 | |
200 | /** | |
ca5b04ad GB |
201 | * Test the {@link CtfTmfEventFactory#getNullEvent(CtfTmfTrace)} method, and |
202 | * the nullEvent's values. | |
6cfa0200 AM |
203 | */ |
204 | @Test | |
205 | public void testNullEvent() { | |
ca5b04ad | 206 | CtfTmfEvent nullEvent2 = CtfTmfEventFactory.getNullEvent(fixture.getTrace()); |
6cfa0200 AM |
207 | assertSame(nullEvent2, nullEvent); |
208 | assertNotNull(nullEvent); | |
209 | assertEquals(-1, nullEvent.getCPU()); | |
33803b9b | 210 | assertEquals("Empty CTF event", nullEvent.getType().getName()); |
a4fa4e36 | 211 | assertNull(nullEvent.getReference()); |
b742c196 | 212 | assertEquals(0, nullEvent.getContent().getFields().size()); |
6cfa0200 AM |
213 | assertEquals(-1L, nullEvent.getID()); |
214 | assertEquals(-1L, nullEvent.getTimestamp().getValue()); | |
215 | } | |
a3fc8213 | 216 | } |