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