[Swift-commit] r4078 - in SwiftApps/SwiftR: . Swift Swift/R Swift/tests

noreply at svn.ci.uchicago.edu noreply at svn.ci.uchicago.edu
Thu Feb 10 08:36:11 CST 2011


Author: tga
Date: 2011-02-10 08:36:10 -0600 (Thu, 10 Feb 2011)
New Revision: 4078

Added:
   SwiftApps/SwiftR/Swift/R/TestFramework.R
   SwiftApps/SwiftR/Swift/tests/runtests.R
Removed:
   SwiftApps/SwiftR/Swift/tests/TestSwift.R
Modified:
   SwiftApps/SwiftR/Makefile
   SwiftApps/SwiftR/Swift/NAMESPACE
   SwiftApps/SwiftR/Swift/R/Tests.R
Log:
Revamped test suite: now we represent testsuite as a data structure, and provide functions to run tests, collect results and timing.  and present a summary of test correctness, performance.  Added a target "test" to the makefile. 
This serves two purposes:
    * Encourage regular running of test suite and addition of tests to preserver developer sanity
    * Basis for benchmarks: timing results for each test function are collected in a list

* Tobe implemented later: parameters to runtests file to allow testing of different servers, etc.





Modified: SwiftApps/SwiftR/Makefile
===================================================================
--- SwiftApps/SwiftR/Makefile	2011-02-10 14:32:42 UTC (rev 4077)
+++ SwiftApps/SwiftR/Makefile	2011-02-10 14:36:10 UTC (rev 4078)
@@ -37,6 +37,9 @@
 check: $(TBALL)
 	R CMD check $(TBALL)
 
+test: install
+	./Swift/tests/runtests.R
+
 clean: 
 	rm -rf Swift/inst/swift/*
 	rm $(TBALL)

Modified: SwiftApps/SwiftR/Swift/NAMESPACE
===================================================================
--- SwiftApps/SwiftR/Swift/NAMESPACE	2011-02-10 14:32:42 UTC (rev 4077)
+++ SwiftApps/SwiftR/Swift/NAMESPACE	2011-02-10 14:36:10 UTC (rev 4078)
@@ -13,3 +13,10 @@
 export(runAllSwiftTests)
 export(basicSwiftTest)
 exportPattern("^swiftTest")
+export(makeTestGroup)
+export(runTestGroup)
+export(runTestSuite)
+exportPattern("^testGroup")
+export(swiftTestSuite)
+export(printTestGroup)
+export(mkTest)

Added: SwiftApps/SwiftR/Swift/R/TestFramework.R
===================================================================
--- SwiftApps/SwiftR/Swift/R/TestFramework.R	                        (rev 0)
+++ SwiftApps/SwiftR/Swift/R/TestFramework.R	2011-02-10 14:36:10 UTC (rev 4078)
@@ -0,0 +1,66 @@
+# Generic functions for running and displaying results
+# from a suite of tests
+
+mkTest <- function (f) {
+    test = list()
+    test$name = substitute(f)
+    test$fun = f
+    test$passed = NULL
+    return (test)
+}
+
+makeTestGroup <- function (name, tlist, init=NULL) {
+    group = list()
+    group$init = init
+    group$tests = tlist
+    return (group)
+}
+
+runTestGroup <- function (group) {
+    cat("\n*** Starting test group ", group$name, "***\n")
+    if (!is.null(group$init))
+        group$init()
+    for (i in 1:length(group$tests)) {
+        test <- group$tests[[i]]
+        cat("\n== Starting test ", test$name, " ==\n")
+        startTime = proc.time()[["elapsed"]]
+        group$tests[[i]]$passed <- try(test$fun())
+        endTime <- proc.time()[["elapsed"]]
+        runTime <- endTime - startTime
+        group$tests[[i]]$time <- runTime
+        
+    }
+    return (group)
+}
+
+printTestGroup <- function (group) {
+    cat("\n*** Test group ", group$name, "***\n")
+    resFmt <- function(res) { 
+        if (is.null(res)) {
+            "???"
+        } else {
+            if (inherits(res, "try-error")) 
+                {paste("ERROR: '", res, "'") }
+            else
+                {if (res) "PASSED" else "FAILED"}
+            }
+        }
+    timeFmt <- function (time) {
+        if (is.null(time)) 
+            "???"
+        else    
+            sprintf("%.2f", time)
+    }
+    for (test in group$tests) {
+        cat(paste(test$name, ": ", resFmt(test$passed), 
+                " (", timeFmt(test$time), ")\n", sep=""))
+    }
+}
+
+runTestSuite <- function (suite) {
+    suite$setup()
+    resSuite <- lapply(suite$tests, runTestGroup)
+    lapply(resSuite, printTestGroup)
+    suite$teardown()
+    return (NULL)
+}

Modified: SwiftApps/SwiftR/Swift/R/Tests.R
===================================================================
--- SwiftApps/SwiftR/Swift/R/Tests.R	2011-02-10 14:32:42 UTC (rev 4077)
+++ SwiftApps/SwiftR/Swift/R/Tests.R	2011-02-10 14:36:10 UTC (rev 4078)
@@ -1,21 +1,18 @@
 
-
-initSwiftTestOptions <- function()
-{
+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
+  options(swift.initialexpr=initcmds) # Set here; used in test group}
+  # FIXME: Save prior options here: restore them when tests are done.  
 }
 
 
 
+basicSwiftTest <- function() { swiftTest_1.1() }
 
-swiftTest_1.1 <- function()
-{
+swiftTest_1.1 <- function() {
 
-  initSwiftTestOptions()
-
   cat("\n*** Starting  test 1.1 ***\n\n")
 
   sumstuff <- function(treedata,cardata) { sum( treedata$Height, cardata$dist ) }
@@ -37,207 +34,18 @@
 
   if(identical(localres,swiftres[[1]])) {
     cat("\n==> test 1.1 passed\n")
+    return (TRUE)
   } else {
     cat("\n==> test 1.1 FAILED !!!!!\n")
+    return (FALSE)
   }
 }
 
-#1.3.* tests export functionality
-swiftTest_1.3.1 <- function()
-{
 
-  initSwiftTestOptions()
-
-  cat("\n*** Starting  test 1.3.1 ***\n\n")
-  y <- 1
-  inc <- function(x) { x + y }
-
-  arglist = list(1,2,3,4,5,6,7,8,9)
-
-  cat("Test of local lapply\n")
-  localres = lapply(arglist, inc)
-  cat("local result=\n")
-  print(localres)
-
-  # Test swiftExport
-  swiftExport(y)
-  cat("\nTest of swiftLapply\n")
-  swiftres = swiftLapply(arglist, inc)
-  cat("Swift result:\n")
-  print(swiftres)
-
-  if(identical(localres,swiftres)) {
-    cat("\n==> test 1.3.1 passed\n")
-  } else {
-    cat("\n==> test 1.3.1 FAILED !!!!!\n")
-  }
-}
-
-swiftTest_1.3.2 <- function()
-{
- # Test swiftExportAll()
-
-  cat("\n*** Starting  test 1.3.2 ***\n\n")
-  y <<- 1
-  inc <- function(x) { x + y }
-
-  arglist = list(1,2,3,4,5,6,7,8,9)
-
-  cat("Test of local lapply\n")
-  localres = lapply(arglist, inc)
-  cat("local result=\n")
-  print(localres)
-
-  # Test swiftExport
-  swiftExportAll()
-  cat("\nTest of swiftLapply\n")
-  swiftres = swiftLapply(arglist, inc)
-  cat("Swift result:\n")
-  print(swiftres)
-
-  if(identical(localres,swiftres)) {
-    cat("\n==> test 1.3.2 passed\n")
-  } else {
-    cat("\n==> test 1.3.2 FAILED !!!!!\n")
-  }
-}
-
-
-swiftTest_1.3.3 <- function()
-{
-
-  initSwiftTestOptions()
-
-  cat("\n*** Starting  test 1.3.3 ***\n\n")
-  y <- 1
-  inc <- function(x) { x + y }
-
-  arglist = list(1,2,3,4)
-
-  # Test swiftExportAll
-  swiftExportAll()
-  cat("\nTest of swiftLapply\n")
-  swiftres = swiftLapply(arglist, inc)
-  cat("Swift result before removal:\n")
-  print(swiftres)
-
-  swiftRemoveAll()
-  swiftres = swiftLapply(arglist, inc)
-  cat("Swift result after removal:\n")
-  for (e in swiftres) {
-    if (!inherits(e, "try-error")) {
-        cat("\n==> test 1.3.3 FAILED !!!!!\n")
-        return()
-    }
-  }
-  cat("\n==> test 1.3.3 passed\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
-
+swiftTest_1.2.1 <- function () {
     # test 10 remote calls
-
-    sumstuff <- function(treedata,cardata) { sum( treedata$Height, cardata$dist ) }
+    sumstuff <- function(treedata,cardata) 
+        { sum( treedata$Height, cardata$dist ) }
     data(cars)
     data(trees)
 
@@ -246,7 +54,6 @@
 
     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)
@@ -261,13 +68,27 @@
 
     if(diffs == 0) {
       cat("\n==> test 1.2.1 passed\n")
+      return (TRUE)
     } else {
       cat("\n!!!==> test 1.2.1 failed.\n")
       cat(sprintf(" %d result elements failed to match.\n",diffs));
       failures=failures+1
+      return (FALSE)
     }
+}
 
-    cat("\n*** Test 1.2.2: 10 calls to substuff() - callsperbatch=10\n")
+swiftTest_1.2.2 <- function () {
+    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("*** 10 calls to sumstuff() - callsperbatch=10\n")
     swiftres = swiftapply(sumstuff,arglist,callsperbatch=10)
     cat("Swift result:\n")
     format(swiftres)
@@ -282,13 +103,27 @@
 
     if(diffs == 0) {
       cat("\n==> test 1.2.2 passed\n")
+      return (TRUE)
     } else {
       cat("\n!!!==> test 1.2.2 failed.\n")
       cat(sprintf(" %d result elements failed to match.\n",diffs));
       failures=failures+1
+      return (FALSE)
     }
+}
 
-    cat("\n*** Test 1.2.3: 10 calls to substuff() - callsperbatch=2\n")
+swiftTest_1.2.3 <- function () {
+    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("*** 10 calls to substuff() - callsperbatch=2\n")
     swiftres = swiftapply(sumstuff,arglist,callsperbatch=2)
     cat("Swift result:\n")
     format(swiftres)
@@ -303,13 +138,29 @@
 
     if(diffs == 0) {
       cat("\n==> test 1.2.3 passed\n")
+      return (TRUE)
     } else {
       cat("\n!!!==> test 1.2.3 failed.\n")
       cat(sprintf(" %d result elements failed to match.\n",diffs));
       failures=failures+1
+      return (FALSE)
     }
 
-    cat("\n*** Test 1.2.4: 10 calls to substuff() - callsperbatch=3\n")
+}
+
+
+swiftTest_1.2.4 <- function () {
+    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("*** 10 calls to substuff() - callsperbatch=3\n")
     swiftres = swiftapply(sumstuff,arglist,callsperbatch=3)
     swiftres <- swiftapply(sumstuff,arglist)
     cat("Swift result:\n")
@@ -325,23 +176,180 @@
 
     if(diffs == 0) {
       cat("\n==> test 1.2.4 passed\n")
+      return (TRUE)
     } else {
       cat("\n!!!==> test 1.2.4 failed.\n")
       cat(sprintf(" %d result elements failed to match.\n",diffs));
       failures=failures+1
+      return (FALSE)
     }
+}
 
-    # swiftres = swiftapply(sumstuff,arglist,callsperbatch=2,site="pbs")
-    # test variations on local vs ssh vs pbs; coasters vs non; etc.
+#1.3.* tests export functionality
+swiftTest_1.3.1 <- function() {
 
-    swiftTest_1.3.1()
-    swiftTest_1.3.2()
-    swiftTest_1.3.3()
+  cat("\n*** Starting  test 1.3.1 ***\n\n")
+  y <- 1
+  inc <- function(x) { x + y }
 
-    ##### Test Group  2
+  arglist = list(1,2,3,4,5,6,7,8,9)
 
-    cat("\n*** Starting test group 2 - test matrix passing***\n")
+  cat("Test of local lapply\n")
+  localres = lapply(arglist, inc)
+  cat("local result=\n")
+  print(localres)
 
+  # Test swiftExport
+  swiftExport(y)
+  rm(y) # Remove y here so that swift can't resolve locally
+  cat("\nTest of swiftLapply\n")
+  swiftres = swiftLapply(arglist, inc)
+  cat("Swift result:\n")
+  print(swiftres)
+
+  if(identical(localres,swiftres)) {
+    cat("\n==> test 1.3.1 passed\n")
+    return(TRUE)
+  } else {
+    cat("\n==> test 1.3.1 FAILED !!!!!\n")
+    return(FALSE)
+  }
+}
+
+swiftTest_1.3.2 <- function() {
+ # Test swiftExportAll()
+
+  cat("\n*** Starting  test 1.3.2 ***\n\n")
+  # put in global environment so we can test global env
+  swift.tmp.y <<- 1
+  inc <- function(x) { x + swift.tmp.y }
+
+  arglist = list(1,2,3,4,5,6,7,8,9)
+
+  cat("Test of local lapply\n")
+  localres = lapply(arglist, inc)
+  cat("local result=\n")
+  print(localres)
+
+  # Test swiftExport
+  swiftExportAll()
+
+  # Remove y here so that swift can't resolve locally
+  rm(swift.tmp.y, envir=globalenv())   
+  cat("\nTest of swiftLapply\n")
+  swiftres = swiftLapply(arglist, inc)
+  cat("Swift result:\n")
+  print(swiftres)
+
+  if(identical(localres,swiftres)) {
+    cat("\n==> test 1.3.2 passed\n")
+    return(TRUE)
+  } else {
+    cat("\n==> test 1.3.2 FAILED !!!!!\n")
+    return (FALSE)
+  }
+}
+
+
+swiftTest_1.3.3 <- function() {
+
+  cat("\n*** Starting  test 1.3.3 ***\n\n")
+  y <- 1
+  inc <- function(x) { x + y }
+
+  arglist = list(1,2,3,4)
+
+  # Test swiftExportAll
+  swiftExportAll()
+  rm(y) # Remove y here so that swift can't resolve locally
+  cat("\nTest of swiftLapply\n")
+  swiftres1 <- swiftLapply(arglist, inc)
+  cat("Swift result before removal:\n")
+  print(swiftres1)
+
+  swiftRemoveAll()
+  inc2 <- function(x) { x + y }
+
+  swiftres2 <- swiftLapply(arglist, inc)
+  cat("Swift result after removal:\n")
+  print(swiftres2)
+  for (e in swiftres2) {
+    if (!inherits(e, "try-error")) {
+        cat("\n==> test 1.3.3 FAILED !!!!!\n")
+        return (FALSE)
+        return()
+    }
+  }
+  cat("\n==> test 1.3.3 passed\n")
+  return(TRUE)
+}
+
+swiftTest_1.3.4 <- function () {
+  # This test demonstrates a case where a variable
+  # does not need to be exported.
+  cat("\n*** Starting  test 1.3.4 ***\n\n")
+  swiftRemoveAll() # Cleanup
+  y <- 1
+  inc <- function(x) { x + y }
+  # DONT export
+  arglist = list(1,2,3,4,5,6,7,8,9)
+
+  cat("Test of local lapply\n")
+  localres = lapply(arglist, inc)
+  cat("local result=\n")
+  print(localres)
+
+  cat("\nTest of swiftLapply\n")
+  swiftres = swiftLapply(arglist, inc)
+  cat("Swift result:\n")
+  print(swiftres)
+
+  if(identical(localres,swiftres)) {
+    cat("\n==> test 1.3.4 passed\n")
+    return(TRUE)
+  } else {
+    cat("\n==> test 1.3.4 FAILED !!!!!\n")
+    return (FALSE)
+  }
+}
+
+
+swiftTest_1.3.5 <- function () {
+  # This test demonstrates a case where a variable
+  # does not need to be exported 
+
+  cat("\n*** Starting  test 1.3.5 ***\n\n")
+  swiftRemoveAll() # Cleanup
+  f_inc <- function (z) { z + 1 }
+  f <- function () {
+      # Use another function
+      inc <- function(x) { f_inc(x) }
+      # DONT export
+      arglist = list(1,2,3,4,5,6,7,8,9)
+
+      cat("Test of local lapply\n")
+      localres = lapply(arglist, inc)
+      cat("local result=\n")
+      print(localres)
+
+      cat("\nTest of swiftLapply\n")
+      swiftres = swiftLapply(arglist, inc)
+      cat("Swift result:\n")
+      print(swiftres)
+
+      if(identical(localres,swiftres)) {
+        cat("\n==> test 1.3.5 passed\n")
+        return (TRUE)
+      } else {
+        cat("\n==> test 1.3.5 FAILED !!!!!\n")
+        return (FALSE)
+      }
+  }
+  f()
+}
+
+
+swiftTest_2.1 <- function() {
     matfunc <- function( m1, m2 )
     {
       (1/m1) %*% m2
@@ -361,9 +369,8 @@
     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) ) { 
+      if( !all.equal(swiftres[[i]],localres) ) {
         diffs <- diffs + 1
         if( diffs < 10 ) cat(sprintf("res[%d]=%s\n",i,format(swiftres[[i]])))
       }
@@ -371,12 +378,20 @@
 
     if(diffs == 0) {
       cat("\n==> test 2.1 passed\n")
+      return (TRUE)
     } else {
-      cat("\n!!!==> test 2.2 failed.\n")
+      cat("\n!!!==> test 2.1 failed.\n")
       cat(sprintf(" %d result elements failed to match.\n",diffs));
       failures=failures+1
+      return (FALSE)
     }
+}
 
+swiftTest_2.2 <- function() {
+    matfunc <- function( m1, m2 )
+    {
+      (1/m1) %*% m2
+    }
     n <- 237
     n <- 50
     m1 <- array(sin(1:n**2), dim=c(n,n))
@@ -384,7 +399,7 @@
 
     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
+    cat("\n*** 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)
@@ -392,7 +407,6 @@
     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) ) { 
@@ -403,19 +417,16 @@
 
     if(diffs == 0) {
       cat("\n==> test 2.2 passed\n")
+      return (TRUE)
     } else {
       cat("\n!!!==> test 2.2 failed.\n")
       cat(sprintf(" %d result elements failed to match.\n",diffs));
       failures=failures+1
+      return (FALSE)
     }
+}
 
-
-    ##### 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
-
+data_3.1 <- function () {
     n <- 5
     m1 <- array(sin(1:n**2), dim=c(n,n))
     m2 <- t(m1)
@@ -427,23 +438,28 @@
     inlist$name2=987
     inlist$mat1 =  m1
     inlist[[99]] = m2
+    return (inlist)
+}
 
-    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)
+listfunc_3.1 <- 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)
+}
 
+swiftTest_3.1 <- function() {
+  #Test if list element names are being sent and returned correctly
+    inlist <- data_3.1() 
+    localres = listfunc_3.1(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)
+    swiftres = swiftapply(listfunc_3.1,arglist,callsperbatch=5)
 
     diffs <- 0
     for(i in 1:length(swiftres) ) {
@@ -455,18 +471,25 @@
 
     if(diffs == 0) {
       cat("\n==> test 3.1 passed\n")
+      return (TRUE)
     } else {
       cat("\n!!!==> test 3.1 failed.\n")
       cat(sprintf(" %d result elements failed to match.\n",diffs));
       failures=failures+1
+      return (FALSE)
     }
+}
 
+swiftTest_3.2 <- function() {
+    inlist <- data_3.1() 
+    localres = listfunc_3.1(inlist)
     cat("\n*** Starting test 3.2 - 99 calls in batches of 11 ***\n")
 
+    inlist <- data_3.1() 
     args=list(inlist)
     arglist <- rep(list(args),99)
 
-    swiftres = swiftapply(listfunc,arglist,callsperbatch=11)
+    swiftres = swiftapply(listfunc_3.1,arglist,callsperbatch=11)
 
     diffs <- 0
     for(i in 1:length(swiftres) ) {
@@ -478,26 +501,67 @@
 
     if(diffs == 0) {
       cat("\n==> test 3.2 passed\n")
+      return (TRUE)
     } else {
       cat("\n!!!==> test 3.2 failed.\n")
       cat(sprintf(" %d result elements failed to match.\n",diffs));
       failures=failures+1
+      return (FALSE)
     }
 
-    ##### Test Group 4 # test initialexpr string
+}
 
-    cat("\n*** Starting test group 4 - test remote R service initialization string ***\n")
+swiftTest_4.1 <- function() {
+  sumivars <- function() { initVar1+initVar2 }
 
-    swiftTest_4.1()
-    swiftTest_4.2()
+  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")
+    return (TRUE)
+  } else {
+    cat("\n==> test 4.1 FAILED !!!!!\n")
+    return (FALSE)
+  }
+}
 
-    ##### Test Group 5 # test error handling
+swiftTest_4.2 <- function() {
 
-    cat("\n*** Starting test group 5 - test remote R service error ***\n")
+  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")
+    return (TRUE)
+  } else {
+    cat("\n==> test 4.2 FAILED !!!!!\n")
+    return (FALSE)
+  }
+}
+
+swiftTest_5.1 <- function () {
+    # Test error handling
+    cat("\n*** Starting test group 5 - test ***\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")
@@ -517,22 +581,62 @@
 
     if(diffs == 0) {
       cat("\n==> test 5.1 passed\n")
+      return (TRUE)
     } else {
       cat("\n!!!==> test 5.1 failed.\n")
       cat(sprintf(" %d result elements failed to match.\n",diffs));
       failures=failures+1
+      return (FALSE)
     }
+}
 
+swiftTest_6.1.1 <- function () {
+    swiftTest_6.1(2, 20)
+}
+
+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")
+    return (TRUE)
+  } else {
+    cat("\n==> test 6.1 FAILED !!!!!\n")
+    return (FALSE)
+  }
+
+}
+
+runAllSwiftTests <- function() {
+
+    startTime = proc.time()[["elapsed"]]
+
+
+    runTestSuite(swiftTestSuite)
+
     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)
 {
@@ -543,3 +647,52 @@
     system("sleep 3")
   }
 }
+
+
+testGroup1.1 <- list( init=NULL,
+    name="1.1 Sanity Check",
+    tests = list(mkTest(swiftTest_1.1)))
+
+testGroup1.2 <- list( init=NULL, 
+    name="1.2 Basic Test - Adding data sets",
+    tests = list(mkTest(swiftTest_1.2.1),
+        mkTest(swiftTest_1.2.2), mkTest(swiftTest_1.2.3),
+        mkTest(swiftTest_1.2.4)))
+
+testGroup1.3 <- list( init=NULL, 
+    name="1.3 - Export functionality",
+    tests = list(mkTest(swiftTest_1.3.1),
+        mkTest(swiftTest_1.3.2), mkTest(swiftTest_1.3.3),
+        mkTest(swiftTest_1.3.4),  mkTest(swiftTest_1.3.5)) )
+
+testGroup2 <- list( init=NULL, 
+    name="2 - test matrix passing",
+    tests = list(mkTest(swiftTest_2.1),
+        mkTest(swiftTest_2.2)) )
+
+testGroup3 <- list( init=NULL, 
+    name="3 - test list element and name passing",
+    tests = list(mkTest(swiftTest_3.1),
+        mkTest(swiftTest_3.2)))
+
+testGroup4 <- list( init=NULL, 
+    name="4 - test remote R service initialization string",
+    tests = list(mkTest(swiftTest_4.1),
+        mkTest(swiftTest_4.2)))
+
+testGroup5 <- list( init=NULL, 
+    name="5 - remote R service error ",
+    tests = list(mkTest(swiftTest_5.1)))
+
+testGroup6 <- list( init=NULL,
+    name="6 - performance tests",
+    tests = list(mkTest(swiftTest_6.1.1)))
+
+
+swiftTestSuite <- list(
+        setup=function () { initSwiftTestOptions();
+                           swiftInit() }, # swiftInit controlled via options
+        tests=list(testGroup1.1, testGroup2, testGroup1.2, testGroup1.3, testGroup3, testGroup4,
+            testGroup5, testGroup6), 
+        teardown=function () { swiftShutdown() })
+

Deleted: SwiftApps/SwiftR/Swift/tests/TestSwift.R
===================================================================
--- SwiftApps/SwiftR/Swift/tests/TestSwift.R	2011-02-10 14:32:42 UTC (rev 4077)
+++ SwiftApps/SwiftR/Swift/tests/TestSwift.R	2011-02-10 14:36:10 UTC (rev 4078)
@@ -1,99 +0,0 @@
-
-##### Setup
-
-# To paste for quick testing: ###########
-
-if (FALSE) {
-
-require(Swift)
-
-initcmds <- "
-initVar1 <- 19
-initVar2 <- sqrt(400)+3
-"
-
-failures=0
-
-options(swift.initialize=initcmds) # Set here; used in test group 4
-
-sumstuff <- function(treedata,cardata) { sum( treedata$Height, cardata$dist ) }
-data(cars)
-data(trees)
-
-args=list(trees,cars)
-arglist = rep(list(args),1)
-
-swiftres = swiftapply(sumstuff,arglist)
-
-
-} ####################################
-
-require(Swift)
-
-runAllSwiftTests()
-
-
-
-if(FALSE) { # Test various batch sizes
-
-    cat("\nTest of swiftapply(sumcrits,arglist,callsperbatch=10)\n")
-    res = swiftapply(sumcrits,arglist,callsperbatch=10)
-    print(res)
-
-    cat("\nTest of swiftapply(sumcrits,arglist,callsperbatch=2)\n")
-    res = swiftapply(sumcrits,arglist,callsperbatch=2)
-    print(res)
-
-    cat("\nTest of swiftapply(sumcrits,arglist,callsperbatch=3)\n")
-    res = swiftapply(sumcrits,arglist,callsperbatch=3)
-    print(res)
-
-    cat("\nTest of swiftapply(sumcrits,arglist,callsperbatch=20)\n")
-    res = swiftapply(sumcrits,arglist,callsperbatch=20)
-    print(res)
-}
-
-if(FALSE) { # Larger-scale tests
-
-    cat("\nTest of swiftapply(sumcrits,arglist[1000],callsperbatch=1)\n")
-
-    arglist = rep(list(args),100)
-#    res = swiftapply(sumcrits,arglist,callsperbatch=2,site="pbs")
-    res = swiftapply(sumcrits,arglist,callsperbatch=2)
-
-    print(res[[1]])
-    print(res[[1000]])
-}
-
-if(FALSE) { # OLD test 5
-
-#### Test Group 5: test passive mode (make this start of multiple config tests?)
-
-cat("\n*** Starting  test 5.1 ***\n\n")
-
-options(swift.site="passive")
-
-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")
-}
-
-} # end if(FALSE)

Added: SwiftApps/SwiftR/Swift/tests/runtests.R
===================================================================
--- SwiftApps/SwiftR/Swift/tests/runtests.R	                        (rev 0)
+++ SwiftApps/SwiftR/Swift/tests/runtests.R	2011-02-10 14:36:10 UTC (rev 4078)
@@ -0,0 +1,5 @@
+#!/bin/env Rscript
+
+library(Swift)
+#TODO: take command line options to setup options
+runAllSwiftTests()


Property changes on: SwiftApps/SwiftR/Swift/tests/runtests.R
___________________________________________________________________
Name: svn:executable
   + *




More information about the Swift-commit mailing list