1
/*******************************************************************************
2
* Copyright (c) 2009 Red Hat, Inc.
3
* All rights reserved. This program and the accompanying materials
4
* are made available under the terms of the Eclipse Public License v1.0
5
* which accompanies this distribution, and is available at
6
* http://www.eclipse.org/legal/epl-v10.html
9
* Kent Sebastian <ksebasti@redhat.com> - initial API and implementation
10
*******************************************************************************/
12
package org.eclipse.linuxtools.oprofile.launch.tests;
14
import org.eclipse.core.runtime.CoreException;
15
import org.eclipse.debug.core.ILaunch;
16
import org.eclipse.debug.core.ILaunchConfiguration;
17
import org.eclipse.debug.core.ILaunchConfigurationType;
18
import org.eclipse.debug.core.ILaunchConfigurationWorkingCopy;
19
import org.eclipse.debug.core.ILaunchManager;
20
import org.eclipse.debug.core.Launch;
21
import org.eclipse.linuxtools.internal.oprofile.core.daemon.OprofileDaemonOptions;
22
import org.eclipse.linuxtools.internal.oprofile.launch.OprofileLaunchPlugin;
23
import org.eclipse.linuxtools.internal.oprofile.launch.configuration.LaunchOptions;
24
import org.eclipse.linuxtools.internal.oprofile.launch.configuration.OprofileEventConfigTab;
25
import org.eclipse.linuxtools.internal.oprofile.launch.configuration.OprofileSetupTab;
26
import org.eclipse.linuxtools.oprofile.launch.tests.utils.TestingOprofileLaunchConfigurationDelegate;
27
import org.eclipse.linuxtools.profiling.tests.AbstractTest;
28
import org.eclipse.swt.layout.GridLayout;
29
import org.eclipse.swt.widgets.Display;
30
import org.eclipse.swt.widgets.Shell;
31
import org.osgi.framework.FrameworkUtil;
33
public class TestLaunching extends AbstractTest {
36
protected ILaunchConfiguration config;
37
protected Shell testShell;
40
protected void setUp() throws Exception {
42
proj = createProjectAndBuild(FrameworkUtil.getBundle(this.getClass()), "primeTest"); //$NON-NLS-1$
43
config = createConfiguration(proj.getProject());
44
testShell = new Shell(Display.getDefault());
45
testShell.setLayout(new GridLayout());
49
protected void tearDown() throws Exception {
56
protected ILaunchConfigurationType getLaunchConfigType() {
57
return getLaunchManager().getLaunchConfigurationType(OprofileLaunchPlugin.ID_LAUNCH_PROFILE);
61
protected void setProfileAttributes(ILaunchConfigurationWorkingCopy wc) throws CoreException {
62
OprofileEventConfigTab configTab = new OprofileEventConfigTab();
63
OprofileSetupTab setupTab = new OprofileSetupTab();
64
configTab.setDefaults(wc);
65
setupTab.setDefaults(wc);
68
public void testDefaultLaunch() throws CoreException {
69
TestingOprofileLaunchConfigurationDelegate delegate = new TestingOprofileLaunchConfigurationDelegate();
70
ILaunch launch = new Launch(config, ILaunchManager.PROFILE_MODE, null);
72
LaunchOptions options = new LaunchOptions();
73
options.loadConfiguration(config);
74
assertTrue(options.isValid());
75
assertEquals("", options.getBinaryImage()); //$NON-NLS-1$
76
assertEquals("", options.getKernelImageFile()); //$NON-NLS-1$
77
assertEquals(OprofileDaemonOptions.SEPARATE_NONE, options.getSeparateSamples());
79
delegate.launch(config, ILaunchManager.PROFILE_MODE, launch, null);
80
assertTrue(delegate.eventsIsNull);
81
assertNotNull(delegate._options);
82
assertTrue(delegate._options.getBinaryImage().length() > 0);
83
assertEquals("", delegate._options.getKernelImageFile()); //$NON-NLS-1$
84
assertEquals(0, delegate._options.getCallgraphDepth());
85
assertFalse(delegate._options.getVerboseLogging());
86
assertEquals(OprofileDaemonOptions.SEPARATE_NONE, delegate._options.getSeparateProfilesMask());
89
public void testEventLaunch() throws CoreException {
90
TestingOprofileLaunchConfigurationDelegate delegate = new TestingOprofileLaunchConfigurationDelegate();
91
ILaunch launch = new Launch(config, ILaunchManager.PROFILE_MODE, null);
93
ILaunchConfigurationWorkingCopy wc = config.getWorkingCopy();
94
wc.setAttribute(OprofileLaunchPlugin.ATTR_USE_DEFAULT_EVENT, false);
95
wc.setAttribute(OprofileLaunchPlugin.ATTR_COUNTER_ENABLED(0), true);
96
wc.setAttribute(OprofileLaunchPlugin.ATTR_COUNTER_COUNT(0), 100000);
97
wc.setAttribute(OprofileLaunchPlugin.ATTR_COUNTER_EVENT(0), "FAKE_EVENT"); //$NON-NLS-1$
98
wc.setAttribute(OprofileLaunchPlugin.ATTR_COUNTER_PROFILE_KERNEL(0), true);
99
wc.setAttribute(OprofileLaunchPlugin.ATTR_COUNTER_PROFILE_USER(0), true);
100
wc.setAttribute(OprofileLaunchPlugin.ATTR_COUNTER_UNIT_MASK(0), 0);
102
LaunchOptions options = new LaunchOptions();
103
options.loadConfiguration(config);
104
assertTrue(options.isValid());
105
assertEquals("", options.getBinaryImage()); //$NON-NLS-1$
106
assertEquals("", options.getKernelImageFile()); //$NON-NLS-1$
107
assertEquals(OprofileDaemonOptions.SEPARATE_NONE, options.getSeparateSamples());
109
delegate.launch(config, ILaunchManager.PROFILE_MODE, launch, null);
110
assertFalse(delegate.eventsIsNull);
111
assertNotNull(delegate._options);
112
assertTrue(delegate._options.getBinaryImage().length() > 0);
113
assertEquals("", delegate._options.getKernelImageFile()); //$NON-NLS-1$
114
assertEquals(0, delegate._options.getCallgraphDepth());
115
assertFalse(delegate._options.getVerboseLogging());
116
assertEquals(OprofileDaemonOptions.SEPARATE_NONE, delegate._options.getSeparateProfilesMask());