os.tests: introduce test cases for the kernel analysis module
[deliverable/tracecompass.git] / analysis / org.eclipse.tracecompass.analysis.os.linux.core.tests / stubs / org / eclipse / tracecompass / analysis / os / linux / core / tests / stubs / LinuxTestCase.java
1 /*******************************************************************************
2 * Copyright (c) 2016 École Polytechnique de Montréal
3 *
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 *******************************************************************************/
9
10 package org.eclipse.tracecompass.analysis.os.linux.core.tests.stubs;
11
12 import static org.junit.Assert.fail;
13
14 import java.util.Collections;
15 import java.util.HashMap;
16 import java.util.List;
17 import java.util.Map;
18 import java.util.Set;
19
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;
30
31 /**
32 * Describe a test case for a linux unit test
33 *
34 * @author Geneviève Bastien
35 */
36 public class LinuxTestCase {
37
38 private final String fTraceFile;
39
40 /**
41 * Class to group an attribute path and its intervals
42 */
43 public static class IntervalInfo {
44
45 private final String[] fAttributePath;
46 private final List<ITmfStateInterval> fIntervals;
47
48 IntervalInfo(List<ITmfStateInterval> intervals, String... attributePath) {
49 fAttributePath = attributePath;
50 fIntervals = intervals;
51 }
52
53 /**
54 * Get the attribute path
55 *
56 * @return The attribute path
57 */
58 public String[] getAttributePath() {
59 return fAttributePath;
60 }
61
62 /**
63 * Get the list of intervals
64 *
65 * @return The list of intervals
66 */
67 public List<ITmfStateInterval> getIntervals() {
68 return fIntervals;
69 }
70 }
71
72 /**
73 * Class to group a timestamp with a map of attributes and their expected
74 * values
75 */
76 public static class PunctualInfo {
77
78 private final long fTs;
79 private final Map<String[], ITmfStateValue> fValueMap;
80
81 /**
82 * Constructor
83 *
84 * @param ts
85 * Timestamp of this test data
86 */
87 public PunctualInfo(long ts) {
88 fTs = ts;
89 fValueMap = new HashMap<>();
90 }
91
92 /**
93 * Get the timestamp this data is applied to
94 *
95 * @return The timestamp of this test data
96 */
97 public long getTimestamp() {
98 return fTs;
99 }
100
101 /**
102 * Get the test values
103 *
104 * @return The map of attribute path and values
105 */
106 public Map<String[], ITmfStateValue> getValues() {
107 return fValueMap;
108 }
109
110 /**
111 * Add an attribute value to verify
112 *
113 * @param key
114 * The attribute path
115 * @param value
116 * The value of this attribute at timestamp
117 */
118 public void addValue(String[] key, ITmfStateValue value) {
119 fValueMap.put(key, value);
120 }
121 }
122
123 /**
124 * Constructor
125 *
126 * @param filename
127 * The filename of the trace file
128 */
129 public LinuxTestCase(String filename) {
130 fTraceFile = filename;
131 }
132
133 /**
134 * Get the last part of the file name containing the test trace
135 *
136 * @return The name of the file
137 */
138 public String getTraceFileName() {
139 return NonNullUtils.checkNotNull(FilenameUtils.getName(fTraceFile));
140 }
141
142 /**
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.
145 *
146 * @return The {@link TmfXmlKernelTraceStub} created for this test case
147 */
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());
154 }
155 try {
156 trace.initTrace(null, filePath.toOSString(), TmfEvent.class);
157 } catch (TmfTraceException e) {
158 fail(e.getMessage());
159 }
160 return trace;
161 }
162
163 /**
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.
168 *
169 * @return A set of {@link IntervalInfo} objects to verify
170 */
171 public Set<IntervalInfo> getTestIntervals() {
172 return Collections.EMPTY_SET;
173 }
174
175 /**
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
179 * tested.
180 *
181 * @return A set of {@link PunctualInfo} objects to verify
182 */
183 public Set<PunctualInfo> getPunctualTestData() {
184 return Collections.EMPTY_SET;
185 }
186
187 }
This page took 0.034472 seconds and 5 git commands to generate.