diff options
author | Andrew Ferrazzutti | 2014-05-26 20:57:51 +0000 |
---|---|---|
committer | Jeff Johnston | 2014-07-17 20:22:08 +0000 |
commit | fc7aeae136a930e0a69043eae629aadffc2e3b58 (patch) | |
tree | 8e06560240210ebc1f01af976781fddf273f851c /systemtap/org.eclipse.linuxtools.systemtap.ui.ide/src/org/eclipse/linuxtools | |
parent | 551c6f297f6e77087ddcb5d599a236275f4118ba (diff) | |
download | org.eclipse.linuxtools-fc7aeae136a930e0a69043eae629aadffc2e3b58.tar.gz org.eclipse.linuxtools-fc7aeae136a930e0a69043eae629aadffc2e3b58.tar.xz org.eclipse.linuxtools-fc7aeae136a930e0a69043eae629aadffc2e3b58.zip |
Systemtap: Remove reliance on stap from UI tests.
Also make changes where appropriate to allow dummy data to be
to be read into the Function & Probe views, so that testing of
their contents is possible without needing stap to populate them.
Change-Id: I054227235e44c8584c79951d44148edb8a615373
Signed-off-by: Andrew Ferrazzutti <aferrazz@redhat.com>
Reviewed-on: https://git.eclipse.org/r/27312
Tested-by: Hudson CI
Reviewed-by: Jeff Johnston <jjohnstn@redhat.com>
Tested-by: Jeff Johnston <jjohnstn@redhat.com>
Diffstat (limited to 'systemtap/org.eclipse.linuxtools.systemtap.ui.ide/src/org/eclipse/linuxtools')
8 files changed, 115 insertions, 96 deletions
diff --git a/systemtap/org.eclipse.linuxtools.systemtap.ui.ide/src/org/eclipse/linuxtools/internal/systemtap/ui/ide/handlers/ExportDataSetHandler.java b/systemtap/org.eclipse.linuxtools.systemtap.ui.ide/src/org/eclipse/linuxtools/internal/systemtap/ui/ide/handlers/ExportDataSetHandler.java index c81a7d6af6..565ec1e9b8 100644 --- a/systemtap/org.eclipse.linuxtools.systemtap.ui.ide/src/org/eclipse/linuxtools/internal/systemtap/ui/ide/handlers/ExportDataSetHandler.java +++ b/systemtap/org.eclipse.linuxtools.systemtap.ui.ide/src/org/eclipse/linuxtools/internal/systemtap/ui/ide/handlers/ExportDataSetHandler.java @@ -24,7 +24,7 @@ import org.eclipse.ui.PlatformUI; import org.eclipse.ui.handlers.HandlerUtil; /** - * This <code>Action</code> exports all data in the currently-active {@link GraphSelectorEditor} + * This handler exports all data in the currently-active {@link GraphSelectorEditor} * into an external file, which can be imported back in later with {@link ImportDataSetHandler}. */ public class ExportDataSetHandler extends AbstractHandler { diff --git a/systemtap/org.eclipse.linuxtools.systemtap.ui.ide/src/org/eclipse/linuxtools/internal/systemtap/ui/ide/handlers/ImportDataSetHandler.java b/systemtap/org.eclipse.linuxtools.systemtap.ui.ide/src/org/eclipse/linuxtools/internal/systemtap/ui/ide/handlers/ImportDataSetHandler.java index 5540e71f3c..4f8b2e1b7a 100644 --- a/systemtap/org.eclipse.linuxtools.systemtap.ui.ide/src/org/eclipse/linuxtools/internal/systemtap/ui/ide/handlers/ImportDataSetHandler.java +++ b/systemtap/org.eclipse.linuxtools.systemtap.ui.ide/src/org/eclipse/linuxtools/internal/systemtap/ui/ide/handlers/ImportDataSetHandler.java @@ -38,7 +38,7 @@ import org.eclipse.ui.PlatformUI; import org.eclipse.ui.WorkbenchException; /** - * This <code>Action</code> imports data from an external file to populate + * This handler imports data from an external file to populate * a {@link GraphSelectorEditor}. * into an external file, which can be imported back in later. */ @@ -50,10 +50,17 @@ public class ImportDataSetHandler extends AbstractHandler { dialog.setFilterExtensions(new String[]{Messages.DataSetFileExtension}); dialog.setText(Messages.ImportDataSetAction_DialogTitle); String path = dialog.open(); - if (path == null) { - return null; + if (path != null) { + execute(path); } + return null; + } + /** + * Import a data set from the specified path. + * @param path The path of the data set to import. + */ + public void execute(String path) { IFilteredDataSet dataset = null; File file = new File(path); try (InputStreamReader fr = new InputStreamReader(new FileInputStream(file), Charset.defaultCharset()); @@ -83,8 +90,6 @@ public class ImportDataSetHandler extends AbstractHandler { } catch (WorkbenchException we) { ExceptionErrorDialog.openError(Messages.RunScriptChartHandler_couldNotSwitchToGraphicPerspective, we); } - - return null; } } diff --git a/systemtap/org.eclipse.linuxtools.systemtap.ui.ide/src/org/eclipse/linuxtools/internal/systemtap/ui/ide/structures/FunctionParser.java b/systemtap/org.eclipse.linuxtools.systemtap.ui.ide/src/org/eclipse/linuxtools/internal/systemtap/ui/ide/structures/FunctionParser.java index 65cd8b67c1..3e1ca26c87 100644 --- a/systemtap/org.eclipse.linuxtools.systemtap.ui.ide/src/org/eclipse/linuxtools/internal/systemtap/ui/ide/structures/FunctionParser.java +++ b/systemtap/org.eclipse.linuxtools.systemtap.ui.ide/src/org/eclipse/linuxtools/internal/systemtap/ui/ide/structures/FunctionParser.java @@ -18,9 +18,7 @@ import java.util.regex.Pattern; import org.eclipse.core.runtime.IProgressMonitor; import org.eclipse.core.runtime.IStatus; -import org.eclipse.core.runtime.Status; import org.eclipse.linuxtools.internal.systemtap.ui.ide.CommentRemover; -import org.eclipse.linuxtools.internal.systemtap.ui.ide.IDEPlugin; import org.eclipse.linuxtools.internal.systemtap.ui.ide.structures.nodedata.FuncparamNodeData; import org.eclipse.linuxtools.internal.systemtap.ui.ide.structures.nodedata.FunctionNodeData; import org.eclipse.linuxtools.systemtap.structures.TreeDefinitionNode; @@ -37,7 +35,6 @@ import org.eclipse.linuxtools.systemtap.structures.TreeNode; public final class FunctionParser extends TreeTapsetParser { private static FunctionParser parser = null; - private TreeNode functions; /** * The descriptor used for unresolvable types. @@ -62,31 +59,13 @@ public final class FunctionParser extends TreeTapsetParser { super("Function Parser"); //$NON-NLS-1$ } - @Override - public synchronized TreeNode getTree() { - return functions; - } - - @Override - protected void resetTree() { - functions = new TreeNode(null, false); - } - - @Override - public void dispose() { - functions.dispose(); - } - /** * Runs stap to collect all available tapset functions. */ @Override - protected IStatus run(IProgressMonitor monitor) { - super.run(monitor); - boolean canceled = !addFunctions(monitor); - functions.sortTree(); - return new Status(!canceled ? IStatus.OK : IStatus.CANCEL, - IDEPlugin.PLUGIN_ID, ""); //$NON-NLS-1$ + protected IStatus runAction(IProgressMonitor monitor) { + addFunctions(monitor); + return super.runAction(monitor); } /** @@ -100,11 +79,17 @@ public final class FunctionParser extends TreeTapsetParser { * <code>true</code> otherwise. */ private boolean addFunctions(IProgressMonitor monitor) { + if (monitor.isCanceled()) { + return false; + } + String tapsetContents = SharedParser.getInstance().getTapsetContents(); if (tapsetContents == null) { // Functions are only drawn from the tapset dump, so exit if it's empty. return true; } + + boolean canceled = false; try (Scanner st = new Scanner(tapsetContents)) { String filename = null; String scriptText = null; @@ -112,7 +97,8 @@ public final class FunctionParser extends TreeTapsetParser { SharedParser sparser = SharedParser.getInstance(); while (st.hasNextLine()) { if (monitor.isCanceled()) { - return false; + canceled = true; + break; } String tok = st.nextLine(); Matcher mFilename = sparser.filePattern.matcher(tok); @@ -135,8 +121,9 @@ public final class FunctionParser extends TreeTapsetParser { } } } - return true; } + tree.sortTree(); + return !canceled; } private void addFunctionFromScript(String functionName, String scriptText, String scriptFilename) { @@ -153,7 +140,7 @@ public final class FunctionParser extends TreeTapsetParser { TreeDefinitionNode function = new TreeDefinitionNode( new FunctionNodeData(functionLine, functionType), functionName, scriptFilename, true); - functions.add(function); + tree.add(function); addParamsFromString(mScript.group(2), function); } } diff --git a/systemtap/org.eclipse.linuxtools.systemtap.ui.ide/src/org/eclipse/linuxtools/internal/systemtap/ui/ide/structures/Messages.java b/systemtap/org.eclipse.linuxtools.systemtap.ui.ide/src/org/eclipse/linuxtools/internal/systemtap/ui/ide/structures/Messages.java index e24af415b0..3ae0b62588 100644 --- a/systemtap/org.eclipse.linuxtools.systemtap.ui.ide/src/org/eclipse/linuxtools/internal/systemtap/ui/ide/structures/Messages.java +++ b/systemtap/org.eclipse.linuxtools.systemtap.ui.ide/src/org/eclipse/linuxtools/internal/systemtap/ui/ide/structures/Messages.java @@ -20,6 +20,7 @@ public class Messages extends NLS { public static String ProbeParser_errorInitializingStaticProbes; public static String ProbeParser_staticProbes; public static String ProbeParser_aliasProbes; + public static String ProbeParser_illegalArgMessage; public static String TapsetParser_CannotRunStapMessage; public static String TapsetParser_CannotRunStapTitle; public static String TapsetParser_ErrorRunningSystemtap; diff --git a/systemtap/org.eclipse.linuxtools.systemtap.ui.ide/src/org/eclipse/linuxtools/internal/systemtap/ui/ide/structures/ProbeParser.java b/systemtap/org.eclipse.linuxtools.systemtap.ui.ide/src/org/eclipse/linuxtools/internal/systemtap/ui/ide/structures/ProbeParser.java index ad7ce447f3..c096d6f6a1 100644 --- a/systemtap/org.eclipse.linuxtools.systemtap.ui.ide/src/org/eclipse/linuxtools/internal/systemtap/ui/ide/structures/ProbeParser.java +++ b/systemtap/org.eclipse.linuxtools.systemtap.ui.ide/src/org/eclipse/linuxtools/internal/systemtap/ui/ide/structures/ProbeParser.java @@ -19,8 +19,6 @@ import java.util.regex.Pattern; import org.eclipse.core.runtime.IProgressMonitor; import org.eclipse.core.runtime.IStatus; -import org.eclipse.core.runtime.Status; -import org.eclipse.linuxtools.internal.systemtap.ui.ide.IDEPlugin; import org.eclipse.linuxtools.internal.systemtap.ui.ide.structures.nodedata.ProbeNodeData; import org.eclipse.linuxtools.internal.systemtap.ui.ide.structures.nodedata.ProbevarNodeData; import org.eclipse.linuxtools.systemtap.structures.TreeDefinitionNode; @@ -39,10 +37,6 @@ public final class ProbeParser extends TreeTapsetParser { public static final String PROBE_REGEX = "(?s)(?<!\\w)probe\\s+{0}\\s*\\+?="; //$NON-NLS-1$ private static final String TAPSET_PROBE_REGEX = "probe {0} \\+?="; //$NON-NLS-1$ - private TreeNode probes; - private TreeNode statics; - private TreeNode aliases; - private static ProbeParser parser = null; public static ProbeParser getInstance(){ if (parser != null) { @@ -56,16 +50,15 @@ public final class ProbeParser extends TreeTapsetParser { super("Probe Parser"); //$NON-NLS-1$ } + /** + * @param tree To be valid, the first-level children of this tree must + * be two nodes respectively named "Static Probes" and "Probe Alias". + */ @Override - public synchronized TreeNode getTree() { - return probes; - } - - @Override - public void dispose() { - probes.dispose(); - statics.dispose(); - aliases.dispose(); + protected String isValidTree(TreeNode tree) { + return tree.getChildByName(Messages.ProbeParser_staticProbes) != null + && tree.getChildByName(Messages.ProbeParser_aliasProbes) != null + ? null : Messages.ProbeParser_illegalArgMessage; } /** @@ -74,29 +67,10 @@ public final class ProbeParser extends TreeTapsetParser { * Root->Named Groups->ProbePoints->Variables */ @Override - protected IStatus run(IProgressMonitor monitor) { - super.run(monitor); - boolean canceled = !addStaticProbes(monitor); - if (!canceled) { - canceled = !addProbeAliases(monitor); - } - constructRootTree(); - return new Status(!monitor.isCanceled() ? IStatus.OK : IStatus.CANCEL, - IDEPlugin.PLUGIN_ID, ""); //$NON-NLS-1$ - } - - @Override - protected void resetTree() { - probes = new TreeNode(null, false); - statics = new TreeNode(Messages.ProbeParser_staticProbes, false); - aliases = new TreeNode(Messages.ProbeParser_aliasProbes, false); - } - - private void constructRootTree() { - statics.sortTree(); - aliases.sortTree(); - probes.add(statics); - probes.add(aliases); + protected IStatus runAction(IProgressMonitor monitor) { + addStaticProbes(monitor); + addProbeAliases(monitor, tree.getChildAt(0)); + return super.runAction(monitor); } /** @@ -106,23 +80,33 @@ public final class ProbeParser extends TreeTapsetParser { * <code>true</code> otherwise. */ private boolean addStaticProbes(IProgressMonitor monitor) { + TreeNode statics = new TreeNode(Messages.ProbeParser_staticProbes, false); + tree.add(statics); + if (monitor.isCanceled()) { + return false; + } + String probeDump = runStap(new String[]{"--dump-probe-types"}, null, false); //$NON-NLS-1$ if (probeDump == null) { - return true; + return false; } - TreeNode group = null; + + boolean canceled = false; try (Scanner st = new Scanner(probeDump)) { + TreeNode group = null; while (st.hasNextLine()) { if (monitor.isCanceled()) { - return false; + canceled = true; + break; } String tokenString = st.nextLine(); String probeName = (new StringTokenizer(tokenString)).nextToken(); group = addOrFindProbeGroup(extractProbeGroupName(probeName), group, statics); group.add(makeStaticProbeNode(probeName)); } - return true; } + statics.sortTree(); + return !canceled; } /** @@ -132,16 +116,25 @@ public final class ProbeParser extends TreeTapsetParser { * @return <code>false</code> if a cancelation prevented all probes from being added; * <code>true</code> otherwise. */ - private boolean addProbeAliases(IProgressMonitor monitor) { + private boolean addProbeAliases(IProgressMonitor monitor, TreeNode statics) { + TreeNode aliases = new TreeNode(Messages.ProbeParser_aliasProbes, false); + tree.add(aliases); + if (statics == null || monitor.isCanceled()) { + return false; + } + String probeDump = runStap(new String[]{"-L"}, "**", false); //$NON-NLS-1$ //$NON-NLS-2$ if (probeDump == null) { - return true; + return false; } - TreeNode group = null; + + boolean canceled = false; try (Scanner st = new Scanner(probeDump)) { + TreeNode group = null; while (st.hasNextLine()) { if (monitor.isCanceled()) { - return false; + canceled = false; + break; } String tokenString = st.nextLine(); // If the token starts with '_' or '__' it is a private probe so @@ -154,15 +147,17 @@ public final class ProbeParser extends TreeTapsetParser { String probeName = probeTokenizer.nextToken(); String groupName = extractProbeGroupName(tokenString); - if (!isStaticProbeGroup(groupName)) { + // Only add this group if it is not a static probe group + if (statics.getChildByName(groupName) == null) { TreeNode probeNode = makeProbeAliasNode(probeName); group = addOrFindProbeGroup(groupName, group, aliases); group.add(probeNode); addAllVarNodesToProbeNode(probeTokenizer, probeNode); } } - return true; } + aliases.sortTree(); + return !canceled; } /** @@ -217,10 +212,6 @@ public final class ProbeParser extends TreeTapsetParser { return new TreeDefinitionNode(new ProbeNodeData(probeName), probeName, findDefinitionOf(probeName), true); } - private boolean isStaticProbeGroup(String groupName) { - return statics.getChildByName(groupName) != null; - } - /** * Search the tapset content dump for the path of the file which defines the provided probe alias. * @param probeName The alias of the probe to find the definition file of. diff --git a/systemtap/org.eclipse.linuxtools.systemtap.ui.ide/src/org/eclipse/linuxtools/internal/systemtap/ui/ide/structures/TapsetLibrary.java b/systemtap/org.eclipse.linuxtools.systemtap.ui.ide/src/org/eclipse/linuxtools/internal/systemtap/ui/ide/structures/TapsetLibrary.java index a1958993e7..1902b5d5ba 100644 --- a/systemtap/org.eclipse.linuxtools.systemtap.ui.ide/src/org/eclipse/linuxtools/internal/systemtap/ui/ide/structures/TapsetLibrary.java +++ b/systemtap/org.eclipse.linuxtools.systemtap.ui.ide/src/org/eclipse/linuxtools/internal/systemtap/ui/ide/structures/TapsetLibrary.java @@ -170,9 +170,9 @@ public final class TapsetLibrary { * This method will get all of the tree information from * the TreeSettings xml file. */ - private static void readTreeFile() { - functionTree = TreeSettings.getFunctionTree(); - probeTree = TreeSettings.getProbeTree(); + public static void readTreeFile() { + functionParser.setTree(TreeSettings.getFunctionTree()); + probeParser.setTree(TreeSettings.getProbeTree()); } /** diff --git a/systemtap/org.eclipse.linuxtools.systemtap.ui.ide/src/org/eclipse/linuxtools/internal/systemtap/ui/ide/structures/TreeTapsetParser.java b/systemtap/org.eclipse.linuxtools.systemtap.ui.ide/src/org/eclipse/linuxtools/internal/systemtap/ui/ide/structures/TreeTapsetParser.java index 2009bd6762..e3b5f2ebe1 100644 --- a/systemtap/org.eclipse.linuxtools.systemtap.ui.ide/src/org/eclipse/linuxtools/internal/systemtap/ui/ide/structures/TreeTapsetParser.java +++ b/systemtap/org.eclipse.linuxtools.systemtap.ui.ide/src/org/eclipse/linuxtools/internal/systemtap/ui/ide/structures/TreeTapsetParser.java @@ -13,6 +13,8 @@ package org.eclipse.linuxtools.internal.systemtap.ui.ide.structures; import org.eclipse.core.runtime.IProgressMonitor; import org.eclipse.core.runtime.IStatus; +import org.eclipse.core.runtime.Status; +import org.eclipse.linuxtools.internal.systemtap.ui.ide.IDEPlugin; import org.eclipse.linuxtools.systemtap.structures.TreeNode; /** @@ -21,6 +23,9 @@ import org.eclipse.linuxtools.systemtap.structures.TreeNode; */ public abstract class TreeTapsetParser extends TapsetParser { + protected TreeNode tree = null; + private TreeNode forcedTree = null; + protected TreeTapsetParser(String jobTitle) { super(jobTitle); } @@ -30,24 +35,53 @@ public abstract class TreeTapsetParser extends TapsetParser { * actions during the run; a call to super.run() is necessary. */ @Override - protected IStatus run(IProgressMonitor monitor) { - resetTree(); - return null; + protected final synchronized IStatus run(IProgressMonitor monitor) { + if (forcedTree != null) { + tree = forcedTree; + forcedTree = null; + return new Status(IStatus.OK, IDEPlugin.PLUGIN_ID, ""); //$NON-NLS-1$ + } else { + tree = new TreeNode(null, false); + return runAction(monitor); + } + } + + protected IStatus runAction(IProgressMonitor monitor) { + return new Status(!monitor.isCanceled() ? IStatus.OK : IStatus.CANCEL, + IDEPlugin.PLUGIN_ID, ""); //$NON-NLS-1$ } /** * @return The tree that this parser constructs. */ - abstract TreeNode getTree(); + public final synchronized TreeNode getTree() { + return tree; + } /** - * Clears & resets the tree that this parser constructs. + * Forcefully set this parser's tree, and subsequently fire update events + * that normally get called when a parse operation completes. + * @param tree The tree to put into this parser. */ - abstract protected void resetTree(); + final synchronized void setTree(TreeNode tree) { + String errorMessage = isValidTree(tree); + if (errorMessage != null) { + throw new IllegalArgumentException(errorMessage); + } + cancel(); + forcedTree = tree; + schedule(); + } /** - * Clean up everything from the last parse run. + * Check if the provided tree a valid tree for this parser. + * Called internally by {@link #setTree(TreeNode)}. + * @param tree The tree to check for validity. + * @return <code>null</code> if the tree is valid; otherwise, + * an error message signifying why the tree is invalid. */ - abstract void dispose(); + protected String isValidTree(TreeNode tree) { + return null; + } } diff --git a/systemtap/org.eclipse.linuxtools.systemtap.ui.ide/src/org/eclipse/linuxtools/internal/systemtap/ui/ide/structures/messages.properties b/systemtap/org.eclipse.linuxtools.systemtap.ui.ide/src/org/eclipse/linuxtools/internal/systemtap/ui/ide/structures/messages.properties index dbe41099f2..0a1e9dafeb 100644 --- a/systemtap/org.eclipse.linuxtools.systemtap.ui.ide/src/org/eclipse/linuxtools/internal/systemtap/ui/ide/structures/messages.properties +++ b/systemtap/org.eclipse.linuxtools.systemtap.ui.ide/src/org/eclipse/linuxtools/internal/systemtap/ui/ide/structures/messages.properties @@ -12,6 +12,7 @@ ProbeParser_errorInitializingStaticProbes=Could not initialize static probe list ProbeParser_staticProbes=Static Probes ProbeParser_aliasProbes=Probe Aliases +ProbeParser_illegalArgMessage=The first-level children of this tree must be two nodes named "Static Probes" and "Probe Alias" respectively. TapsetParser_CannotRunStapMessage=Make sure SystemTap is installed. TapsetParser_CannotRunStapTitle=Cannot Run SystemTap TapsetParser_ErrorRunningSystemtap=Error Running SystemTap |