From 6040f86cb44406001fb18aeb4976b650b129c9c1 Mon Sep 17 00:00:00 2001 From: Alvaro Sanchez-Leon Date: Mon, 31 May 2010 19:24:06 +0000 Subject: [PATCH] --- .../.classpath | 8 + .../.project | 28 +++ .../META-INF/MANIFEST.MF | 12 ++ .../build.properties | 7 + .../plugin.properties | 3 + .../lttng/stubs/LTTngEventParserStub.java | 139 ++++++++++++++ .../lttng/stubs/LTTngTimestampStub.java | 52 ++++++ .../lttng/stubs/LTTngTraceStub.java | 169 ++++++++++++++++++ .../test.xml | 55 ++++++ 9 files changed, 473 insertions(+) create mode 100644 org.eclipse.linuxtools.lttng.ui.tests/.classpath create mode 100644 org.eclipse.linuxtools.lttng.ui.tests/.project create mode 100644 org.eclipse.linuxtools.lttng.ui.tests/META-INF/MANIFEST.MF create mode 100644 org.eclipse.linuxtools.lttng.ui.tests/build.properties create mode 100644 org.eclipse.linuxtools.lttng.ui.tests/plugin.properties create mode 100644 org.eclipse.linuxtools.lttng.ui.tests/stubs/org/eclipse/linuxtools/lttng/stubs/LTTngEventParserStub.java create mode 100644 org.eclipse.linuxtools.lttng.ui.tests/stubs/org/eclipse/linuxtools/lttng/stubs/LTTngTimestampStub.java create mode 100644 org.eclipse.linuxtools.lttng.ui.tests/stubs/org/eclipse/linuxtools/lttng/stubs/LTTngTraceStub.java create mode 100644 org.eclipse.linuxtools.lttng.ui.tests/test.xml diff --git a/org.eclipse.linuxtools.lttng.ui.tests/.classpath b/org.eclipse.linuxtools.lttng.ui.tests/.classpath new file mode 100644 index 0000000000..978c0d27e1 --- /dev/null +++ b/org.eclipse.linuxtools.lttng.ui.tests/.classpath @@ -0,0 +1,8 @@ + + + + + + + + diff --git a/org.eclipse.linuxtools.lttng.ui.tests/.project b/org.eclipse.linuxtools.lttng.ui.tests/.project new file mode 100644 index 0000000000..364e4e5310 --- /dev/null +++ b/org.eclipse.linuxtools.lttng.ui.tests/.project @@ -0,0 +1,28 @@ + + + org.eclipse.linuxtools.lttng.ui.tests + + + + + + org.eclipse.jdt.core.javabuilder + + + + + org.eclipse.pde.ManifestBuilder + + + + + org.eclipse.pde.SchemaBuilder + + + + + + org.eclipse.pde.PluginNature + org.eclipse.jdt.core.javanature + + diff --git a/org.eclipse.linuxtools.lttng.ui.tests/META-INF/MANIFEST.MF b/org.eclipse.linuxtools.lttng.ui.tests/META-INF/MANIFEST.MF new file mode 100644 index 0000000000..bd6d7de636 --- /dev/null +++ b/org.eclipse.linuxtools.lttng.ui.tests/META-INF/MANIFEST.MF @@ -0,0 +1,12 @@ +Manifest-Version: 1.0 +Bundle-ManifestVersion: 2 +Bundle-Name: %Bundle-Name +Bundle-SymbolicName: org.eclipse.linuxtools.lttng.ui.tests +Bundle-Version: 0.2.0.qualifier +Bundle-RequiredExecutionEnvironment: J2SE-1.5 +Bundle-Vendor: %Bundle-Vendor +Require-Bundle: org.junit, + org.eclipse.linuxtools.lttng;bundle-version="0.2.0", + org.eclipse.linuxtools.lttng.ui;bundle-version="0.2.0", + org.eclipse.linuxtools.tmf;bundle-version="0.2.0" +Bundle-Localization: plugin diff --git a/org.eclipse.linuxtools.lttng.ui.tests/build.properties b/org.eclipse.linuxtools.lttng.ui.tests/build.properties new file mode 100644 index 0000000000..0a6de547fd --- /dev/null +++ b/org.eclipse.linuxtools.lttng.ui.tests/build.properties @@ -0,0 +1,7 @@ +source.. = src/,\ + stubs/ +output.. = bin/ +bin.includes = META-INF/,\ + .,\ + plugin.properties,\ + test.xml diff --git a/org.eclipse.linuxtools.lttng.ui.tests/plugin.properties b/org.eclipse.linuxtools.lttng.ui.tests/plugin.properties new file mode 100644 index 0000000000..d5e64e3428 --- /dev/null +++ b/org.eclipse.linuxtools.lttng.ui.tests/plugin.properties @@ -0,0 +1,3 @@ +#Properties file for org.eclipse.linuxtools.lttng.ui.tests +Bundle-Vendor = Eclipse Linux Tools +Bundle-Name = Linux Tracing Toolkit (LTTng) UI Unit Test Suite \ No newline at end of file diff --git a/org.eclipse.linuxtools.lttng.ui.tests/stubs/org/eclipse/linuxtools/lttng/stubs/LTTngEventParserStub.java b/org.eclipse.linuxtools.lttng.ui.tests/stubs/org/eclipse/linuxtools/lttng/stubs/LTTngEventParserStub.java new file mode 100644 index 0000000000..8ad81c3035 --- /dev/null +++ b/org.eclipse.linuxtools.lttng.ui.tests/stubs/org/eclipse/linuxtools/lttng/stubs/LTTngEventParserStub.java @@ -0,0 +1,139 @@ +/******************************************************************************* + * Copyright (c) 2009 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: + * Francois Chouinard - Initial API and implementation + *******************************************************************************/ + +package org.eclipse.linuxtools.lttng.stubs; + +import java.io.IOException; + +import org.eclipse.linuxtools.tmf.event.TmfEvent; +import org.eclipse.linuxtools.tmf.parser.ITmfEventParser; +import org.eclipse.linuxtools.tmf.trace.ITmfTrace; +import org.eclipse.linuxtools.tmf.trace.TmfContext; + +/** + * TmfEventParserStub + *

+ * TODO: Implement me. Please. + */ +public class LTTngEventParserStub implements ITmfEventParser { + + public TmfEvent parseNextEvent(ITmfTrace stream, TmfContext context) + throws IOException { + // TODO Auto-generated method stub + return null; + } + +// // ======================================================================== +// // Attributes +// // ======================================================================== +// +// private final int NB_FORMATS = 10; +// private final TmfEventFormat[] fFormats; +// +// // ======================================================================== +// // Constructors +// // ======================================================================== +// +// public LTTngEventParserStub() { +// fFormats = new TmfEventFormat[NB_FORMATS]; +// for (int i = 0; i < NB_FORMATS; i++) { +// Vector format = new Vector(); +// for (int j = 1; j <= i; j++) { +// format.add(new String("Fmt-" + i + "-Fld-" + j)); +// } +// String[] fields = new String[i]; +// fFormats[i] = new TmfEventFormat(format.toArray(fields)); +// } +// } +// +// // ======================================================================== +// // Accessors +// // ======================================================================== +// +// // ======================================================================== +// // Operators +// // ======================================================================== +// +// /* (non-Javadoc) +// * @see org.eclipse.linuxtools.tmf.eventlog.ITmfEventParser#parseNextEvent() +// */ +// static final String typePrefix = "Type-"; +// public TmfEvent parseNextEvent(ITmfTrace eventStream, TmfTraceContext context) throws IOException { +// +// if (! (eventStream instanceof LTTngTraceStub)) { +// return null; +// } +// +// // Highly inefficient... +// RandomAccessFile stream = ((LTTngTraceStub) eventStream).getStream(); +// String name = eventStream.getName(); +// name = name.substring(name.lastIndexOf('/') + 1); +// +// synchronized(stream) { +// long location = 0; +// if (context != null) +// location = (Long) (context.getLocation()); +// stream.seek(location); +// +// try { +// // Read the individual fields +// long ts = stream.readLong(); +// String source = stream.readUTF(); +// String type = stream.readUTF(); +// @SuppressWarnings("unused") +// int reference = stream.readInt(); +// +// // Read the event parts +// int typeIndex = Integer.parseInt(type.substring(typePrefix.length())); +// String[] fields = new String[typeIndex]; +// for (int i = 0; i < typeIndex; i++) { +// fields[i] = stream.readUTF(); +// } +// +// // Format the content from the individual fields +// String content = "["; +// if (typeIndex > 0) { +// content += fields[0]; +// } +// for (int i = 1; i < typeIndex; i++) { +// content += ", " + fields[i]; +// } +// content += "]"; +// +// // Update the context +// context.setLocation(stream.getFilePointer()); +// context.incrIndex(); +// try { +// long ts2 = stream.readLong(); +// context.setTimestamp(new LTTngTimestampStub(ts2)); +// } catch (EOFException e) { +// context.setTimestamp(null); +// } +// +// // Create the event +// TmfEvent event = new TmfEvent( +// new LTTngTimestampStub(ts), +// new TmfEventSource(source), +// new TmfEventType(type, fFormats[typeIndex]), +// new TmfEventContent(content, fFormats[typeIndex]), +// new TmfEventReference(name)); +// +// return event; +// +// } catch (EOFException e) { +// context.setTimestamp(null); +// } +// } +// return null; +// } + +} \ No newline at end of file diff --git a/org.eclipse.linuxtools.lttng.ui.tests/stubs/org/eclipse/linuxtools/lttng/stubs/LTTngTimestampStub.java b/org.eclipse.linuxtools.lttng.ui.tests/stubs/org/eclipse/linuxtools/lttng/stubs/LTTngTimestampStub.java new file mode 100644 index 0000000000..77cdee6a59 --- /dev/null +++ b/org.eclipse.linuxtools.lttng.ui.tests/stubs/org/eclipse/linuxtools/lttng/stubs/LTTngTimestampStub.java @@ -0,0 +1,52 @@ +/** + * + */ +package org.eclipse.linuxtools.lttng.stubs; + +import org.eclipse.linuxtools.tmf.event.TmfTimestamp; + +/** + * @author francois + * + */ +public class LTTngTimestampStub extends TmfTimestamp { + + /** + * + */ + private static final long serialVersionUID = 216576768443708259L; + + /** + * @param value + * @param scale + * @param precision + */ + public LTTngTimestampStub(long value) { + super(value, (byte) -3, 0); // millisecs + } + + /* (non-Javadoc) + * @see org.eclipse.linuxtools.tmf.event.TmfTimestamp#toString() + */ + @Override + public String toString() { + + // If we are dealing with units of seconds (or higher), + // use the plain formatter + if (fScale >= 0) { + Double value = fValue * Math.pow(10, fScale); + return value.toString(); + } + + // Define a format string + String format = String.format("%%1d.%%0%dd", -fScale); + + // And format the timestamp value + double scale = Math.pow(10, fScale); + long seconds = (long) (fValue * scale); + long fracts = fValue - (long) ((double) seconds / scale); + String result = String.format(format, seconds, fracts); + + return result; + } +} diff --git a/org.eclipse.linuxtools.lttng.ui.tests/stubs/org/eclipse/linuxtools/lttng/stubs/LTTngTraceStub.java b/org.eclipse.linuxtools.lttng.ui.tests/stubs/org/eclipse/linuxtools/lttng/stubs/LTTngTraceStub.java new file mode 100644 index 0000000000..3395776f44 --- /dev/null +++ b/org.eclipse.linuxtools.lttng.ui.tests/stubs/org/eclipse/linuxtools/lttng/stubs/LTTngTraceStub.java @@ -0,0 +1,169 @@ +/******************************************************************************* + * Copyright (c) 2009 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: + * Francois Chouinard (fchouinard@gmail.com) - Initial API and implementation + *******************************************************************************/ + +package org.eclipse.linuxtools.lttng.stubs; + +import java.io.FileNotFoundException; +import java.io.IOException; +import java.io.RandomAccessFile; + +import org.eclipse.linuxtools.lttng.event.LttngEvent; +import org.eclipse.linuxtools.tmf.event.TmfEvent; +import org.eclipse.linuxtools.tmf.parser.ITmfEventParser; +import org.eclipse.linuxtools.tmf.trace.ITmfLocation; +import org.eclipse.linuxtools.tmf.trace.ITmfTrace; +import org.eclipse.linuxtools.tmf.trace.TmfContext; +import org.eclipse.linuxtools.tmf.trace.TmfLocation; +import org.eclipse.linuxtools.tmf.trace.TmfTrace; + +/** + * LTTngTraceStub + *

+ * Dummy test trace. Use in conjunction with LTTngEventParserStub. + */ +public class LTTngTraceStub extends TmfTrace { + + // ======================================================================== + // Attributes + // ======================================================================== + + // The actual stream + private final RandomAccessFile fTrace; + + // The associated event parser + private final ITmfEventParser fParser; + + // ======================================================================== + // Constructors + // ======================================================================== + + /** + * @param filename + * @param parser + * @throws FileNotFoundException + */ + public LTTngTraceStub(String filename) throws FileNotFoundException { + this(filename, DEFAULT_CACHE_SIZE); + } + + /** + * @param filename + * @param parser + * @param cacheSize + * @throws FileNotFoundException + */ + public LTTngTraceStub(String filename, int cacheSize) throws FileNotFoundException { + super(filename, LttngEvent.class, filename, cacheSize); + fTrace = new RandomAccessFile(filename, "r"); + fParser = new LTTngEventParserStub(); + indexTrace(true); + } + + public ITmfTrace createTraceCopy() { + ITmfTrace returnedValue = null; + try { + returnedValue = new LTTngTraceStub(this.getName()); + } + catch (FileNotFoundException e) { + e.printStackTrace(); + } + return returnedValue; + } + + // ======================================================================== + // Accessors + // ======================================================================== + + public RandomAccessFile getStream() { + return fTrace; + } + + // ======================================================================== + // Operators + // ======================================================================== + + /* (non-Javadoc) + * @see org.eclipse.linuxtools.tmf.eventlog.ITmfStreamLocator#seekLocation(java.lang.Object) + */ + @Override + @SuppressWarnings("unchecked") + public TmfContext seekLocation(ITmfLocation location) { + TmfContext context = null; + try { + synchronized(fTrace) { + fTrace.seek((location != null) ? ((TmfLocation) location).getLocation() : 0); + context = new TmfContext(getCurrentLocation(), 0); +// TmfTraceContext context2 = new TmfTraceContext(getCurrentLocation(), 0); +// TmfEvent event = parseEvent(context2); +// context.setTimestamp(event.getTimestamp()); + } + } catch (IOException e) { + // TODO Auto-generated catch block + e.printStackTrace(); + } + return context; + } + + /* (non-Javadoc) + * @see org.eclipse.linuxtools.tmf.eventlog.ITmfStreamLocator#getCurrentLocation() + */ + @Override + public ITmfLocation getCurrentLocation() { + try { + return new TmfLocation(fTrace.getFilePointer()); + } catch (IOException e) { + // TODO Auto-generated catch block + e.printStackTrace(); + } + return null; + } + + /* (non-Javadoc) + * @see org.eclipse.linuxtools.tmf.trace.ITmfTrace#parseEvent() + */ + @Override + public TmfEvent parseEvent(TmfContext context) { + try { + // paserNextEvent updates the context + TmfEvent event = fParser.parseNextEvent(this, context); +// if (event != null) { +// context.setTimestamp(event.getTimestamp()); +// } + return event; + } + catch (IOException e) { + e.printStackTrace(); + } + return null; + } + + /* (non-Javadoc) + * @see java.lang.Object#toString() + */ + @Override + public String toString() { + return "[LTTngTraceStub]"; + } + +// // ======================================================================== +// // Helper functions +// // ======================================================================== +// +// /* (non-Javadoc) +// * @see org.eclipse.linuxtools.tmf.eventlog.ITmfEventStream#getAttributes() +// */ +// public Map getAttributes() { +// // TODO Auto-generated method stub +// return null; +// } + +} \ No newline at end of file diff --git a/org.eclipse.linuxtools.lttng.ui.tests/test.xml b/org.eclipse.linuxtools.lttng.ui.tests/test.xml new file mode 100644 index 0000000000..6023af7c3f --- /dev/null +++ b/org.eclipse.linuxtools.lttng.ui.tests/test.xml @@ -0,0 +1,55 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + -- 2.34.1