ctf: Speed up StandardImportAndReadSmokeTest
[deliverable/tracecompass.git] / ctf / org.eclipse.tracecompass.tmf.ctf.ui.swtbot.tests / src / org / eclipse / tracecompass / tmf / ctf / ui / swtbot / tests / TestInvalidCtfTrace.java
CommitLineData
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
14package org.eclipse.tracecompass.tmf.ctf.ui.swtbot.tests;
15
16import static org.eclipse.swtbot.swt.finder.SWTBotAssert.assertContains;
17
18import java.io.File;
19import java.io.IOException;
20import java.nio.file.FileVisitResult;
21import java.nio.file.FileVisitor;
22import java.nio.file.Files;
23import java.nio.file.Path;
24import java.nio.file.Paths;
25import java.nio.file.SimpleFileVisitor;
26import java.nio.file.attribute.BasicFileAttributes;
27import java.util.HashMap;
28import java.util.LinkedList;
29import java.util.List;
30import java.util.Map;
31
32import org.apache.log4j.ConsoleAppender;
33import org.apache.log4j.Logger;
34import org.apache.log4j.SimpleLayout;
35import org.eclipse.swtbot.eclipse.finder.SWTWorkbenchBot;
36import org.eclipse.swtbot.swt.finder.SWTBot;
37import org.eclipse.swtbot.swt.finder.utils.SWTBotPreferences;
38import org.eclipse.swtbot.swt.finder.waits.Conditions;
39import org.eclipse.swtbot.swt.finder.widgets.SWTBotShell;
40import org.eclipse.tracecompass.tmf.ui.swtbot.tests.shared.SWTBotUtils;
41import org.junit.After;
42import org.junit.Before;
43import org.junit.Test;
44import org.junit.runner.RunWith;
45import org.junit.runners.Parameterized;
46import org.junit.runners.Parameterized.Parameters;
47
48/**
49 * Test invalid trace openning
50 *
51 * @author Matthew Khouzam
52 */
53@RunWith(Parameterized.class)
54public class TestInvalidCtfTrace {
55
56 private static final String PROJET_NAME = "TestInvalidCtfTraces";
3e6e367c 57 private static final Path BASE_PATH = Paths.get("../../ctf/org.eclipse.tracecompass.ctf.core.tests", "traces", "ctf-testsuite", "tests", "1.8");
b373d07b
MK
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
73511e67 71 ERRORS.put("array-redefinition", "MismatchedTokenException(56!=71)");
b373d07b 72 ERRORS.put("array-size-identifier", "Is not an integer: x");
73511e67 73 ERRORS.put("array-size-keyword", "NoViableAltException(74@[])");
b373d07b 74 ERRORS.put("array-size-negative", "Array length is negative");
73511e67 75 ERRORS.put("array-size-not-present", "NoViableAltException(13@[])");
b373d07b
MK
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");
b1ea73b5 83 ERRORS.put("integer-signed-as-string", "Invalid boolean value");
b373d07b
MK
84 ERRORS.put("integer-signed-invalid", "Invalid boolean value svp");
85 ERRORS.put("integer-size-as-string", "Invalid value for size");
b1ea73b5 86 ERRORS.put("integer-size-missing", "Invalid boolean value");
b373d07b
MK
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.");
73511e67 94 ERRORS.put("struct-field-name-keyword", "NoViableAltException(72@[])");
b373d07b
MK
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() {
5785ab49 169 SWTBotUtils.initialize();
b373d07b
MK
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}
This page took 0.04015 seconds and 5 git commands to generate.