tmf: Re-enable the unit tests depending on CTF traces
[deliverable/tracecompass.git] / org.eclipse.linuxtools.tmf.core.tests / src / org / eclipse / linuxtools / tmf / core / tests / ctfadaptor / CtfTmfContextTest.java
1 /*******************************************************************************
2 * Copyright (c) 2012 Ericsson
3 *
4 * All rights reserved. This program and the accompanying materials are
5 * made available under the terms of the Eclipse Public License v1.0 which
6 * accompanies this distribution, and is available at
7 * http://www.eclipse.org/legal/epl-v10.html
8 *
9 * Contributors:
10 * Matthew Khouzam - Initial implementation
11 * Alexandre Montplaisir
12 *******************************************************************************/
13
14 package org.eclipse.linuxtools.tmf.core.tests.ctfadaptor;
15
16 import static org.junit.Assert.assertNotSame;
17 import static org.junit.Assert.assertSame;
18 import static org.junit.Assert.assertTrue;
19 import static org.junit.Assume.assumeTrue;
20
21 import java.util.ArrayList;
22
23 import org.eclipse.core.resources.IResource;
24 import org.eclipse.linuxtools.tmf.core.ctfadaptor.CtfTmfContext;
25 import org.eclipse.linuxtools.tmf.core.ctfadaptor.CtfTmfEvent;
26 import org.eclipse.linuxtools.tmf.core.ctfadaptor.CtfTmfTrace;
27 import org.eclipse.linuxtools.tmf.core.exceptions.TmfTraceException;
28 import org.eclipse.linuxtools.tmf.core.tests.shared.CtfTmfTestTraces;
29 import org.junit.Before;
30 import org.junit.Test;
31
32 /**
33 * Tests for the CtfTmfLightweightContext class
34 *
35 * @author Matthew Khouzam
36 * @version 1.1
37 */
38 public class CtfTmfContextTest {
39
40 private static final int TRACE_INDEX = 0;
41 private static final long begin = 1332170682440133097L; /* Trace start time */
42 private static final long end = 1332170692664579801L; /* Trace end time */
43
44 private CtfTmfTrace trace;
45
46 private class SeekerThread extends Thread {
47 long val;
48
49 public void setVal(long val) {
50 this.val = val;
51 }
52 }
53
54 /**
55 * Pre-test initialization
56 *
57 * @throws TmfTraceException
58 * If the trace couldn't be init'ed, which shouldn't happen.
59 */
60 @Before
61 public void setUp() throws TmfTraceException {
62 assumeTrue(CtfTmfTestTraces.tracesExist());
63 trace = new CtfTmfTrace();
64 String path = CtfTmfTestTraces.getTestTracePath(TRACE_INDEX);
65 trace.initTrace((IResource) null, path, CtfTmfEvent.class);
66 }
67
68 /**
69 * Index all the events in the test trace.
70 */
71 @Test
72 public void testIndexing() {
73 CtfTmfContext context = new CtfTmfContext(trace);
74 context.seek(0);
75
76 int count = 0;
77 while (trace.getNext(context) != null) {
78 count++;
79 }
80 assertTrue(count > 0);
81 }
82
83 /**
84 * Context fuzzer. Use an amount of contexts greater than the size of the
85 * iterator cache and have them access the trace in parallel.
86 *
87 * @throws InterruptedException
88 * Would fail the test
89 */
90 @Test
91 public void testTooManyContexts() throws InterruptedException {
92 final int lwcCount = 101;
93 double increment = (end - begin) / lwcCount;
94 final ArrayList<Long> vals = new ArrayList<Long>();
95 final ArrayList<Thread> threads = new ArrayList<Thread>();
96 final ArrayList<CtfTmfContext> tooManyContexts = new ArrayList<CtfTmfContext>();
97
98 for (double i = begin; i < end; i += increment) {
99 SeekerThread thread = new SeekerThread() {
100 @Override
101 public void run() {
102 CtfTmfContext lwc = new CtfTmfContext(trace);
103 lwc.seek(val);
104 trace.getNext(lwc);
105 synchronized(trace){
106 if (lwc.getCurrentEvent() != null) {
107 vals.add(lwc.getCurrentEvent().getTimestamp().getValue());
108 }
109 tooManyContexts.add(lwc);
110 }
111 }
112 };
113 thread.setVal((long)i);
114 threads.add(thread);
115 thread.start();
116 }
117
118 for( Thread t: threads){
119 t.join();
120 }
121
122 for( Long val : vals){
123 assertTrue(val >= begin);
124 assertTrue(val <= end);
125 }
126 }
127
128 /**
129 * Test for clone method
130 */
131 @Test
132 public void testClone() {
133 CtfTmfContext fixture1 = new CtfTmfContext(trace);
134 CtfTmfContext fixture2 = fixture1.clone();
135 //assertTrue(fixture1.equals(fixture2)); FIXME no .equals() override!
136 assertNotSame(fixture1, fixture2);
137
138 /* Make sure clone() did its job */
139 assertSame(fixture1.getTrace(), fixture2.getTrace());
140 assertSame(fixture1.getLocation(), fixture2.getLocation());
141 assertSame(fixture1.getRank(), fixture2.getRank());
142 }
143 }
This page took 0.032658 seconds and 5 git commands to generate.