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
.context
;
17 import static org
.junit
.Assert
.assertEquals
;
18 import static org
.junit
.Assert
.assertTrue
;
20 import java
.util
.ArrayList
;
22 import org
.eclipse
.jdt
.annotation
.NonNull
;
23 import org
.eclipse
.tracecompass
.testtraces
.ctf
.CtfTestTrace
;
24 import org
.eclipse
.tracecompass
.tmf
.ctf
.core
.context
.CtfTmfContext
;
25 import org
.eclipse
.tracecompass
.tmf
.ctf
.core
.tests
.shared
.CtfTmfTestTraceUtils
;
26 import org
.eclipse
.tracecompass
.tmf
.ctf
.core
.trace
.CtfTmfTrace
;
27 import org
.junit
.After
;
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 @NonNull CtfTestTrace testTrace
= CtfTestTrace
.KERNEL
;
40 private static final long begin
= 1332170682440133097L; /*
43 private static final long end
= 1332170692664579801L; /* Trace end time */
45 private CtfTmfTrace trace
;
47 private class SeekerThread
extends Thread
{
50 public void setVal(long val
) {
56 * Pre-test initialization
60 trace
= CtfTmfTestTraceUtils
.getTrace(testTrace
);
67 public void tearDown() {
74 * Index all the events in the test trace.
77 public void testIndexing() {
78 CtfTmfContext context
= new CtfTmfContext(trace
);
82 while (trace
.getNext(context
) != null) {
85 assertTrue(count
> 0);
89 * Context fuzzer. Use an amount of contexts greater than the size of the
90 * iterator cache and have them access the trace in parallel.
92 * @throws InterruptedException
96 public void testTooManyContexts() throws InterruptedException
{
97 final int lwcCount
= 101;
98 double increment
= (end
- begin
) / lwcCount
;
99 final ArrayList
<Long
> vals
= new ArrayList
<>();
100 final ArrayList
<Thread
> threads
= new ArrayList
<>();
103 for (int i
= 0; i
< lwcCount
; i
++) {
104 SeekerThread thread
= new SeekerThread() {
107 CtfTmfContext lwc
= new CtfTmfContext(trace
);
110 synchronized (trace
) {
111 if (lwc
.getCurrentEvent() != null) {
112 vals
.add(lwc
.getCurrentEvent().getTimestamp().getValue());
117 thread
.setVal((long) time
);
123 for (Thread t
: threads
) {
126 assertEquals("seeks done ", lwcCount
, vals
.size());
127 for (long val
: vals
) {
128 assertTrue("val >= begin, " + val
+ " " + begin
, val
>= begin
);
129 assertTrue("val >= end, " + val
+ " " + end
, val
<= end
);
This page took 0.039081 seconds and 5 git commands to generate.