aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorCamilo Bernal2013-02-13 12:48:07 (EST)
committerRoland Grunberg2013-02-27 10:00:47 (EST)
commit921ba37d95cfec4654ec6abdabfb8ef9bfe2e10f (patch)
tree6792eeb735521e3b1a5ab82978ac5f56eee17093
parent95a683e007593eb70afb35718b1e6648470dc57e (diff)
downloadorg.eclipse.linuxtools-921ba37d95cfec4654ec6abdabfb8ef9bfe2e10f.zip
org.eclipse.linuxtools-921ba37d95cfec4654ec6abdabfb8ef9bfe2e10f.tar.gz
org.eclipse.linuxtools-921ba37d95cfec4654ec6abdabfb8ef9bfe2e10f.tar.bz2
Improve assertions in Valgrind test plug-ins.refs/changes/13/10213/6
Asserting number of error messages is not enough to catch causes of test failures, more specific checks are added. Change-Id: I844f43ca363a42d317f5b7ec8e39c39541d79a8e Reviewed-on: https://git.eclipse.org/r/10213 Tested-by: Hudson CI Reviewed-by: Roland Grunberg <rgrunber@redhat.com> IP-Clean: Roland Grunberg <rgrunber@redhat.com> Tested-by: Roland Grunberg <rgrunber@redhat.com>
-rw-r--r--valgrind/org.eclipse.linuxtools.valgrind.helgrind.tests/src/org/eclipse/linuxtools/internal/valgrind/helgrind/tests/BasicHelgrindTest.java4
-rw-r--r--valgrind/org.eclipse.linuxtools.valgrind.massif.tests/src/org/eclipse/linuxtools/internal/valgrind/massif/tests/AbstractMassifTest.java35
-rw-r--r--valgrind/org.eclipse.linuxtools.valgrind.massif.tests/src/org/eclipse/linuxtools/internal/valgrind/massif/tests/BasicMassifTest.java7
-rw-r--r--valgrind/org.eclipse.linuxtools.valgrind.massif.tests/src/org/eclipse/linuxtools/internal/valgrind/massif/tests/ChartTests.java1
-rw-r--r--valgrind/org.eclipse.linuxtools.valgrind.massif.tests/src/org/eclipse/linuxtools/internal/valgrind/massif/tests/ExportWizardTest.java27
-rw-r--r--valgrind/org.eclipse.linuxtools.valgrind.massif.tests/src/org/eclipse/linuxtools/internal/valgrind/massif/tests/MultiProcessTest.java12
-rw-r--r--valgrind/org.eclipse.linuxtools.valgrind.memcheck.tests/src/org/eclipse/linuxtools/internal/valgrind/memcheck/tests/AbstractMemcheckTest.java48
-rw-r--r--valgrind/org.eclipse.linuxtools.valgrind.memcheck.tests/src/org/eclipse/linuxtools/internal/valgrind/memcheck/tests/BasicMemcheckTest.java11
-rw-r--r--valgrind/org.eclipse.linuxtools.valgrind.memcheck.tests/src/org/eclipse/linuxtools/internal/valgrind/memcheck/tests/MultiProcessTest.java12
9 files changed, 116 insertions, 41 deletions
diff --git a/valgrind/org.eclipse.linuxtools.valgrind.helgrind.tests/src/org/eclipse/linuxtools/internal/valgrind/helgrind/tests/BasicHelgrindTest.java b/valgrind/org.eclipse.linuxtools.valgrind.helgrind.tests/src/org/eclipse/linuxtools/internal/valgrind/helgrind/tests/BasicHelgrindTest.java
index 8def623..10680ac 100644
--- a/valgrind/org.eclipse.linuxtools.valgrind.helgrind.tests/src/org/eclipse/linuxtools/internal/valgrind/helgrind/tests/BasicHelgrindTest.java
+++ b/valgrind/org.eclipse.linuxtools.valgrind.helgrind.tests/src/org/eclipse/linuxtools/internal/valgrind/helgrind/tests/BasicHelgrindTest.java
@@ -11,6 +11,7 @@
package org.eclipse.linuxtools.internal.valgrind.helgrind.tests;
import org.eclipse.debug.core.ILaunchConfiguration;
+import org.eclipse.linuxtools.internal.valgrind.launch.Messages;
import org.eclipse.linuxtools.internal.valgrind.ui.ValgrindUIPlugin;
import org.eclipse.linuxtools.internal.valgrind.ui.ValgrindViewPart;
@@ -33,6 +34,7 @@ public class BasicHelgrindTest extends AbstractHelgrindTest {
doLaunch(config, "testHelgrindGeneric"); //$NON-NLS-1$
ValgrindViewPart view = ValgrindUIPlugin.getDefault().getView();
- assertEquals(3, view.getMessages().length);
+ assertEquals(1, view.getMessages().length);
+ assertEquals(view.getMessages()[0].getText(), Messages.getString("ValgrindOutputView.No_output")); //$NON-NLS-1$
}
}
diff --git a/valgrind/org.eclipse.linuxtools.valgrind.massif.tests/src/org/eclipse/linuxtools/internal/valgrind/massif/tests/AbstractMassifTest.java b/valgrind/org.eclipse.linuxtools.valgrind.massif.tests/src/org/eclipse/linuxtools/internal/valgrind/massif/tests/AbstractMassifTest.java
index cadae21..da3e200 100644
--- a/valgrind/org.eclipse.linuxtools.valgrind.massif.tests/src/org/eclipse/linuxtools/internal/valgrind/massif/tests/AbstractMassifTest.java
+++ b/valgrind/org.eclipse.linuxtools.valgrind.massif.tests/src/org/eclipse/linuxtools/internal/valgrind/massif/tests/AbstractMassifTest.java
@@ -18,6 +18,8 @@ import org.eclipse.jface.text.TextSelection;
import org.eclipse.jface.viewers.ISelection;
import org.eclipse.linuxtools.internal.valgrind.massif.MassifHeapTreeNode;
import org.eclipse.linuxtools.internal.valgrind.massif.MassifPlugin;
+import org.eclipse.linuxtools.internal.valgrind.massif.MassifSnapshot;
+import org.eclipse.linuxtools.internal.valgrind.massif.MassifSnapshot.SnapshotType;
import org.eclipse.linuxtools.internal.valgrind.tests.AbstractValgrindTest;
import org.eclipse.ui.IEditorInput;
import org.eclipse.ui.IEditorPart;
@@ -81,4 +83,37 @@ public abstract class AbstractMassifTest extends AbstractValgrindTest {
}
}
+ /**
+ * Check snapshots contain the expected used bytes.
+ *
+ * @param snapshots MassifSnapshots to check
+ * @param usefulBytesDelta scale of useful bytes
+ * @param extraBytesDelta scale of extra bytes
+ */
+ protected void checkSnapshots(MassifSnapshot[] snapshots, int usefulBytesDelta, int extraBytesDelta){
+ long expectedHeapBytes = 0;
+ long expectedHeapExtraBytes = 0;
+ boolean pastPeakUsage = false;
+
+ for (MassifSnapshot snapshot : snapshots) {
+ if (snapshot.getTime() == 0) {
+ // no need to update expected values
+ } else if (snapshot.getType().compareTo(SnapshotType.PEAK) == 0) {
+ pastPeakUsage = true;
+ // no need to update expected values
+ } else if (!pastPeakUsage) {
+ expectedHeapBytes += usefulBytesDelta;
+ expectedHeapExtraBytes += extraBytesDelta;
+ } else {
+ // past the peak , heap bytes used begin to decrease
+ expectedHeapBytes -= usefulBytesDelta;
+ expectedHeapExtraBytes -= extraBytesDelta;
+ }
+
+ assertEquals(expectedHeapBytes, snapshot.getHeapBytes());
+ assertEquals(expectedHeapExtraBytes, snapshot.getHeapExtra());
+ assertEquals(expectedHeapBytes + expectedHeapExtraBytes, snapshot.getTotal());
+ }
+ }
+
}
diff --git a/valgrind/org.eclipse.linuxtools.valgrind.massif.tests/src/org/eclipse/linuxtools/internal/valgrind/massif/tests/BasicMassifTest.java b/valgrind/org.eclipse.linuxtools.valgrind.massif.tests/src/org/eclipse/linuxtools/internal/valgrind/massif/tests/BasicMassifTest.java
index 58f2fdc..d7652de 100644
--- a/valgrind/org.eclipse.linuxtools.valgrind.massif.tests/src/org/eclipse/linuxtools/internal/valgrind/massif/tests/BasicMassifTest.java
+++ b/valgrind/org.eclipse.linuxtools.valgrind.massif.tests/src/org/eclipse/linuxtools/internal/valgrind/massif/tests/BasicMassifTest.java
@@ -11,6 +11,8 @@
package org.eclipse.linuxtools.internal.valgrind.massif.tests;
import org.eclipse.debug.core.ILaunchConfiguration;
+import org.eclipse.linuxtools.internal.valgrind.massif.MassifSnapshot;
+import org.eclipse.linuxtools.internal.valgrind.massif.MassifSnapshot.SnapshotType;
import org.eclipse.linuxtools.internal.valgrind.massif.MassifViewPart;
import org.eclipse.linuxtools.internal.valgrind.ui.ValgrindUIPlugin;
@@ -33,6 +35,9 @@ public class BasicMassifTest extends AbstractMassifTest {
doLaunch(config, "testNumSnapshots"); //$NON-NLS-1$
MassifViewPart view = (MassifViewPart) ValgrindUIPlugin.getDefault().getView().getDynamicView();
- assertEquals(14, view.getSnapshots().length);
+ MassifSnapshot[] snapshots = view.getSnapshots();
+ assertEquals(14, snapshots.length);
+ checkSnapshots(snapshots , 40, 16);
}
}
+
diff --git a/valgrind/org.eclipse.linuxtools.valgrind.massif.tests/src/org/eclipse/linuxtools/internal/valgrind/massif/tests/ChartTests.java b/valgrind/org.eclipse.linuxtools.valgrind.massif.tests/src/org/eclipse/linuxtools/internal/valgrind/massif/tests/ChartTests.java
index 82f02f4..22b9ccb 100644
--- a/valgrind/org.eclipse.linuxtools.valgrind.massif.tests/src/org/eclipse/linuxtools/internal/valgrind/massif/tests/ChartTests.java
+++ b/valgrind/org.eclipse.linuxtools.valgrind.massif.tests/src/org/eclipse/linuxtools/internal/valgrind/massif/tests/ChartTests.java
@@ -62,7 +62,6 @@ public class ChartTests extends AbstractMassifTest {
IEditorPart part = PlatformUI.getWorkbench().getActiveWorkbenchWindow().getActivePage().getActiveEditor();
assertTrue(part.getTitle().startsWith("Heap Chart - alloctest")); //$NON-NLS-1$
-// assertEquals("Heap Chart - alloctest", part.getTitle()); //$NON-NLS-1$
}
public void testByteScalingKiB() throws Exception {
diff --git a/valgrind/org.eclipse.linuxtools.valgrind.massif.tests/src/org/eclipse/linuxtools/internal/valgrind/massif/tests/ExportWizardTest.java b/valgrind/org.eclipse.linuxtools.valgrind.massif.tests/src/org/eclipse/linuxtools/internal/valgrind/massif/tests/ExportWizardTest.java
index 0a89e7d..661b25c 100644
--- a/valgrind/org.eclipse.linuxtools.valgrind.massif.tests/src/org/eclipse/linuxtools/internal/valgrind/massif/tests/ExportWizardTest.java
+++ b/valgrind/org.eclipse.linuxtools.valgrind.massif.tests/src/org/eclipse/linuxtools/internal/valgrind/massif/tests/ExportWizardTest.java
@@ -44,31 +44,7 @@ public class ExportWizardTest extends AbstractMassifTest {
}
super.tearDown();
}
-
-// public void testExportNoLaunch() throws Exception {
-// Display.getDefault().syncExec(new Runnable() {
-//
-// public void run() {
-// // TODO Auto-generated method stub
-// // No Valgrind launch to export
-// IPath launchPath = ResourcesPlugin.getWorkspace().getRoot().getLocation();
-// launchPath = launchPath.append(".metadata/.plugins/org.eclipse.linuxtools.valgrind.launch"); //$NON-NLS-1$
-// File launchDir = launchPath.toFile();
-// if (launchDir.exists()) {
-// File[] files = launchDir.listFiles();
-// for (int i = 0; i < files.length; ++i) {
-// files[i].delete();
-// }
-// launchDir.delete();
-// }
-// createWizard();
-//
-// assertNotNull(page.getErrorMessage());
-// }
-//
-// });
-// }
-
+
public void testExportBadPath() throws Exception {
ILaunchConfiguration config = createConfiguration(proj.getProject());
ILaunch launch = doLaunch(config, "testExport"); //$NON-NLS-1$
@@ -198,7 +174,6 @@ public class ExportWizardTest extends AbstractMassifTest {
Display.getDefault().syncExec(new Runnable() {
public void run() {
- // TODO Auto-generated method stub
wizard = new ValgrindExportWizard();
wizard.init(PlatformUI.getWorkbench(), null);
diff --git a/valgrind/org.eclipse.linuxtools.valgrind.massif.tests/src/org/eclipse/linuxtools/internal/valgrind/massif/tests/MultiProcessTest.java b/valgrind/org.eclipse.linuxtools.valgrind.massif.tests/src/org/eclipse/linuxtools/internal/valgrind/massif/tests/MultiProcessTest.java
index 6df7e40..1f93e46 100644
--- a/valgrind/org.eclipse.linuxtools.valgrind.massif.tests/src/org/eclipse/linuxtools/internal/valgrind/massif/tests/MultiProcessTest.java
+++ b/valgrind/org.eclipse.linuxtools.valgrind.massif.tests/src/org/eclipse/linuxtools/internal/valgrind/massif/tests/MultiProcessTest.java
@@ -52,7 +52,9 @@ public class MultiProcessTest extends AbstractMassifTest {
MassifViewPart view = (MassifViewPart) ValgrindUIPlugin.getDefault().getView().getDynamicView();
MassifOutput output = view.getOutput();
assertEquals(1, output.getPids().length);
- assertEquals(8, view.getSnapshots().length);
+ MassifSnapshot[] snapshots = view.getSnapshots();
+ assertEquals(8, snapshots.length);
+ checkSnapshots(snapshots, 400, 8);
}
public void testExec() throws Exception {
@@ -73,6 +75,14 @@ public class MultiProcessTest extends AbstractMassifTest {
MassifSnapshot[] snapshots2 = output.getSnapshots(pids[1]);
assertTrue(snapshots2.length == 8 || snapshots2.length == 14);
assertTrue(snapshots1.length != snapshots2.length);
+
+ if (snapshots1.length == 8) {
+ checkSnapshots(snapshots1, 400, 8);
+ checkSnapshots(snapshots2, 40, 16);
+ } else {
+ checkSnapshots(snapshots1, 40, 16);
+ checkSnapshots(snapshots2, 400, 8);
+ }
}
public void testExecPidMenu() throws Exception {
diff --git a/valgrind/org.eclipse.linuxtools.valgrind.memcheck.tests/src/org/eclipse/linuxtools/internal/valgrind/memcheck/tests/AbstractMemcheckTest.java b/valgrind/org.eclipse.linuxtools.valgrind.memcheck.tests/src/org/eclipse/linuxtools/internal/valgrind/memcheck/tests/AbstractMemcheckTest.java
index c344c69..a6e05bd 100644
--- a/valgrind/org.eclipse.linuxtools.valgrind.memcheck.tests/src/org/eclipse/linuxtools/internal/valgrind/memcheck/tests/AbstractMemcheckTest.java
+++ b/valgrind/org.eclipse.linuxtools.valgrind.memcheck.tests/src/org/eclipse/linuxtools/internal/valgrind/memcheck/tests/AbstractMemcheckTest.java
@@ -10,8 +10,10 @@
*******************************************************************************/
package org.eclipse.linuxtools.internal.valgrind.memcheck.tests;
+import org.eclipse.linuxtools.internal.valgrind.core.ValgrindStackFrame;
import org.eclipse.linuxtools.internal.valgrind.memcheck.MemcheckPlugin;
import org.eclipse.linuxtools.internal.valgrind.tests.AbstractValgrindTest;
+import org.eclipse.linuxtools.valgrind.core.IValgrindMessage;
import org.osgi.framework.Bundle;
import org.osgi.framework.FrameworkUtil;
@@ -27,4 +29,50 @@ public abstract class AbstractMemcheckTest extends AbstractValgrindTest {
return MemcheckPlugin.TOOL_ID;
}
+ /**
+ * Check messages appear as expected for the specified test.
+ *
+ * @param messages IValgrindMessage messages
+ * @param testName test name
+ */
+ public void checkTestMessages(IValgrindMessage[] messages, String testName) {
+ assertTrue(messages.length > 0);
+ String lostBytesMsg = "10 bytes in 1 blocks are definitely lost in loss record 1 of 1"; //$NON-NLS-1$
+ String invalidReadMsg = "Invalid read of size 1"; //$NON-NLS-1$
+ String invalidWriteMsg = "Invalid write of size 1"; //$NON-NLS-1$
+
+ for (IValgrindMessage message : messages) {
+ for (IValgrindMessage child : message.getChildren()) {
+ if (child instanceof ValgrindStackFrame) {
+ ValgrindStackFrame stackFrameMsg = (ValgrindStackFrame) child;
+
+ // check expected error messages exist for basicTest (child process in multiProcTest)
+ if (("testNumErrors".equals(testName) || "testExec".equals(testName)) //$NON-NLS-1$ $NON-NLS-2$
+ && "test.c".equals(stackFrameMsg.getFile())) { //$NON-NLS-1$
+ assertTrue(stackFrameMsg.getLine() >= 15);
+ switch (stackFrameMsg.getLine()) {
+ case 15:
+ assertTrue(message.getText().contains(lostBytesMsg));
+ break;
+ case 16:
+ assertTrue(message.getText().contains(invalidReadMsg));
+ break;
+ case 17:
+ assertTrue(message.getText().contains(invalidWriteMsg));
+ break;
+ default:
+ break;
+ }
+ }
+
+ // check expected error messages exist for parent process in multiProcTest
+ if (("testNoExec".equals(testName) || "testExec".equals(testName)) //$NON-NLS-1$ $NON-NLS-2$
+ && "parent.c".equals(stackFrameMsg.getFile())) { //$NON-NLS-1$
+ assertEquals(8, stackFrameMsg.getLine());
+ assertTrue(child.getParent().getText().contains(lostBytesMsg));
+ }
+ }
+ }
+ }
+ }
}
diff --git a/valgrind/org.eclipse.linuxtools.valgrind.memcheck.tests/src/org/eclipse/linuxtools/internal/valgrind/memcheck/tests/BasicMemcheckTest.java b/valgrind/org.eclipse.linuxtools.valgrind.memcheck.tests/src/org/eclipse/linuxtools/internal/valgrind/memcheck/tests/BasicMemcheckTest.java
index db27e10..735807a 100644
--- a/valgrind/org.eclipse.linuxtools.valgrind.memcheck.tests/src/org/eclipse/linuxtools/internal/valgrind/memcheck/tests/BasicMemcheckTest.java
+++ b/valgrind/org.eclipse.linuxtools.valgrind.memcheck.tests/src/org/eclipse/linuxtools/internal/valgrind/memcheck/tests/BasicMemcheckTest.java
@@ -12,7 +12,7 @@ package org.eclipse.linuxtools.internal.valgrind.memcheck.tests;
import org.eclipse.debug.core.ILaunchConfiguration;
import org.eclipse.linuxtools.internal.valgrind.ui.ValgrindUIPlugin;
-import org.eclipse.linuxtools.internal.valgrind.ui.ValgrindViewPart;
+import org.eclipse.linuxtools.valgrind.core.IValgrindMessage;
public class BasicMemcheckTest extends AbstractMemcheckTest {
@@ -31,10 +31,9 @@ public class BasicMemcheckTest extends AbstractMemcheckTest {
public void testNumErrors() throws Exception {
ILaunchConfiguration config = createConfiguration(proj.getProject());
doLaunch(config, "testNumErrors"); //$NON-NLS-1$
-
- ValgrindViewPart view = ValgrindUIPlugin.getDefault().getView();
- assertEquals(3, view.getMessages().length);
- }
-
+ IValgrindMessage[] messages = ValgrindUIPlugin.getDefault().getView().getMessages();
+ assertEquals(3, messages.length);
+ checkTestMessages(messages, "testNumErrors"); //$NON-NLS-1$
+ }
}
diff --git a/valgrind/org.eclipse.linuxtools.valgrind.memcheck.tests/src/org/eclipse/linuxtools/internal/valgrind/memcheck/tests/MultiProcessTest.java b/valgrind/org.eclipse.linuxtools.valgrind.memcheck.tests/src/org/eclipse/linuxtools/internal/valgrind/memcheck/tests/MultiProcessTest.java
index 58d1095..f8617b1 100644
--- a/valgrind/org.eclipse.linuxtools.valgrind.memcheck.tests/src/org/eclipse/linuxtools/internal/valgrind/memcheck/tests/MultiProcessTest.java
+++ b/valgrind/org.eclipse.linuxtools.valgrind.memcheck.tests/src/org/eclipse/linuxtools/internal/valgrind/memcheck/tests/MultiProcessTest.java
@@ -15,7 +15,7 @@ import org.eclipse.debug.core.ILaunchConfiguration;
import org.eclipse.debug.core.ILaunchConfigurationWorkingCopy;
import org.eclipse.linuxtools.internal.valgrind.core.LaunchConfigurationConstants;
import org.eclipse.linuxtools.internal.valgrind.ui.ValgrindUIPlugin;
-import org.eclipse.linuxtools.internal.valgrind.ui.ValgrindViewPart;
+import org.eclipse.linuxtools.valgrind.core.IValgrindMessage;
public class MultiProcessTest extends AbstractMemcheckTest {
ICProject refProj;
@@ -38,8 +38,9 @@ public class MultiProcessTest extends AbstractMemcheckTest {
ILaunchConfiguration config = createConfiguration(proj.getProject());
doLaunch(config, "testNoExec"); //$NON-NLS-1$
- ValgrindViewPart view = ValgrindUIPlugin.getDefault().getView();
- assertEquals(1, view.getMessages().length);
+ IValgrindMessage[] messages = ValgrindUIPlugin.getDefault().getView().getMessages();
+ assertEquals(1, messages.length);
+ checkTestMessages(messages, "testNoExec"); //$NON-NLS-1$
}
public void testExec() throws Exception {
@@ -48,7 +49,8 @@ public class MultiProcessTest extends AbstractMemcheckTest {
config.doSave();
doLaunch(config, "testExec"); //$NON-NLS-1$
- ValgrindViewPart view = ValgrindUIPlugin.getDefault().getView();
- assertEquals(4, view.getMessages().length);
+ IValgrindMessage[] messages = ValgrindUIPlugin.getDefault().getView().getMessages();
+ assertEquals(4, messages.length);
+ checkTestMessages(messages, "testExec"); //$NON-NLS-1$
}
}