Skip to content
Permalink
Browse files

fix interop tests to pass with Truffle Library

  • Loading branch information...
tstupka committed Mar 18, 2019
1 parent b944dfa commit e08e2b19571479dddb6167d9a1d492a14cb4c7b2
@@ -1,5 +1,5 @@
/*
* Copyright (c) 2016, 2018, Oracle and/or its affiliates. All rights reserved.
* Copyright (c) 2016, 2019, Oracle and/or its affiliates. All rights reserved.
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
*
* This code is free software; you can redistribute it and/or modify it
@@ -34,15 +34,7 @@
@Resolve(message = "IS_BOXED")
public abstract static class ActiveBindingIsBoxedNode extends Node {
protected Object access(@SuppressWarnings("unused") ActiveBinding receiver) {
return true;
}
}

@Resolve(message = "UNBOX")
public abstract static class ActiveBindingUnboxNode extends Node {

protected Object access(ActiveBinding receiver) {
return receiver.readValue();
return false;
}
}

@@ -1,5 +1,5 @@
/*
* Copyright (c) 2014, 2018, Oracle and/or its affiliates. All rights reserved.
* Copyright (c) 2014, 2019, Oracle and/or its affiliates. All rights reserved.
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
*
* This code is free software; you can redistribute it and/or modify it
@@ -243,6 +243,16 @@ public Object access(VariablesObject varMap) {

@TruffleBoundary
protected Object access(VariablesObject receiver, String identifier) {
boolean exists = false;
for (String key : receiver.ls()) {
if (identifier.equals(key)) {
exists = true;
break;
}
}
if (!exists) {
return KeyInfo.INSERTABLE;
}
int result = KeyInfo.READABLE;
if (!receiver.frameAccess.bindingIsLocked(identifier)) {
result |= KeyInfo.MODIFIABLE;
@@ -1,5 +1,5 @@
/*
* Copyright (c) 2017, 2018, Oracle and/or its affiliates. All rights reserved.
* Copyright (c) 2017, 2019, Oracle and/or its affiliates. All rights reserved.
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
*
* This code is free software; you can redistribute it and/or modify it
@@ -39,11 +39,6 @@ public void testIsNull() throws Exception {
super.testIsNull(); // force inherited tests from AbstractMRTest
}

@Override
protected Object getUnboxed(TruffleObject obj) {
return ((ActiveBinding) obj).readValue();
}

@Override
protected TruffleObject[] createTruffleObjects() throws Exception {
Source src = Source.newBuilder("R", "f=function() {}", "<testfunction>").internal(true).buildLiteral();
@@ -75,13 +75,13 @@ private void testKeysRead(String createFun) throws Exception {
assertTrue(ForeignAccess.sendRead(Message.READ.createNode(), l, "n") instanceof RNull);

assertSingletonVector(1, ForeignAccess.sendRead(Message.READ.createNode(), l, 0));
assertSingletonVector(1, ForeignAccess.sendRead(Message.READ.createNode(), l, 0f));
assertSingletonVector(2.1, ForeignAccess.sendRead(Message.READ.createNode(), l, 1));
assertSingletonVector(4d, ForeignAccess.sendRead(Message.READ.createNode(), l, 5d));
assertSingletonVector(true, ForeignAccess.sendRead(Message.READ.createNode(), l, 2));
assertTrue(ForeignAccess.sendRead(Message.READ.createNode(), l, 4) instanceof RNull);

assertInteropException(() -> ForeignAccess.sendRead(Message.READ.createNode(), l, -1), UnknownIdentifierException.class);
assertInteropException(() -> ForeignAccess.sendRead(Message.READ.createNode(), l, 0f), UnknownIdentifierException.class);

assertInteropException(() -> ForeignAccess.sendRead(Message.READ.createNode(), l, "nnnoooonnne"), UnknownIdentifierException.class);
assertInteropException(() -> ForeignAccess.sendRead(Message.READ.createNode(), l, 100), UnknownIdentifierException.class);
@@ -124,7 +124,7 @@ public void testKeysInfo(String createFun) {
assertFalse(KeyInfo.isExisting(info));

info = ForeignAccess.sendKeyInfo(Message.KEY_INFO.createNode(), l, 1f);
assertFalse(KeyInfo.isExisting(info));
assertTrue(KeyInfo.isExisting(info));

info = ForeignAccess.sendKeyInfo(Message.KEY_INFO.createNode(), l, 0);
assertTrue(KeyInfo.isExisting(info));
@@ -51,13 +51,13 @@ protected boolean canRead(@SuppressWarnings("unused") TruffleObject obj) {
public void testReadIdx() throws Exception {
TruffleObject args = createTruffleObjects()[0];

assertInteropException(() -> ForeignAccess.sendRead(Message.READ.createNode(), args, 1f), UnknownIdentifierException.class);
assertInteropException(() -> ForeignAccess.sendRead(Message.READ.createNode(), args, 1d), UnknownIdentifierException.class);
assertInteropException(() -> ForeignAccess.sendRead(Message.READ.createNode(), args, -1), UnknownIdentifierException.class);
assertInteropException(() -> ForeignAccess.sendRead(Message.READ.createNode(), args, 100), UnknownIdentifierException.class);

assertSingletonVector("abc", ForeignAccess.sendRead(Message.READ.createNode(), args, 0));
assertSingletonVector(123, ForeignAccess.sendRead(Message.READ.createNode(), args, 1));
assertSingletonVector(123, ForeignAccess.sendRead(Message.READ.createNode(), args, 1d));
assertSingletonVector(123, ForeignAccess.sendRead(Message.READ.createNode(), args, 1f));
assertSingletonVector(1.1, ForeignAccess.sendRead(Message.READ.createNode(), args, 2));
assertSingletonVector(true, ForeignAccess.sendRead(Message.READ.createNode(), args, 3));
assertTrue(ForeignAccess.sendRead(Message.READ.createNode(), args, 4) instanceof RFunction);
@@ -91,7 +91,7 @@ public void testKeysInfo() throws Exception {
assertFalse(KeyInfo.isExisting(info));

info = ForeignAccess.sendKeyInfo(Message.KEY_INFO.createNode(), e, 1f);
assertFalse(KeyInfo.isExisting(info));
assertTrue(KeyInfo.isExisting(info));

info = ForeignAccess.sendKeyInfo(Message.KEY_INFO.createNode(), e, 0);
assertTrue(KeyInfo.isExisting(info));
@@ -37,8 +37,6 @@
import com.oracle.truffle.r.runtime.env.REnvironment;
import com.oracle.truffle.r.test.generate.FastRSession;
import org.graalvm.polyglot.Source;
import static org.hamcrest.CoreMatchers.instanceOf;
import static org.junit.Assert.assertThat;
import static org.junit.Assert.assertTrue;
import static org.junit.Assert.fail;

@@ -65,20 +63,20 @@ public void testReadWrite() throws Exception {

assertInteropException(() -> ForeignAccess.sendRead(Message.READ.createNode(), e, "nnnoooonnne"), UnknownIdentifierException.class);

TruffleObject obj = (TruffleObject) ForeignAccess.sendWrite(Message.WRITE.createNode(), e, "s", "abc");
Object value = ForeignAccess.sendRead(Message.READ.createNode(), obj, "s");
ForeignAccess.sendWrite(Message.WRITE.createNode(), e, "s", "abc");
Object value = ForeignAccess.sendRead(Message.READ.createNode(), e, "s");
assertSingletonVector("abc", value);

obj = (TruffleObject) ForeignAccess.sendWrite(Message.WRITE.createNode(), e, "b", false);
value = ForeignAccess.sendRead(Message.READ.createNode(), obj, "b");
ForeignAccess.sendWrite(Message.WRITE.createNode(), e, "b", false);
value = ForeignAccess.sendRead(Message.READ.createNode(), e, "b");
assertSingletonVector(false, value);

obj = (TruffleObject) ForeignAccess.sendWrite(Message.WRITE.createNode(), e, "i", (short) 1234);
value = ForeignAccess.sendRead(Message.READ.createNode(), obj, "i");
ForeignAccess.sendWrite(Message.WRITE.createNode(), e, "i", (short) 1234);
value = ForeignAccess.sendRead(Message.READ.createNode(), e, "i");
assertSingletonVector(1234, value);

obj = (TruffleObject) ForeignAccess.sendWrite(Message.WRITE.createNode(), e, "newnew", "nneeww");
value = ForeignAccess.sendRead(Message.READ.createNode(), obj, "newnew");
ForeignAccess.sendWrite(Message.WRITE.createNode(), e, "newnew", "nneeww");
value = ForeignAccess.sendRead(Message.READ.createNode(), e, "newnew");
assertSingletonVector("nneeww", value);

assertInteropException(() -> ForeignAccess.sendWrite(Message.WRITE.createNode(), e, "l", 667), UnsupportedMessageException.class);
@@ -160,13 +158,12 @@ public void testRemove() throws Exception {
public void testReadingNAAndWritingNABackKeepsNA() throws Exception {
final TruffleObject e = createEnv("e <- new.env(); e$i <- 42; e$na <- NA_integer_; e")[0];
Object naInteropValue = ForeignAccess.sendRead(Message.READ.createNode(), e, "na");
Object result = ForeignAccess.sendWrite(Message.WRITE.createNode(), e, "i", naInteropValue);
assertThat(result, instanceOf(REnvironment.class));
assertTrue("index 0 is NA in the updated vector", RRuntime.isNA(getEnvIntValue(result, "i")));
ForeignAccess.sendWrite(Message.WRITE.createNode(), e, "i", naInteropValue);
Object result = ForeignAccess.sendRead(Message.READ.createNode(), e, "i");
assertTrue("index 0 is NA in the updated vector", RRuntime.isNA(getEnvIntValue(result)));
}

private static int getEnvIntValue(Object result, String name) {
Object value = ((REnvironment) result).get(name);
private static int getEnvIntValue(Object value) {
if (value instanceof Integer) {
return (int) value;
} else if (value instanceof RAbstractIntVector) {
@@ -53,7 +53,7 @@ public void testKeysInfo() throws Exception {
assertFalse(KeyInfo.isExisting(info));

info = ForeignAccess.sendKeyInfo(Message.KEY_INFO.createNode(), rl, 1f);
assertFalse(KeyInfo.isExisting(info));
assertTrue(KeyInfo.isExisting(info));

info = ForeignAccess.sendKeyInfo(Message.KEY_INFO.createNode(), rl, rl.getLength());
assertFalse(KeyInfo.isExisting(info));
@@ -87,7 +87,7 @@ public void testRead() throws Exception {
assertInteropException(() -> ForeignAccess.sendRead(Message.READ.createNode(), rl, "nnnoooonnne"), UnknownIdentifierException.class);
assertInteropException(() -> ForeignAccess.sendRead(Message.READ.createNode(), rl, rl.getLength()), UnknownIdentifierException.class);
assertTrue(ForeignAccess.sendRead(Message.READ.createNode(), rl, 0d) == RDataFactory.createSymbolInterned("+"));
assertInteropException(() -> ForeignAccess.sendRead(Message.READ.createNode(), rl, 0f), UnknownIdentifierException.class);
assertTrue(ForeignAccess.sendRead(Message.READ.createNode(), rl, 0f) == RDataFactory.createSymbolInterned("+"));

// TODO add some meaningful read tests
Assert.assertNotNull(ForeignAccess.sendRead(Message.READ.createNode(), rl, 0));
@@ -1,4 +1,4 @@
# Copyright (c) 2013, 2018, Oracle and/or its affiliates. All rights reserved.
# Copyright (c) 2013, 2019, Oracle and/or its affiliates. All rights reserved.
# DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
#
# This code is free software; you can redistribute it and/or modify it
@@ -608,12 +608,12 @@ if(any(R.version$engine == "FastR")) {

checkAllEqual(
actual=as.data.frame(mixedArray),
expected=as.data.frame(list(1, 'a', '1')),
expected=as.data.frame(list(1L, 'a', '1')),
desc='as.data.frame(Object[] {1, "a", "1"})')

checkAllEqual(
actual=as.data.frame(mixed2DArray),
expected=as.data.frame(list(c(1, 2, 3), c('a', 'b', 'c'))),
expected=as.data.frame(list(c(1L, 2L, 3L), c('a', 'b', 'c'))),
desc='as.data.frame(Object[][] {{1, 2, 3}, {"a", "b", "c"}})')

checkError(
@@ -7,7 +7,7 @@
{
"name" : "truffle",
"subdir" : True,
"version" : "c4bb8ed4ab9708486745b69ccb3f9f68a1bbf488",
"version" : "dab657b214eaabb8e44029c97b4397d1addd0689",
"urls" : [
{"url" : "https://github.com/graalvm/graal", "kind" : "git"},
{"url" : "https://curio.ssw.jku.at/nexus/content/repositories/snapshots", "kind" : "binary"},

0 comments on commit e08e2b1

Please sign in to comment.
You can’t perform that action at this time.