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
;
21 import java
.nio
.file
.Files
;
22 import java
.nio
.file
.Path
;
23 import java
.nio
.file
.Paths
;
24 import java
.util
.LinkedList
;
25 import java
.util
.List
;
27 import org
.eclipse
.core
.runtime
.FileLocator
;
28 import org
.eclipse
.core
.runtime
.IStatus
;
29 import org
.eclipse
.tracecompass
.testtraces
.ctf
.CtfTestTrace
;
30 import org
.eclipse
.tracecompass
.tmf
.core
.trace
.TraceValidationStatus
;
31 import org
.eclipse
.tracecompass
.tmf
.ctf
.core
.trace
.CtfTmfTrace
;
32 import org
.eclipse
.tracecompass
.tmf
.ctf
.core
.trace
.CtfTraceValidationStatus
;
33 import org
.junit
.Test
;
34 import org
.junit
.runner
.RunWith
;
35 import org
.junit
.runners
.Parameterized
;
36 import org
.junit
.runners
.Parameterized
.Parameters
;
39 * The class <code>CtfTmfTraceValidateTest</code> contains tests for trace
41 * <code>{@link CtfTmfTrace#validate(org.eclipse.core.resources.IProject, String)}</code>
44 * @author Bernd Hufmann
46 @RunWith(Parameterized
.class)
47 public class CtfTmfTraceValidateTest
{
49 private static final Path BASE_PATH
= Paths
.get("../org.eclipse.tracecompass.ctf.core.tests", "traces");
50 private static final Path CTF_SUITE_BASE_PATH
= Paths
.get("../org.eclipse.tracecompass.ctf.core.tests", "traces", "ctf-testsuite", "tests", "1.8");
52 private String fTrace
;
53 private int fServerity
;
54 private int fConfidence
;
55 private boolean fHasException
;
58 * Gets a list of test case parameters.
60 * @return The list of CTF traces (directories) to test
61 * @throws Exception in case of error
63 @Parameters(name
= "{index}: {0}")
64 public static Iterable
<Object
[]> getTracePaths() throws Exception
{
65 final List
<Object
[]> dirs
= new LinkedList
<>();
66 // text-only metadata, valid CTF trace (lttle-endian)
67 addDirsFrom(dirs
, CTF_SUITE_BASE_PATH
.resolve(Paths
.get("regression", "metadata", "pass", "literal-integers")), IStatus
.OK
, 10, false);
68 // packet-based metadata, valid CTF trace (lttle-endian)
69 URI tracePath
= FileLocator
.toFileURL(CtfTestTrace
.KERNEL
.getTraceURL()).toURI();
70 addDirsFrom(dirs
, Paths
.get(tracePath
), IStatus
.OK
, 10, false);
71 // text-only metadata, but invalid
72 addDirsFrom(dirs
, CTF_SUITE_BASE_PATH
.resolve(Paths
.get("regression", "metadata", "fail", "enum-empty")), IStatus
.WARNING
, 1, true);
73 // packet-based metadata, but invalid
74 addDirsFrom(dirs
, CTF_SUITE_BASE_PATH
.resolve(Paths
.get("regression", "metadata", "fail", "lttng-modules-2.0-pre1")), IStatus
.WARNING
, 1, true);
75 // pass file instead of directory
76 addDirsFrom(dirs
, BASE_PATH
.resolve(Paths
.get("synctraces.tar.gz")), IStatus
.ERROR
, 1, false);
81 private static void addDirsFrom(List
<Object
[]> dirs
, Path path
, int severity
, int confidence
, boolean hasException
) {
82 if (!Files
.exists(path
)) {
83 /* Some planned directories may not exist yet in the test suite */
87 Object array
[] = new Object
[] { path
.toString(), severity
, confidence
, hasException
};
95 * severity of validation status expected
97 * confidence of validation status expected
99 * flag whether validation status should contain exception
101 public CtfTmfTraceValidateTest(String trace
, int severity
, int confidence
, boolean hasException
) {
103 fServerity
= severity
;
104 fConfidence
= confidence
;
105 fHasException
= hasException
;
112 public void testValidate() {
113 CtfTmfTrace trace
= new CtfTmfTrace();
114 IStatus status
= trace
.validate(null, fTrace
);
115 assertEquals(toString(), fServerity
, status
.getSeverity());
118 assertNotNull(toString(), status
.getException());
120 switch (status
.getSeverity()) {
122 assertTrue(status
instanceof CtfTraceValidationStatus
);
123 CtfTraceValidationStatus ctfStatus
= (CtfTraceValidationStatus
) status
;
124 assertEquals(toString(), fConfidence
, ctfStatus
.getConfidence());
125 assertNotNull(ctfStatus
.getEnvironment());
128 case IStatus
.WARNING
: {
129 assertTrue(status
instanceof TraceValidationStatus
);
130 TraceValidationStatus ctfStatus
= (TraceValidationStatus
) status
;
131 assertEquals(fConfidence
, ctfStatus
.getConfidence());
134 case IStatus
.ERROR
: {
135 // nothing else to check here
139 // no other severity should be returned
143 assertEquals(fServerity
, status
.getSeverity());