1 /*******************************************************************************
2 * Copyright (c) 2016 École Polytechnique de Montréal
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
.os
.linux
.core
.tests
.stubs
;
12 import static org
.junit
.Assert
.fail
;
14 import java
.util
.Collections
;
15 import java
.util
.HashMap
;
16 import java
.util
.List
;
20 import org
.apache
.commons
.io
.FilenameUtils
;
21 import org
.eclipse
.core
.runtime
.IPath
;
22 import org
.eclipse
.core
.runtime
.IStatus
;
23 import org
.eclipse
.tracecompass
.analysis
.os
.linux
.core
.tests
.Activator
;
24 import org
.eclipse
.tracecompass
.analysis
.os
.linux
.core
.tests
.stubs
.trace
.TmfXmlKernelTraceStub
;
25 import org
.eclipse
.tracecompass
.common
.core
.NonNullUtils
;
26 import org
.eclipse
.tracecompass
.statesystem
.core
.interval
.ITmfStateInterval
;
27 import org
.eclipse
.tracecompass
.statesystem
.core
.statevalue
.ITmfStateValue
;
28 import org
.eclipse
.tracecompass
.tmf
.core
.event
.TmfEvent
;
29 import org
.eclipse
.tracecompass
.tmf
.core
.exceptions
.TmfTraceException
;
32 * Describe a test case for a linux unit test
34 * @author Geneviève Bastien
36 public class LinuxTestCase
{
38 private final String fTraceFile
;
41 * Class to group an attribute path and its intervals
43 public static class IntervalInfo
{
45 private final String
[] fAttributePath
;
46 private final List
<ITmfStateInterval
> fIntervals
;
52 * The list of intervals for the full time range of the
54 * @param attributePath
57 public IntervalInfo(List
<ITmfStateInterval
> intervals
, String
... attributePath
) {
58 fAttributePath
= attributePath
;
59 fIntervals
= intervals
;
63 * Get the attribute path
65 * @return The attribute path
67 public String
[] getAttributePath() {
68 return fAttributePath
;
72 * Get the list of intervals
74 * @return The list of intervals
76 public List
<ITmfStateInterval
> getIntervals() {
82 * Class to group a timestamp with a map of attributes and their expected
85 public static class PunctualInfo
{
87 private final long fTs
;
88 private final Map
<String
[], ITmfStateValue
> fValueMap
;
94 * Timestamp of this test data
96 public PunctualInfo(long ts
) {
98 fValueMap
= new HashMap
<>();
102 * Get the timestamp this data is applied to
104 * @return The timestamp of this test data
106 public long getTimestamp() {
111 * Get the test values
113 * @return The map of attribute path and values
115 public Map
<String
[], ITmfStateValue
> getValues() {
120 * Add an attribute value to verify
125 * The value of this attribute at timestamp
127 public void addValue(String
[] key
, ITmfStateValue value
) {
128 fValueMap
.put(key
, value
);
136 * The filename of the trace file
138 public LinuxTestCase(String filename
) {
139 fTraceFile
= filename
;
143 * Get the last part of the file name containing the test trace
145 * @return The name of the file
147 public String
getTraceFileName() {
148 return NonNullUtils
.checkNotNull(FilenameUtils
.getName(fTraceFile
));
152 * Initializes the trace for this test case. This method will always create
153 * a new trace. The caller must dispose of it the proper way.
155 * @return The {@link TmfXmlKernelTraceStub} created for this test case
157 public TmfXmlKernelTraceStub
getKernelTrace() {
158 TmfXmlKernelTraceStub trace
= new TmfXmlKernelTraceStub();
159 IPath filePath
= Activator
.getAbsoluteFilePath(fTraceFile
);
160 IStatus status
= trace
.validate(null, filePath
.toOSString());
161 if (!status
.isOK()) {
162 fail(status
.getException().getMessage());
165 trace
.initTrace(null, filePath
.toOSString(), TmfEvent
.class);
166 } catch (TmfTraceException e
) {
167 fail(e
.getMessage());
173 * This method will return a set of attributes and their corresponding
174 * expected intervals that will be tested with the actual intervals obtained
175 * from the state system. It does not have to return all attributes of a
176 * given state system, only the ones interesting for this test case.
178 * @return A set of {@link IntervalInfo} objects to verify
180 public Set
<IntervalInfo
> getTestIntervals() {
181 return Collections
.EMPTY_SET
;
185 * This method will return a set of timestamps and their corresponding map
186 * of attributes and state values. The attribute list does not have to
187 * contain all attributes in the state system, only the ones that should be
190 * @return A set of {@link PunctualInfo} objects to verify
192 public Set
<PunctualInfo
> getPunctualTestData() {
193 return Collections
.EMPTY_SET
;