From 8cb1d91601785221ea653e72a4b5bc017a516785 Mon Sep 17 00:00:00 2001 From: stepan <stepan.sindelar@oracle.com> Date: Fri, 23 Feb 2018 16:18:11 +0100 Subject: [PATCH] Add automated tests for R embedded mode and add them to gate tasks --- .gitignore | 3 +- ci.hocon | 4 +- com.oracle.truffle.r.test.native/Makefile | 10 ++- .../embedded/Makefile | 26 +++---- .../embedded/src/embedded.expected.output | 75 +++++++++++++++++++ .../embedded/src/main.expected.output | 8 ++ .../embedded/src/main.input | 2 + .../embedded/test.sh | 61 +++++++++++++++ mx.fastr/copyrights/overrides | 1 + mx.fastr/mx_fastr.py | 23 ++++++ 10 files changed, 196 insertions(+), 17 deletions(-) create mode 100644 com.oracle.truffle.r.test.native/embedded/src/embedded.expected.output create mode 100644 com.oracle.truffle.r.test.native/embedded/src/main.expected.output create mode 100644 com.oracle.truffle.r.test.native/embedded/src/main.input create mode 100755 com.oracle.truffle.r.test.native/embedded/test.sh diff --git a/.gitignore b/.gitignore index fe63b0a59d..6b0dd1ea12 100644 --- a/.gitignore +++ b/.gitignore @@ -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 diff --git a/ci.hocon b/ci.hocon index 91c544d556..259a0e142e 100644 --- a/ci.hocon +++ b/ci.hocon @@ -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"] ] } diff --git a/com.oracle.truffle.r.test.native/Makefile b/com.oracle.truffle.r.test.native/Makefile index e19effc9d8..8708458064 100644 --- a/com.oracle.truffle.r.test.native/Makefile +++ b/com.oracle.truffle.r.test.native/Makefile @@ -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 diff --git a/com.oracle.truffle.r.test.native/embedded/Makefile b/com.oracle.truffle.r.test.native/embedded/Makefile index 77632483e4..7fb216f542 100644 --- a/com.oracle.truffle.r.test.native/embedded/Makefile +++ b/com.oracle.truffle.r.test.native/embedded/Makefile @@ -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) diff --git a/com.oracle.truffle.r.test.native/embedded/src/embedded.expected.output b/com.oracle.truffle.r.test.native/embedded/src/embedded.expected.output new file mode 100644 index 0000000000..4a76493713 --- /dev/null +++ b/com.oracle.truffle.r.test.native/embedded/src/embedded.expected.output @@ -0,0 +1,75 @@ +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 diff --git a/com.oracle.truffle.r.test.native/embedded/src/main.expected.output b/com.oracle.truffle.r.test.native/embedded/src/main.expected.output new file mode 100644 index 0000000000..05a230a88c --- /dev/null +++ b/com.oracle.truffle.r.test.native/embedded/src/main.expected.output @@ -0,0 +1,8 @@ +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 diff --git a/com.oracle.truffle.r.test.native/embedded/src/main.input b/com.oracle.truffle.r.test.native/embedded/src/main.input new file mode 100644 index 0000000000..38d61667bf --- /dev/null +++ b/com.oracle.truffle.r.test.native/embedded/src/main.input @@ -0,0 +1,2 @@ +1:4 + 1:10 +q('no') diff --git a/com.oracle.truffle.r.test.native/embedded/test.sh b/com.oracle.truffle.r.test.native/embedded/test.sh new file mode 100755 index 0000000000..38f05584f4 --- /dev/null +++ b/com.oracle.truffle.r.test.native/embedded/test.sh @@ -0,0 +1,61 @@ +#!/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" diff --git a/mx.fastr/copyrights/overrides b/mx.fastr/copyrights/overrides index f3632cb367..a0e848c665 100644 --- a/mx.fastr/copyrights/overrides +++ b/mx.fastr/copyrights/overrides @@ -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 diff --git a/mx.fastr/mx_fastr.py b/mx.fastr/mx_fastr.py index fbf291a743..700ba88357 100644 --- a/mx.fastr/mx_fastr.py +++ b/mx.fastr/mx_fastr.py @@ -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']], -- GitLab