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
.junit
.Assert
.fail
;
14 import java
.io
.BufferedReader
;
15 import java
.io
.IOException
;
16 import java
.io
.InputStream
;
17 import java
.io
.InputStreamReader
;
19 import java
.util
.Collections
;
20 import java
.util
.List
;
21 import java
.util
.stream
.Collectors
;
23 import org
.eclipse
.core
.runtime
.IProgressMonitor
;
24 import org
.eclipse
.jdt
.annotation
.NonNull
;
25 import org
.eclipse
.jdt
.annotation
.Nullable
;
26 import org
.eclipse
.tracecompass
.internal
.provisional
.analysis
.lami
.core
.module
.LamiAnalysis
;
27 import org
.eclipse
.tracecompass
.internal
.provisional
.analysis
.lami
.core
.module
.LamiChartModel
;
28 import org
.eclipse
.tracecompass
.tmf
.core
.analysis
.ondemand
.OnDemandAnalysisException
;
29 import org
.eclipse
.tracecompass
.tmf
.core
.trace
.ITmfTrace
;
31 import com
.google
.common
.collect
.ImmutableMultimap
;
32 import com
.google
.common
.collect
.Multimap
;
35 * Extension of {@link LamiAnalysis} used for tests.
37 public class LamiAnalysisStub
extends LamiAnalysis
{
39 private final String fMetaDatafilename
;
40 private final String fResultFilename
;
45 * @param metaDatafilename
46 * Filename of the JSON metadata file.
47 * @param resultFilename
48 * Filename of the JSON results file.
50 protected LamiAnalysisStub(String metaDatafilename
, String resultFilename
) {
51 super("Stub Analysis", false, o
-> true, Collections
.singletonList("StubExecutable"));
52 fMetaDatafilename
= metaDatafilename
;
53 fResultFilename
= resultFilename
;
57 public @NonNull String
getName() {
62 protected @NonNull Multimap
<@NonNull String
, @NonNull LamiChartModel
> getPredefinedCharts() {
63 return ImmutableMultimap
.of();
67 protected String
getResultsFromCommand(List
<String
> command
, IProgressMonitor monitor
)
68 throws OnDemandAnalysisException
{
70 return readLamiFile(fResultFilename
);
74 protected @Nullable String
getOutputFromCommand(List
<String
> command
) {
75 return readLamiFile(fMetaDatafilename
);
79 public boolean canExecute(ITmfTrace trace
) {
85 protected synchronized void initialize() {
89 private static String
readLamiFile(String filename
) {
90 String fileContent
= "";
92 URL url
= new URL("platform:/plugin/org.eclipse.tracecompass.analysis.lami.core.tests/testfiles/" + filename
);
94 try (InputStream inputStream
= url
.openConnection().getInputStream()) {
95 BufferedReader in
= new BufferedReader(new InputStreamReader(inputStream
));
96 fileContent
= in
.lines().collect(Collectors
.joining());
98 } catch (IOException e
) {