From e8f9ac01a6da22f78adfd0736eec66b1283dec75 Mon Sep 17 00:00:00 2001 From: Alexandre Montplaisir Date: Fri, 20 Sep 2013 17:12:25 -0400 Subject: [PATCH] tmf: Add unit tests for lost event statistics Dropped the core.statistics messages file, use the string defined in the CTF plugin for lost event names (it shouldn't really be externalized). Change-Id: I7f6a3ecb7b3be5c7a665a44a8c2882d3bb42419f Signed-off-by: Alexandre Montplaisir Reviewed-on: https://git.eclipse.org/r/16664 Reviewed-by: Marc-Andre Laperle Tested-by: Hudson CI --- .../TmfLostEventStatisticsTest.java | 123 ++++++++++++++++++ .../tests/statistics/TmfStatisticsTest.java | 7 + .../tmf/core/statistics/Messages.java | 35 ----- .../core/statistics/StatsStateProvider.java | 2 +- .../core/statistics/TmfEventsStatistics.java | 4 +- .../tmf/core/statistics/messages.properties | 13 -- 6 files changed, 133 insertions(+), 51 deletions(-) create mode 100644 org.eclipse.linuxtools.tmf.core.tests/src/org/eclipse/linuxtools/tmf/core/tests/statistics/TmfLostEventStatisticsTest.java delete mode 100644 org.eclipse.linuxtools.tmf.core/src/org/eclipse/linuxtools/tmf/core/statistics/Messages.java delete mode 100644 org.eclipse.linuxtools.tmf.core/src/org/eclipse/linuxtools/tmf/core/statistics/messages.properties diff --git a/org.eclipse.linuxtools.tmf.core.tests/src/org/eclipse/linuxtools/tmf/core/tests/statistics/TmfLostEventStatisticsTest.java b/org.eclipse.linuxtools.tmf.core.tests/src/org/eclipse/linuxtools/tmf/core/tests/statistics/TmfLostEventStatisticsTest.java new file mode 100644 index 0000000000..c42668b8d6 --- /dev/null +++ b/org.eclipse.linuxtools.tmf.core.tests/src/org/eclipse/linuxtools/tmf/core/tests/statistics/TmfLostEventStatisticsTest.java @@ -0,0 +1,123 @@ +/******************************************************************************* + * Copyright (c) 2012, 2013 Ericsson + * + * All rights reserved. This program and the accompanying materials are + * made available under the terms of the Eclipse Public License v1.0 which + * accompanies this distribution, and is available at + * http://www.eclipse.org/legal/epl-v10.html + * + * Contributors: + * Alexandre Montplaisir - Initial API and implementation + ******************************************************************************/ + +package org.eclipse.linuxtools.tmf.core.tests.statistics; + +import static org.junit.Assert.assertEquals; +import static org.junit.Assert.fail; +import static org.junit.Assume.assumeTrue; + +import java.io.File; +import java.io.IOException; +import java.util.Map; + +import org.eclipse.linuxtools.ctf.core.CTFStrings; +import org.eclipse.linuxtools.tmf.core.exceptions.TmfTraceException; +import org.eclipse.linuxtools.tmf.core.statistics.ITmfStatistics; +import org.eclipse.linuxtools.tmf.core.statistics.TmfStateStatistics; +import org.eclipse.linuxtools.tmf.core.tests.shared.CtfTmfTestTrace; +import org.junit.BeforeClass; +import org.junit.Rule; +import org.junit.Test; +import org.junit.rules.TestRule; +import org.junit.rules.Timeout; + +/** + * Unit tests for handling of lost events by the statistics backends. + * + * @author Alexandre Montplaisir + */ +public class TmfLostEventStatisticsTest { + + /** Time-out tests after 20 seconds */ + @Rule + public TestRule globalTimeout= new Timeout(20000); + + /**Test trace with lost events */ + private static final CtfTmfTestTrace lostEventsTrace = CtfTmfTestTrace.HELLO_LOST; + + /** The statistics back-end object for the trace with lost events */ + private static ITmfStatistics backend; + + // ------------------------------------------------------------------------ + // Maintenance + // ------------------------------------------------------------------------ + + /** + * Class setup + */ + @BeforeClass + public static void setUpClass() { + try { + assumeTrue(lostEventsTrace.exists()); + File htFile = File.createTempFile("stats-test-lostevents", ".ht"); + backend = new TmfStateStatistics(lostEventsTrace.getTrace(), htFile); + + } catch (IOException e) { + fail(); + } catch (TmfTraceException e) { + fail(); + } + } + + // ------------------------------------------------------------------------ + // Test methods + // ------------------------------------------------------------------------ + + /* + * Trace start = 1376592664828559410 + * Trace end = 1376592665108210547 + */ + + private static final long rangeStart = 1376592664900000000L; + private static final long rangeEnd = 1376592665000000000L; + + /** + * Test the total number of "real" events. Make sure the lost events aren't + * counted in the total. + */ + @Test + public void testLostEventsTotals() { + long realEvents = backend.getEventsTotal(); + assertEquals(32300, realEvents); + } + + /** + * Test the number of real events in a given range. Lost events shouldn't be + * counted. + */ + @Test + public void testLostEventsTotalInRange() { + long realEventsInRange = backend.getEventsInRange(rangeStart, rangeEnd); + assertEquals(11209L, realEventsInRange); + } + + /** + * Test the total number of lost events reported in the trace. + */ + @Test + public void testLostEventsTypes() { + Map events = backend.getEventTypesTotal(); + Long lostEvents = events.get(CTFStrings.LOST_EVENT_NAME); + assertEquals(Long.valueOf(967700L), lostEvents); + } + + /** + * Test the number of lost events reported in a given range. + */ + @Test + public void testLostEventsTypesInRange() { + Map eventsInRange = backend.getEventTypesInRange(rangeStart, rangeEnd); + long lostEventsInRange = eventsInRange.get(CTFStrings.LOST_EVENT_NAME); + assertEquals(363494L, lostEventsInRange); + } +} diff --git a/org.eclipse.linuxtools.tmf.core.tests/src/org/eclipse/linuxtools/tmf/core/tests/statistics/TmfStatisticsTest.java b/org.eclipse.linuxtools.tmf.core.tests/src/org/eclipse/linuxtools/tmf/core/tests/statistics/TmfStatisticsTest.java index 138da80d72..915104c3a0 100644 --- a/org.eclipse.linuxtools.tmf.core.tests/src/org/eclipse/linuxtools/tmf/core/tests/statistics/TmfStatisticsTest.java +++ b/org.eclipse.linuxtools.tmf.core.tests/src/org/eclipse/linuxtools/tmf/core/tests/statistics/TmfStatisticsTest.java @@ -19,7 +19,10 @@ import java.util.Map; import org.eclipse.linuxtools.tmf.core.statistics.ITmfStatistics; import org.eclipse.linuxtools.tmf.core.tests.shared.CtfTmfTestTrace; +import org.junit.Rule; import org.junit.Test; +import org.junit.rules.TestRule; +import org.junit.rules.Timeout; /** * Base unit test class for any type of ITmfStatistics. Sub-classes should @@ -29,6 +32,10 @@ import org.junit.Test; */ public abstract class TmfStatisticsTest { + /** Time-out tests after 20 seconds */ + @Rule + public TestRule globalTimeout= new Timeout(20000); + /** Test trace used for these tests */ protected static final CtfTmfTestTrace testTrace = CtfTmfTestTrace.KERNEL; diff --git a/org.eclipse.linuxtools.tmf.core/src/org/eclipse/linuxtools/tmf/core/statistics/Messages.java b/org.eclipse.linuxtools.tmf.core/src/org/eclipse/linuxtools/tmf/core/statistics/Messages.java deleted file mode 100644 index 5df589f0c5..0000000000 --- a/org.eclipse.linuxtools.tmf.core/src/org/eclipse/linuxtools/tmf/core/statistics/Messages.java +++ /dev/null @@ -1,35 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2013 Ericsson - * - * All rights reserved. This program and the accompanying materials are - * made available under the terms of the Eclipse Public License v1.0 which - * accompanies this distribution, and is available at - * http://www.eclipse.org/legal/epl-v10.html - * - * Contributors: - * Alexandre Montplaisir - Initial API and Implementation - *******************************************************************************/ - -package org.eclipse.linuxtools.tmf.core.statistics; - -import org.eclipse.osgi.util.NLS; - -/** - * Messages file for statistics view strings. - * - * @author Alexandre Montplaisir - * @since 2.2 - */ -public class Messages extends NLS { - - private static final String BUNDLE_NAME = "org.eclipse.linuxtools.tmf.core.statistics.messages"; //$NON-NLS-1$ - - static { - NLS.initializeMessages(BUNDLE_NAME, Messages.class); - } - - private Messages() {} - - /** String for the name "Lost events" (displayed in the Statistics View) */ - public static String LostEventsName; -} diff --git a/org.eclipse.linuxtools.tmf.core/src/org/eclipse/linuxtools/tmf/core/statistics/StatsStateProvider.java b/org.eclipse.linuxtools.tmf.core/src/org/eclipse/linuxtools/tmf/core/statistics/StatsStateProvider.java index 33aeba117f..5f54347f67 100644 --- a/org.eclipse.linuxtools.tmf.core/src/org/eclipse/linuxtools/tmf/core/statistics/StatsStateProvider.java +++ b/org.eclipse.linuxtools.tmf.core/src/org/eclipse/linuxtools/tmf/core/statistics/StatsStateProvider.java @@ -86,7 +86,7 @@ class StatsStateProvider extends AbstractTmfStateProvider { /* Special handling for lost events */ if (event instanceof ITmfLostEvent) { ITmfLostEvent le = (ITmfLostEvent) event; - quark = ss.getQuarkAbsoluteAndAdd(Attributes.EVENT_TYPES, Messages.LostEventsName); + quark = ss.getQuarkAbsoluteAndAdd(Attributes.EVENT_TYPES, eventName); int curVal = ss.queryOngoingState(quark).unboxInt(); if (curVal == -1) { curVal = 0; } diff --git a/org.eclipse.linuxtools.tmf.core/src/org/eclipse/linuxtools/tmf/core/statistics/TmfEventsStatistics.java b/org.eclipse.linuxtools.tmf.core/src/org/eclipse/linuxtools/tmf/core/statistics/TmfEventsStatistics.java index 87a817d273..0e0516fe21 100644 --- a/org.eclipse.linuxtools.tmf.core/src/org/eclipse/linuxtools/tmf/core/statistics/TmfEventsStatistics.java +++ b/org.eclipse.linuxtools.tmf.core/src/org/eclipse/linuxtools/tmf/core/statistics/TmfEventsStatistics.java @@ -265,18 +265,18 @@ public class TmfEventsStatistics implements ITmfStatistics { public void handleData(final ITmfEvent event) { super.handleData(event); if (event != null && event.getTrace() == trace) { + String eventType = event.getType().getName(); /* * Special handling for lost events: instead of counting just * one, we will count how many actual events it represents. */ if (event instanceof ITmfLostEvent) { ITmfLostEvent le = (ITmfLostEvent) event; - incrementStats(Messages.LostEventsName, le.getNbLostEvents()); + incrementStats(eventType, le.getNbLostEvents()); return; } /* For standard event types, just increment by one */ - String eventType = event.getType().getName(); incrementStats(eventType, 1L); } } diff --git a/org.eclipse.linuxtools.tmf.core/src/org/eclipse/linuxtools/tmf/core/statistics/messages.properties b/org.eclipse.linuxtools.tmf.core/src/org/eclipse/linuxtools/tmf/core/statistics/messages.properties deleted file mode 100644 index 263172abfa..0000000000 --- a/org.eclipse.linuxtools.tmf.core/src/org/eclipse/linuxtools/tmf/core/statistics/messages.properties +++ /dev/null @@ -1,13 +0,0 @@ -############################################################################### -# Copyright (c) 2013 Ericsson -# -# All rights reserved. This program and the accompanying materials -# are made available under the terms of the Eclipse Public License v1.0 -# which accompanies this distribution, and is available at -# http://www.eclipse.org/legal/epl-v10.html -# -# Contributors: -# Alexandre Montplaisir - Initial API and implementation -############################################################################### - -LostEventsName = Lost events -- 2.34.1