1 /*******************************************************************************
2 * Copyright (c) 2013, 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
10 * Matthew Khouzam - Initial API and implementation
12 * Patrick Tasse - Extract base class from ImportAndReadKernelSmokeTest
13 *******************************************************************************/
15 package org
.eclipse
.tracecompass
.lttng2
.kernel
.ui
.swtbot
.tests
;
17 import static org
.junit
.Assert
.fail
;
19 import java
.util
.List
;
21 import org
.apache
.log4j
.ConsoleAppender
;
22 import org
.apache
.log4j
.Logger
;
23 import org
.apache
.log4j
.SimpleLayout
;
24 import org
.eclipse
.swt
.widgets
.TreeItem
;
25 import org
.eclipse
.swtbot
.eclipse
.finder
.SWTWorkbenchBot
;
26 import org
.eclipse
.swtbot
.eclipse
.finder
.widgets
.SWTBotView
;
27 import org
.eclipse
.swtbot
.swt
.finder
.finders
.UIThreadRunnable
;
28 import org
.eclipse
.swtbot
.swt
.finder
.junit
.SWTBotJunit4ClassRunner
;
29 import org
.eclipse
.swtbot
.swt
.finder
.results
.BoolResult
;
30 import org
.eclipse
.swtbot
.swt
.finder
.results
.Result
;
31 import org
.eclipse
.swtbot
.swt
.finder
.utils
.SWTBotPreferences
;
32 import org
.eclipse
.swtbot
.swt
.finder
.widgets
.SWTBotTree
;
33 import org
.eclipse
.tracecompass
.ctf
.core
.tests
.shared
.LttngTraceGenerator
;
34 import org
.eclipse
.tracecompass
.tmf
.ui
.swtbot
.tests
.shared
.ConditionHelpers
;
35 import org
.eclipse
.tracecompass
.tmf
.ui
.swtbot
.tests
.shared
.SWTBotUtils
;
36 import org
.eclipse
.tracecompass
.tmf
.ui
.tests
.shared
.WaitUtils
;
37 import org
.eclipse
.ui
.PlatformUI
;
38 import org
.eclipse
.ui
.WorkbenchException
;
39 import org
.junit
.After
;
40 import org
.junit
.AfterClass
;
41 import org
.junit
.Before
;
42 import org
.junit
.BeforeClass
;
43 import org
.junit
.runner
.RunWith
;
46 * Base SWTBot test for LTTng Kernel UI.
48 * @author Matthew Khouzam
50 @RunWith(SWTBotJunit4ClassRunner
.class)
51 public abstract class KernelTestBase
{
53 /** LTTng kernel trace type */
54 protected static final String KERNEL_TRACE_TYPE
= "org.eclipse.linuxtools.lttng2.kernel.tracetype";
55 /** LTTng kernel perspective */
56 protected static final String KERNEL_PERSPECTIVE_ID
= "org.eclipse.linuxtools.lttng2.kernel.ui.perspective";
57 /** Default project name */
58 protected static final String TRACE_PROJECT_NAME
= "test";
60 /** The workbench bot */
61 protected static SWTWorkbenchBot fBot
;
63 /** The Log4j logger instance. */
64 private static final Logger fLogger
= Logger
.getRootLogger();
70 public static void beforeClass() {
71 SWTBotUtils
.initialize();
73 /* set up for swtbot */
74 SWTBotPreferences
.TIMEOUT
= 20000; /* 20 second timeout */
75 SWTBotPreferences
.KEYBOARD_LAYOUT
= "EN_US";
76 fLogger
.removeAllAppenders();
77 fLogger
.addAppender(new ConsoleAppender(new SimpleLayout(), ConsoleAppender
.SYSTEM_OUT
));
78 fBot
= new SWTWorkbenchBot();
80 final List
<SWTBotView
> openViews
= fBot
.views();
81 for (SWTBotView view
: openViews
) {
82 if (view
.getTitle().equals("Welcome")) {
84 fBot
.waitUntil(ConditionHelpers
.ViewIsClosed(view
));
87 /* Switch perspectives */
88 switchKernelPerspective();
89 /* Create the trace project */
90 SWTBotUtils
.createProject(TRACE_PROJECT_NAME
);
91 /* Finish waiting for eclipse to load */
92 WaitUtils
.waitForJobs();
99 public static void afterClass() {
100 SWTBotUtils
.deleteProject(TRACE_PROJECT_NAME
, fBot
);
101 fLogger
.removeAllAppenders();
104 private static void switchKernelPerspective() {
105 final Exception retE
[] = new Exception
[1];
106 if (!UIThreadRunnable
.syncExec(new BoolResult() {
108 public Boolean
run() {
110 PlatformUI
.getWorkbench().showPerspective(KERNEL_PERSPECTIVE_ID
,
111 PlatformUI
.getWorkbench().getActiveWorkbenchWindow());
112 } catch (WorkbenchException e
) {
119 fail(retE
[0].getMessage());
128 public void before() {
129 SWTBotUtils
.openTrace(TRACE_PROJECT_NAME
, LttngTraceGenerator
.getPath(), KERNEL_TRACE_TYPE
);
130 SWTBotUtils
.activateEditor(fBot
, LttngTraceGenerator
.getName());
137 public void after() {
138 fBot
.closeAllEditors();
139 SWTBotUtils
.closeSecondaryShells(fBot
);
143 * Class to check number of checked items
145 static final class TreeCheckedCounter
implements Result
<Integer
> {
146 private final SWTBotTree fTreeBot
;
148 TreeCheckedCounter(SWTBotTree treeBot
) {
153 public Integer
run() {
155 for (TreeItem item
: fTreeBot
.widget
.getItems()) {
156 checked
+= getChecked(item
);
161 private int getChecked(TreeItem item
) {
163 if (item
.getChecked()) {
166 for (TreeItem child
: item
.getItems()) {
167 total
+= getChecked(child
);