1 /*******************************************************************************
2 * Copyright (c) 2013 École Polytechnique de Montréal
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
10 * Geneviève Bastien - Initial implementation
11 *******************************************************************************/
13 package org
.eclipse
.tracecompass
.lttng2
.kernel
.core
.tests
.event
.matchandsync
;
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
;
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
;
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
;
38 * Tests for {@link TcpEventMatching}
40 * @author Geneviève Bastien
42 @SuppressWarnings("nls")
43 public class MatchAndSyncTest
{
46 * Testing the packet matching
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();) {
55 List
<ITmfTrace
> tracearr
= new LinkedList
<>();
59 TmfEventMatching
.registerMatchObject(new TcpEventMatching());
60 TmfEventMatching
.registerMatchObject(new TcpLttngEventMatching());
62 TmfNetworkEventMatching twoTraceMatch
= new TmfNetworkEventMatching(tracearr
);
63 assertTrue(twoTraceMatch
.matchEvents());
65 /* Set method and fields accessible to make sure the counts are ok */
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());
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());
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());
91 } catch (NoSuchMethodException
| SecurityException
| IllegalAccessException
| IllegalArgumentException
| InvocationTargetException
| NoSuchFieldException e
) {