diff options
author | Alexander Kurtakov | 2012-06-13 06:55:37 +0000 |
---|---|---|
committer | Alexander Kurtakov | 2012-06-13 06:55:37 +0000 |
commit | a1cebdf89c6743fbae0a4b1dda28980c4c039369 (patch) | |
tree | 4477dea33a560a9dd8924234c4c5ec048f7613d6 | |
parent | a621e11144626033dc4810fb57505550506407cd (diff) | |
download | org.eclipse.linuxtools-stable-0.6.tar.gz org.eclipse.linuxtools-stable-0.6.tar.xz org.eclipse.linuxtools-stable-0.6.zip |
Restor the main valgrind tests bundle.stable-0.6
14 files changed, 753 insertions, 0 deletions
diff --git a/valgrind/org.eclipse.linuxtools.valgrind.tests/.classpath b/valgrind/org.eclipse.linuxtools.valgrind.tests/.classpath new file mode 100644 index 0000000000..64c5e31b7a --- /dev/null +++ b/valgrind/org.eclipse.linuxtools.valgrind.tests/.classpath @@ -0,0 +1,7 @@ +<?xml version="1.0" encoding="UTF-8"?> +<classpath> + <classpathentry kind="con" path="org.eclipse.jdt.launching.JRE_CONTAINER/org.eclipse.jdt.internal.debug.ui.launcher.StandardVMType/J2SE-1.5"/> + <classpathentry kind="con" path="org.eclipse.pde.core.requiredPlugins"/> + <classpathentry kind="src" path="src"/> + <classpathentry kind="output" path="bin"/> +</classpath> diff --git a/valgrind/org.eclipse.linuxtools.valgrind.tests/.project b/valgrind/org.eclipse.linuxtools.valgrind.tests/.project new file mode 100644 index 0000000000..9b94ce72c3 --- /dev/null +++ b/valgrind/org.eclipse.linuxtools.valgrind.tests/.project @@ -0,0 +1,34 @@ +<?xml version="1.0" encoding="UTF-8"?> +<projectDescription> + <name>org.eclipse.linuxtools.valgrind.tests</name> + <comment></comment> + <projects> + </projects> + <buildSpec> + <buildCommand> + <name>org.eclipse.jdt.core.javabuilder</name> + <arguments> + </arguments> + </buildCommand> + <buildCommand> + <name>org.eclipse.pde.ManifestBuilder</name> + <arguments> + </arguments> + </buildCommand> + <buildCommand> + <name>org.eclipse.pde.SchemaBuilder</name> + <arguments> + </arguments> + </buildCommand> + <buildCommand> + <name>org.eclipse.pde.api.tools.apiAnalysisBuilder</name> + <arguments> + </arguments> + </buildCommand> + </buildSpec> + <natures> + <nature>org.eclipse.pde.PluginNature</nature> + <nature>org.eclipse.jdt.core.javanature</nature> + <nature>org.eclipse.pde.api.tools.apiAnalysisNature</nature> + </natures> +</projectDescription> diff --git a/valgrind/org.eclipse.linuxtools.valgrind.tests/.settings/org.eclipse.jdt.core.prefs b/valgrind/org.eclipse.linuxtools.valgrind.tests/.settings/org.eclipse.jdt.core.prefs new file mode 100644 index 0000000000..65b4604a1a --- /dev/null +++ b/valgrind/org.eclipse.linuxtools.valgrind.tests/.settings/org.eclipse.jdt.core.prefs @@ -0,0 +1,7 @@ +#Mon Feb 02 15:48:25 EST 2009 +eclipse.preferences.version=1 +org.eclipse.jdt.core.compiler.codegen.targetPlatform=1.5 +org.eclipse.jdt.core.compiler.compliance=1.5 +org.eclipse.jdt.core.compiler.problem.assertIdentifier=error +org.eclipse.jdt.core.compiler.problem.enumIdentifier=error +org.eclipse.jdt.core.compiler.source=1.5 diff --git a/valgrind/org.eclipse.linuxtools.valgrind.tests/about.html b/valgrind/org.eclipse.linuxtools.valgrind.tests/about.html new file mode 100644 index 0000000000..e6a2741fc0 --- /dev/null +++ b/valgrind/org.eclipse.linuxtools.valgrind.tests/about.html @@ -0,0 +1,26 @@ +<!DOCTYPE HTML PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd"> +<html xmlns="http://www.w3.org/1999/xhtml"><head> + + +<meta http-equiv="Content-Type" content="text/html; charset=ISO-8859-1"> +<title>About</title> +</head><body lang="EN-US"> +<h2>About This Content</h2> + +<p>October 24, 2008</p> +<h3>License</h3> + +<p>The Eclipse Foundation makes available all content in this plug-in ("Content"). Unless otherwise +indicated below, the Content is provided to you under the terms and conditions of the +Eclipse Public License Version 1.0 ("EPL"). A copy of the EPL is available +at <a href="http://www.eclipse.org/legal/epl-v10.html">http://www.eclipse.org/legal/epl-v10.html</a>. +For purposes of the EPL, "Program" will mean the Content.</p> + +<p>If you did not receive this Content directly from the Eclipse Foundation, the Content is +being redistributed by another party ("Redistributor") and different terms and conditions may +apply to your use of any object code in the Content. Check the Redistributor's license that was +provided with the Content. If no such license exists, contact the Redistributor. Unless otherwise +indicated below, the terms and conditions of the EPL still apply to any source code in the Content +and such source code may be obtained at <a href="http://www.eclipse.org/">http://www.eclipse.org</a>.</p> + +</body></html>
\ No newline at end of file diff --git a/valgrind/org.eclipse.linuxtools.valgrind.tests/build.properties b/valgrind/org.eclipse.linuxtools.valgrind.tests/build.properties new file mode 100644 index 0000000000..92693a4347 --- /dev/null +++ b/valgrind/org.eclipse.linuxtools.valgrind.tests/build.properties @@ -0,0 +1,9 @@ +bin.includes = META-INF/,\ + test.xml,\ + about.html,\ + plugin.properties,\ + . +jars.compile.order = . +source.. = src/ +output.. = bin/ + diff --git a/valgrind/org.eclipse.linuxtools.valgrind.tests/src/org/eclipse/linuxtools/internal/valgrind/tests/AbstractValgrindTest.java b/valgrind/org.eclipse.linuxtools.valgrind.tests/src/org/eclipse/linuxtools/internal/valgrind/tests/AbstractValgrindTest.java new file mode 100644 index 0000000000..f81c135ac5 --- /dev/null +++ b/valgrind/org.eclipse.linuxtools.valgrind.tests/src/org/eclipse/linuxtools/internal/valgrind/tests/AbstractValgrindTest.java @@ -0,0 +1,202 @@ +/******************************************************************************* + * Copyright (c) 2009 Red Hat, Inc. + * All rights reserved. This program and the accompanying materials + * are made available under the terms of the Eclipse Public License v1.0 + * which accompanies this distribution, and is available at + * http://www.eclipse.org/legal/epl-v10.html + * + * Contributors: + * Elliott Baron <ebaron@redhat.com> - initial API and implementation + *******************************************************************************/ +package org.eclipse.linuxtools.internal.valgrind.tests; + +import java.io.BufferedReader; +import java.io.File; +import java.io.FileFilter; +import java.io.FileReader; +import java.io.FileWriter; +import java.io.IOException; +import java.io.PrintWriter; +import java.net.URISyntaxException; +import java.net.URL; +import java.util.ArrayList; +import java.util.List; + +import org.eclipse.cdt.core.model.ICProject; +import org.eclipse.core.resources.ResourcesPlugin; +import org.eclipse.core.runtime.CoreException; +import org.eclipse.core.runtime.FileLocator; +import org.eclipse.core.runtime.IPath; +import org.eclipse.core.runtime.Path; +import org.eclipse.debug.core.DebugPlugin; +import org.eclipse.debug.core.ILaunch; +import org.eclipse.debug.core.ILaunchConfiguration; +import org.eclipse.debug.core.ILaunchConfigurationType; +import org.eclipse.debug.core.ILaunchConfigurationWorkingCopy; +import org.eclipse.debug.core.ILaunchManager; +import org.eclipse.debug.core.Launch; +import org.eclipse.debug.ui.ILaunchConfigurationTab; +import org.eclipse.linuxtools.internal.valgrind.core.LaunchConfigurationConstants; +import org.eclipse.linuxtools.internal.valgrind.core.ValgrindCommand; +import org.eclipse.linuxtools.internal.valgrind.launch.ValgrindLaunchPlugin; +import org.eclipse.linuxtools.internal.valgrind.launch.ValgrindOptionsTab; +import org.eclipse.linuxtools.profiling.tests.AbstractTest; +import org.osgi.framework.Bundle; + +public abstract class AbstractValgrindTest extends AbstractTest { + + private static final String TEMPLATE_PREFIX = "template_"; //$NON-NLS-1$ + private static final FileFilter TEMPLATE_FILTER = new FileFilter() { + public boolean accept(File pathname) { + return pathname.getName().startsWith(TEMPLATE_PREFIX) && !pathname.isHidden(); + } + }; + private static final FileFilter NOT_TEMPLATE_FILTER = new FileFilter() { + public boolean accept(File pathname) { + return !pathname.getName().startsWith(TEMPLATE_PREFIX) && !pathname.isHidden(); + } + }; + + private static final String SEARCH_STRING_WS = "XXXXXXXXXXXX"; //$NON-NLS-1$ + private static final String SEARCH_STRING_BL = "YYYYYYYYYYYY"; //$NON-NLS-1$ + + private List<ILaunch> launches; + + @Override + protected void setUp() throws Exception { + launches = new ArrayList<ILaunch>(); + + // Substitute Valgrind command line interaction + ValgrindLaunchPlugin.getDefault().setValgrindCommand(getValgrindCommand()); + + super.setUp(); + } + + @Override + protected void tearDown() throws Exception { + if (launches.size() > 0) { + DebugPlugin.getDefault().getLaunchManager().removeLaunches(launches.toArray(new ILaunch[launches.size()])); + launches.clear(); + } + super.tearDown(); + } + + @Override + protected ILaunchConfigurationType getLaunchConfigType() { + return getLaunchManager().getLaunchConfigurationType(ValgrindLaunchPlugin.LAUNCH_ID); + } + + protected ILaunch doLaunch(ILaunchConfiguration config, String testName) throws Exception { + ILaunch launch; + IPath pathToFiles = getPathToFiles(testName); + + if (!ValgrindTestsPlugin.RUN_VALGRIND) { + bindLocation(pathToFiles); + } + + ILaunchConfigurationWorkingCopy wc = config.getWorkingCopy(); + wc.setAttribute(LaunchConfigurationConstants.ATTR_INTERNAL_OUTPUT_DIR, pathToFiles.toOSString()); + wc.doSave(); + + ValgrindTestLaunchDelegate delegate = new ValgrindTestLaunchDelegate(); + launch = new Launch(config, ILaunchManager.PROFILE_MODE, null); + + DebugPlugin.getDefault().getLaunchManager().addLaunch(launch); + launches.add(launch); + delegate.launch(config, ILaunchManager.PROFILE_MODE, launch, null); + + if (ValgrindTestsPlugin.GENERATE_FILES) { + unbindLocation(pathToFiles); + } + return launch; + } + + protected IPath getPathToFiles(String testName) throws URISyntaxException, + IOException { + URL location = FileLocator.find(getBundle(), new Path("valgrindFiles"), null); //$NON-NLS-1$ + File file = new File(FileLocator.toFileURL(location).toURI()); + IPath pathToFiles = new Path(file.getCanonicalPath()).append(testName); + return pathToFiles; + } + + private void unbindLocation(IPath pathToFiles) throws IOException { + String bundleLoc = FileLocator.getBundleFile(getBundle()).getCanonicalPath(); + String workspaceLoc = ResourcesPlugin.getWorkspace().getRoot().getLocation().toOSString(); + File testDir = pathToFiles.toFile(); + for (File log : testDir.listFiles(NOT_TEMPLATE_FILTER)) { + File template = new File(testDir, TEMPLATE_PREFIX + log.getName()); + replaceLocation(log, template, new String[] { bundleLoc, workspaceLoc }, new String[] { SEARCH_STRING_BL , SEARCH_STRING_WS }); + } + } + + private void bindLocation(IPath pathToFiles) throws IOException { + String bundleLoc = FileLocator.getBundleFile(getBundle()).getCanonicalPath(); + String workspaceLoc = ResourcesPlugin.getWorkspace().getRoot().getLocation().toOSString(); + File testDir = pathToFiles.toFile(); + for (File template : testDir.listFiles(TEMPLATE_FILTER)) { + String name = template.getName().replace(TEMPLATE_PREFIX, ""); //$NON-NLS-1$ + File log = new File(testDir, name.substring(name.indexOf(TEMPLATE_PREFIX) + 1)); + replaceLocation(template, log, new String[] { SEARCH_STRING_BL, SEARCH_STRING_WS }, new String[] { bundleLoc, workspaceLoc }); + } + } + + private void replaceLocation(File oldFile, File newFile, String[] from, String[] to) { + if (oldFile.isFile()) { + BufferedReader br = null; + PrintWriter pw = null; + try { + br = new BufferedReader(new FileReader(oldFile)); + pw = new PrintWriter(new FileWriter(newFile)); + + String line; + while ((line = br.readLine()) != null) { + for (int i = 0; i < from.length; i++) { + line = line.replaceAll(from[i], to[i]); + } + pw.println(line); + } + + } catch (IOException e) { + e.printStackTrace(); + } finally { + if (br != null) { + try { + br.close(); + } catch (IOException e) { + e.printStackTrace(); + } + } + if (pw != null) { + pw.close(); + } + } + } + } + + @Override + protected void setProfileAttributes(ILaunchConfigurationWorkingCopy wc) throws CoreException { + ILaunchConfigurationTab tab = new ValgrindOptionsTab(); + tab.setDefaults(wc); + tab = ValgrindLaunchPlugin.getDefault().getToolPage(getToolID()); + tab.setDefaults(wc); + wc.setAttribute(LaunchConfigurationConstants.ATTR_TOOL, getToolID()); + } + + protected ICProject createProjectAndBuild(String projname) throws Exception { + return createProjectAndBuild(getBundle(), projname); + } + + protected abstract Bundle getBundle(); + + protected abstract String getToolID(); + + private ValgrindCommand getValgrindCommand() { + if (!ValgrindTestsPlugin.RUN_VALGRIND) { + return new ValgrindStubCommand(); + } + else { + return new ValgrindCommand(); + } + } + +}
\ No newline at end of file diff --git a/valgrind/org.eclipse.linuxtools.valgrind.tests/src/org/eclipse/linuxtools/internal/valgrind/tests/ResourceChangePrinter.java b/valgrind/org.eclipse.linuxtools.valgrind.tests/src/org/eclipse/linuxtools/internal/valgrind/tests/ResourceChangePrinter.java new file mode 100644 index 0000000000..f7ff4a0bd6 --- /dev/null +++ b/valgrind/org.eclipse.linuxtools.valgrind.tests/src/org/eclipse/linuxtools/internal/valgrind/tests/ResourceChangePrinter.java @@ -0,0 +1,71 @@ +/******************************************************************************* + * Copyright (c) 2009 Red Hat, Inc. + * All rights reserved. This program and the accompanying materials + * are made available under the terms of the Eclipse Public License v1.0 + * which accompanies this distribution, and is available at + * http://www.eclipse.org/legal/epl-v10.html + * + * Contributors: + * Elliott Baron <ebaron@redhat.com> - initial API and implementation + *******************************************************************************/ +package org.eclipse.linuxtools.internal.valgrind.tests; + +import java.io.PrintStream; +import java.io.PrintWriter; + +import org.eclipse.core.resources.IResourceChangeEvent; +import org.eclipse.core.resources.IResourceChangeListener; +import org.eclipse.core.resources.IResourceDelta; + +public class ResourceChangePrinter implements IResourceChangeListener { + + private PrintWriter resourceChangeWriter; + + public ResourceChangePrinter(PrintStream out) { + resourceChangeWriter = new PrintWriter(out); + } + + public void resourceChanged(IResourceChangeEvent event) { + switch (event.getType()) { + case IResourceChangeEvent.POST_BUILD: + resourceChangeWriter.println("POST_BUILD " + event.getSource()); //$NON-NLS-1$ + break; + case IResourceChangeEvent.PRE_BUILD: + resourceChangeWriter.println("PRE_BUILD " + event.getSource()); //$NON-NLS-1$ + break; + case IResourceChangeEvent.PRE_DELETE: + resourceChangeWriter.println("PRE_DELETE " + event.getResource()); //$NON-NLS-1$ + break; + case IResourceChangeEvent.PRE_REFRESH: + resourceChangeWriter.println("PRE_REFRESH " + event.getResource()); //$NON-NLS-1$ + break; + case IResourceChangeEvent.POST_CHANGE: + resourceChangeWriter.println("POST_CHANGE "); //$NON-NLS-1$ + printDelta(event.getDelta(), 0); + break; + } + } + + private void printDelta(IResourceDelta delta, int depth) { + for (int i = 0; i < depth; i++) { + resourceChangeWriter.print("\t"); //$NON-NLS-1$ + } + switch (delta.getKind()) { + case IResourceDelta.ADDED: + resourceChangeWriter.print("ADDED "); //$NON-NLS-1$ + break; + case IResourceDelta.CHANGED: + resourceChangeWriter.print("CHANGED "); //$NON-NLS-1$ + break; + case IResourceDelta.REMOVED: + resourceChangeWriter.print("REMOVED "); //$NON-NLS-1$ + break; + } + if (delta.getResource() != null) { + resourceChangeWriter.println(delta.getResource()); + } + for (IResourceDelta child : delta.getAffectedChildren()) { + printDelta(child, depth + 1); + } + } +}
\ No newline at end of file diff --git a/valgrind/org.eclipse.linuxtools.valgrind.tests/src/org/eclipse/linuxtools/internal/valgrind/tests/ValgrindStubCommand.java b/valgrind/org.eclipse.linuxtools.valgrind.tests/src/org/eclipse/linuxtools/internal/valgrind/tests/ValgrindStubCommand.java new file mode 100644 index 0000000000..65421a42bf --- /dev/null +++ b/valgrind/org.eclipse.linuxtools.valgrind.tests/src/org/eclipse/linuxtools/internal/valgrind/tests/ValgrindStubCommand.java @@ -0,0 +1,44 @@ +/******************************************************************************* + * Copyright (c) 2009 Red Hat, Inc. + * All rights reserved. This program and the accompanying materials + * are made available under the terms of the Eclipse Public License v1.0 + * which accompanies this distribution, and is available at + * http://www.eclipse.org/legal/epl-v10.html + * + * Contributors: + * Elliott Baron <ebaron@redhat.com> - initial API and implementation + *******************************************************************************/ +package org.eclipse.linuxtools.internal.valgrind.tests; + +import java.io.File; +import java.io.IOException; + +import org.eclipse.linuxtools.internal.valgrind.core.ValgrindCommand; + +public class ValgrindStubCommand extends ValgrindCommand { + protected static final String VERSION_FILE = ".version"; //$NON-NLS-1$ + + protected int exitcode; + + @Override + public String whichValgrind() throws IOException { + return "/path/to/valgrind"; //$NON-NLS-1$ + } + + @Override + public String whichVersion(String whichValgrind) throws IOException { + return "valgrind-3.4.0"; //$NON-NLS-1$ + } + + @Override + public void execute(String[] commandArray, String[] env, File wd, + boolean usePty) throws IOException { + args = commandArray; + } + + @Override + public Process getProcess() { + return null; + } + +} diff --git a/valgrind/org.eclipse.linuxtools.valgrind.tests/src/org/eclipse/linuxtools/internal/valgrind/tests/ValgrindStubProcess.java b/valgrind/org.eclipse.linuxtools.valgrind.tests/src/org/eclipse/linuxtools/internal/valgrind/tests/ValgrindStubProcess.java new file mode 100644 index 0000000000..8edbcd08ca --- /dev/null +++ b/valgrind/org.eclipse.linuxtools.valgrind.tests/src/org/eclipse/linuxtools/internal/valgrind/tests/ValgrindStubProcess.java @@ -0,0 +1,76 @@ +/******************************************************************************* + * Copyright (c) 2009 Red Hat, Inc. + * All rights reserved. This program and the accompanying materials + * are made available under the terms of the Eclipse Public License v1.0 + * which accompanies this distribution, and is available at + * http://www.eclipse.org/legal/epl-v10.html + * + * Contributors: + * Elliott Baron <ebaron@redhat.com> - initial API and implementation + *******************************************************************************/ +package org.eclipse.linuxtools.internal.valgrind.tests; + +import java.util.HashMap; +import java.util.Map; + +import org.eclipse.debug.core.DebugException; +import org.eclipse.debug.core.ILaunch; +import org.eclipse.debug.core.model.IProcess; +import org.eclipse.debug.core.model.IStreamsProxy; + +public class ValgrindStubProcess implements IProcess { + protected Map<String, String> attributes; + protected ILaunch launch; + protected String label; + protected IStreamsProxy streamsProxy; + + public ValgrindStubProcess(ILaunch launch, String label) { + attributes = new HashMap<String, String>(); + streamsProxy = new ValgrindStubStreamsProxy(); + this.launch = launch; + this.label = label; + + launch.addProcess(this); + } + + public String getAttribute(String key) { + return attributes.get(key); + } + + public int getExitValue() throws DebugException { + return 0; + } + + public String getLabel() { + return label; + } + + public ILaunch getLaunch() { + return launch; + } + + public IStreamsProxy getStreamsProxy() { + return streamsProxy; + } + + public void setAttribute(String key, String value) { + attributes.put(key, value); + } + + @SuppressWarnings("unchecked") + public Object getAdapter(Class adapter) { + return null; + } + + public boolean canTerminate() { + return true; + } + + public boolean isTerminated() { + return true; + } + + public void terminate() throws DebugException { + } + +} diff --git a/valgrind/org.eclipse.linuxtools.valgrind.tests/src/org/eclipse/linuxtools/internal/valgrind/tests/ValgrindStubStreamsProxy.java b/valgrind/org.eclipse.linuxtools.valgrind.tests/src/org/eclipse/linuxtools/internal/valgrind/tests/ValgrindStubStreamsProxy.java new file mode 100644 index 0000000000..f202d464f2 --- /dev/null +++ b/valgrind/org.eclipse.linuxtools.valgrind.tests/src/org/eclipse/linuxtools/internal/valgrind/tests/ValgrindStubStreamsProxy.java @@ -0,0 +1,31 @@ +/******************************************************************************* + * Copyright (c) 2009 Red Hat, Inc. + * All rights reserved. This program and the accompanying materials + * are made available under the terms of the Eclipse Public License v1.0 + * which accompanies this distribution, and is available at + * http://www.eclipse.org/legal/epl-v10.html + * + * Contributors: + * Elliott Baron <ebaron@redhat.com> - initial API and implementation + *******************************************************************************/ +package org.eclipse.linuxtools.internal.valgrind.tests; + +import java.io.IOException; + +import org.eclipse.debug.core.model.IStreamMonitor; +import org.eclipse.debug.core.model.IStreamsProxy; + +public class ValgrindStubStreamsProxy implements IStreamsProxy { + + public IStreamMonitor getErrorStreamMonitor() { + return null; + } + + public IStreamMonitor getOutputStreamMonitor() { + return null; + } + + public void write(String input) throws IOException { + } + +} diff --git a/valgrind/org.eclipse.linuxtools.valgrind.tests/src/org/eclipse/linuxtools/internal/valgrind/tests/ValgrindTestLaunchDelegate.java b/valgrind/org.eclipse.linuxtools.valgrind.tests/src/org/eclipse/linuxtools/internal/valgrind/tests/ValgrindTestLaunchDelegate.java new file mode 100644 index 0000000000..360a3a4754 --- /dev/null +++ b/valgrind/org.eclipse.linuxtools.valgrind.tests/src/org/eclipse/linuxtools/internal/valgrind/tests/ValgrindTestLaunchDelegate.java @@ -0,0 +1,65 @@ +/******************************************************************************* + * Copyright (c) 2009 Red Hat, Inc. + * All rights reserved. This program and the accompanying materials + * are made available under the terms of the Eclipse Public License v1.0 + * which accompanies this distribution, and is available at + * http://www.eclipse.org/legal/epl-v10.html + * + * Contributors: + * Elliott Baron <ebaron@redhat.com> - initial API and implementation + *******************************************************************************/ +package org.eclipse.linuxtools.internal.valgrind.tests; + +import java.io.IOException; + +import org.eclipse.core.runtime.CoreException; +import org.eclipse.core.runtime.IPath; +import org.eclipse.debug.core.ILaunch; +import org.eclipse.debug.core.ILaunchConfiguration; +import org.eclipse.debug.core.model.IProcess; +import org.eclipse.linuxtools.internal.valgrind.core.ValgrindCommand; +import org.eclipse.linuxtools.internal.valgrind.launch.ValgrindLaunchConfigurationDelegate; + +public class ValgrindTestLaunchDelegate extends ValgrindLaunchConfigurationDelegate { + + protected static final String ERROR_CODE_FILE = ".errorCode"; //$NON-NLS-1$ + + @Override + protected ValgrindCommand getValgrindCommand() { + if (!ValgrindTestsPlugin.RUN_VALGRIND) { + return new ValgrindStubCommand(); + } + else { + return super.getValgrindCommand(); + } + } + + @Override + protected void createDirectory(IPath path) throws IOException { + if (ValgrindTestsPlugin.RUN_VALGRIND) { + super.createDirectory(path); + } + } + + @Override + protected IProcess createNewProcess(ILaunch launch, Process systemProcess, + String programName) { + IProcess process; + if (ValgrindTestsPlugin.RUN_VALGRIND) { + process = super.createNewProcess(launch, systemProcess, programName); + } + else { + process = new ValgrindStubProcess(launch, programName); + } + return process; + } + + @Override + protected void setOutputPath(ILaunchConfiguration config) + throws CoreException, IOException { + if (!ValgrindTestsPlugin.GENERATE_FILES && ValgrindTestsPlugin.RUN_VALGRIND) { + super.setOutputPath(config); + } + } + +} diff --git a/valgrind/org.eclipse.linuxtools.valgrind.tests/src/org/eclipse/linuxtools/internal/valgrind/tests/ValgrindTestLaunchShortcut.java b/valgrind/org.eclipse.linuxtools.valgrind.tests/src/org/eclipse/linuxtools/internal/valgrind/tests/ValgrindTestLaunchShortcut.java new file mode 100644 index 0000000000..410b35d77f --- /dev/null +++ b/valgrind/org.eclipse.linuxtools.valgrind.tests/src/org/eclipse/linuxtools/internal/valgrind/tests/ValgrindTestLaunchShortcut.java @@ -0,0 +1,29 @@ +/******************************************************************************* + * Copyright (c) 2009 Red Hat, Inc. + * All rights reserved. This program and the accompanying materials + * are made available under the terms of the Eclipse Public License v1.0 + * which accompanies this distribution, and is available at + * http://www.eclipse.org/legal/epl-v10.html + * + * Contributors: + * Elliott Baron <ebaron@redhat.com> - initial API and implementation + *******************************************************************************/ +package org.eclipse.linuxtools.internal.valgrind.tests; + +import org.eclipse.cdt.core.model.IBinary; +import org.eclipse.debug.core.ILaunchConfiguration; +import org.eclipse.linuxtools.internal.valgrind.launch.ValgrindLaunchShortcut; + +public class ValgrindTestLaunchShortcut extends ValgrindLaunchShortcut { + + private ILaunchConfiguration config; + + @Override + public void launch(IBinary bin, String mode) { + config = findLaunchConfiguration(bin, mode); + } + + public ILaunchConfiguration getConfig() { + return config; + } +} diff --git a/valgrind/org.eclipse.linuxtools.valgrind.tests/src/org/eclipse/linuxtools/internal/valgrind/tests/ValgrindTestsPlugin.java b/valgrind/org.eclipse.linuxtools.valgrind.tests/src/org/eclipse/linuxtools/internal/valgrind/tests/ValgrindTestsPlugin.java new file mode 100644 index 0000000000..8d2a9434c5 --- /dev/null +++ b/valgrind/org.eclipse.linuxtools.valgrind.tests/src/org/eclipse/linuxtools/internal/valgrind/tests/ValgrindTestsPlugin.java @@ -0,0 +1,78 @@ +/******************************************************************************* + * Copyright (c) 2009 Red Hat, Inc. + * All rights reserved. This program and the accompanying materials + * are made available under the terms of the Eclipse Public License v1.0 + * which accompanies this distribution, and is available at + * http://www.eclipse.org/legal/epl-v10.html + * + * Contributors: + * Elliott Baron <ebaron@redhat.com> - initial API and implementation + *******************************************************************************/ +package org.eclipse.linuxtools.internal.valgrind.tests; + +import org.eclipse.ui.plugin.AbstractUIPlugin; +import org.osgi.framework.BundleContext; + +public class ValgrindTestsPlugin extends AbstractUIPlugin { + + // The plug-in ID + public static final String PLUGIN_ID = "org.eclipse.linuxtools.valgrind.tests"; //$NON-NLS-1$ + + // Java Runtime System Properties + /** + * usage: -Declipse.valgrind.tests.generateFiles=<yes|no> [default: no] + * if yes, will run Valgrind and store its output files for each test under + * <plugin root>/valgrindFiles + * no, will use default output directory for valgrind's output + */ + public static final String SYSTEM_PROPERTY_GENERATE_FILES = "eclipse.valgrind.tests.generateFiles"; //$NON-NLS-1$ + public static final boolean GENERATE_FILES = System.getProperty(SYSTEM_PROPERTY_GENERATE_FILES, "no").equals("yes"); //$NON-NLS-1$ //$NON-NLS-2$ + + /** + * usage: -Declipse.valgrind.tests.runValgrind=<yes|no> [default: yes] + * if yes, will run Valgrind as in a normal launch + * no, will simulate Valgrind execution with pregenerated log files + */ + public static final String SYSTEM_PROPERTY_RUN_VALGRIND = "eclipse.valgrind.tests.runValgrind"; //$NON-NLS-1$ + // generateFiles implies runValgrind + public static final boolean RUN_VALGRIND = GENERATE_FILES || System.getProperty(SYSTEM_PROPERTY_RUN_VALGRIND, "yes").equals("yes"); //$NON-NLS-1$ //$NON-NLS-2$ + + // Launch config attribute to mock valgrind's exit code + public static final String ATTR_MOCK_EXIT_CODE = PLUGIN_ID + ".MOCK_EXIT_CODE"; //$NON-NLS-1$ + + // The shared instance + private static ValgrindTestsPlugin plugin; + + /** + * The constructor + */ + public ValgrindTestsPlugin() { + } + + /* + * (non-Javadoc) + * @see org.eclipse.ui.plugin.AbstractUIPlugin#start(org.osgi.framework.BundleContext) + */ + public void start(BundleContext context) throws Exception { + super.start(context); + plugin = this; + } + + /* + * (non-Javadoc) + * @see org.eclipse.ui.plugin.AbstractUIPlugin#stop(org.osgi.framework.BundleContext) + */ + public void stop(BundleContext context) throws Exception { + plugin = null; + super.stop(context); + } + + /** + * Returns the shared instance + * + * @return the shared instance + */ + public static ValgrindTestsPlugin getDefault() { + return plugin; + } +} diff --git a/valgrind/org.eclipse.linuxtools.valgrind.tests/test.xml b/valgrind/org.eclipse.linuxtools.valgrind.tests/test.xml new file mode 100644 index 0000000000..6f072efeb6 --- /dev/null +++ b/valgrind/org.eclipse.linuxtools.valgrind.tests/test.xml @@ -0,0 +1,74 @@ +<?xml version="1.0"?> + +<project name="testsuite" default="run" basedir="."> + <property name="cachegrindClassname" value="org.eclipse.linuxtools.internal.valgrind.cachegrind.tests.AllTests" /> + <property name="massifClassname" value="org.eclipse.linuxtools.internal.valgrind.massif.tests.AllTests" /> + <property name="memcheckClassname" value="org.eclipse.linuxtools.internal.valgrind.memcheck.tests.AllTests" /> + + <property name="cachegrind-plugin-name" value="org.eclipse.linuxtools.valgrind.cachegrind.tests" /> + <property name="massif-plugin-name" value="org.eclipse.linuxtools.valgrind.massif.tests" /> + <property name="memcheck-plugin-name" value="org.eclipse.linuxtools.valgrind.memcheck.tests" /> + + <!-- The property ${eclipse-home} should be passed into this script --> + <!-- Set a meaningful default value for when it is not. --> + <property name="eclipse-home" value="${basedir}/../.." /> + <property name="library-file" value="${eclipse-home}/dropins/eclipse/plugins/org.eclipse.test/library.xml" /> + + <!-- This target holds all initialization code that needs to be done for --> + <!-- all tests that are to be run. Initialization for individual tests --> + <!-- should be done within the body of the suite target. --> + <target name="init"> + <tstamp /> + <delete> + <fileset dir="${eclipse-home}" includes="org*.xml" /> + </delete> + </target> + + <target name="memchecksuite"> + <property name="memcheck-folder" value="${eclipse-home}/memcheck_folder" /> + <delete dir="${massif-folder}" quiet="true" /> + <ant target="ui-test" antfile="${library-file}" dir="${eclipse-home}"> + <property name="data-dir" value="${massif-folder}" /> + <property name="plugin-name" value="${memcheck-plugin-name}" /> + <property name="classname" value="${memcheckClassname}" /> + </ant> + </target> + + <target name="massifsuite"> + <property name="massif-folder" value="${eclipse-home}/massif_folder" /> + <delete dir="${massif-folder}" quiet="true" /> + <ant target="ui-test" antfile="${library-file}" dir="${eclipse-home}"> + <property name="data-dir" value="${massif-folder}" /> + <property name="plugin-name" value="${massif-plugin-name}" /> + <property name="classname" value="${massifClassname}" /> + </ant> + </target> + + <target name="cachegrindsuite"> + <property name="cachegrind-folder" value="${eclipse-home}/cachegrind_folder" /> + <delete dir="${cachegrind-folder}" quiet="true" /> + <ant target="ui-test" antfile="${library-file}" dir="${eclipse-home}"> + <property name="data-dir" value="${cachegrind-folder}" /> + <property name="plugin-name" value="${cachegrind-plugin-name}" /> + <property name="classname" value="${cachegrindClassname}" /> + </ant> + </target> + + <!-- This target holds code to cleanup the testing environment after --> + <!-- after all of the tests have been run. You can use this target to --> + <!-- delete temporary files that have been created. --> + <target name="cleanup"> + <mkdir dir="${results}/consolelogs" /> + <copy failonerror="false" file="${eclipse-home}/results/${classname}.txt" tofile="${results}/consolelogs/${classname}_${platform}.metadata.log.txt" /> + </target> + + <!-- This target runs the test suite. Any actions that need to happen --> + <!-- after all the tests have been run should go here. --> + <target name="run" depends="init,memchecksuite,massifsuite,cachegrindsuite,cleanup"> + <ant target="collect" antfile="${library-file}" dir="${eclipse-home}"> + <property name="includes" value="org*.xml" /> + <property name="output-file" value="${plugin-name}.xml" /> + </ant> + </target> + +</project> |