1 /*******************************************************************************
2 * Copyright (c) 2012, 2014 Ericsson
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
10 * Matthew Khouzam - Initial implementation
11 * Alexandre Montplaisir
12 * Patrick Tasse - Updated for removal of context clone
13 *******************************************************************************/
15 package org
.eclipse
.tracecompass
.tmf
.ctf
.core
.tests
;
17 import static org
.junit
.Assert
.assertTrue
;
18 import static org
.junit
.Assume
.assumeTrue
;
20 import java
.util
.ArrayList
;
22 import org
.eclipse
.core
.resources
.IResource
;
23 import org
.eclipse
.tracecompass
.tmf
.core
.exceptions
.TmfTraceException
;
24 import org
.eclipse
.tracecompass
.tmf
.ctf
.core
.CtfTmfContext
;
25 import org
.eclipse
.tracecompass
.tmf
.ctf
.core
.CtfTmfEvent
;
26 import org
.eclipse
.tracecompass
.tmf
.ctf
.core
.CtfTmfTrace
;
27 import org
.eclipse
.tracecompass
.tmf
.ctf
.core
.tests
.shared
.CtfTmfTestTrace
;
28 import org
.junit
.Before
;
29 import org
.junit
.Test
;
32 * Tests for the CtfTmfLightweightContext class
34 * @author Matthew Khouzam
37 public class CtfTmfContextTest
{
39 private static final CtfTmfTestTrace testTrace
= CtfTmfTestTrace
.KERNEL
;
40 private static final long begin
= 1332170682440133097L; /* Trace start time */
41 private static final long end
= 1332170692664579801L; /* Trace end time */
43 private CtfTmfTrace trace
;
45 private class SeekerThread
extends Thread
{
48 public void setVal(long val
) {
54 * Pre-test initialization
56 * @throws TmfTraceException
57 * If the trace couldn't be init'ed, which shouldn't happen.
60 public void setUp() throws TmfTraceException
{
61 assumeTrue(testTrace
.exists());
62 trace
= new CtfTmfTrace();
63 String path
= testTrace
.getPath();
64 trace
.initTrace((IResource
) null, path
, CtfTmfEvent
.class);
68 * Index all the events in the test trace.
71 public void testIndexing() {
72 CtfTmfContext context
= new CtfTmfContext(trace
);
76 while (trace
.getNext(context
) != null) {
79 assertTrue(count
> 0);
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.
86 * @throws InterruptedException
90 public void testTooManyContexts() throws InterruptedException
{
91 final int lwcCount
= 101;
92 double increment
= (end
- begin
) / lwcCount
;
93 final ArrayList
<Long
> vals
= new ArrayList
<>();
94 final ArrayList
<Thread
> threads
= new ArrayList
<>();
95 final ArrayList
<CtfTmfContext
> tooManyContexts
= new ArrayList
<>();
97 for (double i
= begin
; i
< end
; i
+= increment
) {
98 SeekerThread thread
= new SeekerThread() {
101 CtfTmfContext lwc
= new CtfTmfContext(trace
);
105 if (lwc
.getCurrentEvent() != null) {
106 vals
.add(lwc
.getCurrentEvent().getTimestamp().getValue());
108 tooManyContexts
.add(lwc
);
112 thread
.setVal((long)i
);
117 for (Thread t
: threads
){
121 for (long val
: vals
){
122 assertTrue(val
>= begin
);
123 assertTrue(val
<= end
);