TMF: Synchronize an experiment instead of collection of traces
[deliverable/tracecompass.git] / org.eclipse.tracecompass.lttng2.kernel.core.tests / src / org / eclipse / tracecompass / lttng2 / kernel / core / tests / event / matchandsync / MatchAndSyncTest.java
1 /*******************************************************************************
2 * Copyright (c) 2013 École Polytechnique de Montréal
3 *
4 * All rights reserved. This program and the accompanying materials are made
5 * 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 * Geneviève Bastien - Initial implementation
11 *******************************************************************************/
12
13 package org.eclipse.tracecompass.lttng2.kernel.core.tests.event.matchandsync;
14
15 import static org.junit.Assert.assertEquals;
16 import static org.junit.Assert.assertTrue;
17 import static org.junit.Assert.fail;
18 import static org.junit.Assume.assumeTrue;
19
20 import java.lang.reflect.Field;
21 import java.lang.reflect.InvocationTargetException;
22 import java.lang.reflect.Method;
23 import java.util.LinkedList;
24 import java.util.List;
25 import java.util.Map;
26
27 import org.eclipse.tracecompass.lttng2.kernel.core.event.matching.TcpEventMatching;
28 import org.eclipse.tracecompass.lttng2.kernel.core.event.matching.TcpLttngEventMatching;
29 import org.eclipse.tracecompass.tmf.core.event.matching.IMatchProcessingUnit;
30 import org.eclipse.tracecompass.tmf.core.event.matching.TmfEventMatching;
31 import org.eclipse.tracecompass.tmf.core.event.matching.TmfNetworkEventMatching;
32 import org.eclipse.tracecompass.tmf.core.trace.ITmfTrace;
33 import org.eclipse.tracecompass.tmf.ctf.core.tests.shared.CtfTmfTestTrace;
34 import org.eclipse.tracecompass.tmf.ctf.core.trace.CtfTmfTrace;
35 import org.junit.Test;
36
37 /**
38 * Tests for {@link TcpEventMatching}
39 *
40 * @author Geneviève Bastien
41 */
42 @SuppressWarnings("nls")
43 public class MatchAndSyncTest {
44
45 /**
46 * Testing the packet matching
47 */
48 @Test
49 public void testMatching() {
50 assumeTrue(CtfTmfTestTrace.SYNC_SRC.exists());
51 assumeTrue(CtfTmfTestTrace.SYNC_DEST.exists());
52 try (CtfTmfTrace trace1 = CtfTmfTestTrace.SYNC_SRC.getTrace();
53 CtfTmfTrace trace2 = CtfTmfTestTrace.SYNC_DEST.getTrace();) {
54
55 List<ITmfTrace> tracearr = new LinkedList<>();
56 tracearr.add(trace1);
57 tracearr.add(trace2);
58
59 TmfEventMatching.registerMatchObject(new TcpEventMatching());
60 TmfEventMatching.registerMatchObject(new TcpLttngEventMatching());
61
62 TmfNetworkEventMatching twoTraceMatch = new TmfNetworkEventMatching(tracearr);
63 assertTrue(twoTraceMatch.matchEvents());
64
65 /* Set method and fields accessible to make sure the counts are ok */
66 try {
67 /* Verify number of matches */
68 Method method = TmfEventMatching.class.getDeclaredMethod("getProcessingUnit");
69 method.setAccessible(true);
70 IMatchProcessingUnit procUnit = (IMatchProcessingUnit) method.invoke(twoTraceMatch);
71 assertEquals(46, procUnit.countMatches());
72
73 /* Verify unmatched incoming */
74 Field fieldIn = twoTraceMatch.getClass().getDeclaredField("fUnmatchedIn");
75 fieldIn.setAccessible(true);
76 Map<?, ?> unmatched = (Map<?, ?> ) fieldIn.get(twoTraceMatch);
77 Map<?, ?> unmatchedTrace = (Map<?, ?>) unmatched.get(trace1);
78 assertEquals(3, unmatchedTrace.size());
79 unmatchedTrace = (Map<?, ?>) unmatched.get(trace2);
80 assertEquals(2, unmatchedTrace.size());
81
82 /* Verify unmatched outgoing */
83 Field fieldOut = twoTraceMatch.getClass().getDeclaredField("fUnmatchedOut");
84 fieldOut.setAccessible(true);
85 unmatched = (Map<?, ?> ) fieldOut.get(twoTraceMatch);
86 unmatchedTrace = (Map<?, ?>) unmatched.get(trace1);
87 assertEquals(2, unmatchedTrace.size());
88 unmatchedTrace = (Map<?, ?>) unmatched.get(trace2);
89 assertEquals(1, unmatchedTrace.size());
90
91 } catch (NoSuchMethodException | SecurityException | IllegalAccessException | IllegalArgumentException | InvocationTargetException | NoSuchFieldException e) {
92 fail(e.getMessage());
93 }
94
95 }
96 }
97
98 }
This page took 0.0334100000000001 seconds and 5 git commands to generate.