use of org.graalvm.compiler.options.OptionValues in project graal by oracle.
the class DebugContextTest method testInvariantChecking.
/**
* Tests that using a {@link DebugContext} on a thread other than the one on which it was
* created causes an assertion failure.
*/
@Test
public void testInvariantChecking() throws InterruptedException {
Assume.assumeTrue(Assertions.assertionsEnabled());
EconomicMap<OptionKey<?>, Object> map = EconomicMap.create();
// Configure with an option that enables counters
map.put(DebugOptions.Counters, "");
OptionValues options = new OptionValues(map);
DebugContext debug = DebugContext.create(options, DebugHandlersFactory.LOADER);
CounterKey counter = DebugContext.counter("DebugContextTestCounter");
AssertionError[] result = { null };
Thread thread = new Thread() {
@Override
public void run() {
try {
counter.add(debug, 1);
} catch (AssertionError e) {
result[0] = e;
}
}
};
thread.start();
thread.join();
Assert.assertNotNull("Expected thread to throw AssertionError", result[0]);
}
use of org.graalvm.compiler.options.OptionValues in project graal by oracle.
the class DebugContextTest method testLogging.
@Test
public void testLogging() throws IOException {
OptionValues options = new OptionValues(EconomicMap.create());
options = new OptionValues(options, DebugOptions.Log, ":5");
DebugContextSetup setup = new DebugContextSetup();
try (DebugContext debug = setup.openDebugContext(options)) {
for (int level = DebugContext.BASIC_LEVEL; level <= DebugContext.VERY_DETAILED_LEVEL; level++) {
try (DebugContext.Scope s0 = debug.scope("TestLogging")) {
debug.log(level, "log statement at level %d", level);
try (DebugContext.Scope s1 = debug.scope("Level1")) {
debug.log(level, "log statement at level %d", level);
try (DebugContext.Scope s2 = debug.scope("Level2")) {
debug.log(level, "log statement at level %d", level);
try (DebugContext.Scope s3 = debug.scope("Level3")) {
debug.log(level, "log statement at level %d", level);
try (DebugContext.Scope s4 = debug.scope("Level4")) {
debug.log(level, "log statement at level %d", level);
try (DebugContext.Scope s5 = debug.scope("Level5")) {
debug.log(level, "log statement at level %d", level);
}
}
}
}
}
}
}
}
DataInputStream in = new DataInputStream(getClass().getResourceAsStream(getClass().getSimpleName() + ".testLogging.input"));
byte[] buf = new byte[in.available()];
in.readFully(buf);
String threadLabel = "[thread:" + Thread.currentThread().getId() + "]";
String expect = new String(buf).replace("[thread:1]", threadLabel);
String log = setup.logOutput.toString();
Assert.assertEquals(expect, log);
}
use of org.graalvm.compiler.options.OptionValues in project graal by oracle.
the class DebugContextTest method testDumping.
@Test
public void testDumping() {
for (int level = DebugContext.BASIC_LEVEL; level <= DebugContext.VERY_DETAILED_LEVEL; level++) {
OptionValues options = new OptionValues(EconomicMap.create());
options = new OptionValues(options, DebugOptions.Dump, "Scope" + level + ":" + level);
DebugContextSetup setup = new DebugContextSetup();
try (DebugContext debug = setup.openDebugContext(options);
DebugContext.Scope s0 = debug.scope("TestDumping")) {
try (DebugContext.Scope s1 = debug.scope("Scope1")) {
try (DebugContext.Scope s2 = debug.scope("Scope2")) {
try (DebugContext.Scope s3 = debug.scope("Scope3")) {
try (DebugContext.Scope s4 = debug.scope("Scope4")) {
try (DebugContext.Scope s5 = debug.scope("Scope5")) {
debug.dump(level, "an object", "at level %d", level);
}
}
}
}
}
}
String expect = String.format("Dumping an object with label \"at level %d\"%n", level);
String dump = setup.dumpOutput.toString();
Assert.assertEquals(expect, dump);
}
}
use of org.graalvm.compiler.options.OptionValues in project graal by oracle.
the class DebugContextTest method testDisabledSandbox.
@Test
public void testDisabledSandbox() {
EconomicMap<OptionKey<?>, Object> map = EconomicMap.create();
// Configure with an option that enables scopes
map.put(DebugOptions.DumpOnError, true);
OptionValues options = new OptionValues(map);
ByteArrayOutputStream baos = new ByteArrayOutputStream();
DebugContext debug = DebugContext.create(options, NO_DESCRIPTION, NO_GLOBAL_METRIC_VALUES, new PrintStream(baos), DebugHandlersFactory.LOADER);
Exception e = new Exception("testDisabledSandbox");
try {
// Test a disabled sandbox scope
try (DebugContext.Scope d = debug.sandbox("TestExceptionHandling", null)) {
throw e;
} catch (Throwable t) {
assert e == t;
debug.handle(t);
}
} catch (Throwable t) {
// The exception object should propagate all the way out through
// a disabled sandbox scope
Assert.assertEquals(e, t);
}
String logged = baos.toString();
Assert.assertTrue(logged, logged.isEmpty());
}
use of org.graalvm.compiler.options.OptionValues in project graal by oracle.
the class TimerKeyTest method test2.
/**
* Asserts that a timer replied recursively without any other interleaving timers has the same
* flat and accumulated times.
*/
@Test
public void test2() {
EconomicMap<OptionKey<?>, Object> map = EconomicMap.create();
map.put(DebugOptions.Time, "");
OptionValues options = new OptionValues(map);
DebugContext debug = DebugContext.create(options, NO_DESCRIPTION, NO_GLOBAL_METRIC_VALUES, DEFAULT_LOG_STREAM, NO_CONFIG_CUSTOMIZERS);
TimerKey timerC = DebugContext.timer("TimerC");
try (DebugCloseable c1 = timerC.start(debug)) {
spin(50);
try (DebugCloseable c2 = timerC.start(debug)) {
spin(50);
try (DebugCloseable c3 = timerC.start(debug)) {
spin(50);
try (DebugCloseable c4 = timerC.start(debug)) {
spin(50);
try (DebugCloseable c5 = timerC.start(debug)) {
spin(50);
}
}
}
}
}
if (timerC.getFlat() != null) {
assertEquals(timerC.getFlat().getCurrentValue(debug), timerC.getCurrentValue(debug));
}
}
Aggregations