Commit | Line | Data |
---|---|---|
b373d07b MK |
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 | * Matthew Khouzam - Initial API and implementation | |
11 | * Patrick Tasse - Fix editor handling | |
12 | *******************************************************************************/ | |
13 | ||
14 | package org.eclipse.tracecompass.tmf.ctf.ui.swtbot.tests; | |
15 | ||
16 | import static org.eclipse.swtbot.swt.finder.SWTBotAssert.assertContains; | |
17 | ||
18 | import java.io.File; | |
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; | |
30 | import java.util.Map; | |
31 | ||
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.junit.After; | |
42 | import org.junit.Before; | |
43 | import org.junit.Test; | |
44 | import org.junit.runner.RunWith; | |
45 | import org.junit.runners.Parameterized; | |
46 | import org.junit.runners.Parameterized.Parameters; | |
47 | ||
48 | /** | |
49 | * Test invalid trace openning | |
50 | * | |
51 | * @author Matthew Khouzam | |
52 | */ | |
53 | @RunWith(Parameterized.class) | |
54 | public class TestInvalidCtfTrace { | |
55 | ||
56 | private static final String PROJET_NAME = "TestInvalidCtfTraces"; | |
57 | private static final Path BASE_PATH = Paths.get("../org.eclipse.tracecompass.ctf.core.tests", "traces", "ctf-testsuite", "tests", "1.8"); | |
58 | ||
59 | /** The Log4j logger instance. */ | |
60 | private static final Logger fLogger = Logger.getRootLogger(); | |
61 | ||
62 | private static SWTWorkbenchBot fBot; | |
63 | ||
64 | private final File fLocation; | |
65 | ||
66 | private final String fExpectedMessage; | |
67 | ||
68 | private static final Map<String, String> ERRORS = new HashMap<>(); | |
69 | static { | |
70 | // metadata | |
71 | ERRORS.put("array-redefinition", "MismatchedTokenException(57!=72)"); | |
72 | ERRORS.put("array-size-identifier", "Is not an integer: x"); | |
73 | ERRORS.put("array-size-keyword", "NoViableAltException(75@[])"); | |
74 | ERRORS.put("array-size-negative", "Array length is negative"); | |
75 | ERRORS.put("array-size-not-present", "NoViableAltException(14@[])"); | |
76 | ERRORS.put("array-size-string", "Is not an integer: x"); | |
77 | ERRORS.put("array-size-type-field", "Is not an integer: uint32_t"); | |
78 | ERRORS.put("array-size-type", "Is not an integer: uint32_t"); | |
79 | ERRORS.put("integer-encoding-as-string", "Invalid value for encoding"); | |
80 | ERRORS.put("integer-encoding-invalid", "Invalid value for encoding"); | |
81 | ERRORS.put("integer-negative-bit-size", "Invalid value for size"); | |
82 | ERRORS.put("integer-range", "Invalid integer format: 23452397856348975623897562893746589237465289374658923764598237645897234658723648579236"); | |
83 | ERRORS.put("integer-signed-as-string", "org.eclipse.tracecompass.internal.ctf.core.event.metadata.exceptions.ParseException"); | |
84 | ERRORS.put("integer-signed-invalid", "Invalid boolean value svp"); | |
85 | ERRORS.put("integer-size-as-string", "Invalid value for size"); | |
86 | ERRORS.put("integer-size-missing", "org.eclipse.tracecompass.internal.ctf.core.event.metadata.exceptions.ParseException"); | |
87 | ERRORS.put("struct-align-enum", "Invalid value for alignment"); | |
88 | ERRORS.put("struct-align-huge", "Invalid integer format: 0xFFFFFFFFU"); | |
89 | ERRORS.put("struct-align-negative", "Invalid value for alignment : -8"); | |
90 | ERRORS.put("struct-align-string", "Invalid value for alignment"); | |
91 | ERRORS.put("struct-align-zero", "Invalid value for alignment : 0"); | |
92 | ERRORS.put("struct-duplicate-field-name", "Identifier has already been defined:xxx"); | |
93 | ERRORS.put("struct-duplicate-struct-name", "struct a already defined."); | |
94 | ERRORS.put("struct-field-name-keyword", "NoViableAltException(73@[])"); | |
95 | // streams | |
96 | ERRORS.put("content-size-larger-than-packet-size", "UNKNOWN"); //FIXME | |
97 | ERRORS.put("cross-packet-event-alignment-empty-struct", "UNKNOWN"); //FIXME | |
98 | ERRORS.put("cross-packet-event-alignment-integer", "UNKNOWN"); //FIXME | |
99 | ERRORS.put("cross-packet-event-array-of-integers", "UNKNOWN"); //FIXME | |
100 | ERRORS.put("cross-packet-event-float", "UNKNOWN"); //FIXME | |
101 | ERRORS.put("cross-packet-event-integer", "UNKNOWN"); //FIXME | |
102 | ERRORS.put("cross-packet-event-len-of-sequence", "UNKNOWN"); //FIXME | |
103 | ERRORS.put("cross-packet-event-sequence-between-elements", "UNKNOWN"); //FIXME | |
104 | ERRORS.put("cross-packet-event-sequence-start", "UNKNOWN"); //FIXME | |
105 | ERRORS.put("out-of-bound-empty-event-with-aligned-struct", "UNKNOWN"); //FIXME | |
106 | ERRORS.put("out-of-bound-float", "UNKNOWN"); //FIXME | |
107 | ERRORS.put("out-of-bound-integer", "UNKNOWN"); //FIXME | |
108 | ERRORS.put("out-of-bound-large-sequence-length", "UNKNOWN"); //FIXME | |
109 | ERRORS.put("out-of-bound-len-of-sequence", "UNKNOWN"); //FIXME | |
110 | ERRORS.put("out-of-bound-packet-header", "UNKNOWN"); //FIXME | |
111 | ERRORS.put("out-of-bound-sequence-between-elements", "UNKNOWN"); //FIXME | |
112 | ERRORS.put("out-of-bound-sequence-start", "UNKNOWN"); //FIXME | |
113 | ERRORS.put("out-of-bound-sequence-within-element", "UNKNOWN"); //FIXME | |
114 | ||
115 | } | |
116 | ||
117 | /** | |
118 | * Populate the parameters | |
119 | * | |
120 | * @return the parameters. Basically all the errors with lookuped paths | |
121 | */ | |
122 | @Parameters(name = "{index}: {0}") | |
123 | public static Iterable<Object[]> getTracePaths() { | |
124 | final List<Object[]> dirs = new LinkedList<>(); | |
125 | ||
126 | FileVisitor<Path> visitor = new SimpleFileVisitor<Path>() { | |
127 | @Override | |
128 | public FileVisitResult preVisitDirectory(Path dir, BasicFileAttributes attrs) throws IOException { | |
129 | final Path fileName = dir.getFileName(); | |
130 | String res = ERRORS.get(fileName.toString()); | |
131 | if (res != null) { | |
132 | dirs.add(new Object[] { dir.toFile(), res }); | |
133 | return FileVisitResult.SKIP_SUBTREE; | |
134 | } | |
135 | return FileVisitResult.CONTINUE; | |
136 | } | |
137 | ||
138 | }; | |
139 | /* TODO: add way of handling an error in a trace during a run */ | |
140 | /* when that is done, we can add regression/stream/fail */ | |
141 | ||
142 | Path badMetadata = BASE_PATH.resolve(Paths.get("regression", "metadata", "fail")); | |
143 | try { | |
144 | Files.walkFileTree(badMetadata, visitor); | |
145 | } catch (IOException e) { | |
146 | e.printStackTrace(); | |
147 | } | |
148 | return dirs; | |
149 | } | |
150 | ||
151 | /** | |
152 | * Constructor | |
153 | * | |
154 | * @param location | |
155 | * trace file | |
156 | * @param errorMessage | |
157 | * error message | |
158 | */ | |
159 | public TestInvalidCtfTrace(File location, String errorMessage) { | |
160 | fLocation = location; | |
161 | fExpectedMessage = errorMessage; | |
162 | } | |
163 | ||
164 | /** | |
165 | * Initialization | |
166 | */ | |
167 | @Before | |
168 | public void init() { | |
169 | SWTBotUtils.failIfUIThread(); | |
170 | Thread.currentThread().setName("SWTBot Thread"); // for the debugger | |
171 | /* set up for swtbot */ | |
172 | SWTBotPreferences.TIMEOUT = 20000; /* 20 second timeout */ | |
173 | fLogger.removeAllAppenders(); | |
174 | fLogger.addAppender(new ConsoleAppender(new SimpleLayout())); | |
175 | fBot = new SWTWorkbenchBot(); | |
176 | ||
177 | SWTBotUtils.closeView("welcome", fBot); | |
178 | ||
179 | SWTBotUtils.switchToTracingPerspective(); | |
180 | /* finish waiting for eclipse to load */ | |
181 | SWTBotUtils.waitForJobs(); | |
182 | SWTBotUtils.createProject(PROJET_NAME); | |
183 | ||
184 | } | |
185 | ||
186 | /** | |
187 | * Delete file | |
188 | */ | |
189 | @After | |
190 | public void cleanup() { | |
191 | SWTBotUtils.deleteProject(PROJET_NAME, fBot); | |
192 | fLogger.removeAllAppenders(); | |
193 | } | |
194 | ||
195 | /** | |
196 | * Open an invalid trace and see the message | |
197 | */ | |
198 | @Test | |
199 | public void testOpen() { | |
200 | SWTBotUtils.selectTracesFolder(fBot, PROJET_NAME); | |
201 | SWTBotUtils.openTrace(PROJET_NAME, fLocation.getAbsolutePath(), "org.eclipse.linuxtools.tmf.ui.type.ctf"); | |
202 | fBot.waitUntil(Conditions.shellIsActive("Open Trace")); | |
203 | final SWTBotShell shell = fBot.activeShell(); | |
204 | final SWTBot dialogBot = shell.bot(); | |
205 | String text = dialogBot.label(1).getText(); | |
206 | dialogBot.button().click(); | |
207 | fBot.waitUntil(Conditions.shellCloses(shell)); | |
208 | assertContains(fExpectedMessage, text); | |
209 | ||
210 | } | |
211 | ||
212 | } |