import org.apache.log4j.ConsoleAppender;
import org.apache.log4j.Logger;
import org.apache.log4j.SimpleLayout;
-import org.eclipse.jface.viewers.StructuredSelection;
import org.eclipse.swtbot.eclipse.finder.SWTWorkbenchBot;
-import org.eclipse.swtbot.eclipse.finder.widgets.SWTBotEditor;
import org.eclipse.swtbot.eclipse.finder.widgets.SWTBotView;
-import org.eclipse.swtbot.swt.finder.finders.UIThreadRunnable;
import org.eclipse.swtbot.swt.finder.junit.SWTBotJunit4ClassRunner;
-import org.eclipse.swtbot.swt.finder.results.Result;
import org.eclipse.swtbot.swt.finder.utils.SWTBotPreferences;
-import org.eclipse.swtbot.swt.finder.waits.DefaultCondition;
import org.eclipse.swtbot.swt.finder.widgets.SWTBotTable;
import org.eclipse.swtbot.swt.finder.widgets.SWTBotToolbarButton;
import org.eclipse.swtbot.swt.finder.widgets.SWTBotTree;
import org.eclipse.swtbot.swt.finder.widgets.SWTBotTreeItem;
-import org.eclipse.tracecompass.tmf.core.event.ITmfEvent;
import org.eclipse.tracecompass.tmf.core.signal.TmfSelectionRangeUpdatedSignal;
import org.eclipse.tracecompass.tmf.core.signal.TmfSignalManager;
import org.eclipse.tracecompass.tmf.core.timestamp.TmfNanoTimestamp;
import org.eclipse.tracecompass.tmf.ctf.core.tests.shared.CtfTmfTestTrace;
-import org.eclipse.tracecompass.tmf.ui.editors.TmfEventsEditor;
+import org.eclipse.tracecompass.tmf.ui.swtbot.tests.shared.ConditionHelpers;
import org.eclipse.tracecompass.tmf.ui.swtbot.tests.shared.SWTBotUtils;
import org.eclipse.tracecompass.tmf.ui.views.callstack.CallStackView;
import org.junit.After;
for (int i = 0; i < 10; i++) {
viewBot.toolbarPushButton(SELECT_NEXT_EVENT).click();
currentEventOffset++;
- fBot.waitUntil(new EventsTableSelectionCondition(TIMESTAMPS[currentEventOffset]));
+ fBot.waitUntil(ConditionHelpers.selectionInEventsTable(fBot, TIMESTAMPS[currentEventOffset]));
SWTBotUtils.waitForJobs();
assertArrayEquals(STACK_FRAMES[currentEventOffset], getVisibleStackFrames(viewBot).toArray());
for (int i = 0; i < 2; i++) {
viewBot.toolbarPushButton(SELECT_PREVIOUS_EVENT).click();
currentEventOffset--;
- fBot.waitUntil(new EventsTableSelectionCondition(TIMESTAMPS[currentEventOffset]));
+ fBot.waitUntil(ConditionHelpers.selectionInEventsTable(fBot, TIMESTAMPS[currentEventOffset]));
SWTBotUtils.waitForJobs();
assertArrayEquals(STACK_FRAMES[currentEventOffset], getVisibleStackFrames(viewBot).toArray());
}
SWTBotTable table = fBot.activeEditor().bot().table();
table.setFocus();
TmfSignalManager.dispatchSignal(new TmfSelectionRangeUpdatedSignal(table.widget, new TmfNanoTimestamp(timestamp)));
- fBot.waitUntil(new EventsTableSelectionCondition(timestamp));
- }
-
- /**
- * Wait until the events table selection matches the specified time stamp.
- */
- private static class EventsTableSelectionCondition extends DefaultCondition {
- private long fSelectionTime;
-
- private EventsTableSelectionCondition(long selectionTime) {
- fSelectionTime = selectionTime;
- }
-
- @Override
- public boolean test() throws Exception {
- StructuredSelection eventsTableSelection = getEventsTableSelection();
- if (eventsTableSelection.isEmpty()) {
- return false;
- }
- return ((ITmfEvent) eventsTableSelection.getFirstElement()).getTimestamp().getValue() == fSelectionTime;
- }
-
- @Override
- public String getFailureMessage() {
- return "failed";
- }
-
- private static StructuredSelection getEventsTableSelection() {
- return UIThreadRunnable.syncExec(new Result<StructuredSelection>() {
-
- @Override
- public StructuredSelection run() {
- SWTBotEditor eventsEditor = SWTBotUtils.activeEventsEditor(fBot);
- TmfEventsEditor part = (TmfEventsEditor) eventsEditor.getReference().getPart(false);
- StructuredSelection selection = (StructuredSelection) part.getSelection();
- return selection;
- }
- });
- }
+ fBot.waitUntil(ConditionHelpers.selectionInEventsTable(fBot, timestamp));
}
/**
org.eclipse.tracecompass.tmf.ui,
org.eclipse.tracecompass.tmf.core,
org.eclipse.tracecompass.tmf.core.tests,
+ org.eclipse.tracecompass.tmf.ui.tests,
org.eclipse.swtbot.junit4_x,
org.eclipse.swtbot.swt.finder
Import-Package: com.google.common.collect,
package org.eclipse.tracecompass.tmf.ui.swtbot.tests.shared;
-
import static org.eclipse.swtbot.eclipse.finder.matchers.WidgetMatcherFactory.withPartName;
import java.util.Arrays;
+import org.eclipse.jface.viewers.StructuredSelection;
import org.eclipse.jface.wizard.IWizardContainer;
import org.eclipse.jface.wizard.IWizardPage;
import org.eclipse.jface.wizard.Wizard;
import org.eclipse.osgi.util.NLS;
import org.eclipse.swtbot.eclipse.finder.SWTWorkbenchBot;
+import org.eclipse.swtbot.eclipse.finder.widgets.SWTBotEditor;
import org.eclipse.swtbot.eclipse.finder.widgets.SWTBotView;
import org.eclipse.swtbot.swt.finder.SWTBot;
+import org.eclipse.swtbot.swt.finder.finders.UIThreadRunnable;
+import org.eclipse.swtbot.swt.finder.results.Result;
import org.eclipse.swtbot.swt.finder.utils.TableCollection;
import org.eclipse.swtbot.swt.finder.waits.DefaultCondition;
import org.eclipse.swtbot.swt.finder.waits.ICondition;
import org.eclipse.swtbot.swt.finder.widgets.SWTBotTable;
import org.eclipse.swtbot.swt.finder.widgets.SWTBotTree;
import org.eclipse.swtbot.swt.finder.widgets.SWTBotTreeItem;
+import org.eclipse.tracecompass.tmf.core.event.ITmfEvent;
import org.eclipse.tracecompass.tmf.core.timestamp.TmfTimeRange;
import org.eclipse.tracecompass.tmf.core.trace.TmfTraceManager;
+import org.eclipse.tracecompass.tmf.ui.editors.TmfEventsEditor;
import org.eclipse.ui.IEditorReference;
import org.hamcrest.Matcher;
}
};
}
+
+ private static class EventsTableSelectionCondition extends DefaultCondition {
+ private long fSelectionTime;
+ private SWTWorkbenchBot fBot;
+
+ private EventsTableSelectionCondition(SWTWorkbenchBot bot, long selectionTime) {
+ fBot = bot;
+ fSelectionTime = selectionTime;
+ }
+
+ @Override
+ public boolean test() throws Exception {
+ StructuredSelection eventsTableSelection = getEventsTableSelection();
+ if (eventsTableSelection.isEmpty()) {
+ return false;
+ }
+ return ((ITmfEvent) eventsTableSelection.getFirstElement()).getTimestamp().getValue() == fSelectionTime;
+ }
+
+ @Override
+ public String getFailureMessage() {
+ return "The selection in the table was not an event with timestamp " + fSelectionTime;
+ }
+
+ private StructuredSelection getEventsTableSelection() {
+ return UIThreadRunnable.syncExec(new Result<StructuredSelection>() {
+
+ @Override
+ public StructuredSelection run() {
+ SWTBotEditor eventsEditor = SWTBotUtils.activeEventsEditor(fBot);
+ TmfEventsEditor part = (TmfEventsEditor) eventsEditor.getReference().getPart(false);
+ StructuredSelection selection = (StructuredSelection) part.getSelection();
+ return selection;
+ }
+ });
+ }
+ }
+
+ /**
+ * Wait until the events table selection matches the specified time stamp.
+ *
+ * @param bot
+ * a workbench bot
+ *
+ * @param selectionTime
+ * the selection time
+ * @return ICondition for verification
+ */
+ public static ICondition selectionInEventsTable(final SWTWorkbenchBot bot, long selectionTime) {
+ return new EventsTableSelectionCondition(bot, selectionTime);
+ }
}
MovableColumnEventsEditorTest.class,
SDViewTest.class,
TestTraceOffsetting.class,
- TmfAlignTimeAxisTest.class
-
+ TmfAlignTimeAxisTest.class,
+ TestRefreshTextTrace.class,
+ TestRefreshCustomTextTrace.class,
})
public class AllTests {
}
--- /dev/null
+/*******************************************************************************
+ * Copyright (c) 2015 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
+ *******************************************************************************/
+
+package org.eclipse.tracecompass.tmf.ui.swtbot.tests.viewers.events;
+
+import java.io.File;
+import java.io.FileWriter;
+import java.io.IOException;
+import java.net.URISyntaxException;
+import java.text.SimpleDateFormat;
+import java.util.Date;
+
+import org.eclipse.core.runtime.FileLocator;
+import org.eclipse.core.runtime.IPath;
+import org.eclipse.core.runtime.Path;
+import org.eclipse.swtbot.swt.finder.junit.SWTBotJunit4ClassRunner;
+import org.eclipse.tracecompass.tmf.core.parsers.custom.CustomTxtTraceDefinition;
+import org.eclipse.tracecompass.tmf.core.trace.TmfTraceManager;
+import org.eclipse.tracecompass.tmf.ui.tests.TmfUITestPlugin;
+import org.junit.runner.RunWith;
+import org.osgi.framework.Bundle;
+
+/**
+ * Test refreshing a custom text trace after new content was added.
+ */
+@RunWith(SWTBotJunit4ClassRunner.class)
+public class TestRefreshCustomTextTrace extends TestRefreshTextTrace {
+
+ private static final String TRACE_LOCATION = TmfTraceManager.getTemporaryDirPath() + File.separator + "test.txt";
+ private static final String DEFINITION_PATH = "tracesets" + File.separator + "txt" + File.separator + "testTxtDefinition.xml";
+ private static final String TRACE_TYPE_CUSTOM_TEXT = "custom.txt.trace:Custom Text:testtxt";
+ private static final String TIMESTAMP_FORMAT = "dd/MM/yyyy HH:mm:ss:SSS";
+
+ private static final long SECOND_TO_MILLISECOND = 1000;
+ private static final long SECOND_TO_NANOSECOND = 1000000000;
+
+ private long fNbWrittenEvents = 0;
+
+ @Override
+ protected String createTrace(long nbEvents) throws Exception {
+ createDefinition();
+ writeToTrace(nbEvents, false);
+
+ return TRACE_LOCATION;
+ }
+
+ private static void createDefinition() throws URISyntaxException, IOException {
+ File file = getBundleFile(TmfUITestPlugin.getDefault().getBundle(), new Path(DEFINITION_PATH));
+ CustomTxtTraceDefinition[] definitions = CustomTxtTraceDefinition.loadAll(file.toString());
+ for (CustomTxtTraceDefinition text : definitions) {
+ text.save();
+ }
+ }
+
+ private static File getBundleFile(Bundle bundle, IPath relativePath) throws URISyntaxException, IOException {
+ return new File(FileLocator.toFileURL(FileLocator.find(bundle, relativePath, null)).toURI());
+ }
+
+ @Override
+ protected void appendToTrace(long nbEVents) throws IOException {
+ writeToTrace(nbEVents, true);
+ }
+
+ private void writeToTrace(long nbEVents, boolean append) throws IOException {
+ final File file = new File(TRACE_LOCATION);
+ try (FileWriter writer = new FileWriter(file, append)) {
+ for (int i = 0; i < nbEVents; ++i) {
+ SimpleDateFormat f = new SimpleDateFormat(TIMESTAMP_FORMAT);
+ String eventStr = f.format(new Date(fNbWrittenEvents * SECOND_TO_MILLISECOND)) + " hello world\n";
+ writer.write(eventStr);
+ fNbWrittenEvents++;
+ }
+ }
+ }
+
+ @Override
+ protected long getExpectedEndTimeStamp() {
+ return (fNbWrittenEvents - 1) * SECOND_TO_NANOSECOND;
+ }
+
+ @Override
+ protected String getTraceType() {
+ return TRACE_TYPE_CUSTOM_TEXT;
+ }
+
+ @Override
+ protected long getNbWrittenEvents() {
+ return fNbWrittenEvents;
+ }
+}
--- /dev/null
+/*******************************************************************************
+ * Copyright (c) 2015 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
+ *******************************************************************************/
+
+package org.eclipse.tracecompass.tmf.ui.swtbot.tests.viewers.events;
+
+import java.io.File;
+import java.io.FileWriter;
+import java.io.IOException;
+import java.text.SimpleDateFormat;
+import java.util.Calendar;
+import java.util.Date;
+import java.util.GregorianCalendar;
+
+import org.apache.log4j.Logger;
+import org.apache.log4j.varia.NullAppender;
+import org.eclipse.swtbot.eclipse.finder.SWTWorkbenchBot;
+import org.eclipse.swtbot.eclipse.finder.widgets.SWTBotEditor;
+import org.eclipse.swtbot.swt.finder.junit.SWTBotJunit4ClassRunner;
+import org.eclipse.swtbot.swt.finder.keyboard.Keystrokes;
+import org.eclipse.swtbot.swt.finder.utils.SWTBotPreferences;
+import org.eclipse.swtbot.swt.finder.waits.DefaultCondition;
+import org.eclipse.swtbot.swt.finder.widgets.SWTBotTreeItem;
+import org.eclipse.tracecompass.tmf.core.trace.ITmfTrace;
+import org.eclipse.tracecompass.tmf.core.trace.TmfTraceManager;
+import org.eclipse.tracecompass.tmf.ui.swtbot.tests.shared.ConditionHelpers;
+import org.eclipse.tracecompass.tmf.ui.swtbot.tests.shared.SWTBotUtils;
+import org.junit.After;
+import org.junit.Before;
+import org.junit.BeforeClass;
+import org.junit.Test;
+import org.junit.runner.RunWith;
+
+/**
+ * Test refreshing a text trace after new content was added.
+ */
+@RunWith(SWTBotJunit4ClassRunner.class)
+public class TestRefreshTextTrace {
+
+ private static final String PROJECT_NAME = "Test";
+ private static final String TRACE_TYPE_SYSLOG = "org.eclipse.linuxtools.tmf.tests.stubs.trace.text.testsyslog";
+ private static final String TIMESTAMP_FORMAT = "MMM dd HH:mm:ss";
+
+ private static final long INITIAL_NB_EVENTS = 100;
+ private static final int NEW_EVENTS_PER_REFRESH = 40000;
+ private static final int NB_REFRESH = 3;
+ private static final long SECOND_TO_MILLISECOND = 1000;
+ private static final long MICROSECOND_TO_NANOSECOND = 1000000;
+
+ private static final Calendar CURRENT = Calendar.getInstance();
+ private static final String TRACE_LOCATION = TmfTraceManager.getTemporaryDirPath() + File.separator + "test.txt";
+ private static SWTWorkbenchBot fBot;
+
+ private long fNbWrittenEvents = 0;
+
+ /** Test Class setup */
+ @BeforeClass
+ public static void init() {
+ SWTBotPreferences.KEYBOARD_LAYOUT = "EN_US";
+ SWTBotUtils.failIfUIThread();
+ SWTBotPreferences.TIMEOUT = 20000; /* 20 second timeout */
+ Logger.getRootLogger().addAppender(new NullAppender());
+ fBot = new SWTWorkbenchBot();
+
+ SWTBotUtils.closeView("welcome", fBot);
+
+ SWTBotUtils.switchToTracingPerspective();
+ /* finish waiting for eclipse to load */
+ SWTBotUtils.waitForJobs();
+ }
+
+ /**
+ * Test setup
+ *
+ * @throws Exception on error
+ */
+ @Before
+ public void before() throws Exception {
+ SWTBotUtils.createProject(PROJECT_NAME);
+ SWTBotUtils.openTrace(PROJECT_NAME, createTrace(INITIAL_NB_EVENTS), getTraceType());
+ SWTBotUtils.waitForJobs();
+ }
+
+ /**
+ * Test tear down
+ */
+ @After
+ public void after() {
+ SWTBotUtils.deleteProject(PROJECT_NAME, fBot);
+ }
+
+ /**
+ * Test refreshing a trace after new content was added.
+ *
+ * @throws IOException
+ * on error
+ */
+ @Test
+ public void testRefresh() throws IOException {
+ ITmfTrace activeTrace = TmfTraceManager.getInstance().getActiveTrace();
+
+ fBot.waitUntil(new NumberOfEventsCondition(activeTrace, INITIAL_NB_EVENTS));
+
+ for (int i = 0; i < NB_REFRESH; i++) {
+ appendToTrace(NEW_EVENTS_PER_REFRESH);
+
+ // Refresh
+ SWTBotTreeItem tracesFolder = SWTBotUtils.selectTracesFolder(fBot, PROJECT_NAME);
+ SWTBotTreeItem traceItem = SWTBotUtils.getTraceProjectItem(fBot, tracesFolder, activeTrace.getName());
+ traceItem.contextMenu("Refresh").click();
+
+ // Make sure the refresh is completed
+ fBot.waitUntil(new NumberOfEventsCondition(activeTrace, getNbWrittenEvents()));
+ }
+
+ // Make sure the end of the table matches what we expect
+ goToTableEnd();
+ fBot.waitUntil(ConditionHelpers.selectionInEventsTable(fBot, getExpectedEndTimeStamp()));
+ }
+
+ private static class NumberOfEventsCondition extends DefaultCondition {
+
+ private ITmfTrace fTrace;
+ private long fNbEvents;
+
+ private NumberOfEventsCondition(ITmfTrace trace, long nbEvents) {
+ fTrace = trace;
+ fNbEvents = nbEvents;
+ }
+
+ @Override
+ public boolean test() throws Exception {
+ return fTrace.getNbEvents() == fNbEvents;
+ }
+
+ @Override
+ public String getFailureMessage() {
+ return fTrace.getName() + " did not contain the expected number of " + fNbEvents + " events";
+ }
+ }
+
+ /**
+ * Create a trace with a number of events.
+ *
+ * @param nbEvents
+ * the number of events to generate
+ * @return the path to the created trace
+ * @throws Exception
+ * on error
+ */
+ protected String createTrace(long nbEvents) throws Exception {
+ writeToTrace(nbEvents, false);
+ return TRACE_LOCATION;
+ }
+
+ /**
+ * Append a number of events to the trace.
+ *
+ * @param nbEvents
+ * the number of events to append
+ * @throws IOException
+ * on error
+ */
+ protected void appendToTrace(long nbEvents) throws IOException {
+ writeToTrace(nbEvents, true);
+ }
+
+ private void writeToTrace(long nbEvents, boolean append) throws IOException {
+ final File file = new File(TRACE_LOCATION);
+ try (FileWriter writer = new FileWriter(file, append)) {
+ for (int i = 0; i < nbEvents; ++i) {
+ writeEvent(writer);
+ }
+ }
+ }
+
+ private void writeEvent(FileWriter fw) throws IOException {
+ SimpleDateFormat f = new SimpleDateFormat(TIMESTAMP_FORMAT);
+ String timeStampStr = f.format(new Date(fNbWrittenEvents * SECOND_TO_MILLISECOND));
+ fw.write(timeStampStr + " HostF LoggerF: SourceFileF:9 Message F\n");
+ fNbWrittenEvents++;
+ }
+
+ /**
+ * Get the trace type for the test.
+ *
+ * @return the trace type
+ */
+ protected String getTraceType() {
+ return TRACE_TYPE_SYSLOG;
+ }
+
+ /**
+ * Get the expected time in nanosecs at the end of the trace, after
+ * refreshing.
+ *
+ * @return the expected time in nanosecs at the end of the trace
+ */
+ protected long getExpectedEndTimeStamp() {
+ Date date = new Date((fNbWrittenEvents - 1) * SECOND_TO_MILLISECOND);
+ // Syslog fills in the year when parsing so we have to do it for the
+ // expected time stamp as well
+ GregorianCalendar calendar = new GregorianCalendar();
+ calendar.setTime(date);
+ calendar.set(Calendar.YEAR, CURRENT.get(Calendar.YEAR));
+ if (calendar.after(CURRENT)) {
+ calendar.set(Calendar.YEAR, CURRENT.get(Calendar.YEAR) - 1);
+ }
+ return calendar.getTimeInMillis() * MICROSECOND_TO_NANOSECOND;
+ }
+
+ private static void goToTableEnd() {
+ SWTBotEditor eventsEditor = SWTBotUtils.activeEventsEditor(fBot);
+ eventsEditor.setFocus();
+ eventsEditor.bot().table().pressShortcut(Keystrokes.END);
+ }
+
+ /**
+ * Get the number of events written so far.
+ *
+ * @return the number of events written so far
+ */
+ protected long getNbWrittenEvents() {
+ return fNbWrittenEvents;
+ }
+}
.,\
plugin.properties,\
plugin.xml,\
- about.html
+ about.html,\
+ tracesets/txt/testTxtDefinition.xml
src.includes = about.html
additional.bundles = org.eclipse.jdt.annotation
jars.extra.classpath = platform:/plugin/org.eclipse.jdt.annotation