Skip to content

Commit

Permalink
Improve tests.
Browse files Browse the repository at this point in the history
  • Loading branch information
boris-spas committed Jul 22, 2021
1 parent 555b2e3 commit e93c930
Show file tree
Hide file tree
Showing 3 changed files with 24 additions and 9 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -150,6 +150,7 @@ public void testCorrectRootStructureRecursive() {
for (int i = 0; i < executionCount; i++) {
eval(defaultRecursiveSourceForSampling);
}
sampler.setCollecting(false);

Collection<ProfilerNode<CPUSampler.Payload>> children = sampler.getRootNodes();
Assert.assertEquals(1, children.size());
Expand Down Expand Up @@ -190,6 +191,7 @@ public void testShadowStackOverflows() {
for (int i = 0; i < executionCount; i++) {
eval(defaultSourceForSampling);
}
sampler.setCollecting(false);
Assert.assertTrue(sampler.hasData());
Assert.assertTrue(sampler.hasStackOverflowed());
}
Expand Down Expand Up @@ -293,6 +295,7 @@ public void run() {
} catch (InterruptedException e) {
Assert.fail("Thread interrupted");
}
sampler.setCollecting(false);
Map<Thread, Collection<ProfilerNode<CPUSampler.Payload>>> threadToNodesMap = sampler.getThreadToNodesMap();
Collection<ProfilerNode<CPUSampler.Payload>> rootNodes = sampler.getRootNodes();
traverseAndCompareForSameSource(rootNodes, threadToNodesMap.get(first), threadToNodesMap.get(second));
Expand Down Expand Up @@ -333,6 +336,7 @@ public void run() {
Thread execThread = new Thread(runnable);
execThread.start();
ensureIterations(iterations, 2);
sampler.setCollecting(false);
Collection<ProfilerNode<CPUSampler.Payload>> oldNodes = sampler.getRootNodes();
try {
// NOTE: Execution is still running in a separate thread.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,10 +24,8 @@
*/
package com.oracle.truffle.tools.profiler.test;

import java.io.IOException;
import java.util.Collection;

import com.oracle.truffle.tools.profiler.CPUSamplerData;
import org.graalvm.polyglot.Context;
import org.graalvm.polyglot.Source;
import org.junit.Assert;
Expand All @@ -43,6 +41,7 @@
import com.oracle.truffle.api.nodes.RootNode;
import com.oracle.truffle.api.test.polyglot.ProxyLanguage;
import com.oracle.truffle.tools.profiler.CPUSampler;
import com.oracle.truffle.tools.profiler.CPUSamplerData;
import com.oracle.truffle.tools.profiler.ProfilerNode;

public class NoTagSamplingTest {
Expand All @@ -52,13 +51,10 @@ public void testNoTagSampling() {
Context context = Context.create(NoTagLanguage.ID);
CPUSampler sampler = CPUSampler.find(context.getEngine());
sampler.setCollecting(true);
try {
Source source = Source.newBuilder(NoTagLanguage.ID, "", "").build();
context.eval(source);
context.eval(source);
} catch (IOException e) {
Assert.fail();
}
Source source = Source.newBuilder(NoTagLanguage.ID, "", "").buildLiteral();
// Eval twice so that we compile on first call when running with compile immediately.
context.eval(source);
context.eval(source);
sampler.setCollecting(false);
final CPUSamplerData data = sampler.getData().values().iterator().next();
final Collection<ProfilerNode<CPUSampler.Payload>> profilerNodes = data.getThreadData().values().iterator().next();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -996,6 +996,21 @@ public void testRootNode() {
Assert.assertFalse(SourceSectionFilter.newBuilder().lineIs(1).columnIn(IndexRange.between(20, 30)).build().includes(rootNode, rootNode.getSourceSection(), null));
}

@Test
public void testRootNodeWithDifferentSourceSection() {
Source source = Source.newBuilder("", "asdf", "").build();
// Source section is "sd"
SourceSection section = source.createSection(1, 2);
SourceSectionRootNode rootNode = new SourceSectionRootNode(Source.newBuilder("","random string\n12312", "").internal(true).build().createSection(2), null);
Assert.assertTrue(SourceSectionFilter.ANY.includes(rootNode, section, null));
Assert.assertTrue(SourceSectionFilter.newBuilder().includeInternal(false).build().includes(rootNode, section, null));
Assert.assertFalse(SourceSectionFilter.newBuilder().includeInternal(false).build().includes(rootNode, rootNode.getSourceSection(), null));
Assert.assertTrue(SourceSectionFilter.newBuilder().lineIs(1).build().includes(rootNode, section, null));
Assert.assertFalse(SourceSectionFilter.newBuilder().lineIs(1).build().includes(rootNode, rootNode.getSourceSection(), null));
Assert.assertTrue(SourceSectionFilter.newBuilder().lineIs(1).columnIn(IndexRange.between(2, 3)).build().includes(rootNode, section, null));
Assert.assertFalse(SourceSectionFilter.newBuilder().lineIs(1).columnIn(IndexRange.between(20, 30)).build().includes(rootNode, section, null));
}

@Test
public void testRootNodeInternal() {
final String characters = "asdf";
Expand Down

0 comments on commit e93c930

Please sign in to comment.