1 /******************************************************************************
2 * Copyright (c) 2016 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
8 *******************************************************************************/
10 package org
.eclipse
.tracecompass
.integration
.swtbot
.tests
.projectexplorer
;
12 import static org
.junit
.Assert
.assertEquals
;
13 import static org
.junit
.Assert
.assertNotEquals
;
16 import java
.io
.IOException
;
17 import java
.util
.List
;
19 import java
.util
.function
.Supplier
;
21 import org
.apache
.log4j
.Logger
;
22 import org
.apache
.log4j
.varia
.NullAppender
;
23 import org
.eclipse
.core
.runtime
.IPath
;
24 import org
.eclipse
.core
.runtime
.Path
;
25 import org
.eclipse
.jdt
.annotation
.NonNull
;
26 import org
.eclipse
.swtbot
.eclipse
.finder
.SWTWorkbenchBot
;
27 import org
.eclipse
.swtbot
.eclipse
.finder
.widgets
.SWTBotEditor
;
28 import org
.eclipse
.swtbot
.eclipse
.finder
.widgets
.SWTBotView
;
29 import org
.eclipse
.swtbot
.swt
.finder
.SWTBot
;
30 import org
.eclipse
.swtbot
.swt
.finder
.junit
.SWTBotJunit4ClassRunner
;
31 import org
.eclipse
.swtbot
.swt
.finder
.utils
.SWTBotPreferences
;
32 import org
.eclipse
.swtbot
.swt
.finder
.waits
.Conditions
;
33 import org
.eclipse
.swtbot
.swt
.finder
.widgets
.SWTBotButton
;
34 import org
.eclipse
.swtbot
.swt
.finder
.widgets
.SWTBotShell
;
35 import org
.eclipse
.swtbot
.swt
.finder
.widgets
.SWTBotTreeItem
;
36 import org
.eclipse
.tracecompass
.internal
.tmf
.ui
.project
.wizards
.importtrace
.ImportConfirmation
;
37 import org
.eclipse
.tracecompass
.internal
.tmf
.ui
.project
.wizards
.importtrace
.ImportTraceWizardPage
;
38 import org
.eclipse
.tracecompass
.tmf
.core
.parsers
.custom
.CustomTxtTraceDefinition
;
39 import org
.eclipse
.tracecompass
.tmf
.core
.parsers
.custom
.CustomXmlTraceDefinition
;
40 import org
.eclipse
.tracecompass
.tmf
.core
.trace
.TmfTraceManager
;
41 import org
.eclipse
.tracecompass
.tmf
.ctf
.ui
.swtbot
.tests
.SWTBotImportWizardUtils
;
42 import org
.eclipse
.tracecompass
.tmf
.ui
.swtbot
.tests
.shared
.ConditionHelpers
;
43 import org
.eclipse
.tracecompass
.tmf
.ui
.swtbot
.tests
.shared
.SWTBotUtils
;
44 import org
.eclipse
.tracecompass
.tmf
.ui
.tests
.shared
.WaitUtils
;
45 import org
.eclipse
.ui
.IPageLayout
;
46 import org
.junit
.AfterClass
;
47 import org
.junit
.BeforeClass
;
48 import org
.junit
.FixMethodOrder
;
49 import org
.junit
.Test
;
50 import org
.junit
.runner
.RunWith
;
51 import org
.junit
.runners
.MethodSorters
;
53 import com
.google
.common
.collect
.ImmutableList
;
54 import com
.google
.common
.collect
.ImmutableSet
;
57 * SWTBot test for testing Project Explorer trace folders (context-menu,
60 @RunWith(SWTBotJunit4ClassRunner
.class)
61 @FixMethodOrder(MethodSorters
.NAME_ASCENDING
)
62 @SuppressWarnings({"restriction", "javadoc"})
63 public class ProjectExplorerTracesFolderTest
{
65 private static final String PROP_LAST_MODIFIED_PROPERTY
= "last modified";
66 private static final String TEXT_EDITOR_ID
= "org.eclipse.ui.DefaultTextEditor";
68 private static final String GENERIC_CTF_TRACE_TYPE
= "Common Trace Format : Generic CTF Trace";
69 private static final String LTTNG_KERNEL_TRACE_TYPE
= "Common Trace Format : Linux Kernel Trace";
70 private static final String LTTNG_UST_TRACE_TYPE
= "Common Trace Format : LTTng UST Trace";
71 private static final String CUSTOM_TEXT_TRACE_TYPE
= "Custom Text : TmfGeneric";
72 private static final String CUSTOM_XML_TRACE_TYPE
= "Custom XML : Custom XML Log";
74 private static final @NonNull TestTraceInfo CUSTOM_TEXT_LOG
= new TestTraceInfo("ExampleCustomTxt.log", CUSTOM_TEXT_TRACE_TYPE
, 10, "29:52.034");
75 private static final @NonNull TestTraceInfo CUSTOM_XML_LOG
= new TestTraceInfo("ExampleCustomXml.xml", CUSTOM_XML_TRACE_TYPE
, 6, "22:01:20");
76 private static final @NonNull TestTraceInfo LTTNG_KERNEL_TRACE
= new TestTraceInfo("kernel-overlap-testing", LTTNG_KERNEL_TRACE_TYPE
, 1000, "04:32.650 993 664");
77 private static final @NonNull TestTraceInfo SIMPLE_SERVER1_UST_TRACE
= new TestTraceInfo("simple_server-thread1", LTTNG_UST_TRACE_TYPE
, 1000, "04:32.650 993 664");
78 private static final @NonNull TestTraceInfo SIMPLE_SERVER2_UST_TRACE
= new TestTraceInfo("simple_server-thread2", LTTNG_UST_TRACE_TYPE
, 1000, "04:32.650 993 664");
79 private static final @NonNull TestTraceInfo UST_OVERLAP_TESTING_UST_TRACE
= new TestTraceInfo("ust-overlap-testing", LTTNG_UST_TRACE_TYPE
, 1000, "04:32.650 993 664");
81 private static final String CLASHES_DIR_NAME
= "z-clashes";
82 private static final @NonNull TestTraceInfo CLASHES_CUSTOM_TEXT_LOG
= new TestTraceInfo("ExampleCustomTxt.log", CLASHES_DIR_NAME
+ "/ExampleCustomTxt.log", CUSTOM_TEXT_TRACE_TYPE
, 11, "29:52.034");
83 private static final @NonNull TestTraceInfo CLASHES_CUSTOM_XML_LOG
= new TestTraceInfo("ExampleCustomXml.xml", CLASHES_DIR_NAME
+ "/ExampleCustomXml.xml", CUSTOM_XML_TRACE_TYPE
, 7, "22:01:20");
84 private static final @NonNull TestTraceInfo CLASHES_LTTNG_KERNEL_TRACE
= new TestTraceInfo("kernel-overlap-testing", CLASHES_DIR_NAME
+ "/kernel-overlap-testing", LTTNG_KERNEL_TRACE_TYPE
, 1001, "04:32.650 993 664");
85 private static final @NonNull TestTraceInfo CLASHES_SIMPLE_SERVER1_UST_TRACE
= new TestTraceInfo("simple_server-thread1", CLASHES_DIR_NAME
+ "/simple_server-thread1", LTTNG_UST_TRACE_TYPE
, 1001, "04:32.650 993 664");
86 private static final @NonNull TestTraceInfo CLASHES_SIMPLE_SERVER2_UST_TRACE
= new TestTraceInfo("simple_server-thread2", CLASHES_DIR_NAME
+ "/simple_server-thread2", LTTNG_UST_TRACE_TYPE
, 1001, "04:32.650 993 664");
87 private static final @NonNull TestTraceInfo CLASHES_UST_OVERLAP_TESTING_UST_TRACE
= new TestTraceInfo("ust-overlap-testing", CLASHES_DIR_NAME
+ "/ust-overlap-testing", LTTNG_UST_TRACE_TYPE
, 1001, "04:32.650 993 664");
90 private static final @NonNull TestTraceInfo LTTNG_KERNEL_TRACE_METADATA
= new TestTraceInfo(LTTNG_KERNEL_TRACE
.getTraceName(), LTTNG_KERNEL_TRACE
.getTraceName() + "/metadata", LTTNG_KERNEL_TRACE
.getTraceType(), LTTNG_KERNEL_TRACE
.getNbEvents(),
91 LTTNG_KERNEL_TRACE
.getFirstEventTimestamp());
92 private static final @NonNull TestTraceInfo UNRECOGNIZED_LOG
= new TestTraceInfo("unrecognized.log", "", 0, "");
93 private static final @NonNull TestTraceInfo CUSTOM_XML_LOG_AS_TEXT
= new TestTraceInfo("ExampleCustomXml.xml", CUSTOM_TEXT_TRACE_TYPE
, 0, "");
95 private static final TestTraceInfo
[] ALL_TRACEINFOS
= new TestTraceInfo
[] {
99 SIMPLE_SERVER1_UST_TRACE
,
100 SIMPLE_SERVER2_UST_TRACE
,
101 UST_OVERLAP_TESTING_UST_TRACE
,
103 CLASHES_CUSTOM_TEXT_LOG
,
104 CLASHES_CUSTOM_XML_LOG
,
105 CLASHES_LTTNG_KERNEL_TRACE
,
106 CLASHES_SIMPLE_SERVER1_UST_TRACE
,
107 CLASHES_SIMPLE_SERVER2_UST_TRACE
,
108 CLASHES_UST_OVERLAP_TESTING_UST_TRACE
111 private static final Set
<TestTraceInfo
> CLASHING_TRACEINFOS
= ImmutableSet
.of(
112 CLASHES_CUSTOM_TEXT_LOG
,
113 CLASHES_CUSTOM_XML_LOG
,
114 CLASHES_LTTNG_KERNEL_TRACE
,
115 CLASHES_SIMPLE_SERVER1_UST_TRACE
,
116 CLASHES_SIMPLE_SERVER2_UST_TRACE
,
117 CLASHES_UST_OVERLAP_TESTING_UST_TRACE
);
119 // All normal traces plus the unrecognized trace
120 private static final int NUM_UNIQUE_TRACES
= CLASHING_TRACEINFOS
.size() + 1;
123 private static final File TEST_TRACES_PATH
= new File(new Path(TmfTraceManager
.getTemporaryDirPath()).append("testtraces").toOSString());
124 private static final String TRACE_PROJECT_NAME
= "test";
125 private static final String MANAGE_CUSTOM_PARSERS_SHELL_TITLE
= "Manage Custom Parsers";
127 private static SWTWorkbenchBot fBot
;
129 /** The Log4j logger instance. */
130 private static final Logger fLogger
= Logger
.getRootLogger();
132 private static String
getPath(String relativePath
) {
133 return new Path(TEST_TRACES_PATH
.getAbsolutePath()).append(relativePath
).toOSString();
139 * @throws IOException
142 public static void init() throws IOException
{
143 TestDirectoryStructureUtil
.generateTraceStructure(TEST_TRACES_PATH
);
145 SWTBotUtils
.initialize();
147 /* Set up for swtbot */
148 SWTBotPreferences
.TIMEOUT
= 20000; /* 20 second timeout */
149 SWTBotPreferences
.KEYBOARD_LAYOUT
= "EN_US";
150 fLogger
.removeAllAppenders();
151 fLogger
.addAppender(new NullAppender());
152 fBot
= new SWTWorkbenchBot();
154 SWTBotUtils
.closeView("Welcome", fBot
);
156 SWTBotUtils
.switchToTracingPerspective();
158 /* Finish waiting for eclipse to load */
159 WaitUtils
.waitForJobs();
160 SWTBotUtils
.createProject(TRACE_PROJECT_NAME
);
164 * Test class tear down method.
167 public static void tearDown() {
168 SWTBotUtils
.deleteProject(TRACE_PROJECT_NAME
, fBot
);
169 fLogger
.removeAllAppenders();
172 private static void test3_01Preparation() {
173 // FIXME: We can't use Manage Custom Parsers > Import because it uses a native dialog. We'll still check that they show up in the dialog
174 CustomTxtTraceDefinition
[] txtDefinitions
= CustomTxtTraceDefinition
.loadAll(getPath("customParsers/ExampleCustomTxtParser.xml"));
175 txtDefinitions
[0].save();
176 CustomXmlTraceDefinition
[] xmlDefinitions
= CustomXmlTraceDefinition
.loadAll(getPath("customParsers/ExampleCustomXmlParser.xml"));
177 xmlDefinitions
[0].save();
179 SWTBotTreeItem traceFolder
= SWTBotUtils
.selectTracesFolder(fBot
, TRACE_PROJECT_NAME
);
180 traceFolder
.contextMenu("Manage Custom Parsers...").click();
181 fBot
.waitUntil(Conditions
.shellIsActive(MANAGE_CUSTOM_PARSERS_SHELL_TITLE
));
182 SWTBotShell shell
= fBot
.shell(MANAGE_CUSTOM_PARSERS_SHELL_TITLE
);
183 SWTBot shellBot
= shell
.bot();
185 // Make sure the custom text trace type is imported
186 shellBot
.list().select(CUSTOM_TEXT_LOG
.getTraceType());
188 // Make sure the custom xml trace type is imported
189 shellBot
.radio("XML").click();
190 shellBot
.list().select(CUSTOM_XML_LOG
.getTraceType());
191 shellBot
.button("Close").click();
192 shellBot
.waitUntil(Conditions
.shellCloses(shell
));
196 * Test that the expected context menu items are there
198 * Action : Trace Folder menu
200 * Procedure :Select the Traces folder and open its context menu
202 * Expected Results: Correct menu opens (Import, Refresh, etc)
205 public void test3_01ContextMenuPresence() {
206 test3_01Preparation();
208 SWTBotTreeItem traceItem
= SWTBotUtils
.selectTracesFolder(fBot
, TRACE_PROJECT_NAME
);
210 final List
<String
> EXPECTED_MENU_LABELS
= ImmutableList
.of(
218 "Import Trace Package...",
219 "Fetch Remote Traces...",
221 "Export Trace Package...",
223 "Manage Custom Parsers...",
224 "Manage XML analyses...",
226 "Apply Time Offset...",
231 List
<String
> menuLabels
= traceItem
.contextMenu().menuItems();
232 for (int i
= 0; i
< menuLabels
.size(); i
++) {
233 assertEquals(EXPECTED_MENU_LABELS
.get(i
), menuLabels
.get(i
));
236 fBot
.closeAllEditors();
240 * Test that the trace import wizard appears
242 * Action : Trace Import Wizard
244 * Procedure : Select Import
246 * Expected Results: Trace Import Wizard appears
249 public void test3_02Import() {
250 SWTBotTreeItem traceItem
= SWTBotUtils
.selectTracesFolder(fBot
, TRACE_PROJECT_NAME
);
252 SWTBotShell shell
= openTraceFoldersImport(traceItem
);
253 shell
.bot().button("Cancel").click();
257 * Test that the trace import wizard can import a single custom text trace
259 * Action : Import single custom text trace (link to workspace)
262 * Procedure : 1) Browse to directory ${local}/traces/import/
263 * 2) Select trace ExampleCustomTxt.log
264 * 3) Keep <Auto Detection>, Select "Import unrecognized traces", unselect "Overwrite existing without warning" and select "Create Links to workspace" and
268 * Expected Results: Imported trace appear in Traces Folder and the Trace Type Tmf Generic is set. Make sure trace can be opened
271 public void test3_03SingleCustomTextTrace() {
272 int optionFlags
= ImportTraceWizardPage
.OPTION_IMPORT_UNRECOGNIZED_TRACES
| ImportTraceWizardPage
.OPTION_CREATE_LINKS_IN_WORKSPACE
;
273 testSingleTrace(CUSTOM_TEXT_LOG
, optionFlags
);
278 * Action : Import Single custom XML trace (link to workspace)
282 * Procedure : redo 3.1-3.3 but this time select ExampleCustomXml.xml
285 * Expected Results: Imported trace appear in Traces Folder and the Trace
286 * Type "Custom XML log" is set. Make sure that trace can be opened
289 public void test3_04SingleCustomXmlTrace() {
290 int optionFlags
= ImportTraceWizardPage
.OPTION_IMPORT_UNRECOGNIZED_TRACES
| ImportTraceWizardPage
.OPTION_CREATE_LINKS_IN_WORKSPACE
;
291 testSingleTrace(CUSTOM_XML_LOG
, optionFlags
);
296 * Action : Import LTTng Kernel CTF trace (link to workspace)
300 * Procedure : redo 3.1-3.3 but this time select directory kernel-overlap-testing/
303 * Expected Results: Imported trace appear in Traces Folder and the Trace
304 * Type "LTTng Kernel" is set. Make sure that trace can be opened
307 public void test3_05SingleCtfTrace() {
308 int optionFlags
= ImportTraceWizardPage
.OPTION_IMPORT_UNRECOGNIZED_TRACES
| ImportTraceWizardPage
.OPTION_CREATE_LINKS_IN_WORKSPACE
;
309 testSingleTrace(LTTNG_KERNEL_TRACE
, optionFlags
);
314 * Action : Rename + copy import
318 * Procedure : 1) redo 3.3, 3.4, 3.5. However, Unselect "Create Links to workspace"
319 * 2) When dialog box appear select Rename
322 * Expected Results: Traces are imported with new name that has a suffix (2)
323 * at the end. Make sure that imported traces are copied to the project.
326 public void test3_06RenameCopyImport() {
327 testRenameCopyImport(CUSTOM_TEXT_LOG
);
328 testRenameCopyImport(CUSTOM_XML_LOG
);
329 testRenameCopyImport(LTTNG_KERNEL_TRACE
);
332 private static void testRenameCopyImport(TestTraceInfo traceInfo
) {
333 int optionFlags
= ImportTraceWizardPage
.OPTION_IMPORT_UNRECOGNIZED_TRACES
;
334 importTrace(optionFlags
, ImportConfirmation
.RENAME
, traceInfo
.getTraceName());
335 String renamed
= toRenamedName(traceInfo
.getTraceName());
336 verifyTrace(traceInfo
, optionFlags
, renamed
);
341 * Action : Overwrite + copy import
345 * Procedure : 1) redo 3.3, 3.4, 3.5. However, Unselect "Create Links to workspace"
346 * 2) When dialog box appear select Overwrite
349 * Expected Results: Existing traces are deleted and new traces are
350 * imported. Make sure that imported traces are copied to the project and
354 public void test3_07OverwriteCopyImport() {
355 testOverwriteCopyImport(CUSTOM_TEXT_LOG
);
356 testOverwriteCopyImport(CUSTOM_XML_LOG
);
357 testOverwriteCopyImport(LTTNG_KERNEL_TRACE
);
360 private static void testOverwriteCopyImport(TestTraceInfo traceInfo
) {
361 String traceName
= traceInfo
.getTraceName();
362 SWTBotTreeItem traceItem
= SWTBotUtils
.getTreeItem(fBot
, SWTBotUtils
.selectTracesFolder(fBot
, TRACE_PROJECT_NAME
), traceName
);
363 String lastModified
= getTraceProperty(traceItem
, PROP_LAST_MODIFIED_PROPERTY
);
364 int optionFlags
= ImportTraceWizardPage
.OPTION_IMPORT_UNRECOGNIZED_TRACES
;
365 importTrace(optionFlags
, ImportConfirmation
.OVERWRITE
, traceName
);
366 verifyTrace(traceInfo
, optionFlags
);
368 assertNotEquals(lastModified
, getTraceProperty(traceItem
, PROP_LAST_MODIFIED_PROPERTY
));
377 * Procedure : 1) redo 3.3, 3.4, 3.5. However, Unselect "Create Links to workspace"
378 * 2) When dialog box appear select Skip
381 * Expected Results: Make sure that no new trace is imported
384 public void test3_08SkipImport() {
385 testSkipImport(CUSTOM_TEXT_LOG
);
386 testSkipImport(CUSTOM_XML_LOG
);
387 testSkipImport(LTTNG_KERNEL_TRACE
);
390 private static void testSkipImport(TestTraceInfo traceInfo
) {
391 String traceName
= traceInfo
.getTraceName();
392 SWTBotTreeItem traceItem
= SWTBotUtils
.getTreeItem(fBot
, SWTBotUtils
.selectTracesFolder(fBot
, TRACE_PROJECT_NAME
), traceName
);
393 String lastModified
= getTraceProperty(traceItem
, PROP_LAST_MODIFIED_PROPERTY
);
394 int optionFlags
= ImportTraceWizardPage
.OPTION_IMPORT_UNRECOGNIZED_TRACES
;
395 importTrace(optionFlags
, ImportConfirmation
.SKIP
, traceName
);
396 verifyTrace(traceInfo
, optionFlags
);
398 assertEquals(lastModified
, getTraceProperty(traceItem
, PROP_LAST_MODIFIED_PROPERTY
));
403 * Action : Default overwrite
407 * Procedure : 1) redo 3.3, 3.4, 3.5. However, Unselect "Create Links to workspace" and select "Overwrite existing without warning"
410 * Expected Results: Make sure that no dialog box appears (for renaming,
411 * overwriting, skipping) and existing traces are overwritten). Make sure
412 * trace can be opened
415 public void test3_09OverwriteOptionImport() {
416 testOverwriteOptionImport(CUSTOM_TEXT_LOG
);
417 testOverwriteOptionImport(CUSTOM_XML_LOG
);
418 testOverwriteOptionImport(LTTNG_KERNEL_TRACE
);
421 private static void testOverwriteOptionImport(TestTraceInfo traceInfo
) {
422 String traceName
= traceInfo
.getTraceName();
423 SWTBotTreeItem traceItem
= SWTBotUtils
.getTreeItem(fBot
, SWTBotUtils
.selectTracesFolder(fBot
, TRACE_PROJECT_NAME
), traceName
);
424 String lastModified
= getTraceProperty(traceItem
, PROP_LAST_MODIFIED_PROPERTY
);
426 int optionFlags
= ImportTraceWizardPage
.OPTION_IMPORT_UNRECOGNIZED_TRACES
| ImportTraceWizardPage
.OPTION_OVERWRITE_EXISTING_RESOURCES
;
427 importTrace(optionFlags
, ImportConfirmation
.CONTINUE
, traceName
);
428 verifyTrace(traceInfo
, optionFlags
);
430 assertNotEquals(lastModified
, getTraceProperty(traceItem
, PROP_LAST_MODIFIED_PROPERTY
));
435 * Action : Import unrecognized
439 * Procedure : 1) Open Import wizard (see 3.1-3.2)
440 * 2) Browse to directory ${local}/traces/import
441 * 3) Select trace unrecognized.log
442 * 4) Keep <Auto Detection>, Select "Import unrecognized traces", unselect "Overwrite existing without warning" and select "Create Links to workspace" and
446 * Expected Results: unrecognized.log is imported with trace type unknown.
447 * The default text file icon is displayed. The trace, when opened, is
448 * displayed in the text editor.
451 public void test3_10ImportUnrecognized() {
452 String traceName
= UNRECOGNIZED_LOG
.getTraceName();
453 int optionFlags
= ImportTraceWizardPage
.OPTION_IMPORT_UNRECOGNIZED_TRACES
| ImportTraceWizardPage
.OPTION_CREATE_LINKS_IN_WORKSPACE
;
454 importTrace(optionFlags
, traceName
);
455 verifyTrace(UNRECOGNIZED_LOG
, optionFlags
);
460 * Action : Import unrecognized (ignore)
464 * Procedure : 1) redo 3.10, however unselect "Import unrecognized traces"
467 * Expected Results: unrecognized.log is not imported
470 public void test3_11ImportUnrecognizedIgnore() {
471 String traceName
= UNRECOGNIZED_LOG
.getTraceName();
472 SWTBotTreeItem tracesFolderItem
= SWTBotUtils
.selectTracesFolder(fBot
, TRACE_PROJECT_NAME
);
473 int numTraces
= tracesFolderItem
.getItems().length
;
475 SWTBotTreeItem traceItem
= SWTBotUtils
.getTreeItem(fBot
, tracesFolderItem
, traceName
);
476 String lastModified
= getTraceProperty(traceItem
, PROP_LAST_MODIFIED_PROPERTY
);
478 int optionFlags
= ImportTraceWizardPage
.OPTION_CREATE_LINKS_IN_WORKSPACE
;
479 importTrace(optionFlags
, traceName
);
480 verifyTrace(UNRECOGNIZED_LOG
, optionFlags
);
482 assertEquals(lastModified
, getTraceProperty(traceItem
, PROP_LAST_MODIFIED_PROPERTY
));
483 assertEquals(numTraces
, tracesFolderItem
.getItems().length
);
488 * Action : Import CTF trace by selection metadata file only
492 * Procedure : 1) Redo 3.5, However only select metadata file instead of directory trace
495 * Expected Results: Imported trace appear in Traces Folder and the Trace
496 * Type "LTTng Kernel" is set. Make sure that trace can be opened
499 public void test3_12ImportCtfWithMetadataSelection() {
500 SWTBotUtils
.clearTracesFolderUI(fBot
, TRACE_PROJECT_NAME
);
501 testSingleTrace(LTTNG_KERNEL_TRACE_METADATA
, ImportTraceWizardPage
.OPTION_IMPORT_UNRECOGNIZED_TRACES
| ImportTraceWizardPage
.OPTION_CREATE_LINKS_IN_WORKSPACE
);
506 * Action : Recursive import with auto-detection (Rename All)
510 * Procedure : 1) Open Import wizard (see 3.1-3.2)
511 * 2) Browse to directory ${local}/traces/import
512 * 3) select directory import
513 * 4) Keep <Auto Detection>, Select "Import unrecognized traces", unselect "Overwrite existing without warning", select "Create Links to workspace" and unselect "Preserve Folder Structure"
515 * 6) When dialog appears select "Rename All"
518 * Expected Results: All Traces are imported with respective trace type set.
519 * Traces with name clashes are imported with suffix (2). 1 trace
520 * (unrecognized.log) is imported with trace type unknown. Make sure that
521 * traces can be opened which have a trace type set. The unknown trace type
522 * should open with the text editor.
525 public void test3_13ImportRecursiveAutoRenameAll() {
526 SWTBotUtils
.clearTracesFolderUI(fBot
, TRACE_PROJECT_NAME
);
528 int optionFlags
= ImportTraceWizardPage
.OPTION_IMPORT_UNRECOGNIZED_TRACES
| ImportTraceWizardPage
.OPTION_CREATE_LINKS_IN_WORKSPACE
;
529 importTrace(optionFlags
, ImportConfirmation
.RENAME_ALL
, "");
531 for (TestTraceInfo info
: ALL_TRACEINFOS
) {
532 String traceName
= info
.getTraceName();
533 if (CLASHING_TRACEINFOS
.contains(info
)) {
534 traceName
= toRenamedName(traceName
);
536 verifyTrace(info
, optionFlags
, traceName
);
539 // Also check unrecognized file
540 verifyTrace(UNRECOGNIZED_LOG
, optionFlags
);
545 * Action : Recursive import with auto-detection (Overwrite All)
549 * Procedure : 1) Open Import wizard (see 3.1-3.2)
550 * 2) Browse to directory ${local}/traces/import/
551 * 3) select directory import
552 * 4) Keep <Auto Detection>, Select "Import unrecognized traces", unselect "Overwrite existing without warning", select "Create Links to workspace" and unselect "Preserve Folder Structure"
554 * 6) When dialog appears select Overwrite All"
557 * Expected Results: All Traces are imported with respective trace type set.
558 * Traces with name clashes are overwritten . 1 trace (unrecognized.log) is
559 * imported with trace type unknown. Make sure that traces can be opened
560 * which have a trace type set. The unknown trace type should open with the
564 public void test3_14ImportRecursiveAutoOverwriteAll() {
565 SWTBotUtils
.clearTracesFolderUI(fBot
, TRACE_PROJECT_NAME
);
567 int optionFlags
= ImportTraceWizardPage
.OPTION_IMPORT_UNRECOGNIZED_TRACES
| ImportTraceWizardPage
.OPTION_CREATE_LINKS_IN_WORKSPACE
;
568 importTrace(optionFlags
, ImportConfirmation
.OVERWRITE_ALL
, "");
570 for (TestTraceInfo info
: CLASHING_TRACEINFOS
) {
571 verifyTrace(info
, optionFlags
);
574 // All traces should have clashed/overwritten (plus the unrecognized trace)
575 SWTBotTreeItem tracesFolderItem
= SWTBotUtils
.selectTracesFolder(fBot
, TRACE_PROJECT_NAME
);
576 assertEquals(NUM_UNIQUE_TRACES
, tracesFolderItem
.getItems().length
);
578 // Also check unrecognized file
579 verifyTrace(UNRECOGNIZED_LOG
, optionFlags
);
584 * Action : Recursive import with auto-detection (Skip All)
588 * Procedure : 1) Open Import wizard (see 3.1-3.2)
589 * 2) Browse to directory ${local}/traces/import/
590 * 3) select directory import
591 * 4) Keep <Auto Detection>, Select "Import unrecognized traces", unselect "Overwrite existing without warning" and select "Create Links to workspace" and uncheck "preserve folder structure"
593 * 6) When dialog appears select Skip All"
596 * Expected Results: All Traces are imported with respective trace type set. Traces with name
597 * clashes are not imported. 1 trace (unrecognized.log) is imported with
598 * trace type unknown. The unknown trace type should open with the text
602 public void test3_15ImportRecursiveAutoSkipAll() {
603 SWTBotUtils
.clearTracesFolderUI(fBot
, TRACE_PROJECT_NAME
);
605 int optionFlags
= ImportTraceWizardPage
.OPTION_IMPORT_UNRECOGNIZED_TRACES
| ImportTraceWizardPage
.OPTION_CREATE_LINKS_IN_WORKSPACE
;
606 importTrace(optionFlags
, ImportConfirmation
.SKIP_ALL
, "");
608 SWTBotTreeItem tracesFolderItem
= SWTBotUtils
.selectTracesFolder(fBot
, TRACE_PROJECT_NAME
);
609 for (TestTraceInfo info
: ALL_TRACEINFOS
) {
610 if (!CLASHING_TRACEINFOS
.contains(info
)) {
611 verifyTrace(info
, optionFlags
);
615 // All traces should have skipped (plus the unrecognized trace)
616 assertEquals(NUM_UNIQUE_TRACES
, tracesFolderItem
.getItems().length
);
618 // Also check unrecognized file
619 verifyTrace(UNRECOGNIZED_LOG
, optionFlags
);
624 * Action : Recursive import with auto-detection (test rename, overwrite and
629 * Procedure : 1) Open Import wizard (see 3.1-3.2)
630 * 2) Browse to directory ${local}/traces/import/
631 * 3) select directory import
632 * 4) Keep <Auto Detection>, Select "Import unrecognized traces", unselect "Overwrite existing without warning", select "Create Links to workspace" and unselect "Preserve Folder Structure"
634 * 6) When dialog appears select "Rename"
635 * 7) When dialog appears select "Overwrite"
636 * 8) When dialog appears select "Skip"
639 * Expected Results: All Traces are imported with respective trace type set. Traces with name
640 * clashes are either renamed, overwritten or skipped as per dialog action.
641 * Make sure that traces can be opened which have trace type set. The
642 * unknown trace type should open with the text editor.
645 public void test3_16ImportRecursiveAutoRenameOverwriteSkip() {
646 SWTBotUtils
.clearTracesFolderUI(fBot
, TRACE_PROJECT_NAME
);
648 Supplier
<ImportConfirmation
> confirmationSupplier
= new Supplier
<ImportConfirmation
>() {
649 final ImportConfirmation dialogConfirmationOrder
[] = new ImportConfirmation
[] { ImportConfirmation
.RENAME
, ImportConfirmation
.OVERWRITE
, ImportConfirmation
.SKIP
};
653 public ImportConfirmation
get() {
654 if (fRsponseNum
>= dialogConfirmationOrder
.length
) {
658 ImportConfirmation confirmation
= dialogConfirmationOrder
[fRsponseNum
];
663 int optionFlags
= ImportTraceWizardPage
.OPTION_IMPORT_UNRECOGNIZED_TRACES
| ImportTraceWizardPage
.OPTION_CREATE_LINKS_IN_WORKSPACE
;
664 importTrace(optionFlags
, confirmationSupplier
, LTTNG_KERNEL_TRACE
.getTracePath(), CLASHES_LTTNG_KERNEL_TRACE
.getTracePath(), SIMPLE_SERVER1_UST_TRACE
.getTracePath(), CLASHES_SIMPLE_SERVER1_UST_TRACE
.getTracePath(),
665 SIMPLE_SERVER2_UST_TRACE
.getTracePath(), CLASHES_SIMPLE_SERVER2_UST_TRACE
.getTracePath(), UNRECOGNIZED_LOG
.getTracePath());
667 verifyTrace(LTTNG_KERNEL_TRACE
, optionFlags
);
670 String renamed
= toRenamedName(CLASHES_LTTNG_KERNEL_TRACE
.getTraceName());
671 verifyTrace(CLASHES_LTTNG_KERNEL_TRACE
, optionFlags
, renamed
);
674 verifyTrace(CLASHES_SIMPLE_SERVER1_UST_TRACE
, optionFlags
);
677 verifyTrace(SIMPLE_SERVER2_UST_TRACE
, optionFlags
);
679 // Also check unrecognized file
680 verifyTrace(UNRECOGNIZED_LOG
, optionFlags
);
685 * Action : Recursive import with specific trace type 1 (Skip All) skip)
689 * Procedure : 1) Open Import wizard
690 * 2) Browse to directory ${local}/traces/import/
691 * 3) Select directory import
692 * 4) Select trace type "Generic CTF Trace", unselect "Overwrite existing without warning", select "Create Links to workspace" and unselect "Preserve Folder Structure"and
694 * 6) When dialog appears select Skip All"
697 * Expected Results: After selecting trace type, verify that button "Import
698 * unrecognized traces" is disabled. 4 CTF traces are imported with trace
699 * type "Generic CTF Trace" . Make sure that these traces can be opened
702 public void test3_17ImportRecursiveSpecityTraceTypeCTF() {
703 SWTBotUtils
.clearTracesFolderUI(fBot
, TRACE_PROJECT_NAME
);
705 int optionFlags
= ImportTraceWizardPage
.OPTION_CREATE_LINKS_IN_WORKSPACE
;
706 importTrace(GENERIC_CTF_TRACE_TYPE
, optionFlags
, ImportConfirmation
.SKIP_ALL
, "");
708 final TestTraceInfo
[] CTF_TRACEINFOS
= new TestTraceInfo
[] {
710 SIMPLE_SERVER1_UST_TRACE
,
711 SIMPLE_SERVER2_UST_TRACE
,
712 UST_OVERLAP_TESTING_UST_TRACE
714 for (TestTraceInfo info
: CTF_TRACEINFOS
) {
715 verifyTrace(info
, optionFlags
, info
.getTraceName(), GENERIC_CTF_TRACE_TYPE
);
718 SWTBotTreeItem tracesFolderItem
= SWTBotUtils
.selectTracesFolder(fBot
, TRACE_PROJECT_NAME
);
719 assertEquals(CTF_TRACEINFOS
.length
, tracesFolderItem
.getItems().length
);
724 * Action : Recursive import with specific trace type 2 (Skip All)
728 * Procedure : 1) Open Import wizard (see 3.1-3.2)
729 * 2) Browse to directory ${local}/traces/import/
730 * 3) Select directory import
731 * 4) Select trace type "LTTng Kernel Trace", unselect "Overwrite existing without warning", select "Create Links to workspace" and unselect "Preserve Folder Structure"
733 * 6) When dialog appears select Skip All"
736 * Expected Results: After selecting trace type, verify that button "Import
737 * unrecognized traces" is disabled. One LTTng Kernel trace is imported with
738 * trace type "LTTng Kernel Trace". Make sure that this trace can be opened.
741 public void test3_18ImportRecursiveSpecityTraceTypeKernel() {
742 SWTBotUtils
.clearTracesFolderUI(fBot
, TRACE_PROJECT_NAME
);
744 int optionFlags
= ImportTraceWizardPage
.OPTION_CREATE_LINKS_IN_WORKSPACE
;
745 importTrace(LTTNG_KERNEL_TRACE_TYPE
, optionFlags
, ImportConfirmation
.SKIP_ALL
, "");
747 verifyTrace(LTTNG_KERNEL_TRACE
, optionFlags
);
749 SWTBotTreeItem tracesFolderItem
= SWTBotUtils
.selectTracesFolder(fBot
, TRACE_PROJECT_NAME
);
750 assertEquals(1, tracesFolderItem
.getItems().length
);
755 * Action : Recursive import with specific trace type 3 (Skip All)
759 * Procedure : 1) Open Import wizard
760 * 2) Browse to directory ${local}/traces/import/
761 * 3) Select directory import
762 * 4) Select trace type "LTTng UST Trace", unselect "Overwrite existing without warning", select "Create Links to workspace" and unselect "Preserve Folder Structure"
764 * 6) When dialog appears select Skip All"
767 * Expected Results: After selecting trace type, verify that button "Import
768 * unrecognized traces" is disabled. 3 LTTng UST traces are imported with
769 * trace type "LTTng UST Trace". Make sure that these traces can be opened.
772 public void test3_19ImportRecursiveSpecityTraceTypeUST() {
773 SWTBotUtils
.clearTracesFolderUI(fBot
, TRACE_PROJECT_NAME
);
775 int optionFlags
= ImportTraceWizardPage
.OPTION_CREATE_LINKS_IN_WORKSPACE
;
776 importTrace(LTTNG_UST_TRACE_TYPE
, optionFlags
, ImportConfirmation
.SKIP_ALL
, "");
778 final TestTraceInfo
[] UST_TRACEINFOS
= new TestTraceInfo
[] {
779 SIMPLE_SERVER1_UST_TRACE
,
780 SIMPLE_SERVER2_UST_TRACE
,
781 UST_OVERLAP_TESTING_UST_TRACE
783 for (TestTraceInfo info
: UST_TRACEINFOS
) {
784 verifyTrace(info
, optionFlags
);
787 SWTBotTreeItem tracesFolderItem
= SWTBotUtils
.selectTracesFolder(fBot
, TRACE_PROJECT_NAME
);
788 assertEquals(UST_TRACEINFOS
.length
, tracesFolderItem
.getItems().length
);
793 * Action : Recursive import with specific trace type 4 (Skip All)
797 * Procedure : 1) Open Import wizard (see 3.1-3.2)
798 * 2) Browse to directory ${local}/traces/import/
799 * 3) select directory import
800 * 4) Select trace type "Tmf Generic", unselect "Overwrite existing without warning", select "Create Links to workspace" and unselect "Preserve Folder Structure"
802 * 6) When dialog appears select Skip All"
805 * Expected Results: All text files in directories are imported as trace and
806 * trace type "Tmf Generic" is set. Note that trace type validation only
807 * checks for file exists and that file is not a directory. Make sure that
808 * these traces can be opened. However traces with wrong trace type won't
809 * show any events in the table.
812 public void test3_20ImportRecursiveSpecityTraceTypeCustomText() {
813 SWTBotUtils
.clearTracesFolderUI(fBot
, TRACE_PROJECT_NAME
);
815 int optionFlags
= ImportTraceWizardPage
.OPTION_CREATE_LINKS_IN_WORKSPACE
;
816 importTrace(CUSTOM_TEXT_TRACE_TYPE
, optionFlags
, ImportConfirmation
.SKIP_ALL
, "");
817 verifyTrace(CUSTOM_TEXT_LOG
, optionFlags
);
819 final TestTraceInfo
[] TEXT_BASED_TRACEINFOS
= new TestTraceInfo
[] {
821 CUSTOM_XML_LOG_AS_TEXT
,
824 for (TestTraceInfo info
: TEXT_BASED_TRACEINFOS
) {
825 verifyTrace(info
, optionFlags
, info
.getTraceName(), CUSTOM_TEXT_TRACE_TYPE
);
828 SWTBotTreeItem tracesFolderItem
= SWTBotUtils
.selectTracesFolder(fBot
, TRACE_PROJECT_NAME
);
829 assertEquals(TEXT_BASED_TRACEINFOS
.length
, tracesFolderItem
.getItems().length
);
832 private static void verifyTrace(TestTraceInfo traceInfo
, int importOptionFlags
) {
833 verifyTrace(traceInfo
, importOptionFlags
, traceInfo
.getTraceName());
836 private static void verifyTrace(TestTraceInfo traceInfo
, int importOptionFlags
, String traceName
) {
837 verifyTrace(traceInfo
, importOptionFlags
, traceName
, traceInfo
.getTraceType());
840 private static void verifyTrace(TestTraceInfo traceInfo
, int importOptionFlags
, String traceName
, String traceType
) {
841 SWTBotTreeItem traceItem
= SWTBotUtils
.getTreeItem(fBot
, SWTBotUtils
.selectTracesFolder(fBot
, TRACE_PROJECT_NAME
), traceName
);
842 checkTraceType(traceItem
, traceType
);
843 openTrace(traceItem
);
844 if (traceType
!= null && !traceType
.isEmpty()) {
845 SWTBotImportWizardUtils
.testEventsTable(fBot
, traceName
, traceInfo
.getNbEvents(), traceInfo
.getFirstEventTimestamp());
847 // If there is no trace type, make sure it can be opened with the text editor
848 fBot
.waitUntil(ConditionHelpers
.isEditorOpened(fBot
, traceName
));
849 SWTBotEditor editor
= fBot
.editorByTitle(traceName
);
850 assertEquals(TEXT_EDITOR_ID
, editor
.getReference().getId());
852 checkTraceLinked(traceItem
, (importOptionFlags
& ImportTraceWizardPage
.OPTION_CREATE_LINKS_IN_WORKSPACE
) != 0);
855 private static String
toRenamedName(String traceName
) {
856 return traceName
+ "(2)";
859 private static void openTrace(SWTBotTreeItem traceItem
) {
861 traceItem
.doubleClick();
864 private static void testSingleTrace(TestTraceInfo traceInfo
, int optionFlags
) {
865 importTrace(optionFlags
, traceInfo
.getTracePath());
866 verifyTrace(traceInfo
, optionFlags
);
869 private static void importTrace(int optionFlags
, String
... tracePaths
) {
870 importTrace(optionFlags
, ImportConfirmation
.CONTINUE
, tracePaths
);
873 private static void importTrace(int optionFlags
, ImportConfirmation confirmationMode
, String
... tracePaths
) {
874 importTrace(null, optionFlags
, confirmationMode
, tracePaths
);
877 private static void importTrace(String traceType
, int optionFlags
, ImportConfirmation confirmationMode
, String
... tracePaths
) {
878 importTrace(traceType
, optionFlags
, new Supplier
<ImportConfirmation
>() {
879 boolean fDone
= false;
881 public ImportConfirmation
get() {
886 return confirmationMode
;
891 private static void importTrace(int optionFlags
, Supplier
<ImportConfirmation
> confirmationSuplier
, String
... tracePaths
) {
892 importTrace(null, optionFlags
, confirmationSuplier
, tracePaths
);
896 * @param tracePath relative to parent test traces folder
898 private static void importTrace(String traceType
, int optionFlags
, Supplier
<ImportConfirmation
> confirmationSuplier
, String
... tracePaths
) {
899 SWTBotTreeItem traceFolder
= SWTBotUtils
.selectTracesFolder(fBot
, TRACE_PROJECT_NAME
);
901 SWTBotShell shell
= openTraceFoldersImport(traceFolder
);
902 SWTBot bot
= shell
.bot();
903 final String importDirectoryRelativePath
= "import";
904 String importDirectoryFullPath
= getPath(importDirectoryRelativePath
);
906 for (String tracePath
: tracePaths
) {
907 IPath somePath
= new Path(importDirectoryRelativePath
).append(tracePath
);
908 IPath fullParentPath
= somePath
.removeLastSegments(1);
909 boolean isDirectory
= new Path(importDirectoryFullPath
).append(tracePath
).toFile().isDirectory();
911 SWTBotImportWizardUtils
.selectImportFromDirectory(bot
, importDirectoryFullPath
);
913 SWTBotImportWizardUtils
.selectFolder(fBot
, true, somePath
.segments());
915 SWTBotImportWizardUtils
.selectFile(bot
, new Path(tracePath
).lastSegment(), fullParentPath
.segments());
919 SWTBotImportWizardUtils
.setOptions(bot
, optionFlags
, traceType
);
920 bot
.button("Finish").click();
922 ImportConfirmation importConfirmation
= confirmationSuplier
.get();
923 while (importConfirmation
!= null) {
924 if (importConfirmation
!= ImportConfirmation
.CONTINUE
) {
925 fBot
.waitUntil(Conditions
.shellIsActive("Confirmation"));
926 SWTBotShell shell2
= fBot
.activeShell();
927 SWTBotButton button
= shell2
.bot().button(importConfirmation
.getInName());
930 importConfirmation
= confirmationSuplier
.get();
933 fBot
.waitUntil(Conditions
.shellCloses(shell
));
936 private static void checkTraceType(SWTBotTreeItem traceItem
, String traceType
) {
937 assertEquals(traceType
, getTraceProperty(traceItem
, "type"));
940 private static void checkTraceLinked(SWTBotTreeItem traceItem
, boolean linked
) {
941 assertEquals(Boolean
.toString(linked
), getTraceProperty(traceItem
, "linked"));
944 private static String
getTraceProperty(SWTBotTreeItem traceItem
, String property
) {
945 SWTBotUtils
.openView(IPageLayout
.ID_PROP_SHEET
);
946 SWTBotView view
= fBot
.viewById(IPageLayout
.ID_PROP_SHEET
);
949 SWTBotTreeItem traceTypeItem
= SWTBotUtils
.getTreeItem(view
.bot(), view
.bot().tree(), "Resource properties", property
);
950 return traceTypeItem
.cell(1);
953 private static SWTBotShell
openTraceFoldersImport(SWTBotTreeItem traceItem
) {
954 traceItem
.contextMenu().menu("Import...").click();
955 fBot
.waitUntil(Conditions
.shellIsActive("Trace Import"));
957 SWTBotShell shell
= fBot
.shell("Trace Import");