rcp: Move plugins to their own sub-directory
[deliverable/tracecompass.git] / org.eclipse.tracecompass.tmf.ctf.core.tests / src / org / eclipse / tracecompass / tmf / ctf / core / tests / context / CtfTmfContextTest.java
CommitLineData
53b235e1 1/*******************************************************************************
60ae41e1 2 * Copyright (c) 2012, 2014 Ericsson
53b235e1
MK
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
ea271da6 12 * Patrick Tasse - Updated for removal of context clone
53b235e1
MK
13 *******************************************************************************/
14
9722e5d7 15package org.eclipse.tracecompass.tmf.ctf.core.tests.context;
53b235e1
MK
16
17import static org.junit.Assert.assertTrue;
5dd1fa65 18import static org.junit.Assume.assumeTrue;
53b235e1
MK
19
20import java.util.ArrayList;
21
22import org.eclipse.core.resources.IResource;
2bdf0193 23import org.eclipse.tracecompass.tmf.core.exceptions.TmfTraceException;
9722e5d7
AM
24import org.eclipse.tracecompass.tmf.ctf.core.context.CtfTmfContext;
25import org.eclipse.tracecompass.tmf.ctf.core.event.CtfTmfEvent;
2bdf0193 26import org.eclipse.tracecompass.tmf.ctf.core.tests.shared.CtfTmfTestTrace;
9722e5d7 27import org.eclipse.tracecompass.tmf.ctf.core.trace.CtfTmfTrace;
53b235e1
MK
28import org.junit.Before;
29import org.junit.Test;
30
31/**
32 * Tests for the CtfTmfLightweightContext class
33 *
34 * @author Matthew Khouzam
35 * @version 1.1
36 */
81a2d02e 37public class CtfTmfContextTest {
53b235e1 38
9ac63b5b 39 private static final CtfTmfTestTrace testTrace = CtfTmfTestTrace.KERNEL;
53b235e1
MK
40 private static final long begin = 1332170682440133097L; /* Trace start time */
41 private static final long end = 1332170692664579801L; /* Trace end time */
42
81a2d02e 43 private CtfTmfTrace trace;
53b235e1
MK
44
45 private class SeekerThread extends Thread {
46 long val;
47
48 public void setVal(long val) {
49 this.val = val;
50 }
51 }
52
53 /**
54 * Pre-test initialization
55 *
56 * @throws TmfTraceException
57 * If the trace couldn't be init'ed, which shouldn't happen.
58 */
59 @Before
60 public void setUp() throws TmfTraceException {
9ac63b5b 61 assumeTrue(testTrace.exists());
81a2d02e 62 trace = new CtfTmfTrace();
9ac63b5b 63 String path = testTrace.getPath();
5dd1fa65 64 trace.initTrace((IResource) null, path, CtfTmfEvent.class);
53b235e1
MK
65 }
66
67 /**
68 * Index all the events in the test trace.
69 */
70 @Test
71 public void testIndexing() {
81a2d02e 72 CtfTmfContext context = new CtfTmfContext(trace);
53b235e1
MK
73 context.seek(0);
74
75 int count = 0;
81a2d02e 76 while (trace.getNext(context) != null) {
53b235e1
MK
77 count++;
78 }
79 assertTrue(count > 0);
80 }
81
82 /**
83 * Context fuzzer. Use an amount of contexts greater than the size of the
84 * iterator cache and have them access the trace in parallel.
85 *
53b235e1
MK
86 * @throws InterruptedException
87 * Would fail the test
88 */
89 @Test
54a7a54c 90 public void testTooManyContexts() throws InterruptedException {
53b235e1
MK
91 final int lwcCount = 101;
92 double increment = (end - begin) / lwcCount;
ccf2bbb4
AM
93 final ArrayList<Long> vals = new ArrayList<>();
94 final ArrayList<Thread> threads = new ArrayList<>();
95 final ArrayList<CtfTmfContext> tooManyContexts = new ArrayList<>();
53b235e1
MK
96
97 for (double i = begin; i < end; i += increment) {
98 SeekerThread thread = new SeekerThread() {
99 @Override
100 public void run() {
81a2d02e 101 CtfTmfContext lwc = new CtfTmfContext(trace);
53b235e1 102 lwc.seek(val);
81a2d02e
AM
103 trace.getNext(lwc);
104 synchronized(trace){
132a02b0 105 if (lwc.getCurrentEvent() != null) {
58f3bc52 106 vals.add(lwc.getCurrentEvent().getTimestamp().getValue());
132a02b0 107 }
53b235e1
MK
108 tooManyContexts.add(lwc);
109 }
110 }
111 };
112 thread.setVal((long)i);
113 threads.add(thread);
114 thread.start();
115 }
116
0126a8ca 117 for (Thread t: threads){
53b235e1
MK
118 t.join();
119 }
120
0126a8ca 121 for (long val : vals){
53b235e1
MK
122 assertTrue(val >= begin);
123 assertTrue(val <= end);
124 }
125 }
126}
This page took 0.068526 seconds and 5 git commands to generate.