diff options
Diffstat (limited to 'gprof/org.eclipse.linuxtools.gprof.test/src/org/eclipse')
8 files changed, 552 insertions, 552 deletions
diff --git a/gprof/org.eclipse.linuxtools.gprof.test/src/org/eclipse/linuxtools/internal/gprof/test/AllGprofTests.java b/gprof/org.eclipse.linuxtools.gprof.test/src/org/eclipse/linuxtools/internal/gprof/test/AllGprofTests.java index ac130df2fa..f22ea7e1b1 100644 --- a/gprof/org.eclipse.linuxtools.gprof.test/src/org/eclipse/linuxtools/internal/gprof/test/AllGprofTests.java +++ b/gprof/org.eclipse.linuxtools.gprof.test/src/org/eclipse/linuxtools/internal/gprof/test/AllGprofTests.java @@ -15,7 +15,7 @@ import org.junit.runners.Suite; @RunWith(Suite.class) @Suite.SuiteClasses({ GprofAggregatorTest.class, GprofBinaryTest.class, - GprofParserTest.class, GprofLaunchTest.class, GprofShortcutTest.class, - GprofTest.class }) + GprofParserTest.class, GprofLaunchTest.class, GprofShortcutTest.class, + GprofTest.class }) public class AllGprofTests { } diff --git a/gprof/org.eclipse.linuxtools.gprof.test/src/org/eclipse/linuxtools/internal/gprof/test/GprofAggregatorTest.java b/gprof/org.eclipse.linuxtools.gprof.test/src/org/eclipse/linuxtools/internal/gprof/test/GprofAggregatorTest.java index 37839a5d88..24916006c2 100644 --- a/gprof/org.eclipse.linuxtools.gprof.test/src/org/eclipse/linuxtools/internal/gprof/test/GprofAggregatorTest.java +++ b/gprof/org.eclipse.linuxtools.gprof.test/src/org/eclipse/linuxtools/internal/gprof/test/GprofAggregatorTest.java @@ -32,51 +32,51 @@ import org.junit.runners.Parameterized.Parameters; @RunWith(Parameterized.class) public class GprofAggregatorTest { - @Parameters - public static Collection<Object[]> data() { - List<Object[]> params = new ArrayList<>(); - for (File testDir : STJunitUtils.getTestDirs()) { - final String dirName = testDir.getName(); - params.add(new Object[] { dirName }); - } - return params; - } + @Parameters + public static Collection<Object[]> data() { + List<Object[]> params = new ArrayList<>(); + for (File testDir : STJunitUtils.getTestDirs()) { + final String dirName = testDir.getName(); + params.add(new Object[] { dirName }); + } + return params; + } - private String dir; + private String dir; - public GprofAggregatorTest(String dir) { - this.dir = dir; - } + public GprofAggregatorTest(String dir) { + this.dir = dir; + } - @Test - public void testAggregation() throws IOException, InterruptedException { - File directory = new File(STJunitUtils.getAbsolutePath( - "org.eclipse.linuxtools.gprof.test", dir)); - File gmonPath = new File(STJunitUtils.getAbsolutePath( - "org.eclipse.linuxtools.gprof.test", dir + File.separator - + OUTPUT_FILE)); - File binaryPath = new File(STJunitUtils.getAbsolutePath( - "org.eclipse.linuxtools.gprof.test", dir + File.separator - + BINARY_FILE)); + @Test + public void testAggregation() throws IOException, InterruptedException { + File directory = new File(STJunitUtils.getAbsolutePath( + "org.eclipse.linuxtools.gprof.test", dir)); + File gmonPath = new File(STJunitUtils.getAbsolutePath( + "org.eclipse.linuxtools.gprof.test", dir + File.separator + + OUTPUT_FILE)); + File binaryPath = new File(STJunitUtils.getAbsolutePath( + "org.eclipse.linuxtools.gprof.test", dir + File.separator + + BINARY_FILE)); - String gmon = gmonPath.toString(); - String binary = binaryPath.toString(); + String gmon = gmonPath.toString(); + String binary = binaryPath.toString(); - LinkedList<String> s = new LinkedList<>(); - s.add(gmon.toString()); - s.add(gmon.toString()); + LinkedList<String> s = new LinkedList<>(); + s.add(gmon.toString()); + s.add(gmon.toString()); - String gprof2use = "gprof"; - File f = Aggregator.aggregate(gprof2use, binary, s, directory); + String gprof2use = "gprof"; + File f = Aggregator.aggregate(gprof2use, binary, s, directory); - Process p = Runtime.getRuntime().exec( - new String[] { gprof2use, binary, f.getAbsolutePath() }); - Process p2 = Runtime.getRuntime().exec( - new String[] { gprof2use, binary, - directory + File.separator + "gmon.sum.ref" }); + Process p = Runtime.getRuntime().exec( + new String[] { gprof2use, binary, f.getAbsolutePath() }); + Process p2 = Runtime.getRuntime().exec( + new String[] { gprof2use, binary, + directory + File.separator + "gmon.sum.ref" }); - STJunitUtils.compare(p.getInputStream(), p2.getInputStream()); - p.waitFor(); - p2.waitFor(); - } + STJunitUtils.compare(p.getInputStream(), p2.getInputStream()); + p.waitFor(); + p2.waitFor(); + } } diff --git a/gprof/org.eclipse.linuxtools.gprof.test/src/org/eclipse/linuxtools/internal/gprof/test/GprofBinaryTest.java b/gprof/org.eclipse.linuxtools.gprof.test/src/org/eclipse/linuxtools/internal/gprof/test/GprofBinaryTest.java index 94b537f983..104b6f4e28 100644 --- a/gprof/org.eclipse.linuxtools.gprof.test/src/org/eclipse/linuxtools/internal/gprof/test/GprofBinaryTest.java +++ b/gprof/org.eclipse.linuxtools.gprof.test/src/org/eclipse/linuxtools/internal/gprof/test/GprofBinaryTest.java @@ -26,24 +26,24 @@ import org.osgi.framework.FrameworkUtil; @RunWith(Parameterized.class) public class GprofBinaryTest { - @Parameters + @Parameters public static Collection<Object[]> data() { - List<Object[]> params = new ArrayList<>(); - for (File testDir : STJunitUtils.getTestDirs()) { - params.add(new Object[]{testDir.getName()+File.separator+BINARY_FILE}); - } - return params; - } + List<Object[]> params = new ArrayList<>(); + for (File testDir : STJunitUtils.getTestDirs()) { + params.add(new Object[]{testDir.getName()+File.separator+BINARY_FILE}); + } + return params; + } private String path; public GprofBinaryTest(String path){ - this.path = path; + this.path = path; } @Test - public void testValidBinary() { - STJunitUtils.getAbsolutePath(FrameworkUtil.getBundle(GprofBinaryTest.class).getSymbolicName(), path); - } + public void testValidBinary() { + STJunitUtils.getAbsolutePath(FrameworkUtil.getBundle(GprofBinaryTest.class).getSymbolicName(), path); + } } diff --git a/gprof/org.eclipse.linuxtools.gprof.test/src/org/eclipse/linuxtools/internal/gprof/test/GprofLaunchTest.java b/gprof/org.eclipse.linuxtools.gprof.test/src/org/eclipse/linuxtools/internal/gprof/test/GprofLaunchTest.java index 58bf3deb02..6ef0f34fa8 100644 --- a/gprof/org.eclipse.linuxtools.gprof.test/src/org/eclipse/linuxtools/internal/gprof/test/GprofLaunchTest.java +++ b/gprof/org.eclipse.linuxtools.gprof.test/src/org/eclipse/linuxtools/internal/gprof/test/GprofLaunchTest.java @@ -38,65 +38,65 @@ import org.osgi.framework.FrameworkUtil; public class GprofLaunchTest extends AbstractTest { - protected ILaunchConfiguration config; - protected AbstractCLaunchDelegate delegate; - protected ILaunch launch; - protected ILaunchConfigurationWorkingCopy wc; - private static final String ID = "org.eclipse.linuxtools.profiling.provider.TimingLaunchShortcut"; //$NON-NLS-1$ - private static final String LAUNCH_SHORT_EXTPT = "org.eclipse.debug.ui.launchShortcuts"; //$NON-NLS-1$ - private static final String GPROF_PROVIDER_ID = "org.eclipse.linuxtools.profiling.provider.timing.gprof"; //$NON-NLS-1$ - private static final String GPROF_CATEGORY = "timing"; //$NON-NLS-1$ + protected ILaunchConfiguration config; + protected AbstractCLaunchDelegate delegate; + protected ILaunch launch; + protected ILaunchConfigurationWorkingCopy wc; + private static final String ID = "org.eclipse.linuxtools.profiling.provider.TimingLaunchShortcut"; //$NON-NLS-1$ + private static final String LAUNCH_SHORT_EXTPT = "org.eclipse.debug.ui.launchShortcuts"; //$NON-NLS-1$ + private static final String GPROF_PROVIDER_ID = "org.eclipse.linuxtools.profiling.provider.timing.gprof"; //$NON-NLS-1$ + private static final String GPROF_CATEGORY = "timing"; //$NON-NLS-1$ - ProviderLaunchShortcut shortcut; - String launchConfigTypeId; + ProviderLaunchShortcut shortcut; + String launchConfigTypeId; - @Before - public void setUp() throws Exception { - proj = createProjectAndBuild(FrameworkUtil.getBundle(this.getClass()), "fibTest"); //$NON-NLS-1$ - ProjectScope ps = new ProjectScope(proj.getProject()); - ScopedPreferenceStore scoped = new ScopedPreferenceStore(ps, ProviderProfileConstants.PLUGIN_ID); - scoped.setSearchContexts(new IScopeContext[] { ps, InstanceScope.INSTANCE }); - scoped.setValue(ProviderProfileConstants.PREFS_KEY + GPROF_CATEGORY, GPROF_PROVIDER_ID); - scoped.setValue(ProviderProfileConstants.USE_PROJECT_SETTINGS + GPROF_CATEGORY, true); - scoped.save(); + @Before + public void setUp() throws Exception { + proj = createProjectAndBuild(FrameworkUtil.getBundle(this.getClass()), "fibTest"); //$NON-NLS-1$ + ProjectScope ps = new ProjectScope(proj.getProject()); + ScopedPreferenceStore scoped = new ScopedPreferenceStore(ps, ProviderProfileConstants.PLUGIN_ID); + scoped.setSearchContexts(new IScopeContext[] { ps, InstanceScope.INSTANCE }); + scoped.setValue(ProviderProfileConstants.PREFS_KEY + GPROF_CATEGORY, GPROF_PROVIDER_ID); + scoped.setValue(ProviderProfileConstants.USE_PROJECT_SETTINGS + GPROF_CATEGORY, true); + scoped.save(); - IExtensionPoint extPoint = Platform.getExtensionRegistry().getExtensionPoint(LAUNCH_SHORT_EXTPT); - IConfigurationElement[] configs = extPoint.getConfigurationElements(); - for (IConfigurationElement cfg : configs) { - if (cfg.getAttribute("id").equals(ID)){ //$NON-NLS-1$ - try { - shortcut = (ProviderLaunchShortcut) cfg.createExecutableExtension("class"); //$NON-NLS-1$ - launchConfigTypeId = cfg.getChildren("class")[0].getChildren("parameter")[1].getAttribute("value"); //$NON-NLS-1$ - } catch (Exception e){ - fail (e.getMessage()); - } - } - } - config = createConfiguration(proj.getProject()); - launch = new Launch(config, ILaunchManager.PROFILE_MODE, null); - wc = config.getWorkingCopy(); - } + IExtensionPoint extPoint = Platform.getExtensionRegistry().getExtensionPoint(LAUNCH_SHORT_EXTPT); + IConfigurationElement[] configs = extPoint.getConfigurationElements(); + for (IConfigurationElement cfg : configs) { + if (cfg.getAttribute("id").equals(ID)){ //$NON-NLS-1$ + try { + shortcut = (ProviderLaunchShortcut) cfg.createExecutableExtension("class"); //$NON-NLS-1$ + launchConfigTypeId = cfg.getChildren("class")[0].getChildren("parameter")[1].getAttribute("value"); //$NON-NLS-1$ + } catch (Exception e){ + fail (e.getMessage()); + } + } + } + config = createConfiguration(proj.getProject()); + launch = new Launch(config, ILaunchManager.PROFILE_MODE, null); + wc = config.getWorkingCopy(); + } - @After - public void tearDown() throws Exception { - deleteProject(proj); - wc.delete(); - config.delete(); - } + @After + public void tearDown() throws Exception { + deleteProject(proj); + wc.delete(); + config.delete(); + } - @Override - protected ILaunchConfigurationType getLaunchConfigType() { - return getLaunchManager().getLaunchConfigurationType(launchConfigTypeId); - } + @Override + protected ILaunchConfigurationType getLaunchConfigType() { + return getLaunchManager().getLaunchConfigurationType(launchConfigTypeId); + } - @Override - protected void setProfileAttributes(ILaunchConfigurationWorkingCopy wc) { - } + @Override + protected void setProfileAttributes(ILaunchConfigurationWorkingCopy wc) { + } - @Test - public void testDelegateLaunch() throws CoreException { - delegate = new GprofLaunchConfigurationDelegate(); - delegate.launch(wc, ILaunchManager.PROFILE_MODE, launch, null); - } + @Test + public void testDelegateLaunch() throws CoreException { + delegate = new GprofLaunchConfigurationDelegate(); + delegate.launch(wc, ILaunchManager.PROFILE_MODE, launch, null); + } } diff --git a/gprof/org.eclipse.linuxtools.gprof.test/src/org/eclipse/linuxtools/internal/gprof/test/GprofParserTest.java b/gprof/org.eclipse.linuxtools.gprof.test/src/org/eclipse/linuxtools/internal/gprof/test/GprofParserTest.java index fe1bd40733..aa589a2589 100644 --- a/gprof/org.eclipse.linuxtools.gprof.test/src/org/eclipse/linuxtools/internal/gprof/test/GprofParserTest.java +++ b/gprof/org.eclipse.linuxtools.gprof.test/src/org/eclipse/linuxtools/internal/gprof/test/GprofParserTest.java @@ -30,40 +30,40 @@ import org.junit.runners.Parameterized.Parameters; @RunWith(Parameterized.class) public class GprofParserTest { - @Parameters - public static Collection<Object[]> data() { - List<Object[]> params = new ArrayList<>(); - for (File testDir : STJunitUtils.getTestDirs()) { - params.add(new Object[] { new File(testDir, OUTPUT_FILE), - new File(testDir, BINARY_FILE), - new File(testDir, "testParse.ref"), - new File(testDir, "testParse.dump") }); - } - return params; - } + @Parameters + public static Collection<Object[]> data() { + List<Object[]> params = new ArrayList<>(); + for (File testDir : STJunitUtils.getTestDirs()) { + params.add(new Object[] { new File(testDir, OUTPUT_FILE), + new File(testDir, BINARY_FILE), + new File(testDir, "testParse.ref"), + new File(testDir, "testParse.dump") }); + } + return params; + } - private File gmonFile; - private File binaryFile; - private File parserRefFile; - private File parserDumpFile; + private File gmonFile; + private File binaryFile; + private File parserRefFile; + private File parserDumpFile; - public GprofParserTest(File gmonFile, File binaryFile, File parserRefFile, - File parserDumpFile) { - this.gmonFile = gmonFile; - this.binaryFile = binaryFile; - this.parserRefFile = parserRefFile; - this.parserDumpFile = parserDumpFile; - } + public GprofParserTest(File gmonFile, File binaryFile, File parserRefFile, + File parserDumpFile) { + this.gmonFile = gmonFile; + this.binaryFile = binaryFile; + this.parserRefFile = parserRefFile; + this.parserDumpFile = parserDumpFile; + } - @Test - public void testProcessGmonFile() throws IOException { - IBinaryObject binary = STSymbolManager.sharedInstance - .getBinaryObject(binaryFile.getAbsolutePath()); - final GmonDecoder gmondecoder = new GmonDecoder(binary, - new PrintStream(parserDumpFile), null); - gmondecoder.setShouldDump(true); - gmondecoder.read(gmonFile.getAbsolutePath()); - STJunitUtils.compareIgnoreEOL(parserDumpFile.getAbsolutePath(), - parserRefFile.getAbsolutePath(), true); - } + @Test + public void testProcessGmonFile() throws IOException { + IBinaryObject binary = STSymbolManager.sharedInstance + .getBinaryObject(binaryFile.getAbsolutePath()); + final GmonDecoder gmondecoder = new GmonDecoder(binary, + new PrintStream(parserDumpFile), null); + gmondecoder.setShouldDump(true); + gmondecoder.read(gmonFile.getAbsolutePath()); + STJunitUtils.compareIgnoreEOL(parserDumpFile.getAbsolutePath(), + parserRefFile.getAbsolutePath(), true); + } } diff --git a/gprof/org.eclipse.linuxtools.gprof.test/src/org/eclipse/linuxtools/internal/gprof/test/GprofShortcutTest.java b/gprof/org.eclipse.linuxtools.gprof.test/src/org/eclipse/linuxtools/internal/gprof/test/GprofShortcutTest.java index 67640f9099..9dc9f9a3c7 100644 --- a/gprof/org.eclipse.linuxtools.gprof.test/src/org/eclipse/linuxtools/internal/gprof/test/GprofShortcutTest.java +++ b/gprof/org.eclipse.linuxtools.gprof.test/src/org/eclipse/linuxtools/internal/gprof/test/GprofShortcutTest.java @@ -38,67 +38,67 @@ import org.osgi.framework.FrameworkUtil; public class GprofShortcutTest extends AbstractTest { - protected ILaunchConfiguration config; - protected GprofLaunchConfigurationDelegate delegate; - protected ILaunch launch; - protected ILaunchConfigurationWorkingCopy wc; - private static final String ID = "org.eclipse.linuxtools.profiling.provider.TimingLaunchShortcut"; //$NON-NLS-1$ - private static final String LAUNCH_SHORT_EXTPT = "org.eclipse.debug.ui.launchShortcuts"; //$NON-NLS-1$ - private static final String GPROF_PROVIDER_ID = "org.eclipse.linuxtools.profiling.provider.timing.gprof"; //$NON-NLS-1$ - private static final String GPROF_CATEGORY = "timing"; //$NON-NLS-1$ + protected ILaunchConfiguration config; + protected GprofLaunchConfigurationDelegate delegate; + protected ILaunch launch; + protected ILaunchConfigurationWorkingCopy wc; + private static final String ID = "org.eclipse.linuxtools.profiling.provider.TimingLaunchShortcut"; //$NON-NLS-1$ + private static final String LAUNCH_SHORT_EXTPT = "org.eclipse.debug.ui.launchShortcuts"; //$NON-NLS-1$ + private static final String GPROF_PROVIDER_ID = "org.eclipse.linuxtools.profiling.provider.timing.gprof"; //$NON-NLS-1$ + private static final String GPROF_CATEGORY = "timing"; //$NON-NLS-1$ - ProviderLaunchShortcut shortcut; - String launchConfigTypeId; + ProviderLaunchShortcut shortcut; + String launchConfigTypeId; - @Before - public void setUp() throws Exception { - proj = createProjectAndBuild(FrameworkUtil.getBundle(this.getClass()), "fibTest2"); //$NON-NLS-1$ - ProjectScope ps = new ProjectScope(proj.getProject()); - ScopedPreferenceStore scoped = new ScopedPreferenceStore(ps, ProviderProfileConstants.PLUGIN_ID); - scoped.setSearchContexts(new IScopeContext[] { ps, InstanceScope.INSTANCE }); - scoped.setValue(ProviderProfileConstants.PREFS_KEY + GPROF_CATEGORY, GPROF_PROVIDER_ID); - scoped.setValue(ProviderProfileConstants.USE_PROJECT_SETTINGS + GPROF_CATEGORY, true); - scoped.save(); + @Before + public void setUp() throws Exception { + proj = createProjectAndBuild(FrameworkUtil.getBundle(this.getClass()), "fibTest2"); //$NON-NLS-1$ + ProjectScope ps = new ProjectScope(proj.getProject()); + ScopedPreferenceStore scoped = new ScopedPreferenceStore(ps, ProviderProfileConstants.PLUGIN_ID); + scoped.setSearchContexts(new IScopeContext[] { ps, InstanceScope.INSTANCE }); + scoped.setValue(ProviderProfileConstants.PREFS_KEY + GPROF_CATEGORY, GPROF_PROVIDER_ID); + scoped.setValue(ProviderProfileConstants.USE_PROJECT_SETTINGS + GPROF_CATEGORY, true); + scoped.save(); - IExtensionPoint extPoint = Platform.getExtensionRegistry().getExtensionPoint(LAUNCH_SHORT_EXTPT); - IConfigurationElement[] configs = extPoint.getConfigurationElements(); - for (IConfigurationElement cfg : configs) { - if (cfg.getAttribute("id").equals(ID)){ //$NON-NLS-1$ - try { - shortcut = (ProviderLaunchShortcut) cfg.createExecutableExtension("class"); //$NON-NLS-1$ - launchConfigTypeId = cfg.getChildren("class")[0].getChildren("parameter")[1].getAttribute("value"); //$NON-NLS-1$ - } catch (Exception e){ - fail (e.getMessage()); - } - } - } - config = createConfiguration(proj.getProject()); - launch = new Launch(config, ILaunchManager.PROFILE_MODE, null); - wc = config.getWorkingCopy(); - } + IExtensionPoint extPoint = Platform.getExtensionRegistry().getExtensionPoint(LAUNCH_SHORT_EXTPT); + IConfigurationElement[] configs = extPoint.getConfigurationElements(); + for (IConfigurationElement cfg : configs) { + if (cfg.getAttribute("id").equals(ID)){ //$NON-NLS-1$ + try { + shortcut = (ProviderLaunchShortcut) cfg.createExecutableExtension("class"); //$NON-NLS-1$ + launchConfigTypeId = cfg.getChildren("class")[0].getChildren("parameter")[1].getAttribute("value"); //$NON-NLS-1$ + } catch (Exception e){ + fail (e.getMessage()); + } + } + } + config = createConfiguration(proj.getProject()); + launch = new Launch(config, ILaunchManager.PROFILE_MODE, null); + wc = config.getWorkingCopy(); + } - @After - public void tearDown() throws Exception { - deleteProject(proj); - wc.delete(); - config.delete(); - } + @After + public void tearDown() throws Exception { + deleteProject(proj); + wc.delete(); + config.delete(); + } - @Override - protected ILaunchConfigurationType getLaunchConfigType() { - return getLaunchManager().getLaunchConfigurationType(launchConfigTypeId); - } + @Override + protected ILaunchConfigurationType getLaunchConfigType() { + return getLaunchManager().getLaunchConfigurationType(launchConfigTypeId); + } - @Override - protected void setProfileAttributes(ILaunchConfigurationWorkingCopy wc) { - } + @Override + protected void setProfileAttributes(ILaunchConfigurationWorkingCopy wc) { + } - @Test - public void testShortCut() throws CModelException { - String id = ProviderFramework.getProviderIdToRun(wc, GPROF_CATEGORY); - assertTrue(id.equals(GPROF_PROVIDER_ID)); - shortcut.launch(proj.getBinaryContainer().getBinaries()[0], - ILaunchManager.PROFILE_MODE); - } + @Test + public void testShortCut() throws CModelException { + String id = ProviderFramework.getProviderIdToRun(wc, GPROF_CATEGORY); + assertTrue(id.equals(GPROF_PROVIDER_ID)); + shortcut.launch(proj.getBinaryContainer().getBinaries()[0], + ILaunchManager.PROFILE_MODE); + } } diff --git a/gprof/org.eclipse.linuxtools.gprof.test/src/org/eclipse/linuxtools/internal/gprof/test/GprofTest.java b/gprof/org.eclipse.linuxtools.gprof.test/src/org/eclipse/linuxtools/internal/gprof/test/GprofTest.java index 41667aab39..a276539938 100644 --- a/gprof/org.eclipse.linuxtools.gprof.test/src/org/eclipse/linuxtools/internal/gprof/test/GprofTest.java +++ b/gprof/org.eclipse.linuxtools.gprof.test/src/org/eclipse/linuxtools/internal/gprof/test/GprofTest.java @@ -48,164 +48,164 @@ import org.junit.runners.Parameterized.Parameters; @RunWith(Parameterized.class) public class GprofTest { - @Parameters - public static Collection<Object[]> data() { - List<Object[]> params = new ArrayList<>(); - boolean addr2line2_16 = false; - try { - Process p = Runtime.getRuntime().exec("addr2line --version"); - InputStream is = p.getInputStream(); - LineNumberReader reader = new LineNumberReader( - new InputStreamReader(is)); - String line; - while ((line = reader.readLine()) != null) { - if (line.contains("addr2line 2.16.")) { - addr2line2_16 = true; - break; - } - } - } catch (IOException _) { - } - - for (File testDir : STJunitUtils.getTestDirs()) { - final File gmonFile = new File(testDir, OUTPUT_FILE); - final File binaryFile = new File(testDir, BINARY_FILE); - - File view_cg_RefFile_default = new File(testDir, - "testCallgraphView.ref"); - File view_cg_RefFile_alternate = new File(testDir, - "testCallgraphView.ref.binutils-2.16"); - File view_cg2_RefFile_default = new File(testDir, - "testCallgraphTimeView.ref"); - File view_cg2_RefFile_alternate = new File(testDir, - "testCallgraphTimeView.ref.binutils-2.16"); - final File view_cg_RefFile; - final File view_cg2_RefFile; - if (addr2line2_16 && view_cg_RefFile_alternate.exists()) { - view_cg_RefFile = view_cg_RefFile_alternate; - } else { - view_cg_RefFile = view_cg_RefFile_default; - } - if (addr2line2_16 && view_cg2_RefFile_alternate.exists()) { - view_cg2_RefFile = view_cg2_RefFile_alternate; - } else { - view_cg2_RefFile = view_cg2_RefFile_default; - } - final File view_cg2_DumpFile = new File(testDir, - "testCallgraphTimeView.dump"); - final File view_cg_DumpFile = new File(testDir, - "testCallgraphView.dump"); - - final File view_samplesFile_RefFile = new File(testDir, - "testSampleView.ref"); - final File view_samplesFile_DumpFile = new File(testDir, - "testSampleView.dump"); - final File view_samplesFileT_RefFile = new File(testDir, - "testTimeView.ref"); - final File view_samplesFileT_DumpFile = new File(testDir, - "testTimeView.dump"); - - final File view_samplesFunction_RefFile = new File(testDir, - "testFunctionSampleView.ref"); - final File view_samplesFunction_DumpFile = new File(testDir, - "testFunctionSampleView.dump"); - final File view_samplesFunctionT_RefFile = new File(testDir, - "testFunctionTimeView.ref"); - final File view_samplesFunctionT_DumpFile = new File(testDir, - "testFunctionTimeView.dump"); - final File view_samplesFlat_RefFile = new File(testDir, - "testFlatSampleView.ref"); - final File view_samplesFlat_DumpFile = new File(testDir, - "testFlatSampleView.dump"); - final File view_samplesFlatT_RefFile = new File(testDir, - "testFlatTimeView.ref"); - final File view_samplesFlatT_DumpFile = new File(testDir, - "testFlatTimeView.dump"); - - IBinaryObject binary = STSymbolManager.sharedInstance - .getBinaryObject(new Path(binaryFile.getAbsolutePath())); - final GmonDecoder gd = new GmonDecoder(binary, null); - try { - gd.read(gmonFile.getAbsolutePath()); - } catch (IOException e) { - e.printStackTrace(); - } - params.add(new Object[] { gmonFile, gd, view_cg_RefFile, - view_cg_DumpFile, CallGraphContentProvider.sharedInstance, - false }); - params.add(new Object[] { gmonFile, gd, view_cg2_RefFile, - view_cg2_DumpFile, CallGraphContentProvider.sharedInstance, - true }); - params.add(new Object[] { gmonFile, gd, view_samplesFile_RefFile, - view_samplesFile_DumpFile, - FileHistogramContentProvider.sharedInstance, false }); - params.add(new Object[] { gmonFile, gd, view_samplesFileT_RefFile, - view_samplesFileT_DumpFile, - FileHistogramContentProvider.sharedInstance, true }); - params.add(new Object[] { gmonFile, gd, - view_samplesFunction_RefFile, - view_samplesFunction_DumpFile, - FunctionHistogramContentProvider.sharedInstance, false }); - params.add(new Object[] { gmonFile, gd, - view_samplesFunctionT_RefFile, - view_samplesFunctionT_DumpFile, - FunctionHistogramContentProvider.sharedInstance, true }); - params.add(new Object[] { gmonFile, gd, view_samplesFlat_RefFile, - view_samplesFlat_DumpFile, - FlatHistogramContentProvider.sharedInstance, false }); - params.add(new Object[] { gmonFile, gd, view_samplesFlatT_RefFile, - view_samplesFlatT_DumpFile, - FlatHistogramContentProvider.sharedInstance, true }); - } - return params; - } - - private File gmonFile; - private GmonDecoder gd; - private File refFile; - private File dumpFile; - private ITreeContentProvider contentProvider; - private boolean timeMode; - - public GprofTest(File gmonFile, GmonDecoder gd, File refFile, - File dumpFile, ITreeContentProvider contentProvider, - boolean timeMode) { - this.gmonFile = gmonFile; - this.gd = gd; - this.refFile = refFile; - this.dumpFile = dumpFile; - this.contentProvider = contentProvider; - this.timeMode = timeMode; - - } - - private void changeMode(GmonView view, boolean timeModeRequested) { - AbstractSTTreeViewer gmonViewer = (AbstractSTTreeViewer) view - .getSTViewer(); - GmonDecoder decoder = (GmonDecoder) gmonViewer.getInput(); - int prof_rate = decoder.getHistogramDecoder().getProfRate(); - if (prof_rate == 0) { - return; - } - - TreeColumn tc = gmonViewer.getViewer().getTree().getColumn(1); - SampleProfField spf = (SampleProfField) tc.getData(); - - if (spf.getColumnHeaderText().endsWith("Samples") ^ !timeModeRequested) { - new SwitchSampleTimeAction(view).run(); - } - } - - @Test - public void testView() { - GmonView view = GmonView.displayGprofView(gd, - gmonFile.getAbsolutePath()); - SwitchContentProviderAction action = new SwitchContentProviderAction( - "testAction", "icons/ch_callees.png" /* to avoid error */, view - .getSTViewer().getViewer(), contentProvider); - action.run(); - changeMode(view, timeMode); - STJunitUtils.testCSVExport(view, dumpFile.getAbsolutePath(), - refFile.getAbsolutePath()); - } + @Parameters + public static Collection<Object[]> data() { + List<Object[]> params = new ArrayList<>(); + boolean addr2line2_16 = false; + try { + Process p = Runtime.getRuntime().exec("addr2line --version"); + InputStream is = p.getInputStream(); + LineNumberReader reader = new LineNumberReader( + new InputStreamReader(is)); + String line; + while ((line = reader.readLine()) != null) { + if (line.contains("addr2line 2.16.")) { + addr2line2_16 = true; + break; + } + } + } catch (IOException _) { + } + + for (File testDir : STJunitUtils.getTestDirs()) { + final File gmonFile = new File(testDir, OUTPUT_FILE); + final File binaryFile = new File(testDir, BINARY_FILE); + + File view_cg_RefFile_default = new File(testDir, + "testCallgraphView.ref"); + File view_cg_RefFile_alternate = new File(testDir, + "testCallgraphView.ref.binutils-2.16"); + File view_cg2_RefFile_default = new File(testDir, + "testCallgraphTimeView.ref"); + File view_cg2_RefFile_alternate = new File(testDir, + "testCallgraphTimeView.ref.binutils-2.16"); + final File view_cg_RefFile; + final File view_cg2_RefFile; + if (addr2line2_16 && view_cg_RefFile_alternate.exists()) { + view_cg_RefFile = view_cg_RefFile_alternate; + } else { + view_cg_RefFile = view_cg_RefFile_default; + } + if (addr2line2_16 && view_cg2_RefFile_alternate.exists()) { + view_cg2_RefFile = view_cg2_RefFile_alternate; + } else { + view_cg2_RefFile = view_cg2_RefFile_default; + } + final File view_cg2_DumpFile = new File(testDir, + "testCallgraphTimeView.dump"); + final File view_cg_DumpFile = new File(testDir, + "testCallgraphView.dump"); + + final File view_samplesFile_RefFile = new File(testDir, + "testSampleView.ref"); + final File view_samplesFile_DumpFile = new File(testDir, + "testSampleView.dump"); + final File view_samplesFileT_RefFile = new File(testDir, + "testTimeView.ref"); + final File view_samplesFileT_DumpFile = new File(testDir, + "testTimeView.dump"); + + final File view_samplesFunction_RefFile = new File(testDir, + "testFunctionSampleView.ref"); + final File view_samplesFunction_DumpFile = new File(testDir, + "testFunctionSampleView.dump"); + final File view_samplesFunctionT_RefFile = new File(testDir, + "testFunctionTimeView.ref"); + final File view_samplesFunctionT_DumpFile = new File(testDir, + "testFunctionTimeView.dump"); + final File view_samplesFlat_RefFile = new File(testDir, + "testFlatSampleView.ref"); + final File view_samplesFlat_DumpFile = new File(testDir, + "testFlatSampleView.dump"); + final File view_samplesFlatT_RefFile = new File(testDir, + "testFlatTimeView.ref"); + final File view_samplesFlatT_DumpFile = new File(testDir, + "testFlatTimeView.dump"); + + IBinaryObject binary = STSymbolManager.sharedInstance + .getBinaryObject(new Path(binaryFile.getAbsolutePath())); + final GmonDecoder gd = new GmonDecoder(binary, null); + try { + gd.read(gmonFile.getAbsolutePath()); + } catch (IOException e) { + e.printStackTrace(); + } + params.add(new Object[] { gmonFile, gd, view_cg_RefFile, + view_cg_DumpFile, CallGraphContentProvider.sharedInstance, + false }); + params.add(new Object[] { gmonFile, gd, view_cg2_RefFile, + view_cg2_DumpFile, CallGraphContentProvider.sharedInstance, + true }); + params.add(new Object[] { gmonFile, gd, view_samplesFile_RefFile, + view_samplesFile_DumpFile, + FileHistogramContentProvider.sharedInstance, false }); + params.add(new Object[] { gmonFile, gd, view_samplesFileT_RefFile, + view_samplesFileT_DumpFile, + FileHistogramContentProvider.sharedInstance, true }); + params.add(new Object[] { gmonFile, gd, + view_samplesFunction_RefFile, + view_samplesFunction_DumpFile, + FunctionHistogramContentProvider.sharedInstance, false }); + params.add(new Object[] { gmonFile, gd, + view_samplesFunctionT_RefFile, + view_samplesFunctionT_DumpFile, + FunctionHistogramContentProvider.sharedInstance, true }); + params.add(new Object[] { gmonFile, gd, view_samplesFlat_RefFile, + view_samplesFlat_DumpFile, + FlatHistogramContentProvider.sharedInstance, false }); + params.add(new Object[] { gmonFile, gd, view_samplesFlatT_RefFile, + view_samplesFlatT_DumpFile, + FlatHistogramContentProvider.sharedInstance, true }); + } + return params; + } + + private File gmonFile; + private GmonDecoder gd; + private File refFile; + private File dumpFile; + private ITreeContentProvider contentProvider; + private boolean timeMode; + + public GprofTest(File gmonFile, GmonDecoder gd, File refFile, + File dumpFile, ITreeContentProvider contentProvider, + boolean timeMode) { + this.gmonFile = gmonFile; + this.gd = gd; + this.refFile = refFile; + this.dumpFile = dumpFile; + this.contentProvider = contentProvider; + this.timeMode = timeMode; + + } + + private void changeMode(GmonView view, boolean timeModeRequested) { + AbstractSTTreeViewer gmonViewer = (AbstractSTTreeViewer) view + .getSTViewer(); + GmonDecoder decoder = (GmonDecoder) gmonViewer.getInput(); + int prof_rate = decoder.getHistogramDecoder().getProfRate(); + if (prof_rate == 0) { + return; + } + + TreeColumn tc = gmonViewer.getViewer().getTree().getColumn(1); + SampleProfField spf = (SampleProfField) tc.getData(); + + if (spf.getColumnHeaderText().endsWith("Samples") ^ !timeModeRequested) { + new SwitchSampleTimeAction(view).run(); + } + } + + @Test + public void testView() { + GmonView view = GmonView.displayGprofView(gd, + gmonFile.getAbsolutePath()); + SwitchContentProviderAction action = new SwitchContentProviderAction( + "testAction", "icons/ch_callees.png" /* to avoid error */, view + .getSTViewer().getViewer(), contentProvider); + action.run(); + changeMode(view, timeMode); + STJunitUtils.testCSVExport(view, dumpFile.getAbsolutePath(), + refFile.getAbsolutePath()); + } } diff --git a/gprof/org.eclipse.linuxtools.gprof.test/src/org/eclipse/linuxtools/internal/gprof/test/STJunitUtils.java b/gprof/org.eclipse.linuxtools.gprof.test/src/org/eclipse/linuxtools/internal/gprof/test/STJunitUtils.java index d295cd8a64..ba490afe2b 100644 --- a/gprof/org.eclipse.linuxtools.gprof.test/src/org/eclipse/linuxtools/internal/gprof/test/STJunitUtils.java +++ b/gprof/org.eclipse.linuxtools.gprof.test/src/org/eclipse/linuxtools/internal/gprof/test/STJunitUtils.java @@ -39,203 +39,203 @@ import org.osgi.framework.Bundle; */ public class STJunitUtils { - public static final String BINARY_FILE = "a.out"; - public static final String OUTPUT_FILE = "gmon.out"; - public static final String DIRECTORY_SUFFIX = "_gprof_input"; - - - /** - * Test CSV export of the given view - * @param view - * @param dumpFullFileName - * @param refFullFileName - */ - public static boolean testCSVExport(AbstractSTDataView view, String dumpFullFileName, String refFullFileName) { - STDataViewersCSVExporter exporter = new STDataViewersCSVExporter(view.getSTViewer()); - exporter.exportTo(dumpFullFileName, new NullProgressMonitor()); - // compare with ref - return compareCSVIgnoreEOL(dumpFullFileName, refFullFileName, true); - } - - /** - * Utility method to compare files - * @param dumpFile - * @param refFile - * @return - */ - public static boolean compareIgnoreEOL(String dumpFile, String refFile, boolean deleteDumpFileIfOk) { - String message = "Comparing ref file ("+refFile+ ")and dump file (" + - dumpFile+")"; - boolean equals = false; - try (LineNumberReader is1 = new LineNumberReader(new FileReader(dumpFile)); - LineNumberReader is2 = new LineNumberReader(new FileReader(refFile))){ - do { - String line1 = is1.readLine(); - String line2 = is2.readLine(); - if (line1 == null) { - if (line2 == null) { - equals = true; - } - break; - } else if (line2 == null || !line1.equals(line2)) { - break; - } - } while (true); - - if (!equals) { - assertEquals(message + ": not correspond ", true, false); - } - - is1.close(); - is2.close(); - // delete dump only for successful tests - if (equals && deleteDumpFileIfOk) { - new File(dumpFile).delete(); - } - }catch (FileNotFoundException fnfe) { - message += "... FAILED: One of these files may not exist"; - assertNull(message, fnfe); - } - catch (Exception e) { - message += ": exception raised ... FAILED"; - assertNull(message, e); - } - return equals; - } - - /** - * Utility method to compare exported CSV files - * @param dumpFile - * @param refFile - * @return - */ - public static boolean compareCSVIgnoreEOL(String dumpFile, String refFile, boolean deleteDumpFileIfOk) { - String message = "Comparing ref file ("+refFile+ ")and dump file (" + - dumpFile+")"; - boolean equals = false; - String str = "[in-charge]"; // this string can be dumped according to binutils version installed on local machine - - try (LineNumberReader is1 = new LineNumberReader(new FileReader(dumpFile)); - LineNumberReader is2 = new LineNumberReader(new FileReader(refFile))){ - do { - String line1 = is1.readLine(); - String line2 = is2.readLine(); - int length = str.length(); - if (line1 == null) { - if (line2 == null) { - equals = true; - } - break; - } else if (line1.contains(str)){ - int idx = line1.indexOf("[in-charge]"); - char c = line1.charAt(idx -1); - if (c == ' ' ){ - idx--; - length++; - } - line1 = line1.substring(0, idx) + line1.substring(idx+length, line1.length()); - if (!line1.equals(line2)) - break; - } else if (line2 == null || !line1.equals(line2)) { - break; - } - } while (true); - - is1.close(); - is2.close(); - if (!equals) { - StringBuffer msg = new StringBuffer(message + ": not correspond "); - msg.append("\n========= begin dump file =========\n"); - try (FileReader fr = new FileReader(dumpFile)) { - int c; - while ((c = fr.read()) != -1) { - msg.append((char) c); - } - } - msg.append("\n========= end dump file =========\n"); - assertEquals(msg.toString(), true, false); - } - - // delete dump only for successful tests - if (equals && deleteDumpFileIfOk) { - new File(dumpFile).delete(); - } - }catch (FileNotFoundException _) { - message += "... FAILED: One of these files may not exist"; - assertNull(message, _); - } - catch (Exception _) { - message += ": exception raised ... FAILED"; - assertNull(message, _); - } - return equals; - } - - /** - * Utility method to compare Input streams - * @param ISdump - * @param ISref - * @return - * @throws IOException - */ - public static boolean compare(InputStream ISdump, InputStream ISref) throws IOException { - try { - boolean equals = false; - do { - int char1 = ISdump.read(); - int char2 = ISref.read(); - if (char1 != char2) - break; - if (char1 == -1) { - equals = true; - break; - } - } while (true); - return equals; - } finally { - ISdump.close(); - ISref.close(); - } - } - - /** - * Gets the absolute path of a resource in the given plugin - * @param pluginId - * @param relativeName - * @return an absolute path to a file - */ - public static String getAbsolutePath(String pluginId, String relativeName) { - Bundle b = Platform.getBundle(pluginId); - URL url = FileLocator.find(b, new Path(relativeName), null); - try { - url = FileLocator.toFileURL(url); - } catch (IOException e) { - assertNotNull("Problem locating " + relativeName + " in" + pluginId,e); - } - String filename = url.getFile(); - return filename; - } - - /** - * Utility method - * @return the list of directories that belong to the pluginDirectory and - * ends with the given extensionSuffix - */ - public static File[] getTestDirs() { - // load directories containing tests - String filename = getAbsolutePath("org.eclipse.linuxtools.gprof.test", "."); - File dir = new File(filename); - File[] testDirs = dir.listFiles( - new FileFilter() { - @Override - public boolean accept(File arg0) { - return (arg0.isDirectory() && arg0.getName().matches(".*" + DIRECTORY_SUFFIX)); - } - } - ); - - // test if there is any directory samples - assertNotNull("No project files to test",testDirs); - return testDirs; - } + public static final String BINARY_FILE = "a.out"; + public static final String OUTPUT_FILE = "gmon.out"; + public static final String DIRECTORY_SUFFIX = "_gprof_input"; + + + /** + * Test CSV export of the given view + * @param view + * @param dumpFullFileName + * @param refFullFileName + */ + public static boolean testCSVExport(AbstractSTDataView view, String dumpFullFileName, String refFullFileName) { + STDataViewersCSVExporter exporter = new STDataViewersCSVExporter(view.getSTViewer()); + exporter.exportTo(dumpFullFileName, new NullProgressMonitor()); + // compare with ref + return compareCSVIgnoreEOL(dumpFullFileName, refFullFileName, true); + } + + /** + * Utility method to compare files + * @param dumpFile + * @param refFile + * @return + */ + public static boolean compareIgnoreEOL(String dumpFile, String refFile, boolean deleteDumpFileIfOk) { + String message = "Comparing ref file ("+refFile+ ")and dump file (" + + dumpFile+")"; + boolean equals = false; + try (LineNumberReader is1 = new LineNumberReader(new FileReader(dumpFile)); + LineNumberReader is2 = new LineNumberReader(new FileReader(refFile))){ + do { + String line1 = is1.readLine(); + String line2 = is2.readLine(); + if (line1 == null) { + if (line2 == null) { + equals = true; + } + break; + } else if (line2 == null || !line1.equals(line2)) { + break; + } + } while (true); + + if (!equals) { + assertEquals(message + ": not correspond ", true, false); + } + + is1.close(); + is2.close(); + // delete dump only for successful tests + if (equals && deleteDumpFileIfOk) { + new File(dumpFile).delete(); + } + }catch (FileNotFoundException fnfe) { + message += "... FAILED: One of these files may not exist"; + assertNull(message, fnfe); + } + catch (Exception e) { + message += ": exception raised ... FAILED"; + assertNull(message, e); + } + return equals; + } + + /** + * Utility method to compare exported CSV files + * @param dumpFile + * @param refFile + * @return + */ + public static boolean compareCSVIgnoreEOL(String dumpFile, String refFile, boolean deleteDumpFileIfOk) { + String message = "Comparing ref file ("+refFile+ ")and dump file (" + + dumpFile+")"; + boolean equals = false; + String str = "[in-charge]"; // this string can be dumped according to binutils version installed on local machine + + try (LineNumberReader is1 = new LineNumberReader(new FileReader(dumpFile)); + LineNumberReader is2 = new LineNumberReader(new FileReader(refFile))){ + do { + String line1 = is1.readLine(); + String line2 = is2.readLine(); + int length = str.length(); + if (line1 == null) { + if (line2 == null) { + equals = true; + } + break; + } else if (line1.contains(str)){ + int idx = line1.indexOf("[in-charge]"); + char c = line1.charAt(idx -1); + if (c == ' ' ){ + idx--; + length++; + } + line1 = line1.substring(0, idx) + line1.substring(idx+length, line1.length()); + if (!line1.equals(line2)) + break; + } else if (line2 == null || !line1.equals(line2)) { + break; + } + } while (true); + + is1.close(); + is2.close(); + if (!equals) { + StringBuffer msg = new StringBuffer(message + ": not correspond "); + msg.append("\n========= begin dump file =========\n"); + try (FileReader fr = new FileReader(dumpFile)) { + int c; + while ((c = fr.read()) != -1) { + msg.append((char) c); + } + } + msg.append("\n========= end dump file =========\n"); + assertEquals(msg.toString(), true, false); + } + + // delete dump only for successful tests + if (equals && deleteDumpFileIfOk) { + new File(dumpFile).delete(); + } + }catch (FileNotFoundException _) { + message += "... FAILED: One of these files may not exist"; + assertNull(message, _); + } + catch (Exception _) { + message += ": exception raised ... FAILED"; + assertNull(message, _); + } + return equals; + } + + /** + * Utility method to compare Input streams + * @param ISdump + * @param ISref + * @return + * @throws IOException + */ + public static boolean compare(InputStream ISdump, InputStream ISref) throws IOException { + try { + boolean equals = false; + do { + int char1 = ISdump.read(); + int char2 = ISref.read(); + if (char1 != char2) + break; + if (char1 == -1) { + equals = true; + break; + } + } while (true); + return equals; + } finally { + ISdump.close(); + ISref.close(); + } + } + + /** + * Gets the absolute path of a resource in the given plugin + * @param pluginId + * @param relativeName + * @return an absolute path to a file + */ + public static String getAbsolutePath(String pluginId, String relativeName) { + Bundle b = Platform.getBundle(pluginId); + URL url = FileLocator.find(b, new Path(relativeName), null); + try { + url = FileLocator.toFileURL(url); + } catch (IOException e) { + assertNotNull("Problem locating " + relativeName + " in" + pluginId,e); + } + String filename = url.getFile(); + return filename; + } + + /** + * Utility method + * @return the list of directories that belong to the pluginDirectory and + * ends with the given extensionSuffix + */ + public static File[] getTestDirs() { + // load directories containing tests + String filename = getAbsolutePath("org.eclipse.linuxtools.gprof.test", "."); + File dir = new File(filename); + File[] testDirs = dir.listFiles( + new FileFilter() { + @Override + public boolean accept(File arg0) { + return (arg0.isDirectory() && arg0.getName().matches(".*" + DIRECTORY_SUFFIX)); + } + } + ); + + // test if there is any directory samples + assertNotNull("No project files to test",testDirs); + return testDirs; + } } |