Initial commit

This commit is contained in:
Bassem Girgis
2018-12-20 17:34:07 -06:00
parent 7a2d899662
commit 81b4b9e273
34743 changed files with 5940233 additions and 0 deletions

View File

@@ -0,0 +1,79 @@
#######################################################################
# Makefile for r test-suite
#######################################################################
LANGUAGE = r
SCRIPTSUFFIX = _runme.R
WRAPSUFFIX = .R
R_OPT = --quiet --no-save --no-restore
RUNR = R CMD BATCH $(R_OPT) '--args $(SCRIPTDIR)'
srcdir = @srcdir@
top_srcdir = @top_srcdir@
top_builddir = @top_builddir@
C_TEST_CASES += \
r_copy_struct \
r_legacy
CPP_TEST_CASES += \
r_double_delete \
r_overload_array \
r_sexp \
r_overload_comma
include $(srcdir)/../common.mk
# Overridden variables here
# none!
# Custom tests - tests with additional commandline options
# none!
# Rules for the different types of tests
%.cpptest:
$(setup)
+$(swig_and_compile_cpp)
$(run_testcase)
%.ctest:
$(setup)
+$(swig_and_compile_c)
$(run_testcase)
%.multicpptest:
$(setup)
+$(swig_and_compile_multi_cpp)
$(run_multitestcase)
# Runs the testcase.
#
# Run the runme if it exists. If not just load the R wrapper to
# check for syntactic correctness
run_testcase = \
if [ -f $(SCRIPTDIR)/$(SCRIPTPREFIX)$*$(SCRIPTSUFFIX) ]; then \
env LD_LIBRARY_PATH=.:$$LD_LIBRARY_PATH PATH=.:"$$PATH" $(RUNTOOL) $(RUNR) $(SCRIPTDIR)/$(SCRIPTPREFIX)$*$(SCRIPTSUFFIX) || (cat $(SCRIPTDIR)/$(SCRIPTPREFIX)$*$(SCRIPTSUFFIX)out ; false); \
else \
$(RUNTOOL) $(RUNR) ./$(SCRIPTPREFIX)$*$(WRAPSUFFIX) || (cat ./$(SCRIPTPREFIX)$*$(WRAPSUFFIX)out ; false); \
fi
run_multitestcase = \
for f in `cat $(top_srcdir)/$(EXAMPLES)/$(TEST_SUITE)/$*.list` ; do \
if [ -f $(SCRIPTDIR)/$(SCRIPTPREFIX)$${f}$(SCRIPTSUFFIX) ]; then \
env LD_LIBRARY_PATH=.:$$LD_LIBRARY_PATH PATH=.:"$$PATH" $(RUNTOOL) $(RUNR) $(SCRIPTDIR)/$(SCRIPTPREFIX)$${f}$(SCRIPTSUFFIX) || (cat $(SCRIPTDIR)/$(SCRIPTPREFIX)$${f}$(SCRIPTSUFFIX)out ; false); \
else \
$(RUNTOOL) $(RUNR) ./$(SCRIPTPREFIX)$${f}$(WRAPSUFFIX) || (cat ./$(SCRIPTPREFIX)$${f}$(WRAPSUFFIX)out ; false); \
fi; \
done
# Clean
clean:
$(MAKE) -f $(top_builddir)/$(EXAMPLES)/Makefile SRCDIR='$(SRCDIR)' r_clean
%.clean:
@rm -f $*.R $*_wrap.so $*_wrap.cpp $*_wrap.c $*_wrap.o $*_runme.Rout $*.Rout
@if [ -f $(top_srcdir)/$(EXAMPLES)/$(TEST_SUITE)/$*.list ]; then \
for f in `cat $(top_srcdir)/$(EXAMPLES)/$(TEST_SUITE)/$*.list` ; do \
rm -f $${f}.R $${f}.Rout ; \
done \
fi

View File

@@ -0,0 +1,22 @@
clargs <- commandArgs(trailing=TRUE)
source(file.path(clargs[1], "unittest.R"))
dyn.load(paste("arrays_dimensionless", .Platform$dynlib.ext, sep=""))
source("arrays_dimensionless.R")
cacheMetaData(1)
unittest(arr_short(1:4, 3), 6)
unittest(arr_ushort(1:4, 3), 6)
unittest(arr_int(1:4, 3), 6)
unittest(arr_uint(1:4, 3), 6)
unittest(arr_long(1:4, 3), 6)
unittest(arr_ulong(1:4, 3), 6)
unittest(arr_ll(1:4, 3), 6)
unittest(arr_ull(1:4, 3), 6)
unittest(arr_float(as.numeric(1:4), 3), 6)
unittest(arr_double(as.numeric(1:4), 3), 6)
q(save="no")

View File

@@ -0,0 +1,9 @@
clargs <- commandArgs(trailing=TRUE)
source(file.path(clargs[1], "unittest.R"))
dyn.load(paste("funcptr", .Platform$dynlib.ext, sep=""))
source("funcptr.R")
cacheMetaData(1)
unittest(do_op(1, 3, add), 4)
unittest(do_op(2, 3, multiply), 6)
unittest(do_op(2, 3, funcvar()), 5)

View File

@@ -0,0 +1,12 @@
clargs <- commandArgs(trailing=TRUE)
source(file.path(clargs[1], "unittest.R"))
dyn.load(paste("ignore_parameter", .Platform$dynlib.ext, sep=""))
source("ignore_parameter.R")
cacheMetaData(1)
unittest(jaguar(1, 1.0), "hello")
q(save="no")

View File

@@ -0,0 +1,22 @@
clargs <- commandArgs(trailing=TRUE)
source(file.path(clargs[1], "unittest.R"))
dyn.load(paste("integers", .Platform$dynlib.ext, sep=""))
source("integers.R")
cacheMetaData(1)
unittest(signed_char_identity(1), 1)
unittest(unsigned_char_identity(1), 1)
unittest(signed_short_identity(1), 1)
unittest(unsigned_short_identity(1), 1)
unittest(signed_int_identity(1), 1)
unittest(unsigned_int_identity(1), 1)
unittest(signed_long_identity(1), 1)
unittest(unsigned_long_identity(1), 1)
unittest(signed_long_long_identity(1), 1)
unittest(unsigned_long_long_identity(1), 1)
q(save="no")

View File

@@ -0,0 +1,19 @@
clargs <- commandArgs(trailing=TRUE)
source(file.path(clargs[1], "unittest.R"))
dyn.load(paste("li_std_vector", .Platform$dynlib.ext, sep=""))
source("li_std_vector.R")
cacheMetaData(1)
testvec <- c(1, 2, 3)
unittest(half(testvec), testvec/2)
unittest(average(testvec), mean(testvec))
## string vector test
vlen <- 13
stringvec <- paste(letters[1:vlen], as.character(rnorm(vlen)))
unittest(rev(stringvec), RevStringVec(stringvec))
q(save="no")

View File

@@ -0,0 +1,15 @@
clargs <- commandArgs(trailing=TRUE)
source(file.path(clargs[1], "unittest.R"))
dyn.load(paste("overload_method", .Platform$dynlib.ext, sep=""))
source("overload_method.R")
cacheMetaData(1)
b <- Base()
Base_method(b)
Base_overloaded_method(b)
Base_overloaded_method(b, 43)
Base_overloaded_method(b)
b$method()
b$overloaded_method()

View File

@@ -0,0 +1,12 @@
clargs <- commandArgs(trailing=TRUE)
source(file.path(clargs[1], "unittest.R"))
dyn.load(paste("preproc_constants", .Platform$dynlib.ext, sep=""))
source("preproc_constants.R")
cacheMetaData(1)
v <- enumToInteger('kValue', '_MyEnum')
print(v)
# temporarily removed until fixed (in progress, see Github patch #500)
#unittest(v,4)
q(save="no")

View File

@@ -0,0 +1,60 @@
clargs <- commandArgs(trailing=TRUE)
source(file.path(clargs[1], "unittest.R"))
dyn.load(paste("r_copy_struct", .Platform$dynlib.ext, sep=""))
source("r_copy_struct.R")
cacheMetaData(1)
a <- getA()
r = getARef()
unittest(A_d_get(r), 42)
unittest(r$d, 42)
unittest(r$i, 20)
# An error in trying to access a field that doesn't exist.
try(r$foo)
r$d <- pi
unittesttol(r$d, 3.141593, 0.0001)
r$i <- -100
r$ui
r$ui <- 10
# An error since i is unsigned and so must be positive.
try(r$ui <- -10)
a = A()
unittest(a$i,0)
unittest(a$d,0)
unittest(a$ui,0)
a$ui <- 100
unittest(a$ui,100)
a$d = 1
unittest(a$d,1)
d <- bar()
unittest(class(d), "_p_D")
unittest(d$x, 1)
unittest(d$u, 0)
la <- new("A");
la@ui <- as.integer(5)
# Removing the next line makes this fail in R 2.4
la@str <- ""
other = A()
foo <- copyToC(la, other)
aa = A()
aa$i = as.integer(201)
aa$d = pi
aa$str = "foo"
aa$ui = as.integer(0)
copyToR(aa)

View File

@@ -0,0 +1,9 @@
dyn.load(paste("r_double_delete", .Platform$dynlib.ext, sep=""))
source("r_double_delete.R")
cacheMetaData(1)
# ----- Object creation -----
f <- Foo(2.0)
delete(f);
delete(f);

View File

@@ -0,0 +1,32 @@
clargs <- commandArgs(trailing=TRUE)
source(file.path(clargs[1], "unittest.R"))
dyn.load(paste("r_legacy", .Platform$dynlib.ext, sep=""))
source("r_legacy.R")
cacheMetaData(1)
obj <- getObject(1,3)
unittest(class(obj), "_p_Obj")
unittest(obj$i, 1)
unittesttol(obj$d, 3, 0.001)
unittest(obj$str, "a test string")
obj$i <- 2
unittest(obj$i, 2)
obj$d <- 4
unittesttol(obj$d, 4, 0.001)
obj$str <- "a new string"
unittest(obj$str, "a new string")
unittest(getInt(), 42)
unittesttol(getDouble(),3.14159, 0.001)
unittesttol(getFloat(),3.14159/2.0, 0.001)
unittest(getLong(), -321313)
unittest(getUnsignedLong(), 23123)
unittest(getChar(), "A")
q(save="no")

View File

@@ -0,0 +1,9 @@
clargs <- commandArgs(trailing=TRUE)
source(file.path(clargs[1], "unittest.R"))
dyn.load(paste("r_sexp", .Platform$dynlib.ext, sep=""))
source("r_sexp.R")
cacheMetaData(1)
obj <- return_sexp(1);
unittest(obj, 1)

View File

@@ -0,0 +1,22 @@
clargs <- commandArgs(trailing=TRUE)
source(file.path(clargs[1], "unittest.R"))
dyn.load(paste("rename_simple", .Platform$dynlib.ext, sep=""))
source("rename_simple.R")
cacheMetaData(1)
s <- NewStruct();
unittest(111, s$NewInstanceVariable)
unittest(222, s$NewInstanceMethod())
unittest(333, NewStruct_NewStaticMethod())
unittest(444, NewStruct_NewStaticVariable())
unittest(555, NewFunction())
unittest(666, NewGlobalVariable())
s$NewInstanceVariable <- 1111
NewStruct_NewStaticVariable(4444)
NewGlobalVariable(6666)
unittest(1111, s$NewInstanceVariable)
unittest(4444, NewStruct_NewStaticVariable())
unittest(6666, NewGlobalVariable())

View File

@@ -0,0 +1,10 @@
clargs <- commandArgs(trailing=TRUE)
source(file.path(clargs[1], "unittest.R"))
dyn.load(paste("simple_array", .Platform$dynlib.ext, sep=""))
source("simple_array.R")
cacheMetaData(1)
initArray()
q(save="no")

View File

@@ -0,0 +1,13 @@
clargs <- commandArgs(trailing=TRUE)
source(file.path(clargs[1], "unittest.R"))
dyn.load(paste("unions", .Platform$dynlib.ext, sep=""))
source("unions.R")
cacheMetaData(1)
ss <- SmallStruct()
bstruct <- BigStruct()
q(save="no")

View File

@@ -0,0 +1,17 @@
unittest <- function (x,y) {
if (all(x==y)) {
print("PASS")
} else {
print("FAIL")
stop("Test failed")
}
}
unittesttol <- function(x,y,z) {
if (all(abs(x-y) < z)) {
print("PASS")
} else {
print("FAIL")
stop("Test failed")
}
}