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 * Matthew Khouzam - Initial API and implementation
11 * Patrick Tasse - Fix editor handling
12 *******************************************************************************/
14 package org
.eclipse
.tracecompass
.tmf
.ctf
.ui
.swtbot
.tests
;
16 import static org
.eclipse
.swtbot
.swt
.finder
.SWTBotAssert
.assertContains
;
19 import java
.io
.IOException
;
20 import java
.nio
.file
.FileVisitResult
;
21 import java
.nio
.file
.FileVisitor
;
22 import java
.nio
.file
.Files
;
23 import java
.nio
.file
.Path
;
24 import java
.nio
.file
.Paths
;
25 import java
.nio
.file
.SimpleFileVisitor
;
26 import java
.nio
.file
.attribute
.BasicFileAttributes
;
27 import java
.util
.HashMap
;
28 import java
.util
.LinkedList
;
29 import java
.util
.List
;
32 import org
.apache
.log4j
.ConsoleAppender
;
33 import org
.apache
.log4j
.Logger
;
34 import org
.apache
.log4j
.SimpleLayout
;
35 import org
.eclipse
.swtbot
.eclipse
.finder
.SWTWorkbenchBot
;
36 import org
.eclipse
.swtbot
.swt
.finder
.SWTBot
;
37 import org
.eclipse
.swtbot
.swt
.finder
.utils
.SWTBotPreferences
;
38 import org
.eclipse
.swtbot
.swt
.finder
.waits
.Conditions
;
39 import org
.eclipse
.swtbot
.swt
.finder
.widgets
.SWTBotShell
;
40 import org
.eclipse
.tracecompass
.tmf
.ui
.swtbot
.tests
.shared
.SWTBotUtils
;
41 import org
.eclipse
.tracecompass
.tmf
.ui
.tests
.shared
.WaitUtils
;
42 import org
.junit
.After
;
43 import org
.junit
.AfterClass
;
44 import org
.junit
.BeforeClass
;
45 import org
.junit
.Test
;
46 import org
.junit
.runner
.RunWith
;
47 import org
.junit
.runners
.Parameterized
;
48 import org
.junit
.runners
.Parameterized
.Parameters
;
51 * Test invalid trace openning
53 * @author Matthew Khouzam
55 @RunWith(Parameterized
.class)
56 public class TestInvalidCtfTrace
{
58 private static final String PROJET_NAME
= "TestInvalidCtfTraces";
59 private static final Path BASE_PATH
= Paths
.get("../../ctf/org.eclipse.tracecompass.ctf.core.tests", "traces", "ctf-testsuite", "tests", "1.8");
61 /** The Log4j logger instance. */
62 private static final Logger fLogger
= Logger
.getRootLogger();
64 private static SWTWorkbenchBot fBot
;
66 private final File fLocation
;
68 private final String fExpectedMessage
;
70 private static final Map
<String
, String
> ERRORS
= new HashMap
<>();
73 ERRORS
.put("array-redefinition", "MismatchedTokenException(56!=71)");
74 ERRORS
.put("array-size-identifier", "Is not an integer: x");
75 ERRORS
.put("array-size-keyword", "NoViableAltException(74@[])");
76 ERRORS
.put("array-size-negative", "Array length is negative");
77 ERRORS
.put("array-size-not-present", "NoViableAltException(13@[])");
78 ERRORS
.put("array-size-string", "Is not an integer: x");
79 ERRORS
.put("array-size-type-field", "Is not an integer: uint32_t");
80 ERRORS
.put("array-size-type", "Is not an integer: uint32_t");
81 ERRORS
.put("integer-encoding-as-string", "Invalid value for encoding");
82 ERRORS
.put("integer-encoding-invalid", "Invalid value for encoding");
83 ERRORS
.put("integer-negative-bit-size", "Invalid value for size");
84 ERRORS
.put("integer-range", "Invalid integer format: 23452397856348975623897562893746589237465289374658923764598237645897234658723648579236");
85 ERRORS
.put("integer-signed-as-string", "Invalid boolean value");
86 ERRORS
.put("integer-signed-invalid", "Invalid boolean value svp");
87 ERRORS
.put("integer-size-as-string", "Invalid value for size");
88 ERRORS
.put("integer-size-missing", "Invalid boolean value");
89 ERRORS
.put("struct-align-enum", "Invalid value for alignment");
90 ERRORS
.put("struct-align-huge", "Invalid integer format: 0xFFFFFFFFU");
91 ERRORS
.put("struct-align-negative", "Invalid value for alignment : -8");
92 ERRORS
.put("struct-align-string", "Invalid value for alignment");
93 ERRORS
.put("struct-align-zero", "Invalid value for alignment : 0");
94 ERRORS
.put("struct-duplicate-field-name", "Identifier has already been defined:xxx");
95 ERRORS
.put("struct-duplicate-struct-name", "struct a already defined.");
96 ERRORS
.put("struct-field-name-keyword", "NoViableAltException(72@[])");
98 ERRORS
.put("content-size-larger-than-packet-size", "UNKNOWN"); //FIXME
99 ERRORS
.put("cross-packet-event-alignment-empty-struct", "UNKNOWN"); //FIXME
100 ERRORS
.put("cross-packet-event-alignment-integer", "UNKNOWN"); //FIXME
101 ERRORS
.put("cross-packet-event-array-of-integers", "UNKNOWN"); //FIXME
102 ERRORS
.put("cross-packet-event-float", "UNKNOWN"); //FIXME
103 ERRORS
.put("cross-packet-event-integer", "UNKNOWN"); //FIXME
104 ERRORS
.put("cross-packet-event-len-of-sequence", "UNKNOWN"); //FIXME
105 ERRORS
.put("cross-packet-event-sequence-between-elements", "UNKNOWN"); //FIXME
106 ERRORS
.put("cross-packet-event-sequence-start", "UNKNOWN"); //FIXME
107 ERRORS
.put("out-of-bound-empty-event-with-aligned-struct", "UNKNOWN"); //FIXME
108 ERRORS
.put("out-of-bound-float", "UNKNOWN"); //FIXME
109 ERRORS
.put("out-of-bound-integer", "UNKNOWN"); //FIXME
110 ERRORS
.put("out-of-bound-large-sequence-length", "UNKNOWN"); //FIXME
111 ERRORS
.put("out-of-bound-len-of-sequence", "UNKNOWN"); //FIXME
112 ERRORS
.put("out-of-bound-packet-header", "UNKNOWN"); //FIXME
113 ERRORS
.put("out-of-bound-sequence-between-elements", "UNKNOWN"); //FIXME
114 ERRORS
.put("out-of-bound-sequence-start", "UNKNOWN"); //FIXME
115 ERRORS
.put("out-of-bound-sequence-within-element", "UNKNOWN"); //FIXME
120 * Populate the parameters
122 * @return the parameters. Basically all the errors with lookuped paths
124 @Parameters(name
= "{index}: {0}")
125 public static Iterable
<Object
[]> getTracePaths() {
126 final List
<Object
[]> dirs
= new LinkedList
<>();
128 FileVisitor
<Path
> visitor
= new SimpleFileVisitor
<Path
>() {
130 public FileVisitResult
preVisitDirectory(Path dir
, BasicFileAttributes attrs
) throws IOException
{
131 final Path fileName
= dir
.getFileName();
132 String res
= ERRORS
.get(fileName
.toString());
134 dirs
.add(new Object
[] { dir
.toFile(), res
});
135 return FileVisitResult
.SKIP_SUBTREE
;
137 return FileVisitResult
.CONTINUE
;
141 /* TODO: add way of handling an error in a trace during a run */
142 /* when that is done, we can add regression/stream/fail */
144 Path badMetadata
= BASE_PATH
.resolve(Paths
.get("regression", "metadata", "fail"));
146 Files
.walkFileTree(badMetadata
, visitor
);
147 } catch (IOException e
) {
158 * @param errorMessage
161 public TestInvalidCtfTrace(File location
, String errorMessage
) {
162 fLocation
= location
;
163 fExpectedMessage
= errorMessage
;
170 public static void beforeClass() {
171 SWTBotUtils
.initialize();
172 Thread
.currentThread().setName("SWTBot Thread"); // for the debugger
173 /* set up for swtbot */
174 SWTBotPreferences
.TIMEOUT
= 20000; /* 20 second timeout */
175 fLogger
.removeAllAppenders();
176 fLogger
.addAppender(new ConsoleAppender(new SimpleLayout()));
177 fBot
= new SWTWorkbenchBot();
179 SWTBotUtils
.closeView("welcome", fBot
);
181 SWTBotUtils
.switchToTracingPerspective();
182 /* finish waiting for eclipse to load */
183 WaitUtils
.waitForJobs();
184 SWTBotUtils
.createProject(PROJET_NAME
);
192 public void teardown() {
193 SWTBotUtils
.clearTracesFolder(fBot
, PROJET_NAME
);
194 SWTBotUtils
.closeSecondaryShells(fBot
);
201 public static void afterClass() {
202 SWTBotUtils
.deleteProject(PROJET_NAME
, fBot
);
203 fLogger
.removeAllAppenders();
207 * Open an invalid trace and see the message
210 public void testOpen() {
211 SWTBotUtils
.selectTracesFolder(fBot
, PROJET_NAME
);
212 SWTBotUtils
.openTrace(PROJET_NAME
, fLocation
.getAbsolutePath(), "org.eclipse.linuxtools.tmf.ui.type.ctf", false);
213 fBot
.waitUntil(Conditions
.shellIsActive("Open Trace"));
214 final SWTBotShell shell
= fBot
.activeShell();
215 final SWTBot dialogBot
= shell
.bot();
216 String text
= dialogBot
.label(1).getText();
217 dialogBot
.button().click();
218 fBot
.waitUntil(Conditions
.shellCloses(shell
));
219 assertContains(fExpectedMessage
, text
);