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