Skip to main content
aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorAlexander Kurtakov2013-09-06 08:36:46 +0000
committerAlexander Kurtakov2013-09-06 08:36:46 +0000
commit83073f088bb6e1c0b7c843f0251261ffbf88cecc (patch)
treef696cd141ce4b155609087885b0f2a857d038670 /perf/org.eclipse.linuxtools.perf.tests
parent58e666940bef3a4e77ec316228dcbca8e83181b6 (diff)
downloadorg.eclipse.linuxtools-83073f088bb6e1c0b7c843f0251261ffbf88cecc.tar.gz
org.eclipse.linuxtools-83073f088bb6e1c0b7c843f0251261ffbf88cecc.tar.xz
org.eclipse.linuxtools-83073f088bb6e1c0b7c843f0251261ffbf88cecc.zip
perf.tests: Simplifications.
* drop unused methods/fields * drop unused bundle requires * use foreach * initialize arrays with needed size * equals("") replaced with isEmpty * use assertArrayEquals instead of iterating and checking * remove empty fail() calls on exception - better to throw and let junit give us the exception info than plain hiding it Change-Id: I3eadb1fed16b6bd0675a7c2178878a05e8a97c65
Diffstat (limited to 'perf/org.eclipse.linuxtools.perf.tests')
-rw-r--r--perf/org.eclipse.linuxtools.perf.tests/META-INF/MANIFEST.MF5
-rw-r--r--perf/org.eclipse.linuxtools.perf.tests/src/org/eclipse/linuxtools/internal/perf/tests/DataManipulatorTest.java14
-rw-r--r--perf/org.eclipse.linuxtools.perf.tests/src/org/eclipse/linuxtools/internal/perf/tests/LaunchRemoteTest.java47
-rw-r--r--perf/org.eclipse.linuxtools.perf.tests/src/org/eclipse/linuxtools/internal/perf/tests/LaunchTabsTest.java4
-rw-r--r--perf/org.eclipse.linuxtools.perf.tests/src/org/eclipse/linuxtools/internal/perf/tests/LaunchTest.java28
-rw-r--r--perf/org.eclipse.linuxtools.perf.tests/src/org/eclipse/linuxtools/internal/perf/tests/ModelTest.java126
-rw-r--r--perf/org.eclipse.linuxtools.perf.tests/src/org/eclipse/linuxtools/internal/perf/tests/StatsComparisonTest.java6
7 files changed, 82 insertions, 148 deletions
diff --git a/perf/org.eclipse.linuxtools.perf.tests/META-INF/MANIFEST.MF b/perf/org.eclipse.linuxtools.perf.tests/META-INF/MANIFEST.MF
index b4844b7f50..39bfb4d90e 100644
--- a/perf/org.eclipse.linuxtools.perf.tests/META-INF/MANIFEST.MF
+++ b/perf/org.eclipse.linuxtools.perf.tests/META-INF/MANIFEST.MF
@@ -6,8 +6,7 @@ Bundle-Version: 1.0.0.qualifier
Bundle-RequiredExecutionEnvironment: JavaSE-1.6
Bundle-ActivationPolicy: lazy
Fragment-Host: org.eclipse.linuxtools.perf
-Require-Bundle: org.eclipse.core.runtime,
+Require-Bundle:
org.junit,
- org.eclipse.linuxtools.profiling.tests,
- org.eclipse.linuxtools.rdt.proxy
+ org.eclipse.linuxtools.profiling.tests
Bundle-Vendor: %provider
diff --git a/perf/org.eclipse.linuxtools.perf.tests/src/org/eclipse/linuxtools/internal/perf/tests/DataManipulatorTest.java b/perf/org.eclipse.linuxtools.perf.tests/src/org/eclipse/linuxtools/internal/perf/tests/DataManipulatorTest.java
index c2fcad8390..db63b02853 100644
--- a/perf/org.eclipse.linuxtools.perf.tests/src/org/eclipse/linuxtools/internal/perf/tests/DataManipulatorTest.java
+++ b/perf/org.eclipse.linuxtools.perf.tests/src/org/eclipse/linuxtools/internal/perf/tests/DataManipulatorTest.java
@@ -53,8 +53,8 @@ public class DataManipulatorTest {
sData.parse();
String expected = "perf stat -r " + runCount + " " + binary; //$NON-NLS-1$
- for (int i = 0; i < args.length; i++) {
- expected += " " + args[i]; //$NON-NLS-1$
+ for (String i:args) {
+ expected += " " + i; //$NON-NLS-1$
}
assertEquals(expected, sData.getPerfData().trim());
@@ -76,8 +76,8 @@ public class DataManipulatorTest {
}
expected = expected + " " + binary; //$NON-NLS-1$
- for (int i = 0; i < args.length; i++) {
- expected += " " + args[i]; //$NON-NLS-1$
+ for (String i : args) {
+ expected += " " + i; //$NON-NLS-1$
}
assertEquals(expected, sData.getPerfData().trim());
@@ -131,7 +131,7 @@ public class DataManipulatorTest {
// return the same command with 'echo' prepended
ret.add("echo"); //$NON-NLS-1$
ret.addAll(Arrays.asList(super.getCommand(workingDir)));
- return ret.toArray(new String[0]);
+ return ret.toArray(new String[ret.size()]);
}
}
@@ -151,7 +151,7 @@ public class DataManipulatorTest {
List<String> ret = new ArrayList<String>();
ret.add("echo"); //$NON-NLS-1$
ret.addAll(Arrays.asList(super.getCommand(command, args)));
- return ret.toArray(new String[0]);
+ return ret.toArray(new String[ret.size()]);
}
@Override
@@ -177,7 +177,7 @@ public class DataManipulatorTest {
List<String> ret = new ArrayList<String>();
ret.add("echo"); //$NON-NLS-1$
ret.addAll(Arrays.asList(super.getCommand()));
- return ret.toArray(new String[0]);
+ return ret.toArray(new String[ret.size()]);
}
}
diff --git a/perf/org.eclipse.linuxtools.perf.tests/src/org/eclipse/linuxtools/internal/perf/tests/LaunchRemoteTest.java b/perf/org.eclipse.linuxtools.perf.tests/src/org/eclipse/linuxtools/internal/perf/tests/LaunchRemoteTest.java
index e0e941ab03..be67bbbdf8 100644
--- a/perf/org.eclipse.linuxtools.perf.tests/src/org/eclipse/linuxtools/internal/perf/tests/LaunchRemoteTest.java
+++ b/perf/org.eclipse.linuxtools.perf.tests/src/org/eclipse/linuxtools/internal/perf/tests/LaunchRemoteTest.java
@@ -11,12 +11,11 @@
package org.eclipse.linuxtools.internal.perf.tests;
-import static org.junit.Assert.fail;
-
import java.util.ArrayList;
import java.util.Arrays;
import org.eclipse.core.resources.IProject;
+import org.eclipse.core.runtime.CoreException;
import org.eclipse.debug.core.ILaunch;
import org.eclipse.debug.core.ILaunchConfiguration;
import org.eclipse.debug.core.ILaunchConfigurationType;
@@ -35,10 +34,10 @@ import org.osgi.framework.FrameworkUtil;
public class LaunchRemoteTest extends AbstractRemoteTest {
- protected ILaunchConfiguration config;
- protected PerfLaunchConfigDelegate delegate;
- protected ILaunch launch;
- protected ILaunchConfigurationWorkingCopy wc;
+ private ILaunchConfiguration config;
+ private PerfLaunchConfigDelegate delegate;
+ private ILaunch launch;
+ private ILaunchConfigurationWorkingCopy wc;
private IProject project;
private final String CONNECTION_NAME = "localhost"; //$NON-NLS-1$
@@ -49,7 +48,7 @@ public class LaunchRemoteTest extends AbstractRemoteTest {
@Before
public void setUp() throws Exception {
- if ((!(AbstractRemoteTest.USERNAME.equals("")))) {
+ if ((!(AbstractRemoteTest.USERNAME.isEmpty()))) {
project = createRemoteExternalProjectAndBuild(FrameworkUtil.getBundle(this.getClass()),
PROJECT_NAME, EXTERNAL_PROJECT_PATH, SOURCE_FILE);
@@ -63,8 +62,9 @@ public class LaunchRemoteTest extends AbstractRemoteTest {
@After
public void tearDown() {
- if (!(AbstractRemoteTest.USERNAME.equals("")))
+ if (!(AbstractRemoteTest.USERNAME.isEmpty())) {
deleteResource(CONNECTION_DIR);
+ }
}
@Override
@@ -82,28 +82,21 @@ public class LaunchRemoteTest extends AbstractRemoteTest {
}
@Test
- public void testDefaultRun () {
- if (!(AbstractRemoteTest.USERNAME.equals(""))) {
- try {
- delegate.launch(wc, ILaunchManager.PROFILE_MODE, launch, null);
- } catch (Exception e) {
- e.printStackTrace();
- fail(e.getMessage());
- }
+ public void testDefaultRun() throws CoreException {
+ if (!(AbstractRemoteTest.USERNAME.isEmpty())) {
+ delegate.launch(wc, ILaunchManager.PROFILE_MODE, launch, null);
}
}
+
@Test
- public void testClockEventRun () {
- if (!(AbstractRemoteTest.USERNAME.equals(""))) {
- try {
- ArrayList<String> list = new ArrayList<String>();
- list.addAll(Arrays.asList(new String [] {"cpu-clock", "task-clock", "cycles"}));
- wc.setAttribute(PerfPlugin.ATTR_DefaultEvent, false);
- wc.setAttribute(PerfPlugin.ATTR_SelectedEvents, list);
- delegate.launch(wc, ILaunchManager.PROFILE_MODE, launch, null);
- } catch (Exception e) {
- fail(e.getMessage());
- }
+ public void testClockEventRun() throws CoreException {
+ if (!(AbstractRemoteTest.USERNAME.isEmpty())) {
+ ArrayList<String> list = new ArrayList<String>();
+ list.addAll(Arrays.asList(new String[] { "cpu-clock", "task-clock",
+ "cycles" }));
+ wc.setAttribute(PerfPlugin.ATTR_DefaultEvent, false);
+ wc.setAttribute(PerfPlugin.ATTR_SelectedEvents, list);
+ delegate.launch(wc, ILaunchManager.PROFILE_MODE, launch, null);
}
}
diff --git a/perf/org.eclipse.linuxtools.perf.tests/src/org/eclipse/linuxtools/internal/perf/tests/LaunchTabsTest.java b/perf/org.eclipse.linuxtools.perf.tests/src/org/eclipse/linuxtools/internal/perf/tests/LaunchTabsTest.java
index dfea5e33dc..acc468894f 100644
--- a/perf/org.eclipse.linuxtools.perf.tests/src/org/eclipse/linuxtools/internal/perf/tests/LaunchTabsTest.java
+++ b/perf/org.eclipse.linuxtools.perf.tests/src/org/eclipse/linuxtools/internal/perf/tests/LaunchTabsTest.java
@@ -36,8 +36,8 @@ import org.junit.Test;
import org.osgi.framework.FrameworkUtil;
public class LaunchTabsTest extends AbstractTest {
- protected ILaunchConfiguration config;
- protected Shell testShell;
+ private ILaunchConfiguration config;
+ private Shell testShell;
@Before
public void setUp() throws Exception {
diff --git a/perf/org.eclipse.linuxtools.perf.tests/src/org/eclipse/linuxtools/internal/perf/tests/LaunchTest.java b/perf/org.eclipse.linuxtools.perf.tests/src/org/eclipse/linuxtools/internal/perf/tests/LaunchTest.java
index 6758f9a1b9..2fd4669c7e 100644
--- a/perf/org.eclipse.linuxtools.perf.tests/src/org/eclipse/linuxtools/internal/perf/tests/LaunchTest.java
+++ b/perf/org.eclipse.linuxtools.perf.tests/src/org/eclipse/linuxtools/internal/perf/tests/LaunchTest.java
@@ -10,8 +10,6 @@
*******************************************************************************/
package org.eclipse.linuxtools.internal.perf.tests;
-import static org.junit.Assert.fail;
-
import java.util.ArrayList;
import java.util.Arrays;
@@ -73,27 +71,21 @@ public class LaunchTest extends AbstractTest {
}
@Test
- public void testDefaultRun () {
+ public void testDefaultRun() throws CoreException {
if (PerfCore.checkPerfInPath()) {
- try {
- delegate.launch(wc, ILaunchManager.PROFILE_MODE, launch, null);
- } catch (CoreException e) {
- fail(e.getMessage());
- }
+ delegate.launch(wc, ILaunchManager.PROFILE_MODE, launch, null);
}
}
+
@Test
- public void testClockEventRun () {
+ public void testClockEventRun() throws CoreException {
if (PerfCore.checkPerfInPath()) {
- try {
- ArrayList<String> list = new ArrayList<String>();
- list.addAll(Arrays.asList(new String [] {"cpu-clock", "task-clock", "cycles"}));
- wc.setAttribute(PerfPlugin.ATTR_DefaultEvent, false);
- wc.setAttribute(PerfPlugin.ATTR_SelectedEvents, list);
- delegate.launch(wc, ILaunchManager.PROFILE_MODE, launch, null);
- } catch (CoreException e) {
- fail(e.getMessage());
- }
+ ArrayList<String> list = new ArrayList<String>();
+ list.addAll(Arrays.asList(new String[] { "cpu-clock", "task-clock",
+ "cycles" }));
+ wc.setAttribute(PerfPlugin.ATTR_DefaultEvent, false);
+ wc.setAttribute(PerfPlugin.ATTR_SelectedEvents, list);
+ delegate.launch(wc, ILaunchManager.PROFILE_MODE, launch, null);
}
}
diff --git a/perf/org.eclipse.linuxtools.perf.tests/src/org/eclipse/linuxtools/internal/perf/tests/ModelTest.java b/perf/org.eclipse.linuxtools.perf.tests/src/org/eclipse/linuxtools/internal/perf/tests/ModelTest.java
index 8e071d0362..24f30db95d 100644
--- a/perf/org.eclipse.linuxtools.perf.tests/src/org/eclipse/linuxtools/internal/perf/tests/ModelTest.java
+++ b/perf/org.eclipse.linuxtools.perf.tests/src/org/eclipse/linuxtools/internal/perf/tests/ModelTest.java
@@ -197,7 +197,7 @@ public class ModelTest extends AbstractTest {
"libc-2.14.90.so" };
checkCommadLabels(cmdLabels, cmd);
} else if ("major-faults".equals(cur)) {
- assertTrue(!event.hasChildren());
+ assertFalse(event.hasChildren());
}
}
@@ -316,114 +316,66 @@ public class ModelTest extends AbstractTest {
}
}
}
+
@Test
- public void testAnnotateString(){
- ILaunchConfigurationWorkingCopy tempConfig = null;
- try {
- tempConfig = config.copy("test-config");
- tempConfig.setAttribute(PerfPlugin.ATTR_Kernel_Location,
- "/boot/kernel");
- tempConfig.setAttribute(PerfPlugin.ATTR_ModuleSymbols, true);
- } catch (CoreException e) {
- fail();
- }
+ public void testAnnotateString() throws CoreException {
+ ILaunchConfigurationWorkingCopy tempConfig = config.copy("test-config");
+ tempConfig
+ .setAttribute(PerfPlugin.ATTR_Kernel_Location, "/boot/kernel");
+ tempConfig.setAttribute(PerfPlugin.ATTR_ModuleSymbols, true);
String[] annotateString = PerfCore.getAnnotateString(tempConfig, "dso",
"symbol", "resources/defaultevent-data/perf.data", false);
String[] expectedString = new String[] { PerfPlugin.PERF_COMMAND,
- "annotate",
- "-d",
- "dso",
- "-s",
- "symbol",
- "-l",
- "-P",
- "--vmlinux",
- "/boot/kernel",
- "-m",
- "-i",
+ "annotate", "-d", "dso", "-s", "symbol", "-l", "-P",
+ "--vmlinux", "/boot/kernel", "-m", "-i",
"resources/defaultevent-data/perf.data" };
- for (int i = 0; i < annotateString.length; i++) {
- assertTrue(annotateString[i].equals(expectedString[i]));
- }
+ assertArrayEquals(expectedString, annotateString);
}
+
@Test
- public void testRecordString() {
- ILaunchConfigurationWorkingCopy tempConfig = null;
- try {
- tempConfig = config.copy("test-config");
- tempConfig.setAttribute(PerfPlugin.ATTR_Record_Realtime, true);
- tempConfig.setAttribute(PerfPlugin.ATTR_Record_Verbose, true);
- tempConfig.setAttribute(PerfPlugin.ATTR_Multiplex, true);
+ public void testRecordString() throws CoreException {
+ ILaunchConfigurationWorkingCopy tempConfig = config.copy("test-config");
+ tempConfig.setAttribute(PerfPlugin.ATTR_Record_Realtime, true);
+ tempConfig.setAttribute(PerfPlugin.ATTR_Record_Verbose, true);
+ tempConfig.setAttribute(PerfPlugin.ATTR_Multiplex, true);
- ArrayList<String> selectedEvents = new ArrayList<String>();
- selectedEvents.add("cpu-cycles");
- selectedEvents.add("cache-misses");
- selectedEvents.add("cpu-clock");
- tempConfig.setAttribute(PerfPlugin.ATTR_SelectedEvents, selectedEvents);
+ ArrayList<String> selectedEvents = new ArrayList<String>();
+ selectedEvents.add("cpu-cycles");
+ selectedEvents.add("cache-misses");
+ selectedEvents.add("cpu-clock");
+ tempConfig.setAttribute(PerfPlugin.ATTR_SelectedEvents, selectedEvents);
- tempConfig.setAttribute(PerfPlugin.ATTR_DefaultEvent, false);
-
- } catch (CoreException e) {
- fail();
- }
+ tempConfig.setAttribute(PerfPlugin.ATTR_DefaultEvent, false);
String[] recordString = PerfCore.getRecordString(tempConfig);
assertNotNull(recordString);
- String[] expectedString = { PerfPlugin.PERF_COMMAND,
- "record",
- "-f",
- "-r",
- "-v",
- "-M",
- "-e",
- "cpu-cycles",
- "-e",
- "cache-misses",
- "-e",
- "cpu-clock" };
- assertTrue(recordString.length == expectedString.length);
-
- for (int i = 0; i < recordString.length; i++) {
- assertTrue(recordString[i].equals(expectedString[i]));
- }
+ String[] expectedString = { PerfPlugin.PERF_COMMAND, "record", "-f",
+ "-r", "-v", "-M", "-e", "cpu-cycles", "-e", "cache-misses",
+ "-e", "cpu-clock" };
+ assertArrayEquals(expectedString, recordString);
}
+
@Test
- public void testReportString(){ILaunchConfigurationWorkingCopy tempConfig = null;
- try {
- tempConfig = config.copy("test-config");
- tempConfig.setAttribute(PerfPlugin.ATTR_Kernel_Location,
- "/boot/kernel");
- tempConfig.setAttribute(PerfPlugin.ATTR_ModuleSymbols, true);
- } catch (CoreException e) {
- fail();
- }
+ public void testReportString() throws CoreException {
+ ILaunchConfigurationWorkingCopy tempConfig = null;
+ tempConfig = config.copy("test-config");
+ tempConfig
+ .setAttribute(PerfPlugin.ATTR_Kernel_Location, "/boot/kernel");
+ tempConfig.setAttribute(PerfPlugin.ATTR_ModuleSymbols, true);
String[] reportString = PerfCore.getReportString(tempConfig,
"resources/defaultevent-data/perf.data");
assertNotNull(reportString);
- String[] expectedString = { PerfPlugin.PERF_COMMAND,
- "report",
- "--sort",
- "comm,dso,sym",
- "-n",
- "-t",
- "" + (char) 1,
- "--vmlinux",
- "/boot/kernel",
- "-m",
- "-i",
+ String[] expectedString = { PerfPlugin.PERF_COMMAND, "report",
+ "--sort", "comm,dso,sym", "-n", "-t", "" + (char) 1,
+ "--vmlinux", "/boot/kernel", "-m", "-i",
"resources/defaultevent-data/perf.data" };
- assertTrue(reportString.length == expectedString.length);
-
- for (int i = 0; i < reportString.length; i++) {
- assertTrue(reportString[i].equals(expectedString[i]));
- }
-
+ assertArrayEquals(expectedString, reportString);
}
/**
@@ -453,9 +405,7 @@ public class ModelTest extends AbstractTest {
* @param stack a stack of classes
*/
private void checkChildrenStructure (TreeParent root, Stack<Class<?>> stack){
- if (stack.isEmpty()){
- return;
- }else{
+ if (!stack.isEmpty()){
// children of root must be instances of the top class on the stack
Class<?> klass = stack.pop();
for (TreeParent tp : root.getChildren()){
diff --git a/perf/org.eclipse.linuxtools.perf.tests/src/org/eclipse/linuxtools/internal/perf/tests/StatsComparisonTest.java b/perf/org.eclipse.linuxtools.perf.tests/src/org/eclipse/linuxtools/internal/perf/tests/StatsComparisonTest.java
index 34a75eebbe..25cbdce76f 100644
--- a/perf/org.eclipse.linuxtools.perf.tests/src/org/eclipse/linuxtools/internal/perf/tests/StatsComparisonTest.java
+++ b/perf/org.eclipse.linuxtools.perf.tests/src/org/eclipse/linuxtools/internal/perf/tests/StatsComparisonTest.java
@@ -10,6 +10,7 @@
*******************************************************************************/
package org.eclipse.linuxtools.internal.perf.tests;
+import static org.junit.Assert.assertArrayEquals;
import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertFalse;
import static org.junit.Assert.assertNotNull;
@@ -21,7 +22,6 @@ import java.io.File;
import java.io.FileReader;
import java.io.IOException;
import java.util.ArrayList;
-import java.util.Arrays;
import org.eclipse.linuxtools.internal.perf.BaseDataManipulator;
import org.eclipse.linuxtools.internal.perf.PerfPlugin;
@@ -83,7 +83,7 @@ public class StatsComparisonTest {
String[] actualList = statEntry.toStringArray();
// test string array representation
- assertTrue(Arrays.equals(expectedList, actualList));
+ assertArrayEquals(expectedList, actualList);
}
@Test
@@ -102,7 +102,7 @@ public class StatsComparisonTest {
PMStatEntry actualDiff = statEntry.compare(statEntry2);
// test stat entry comparison
- assertTrue(expectedDiff.equals(actualDiff));
+ assertEquals(expectedDiff,actualDiff);
}

Back to the top