~ubuntu-branches/ubuntu/trusty/eclipse-linuxtools/trusty

« back to all changes in this revision

Viewing changes to oprofile/org.eclipse.linuxtools.oprofile.launch.tests/src/org/eclipse/linuxtools/oprofile/launch/tests/TestLaunching.java

  • Committer: Package Import Robot
  • Author(s): Jakub Adam
  • Date: 2012-06-29 12:07:30 UTC
  • Revision ID: package-import@ubuntu.com-20120629120730-bfri1xys1i71dpn6
Tags: upstream-1.0.0
ImportĀ upstreamĀ versionĀ 1.0.0

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
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
 
7
 *
 
8
 * Contributors:
 
9
 *    Kent Sebastian <ksebasti@redhat.com> - initial API and implementation
 
10
 *******************************************************************************/
 
11
 
 
12
package org.eclipse.linuxtools.oprofile.launch.tests;
 
13
 
 
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;
 
32
 
 
33
public class TestLaunching extends AbstractTest {
 
34
        
 
35
        
 
36
        protected ILaunchConfiguration config;
 
37
        protected Shell testShell;
 
38
        
 
39
        @Override
 
40
        protected void setUp() throws Exception {
 
41
                super.setUp();
 
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());
 
46
        }
 
47
 
 
48
        @Override
 
49
        protected void tearDown() throws Exception {
 
50
                testShell.dispose();
 
51
                deleteProject(proj);
 
52
                super.tearDown();
 
53
        }
 
54
 
 
55
        @Override
 
56
        protected ILaunchConfigurationType getLaunchConfigType() {
 
57
                return getLaunchManager().getLaunchConfigurationType(OprofileLaunchPlugin.ID_LAUNCH_PROFILE);
 
58
        }
 
59
 
 
60
        @Override
 
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);
 
66
        }
 
67
        
 
68
        public void testDefaultLaunch() throws CoreException {
 
69
                TestingOprofileLaunchConfigurationDelegate delegate = new TestingOprofileLaunchConfigurationDelegate();
 
70
                ILaunch launch = new Launch(config, ILaunchManager.PROFILE_MODE, null);
 
71
                
 
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());
 
78
                
 
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());
 
87
        }
 
88
        
 
89
        public void testEventLaunch() throws CoreException {
 
90
                TestingOprofileLaunchConfigurationDelegate delegate = new TestingOprofileLaunchConfigurationDelegate();
 
91
                ILaunch launch = new Launch(config, ILaunchManager.PROFILE_MODE, null);
 
92
                
 
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);
 
101
                wc.doSave();
 
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());
 
108
 
 
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());
 
117
        }
 
118
}