Skip to content
Snippets Groups Projects
Commit 8cb1d916 authored by stepan's avatar stepan
Browse files

Add automated tests for R embedded mode and add them to gate tasks

parent b0b10a8e
No related branches found
No related tags found
No related merge requests found
......@@ -146,4 +146,5 @@ com.oracle.truffle.r.test.native/packages/testrffi/testrffi/tests/coerceTests.R
com.oracle.truffle.r.native/version.built
documentation/.pydevproject
com.oracle.truffle.r.native/gnur/patch-build
/com.oracle.truffle.r.native/fficall/common.done
\ No newline at end of file
com.oracle.truffle.r.test.native/embedded/embedded.actual.output
com.oracle.truffle.r.test.native/embedded/main.actual.output
......@@ -36,6 +36,8 @@ logfiles : [
"libdownloads/R-*/gnur_make.log"
"libdownloads/R-*/Makeconf"
"com.oracle.truffle.r.native/gnur/tests/log/all.diff"
"com.oracle.truffle.r.test.native/embedded/*.output"
"com.oracle.truffle.r.test.native/embedded/src/*.output"
"*-tests/*.Rout"
]
......@@ -93,7 +95,7 @@ gateCmd : ["mx", "--strict-compliance", "rgate", "--strict-mode", "-t"]
gateTestCommon : ${common} {
run : [
${gateCmd} ["Versions,JDKReleaseInfo,BuildJavaWithJavac,UnitTests: with specials"]
${gateCmd} ["Versions,JDKReleaseInfo,BuildJavaWithJavac,UnitTests: with specials,Rembedded"]
]
}
......
......@@ -37,7 +37,10 @@ all:
$(MAKE) -C urand
$(MAKE) -C packages
ifneq ($(OSNAME), SunOS)
ifeq ($(FASTR_RFFI),jni)
ifeq ($(FASTR_RFFI),nfi)
$(MAKE) -C embedded
endif
ifeq ($(FASTR_RFFI),)
$(MAKE) -C embedded
endif
endif
......@@ -46,7 +49,10 @@ clean:
$(MAKE) -C urand clean
$(MAKE) -C packages clean
ifneq ($(OSNAME), SunOS)
ifeq ($(FASTR_RFFI),jni)
ifeq ($(FASTR_RFFI),nfi)
$(MAKE) -C embedded clean
endif
ifeq ($(FASTR_RFFI),)
$(MAKE) -C embedded clean
endif
endif
......
......@@ -45,28 +45,28 @@ FASTR_LIB_DIR = $(abspath ../../lib)
.PHONY: all clean
OBJ = lib
BIN = bin
SRC = src
C_SOURCES := $(wildcard $(SRC)/*.c)
C_OBJECTS := $(subst $(SRC),$(OBJ),$(C_SOURCES:.c=.o))
C_OBJECTS := $(subst $(SRC),$(BIN),$(C_SOURCES:.c=.o))
INCLUDE_DIR := $(NATIVE_PROJECT)/include
all: $(OBJ)/main $(OBJ)/embedded Makefile
all: $(BIN)/main $(BIN)/embedded Makefile
$(OBJ)/main: | $(OBJ)
$(OBJ)/embedded: | $(OBJ)
$(BIN)/main: | $(BIN)
$(BIN)/embedded: | $(BIN)
$(OBJ):
mkdir -p $(OBJ)
$(BIN):
mkdir -p $(BIN)
$(OBJ)/main: $(SRC)/main.c
$(CC) $(CFLAGS) -I$(INCLUDE_DIR) $< -o $(OBJ)/main -L $(FASTR_LIB_DIR) -ldl -lR $(LD_FLAGS) -Wl,-rpath,$(FASTR_LIB_DIR)
$(BIN)/main: $(SRC)/main.c
$(CC) $(CFLAGS) -I$(INCLUDE_DIR) $< -o $(BIN)/main -L $(FASTR_LIB_DIR) -ldl -lR $(LD_FLAGS) -Wl,-rpath,$(FASTR_LIB_DIR)
$(OBJ)/embedded: $(SRC)/embedded.c
$(CC) $(CFLAGS) -I$(INCLUDE_DIR) $< -o $(OBJ)/embedded -L $(FASTR_LIB_DIR) -ldl -lR $(LD_FLAGS) -Wl,-rpath,$(FASTR_LIB_DIR)
cp $(SRC)/*.R $(OBJ)
$(BIN)/embedded: $(SRC)/embedded.c
$(CC) $(CFLAGS) -I$(INCLUDE_DIR) $< -o $(BIN)/embedded -L $(FASTR_LIB_DIR) -ldl -lR $(LD_FLAGS) -Wl,-rpath,$(FASTR_LIB_DIR)
cp $(SRC)/*.R $(BIN)
clean:
rm -rf $(OBJ)
rm -rf $(BIN)
Initializing R with Rf_initEmbeddedR...
Sourcing 'error.R'...
Invoking foo() via tryEval...Error in foo() : Stopping in function foo
[1] 1 2 3 4 5 6 7 8 9 10
errorOccurred=1
Invoking foo() via tryEval once more...Error in foo() : Stopping in function foo
[1] 1 2 3 4 5 6 7 8 9 10
errorOccurred=1
Trying sqrt with wrong and then correct argument...
Error in sqrt("") : non-numeric argument to mathematical function
Caught an error calling sqrt(). Try again with a different argument.
[1] 3
Sourcing 'foo.R'...
Calling foo with named arguments...
Printing the expression to be eval'ed...
[[1]]
function(...)
{
args <- list(...)
print(args)
print(names(args))
TRUE
}
$pch
[1] "+"
$id
[1] 123
[[4]]
[1] TRUE FALSE
Eval'ing the expression...
$pch
[1] "+"
$id
[1] 123
[[3]]
[1] TRUE FALSE
[1] "pch" "id" ""
Printing the expression to be tryEval'ed...
[[1]]
foo
$pch
[1] "+"
$id
[1] 123
[[4]]
[1] TRUE FALSE
TryEval'ing the expression...
$pch
[1] "+"
$id
[1] 123
[[3]]
[1] TRUE FALSE
[1] "pch" "id" ""
Calling R_getEmbeddingDllInfo...
Sourcing 'embedding.R'...
getDLLRegisteredRoutines('(embedding)'):
.Call .Call.numParameters
1 twice 2
[1] 2 4 6 8 10
DONE
Initializing R with Rf_initialize_R...
Initializing R with R_SetParams...
Running R with Rf_mainloop...
TODO prompt> [1] 2 4 6 8 6 8 10 12 10 12
Warning message:
In 1:4 + 1:10 :
longer object length is not a multiple of shorter object length
TODO prompt>test Cleanup
1:4 + 1:10
q('no')
#!/bin/bash
#
# Copyright (c) 2018, 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.
#
set -e
# Resolve the location of this script
source="${BASH_SOURCE[0]}"
while [ -h "$source" ] ; do
prev_source="$source"
source="$(readlink "$source")";
if [[ "$source" != /* ]]; then
# if the link was relative, it was relative to where it came from
dir="$( cd -P "$( dirname "$prev_source" )" && pwd )"
source="$dir/$source"
fi
done
dir="$( cd -P "$( dirname "$source" )" && pwd )"
: ${R_HOME?"R_HOME must point to FastR directory"}
: ${NFI_LIB?"NFI_LIB must point to libtrufflenfi.so located in mxbuild directory of Truffle"}
echo "Testing 'main' embedding example..."
(cd $dir/bin; ./main -Dtruffle.nfi.library=$NFI_LIB --vanilla < $dir/src/main.input > $dir/main.actual.output 2>&1)
if ! diff -q $dir/main.actual.output $dir/src/main.expected.output > /dev/null 2>&1; then
echo "'main' embedding test failed"
echo "for details see $dir/main.actual.output $dir/src/main.expected.output"
echo "to run this test: mx rembedtest"
exit 1
fi
echo "Testing 'embedded' embedding example..."
(cd $dir/bin; ./embedded -Dtruffle.nfi.library=$NFI_LIB --vanilla > $dir/embedded.actual.output 2>&1)
if ! diff -q $dir/embedded.actual.output $dir/src/embedded.expected.output > /dev/null 2>&1; then
echo "'embedded' embedding test failed"
echo "for details see $dir/embedded.actual.output $dir/src/embedded.expected.output"
echo "to run this test: mx rembedtest"
exit 2
fi
echo "DONE"
......@@ -101,6 +101,7 @@ com.oracle.truffle.r.native/gnur/patch/src/library/stats/src/ts.h,no.copyright
com.oracle.truffle.r.native/gnur/patch/src/library/tools/src/tools_dummy.c,no.copyright
com.oracle.truffle.r.native/gnur/patch/src/library/utils/src/utils_dummy.c,no.copyright
com.oracle.truffle.r.native/run/R.sh,oracle_bash.copyright
com.oracle.truffle.r.test.native/embedded/test.sh,oracle_bash.copyright
com.oracle.truffle.r.native/run/Rclasspath.sh,oracle_bash.copyright
com.oracle.truffle.r.native/run/Rscript_exec.sh,oracle_bash.copyright
com.oracle.truffle.r.native/run/Rscript.sh,oracle_bash.copyright
......
......@@ -245,8 +245,25 @@ def rrepl(args, nonZeroIsFatal=True, extraVmArgs=None):
run_r(args, 'rrepl')
def rembed(args, nonZeroIsFatal=True, extraVmArgs=None):
'''
Runs pure Java program that simulates the embedding scenario doing the same up-calls as embedded would call.
'''
run_r(args, 'rembed')
def rembedtest(args, nonZeroIsFatal=False, extraVmArgs=None):
'''
Runs simple R embedding API tests located in com.oracle.truffle.r.test.native/embedded.
The tests should be compiled by mx build before they can be run.
Each test (native application) is run and its output compared to the expected output
file located next to the source file.
'''
env = os.environ.copy()
env['R_HOME'] = _fastr_suite.dir
so_suffix = '.dylib' if platform.system().lower() == 'darwin' else '.so'
env['NFI_LIB'] = join(mx.suite('truffle').get_output_root(platformDependent=True), 'truffle-nfi-native/bin/libtrufflenfi' + so_suffix)
tests_script = join(_fastr_suite.dir, 'com.oracle.truffle.r.test.native/embedded/test.sh')
return mx.run([tests_script], env=env, nonZeroIsFatal=nonZeroIsFatal)
def _fastr_gate_runner(args, tasks):
'''
The specific additional gates tasks provided by FastR:
......@@ -277,6 +294,11 @@ def _fastr_gate_runner(args, tasks):
if t:
mx_unittest.unittest(_apps_unit_tests())
with mx_gate.Task('Rembedded', tasks) as t:
if t:
if rembedtest([]) != 0:
t.abort("Rembedded tests failed")
mx_gate.add_gate_runner(_fastr_suite, _fastr_gate_runner)
def rgate(args):
......@@ -553,6 +575,7 @@ _commands = {
'rbdiag' : [rbdiag, '(builtin)* [-v] [-n] [-m] [--sweep | --sweep=lite | --sweep=total] [--mnonly] [--noSelfTest] [--matchLevel=same | --matchLevel=error] [--maxSweeps=N] [--outMaxLev=N]'],
'rrepl' : [rrepl, '[options]'],
'rembed' : [rembed, '[options]'],
'rembedtest' : [rembedtest, '[options]'],
'r-cp' : [r_classpath, '[options]'],
'pkgtest' : [mx_fastr_pkgs.pkgtest, ['options']],
'pkgtest-cmp' : [mx_fastr_pkgs.pkgtest_cmp, ['gnur_path fastr_path']],
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment