1 /*******************************************************************************
2 * Copyright (c) 2015 Ericsson
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
10 * Bernd Hufmann - IInitial API and implementation
11 *******************************************************************************/
13 package org
.eclipse
.tracecompass
.tmf
.ctf
.core
.tests
.trace
;
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
;
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
;
26 import org
.eclipse
.core
.runtime
.FileLocator
;
27 import org
.eclipse
.core
.runtime
.IStatus
;
28 import org
.eclipse
.tracecompass
.testtraces
.ctf
.CtfTestTrace
;
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
;
38 * The class <code>CtfTmfTraceValidateTest</code> contains tests for trace
40 * <code>{@link CtfTmfTrace#validate(org.eclipse.core.resources.IProject, String)}</code>
43 * @author Bernd Hufmann
45 @RunWith(Parameterized
.class)
46 public class CtfTmfTraceValidateTest
{
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");
51 private String fTrace
;
52 private int fServerity
;
53 private int fConfidence
;
54 private boolean fHasException
;
57 * Gets a list of test case parameters.
59 * @return The list of CTF traces (directories) to test
60 * @throws Exception in case of error
62 @Parameters(name
= "{index}: {0}")
63 public static Iterable
<Object
[]> getTracePaths() throws Exception
{
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)
68 String tracePath
= FileLocator
.toFileURL(CtfTestTrace
.KERNEL
.getTraceURL()).getPath();
69 addDirsFrom(dirs
, Paths
.get(tracePath
), IStatus
.OK
, 10, false);
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
75 addDirsFrom(dirs
, BASE_PATH
.resolve(Paths
.get("synctraces.tar.gz")), IStatus
.ERROR
, 1, false);
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 */
86 Object array
[] = new Object
[] { path
.toString(), severity
, confidence
, hasException
};
94 * severity of validation status expected
96 * confidence of validation status expected
98 * flag whether validation status should contain exception
100 public CtfTmfTraceValidateTest(String trace
, int severity
, int confidence
, boolean hasException
) {
102 fServerity
= severity
;
103 fConfidence
= confidence
;
104 fHasException
= hasException
;
111 public void testValidate() {
112 CtfTmfTrace trace
= new CtfTmfTrace();
113 IStatus status
= trace
.validate(null, fTrace
);
114 assertEquals(toString(), fServerity
, status
.getSeverity());
117 assertNotNull(toString(), status
.getException());
119 switch (status
.getSeverity()) {
121 assertTrue(status
instanceof CtfTraceValidationStatus
);
122 CtfTraceValidationStatus ctfStatus
= (CtfTraceValidationStatus
) status
;
123 assertEquals(toString(), fConfidence
, ctfStatus
.getConfidence());
124 assertNotNull(ctfStatus
.getEnvironment());
127 case IStatus
.WARNING
: {
128 assertTrue(status
instanceof TraceValidationStatus
);
129 TraceValidationStatus ctfStatus
= (TraceValidationStatus
) status
;
130 assertEquals(fConfidence
, ctfStatus
.getConfidence());
133 case IStatus
.ERROR
: {
134 // nothing else to check here
138 // no other severity should be returned
142 assertEquals(fServerity
, status
.getSeverity());