1 /*******************************************************************************
2 * Copyright (c) 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 API and implementation
11 *******************************************************************************/
13 package org
.eclipse
.tracecompass
.ctf
.core
.tests
.trace
;
15 import static org
.junit
.Assert
.assertEquals
;
16 import static org
.junit
.Assert
.fail
;
17 import static org
.junit
.Assume
.assumeTrue
;
19 import java
.util
.ArrayList
;
20 import java
.util
.List
;
21 import java
.util
.concurrent
.TimeUnit
;
23 import org
.eclipse
.tracecompass
.ctf
.core
.CTFException
;
24 import org
.eclipse
.tracecompass
.ctf
.core
.CTFStrings
;
25 import org
.eclipse
.tracecompass
.ctf
.core
.event
.EventDefinition
;
26 import org
.eclipse
.tracecompass
.ctf
.core
.event
.types
.IntegerDefinition
;
27 import org
.eclipse
.tracecompass
.ctf
.core
.tests
.shared
.CtfTestTraceUtils
;
28 import org
.eclipse
.tracecompass
.ctf
.core
.trace
.CTFTraceReader
;
29 import org
.eclipse
.tracecompass
.testtraces
.ctf
.CtfTestTrace
;
30 import org
.junit
.Rule
;
31 import org
.junit
.Test
;
32 import org
.junit
.rules
.TestRule
;
33 import org
.junit
.rules
.Timeout
;
34 import org
.junit
.runner
.RunWith
;
35 import org
.junit
.runners
.Parameterized
;
36 import org
.junit
.runners
.Parameterized
.Parameters
;
39 * Read all the traces and verify some metrics. Nominally the event count and
40 * the duration of the trace (not the time to parse it).
42 * @author Matthew Khouzam
44 @RunWith(Parameterized
.class)
45 public class TraceReadAllTracesTest
{
47 /** Time-out tests after 20 seconds. */
49 public TestRule globalTimeout
= new Timeout(20, TimeUnit
.SECONDS
);
52 * Get the list of traces
54 * @return the list of traces
56 @Parameters(name
= "{index}: {0}")
57 public static Iterable
<Object
[]> getTracePaths() {
58 CtfTestTrace
[] values
= CtfTestTrace
.values();
59 List
<Object
[]> list
= new ArrayList
<>();
60 for (CtfTestTrace value
: values
) {
61 list
.add(new Object
[] { value
.name(), value
});
66 private final CtfTestTrace fTraceEnum
;
77 public TraceReadAllTracesTest(String name
, CtfTestTrace traceEnum
) {
78 fTraceEnum
= traceEnum
;
82 * Reads all the traces
85 public void readTraces() {
86 if (fTraceEnum
.getNbEvents() != -1) {
87 try (CTFTraceReader reader
= new CTFTraceReader(CtfTestTraceUtils
.getTrace(fTraceEnum
))) {
88 EventDefinition currentEventDef
= reader
.getCurrentEventDef();
89 double start
= currentEventDef
.getTimestamp();
92 while (reader
.hasMoreEvents()) {
95 currentEventDef
= reader
.getCurrentEventDef();
96 if (currentEventDef
!= null) {
97 end
= currentEventDef
.getTimestamp();
98 if (currentEventDef
.getDeclaration().getName().equals(CTFStrings
.LOST_EVENT_NAME
)) {
99 count
+= ((IntegerDefinition
) currentEventDef
.getFields().getDefinition(CTFStrings
.LOST_EVENTS_FIELD
)).getValue() - 1;
103 assertEquals("Event count", fTraceEnum
.getNbEvents(), count
);
104 assertEquals("Trace duration", fTraceEnum
.getDuration(), (end
- start
) / 1000000000.0, 1.0);
105 } catch (CTFException e
) {
106 fail(fTraceEnum
.name() + " " + e
.getMessage());
109 assumeTrue("Trace did not specify events count", false);