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
.IStatus
;
27 import org
.eclipse
.tracecompass
.tmf
.core
.trace
.TraceValidationStatus
;
28 import org
.eclipse
.tracecompass
.tmf
.ctf
.core
.trace
.CtfTmfTrace
;
29 import org
.eclipse
.tracecompass
.tmf
.ctf
.core
.trace
.CtfTraceValidationStatus
;
30 import org
.junit
.Test
;
31 import org
.junit
.runner
.RunWith
;
32 import org
.junit
.runners
.Parameterized
;
33 import org
.junit
.runners
.Parameterized
.Parameters
;
36 * The class <code>CtfTmfTraceValidateTest</code> contains tests for trace
38 * <code>{@link CtfTmfTrace#validate(org.eclipse.core.resources.IProject, String)}</code>
41 * @author Bernd Hufmann
43 @RunWith(Parameterized
.class)
44 public class CtfTmfTraceValidateTest
{
46 private static final Path BASE_PATH
= Paths
.get("../org.eclipse.tracecompass.ctf.core.tests", "traces");
47 private static final Path CTF_SUITE_BASE_PATH
= Paths
.get("../org.eclipse.tracecompass.ctf.core.tests", "traces", "ctf-testsuite", "tests", "1.8");
49 private String fTrace
;
50 private int fServerity
;
51 private int fConfidence
;
52 private boolean fHasException
;
55 * Gets a list of test case parameters.
57 * @return The list of CTF traces (directories) to test
59 @Parameters(name
= "{index}: {0}")
60 public static Iterable
<Object
[]> getTracePaths() {
61 final List
<Object
[]> dirs
= new LinkedList
<>();
62 // text-only metadata, valid CTF trace (lttle-endian)
63 addDirsFrom(dirs
, CTF_SUITE_BASE_PATH
.resolve(Paths
.get("regression", "metadata", "pass", "literal-integers")), IStatus
.OK
, 10, false);
64 // packet-based metadata, valid CTF trace (lttle-endian)
65 addDirsFrom(dirs
, BASE_PATH
.resolve(Paths
.get("kernel")), IStatus
.OK
, 10, false);
66 // text-only metadata, but invalid
67 addDirsFrom(dirs
, CTF_SUITE_BASE_PATH
.resolve(Paths
.get("regression", "metadata", "fail", "enum-empty")), IStatus
.WARNING
, 1, true);
68 // packet-based metadata, but invalid
69 addDirsFrom(dirs
, CTF_SUITE_BASE_PATH
.resolve(Paths
.get("regression", "metadata", "fail", "lttng-modules-2.0-pre1")), IStatus
.WARNING
, 1, true);
70 // pass file instead of directory
71 addDirsFrom(dirs
, BASE_PATH
.resolve(Paths
.get("trace2.tar.bz2")), IStatus
.ERROR
, 1, false);
76 private static void addDirsFrom(List
<Object
[]> dirs
, Path path
, int severity
, int confidence
, boolean hasException
) {
77 if (!Files
.exists(path
)) {
78 /* Some planned directories may not exist yet in the test suite */
82 Object array
[] = new Object
[] { path
.toString(), severity
, confidence
, hasException
};
90 * severity of validation status expected
92 * confidence of validation status expected
94 * flag whether validation status should contain exception
96 public CtfTmfTraceValidateTest(String trace
, int severity
, int confidence
, boolean hasException
) {
98 fServerity
= severity
;
99 fConfidence
= confidence
;
100 fHasException
= hasException
;
107 public void testValidate() {
108 try (CtfTmfTrace trace
= new CtfTmfTrace();) {
109 IStatus status
= trace
.validate(null, fTrace
);
110 assertEquals(toString(), fServerity
, status
.getSeverity());
113 assertNotNull(toString(), status
.getException());
115 switch (status
.getSeverity()) {
117 assertTrue(status
instanceof CtfTraceValidationStatus
);
118 CtfTraceValidationStatus ctfStatus
= (CtfTraceValidationStatus
) status
;
119 assertEquals(toString(), fConfidence
, ctfStatus
.getConfidence());
120 assertNotNull(ctfStatus
.getEnvironment());
123 case IStatus
.WARNING
: {
124 assertTrue(status
instanceof TraceValidationStatus
);
125 TraceValidationStatus ctfStatus
= (TraceValidationStatus
) status
;
126 assertEquals(fConfidence
, ctfStatus
.getConfidence());
129 case IStatus
.ERROR
: {
130 // nothing else to check here
134 // no other severity should be returned
138 assertEquals(fServerity
, status
.getSeverity());