analysis.os: add more complete tests to the CPU usage analysis
authorGeneviève Bastien <gbastien+lttng@versatic.net>
Wed, 10 Feb 2016 21:10:12 +0000 (16:10 -0500)
committerGenevieve Bastien <gbastien+lttng@versatic.net>
Fri, 12 Feb 2016 22:23:48 +0000 (17:23 -0500)
It uses the state system unit test utility methods to allow more
complete testing of the CPU usage analysis resulting state system.

Change-Id: Ic31c7ff94e42c51862a1cafdc77e2d9f053b9c04
Signed-off-by: Geneviève Bastien <gbastien+lttng@versatic.net>
Reviewed-on: https://git.eclipse.org/r/66404
Reviewed-by: Hudson CI
Reviewed-by: Bernd Hufmann <bernd.hufmann@ericsson.com>
Tested-by: Bernd Hufmann <bernd.hufmann@ericsson.com>
analysis/org.eclipse.tracecompass.analysis.os.linux.core.tests/META-INF/MANIFEST.MF
analysis/org.eclipse.tracecompass.analysis.os.linux.core.tests/src/org/eclipse/tracecompass/analysis/os/linux/core/tests/cpuusage/CpuUsageStateProviderTest.java

index 89d0d6cea3b967db92ff268da2a47c22aa595513..f8933b2bef47e168711e1d38a2fa221bd0a710a1 100644 (file)
@@ -17,7 +17,8 @@ Require-Bundle: org.junit;bundle-version="4.0.0",
  org.eclipse.tracecompass.tmf.ctf.core,
  org.eclipse.tracecompass.tmf.ctf.core.tests,
  org.eclipse.core.resources,
- org.eclipse.tracecompass.analysis.timing.core;bundle-version="1.0.0"
+ org.eclipse.tracecompass.analysis.timing.core;bundle-version="1.0.0",
+ org.eclipse.tracecompass.statesystem.core.tests
 Import-Package: com.google.common.collect,
  org.eclipse.tracecompass.testtraces.ctf;version="1.0.0"
 Export-Package: org.eclipse.tracecompass.analysis.os.linux.core.tests,
index 51b4b70d4608ad34392f30877cf873bc5ce7768c..bff9950ebc123077947adf03330cd47b48ad1b01 100644 (file)
@@ -19,20 +19,25 @@ import static org.junit.Assert.assertTrue;
 import static org.junit.Assert.fail;
 
 import java.io.File;
+import java.util.ArrayList;
 import java.util.HashMap;
 import java.util.List;
 import java.util.Map;
 
 import org.eclipse.core.runtime.IPath;
 import org.eclipse.core.runtime.IStatus;
+import org.eclipse.jdt.annotation.NonNull;
 import org.eclipse.tracecompass.analysis.os.linux.core.cpuusage.KernelCpuUsageAnalysis;
 import org.eclipse.tracecompass.analysis.os.linux.core.kernelanalysis.Attributes;
 import org.eclipse.tracecompass.analysis.os.linux.core.kernelanalysis.KernelAnalysisModule;
 import org.eclipse.tracecompass.analysis.os.linux.core.tests.Activator;
 import org.eclipse.tracecompass.statesystem.core.ITmfStateSystem;
 import org.eclipse.tracecompass.statesystem.core.exceptions.AttributeNotFoundException;
-import org.eclipse.tracecompass.statesystem.core.exceptions.StateSystemDisposedException;
 import org.eclipse.tracecompass.statesystem.core.interval.ITmfStateInterval;
+import org.eclipse.tracecompass.statesystem.core.statevalue.ITmfStateValue;
+import org.eclipse.tracecompass.statesystem.core.statevalue.TmfStateValue;
+import org.eclipse.tracecompass.statesystem.core.tests.shared.utils.StateSystemTestUtils;
+import org.eclipse.tracecompass.statesystem.core.tests.shared.utils.StateIntervalStub;
 import org.eclipse.tracecompass.tmf.core.analysis.IAnalysisModule;
 import org.eclipse.tracecompass.tmf.core.event.TmfEvent;
 import org.eclipse.tracecompass.tmf.core.exceptions.TmfTraceException;
@@ -151,44 +156,51 @@ public class CpuUsageStateProviderTest {
                 assertEquals(3, ss.getSubAttributes(cpuQuark, false).size());
             }
 
-            /* Proc 2 on CPU 0 should run from 1 to 20 seconds */
-            int proc2Quark = ss.getQuarkAbsolute(Attributes.CPUS, "0", "2");
-            ITmfStateInterval interval = ss.querySingleState(2L, proc2Quark);
-            assertEquals(1L, interval.getStartTime());
-            assertEquals(19L, interval.getEndTime());
+            /* Test the intervals of proc2 on CPU 0 */
+            List<@NonNull ITmfStateInterval> intervals = new ArrayList<>();
+            intervals.add(new StateIntervalStub(1, 19, TmfStateValue.nullValue()));
+            intervals.add(new StateIntervalStub(20, 25, TmfStateValue.newValueLong(19L)));
+            StateSystemTestUtils.testIntervalForAttributes(ss, intervals, Attributes.CPUS, "0", "2");
+
+            /* Test the intervals of proc 4 CPU 1 */
+            intervals.clear();
+            intervals.add(new StateIntervalStub(1, 4, TmfStateValue.nullValue()));
+            intervals.add(new StateIntervalStub(5, 14, TmfStateValue.newValueLong(3L)));
+            intervals.add(new StateIntervalStub(15, 25, TmfStateValue.newValueLong(8L)));
+            StateSystemTestUtils.testIntervalForAttributes(ss, intervals, Attributes.CPUS, "1", "4");
+
+            /* Test the intervals of proc 3 on both CPUs */
+            intervals.clear();
+            intervals.add(new StateIntervalStub(1, 24, TmfStateValue.nullValue()));
+            intervals.add(new StateIntervalStub(25, 25, TmfStateValue.newValueLong(5L)));
+            StateSystemTestUtils.testIntervalForAttributes(ss, intervals, Attributes.CPUS, "0", "3");
+
+            intervals.clear();
+            intervals.add(new StateIntervalStub(1, 1, TmfStateValue.nullValue()));
+            intervals.add(new StateIntervalStub(2, 9, TmfStateValue.newValueLong(1L)));
+            intervals.add(new StateIntervalStub(10, 25, TmfStateValue.newValueLong(6L)));
+            StateSystemTestUtils.testIntervalForAttributes(ss, intervals, Attributes.CPUS, "1", "3");
 
             /*
              * Query at the end and make sure all processes on all CPU have the
              * expected values
              */
-            List<ITmfStateInterval> state = ss.queryFullState(25L);
-
-            int quark = ss.getQuarkAbsolute("CPUs", "0", "1");
-            assertEquals(0L, state.get(quark).getStateValue().unboxLong());
-
-            quark = ss.getQuarkAbsolute("CPUs", "0", "2");
-            assertEquals(19L, state.get(quark).getStateValue().unboxLong());
-
-            quark = ss.getQuarkAbsolute("CPUs", "0", "3");
-            assertEquals(5L, state.get(quark).getStateValue().unboxLong());
-
-            quark = ss.getQuarkAbsolute("CPUs", "1", "1");
-            assertEquals(5L, state.get(quark).getStateValue().unboxLong());
-
-            quark = ss.getQuarkAbsolute("CPUs", "1", "3");
-            assertEquals(6L, state.get(quark).getStateValue().unboxLong());
-
-            quark = ss.getQuarkAbsolute("CPUs", "1", "4");
-            assertEquals(8L, state.get(quark).getStateValue().unboxLong());
+            Map<@NonNull String @NonNull [], @NonNull ITmfStateValue> map = new HashMap<>();
+            map.put(StateSystemTestUtils.makeAttribute(Attributes.CPUS, "0", "1"), TmfStateValue.newValueLong(0L));
+            map.put(StateSystemTestUtils.makeAttribute(Attributes.CPUS, "0", "2"), TmfStateValue.newValueLong(19L));
+            map.put(StateSystemTestUtils.makeAttribute(Attributes.CPUS, "0", "3"), TmfStateValue.newValueLong(5L));
+            map.put(StateSystemTestUtils.makeAttribute(Attributes.CPUS, "1", "1"), TmfStateValue.newValueLong(5L));
+            map.put(StateSystemTestUtils.makeAttribute(Attributes.CPUS, "1", "3"), TmfStateValue.newValueLong(6L));
+            map.put(StateSystemTestUtils.makeAttribute(Attributes.CPUS, "1", "4"), TmfStateValue.newValueLong(8L));
+            StateSystemTestUtils.testValuesAtTime(ss, 25L, map);
 
-        } catch (AttributeNotFoundException | StateSystemDisposedException e) {
+        } catch (AttributeNotFoundException e) {
             fail(e.getMessage());
         }
     }
 
     /**
-     * Test the
-     * {@link KernelCpuUsageAnalysis#getCpuUsageInRange(long, long)}
+     * Test the {@link KernelCpuUsageAnalysis#getCpuUsageInRange(long, long)}
      * method.
      */
     @Test
This page took 0.029151 seconds and 5 git commands to generate.