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
CommitLineData
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 13package org.eclipse.tracecompass.lttng2.kernel.core.tests.event.matchandsync;
e73a4ba5
GB
14
15import static org.junit.Assert.assertEquals;
16import static org.junit.Assert.assertTrue;
4d2a4a2c 17import static org.junit.Assert.fail;
75b7c1bc 18import static org.junit.Assume.assumeTrue;
e73a4ba5 19
4d2a4a2c
GB
20import java.lang.reflect.Field;
21import java.lang.reflect.InvocationTargetException;
22import java.lang.reflect.Method;
27213c57
AM
23import java.util.LinkedList;
24import java.util.List;
4d2a4a2c 25import java.util.Map;
27213c57 26
9bc60be7
AM
27import org.eclipse.tracecompass.lttng2.kernel.core.event.matching.TcpEventMatching;
28import org.eclipse.tracecompass.lttng2.kernel.core.event.matching.TcpLttngEventMatching;
4d2a4a2c 29import org.eclipse.tracecompass.tmf.core.event.matching.IMatchProcessingUnit;
2bdf0193
AM
30import org.eclipse.tracecompass.tmf.core.event.matching.TmfEventMatching;
31import org.eclipse.tracecompass.tmf.core.event.matching.TmfNetworkEventMatching;
32import org.eclipse.tracecompass.tmf.core.trace.ITmfTrace;
2bdf0193 33import org.eclipse.tracecompass.tmf.ctf.core.tests.shared.CtfTmfTestTrace;
9722e5d7 34import org.eclipse.tracecompass.tmf.ctf.core.trace.CtfTmfTrace;
e73a4ba5
GB
35import org.junit.Test;
36
37/**
38 * Tests for {@link TcpEventMatching}
39 *
40 * @author Geneviève Bastien
41 */
42@SuppressWarnings("nls")
43public 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}
This page took 0.048491 seconds and 5 git commands to generate.