Skip to content

Commit

Permalink
callstack.core: Add test for CallStackSeries contains methods
Browse files Browse the repository at this point in the history
[Modified] Add tests for contains method in CallStackSegmentStoreTest

Signed-off-by: Arnaud Fiorini <fiorini.arnaud@gmail.com>
Change-Id: I60300d6add67700b0a2194c2cf7c81fed73d4ebd
Reviewed-on: https://git.eclipse.org/r/c/tracecompass/org.eclipse.tracecompass/+/202561
Tested-by: Trace Compass Bot <tracecompass-bot@eclipse.org>
Tested-by: Matthew Khouzam <matthew.khouzam@ericsson.com>
Reviewed-by: Matthew Khouzam <matthew.khouzam@ericsson.com>
Reviewed-by: Bernd Hufmann <bernd.hufmann@ericsson.com>
  • Loading branch information
arfio authored and bhufmann committed Nov 9, 2023
1 parent 74c143e commit d780d04
Show file tree
Hide file tree
Showing 2 changed files with 149 additions and 0 deletions.
Expand Up @@ -14,11 +14,16 @@
import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertFalse;
import static org.junit.Assert.assertNotNull;
import static org.junit.Assert.assertTrue;

import java.util.ArrayList;
import java.util.Collections;
import java.util.Iterator;
import java.util.List;

import org.eclipse.jdt.annotation.NonNull;
import org.eclipse.tracecompass.analysis.callstack.core.tests.stubs.CallStackAnalysisStub;
import org.eclipse.tracecompass.analysis.callstack.core.tests.stubs.CalledFunctionStub;
import org.eclipse.tracecompass.segmentstore.core.ISegment;
import org.eclipse.tracecompass.segmentstore.core.ISegmentStore;
import org.junit.Test;
Expand Down Expand Up @@ -69,4 +74,63 @@ public void testIntersectingSegmentStore() {
elements = segmentStore.getIntersectingElements(10L, 15L);
assertEquals("Between 10 and 15", 12, Iterables.size(elements));
}

/**
* Test the segment store's contains method with invalid / fake inputs
*/
@Test
public void testContainsSegmentStoreInvalidInput() {
CallStackAnalysisStub module = getModule();
assertNotNull(module);

ISegmentStore<@NonNull ISegment> segmentStore = module.getSegmentStore();
assertNotNull(segmentStore);

// Test wrong input
assertFalse(segmentStore.contains(null));
assertFalse(segmentStore.containsAll(null));
assertTrue(segmentStore.containsAll(Collections.emptyList()));

// Test with fake segments
ISegment fakeSegment = new CalledFunctionStub(0L, 1L);
assertFalse(segmentStore.contains(fakeSegment));
fakeSegment = new CalledFunctionStub(2L, 321321L);
assertFalse(segmentStore.contains(fakeSegment));
fakeSegment = new CalledFunctionStub(-10L, -2L);
assertFalse(segmentStore.contains(fakeSegment));
fakeSegment = new CalledFunctionStub(-10L, 10L);
assertFalse(segmentStore.contains(fakeSegment));
fakeSegment = new CalledFunctionStub(0L, 10L);
assertFalse(segmentStore.contains(fakeSegment));
fakeSegment = new CalledFunctionStub(32137216321L, 10L);
assertFalse(segmentStore.contains(fakeSegment));
fakeSegment = new CalledFunctionStub(32137216321L, 32137216322L);
assertFalse(segmentStore.contains(fakeSegment));
}

/**
* Test the segment store's contains method with correct input
*/
@Test
public void testContainsSegmentStore() {
CallStackAnalysisStub module = getModule();
assertNotNull(module);

ISegmentStore<@NonNull ISegment> segmentStore = module.getSegmentStore();
assertNotNull(segmentStore);

// Test that it contains what it really contains
Iterator<@NonNull ISegment> segmentIterator = segmentStore.iterator();
List<ISegment> segments = new ArrayList<>();
while (segmentIterator.hasNext()) {
ISegment segment = segmentIterator.next();
assertTrue(segmentStore.contains(segment));
segments.add(segment);
assertTrue(segmentStore.containsAll(segments));
}
while (!segments.isEmpty()) {
segments.remove(0);
assertTrue(segmentStore.containsAll(segments));
}
}
}
@@ -0,0 +1,85 @@
/*******************************************************************************
* Copyright (c) 2023 École Polytechnique de Montréal
*
* All rights reserved. This program and the accompanying materials are
* made available under the terms of the Eclipse Public License 2.0 which
* accompanies this distribution, and is available at
* https://www.eclipse.org/legal/epl-2.0/
*
* SPDX-License-Identifier: EPL-2.0
*******************************************************************************/

package org.eclipse.tracecompass.analysis.callstack.core.tests.stubs;

import org.eclipse.jdt.annotation.Nullable;
import org.eclipse.tracecompass.internal.analysis.callstack.core.callgraph.ICalledFunction;

/**
* A Stub for the CalledFunction segment.
*
* @author Arnaud Fiorini
*/
public class CalledFunctionStub implements ICalledFunction {

private static final long serialVersionUID = 1L;
private final long fStart;
private final long fEnd;

/**
* Constructor
*
* @param start
* The start of the segment
* @param end
* The end of the segment
*/
public CalledFunctionStub(long start, long end) {
fStart = start;
fEnd = end;
}

@Override
public String getName() {
return "";
}

@Override
public long getStart() {
return fStart;
}

@Override
public long getEnd() {
return fEnd;
}

@Override
public Object getSymbol() {
return "";
}

@Override
public @Nullable ICalledFunction getParent() {
return null;
}

@Override
public long getSelfTime() {
return fEnd - fStart;
}

@Override
public long getCpuTime() {
return fEnd - fStart;
}

@Override
public int getProcessId() {
return 0;
}

@Override
public int getThreadId() {
return 0;
}
}

0 comments on commit d780d04

Please sign in to comment.