Commit | Line | Data |
---|---|---|
cd8779d2 BH |
1 | /******************************************************************************* |
2 | * Copyright (c) 2015 Ericsson | |
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 | * Contributors: | |
10 | * Bernd Hufmann - IInitial API and implementation | |
11 | *******************************************************************************/ | |
12 | ||
13 | package org.eclipse.tracecompass.tmf.ctf.core.tests.trace; | |
14 | ||
15 | import static org.junit.Assert.assertEquals; | |
16 | import static org.junit.Assert.assertNotNull; | |
17 | import static org.junit.Assert.assertTrue; | |
18 | import static org.junit.Assert.fail; | |
19 | ||
20 | import java.nio.file.Files; | |
21 | import java.nio.file.Path; | |
22 | import java.nio.file.Paths; | |
23 | import java.util.LinkedList; | |
24 | import java.util.List; | |
25 | ||
d35f4ee9 | 26 | import org.eclipse.core.runtime.FileLocator; |
cd8779d2 | 27 | import org.eclipse.core.runtime.IStatus; |
d35f4ee9 | 28 | import org.eclipse.tracecompass.testtraces.ctf.CtfTestTrace; |
cd8779d2 BH |
29 | import org.eclipse.tracecompass.tmf.core.trace.TraceValidationStatus; |
30 | import org.eclipse.tracecompass.tmf.ctf.core.trace.CtfTmfTrace; | |
31 | import org.eclipse.tracecompass.tmf.ctf.core.trace.CtfTraceValidationStatus; | |
32 | import org.junit.Test; | |
33 | import org.junit.runner.RunWith; | |
34 | import org.junit.runners.Parameterized; | |
35 | import org.junit.runners.Parameterized.Parameters; | |
36 | ||
37 | /** | |
38 | * The class <code>CtfTmfTraceValidateTest</code> contains tests for trace | |
39 | * validation | |
40 | * <code>{@link CtfTmfTrace#validate(org.eclipse.core.resources.IProject, String)}</code> | |
41 | * . | |
42 | * | |
43 | * @author Bernd Hufmann | |
44 | */ | |
45 | @RunWith(Parameterized.class) | |
46 | public class CtfTmfTraceValidateTest { | |
47 | ||
48 | private static final Path BASE_PATH = Paths.get("../org.eclipse.tracecompass.ctf.core.tests", "traces"); | |
49 | private static final Path CTF_SUITE_BASE_PATH = Paths.get("../org.eclipse.tracecompass.ctf.core.tests", "traces", "ctf-testsuite", "tests", "1.8"); | |
50 | ||
51 | private String fTrace; | |
52 | private int fServerity; | |
53 | private int fConfidence; | |
54 | private boolean fHasException; | |
55 | ||
56 | /** | |
57 | * Gets a list of test case parameters. | |
58 | * | |
59 | * @return The list of CTF traces (directories) to test | |
d35f4ee9 | 60 | * @throws Exception in case of error |
cd8779d2 BH |
61 | */ |
62 | @Parameters(name = "{index}: {0}") | |
d35f4ee9 | 63 | public static Iterable<Object[]> getTracePaths() throws Exception { |
cd8779d2 BH |
64 | final List<Object[]> dirs = new LinkedList<>(); |
65 | // text-only metadata, valid CTF trace (lttle-endian) | |
66 | addDirsFrom(dirs, CTF_SUITE_BASE_PATH.resolve(Paths.get("regression", "metadata", "pass", "literal-integers")), IStatus.OK, 10, false); | |
67 | // packet-based metadata, valid CTF trace (lttle-endian) | |
d35f4ee9 BH |
68 | String tracePath = FileLocator.toFileURL(CtfTestTrace.KERNEL.getTraceURL()).getPath(); |
69 | addDirsFrom(dirs, Paths.get(tracePath), IStatus.OK, 10, false); | |
cd8779d2 BH |
70 | // text-only metadata, but invalid |
71 | addDirsFrom(dirs, CTF_SUITE_BASE_PATH.resolve(Paths.get("regression", "metadata", "fail", "enum-empty")), IStatus.WARNING, 1, true); | |
72 | // packet-based metadata, but invalid | |
73 | addDirsFrom(dirs, CTF_SUITE_BASE_PATH.resolve(Paths.get("regression", "metadata", "fail", "lttng-modules-2.0-pre1")), IStatus.WARNING, 1, true); | |
74 | // pass file instead of directory | |
d35f4ee9 | 75 | addDirsFrom(dirs, BASE_PATH.resolve(Paths.get("synctraces.tar.gz")), IStatus.ERROR, 1, false); |
cd8779d2 BH |
76 | |
77 | return dirs; | |
78 | } | |
79 | ||
80 | private static void addDirsFrom(List<Object[]> dirs, Path path, int severity, int confidence, boolean hasException) { | |
81 | if (!Files.exists(path)) { | |
82 | /* Some planned directories may not exist yet in the test suite */ | |
83 | return; | |
84 | } | |
85 | ||
86 | Object array[] = new Object[] { path.toString(), severity, confidence, hasException }; | |
87 | dirs.add(array); | |
88 | } | |
89 | ||
90 | /** | |
91 | * @param trace | |
92 | * a trace path | |
93 | * @param severity | |
94 | * severity of validation status expected | |
95 | * @param confidence | |
96 | * confidence of validation status expected | |
97 | * @param hasException | |
98 | * flag whether validation status should contain exception | |
99 | */ | |
100 | public CtfTmfTraceValidateTest(String trace, int severity, int confidence, boolean hasException) { | |
101 | fTrace = trace; | |
102 | fServerity = severity; | |
103 | fConfidence = confidence; | |
104 | fHasException = hasException; | |
105 | } | |
106 | ||
107 | /** | |
108 | * Main test cases | |
109 | */ | |
110 | @Test | |
111 | public void testValidate() { | |
0ff9e595 AM |
112 | CtfTmfTrace trace = new CtfTmfTrace(); |
113 | IStatus status = trace.validate(null, fTrace); | |
114 | assertEquals(toString(), fServerity, status.getSeverity()); | |
cd8779d2 | 115 | |
0ff9e595 AM |
116 | if (fHasException) { |
117 | assertNotNull(toString(), status.getException()); | |
cd8779d2 | 118 | } |
0ff9e595 AM |
119 | switch (status.getSeverity()) { |
120 | case IStatus.OK: { | |
121 | assertTrue(status instanceof CtfTraceValidationStatus); | |
122 | CtfTraceValidationStatus ctfStatus = (CtfTraceValidationStatus) status; | |
123 | assertEquals(toString(), fConfidence, ctfStatus.getConfidence()); | |
124 | assertNotNull(ctfStatus.getEnvironment()); | |
125 | break; | |
126 | } | |
127 | case IStatus.WARNING: { | |
128 | assertTrue(status instanceof TraceValidationStatus); | |
129 | TraceValidationStatus ctfStatus = (TraceValidationStatus) status; | |
130 | assertEquals(fConfidence, ctfStatus.getConfidence()); | |
131 | break; | |
132 | } | |
133 | case IStatus.ERROR: { | |
134 | // nothing else to check here | |
135 | break; | |
136 | } | |
137 | default: | |
138 | // no other severity should be returned | |
139 | fail(); | |
140 | break; | |
141 | } | |
142 | assertEquals(fServerity, status.getSeverity()); | |
143 | trace.dispose(); | |
cd8779d2 BH |
144 | } |
145 | ||
146 | } |