From e78eca17dc1708046925bae9ca9096a15c81daeb Mon Sep 17 00:00:00 2001
From: Mick Jordan <mick.jordan@oracle.com>
Date: Mon, 28 Nov 2016 18:14:35 -0800
Subject: [PATCH] =?UTF-8?q?refactor=20TestRFFIPackage,=20add=20more=20test?=
 =?UTF-8?q?s;=20(pessimally)=20fix=20=E2=80=9Ccomplete=E2=80=9D=20status?=
 =?UTF-8?q?=20of=20vectors=20updated=20in=20RFFI?=
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: 8bit

---
 .../fficall/src/jni/Rinternals.c              |   4 +
 .../fficall/src/jni/rffiutils.c               |  26 ++-
 .../fficall/src/jni/rffiutils.h               |   1 +
 .../r/runtime/ffi/jni/CallRFFIHelper.java     |  12 ++
 .../truffle/r/test/ExpectedTestOutput.test    |  87 ++++++----
 .../truffle/r/test/rffi/TestRFFIPackage.java  | 148 ++++++++++++++++++
 .../r/test/rpackages/TestRFFIPackage.java     |  92 -----------
 7 files changed, 238 insertions(+), 132 deletions(-)
 create mode 100644 com.oracle.truffle.r.test/src/com/oracle/truffle/r/test/rffi/TestRFFIPackage.java
 delete mode 100644 com.oracle.truffle.r.test/src/com/oracle/truffle/r/test/rpackages/TestRFFIPackage.java

diff --git a/com.oracle.truffle.r.native/fficall/src/jni/Rinternals.c b/com.oracle.truffle.r.native/fficall/src/jni/Rinternals.c
index 08b2380ae7..ff81c0002a 100644
--- a/com.oracle.truffle.r.native/fficall/src/jni/Rinternals.c
+++ b/com.oracle.truffle.r.native/fficall/src/jni/Rinternals.c
@@ -136,6 +136,8 @@ static jmethodID Rf_ncolsMethodID;
 static jclass CharSXPWrapperClass;
 static jfieldID CharSXPWrapperContentsFieldID;
 
+jmethodID setCompleteMethodID;
+
 void init_internals(JNIEnv *env) {
 	Rf_ScalarIntegerMethodID = checkGetMethodID(env, CallRFFIHelperClass, "Rf_ScalarInteger", "(I)Lcom/oracle/truffle/r/runtime/data/RIntVector;", 1);
 	Rf_ScalarDoubleMethodID = checkGetMethodID(env, CallRFFIHelperClass, "Rf_ScalarDouble", "(D)Lcom/oracle/truffle/r/runtime/data/RDoubleVector;", 1);
@@ -240,6 +242,8 @@ void init_internals(JNIEnv *env) {
     Rf_copyMatrixMethodID = checkGetMethodID(env, CallRFFIHelperClass, "Rf_copyMatrix", "(Ljava/lang/Object;Ljava/lang/Object;I)V", 1);
     Rf_nrowsMethodID = checkGetMethodID(env, CallRFFIHelperClass, "Rf_nrows", "(Ljava/lang/Object;)I", 1);
     Rf_ncolsMethodID = checkGetMethodID(env, CallRFFIHelperClass, "Rf_ncols", "(Ljava/lang/Object;)I", 1);
+
+    setCompleteMethodID = checkGetMethodID(env, CallRFFIHelperClass, "setComplete", "(Ljava/lang/Object;Z)V", 1);
 }
 
 static jstring stringFromCharSXP(JNIEnv *thisenv, SEXP charsxp) {
diff --git a/com.oracle.truffle.r.native/fficall/src/jni/rffiutils.c b/com.oracle.truffle.r.native/fficall/src/jni/rffiutils.c
index 381fd1bbd3..aa7a7506b4 100644
--- a/com.oracle.truffle.r.native/fficall/src/jni/rffiutils.c
+++ b/com.oracle.truffle.r.native/fficall/src/jni/rffiutils.c
@@ -294,6 +294,7 @@ static void releaseNativeArray(JNIEnv *env, int i, int freedata) {
                fprintf(traceFile, "releaseNativeArray(x=%p, ix=%d, freedata=%d)\n", cv.obj, i, freedata);
 #endif
 	if (cv.obj != NULL) {
+		jboolean complete = JNI_FALSE; // pessimal
 		switch (cv.type) {
 		case INTSXP: {
 			jintArray intArray = (jintArray) cv.jArray;
@@ -307,13 +308,21 @@ static void releaseNativeArray(JNIEnv *env, int i, int freedata) {
 			int len = (*env)->GetArrayLength(env, byteArray);
 			jbyte* internalData = (*env)->GetByteArrayElements(env, byteArray, NULL);
 			int* data = (int*) cv.data;
+			complete = JNI_TRUE; // since we going to look at each element anyway
 			for (int i = 0; i < len; i++) {
-				internalData[i] = data[i] == NA_INTEGER ? 255 : (jbyte) data[i];
+				int isNA = data[i] == NA_INTEGER ? JNI_TRUE : JNI_FALSE;
+				if (isNA) {
+					internalData[i] = 255;
+					complete = JNI_FALSE;
+				} else {
+					internalData[i] = (jbyte) data[i];
+				}
+
 			}
 			(*env)->ReleaseByteArrayElements(env, byteArray, internalData, 0);
-                       if (freedata){
-                           free(data); // was malloc'ed in addNativeArray
-                       }
+            if (freedata){
+                free(data); // was malloc'ed in addNativeArray
+            }
 			break;
 		}
 
@@ -333,10 +342,13 @@ static void releaseNativeArray(JNIEnv *env, int i, int freedata) {
 		default:
 			fatalError("releaseNativeArray type");
 		}
-               if (freedata) {
-                   // free up the slot
+		// update complete status
+		(*env)->CallVoidMethod(env, cv.obj, setCompleteMethodID, cv.obj, complete);
+
+        if (freedata) {
+            // free up the slot
 		    cv.obj = NULL;
-               }
+        }
 	}
 }
 
diff --git a/com.oracle.truffle.r.native/fficall/src/jni/rffiutils.h b/com.oracle.truffle.r.native/fficall/src/jni/rffiutils.h
index 1a217b586c..9ace813ba4 100644
--- a/com.oracle.truffle.r.native/fficall/src/jni/rffiutils.h
+++ b/com.oracle.truffle.r.native/fficall/src/jni/rffiutils.h
@@ -126,6 +126,7 @@ extern jmethodID INTEGER_MethodID;
 extern jmethodID LOGICAL_MethodID;
 extern jmethodID REAL_MethodID;
 extern jmethodID RAW_MethodID;
+extern jmethodID setCompleteMethodID;
 
 extern int callDepth;
 
diff --git a/com.oracle.truffle.r.runtime.ffi/src/com/oracle/truffle/r/runtime/ffi/jni/CallRFFIHelper.java b/com.oracle.truffle.r.runtime.ffi/src/com/oracle/truffle/r/runtime/ffi/jni/CallRFFIHelper.java
index 4458747d47..10366ff26f 100644
--- a/com.oracle.truffle.r.runtime.ffi/src/com/oracle/truffle/r/runtime/ffi/jni/CallRFFIHelper.java
+++ b/com.oracle.truffle.r.runtime.ffi/src/com/oracle/truffle/r/runtime/ffi/jni/CallRFFIHelper.java
@@ -71,6 +71,7 @@ import com.oracle.truffle.r.runtime.data.RShareable;
 import com.oracle.truffle.r.runtime.data.RStringVector;
 import com.oracle.truffle.r.runtime.data.RSymbol;
 import com.oracle.truffle.r.runtime.data.RUnboundValue;
+import com.oracle.truffle.r.runtime.data.RVector;
 import com.oracle.truffle.r.runtime.data.model.RAbstractContainer;
 import com.oracle.truffle.r.runtime.data.model.RAbstractListVector;
 import com.oracle.truffle.r.runtime.data.model.RAbstractStringVector;
@@ -659,6 +660,17 @@ public class CallRFFIHelper {
         }
     }
 
+    /**
+     * Called to possibly update the "complete" status on {@code x}. N.B. {@code x} may not be an
+     * object with a concrete {@code setComplete} method, e.g. see {@link #INTEGER(Object)}.
+     */
+    public static void setComplete(Object x, boolean complete) {
+        // only care about concrete vectors
+        if (x instanceof RVector) {
+            ((RVector<?>) x).setComplete(complete);
+        }
+    }
+
     public static void logObject(Object x) {
         System.out.println("object " + x);
         System.out.println("class " + x.getClass());
diff --git a/com.oracle.truffle.r.test/src/com/oracle/truffle/r/test/ExpectedTestOutput.test b/com.oracle.truffle.r.test/src/com/oracle/truffle/r/test/ExpectedTestOutput.test
index 0511c8d585..768d18e36d 100644
--- a/com.oracle.truffle.r.test/src/com/oracle/truffle/r/test/ExpectedTestOutput.test
+++ b/com.oracle.truffle.r.test/src/com/oracle/truffle/r/test/ExpectedTestOutput.test
@@ -114708,14 +114708,16 @@ Error: unexpected '*' in:
 #'\ ' == ' '
 [1] TRUE
 
-##com.oracle.truffle.r.test.rffi.TestUserRNG.testUserRNG#
-#{ dyn.load("com.oracle.truffle.r.test.native/urand/lib/liburand.so"); RNGkind("user"); print(RNGkind()); set.seed(4567); runif(10) }
-[1] "user-supplied" "Inversion"
- [1] 0.45336386 0.38848030 0.94576608 0.11726267 0.21542351 0.08672997
- [7] 0.35201276 0.16919220 0.93579263 0.26084486
+##com.oracle.truffle.r.test.rffi.TestRFFIPackage.testRFFI1#
+#{ library("testrffi", lib.loc = "tmptest/com.oracle.truffle.r.test.rpackages"); x <- rffi.addInt(2L, 3L); detach("package:testrffi"); x }
+[1] 5
+
+##com.oracle.truffle.r.test.rffi.TestRFFIPackage.testRFFI10#
+#{ library("testrffi", lib.loc = "tmptest/com.oracle.truffle.r.test.rpackages"); a <- c(1L,2L,3L); x <- rffi.iterate_iptr(a); detach("package:testrffi"); x }
+[1] 1 2 3
 
-##com.oracle.truffle.r.test.rpackages.TestRFFIPackage.testLoadTestRFFIDotC#
-#{ library("testrffi", lib.loc = "tmptest/com.oracle.truffle.r.test.rpackages"); r1 <- rffi.dotCModifiedArguments(c(0,1,2,3)); r1 }
+##com.oracle.truffle.r.test.rffi.TestRFFIPackage.testRFFI11#
+#{ library("testrffi", lib.loc = "tmptest/com.oracle.truffle.r.test.rpackages"); x <- rffi.dotCModifiedArguments(c(0,1,2,3)); detach("package:testrffi"); x }
 [[1]]
 [1] 4
 
@@ -114729,8 +114731,8 @@ Error: unexpected '*' in:
 [1]  TRUE FALSE FALSE FALSE
 
 
-##com.oracle.truffle.r.test.rpackages.TestRFFIPackage.testLoadTestRFFIExternal#
-#{ library("testrffi", lib.loc = "tmptest/com.oracle.truffle.r.test.rpackages"); r1 <- rffi.dotExternalAccessArgs(1L, 3, c(1,2,3), c('a', 'b'), 'b', TRUE, as.raw(12)); detach("package:testrffi"); r1 }
+##com.oracle.truffle.r.test.rffi.TestRFFIPackage.testRFFI12#
+#{ library("testrffi", lib.loc = "tmptest/com.oracle.truffle.r.test.rpackages"); x <- rffi.dotExternalAccessArgs(1L, 3, c(1,2,3), c('a', 'b'), 'b', TRUE, as.raw(12)); detach("package:testrffi"); x }
 [[1]]
 [[1]][[1]]
 NULL
@@ -114788,8 +114790,8 @@ NULL
 
 
 
-##com.oracle.truffle.r.test.rpackages.TestRFFIPackage.testLoadTestRFFIExternalWithNames#
-#{ library("testrffi", lib.loc = "tmptest/com.oracle.truffle.r.test.rpackages"); r1 <- rffi.dotExternalAccessArgs(x=1L, 3, c(1,2,3), y=c('a', 'b'), 'b', TRUE, as.raw(12)); detach("package:testrffi"); r1 }
+##com.oracle.truffle.r.test.rffi.TestRFFIPackage.testRFFI13#
+#{ library("testrffi", lib.loc = "tmptest/com.oracle.truffle.r.test.rpackages"); x <- rffi.dotExternalAccessArgs(x=1L, 3, c(1,2,3), y=c('a', 'b'), 'b', TRUE, as.raw(12)); detach("package:testrffi"); x }
 [[1]]
 [[1]][[1]]
 x
@@ -114847,48 +114849,67 @@ NULL
 
 
 
-##com.oracle.truffle.r.test.rpackages.TestRFFIPackage.testLoadTestRFFIManyArgs#
-#{ library("testrffi", lib.loc = "tmptest/com.oracle.truffle.r.test.rpackages"); r1 <- rffi.invoke12(); detach("package:testrffi"); r1 }
+##com.oracle.truffle.r.test.rffi.TestRFFIPackage.testRFFI14#
+#{ library("testrffi", lib.loc = "tmptest/com.oracle.truffle.r.test.rpackages"); x <- rffi.invoke12(); detach("package:testrffi"); x }
 [1] 12
 
-##com.oracle.truffle.r.test.rpackages.TestRFFIPackage.testLoadTestRFFISimple#
-#{ library("testrffi", lib.loc = "tmptest/com.oracle.truffle.r.test.rpackages"); c3 <- c(1L,2L,3L); r1 <- rffi.iterate_iarray(c3); r2 <- rffi.iterate_iptr(c3); detach("package:testrffi"); list(r1, r2) }
-[[1]]
-[1] 1 2 3
+##com.oracle.truffle.r.test.rffi.TestRFFIPackage.testRFFI15#
+#{ library("testrffi", lib.loc = "tmptest/com.oracle.truffle.r.test.rpackages"); x <- rffi.TYPEOF(3L); detach("package:testrffi"); x }
+[1] 13
 
-[[2]]
-[1] 1 2 3
+##com.oracle.truffle.r.test.rffi.TestRFFIPackage.testRFFI16#
+#{ library("testrffi", lib.loc = "tmptest/com.oracle.truffle.r.test.rpackages"); x <- rffi.isRString("hello"); detach("package:testrffi"); x }
+[1] TRUE
 
+##com.oracle.truffle.r.test.rffi.TestRFFIPackage.testRFFI17#
+#{ library("testrffi", lib.loc = "tmptest/com.oracle.truffle.r.test.rpackages"); x <- rffi.isRString(NULL); detach("package:testrffi"); x }
+[1] FALSE
 
-##com.oracle.truffle.r.test.rpackages.TestRFFIPackage.testLoadTestRFFISimple#
-#{ library("testrffi", lib.loc = "tmptest/com.oracle.truffle.r.test.rpackages"); r1 <- rffi.addInt(2L, 3L); r2 <- rffi.addDouble(2, 3); r3 <- rffi.populateIntVector(5); r4 <- rffi.populateLogicalVector(5); detach("package:testrffi"); list(r1, r2, r3, r4) }
-[[1]]
-[1] 5
+##com.oracle.truffle.r.test.rffi.TestRFFIPackage.testRFFI18#
+#{ library("testrffi", lib.loc = "tmptest/com.oracle.truffle.r.test.rpackages"); x <- rffi.interactive(); detach("package:testrffi"); x }
+[1] FALSE
 
-[[2]]
+##com.oracle.truffle.r.test.rffi.TestRFFIPackage.testRFFI19#
+#{ library("testrffi", lib.loc = "tmptest/com.oracle.truffle.r.test.rpackages"); x <- 1; x <- rffi.findVar(x, globalenv()); detach("package:testrffi"); x }
+Error: could not find function "rffi.findVar"
+
+##com.oracle.truffle.r.test.rffi.TestRFFIPackage.testRFFI2#
+#{ library("testrffi", lib.loc = "tmptest/com.oracle.truffle.r.test.rpackages"); x <- rffi.addDouble(2, 3); detach("package:testrffi"); x }
 [1] 5
 
-[[3]]
+##com.oracle.truffle.r.test.rffi.TestRFFIPackage.testRFFI3#
+#{ library("testrffi", lib.loc = "tmptest/com.oracle.truffle.r.test.rpackages"); x <- rffi.populateIntVector(5); detach("package:testrffi"); x }
 [1] 0 1 2 3 4
 
-[[4]]
+##com.oracle.truffle.r.test.rffi.TestRFFIPackage.testRFFI4#
+#{ library("testrffi", lib.loc = "tmptest/com.oracle.truffle.r.test.rpackages"); x <- rffi.populateLogicalVector(5); detach("package:testrffi"); x }
 [1]  TRUE    NA FALSE FALSE FALSE
 
-
-##com.oracle.truffle.r.test.rpackages.TestRFFIPackage.testLoadTestRFFISimple#
-#{ library("testrffi", lib.loc = "tmptest/com.oracle.truffle.r.test.rpackages"); r1 <- rffi.mkStringFromChar(); r2 <- rffi.mkStringFromBytes(); r3 <- rffi.null(); r4 <-rffi.isRString(character(0)); detach("package:testrffi"); list(r1, r2, r3, r4) }
-[[1]]
+##com.oracle.truffle.r.test.rffi.TestRFFIPackage.testRFFI5#
+#{ library("testrffi", lib.loc = "tmptest/com.oracle.truffle.r.test.rpackages"); x <- rffi.mkStringFromChar(); detach("package:testrffi"); x }
 [1] "hello"
 
-[[2]]
+##com.oracle.truffle.r.test.rffi.TestRFFIPackage.testRFFI6#
+#{ library("testrffi", lib.loc = "tmptest/com.oracle.truffle.r.test.rpackages"); x <- rffi.mkStringFromBytes(); detach("package:testrffi"); x }
 [1] "hello"
 
-[[3]]
+##com.oracle.truffle.r.test.rffi.TestRFFIPackage.testRFFI7#
+#{ library("testrffi", lib.loc = "tmptest/com.oracle.truffle.r.test.rpackages"); x <- rffi.null(); detach("package:testrffi"); x }
 NULL
 
-[[4]]
+##com.oracle.truffle.r.test.rffi.TestRFFIPackage.testRFFI8#
+#{ library("testrffi", lib.loc = "tmptest/com.oracle.truffle.r.test.rpackages"); x <- rffi.isRString(character(0)); detach("package:testrffi"); x }
 [1] TRUE
 
+##com.oracle.truffle.r.test.rffi.TestRFFIPackage.testRFFI9#
+#{ library("testrffi", lib.loc = "tmptest/com.oracle.truffle.r.test.rpackages"); a <- c(1L,2L,3L); x <- rffi.iterate_iarray(a); detach("package:testrffi"); x }
+[1] 1 2 3
+
+##com.oracle.truffle.r.test.rffi.TestUserRNG.testUserRNG#
+#{ dyn.load("com.oracle.truffle.r.test.native/urand/lib/liburand.so"); RNGkind("user"); print(RNGkind()); set.seed(4567); runif(10) }
+[1] "user-supplied" "Inversion"
+ [1] 0.45336386 0.38848030 0.94576608 0.11726267 0.21542351 0.08672997
+ [7] 0.35201276 0.16919220 0.93579263 0.26084486
 
 ##com.oracle.truffle.r.test.rpackages.TestRecommendedPackages.testLoad#Ignored.OutputFormatting#Context.NonShared#Context.LongTimeout#
 #{ library(KernSmooth, lib.loc = "tmptest/com.oracle.truffle.r.test.rpackages"); detach("package:KernSmooth"); }
diff --git a/com.oracle.truffle.r.test/src/com/oracle/truffle/r/test/rffi/TestRFFIPackage.java b/com.oracle.truffle.r.test/src/com/oracle/truffle/r/test/rffi/TestRFFIPackage.java
new file mode 100644
index 0000000000..1b8cd192ef
--- /dev/null
+++ b/com.oracle.truffle.r.test/src/com/oracle/truffle/r/test/rffi/TestRFFIPackage.java
@@ -0,0 +1,148 @@
+/*
+ * Copyright (c) 2014, 2016, 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
+ * under the terms of the GNU General Public License version 2 only, as
+ * published by the Free Software Foundation.
+ *
+ * This code is distributed in the hope that it will be useful, but WITHOUT
+ * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
+ * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
+ * version 2 for more details (a copy is included in the LICENSE file that
+ * accompanied this code).
+ *
+ * You should have received a copy of the GNU General Public License version
+ * 2 along with this work; if not, write to the Free Software Foundation,
+ * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
+ *
+ * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
+ * or visit www.oracle.com if you need additional information or have any
+ * questions.
+ */
+package com.oracle.truffle.r.test.rffi;
+
+import org.junit.AfterClass;
+import org.junit.BeforeClass;
+import org.junit.Test;
+
+import com.oracle.truffle.r.test.TestBase;
+import com.oracle.truffle.r.test.rpackages.TestRPackages;
+
+public class TestRFFIPackage extends TestRPackages {
+
+    private static final String[] TEST_PACKAGES = new String[]{"testrffi"};
+
+    @BeforeClass
+    public static void setupInstallMyTestPackages() {
+        setupInstallTestPackages(TEST_PACKAGES);
+    }
+
+    @AfterClass
+    public static void tearDownUninstallMyTestPackages() {
+        tearDownUninstallTestPackages(TEST_PACKAGES);
+    }
+
+    private void assertEvalWithLibWithSetup(String setup, String test) {
+        assertEval(TestBase.template("{ library(\"testrffi\", lib.loc = \"%0\"); " + setup + "x <- " + test + "; detach(\"package:testrffi\"); x }", new String[]{TestRPackages.libLoc()}));
+    }
+
+    private void assertEvalWithLib(String test) {
+        assertEvalWithLibWithSetup("", test);
+    }
+
+    @Test
+    public void testRFFI1() {
+        assertEvalWithLib("rffi.addInt(2L, 3L)");
+    }
+
+    @Test
+    public void testRFFI2() {
+        assertEvalWithLib("rffi.addDouble(2, 3)");
+    }
+
+    @Test
+    public void testRFFI3() {
+        assertEvalWithLib("rffi.populateIntVector(5)");
+    }
+
+    @Test
+    public void testRFFI4() {
+        assertEvalWithLib("rffi.populateLogicalVector(5)");
+    }
+
+    @Test
+    public void testRFFI5() {
+        assertEvalWithLib("rffi.mkStringFromChar()");
+    }
+
+    @Test
+    public void testRFFI6() {
+        assertEvalWithLib("rffi.mkStringFromBytes()");
+    }
+
+    @Test
+    public void testRFFI7() {
+        assertEvalWithLib("rffi.null()");
+    }
+
+    @Test
+    public void testRFFI8() {
+        assertEvalWithLib("rffi.isRString(character(0))");
+    }
+
+    @Test
+    public void testRFFI9() {
+        assertEvalWithLibWithSetup("a <- c(1L,2L,3L); ", "rffi.iterate_iarray(a)");
+    }
+
+    @Test
+    public void testRFFI10() {
+        assertEvalWithLibWithSetup("a <- c(1L,2L,3L); ", "rffi.iterate_iptr(a)");
+    }
+
+    @Test
+    public void testRFFI11() {
+        assertEvalWithLib("rffi.dotCModifiedArguments(c(0,1,2,3))");
+    }
+
+    @Test
+    public void testRFFI12() {
+        assertEvalWithLib("rffi.dotExternalAccessArgs(1L, 3, c(1,2,3), c('a', 'b'), 'b', TRUE, as.raw(12))");
+    }
+
+    @Test
+    public void testRFFI13() {
+        assertEvalWithLib("rffi.dotExternalAccessArgs(x=1L, 3, c(1,2,3), y=c('a', 'b'), 'b', TRUE, as.raw(12))");
+    }
+
+    @Test
+    public void testRFFI14() {
+        assertEvalWithLib("rffi.invoke12()");
+    }
+
+    @Test
+    public void testRFFI15() {
+        assertEvalWithLib("rffi.TYPEOF(3L)");
+    }
+
+    @Test
+    public void testRFFI16() {
+        assertEvalWithLib("rffi.isRString(\"hello\")");
+    }
+
+    @Test
+    public void testRFFI17() {
+        assertEvalWithLib("rffi.isRString(NULL)");
+    }
+
+    @Test
+    public void testRFFI18() {
+        assertEvalWithLib("rffi.interactive()");
+    }
+
+    @Test
+    public void testRFFI19() {
+        assertEvalWithLibWithSetup("x <- 1; ", "rffi.findVar(x, globalenv())");
+    }
+}
diff --git a/com.oracle.truffle.r.test/src/com/oracle/truffle/r/test/rpackages/TestRFFIPackage.java b/com.oracle.truffle.r.test/src/com/oracle/truffle/r/test/rpackages/TestRFFIPackage.java
deleted file mode 100644
index c6c3f54029..0000000000
--- a/com.oracle.truffle.r.test/src/com/oracle/truffle/r/test/rpackages/TestRFFIPackage.java
+++ /dev/null
@@ -1,92 +0,0 @@
-/*
- * Copyright (c) 2014, 2016, 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
- * under the terms of the GNU General Public License version 2 only, as
- * published by the Free Software Foundation.
- *
- * This code is distributed in the hope that it will be useful, but WITHOUT
- * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
- * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
- * version 2 for more details (a copy is included in the LICENSE file that
- * accompanied this code).
- *
- * You should have received a copy of the GNU General Public License version
- * 2 along with this work; if not, write to the Free Software Foundation,
- * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
- *
- * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
- * or visit www.oracle.com if you need additional information or have any
- * questions.
- */
-package com.oracle.truffle.r.test.rpackages;
-
-import org.junit.AfterClass;
-import org.junit.BeforeClass;
-import org.junit.Test;
-
-import com.oracle.truffle.r.test.TestBase;
-
-/**
- * Tests related to the loading, etc. of R packages.
- */
-public class TestRFFIPackage extends TestRPackages {
-
-    private static final String[] TEST_PACKAGES = new String[]{"testrffi"};
-
-    @BeforeClass
-    public static void setupInstallMyTestPackages() {
-        setupInstallTestPackages(TEST_PACKAGES);
-    }
-
-    @AfterClass
-    public static void tearDownUninstallMyTestPackages() {
-        tearDownUninstallTestPackages(TEST_PACKAGES);
-    }
-
-    @Test
-    public void testLoadTestRFFISimple() {
-        assertEval(TestBase.template(
-                        "{ library(\"testrffi\", lib.loc = \"%0\"); r1 <- rffi.addInt(2L, 3L); r2 <- rffi.addDouble(2, 3); r3 <- rffi.populateIntVector(5); " +
-                                        "r4 <- rffi.populateLogicalVector(5); detach(\"package:testrffi\"); list(r1, r2, r3, r4) }",
-                        new String[]{TestRPackages.libLoc()}));
-        assertEval(TestBase.template(
-                        "{ library(\"testrffi\", lib.loc = \"%0\"); r1 <- rffi.mkStringFromChar(); r2 <- rffi.mkStringFromBytes(); r3 <- rffi.null(); " +
-                                        "r4 <-rffi.isRString(character(0)); detach(\"package:testrffi\"); list(r1, r2, r3, r4) }",
-                        new String[]{TestRPackages.libLoc()}));
-        assertEval(TestBase.template(
-                        "{ library(\"testrffi\", lib.loc = \"%0\"); c3 <- c(1L,2L,3L); r1 <- rffi.iterate_iarray(c3); r2 <- rffi.iterate_iptr(c3); " +
-                                        "detach(\"package:testrffi\"); list(r1, r2) }",
-                        new String[]{TestRPackages.libLoc()}));
-    }
-
-    @Test
-    public void testLoadTestRFFIDotC() {
-        assertEval(TestBase.template(
-                        "{ library(\"testrffi\", lib.loc = \"%0\"); r1 <- rffi.dotCModifiedArguments(c(0,1,2,3)); r1 }",
-                        new String[]{TestRPackages.libLoc()}));
-    }
-
-    @Test
-    public void testLoadTestRFFIExternal() {
-        assertEval(TestBase.template(
-                        "{ library(\"testrffi\", lib.loc = \"%0\"); r1 <- rffi.dotExternalAccessArgs(1L, 3, c(1,2,3), c('a', 'b'), 'b', TRUE, as.raw(12)); detach(\"package:testrffi\"); r1 }",
-                        new String[]{TestRPackages.libLoc()}));
-    }
-
-    @Test
-    public void testLoadTestRFFIExternalWithNames() {
-        assertEval(TestBase.template(
-                        "{ library(\"testrffi\", lib.loc = \"%0\"); r1 <- rffi.dotExternalAccessArgs(x=1L, 3, c(1,2,3), y=c('a', 'b'), 'b', TRUE, as.raw(12)); detach(\"package:testrffi\"); r1 }",
-                        new String[]{TestRPackages.libLoc()}));
-    }
-
-    @Test
-    public void testLoadTestRFFIManyArgs() {
-        assertEval(TestBase.template(
-                        "{ library(\"testrffi\", lib.loc = \"%0\"); r1 <- rffi.invoke12(); detach(\"package:testrffi\"); r1 }",
-                        new String[]{TestRPackages.libLoc()}));
-    }
-
-}
-- 
GitLab