Commit | Line | Data |
---|---|---|
e73a4ba5 GB |
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 | ||
9bc60be7 | 13 | package org.eclipse.tracecompass.lttng2.kernel.core.tests.event.matchandsync; |
e73a4ba5 GB |
14 | |
15 | import static org.junit.Assert.assertEquals; | |
16 | import static org.junit.Assert.assertTrue; | |
4d2a4a2c | 17 | import static org.junit.Assert.fail; |
75b7c1bc | 18 | import static org.junit.Assume.assumeTrue; |
e73a4ba5 | 19 | |
4d2a4a2c GB |
20 | import java.lang.reflect.Field; |
21 | import java.lang.reflect.InvocationTargetException; | |
22 | import java.lang.reflect.Method; | |
27213c57 AM |
23 | import java.util.LinkedList; |
24 | import java.util.List; | |
4d2a4a2c | 25 | import java.util.Map; |
27213c57 | 26 | |
9bc60be7 AM |
27 | import org.eclipse.tracecompass.lttng2.kernel.core.event.matching.TcpEventMatching; |
28 | import org.eclipse.tracecompass.lttng2.kernel.core.event.matching.TcpLttngEventMatching; | |
4d2a4a2c | 29 | import org.eclipse.tracecompass.tmf.core.event.matching.IMatchProcessingUnit; |
2bdf0193 AM |
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; | |
2bdf0193 | 33 | import org.eclipse.tracecompass.tmf.ctf.core.tests.shared.CtfTmfTestTrace; |
9722e5d7 | 34 | import org.eclipse.tracecompass.tmf.ctf.core.trace.CtfTmfTrace; |
e73a4ba5 GB |
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() { | |
75b7c1bc GB |
50 | assumeTrue(CtfTmfTestTrace.SYNC_SRC.exists()); |
51 | assumeTrue(CtfTmfTestTrace.SYNC_DEST.exists()); | |
090c006e AM |
52 | try (CtfTmfTrace trace1 = CtfTmfTestTrace.SYNC_SRC.getTrace(); |
53 | CtfTmfTrace trace2 = CtfTmfTestTrace.SYNC_DEST.getTrace();) { | |
e73a4ba5 | 54 | |
090c006e AM |
55 | List<ITmfTrace> tracearr = new LinkedList<>(); |
56 | tracearr.add(trace1); | |
57 | tracearr.add(trace2); | |
e73a4ba5 | 58 | |
090c006e AM |
59 | TmfEventMatching.registerMatchObject(new TcpEventMatching()); |
60 | TmfEventMatching.registerMatchObject(new TcpLttngEventMatching()); | |
e73a4ba5 | 61 | |
090c006e AM |
62 | TmfNetworkEventMatching twoTraceMatch = new TmfNetworkEventMatching(tracearr); |
63 | assertTrue(twoTraceMatch.matchEvents()); | |
e73a4ba5 | 64 | |
4d2a4a2c GB |
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 | } | |
75b7c1bc | 94 | |
090c006e | 95 | } |
e73a4ba5 GB |
96 | } |
97 | ||
98 | } |