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
;
48 IntervalInfo(List
<ITmfStateInterval
> intervals
, String
... attributePath
) {
49 fAttributePath
= attributePath
;
50 fIntervals
= intervals
;
54 * Get the attribute path
56 * @return The attribute path
58 public String
[] getAttributePath() {
59 return fAttributePath
;
63 * Get the list of intervals
65 * @return The list of intervals
67 public List
<ITmfStateInterval
> getIntervals() {
73 * Class to group a timestamp with a map of attributes and their expected
76 public static class PunctualInfo
{
78 private final long fTs
;
79 private final Map
<String
[], ITmfStateValue
> fValueMap
;
85 * Timestamp of this test data
87 public PunctualInfo(long ts
) {
89 fValueMap
= new HashMap
<>();
93 * Get the timestamp this data is applied to
95 * @return The timestamp of this test data
97 public long getTimestamp() {
102 * Get the test values
104 * @return The map of attribute path and values
106 public Map
<String
[], ITmfStateValue
> getValues() {
111 * Add an attribute value to verify
116 * The value of this attribute at timestamp
118 public void addValue(String
[] key
, ITmfStateValue value
) {
119 fValueMap
.put(key
, value
);
127 * The filename of the trace file
129 public LinuxTestCase(String filename
) {
130 fTraceFile
= filename
;
134 * Get the last part of the file name containing the test trace
136 * @return The name of the file
138 public String
getTraceFileName() {
139 return NonNullUtils
.checkNotNull(FilenameUtils
.getName(fTraceFile
));
143 * Initializes the trace for this test case. This method will always create
144 * a new trace. The caller must dispose of it the proper way.
146 * @return The {@link TmfXmlKernelTraceStub} created for this test case
148 public TmfXmlKernelTraceStub
getKernelTrace() {
149 TmfXmlKernelTraceStub trace
= new TmfXmlKernelTraceStub();
150 IPath filePath
= Activator
.getAbsoluteFilePath(fTraceFile
);
151 IStatus status
= trace
.validate(null, filePath
.toOSString());
152 if (!status
.isOK()) {
153 fail(status
.getException().getMessage());
156 trace
.initTrace(null, filePath
.toOSString(), TmfEvent
.class);
157 } catch (TmfTraceException e
) {
158 fail(e
.getMessage());
164 * This method will return a set of attributes and their corresponding
165 * expected intervals that will be tested with the actual intervals obtained
166 * from the state system. It does not have to return all attributes of a
167 * given state system, only the ones interesting for this test case.
169 * @return A set of {@link IntervalInfo} objects to verify
171 public Set
<IntervalInfo
> getTestIntervals() {
172 return Collections
.EMPTY_SET
;
176 * This method will return a set of timestamps and their corresponding map
177 * of attributes and state values. The attribute list does not have to
178 * contain all attributes in the state system, only the ones that should be
181 * @return A set of {@link PunctualInfo} objects to verify
183 public Set
<PunctualInfo
> getPunctualTestData() {
184 return Collections
.EMPTY_SET
;