aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorSimon Delisle2013-05-09 11:12:39 (EDT)
committerAlexandre Montplaisir2013-05-23 17:13:45 (EDT)
commitfb8fe6c1a5f167fecf38f2a24c4e4e2bd71daf2b (patch)
treee8c9b97da2bc4ade754eb519dccf5bc7e4031c0f
parent46a40cc428770d378d8300e66b0f2b4a2d18a1fc (diff)
downloadorg.eclipse.linuxtools-fb8fe6c1a5f167fecf38f2a24c4e4e2bd71daf2b.zip
org.eclipse.linuxtools-fb8fe6c1a5f167fecf38f2a24c4e4e2bd71daf2b.tar.gz
org.eclipse.linuxtools-fb8fe6c1a5f167fecf38f2a24c4e4e2bd71daf2b.tar.bz2
Generate trace in IOstructgenTestrefs/changes/80/12680/7
Modification to be able to generate trace Change-Id: I79e5100122f2be137da32625c0973f9418ae42e0 Signed-off-by: Simon Delisle <simon.delisle@ericsson.com> Reviewed-on: https://git.eclipse.org/r/12680 Tested-by: Hudson CI Reviewed-by: Alexandre Montplaisir <alexmonthy@voxpopuli.im> IP-Clean: Alexandre Montplaisir <alexmonthy@voxpopuli.im> Reviewed-by: Matthew Khouzam <matthew.khouzam@ericsson.com> IP-Clean: Matthew Khouzam <matthew.khouzam@ericsson.com> Tested-by: Matthew Khouzam <matthew.khouzam@ericsson.com>
-rw-r--r--lttng/org.eclipse.linuxtools.ctf.core.tests/src/org/eclipse/linuxtools/ctf/core/tests/trace/IOstructgenTest.java165
1 files changed, 132 insertions, 33 deletions
diff --git a/lttng/org.eclipse.linuxtools.ctf.core.tests/src/org/eclipse/linuxtools/ctf/core/tests/trace/IOstructgenTest.java b/lttng/org.eclipse.linuxtools.ctf.core.tests/src/org/eclipse/linuxtools/ctf/core/tests/trace/IOstructgenTest.java
index d64a8e1..25dc04d 100644
--- a/lttng/org.eclipse.linuxtools.ctf.core.tests/src/org/eclipse/linuxtools/ctf/core/tests/trace/IOstructgenTest.java
+++ b/lttng/org.eclipse.linuxtools.ctf.core.tests/src/org/eclipse/linuxtools/ctf/core/tests/trace/IOstructgenTest.java
@@ -7,6 +7,7 @@
*
* Contributors:
* Matthew Khouzam - Initial API and implementation
+ * Simon Delisle - Generate dummy trace
*******************************************************************************/
package org.eclipse.linuxtools.ctf.core.tests.trace;
@@ -17,6 +18,8 @@ import java.io.File;
import java.io.FileOutputStream;
import java.io.FileWriter;
import java.io.IOException;
+import java.nio.ByteBuffer;
+import java.nio.ByteOrder;
import java.util.HashMap;
import org.eclipse.linuxtools.ctf.core.event.IEventDeclaration;
@@ -24,6 +27,7 @@ import org.eclipse.linuxtools.ctf.core.trace.CTFReaderException;
import org.eclipse.linuxtools.ctf.core.trace.CTFTrace;
import org.eclipse.linuxtools.internal.ctf.core.event.EventDeclaration;
import org.eclipse.linuxtools.internal.ctf.core.event.metadata.IOStructGen;
+import org.junit.After;
import org.junit.Test;
/**
@@ -268,7 +272,57 @@ public class IOstructgenTest {
+ ctfStart + ctfHeaders + ctfBody + enumMd + callsiteMD;
static final String tempTraceDir = System.getProperty("java.io.tmpdir")
- + "/" + "tempTrace";
+ + File.separator + "tempTrace";
+
+ private static final int DATA_SIZE = 4096;
+
+ private static final int HEADER_SIZE = 68;
+
+ private static final int PACKET_SIZE = DATA_SIZE + HEADER_SIZE + 512;
+
+ private CTFTrace trace;
+
+ private static class Event {
+ private static final int EVENT_SIZE = 16;
+ private int eventId;
+ private int eventTimestamp;
+ private int eventContent;
+
+ public Event(int id, int content) {
+ eventId = id;
+ eventTimestamp = 0;
+ eventContent = content;
+ }
+
+ public void setEventTimestamp(int eventTimestamp) {
+ this.eventTimestamp = eventTimestamp;
+ }
+
+ public void setEventContent(int eventContent) {
+ this.eventContent = eventContent;
+ }
+
+ public void writeEvent(ByteBuffer data) {
+ // Id and Timestamp
+ int timeId = eventTimestamp << 5;
+ timeId |= eventId & 0x1f;
+ data.putInt(timeId);
+
+ // Context
+ long ip = 0x0000facedecafe00L + ((data.position() /
+ getSize()) & 0x0F);
+ data.putLong(ip);
+
+ // Content
+ data.putInt(eventContent);
+
+ }
+
+ public int getSize() {
+ return EVENT_SIZE;
+ }
+
+ }
private static void deltree(File f) {
for (File elem : f.listFiles()) {
@@ -282,46 +336,92 @@ public class IOstructgenTest {
private static void createDummyTrace(String metadata) {
- File f;
try {
- f = new File(tempTraceDir);
- if (f.exists()) {
- deltree(f);
+ File dir;
+ dir = new File(tempTraceDir);
+ if (dir.exists()) {
+ deltree(dir);
}
- f.mkdirs();
- f = new File(tempTraceDir + "/metadata");
- FileWriter fw = new FileWriter(f);
+ dir.mkdirs();
+ File metadataFile;
+ metadataFile = new File(tempTraceDir + "/metadata");
+ FileWriter fw = new FileWriter(metadataFile);
fw.write(metadata);
fw.close();
- f.createNewFile();
- byte magicLE[] = { (byte) 0xC1, (byte) 0x1F, (byte) 0xFC, (byte) 0xC1 };
- byte uuid[] = { (byte) 0xb0, 0x4d, 0x39, 0x1b, (byte) 0xe7, 0x36,
- 0x44, (byte) 0xc1, (byte) 0x8d, (byte) 0x89, 0x4b,
+ byte magicLE[] = { (byte) 0xC1, (byte) 0x1F, (byte) 0xFC,
+ (byte) 0xC1 };
+ byte uuid[] = { (byte) 0xb0, 0x4d, 0x39, 0x1b, (byte) 0xe7,
+ 0x36, 0x44, (byte) 0xc1, (byte) 0x8d, (byte) 0x89, 0x4b,
(byte) 0xb4, 0x38, (byte) 0x85, 0x7f, (byte) 0x8d };
- final int size = 4096;
- byte[] data = new byte[size];
- for (int i = 0; i < size; i++) {
- data[i] = 0x00;
+
+ Event ev = new Event(2, 2);
+
+ final int nbEvents = (DATA_SIZE / ev.getSize()) - 1;
+ final int contentSize = (nbEvents * ev.getSize() +
+ HEADER_SIZE) * 8;
+
+ ByteBuffer data = ByteBuffer.allocate(PACKET_SIZE);
+ data.order(ByteOrder.LITTLE_ENDIAN);
+ data.clear();
+
+ // packet header
+ // magic number 4
+ data.put(magicLE);
+ // uuid 16
+ data.put(uuid);
+ // stream ID 4
+ data.putInt(0);
+
+ // packet context
+ // timestamp_begin 8
+ data.putLong(0xa500);
+
+ // timestamp_end 8
+ data.putLong(nbEvents * 0x10000 + 0xa5a6);
+
+ // content_size 8
+ data.putLong(contentSize);
+
+ // packet_size 8
+ data.putLong(PACKET_SIZE * 8);
+
+ // events_discarded 8
+ data.putLong(0);
+
+ // cpu_id 4
+ data.putInt(0);
+
+ // fill me
+ for (int i = 0; i < nbEvents; i++) {
+ ev.setEventTimestamp(i * 0x10000 + 0xa5a5);
+ ev.setEventContent(i);
+ ev.writeEvent(data);
}
- f = new File(tempTraceDir + "/dummyChan");
- fw = new FileWriter(f);
- FileOutputStream fos = new FileOutputStream(f);
- fos.write(magicLE);
- fos.write(uuid);
- fos.write(data);
+
+ File dummyFile;
+ dummyFile = new File(tempTraceDir + "/dummyChan");
+ FileOutputStream fos = new FileOutputStream(dummyFile);
+ // The byteBuffer needs to be flipped in file writing mode
+ data.flip();
+ fos.getChannel().write(data);
fos.close();
- fw.close();
- f.createNewFile();
} catch (IOException e) {
e.printStackTrace();
} finally {
- f = null;
}
}
/**
+ * Close trace
+ */
+ @After
+ public void tearDown(){
+ trace.dispose();
+ }
+
+ /**
* Simple test (only the minimum)
*
* @throws CTFReaderException
@@ -330,9 +430,8 @@ public class IOstructgenTest {
@Test
public void TSDLSimpleTest() throws CTFReaderException {
createDummyTrace(simpleTSDL);
- CTFTrace trace = new CTFTrace(tempTraceDir);
+ trace = new CTFTrace(tempTraceDir);
assertNotNull(trace);
-
}
/**
@@ -344,7 +443,7 @@ public class IOstructgenTest {
@Test
public void TSDLEnvironmentTest() throws CTFReaderException {
createDummyTrace(envTSDL);
- CTFTrace trace = new CTFTrace(tempTraceDir);
+ trace = new CTFTrace(tempTraceDir);
assertNotNull(trace);
}
@@ -357,7 +456,7 @@ public class IOstructgenTest {
@Test
public void TSDLEnumTest() throws CTFReaderException {
createDummyTrace(enumTSDL);
- CTFTrace trace = new CTFTrace(tempTraceDir);
+ trace = new CTFTrace(tempTraceDir);
assertNotNull(trace);
}
@@ -370,7 +469,7 @@ public class IOstructgenTest {
@Test
public void TSDLClockTest() throws CTFReaderException {
createDummyTrace(clockTSDL);
- CTFTrace trace = new CTFTrace(tempTraceDir);
+ trace = new CTFTrace(tempTraceDir);
assertNotNull(trace);
}
@@ -383,7 +482,7 @@ public class IOstructgenTest {
@Test
public void TSDLContextTest() throws CTFReaderException {
createDummyTrace(contextTSDL);
- CTFTrace trace = new CTFTrace(tempTraceDir);
+ trace = new CTFTrace(tempTraceDir);
assertNotNull(trace);
}
@@ -396,7 +495,7 @@ public class IOstructgenTest {
@Test
public void TSDLCallsiteTest() throws CTFReaderException {
createDummyTrace(callsiteTSDL);
- CTFTrace trace = new CTFTrace(tempTraceDir);
+ trace = new CTFTrace(tempTraceDir);
assertNotNull(trace);
}
@@ -409,7 +508,7 @@ public class IOstructgenTest {
@Test
public void TSDLAllTest() throws CTFReaderException {
createDummyTrace(allDressedTSDL);
- CTFTrace trace = new CTFTrace(tempTraceDir);
+ trace = new CTFTrace(tempTraceDir);
assertNotNull(trace);
HashMap<Long, IEventDeclaration> events = trace.getEvents(0L);