1 /*******************************************************************************
2 * Copyright (c) 2016 EfficiOS Inc., Michael Jeanson
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 *******************************************************************************/
10 package org
.eclipse
.tracecompass
.analysis
.lami
.core
.tests
;
12 import static org
.eclipse
.tracecompass
.common
.core
.NonNullUtils
.checkNotNull
;
13 import static org
.junit
.Assert
.assertEquals
;
14 import static org
.junit
.Assert
.assertFalse
;
15 import static org
.junit
.Assert
.assertNotNull
;
16 import static org
.junit
.Assert
.assertNull
;
17 import static org
.junit
.Assert
.assertTrue
;
19 import java
.util
.List
;
22 import org
.eclipse
.core
.runtime
.CoreException
;
23 import org
.eclipse
.core
.runtime
.NullProgressMonitor
;
24 import org
.eclipse
.tracecompass
.internal
.provisional
.analysis
.lami
.core
.aspect
.LamiTableEntryAspect
;
25 import org
.eclipse
.tracecompass
.internal
.provisional
.analysis
.lami
.core
.module
.LamiResultTable
;
26 import org
.eclipse
.tracecompass
.internal
.provisional
.analysis
.lami
.core
.module
.LamiTableClass
;
27 import org
.eclipse
.tracecompass
.internal
.provisional
.analysis
.lami
.core
.module
.LamiTableEntry
;
28 import org
.eclipse
.tracecompass
.internal
.provisional
.analysis
.lami
.core
.types
.LamiBitrate
;
29 import org
.eclipse
.tracecompass
.internal
.provisional
.analysis
.lami
.core
.types
.LamiData
;
30 import org
.eclipse
.tracecompass
.internal
.provisional
.analysis
.lami
.core
.types
.LamiDuration
;
31 import org
.eclipse
.tracecompass
.internal
.provisional
.analysis
.lami
.core
.types
.LamiSize
;
32 import org
.eclipse
.tracecompass
.internal
.provisional
.analysis
.lami
.core
.types
.LamiSystemCall
;
33 import org
.eclipse
.tracecompass
.internal
.provisional
.analysis
.lami
.core
.types
.LamiTimeRange
;
34 import org
.eclipse
.tracecompass
.tmf
.core
.timestamp
.ITmfTimestamp
;
35 import org
.eclipse
.tracecompass
.tmf
.core
.timestamp
.TmfTimeRange
;
36 import org
.eclipse
.tracecompass
.tmf
.core
.timestamp
.TmfTimestamp
;
37 import org
.eclipse
.tracecompass
.tmf
.tests
.stubs
.trace
.TmfTraceStub
;
38 import org
.junit
.After
;
39 import org
.junit
.Before
;
40 import org
.junit
.Test
;
44 * Test cases to verify the JSON parsing of LamiAnalyses.
46 public class LamiJsonParserTest
{
48 private static final double DELTA
= 0.001;
50 private static final String TRACEPATH
= "fake/path/to/trace";
51 private LamiTmfTraceStub fTrace
;
54 * Extend TmfTraceStub to return a fake path.
56 private static class LamiTmfTraceStub
extends TmfTraceStub
{
58 public String
getPath() {
68 fTrace
= new LamiTmfTraceStub();
75 public void teardown() {
80 * Test the metadata parsing.
83 public void testMetadata() {
84 LamiAnalysisStub analysis
= new LamiAnalysisStub("test-metadata.json", "test-results.json");
86 assertTrue(analysis
.canExecute(fTrace
));
87 assertEquals("LAMI test", analysis
.getAnalysisTitle());
89 Map
<String
, LamiTableClass
> tableModels
= analysis
.getTableClasses();
91 /* Table models tests */
92 assertNotNull(tableModels
);
93 assertFalse(tableModels
.isEmpty());
94 assertEquals(3, tableModels
.size());
96 /* Table class tests */
97 LamiTableClass perSyscallClass
= tableModels
.get("per-syscall");
98 assertNotNull(perSyscallClass
);
99 LamiTableClass perProcessClass
= tableModels
.get("per-proc");
100 assertNotNull(perProcessClass
);
101 LamiTableClass perInterruptClass
= tableModels
.get("per-irq");
102 assertNotNull(perInterruptClass
);
104 assertEquals("Per-syscall stuff", perSyscallClass
.getTableTitle());
105 assertEquals("Per-process stuff", perProcessClass
.getTableTitle());
106 assertEquals("Per-interrupt stuff", perInterruptClass
.getTableTitle());
109 List
<LamiTableEntryAspect
> aspects
= perSyscallClass
.getAspects();
111 assertFalse(aspects
.isEmpty());
112 assertEquals(8, aspects
.size());
114 assertEquals("System call", aspects
.get(0).getLabel());
115 assertEquals("Duration (ns)", aspects
.get(1).getLabel());
116 assertEquals("Size (bytes)", aspects
.get(2).getLabel());
117 assertEquals("Bitrate (bps)", aspects
.get(3).getLabel());
118 assertEquals("Time range (begin)", aspects
.get(4).getLabel());
119 assertEquals("Time range (end)", aspects
.get(5).getLabel());
120 assertEquals("Time range (duration) (ns)", aspects
.get(6).getLabel());
121 assertEquals("", aspects
.get(7).getLabel()); // Empty aspect to fix SWT display bug
125 * Test the results parsing.
127 * @throws CoreException when execute() fails.
130 public void testResults() throws CoreException
{
131 LamiAnalysisStub analysis
= new LamiAnalysisStub("test-metadata.json", "test-results.json");
133 List
<LamiResultTable
> resultTables
= analysis
.execute(fTrace
, null, "", new NullProgressMonitor());
135 assertFalse(resultTables
.isEmpty());
136 assertEquals(4, resultTables
.size());
138 LamiResultTable perProcessTable
= resultTables
.get(0);
139 LamiResultTable perSyscallTable
= resultTables
.get(1);
140 LamiResultTable perInterruptTable
= resultTables
.get(2);
141 LamiResultTable perInterruptOverrideTable
= resultTables
.get(3);
143 assertEquals("Per-process stuff", perProcessTable
.getTableClass().getTableTitle());
144 assertEquals("per-proc", perProcessTable
.getTableClass().getTableClassName());
146 assertEquals("Per-syscall stuff", perSyscallTable
.getTableClass().getTableTitle());
147 assertEquals("per-syscall", perSyscallTable
.getTableClass().getTableClassName());
149 assertEquals("Per-interrupt stuff", perInterruptTable
.getTableClass().getTableTitle());
150 assertEquals("per-irq", perInterruptTable
.getTableClass().getTableClassName());
152 assertEquals("Per-interrupt stuff [with overridden title]", perInterruptOverrideTable
.getTableClass().getTableTitle());
153 assertEquals("Extended per-irq", perInterruptOverrideTable
.getTableClass().getTableClassName());
155 assertEquals(1000, perProcessTable
.getTimeRange().getStart());
156 assertEquals(2000, perProcessTable
.getTimeRange().getEnd());
157 assertEquals(1000, perProcessTable
.getTimeRange().getDuration());
159 List
<LamiTableEntry
> syscallEntries
= perSyscallTable
.getEntries();
161 assertFalse(syscallEntries
.isEmpty());
162 assertEquals(5, syscallEntries
.size());
164 LamiTableEntry readEntry
= syscallEntries
.get(0);
165 LamiTimeRange readEntryTimeRange
= readEntry
.getCorrespondingTimeRange();
167 assertNotNull(readEntryTimeRange
);
168 assertEquals(98233, readEntryTimeRange
.getStart());
169 assertEquals(1293828, readEntryTimeRange
.getEnd());
170 assertEquals(1195595, readEntryTimeRange
.getDuration());
173 /* Test raw values */
174 LamiData value0
= readEntry
.getValue(0);
175 assertTrue(value0
instanceof LamiSystemCall
);
176 assertEquals("read", ((LamiSystemCall
) value0
).getValue());
178 LamiData value1
= readEntry
.getValue(1);
179 assertTrue(value1
instanceof LamiDuration
);
180 assertEquals(2398123, ((LamiDuration
) value1
).getValue());
182 LamiData value2
= readEntry
.getValue(2);
183 assertTrue(value2
instanceof LamiSize
);
184 assertEquals(8123982, ((LamiSize
) value2
).getValue());
186 LamiData value3
= readEntry
.getValue(3);
187 assertTrue(value3
instanceof LamiBitrate
);
188 assertEquals(223232, ((LamiBitrate
) value3
).getValue());
190 LamiData value4
= readEntry
.getValue(4);
191 assertTrue(value4
instanceof LamiTimeRange
);
192 assertEquals(98233, ((LamiTimeRange
) value4
).getStart());
193 assertEquals(1293828, ((LamiTimeRange
) value4
).getEnd());
196 /* Test with aspects */
197 Map
<String
, LamiTableClass
> tableModels
= analysis
.getTableClasses();
198 assertNotNull(tableModels
);
199 LamiTableClass perSyscallClass
= tableModels
.get("per-syscall");
200 assertNotNull(perSyscallClass
);
201 List
<LamiTableEntryAspect
> aspects
= perSyscallClass
.getAspects();
203 assertEquals("read()", aspects
.get(0).resolveString(readEntry
));
204 assertEquals(2398123.0, checkNotNull(aspects
.get(1).resolveDouble(readEntry
)).doubleValue(), DELTA
);
205 assertEquals(8123982.0, checkNotNull(aspects
.get(2).resolveDouble(readEntry
)).doubleValue(), DELTA
);
206 assertEquals(223232.0, checkNotNull(aspects
.get(3).resolveDouble(readEntry
)).doubleValue(), DELTA
);
207 assertEquals(98233.0, checkNotNull(aspects
.get(4).resolveDouble(readEntry
)).doubleValue(), DELTA
);
208 assertEquals(1293828.0, checkNotNull(aspects
.get(5).resolveDouble(readEntry
)).doubleValue(), DELTA
);
209 assertEquals(1195595.0, checkNotNull(aspects
.get(6).resolveDouble(readEntry
)).doubleValue(), DELTA
);
210 assertNull(aspects
.get(7).resolveString(readEntry
));
214 * Test the error parsing of the results.
216 * @throws CoreException when execute() fails.
218 @Test (expected
= CoreException
.class)
219 public void testResultsError() throws CoreException
{
220 LamiAnalysisStub analysis
= new LamiAnalysisStub("test-metadata.json", "test-error.json");
222 analysis
.execute(fTrace
, null, "", new NullProgressMonitor());
226 * Test the command generation.
229 public void testBaseCommand() {
230 LamiAnalysisStub analysis
= new LamiAnalysisStub("test-metadata.json", "test-error.json");
232 ITmfTimestamp begin
= TmfTimestamp
.fromNanos(98233);
233 ITmfTimestamp end
= TmfTimestamp
.fromNanos(1293828);
235 TmfTimeRange timerange
= new TmfTimeRange(begin
, end
);
237 assertEquals("StubExecutable " + '\"' + TRACEPATH
+ '\"', analysis
.getFullCommandAsString(fTrace
, null));
238 assertEquals("StubExecutable --begin 98233 --end 1293828 " + '\"' + TRACEPATH
+ '\"', analysis
.getFullCommandAsString(fTrace
, timerange
));