[Swift-commit] r4049 - SwiftApps/SwiftR/Swift/R

noreply at svn.ci.uchicago.edu noreply at svn.ci.uchicago.edu
Wed Feb 2 10:46:44 CST 2011


Author: tga
Date: 2011-02-02 10:46:44 -0600 (Wed, 02 Feb 2011)
New Revision: 4049

Added:
   SwiftApps/SwiftR/Swift/R/Tests.R
Log:
Forgot to check in new tests file on previous commit.


Added: SwiftApps/SwiftR/Swift/R/Tests.R
===================================================================
--- SwiftApps/SwiftR/Swift/R/Tests.R	                        (rev 0)
+++ SwiftApps/SwiftR/Swift/R/Tests.R	2011-02-02 16:46:44 UTC (rev 4049)
@@ -0,0 +1,451 @@
+
+
+initSwiftTestOptions <- function()
+{
+  options(swift.site="service")
+  options(swift.keepwork=TRUE)
+  initcmds <- "initVar1 <<- 19; initVar2 <<- sqrt(400)+3"
+  options(swift.initialexpr=initcmds) # Set here; used in test group 4
+}
+
+
+
+
+swiftTest_1.1 <- function()
+{
+
+  initSwiftTestOptions()
+
+  cat("\n*** Starting  test 1.1 ***\n\n")
+
+  sumstuff <- function(treedata,cardata) { sum( treedata$Height, cardata$dist ) }
+  data(cars)
+  data(trees)
+
+  args=list(trees,cars)
+  arglist = rep(list(args),1)
+
+  cat("Test of local do.call(sumstuff)\n")
+  localres = do.call(sumstuff,args)
+  cat("local result=\n")
+  print(localres)
+
+  cat("\nTest of swiftapply(sumstuff,arglist)\n")
+  swiftres = swiftapply(sumstuff,arglist)
+  cat("Swift result:\n")
+  print(swiftres)
+
+  if(identical(localres,swiftres[[1]])) {
+    cat("\n==> test 1.1 passed\n")
+  } else {
+    cat("\n==> test 1.1 FAILED !!!!!\n")
+  }
+}
+
+basicSwiftTest <- function() { swiftTest_1.1() }
+
+# .... more tests from below to move here
+swiftTest_4.1 <- function()
+{
+  sumivars <- function() { initVar1+initVar2 }
+
+  args=list()
+  arglist = rep(list(args),1)
+
+  localres = 42
+
+  cat("\nTest of swiftapply(sumivars,arglist)\n")
+  swiftres = swiftapply(sumivars,arglist)
+  cat("Swift result:\n")
+  print(swiftres)
+
+  if(identical(localres,swiftres[[1]])) {
+    cat("\n==> test 4.1 passed\n")
+  } else {
+    cat("\n==> test 4.1 FAILED !!!!!\n")
+  }
+}
+
+swiftTest_4.2 <- function()
+{
+
+  options(swift.initialexpr="initVar3 <<- 123; initVar4 <<- 100");
+
+  mulivars <- function() { initVar3*initVar4 }
+
+  args=list()
+  arglist = rep(list(args),1)
+
+  localres = 12300;
+
+  cat("\nTest of swiftapply(mulivars,arglist)\n")
+  swiftres = swiftapply(mulivars,arglist)
+  cat("Swift result:\n")
+  print(swiftres)
+
+  if(identical(localres,swiftres[[1]])) {
+    cat("\n==> test 4.2 passed\n")
+  } else {
+    cat("\n==> test 4.2 FAILED !!!!!\n")
+  }
+}
+
+# Performance tests
+
+swiftTest_6.1 <- function(delay,ncalls)
+{
+  options(swift.initialexpr="initVar3 <<- 123; initVar4 <<- 100");
+
+  timed <- function(delay) { Sys.sleep(delay); delay }
+
+  args=list(delay)
+  arglist = rep(list(args),ncalls)
+
+  cat("\nTest of swiftapply(delay,arglist)\n")
+
+  startTime = proc.time()[["elapsed"]]
+  swiftres = swiftapply(timed,arglist)
+  endTime = proc.time()[["elapsed"]]
+  runTime <- endTime - startTime
+
+  cat("\n\n ===> Total elapsed unit test time = ",runTime," seconds.\n\n") 
+
+  cat("Swift result:\n")
+  print(swiftres[[1]])
+
+  if(identical(delay,swiftres[[1]])) {
+    cat("\n==> test 6.1 passed\n")
+  } else {
+    cat("\n==> test 6.1 FAILED !!!!!\n")
+  }
+
+}
+
+runAllSwiftTests <- function()
+{
+    # Launch workerif nothing already running
+    # testPid will be NULL if nothihg launched
+    testPid <- tryCatch(
+            (function() { swiftapply(log, list(list(1)),quiet=TRUE) ; 
+                          return(NULL); })(), 
+            error=function(x) {swiftInit();})
+
+    ### FIXME: Save prior options here: restore them when tests are done.  
+    ### Recovery if interrrupted?
+
+    failures=0
+
+    startTime = proc.time()[["elapsed"]]
+
+    cat("\n*** Starting test group 1 - functions on simple data structures ***\n\n")
+
+    swiftTest_1.1()
+
+    ##### Test 1.2
+
+    # test 10 remote calls
+
+    sumstuff <- function(treedata,cardata) { sum( treedata$Height, cardata$dist ) }
+    data(cars)
+    data(trees)
+
+    args=list(trees,cars)
+    arglist <- rep(list(args),10)
+
+    localres = do.call(sumstuff,args)
+
+    cat("\n*** Test 1.2.1: 10 calls to substuff()\n")
+    swiftres <- swiftapply(sumstuff,arglist)
+    cat("Swift result:\n")
+    format(swiftres)
+
+    diffs <- 0
+    for(i in 1:length(swiftres) ) {
+      if( !identical(swiftres[[i]],localres) ) { 
+        diffs <- diffs + 1
+        if( diffs < 10 ) cat(sprintf("res[%d]=%s\n",i,format( swiftres[[i]] )))
+      }
+    }
+
+    if(diffs == 0) {
+      cat("\n==> test 1.2.1 passed\n")
+    } else {
+      cat("\n!!!==> test 1.2.1 failed.\n")
+      cat(sprintf(" %d result elements failed to match.\n",diffs));
+      failures=failures+1
+    }
+
+    cat("\n*** Test 1.2.2: 10 calls to substuff() - callsperbatch=10\n")
+    swiftres = swiftapply(sumstuff,arglist,callsperbatch=10)
+    cat("Swift result:\n")
+    format(swiftres)
+
+    diffs <- 0
+    for(i in 1:length(swiftres) ) {
+      if( !identical(swiftres[[i]],localres) ) { 
+        diffs <- diffs + 1
+        if( diffs < 10 ) cat(sprintf("res[%d]=%s\n",i,format( swiftres[[i]] )))
+      }
+    }
+
+    if(diffs == 0) {
+      cat("\n==> test 1.2.2 passed\n")
+    } else {
+      cat("\n!!!==> test 1.2.2 failed.\n")
+      cat(sprintf(" %d result elements failed to match.\n",diffs));
+      failures=failures+1
+    }
+
+    cat("\n*** Test 1.2.3: 10 calls to substuff() - callsperbatch=2\n")
+    swiftres = swiftapply(sumstuff,arglist,callsperbatch=2)
+    cat("Swift result:\n")
+    format(swiftres)
+
+    diffs <- 0
+    for(i in 1:length(swiftres) ) {
+      if( !identical(swiftres[[i]],localres) ) { 
+        diffs <- diffs + 1
+        if( diffs < 10 ) cat(sprintf("res[%d]=%s\n",i, format( swiftres[[i]] )))
+      }
+    }
+
+    if(diffs == 0) {
+      cat("\n==> test 1.2.3 passed\n")
+    } else {
+      cat("\n!!!==> test 1.2.3 failed.\n")
+      cat(sprintf(" %d result elements failed to match.\n",diffs));
+      failures=failures+1
+    }
+
+    cat("\n*** Test 1.2.4: 10 calls to substuff() - callsperbatch=3\n")
+    swiftres = swiftapply(sumstuff,arglist,callsperbatch=3)
+    swiftres <- swiftapply(sumstuff,arglist)
+    cat("Swift result:\n")
+    format(swiftres)
+
+    diffs <- 0
+    for(i in 1:length(swiftres) ) {
+      if( !identical(swiftres[[i]],localres) ) { 
+        diffs <- diffs + 1
+        if( diffs < 10 ) cat(sprintf("res[%d]=%d\n",i, format( swiftres[[i]] )))
+      }
+    }
+
+    if(diffs == 0) {
+      cat("\n==> test 1.2.4 passed\n")
+    } else {
+      cat("\n!!!==> test 1.2.4 failed.\n")
+      cat(sprintf(" %d result elements failed to match.\n",diffs));
+      failures=failures+1
+    }
+
+    # swiftres = swiftapply(sumstuff,arglist,callsperbatch=2,site="pbs")
+    # test variations on local vs ssh vs pbs; coasters vs non; etc.
+
+
+
+    ##### Test Group  2
+
+    cat("\n*** Starting test group 2 - test matrix passing***\n")
+
+    matfunc <- function( m1, m2 )
+    {
+      (1/m1) %*% m2
+    }
+
+    n <- 5
+    m1 <- array(sin(1:n**2), dim=c(n,n))
+    m2 <- t(m1)
+
+    localres = matfunc(m1,m2)
+
+    cat("\n*** Test 2.1: 100 calls to matfunc(dim=5x5) - callsperbatch=9\n")
+
+    args=list(m1,m2)
+    arglist <- rep(list(args),100)
+
+    swiftres = swiftapply(matfunc,arglist,callsperbatch=9)
+
+    diffs <- 0
+    #for(i in 1:length(swiftres) ) {
+    for(i in c(seq(1,100,10),100)) {
+      if( !all.equal(swiftres[[i]],localres) ) { 
+        diffs <- diffs + 1
+        if( diffs < 10 ) cat(sprintf("res[%d]=%s\n",i,format(swiftres[[i]])))
+      }
+    }
+
+    if(diffs == 0) {
+      cat("\n==> test 2.1 passed\n")
+    } else {
+      cat("\n!!!==> test 2.2 failed.\n")
+      cat(sprintf(" %d result elements failed to match.\n",diffs));
+      failures=failures+1
+    }
+
+    n <- 237
+    n <- 50
+    m1 <- array(sin(1:n**2), dim=c(n,n))
+    m2 <- t(m1)
+
+    localres = matfunc(m1,m2)
+
+    cat("\n*** Test 2.2: 123 calls to matfunc(dim=bigger) - callsperbatch=7\n") # FIXME make n easy to adjust and print actual value
+
+    args=list(m1,m2)
+    arglist <- rep(list(args),123)
+
+    swiftres = swiftapply(matfunc,arglist,callsperbatch=7)
+
+    diffs <- 0
+    #for(i in 1:length(swiftres) ) {
+    for(i in c(seq(1,length(swiftres),10),length(swiftres))) {
+
+      if( !all.equal(swiftres[[i]],localres) ) { 
+        diffs <- diffs + 1
+        if( diffs < 10 ) cat(sprintf("res[%d]=%s\n",i,format(swiftres[[i]])))
+      }
+    }
+
+    if(diffs == 0) {
+      cat("\n==> test 2.2 passed\n")
+    } else {
+      cat("\n!!!==> test 2.2 failed.\n")
+      cat(sprintf(" %d result elements failed to match.\n",diffs));
+      failures=failures+1
+    }
+
+
+    ##### Test Group 3
+
+    cat("\n*** Starting test group 3 - test list element and name passing***\n")
+
+    # Test if list element names are being sent and returned correctly
+
+    n <- 5
+    m1 <- array(sin(1:n**2), dim=c(n,n))
+    m2 <- t(m1)
+
+    inlist = list()
+    inlist[[1]]=123
+    inlist[[2]]=456
+    inlist$name1=789
+    inlist$name2=987
+    inlist$mat1 =  m1
+    inlist[[99]] = m2
+
+    listfunc <- function(ilist)
+    {
+      olist = ilist
+      olist$sum = ilist[[1]] + ilist[[2]] + ilist$name1 + ilist$name2
+      olist$names = names(ilist)
+      olist$mprod = ilist$mat1 %*% ilist[[99]]
+      return(olist)
+    }
+    localres = listfunc(inlist)
+
+    cat("\n*** Starting test 3.1 - 4 calls in one batch of 5 ***\n")
+
+    args=list(inlist)
+    arglist <- rep(list(args),4)
+
+    swiftres = swiftapply(listfunc,arglist,callsperbatch=5)
+
+    diffs <- 0
+    for(i in 1:length(swiftres) ) {
+      if( !all.equal(swiftres[[i]],localres) ) { 
+        diffs <- diffs + 1
+        if( diffs < 10 ) cat(sprintf("res[%d=%s\n",i,format(swiftres[[i]])))
+      }
+    }
+
+    if(diffs == 0) {
+      cat("\n==> test 3.1 passed\n")
+    } else {
+      cat("\n!!!==> test 3.1 failed.\n")
+      cat(sprintf(" %d result elements failed to match.\n",diffs));
+      failures=failures+1
+    }
+
+    cat("\n*** Starting test 3.2 - 99 calls in batches of 11 ***\n")
+
+    args=list(inlist)
+    arglist <- rep(list(args),99)
+
+    swiftres = swiftapply(listfunc,arglist,callsperbatch=11)
+
+    diffs <- 0
+    for(i in 1:length(swiftres) ) {
+      if( !all.equal(swiftres[[i]],localres) ) { 
+        diffs <- diffs + 1
+        if( diffs < 10 ) cat(sprintf("res[%d]=%s\n",i,format(swiftres[[i]])))
+      }
+    }
+
+    if(diffs == 0) {
+      cat("\n==> test 3.2 passed\n")
+    } else {
+      cat("\n!!!==> test 3.2 failed.\n")
+      cat(sprintf(" %d result elements failed to match.\n",diffs));
+      failures=failures+1
+    }
+
+    ##### Test Group 4 # test initialexpr string
+
+    cat("\n*** Starting test group 4 - test remote R service initialization string ***\n")
+
+    swiftTest_4.1()
+    swiftTest_4.2()
+
+
+
+
+    ##### Test Group 5 # test error handling
+
+    cat("\n*** Starting test group 5 - test remote R service error ***\n")
+
+    arglist = list(list(1.0),list(2.0),list("3.0"),list(4.0),list(5.0))
+
+    cat("\nTest of swiftapply(sumivars,arglist)\n")
+    swiftres = swiftapply(log,arglist)
+    cat("Swift result:\n")
+    print(swiftres)
+
+    goodres = c("numeric","numeric","try-error","numeric","numeric")
+
+    diffs <- 0
+    for(i in 1:length(swiftres) ) {
+      if( class(swiftres[[i]]) != goodres[i] ) { 
+        diffs <- diffs + 1
+        if( diffs < 10 ) cat(sprintf("res[%d]=%s\n",i,format(swiftres[[i]])))
+      }
+    }
+
+    if(diffs == 0) {
+      cat("\n==> test 5.1 passed\n")
+    } else {
+      cat("\n!!!==> test 5.1 failed.\n")
+      cat(sprintf(" %d result elements failed to match.\n",diffs));
+      failures=failures+1
+    }
+
+    endTime <- proc.time()[["elapsed"]]
+    runTime <- endTime - startTime
+
+    cat("\n\n ===> Total elapsed test time = ",runTime," seconds.\n\n") 
+    if (!is.null(testPid))
+        swiftShutdown(testPid)
+} # end function runAllTests
+
+#options(swift.site="local")
+#runAllTests()
+
+testloop <- function(npass)
+{
+  for(i in 1:npass) {
+    cat("\n\n\n ***** Starting test pass ", i, " ***** \n\n\n");
+    runAllSwiftTests()
+    cat("\n\n\n ***** Completed test pass ", i, " ***** \n\n\n");
+    system("sleep 3")
+  }
+}




More information about the Swift-commit mailing list