/
CallStackStateSystemTest.java
275 lines (249 loc) · 14.3 KB
/
CallStackStateSystemTest.java
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
/*******************************************************************************
* Copyright (c) 2016 École Polytechnique de Montréal
*
* All rights reserved. This program and the accompanying materials are
* made available under the terms of the Eclipse Public License 2.0 which
* accompanies this distribution, and is available at
* https://www.eclipse.org/legal/epl-2.0/
*
* SPDX-License-Identifier: EPL-2.0
*******************************************************************************/
package org.eclipse.tracecompass.analysis.callstack.core.tests;
import static org.junit.Assert.assertArrayEquals;
import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertNotNull;
import static org.junit.Assert.assertNull;
import static org.junit.Assert.assertTrue;
import static org.junit.Assert.fail;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.List;
import org.eclipse.tracecompass.analysis.callstack.core.tests.stubs.CallStackAnalysisStub;
import org.eclipse.tracecompass.analysis.profiling.core.callstack.CallStackStateProvider;
import org.eclipse.tracecompass.internal.analysis.callstack.core.base.ICallStackGroupDescriptor;
import org.eclipse.tracecompass.internal.analysis.callstack.core.callstack.CallStackSeries;
import org.eclipse.tracecompass.internal.analysis.callstack.core.instrumented.InstrumentedCallStackAnalysis;
import org.eclipse.tracecompass.internal.analysis.callstack.core.instrumented.InstrumentedGroupDescriptor;
import org.eclipse.tracecompass.statesystem.core.ITmfStateSystem;
import org.eclipse.tracecompass.statesystem.core.exceptions.AttributeNotFoundException;
import org.eclipse.tracecompass.statesystem.core.interval.ITmfStateInterval;
import org.eclipse.tracecompass.statesystem.core.statevalue.TmfStateValue;
import org.eclipse.tracecompass.statesystem.core.tests.shared.utils.StateIntervalStub;
import org.eclipse.tracecompass.statesystem.core.tests.shared.utils.StateSystemTestUtils;
import org.junit.Test;
/**
* Test the call stack provider and callstack analysis for state system
* callstacks. This class specifically tests the content of the state system
* built from the {@link InstrumentedCallStackAnalysis} and the
* {@link CallStackStateProvider} (o.e.t.a.profiling.core.callstack one for now)
*
* @author Geneviève Bastien
*/
public class CallStackStateSystemTest extends CallStackTestBase {
/**
* Test that the module as a callstack provider produces the same results as
* the callstack analysis module under it
*/
@Test
public void testCallStackProvider() {
CallStackAnalysisStub module = getModule();
assertNotNull(module);
// There should be only 1 callstack series
CallStackSeries callstack = module.getCallStackSeries();
assertNotNull(callstack);
// Get the patterns for each level of the callstack
List<String[]> patterns = module.getPatterns();
assertEquals(2, patterns.size());
// Check each level of the callstack. Make sure the path in the series
// correspond to the expected path
ICallStackGroupDescriptor nextLevel = callstack.getRootGroup();
assertTrue(nextLevel instanceof InstrumentedGroupDescriptor);
String[] subPattern = ((InstrumentedGroupDescriptor) nextLevel).getSubPattern();
assertArrayEquals(patterns.get(0), subPattern);
nextLevel = nextLevel.getNextGroup();
assertTrue(nextLevel instanceof InstrumentedGroupDescriptor);
subPattern = ((InstrumentedGroupDescriptor) nextLevel).getSubPattern();
assertArrayEquals(patterns.get(1), subPattern);
nextLevel = nextLevel.getNextGroup();
assertNull(nextLevel);
}
/**
* Test the content of the callstack state system built from the state
* provider
*
* @throws AttributeNotFoundException
* Exception thrown by test
*/
@SuppressWarnings("null")
@Test
public void testCallStackContent() throws AttributeNotFoundException {
// The javadoc of getModule() contains the expected structure of the
// callstack
CallStackAnalysisStub module = getModule();
assertNotNull(module);
// There should be 1 callstack series
CallStackSeries callstack = module.getCallStackSeries();
assertNotNull(callstack);
ITmfStateSystem ss = module.getStateSystem();
assertNotNull(ss);
List<String[]> patterns = module.getPatterns();
// Get the process quarks (first level)
List<Integer> quarks = ss.getQuarks(patterns.get(0));
assertEquals("Number of processes", 2, quarks.size());
for (Integer processQuark : quarks) {
// Get the threads under this process (second level)
List<Integer> threadQuarks = ss.getQuarks(processQuark, patterns.get(1));
switch (ss.getAttributeName(processQuark)) {
case "1":
verifyProcess1(ss, threadQuarks);
break;
case "5":
verifyProcess5(ss, threadQuarks);
break;
default:
fail("Unknown process in callstack");
}
}
}
@SuppressWarnings("null")
private static void verifyProcess1(ITmfStateSystem ss, List<Integer> threadQuarks) throws AttributeNotFoundException {
for (Integer threadQuark : threadQuarks) {
int csQuark = ss.getQuarkRelative(threadQuark, InstrumentedCallStackAnalysis.CALL_STACK);
String[] csPathArray = ss.getFullAttributePathArray(csQuark);
List<String> pathList = new ArrayList<>();
pathList.addAll(Arrays.asList(csPathArray));
switch (ss.getAttributeName(threadQuark)) {
case "2": {
List<Integer> subAttributes = ss.getSubAttributes(csQuark, false);
assertEquals(3, subAttributes.size());
List<ITmfStateInterval> expected = new ArrayList<>();
// Check the first depth level of thread 2
pathList.add("1");
expected.add(new StateIntervalStub(1, 9, TmfStateValue.newValueString("op1")));
expected.add(new StateIntervalStub(10, 11, TmfStateValue.nullValue()));
expected.add(new StateIntervalStub(12, 19, TmfStateValue.newValueString("op4")));
expected.add(new StateIntervalStub(20, 20, TmfStateValue.nullValue()));
StateSystemTestUtils.testIntervalForAttributes(ss, expected, pathList.toArray(new String[pathList.size()]));
// Check the second depth level
pathList.remove(pathList.size() - 1);
pathList.add("2");
expected.clear();
expected.add(new StateIntervalStub(1, 2, TmfStateValue.nullValue()));
expected.add(new StateIntervalStub(3, 6, TmfStateValue.newValueString("op2")));
expected.add(new StateIntervalStub(7, 20, TmfStateValue.nullValue()));
StateSystemTestUtils.testIntervalForAttributes(ss, expected, pathList.toArray(new String[pathList.size()]));
// Check the third depth level
pathList.remove(pathList.size() - 1);
pathList.add("3");
expected.clear();
expected.add(new StateIntervalStub(1, 3, TmfStateValue.nullValue()));
expected.add(new StateIntervalStub(4, 4, TmfStateValue.newValueString("op3")));
expected.add(new StateIntervalStub(5, 20, TmfStateValue.nullValue()));
StateSystemTestUtils.testIntervalForAttributes(ss, expected, pathList.toArray(new String[pathList.size()]));
}
break;
case "3": {
List<Integer> subAttributes = ss.getSubAttributes(csQuark, false);
assertEquals(2, subAttributes.size());
List<ITmfStateInterval> expected = new ArrayList<>();
// Check the first depth level of thread 3
pathList.add("1");
expected.add(new StateIntervalStub(1, 2, TmfStateValue.nullValue()));
expected.add(new StateIntervalStub(3, 19, TmfStateValue.newValueString("op2")));
expected.add(new StateIntervalStub(20, 20, TmfStateValue.nullValue()));
StateSystemTestUtils.testIntervalForAttributes(ss, expected, pathList.toArray(new String[pathList.size()]));
// Check the second depth level
pathList.remove(pathList.size() - 1);
pathList.add("2");
expected.clear();
expected.add(new StateIntervalStub(1, 4, TmfStateValue.nullValue()));
expected.add(new StateIntervalStub(5, 5, TmfStateValue.newValueString("op3")));
expected.add(new StateIntervalStub(6, 6, TmfStateValue.nullValue()));
expected.add(new StateIntervalStub(7, 12, TmfStateValue.newValueString("op2")));
expected.add(new StateIntervalStub(13, 20, TmfStateValue.nullValue()));
StateSystemTestUtils.testIntervalForAttributes(ss, expected, pathList.toArray(new String[pathList.size()]));
}
break;
default:
fail("Unknown thread child of process 5");
}
}
}
@SuppressWarnings("null")
private static void verifyProcess5(ITmfStateSystem ss, List<Integer> threadQuarks) throws AttributeNotFoundException {
for (Integer threadQuark : threadQuarks) {
int csQuark = ss.getQuarkRelative(threadQuark, InstrumentedCallStackAnalysis.CALL_STACK);
String[] csPathArray = ss.getFullAttributePathArray(csQuark);
List<String> pathList = new ArrayList<>();
pathList.addAll(Arrays.asList(csPathArray));
switch (ss.getAttributeName(threadQuark)) {
case "6": {
List<Integer> subAttributes = ss.getSubAttributes(csQuark, false);
assertEquals(3, subAttributes.size());
List<ITmfStateInterval> expected = new ArrayList<>();
// Check the first depth level of thread 6
pathList.add("1");
expected.add(new StateIntervalStub(1, 19, TmfStateValue.newValueString("op1")));
expected.add(new StateIntervalStub(20, 20, TmfStateValue.nullValue()));
StateSystemTestUtils.testIntervalForAttributes(ss, expected, pathList.toArray(new String[pathList.size()]));
// Check the second depth level
pathList.remove(pathList.size() - 1);
pathList.add("2");
expected.clear();
expected.add(new StateIntervalStub(1, 1, TmfStateValue.nullValue()));
expected.add(new StateIntervalStub(2, 6, TmfStateValue.newValueString("op3")));
expected.add(new StateIntervalStub(7, 7, TmfStateValue.nullValue()));
expected.add(new StateIntervalStub(8, 10, TmfStateValue.newValueString("op2")));
expected.add(new StateIntervalStub(11, 11, TmfStateValue.nullValue()));
expected.add(new StateIntervalStub(12, 19, TmfStateValue.newValueString("op4")));
expected.add(new StateIntervalStub(20, 20, TmfStateValue.nullValue()));
StateSystemTestUtils.testIntervalForAttributes(ss, expected, pathList.toArray(new String[pathList.size()]));
// Check the third depth level
pathList.remove(pathList.size() - 1);
pathList.add("3");
expected.clear();
expected.add(new StateIntervalStub(1, 3, TmfStateValue.nullValue()));
expected.add(new StateIntervalStub(4, 5, TmfStateValue.newValueString("op1")));
expected.add(new StateIntervalStub(6, 8, TmfStateValue.nullValue()));
expected.add(new StateIntervalStub(9, 9, TmfStateValue.newValueString("op3")));
expected.add(new StateIntervalStub(10, 20, TmfStateValue.nullValue()));
StateSystemTestUtils.testIntervalForAttributes(ss, expected, pathList.toArray(new String[pathList.size()]));
}
break;
case "7": {
List<Integer> subAttributes = ss.getSubAttributes(csQuark, false);
assertEquals(3, subAttributes.size());
List<ITmfStateInterval> expected = new ArrayList<>();
// Check the first depth level of thread 7
pathList.add("1");
expected.add(new StateIntervalStub(1, 19, TmfStateValue.newValueString("op5")));
expected.add(new StateIntervalStub(20, 20, TmfStateValue.nullValue()));
StateSystemTestUtils.testIntervalForAttributes(ss, expected, pathList.toArray(new String[pathList.size()]));
// Check the second depth level
pathList.remove(pathList.size() - 1);
pathList.add("2");
expected.clear();
expected.add(new StateIntervalStub(1, 1, TmfStateValue.nullValue()));
expected.add(new StateIntervalStub(2, 5, TmfStateValue.newValueString("op2")));
expected.add(new StateIntervalStub(6, 8, TmfStateValue.nullValue()));
expected.add(new StateIntervalStub(9, 12, TmfStateValue.newValueString("op2")));
expected.add(new StateIntervalStub(13, 14, TmfStateValue.nullValue()));
expected.add(new StateIntervalStub(15, 18, TmfStateValue.newValueString("op2")));
expected.add(new StateIntervalStub(19, 20, TmfStateValue.nullValue()));
StateSystemTestUtils.testIntervalForAttributes(ss, expected, pathList.toArray(new String[pathList.size()]));
// Check the third depth level
pathList.remove(pathList.size() - 1);
pathList.add("3");
expected.clear();
expected.add(new StateIntervalStub(1, 9, TmfStateValue.nullValue()));
expected.add(new StateIntervalStub(10, 10, TmfStateValue.newValueString("op3")));
expected.add(new StateIntervalStub(11, 20, TmfStateValue.nullValue()));
StateSystemTestUtils.testIntervalForAttributes(ss, expected, pathList.toArray(new String[pathList.size()]));
}
break;
default:
fail("Unknown thread child of process 5");
}
}
}
}