Skip to content

Commit

Permalink
memtest can be 1 (gc before ps) or 2 (gc after ps); thanks Jan
Browse files Browse the repository at this point in the history
  • Loading branch information
mattdowle committed Nov 8, 2022
1 parent c211009 commit 997c4ab
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 6 deletions.
11 changes: 7 additions & 4 deletions R/test.data.table.R
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
test.data.table = function(script="tests.Rraw", verbose=FALSE, pkg=".", silent=FALSE, showProgress=interactive()&&!silent,
memtest=as.logical(Sys.getenv("TEST_DATA_TABLE_MEMTEST", "FALSE"))) {
memtest=Sys.getenv("TEST_DATA_TABLE_MEMTEST", 0)) {
stopifnot(isTRUEorFALSE(verbose), isTRUEorFALSE(silent), isTRUEorFALSE(showProgress))
memtest = as.integer(memtest)
stopifnot(length(memtest)==1L, memtest %in% 0:2)
if (exists("test.data.table", .GlobalEnv, inherits=FALSE)) {
# package developer
# nocov start
Expand Down Expand Up @@ -124,7 +126,7 @@ test.data.table = function(script="tests.Rraw", verbose=FALSE, pkg=".", silent=F
on.exit(setwd(owd))

if (memtest) {
catf("\n***\n*** memtest=TRUE. This should be the first task in a fresh R session for best results. Ctrl-C now if not.\n***\n\n")
catf("\n***\n*** memtest=%d. This should be the first task in a fresh R session for best results. Ctrl-C now if not.\n***\n\n", memtest)
if (is.na(ps_mem())) stopf("memtest intended for Linux. Step through ps_mem() to see what went wrong.")
}

Expand Down Expand Up @@ -277,8 +279,9 @@ test = function(num,x,y=TRUE,error=NULL,warning=NULL,message=NULL,output=NULL,no
took = proc.time()[3L]-lasttime # so that prep time between tests is attributed to the following test
timings[as.integer(num), `:=`(time=time+took, nTest=nTest+1L), verbose=FALSE]
if (memtest) {
gc() # force gc so we can find tests that use relatively larger amounts of RAM
if (memtest==1L) gc() # see #5515 for before/after
timings[as.integer(num), RSS:=max(ps_mem(),RSS), verbose=FALSE]
if (memtest==2L) gc()
}
assign("lasttime", proc.time()[3L], parent.frame(), inherits=TRUE) # after gc() to exclude gc() time from next test when memtest
} )
Expand All @@ -293,7 +296,7 @@ test = function(num,x,y=TRUE,error=NULL,warning=NULL,message=NULL,output=NULL,no
# not be flushed to the output upon segfault, depending on OS).
} else {
# not `test.data.table` but developer running tests manually; i.e. `cc(F); test(...)`
memtest = FALSE # nocov
memtest = 0L # nocov
filename = NA_character_ # nocov
foreign = FALSE # nocov ; assumes users of 'cc(F); test(...)' has LANGUAGE=en
showProgress = FALSE # nocov
Expand Down
4 changes: 2 additions & 2 deletions man/test.data.table.Rd
Original file line number Diff line number Diff line change
Expand Up @@ -8,15 +8,15 @@
test.data.table(script = "tests.Rraw", verbose = FALSE, pkg = ".",
silent = FALSE,
showProgress = interactive() && !silent,
memtest = as.logical(Sys.getenv("TEST_DATA_TABLE_MEMTEST", "FALSE")))
memtest = Sys.getenv("TEST_DATA_TABLE_MEMTEST", 0))
}
\arguments{
\item{script}{ Run arbitrary R test script. }
\item{verbose}{ \code{TRUE} sets \code{options(datatable.verbose=TRUE)} for the duration of the tests. This tests there are no errors in the branches that produce the verbose output, and produces a lot of output. The output is normally used for tracing bugs or performance tuning. Tests which specifically test the verbose output is correct (typically looking for an expected substring) always run regardless of this option. }
\item{pkg}{ Root directory name under which all package content (ex: DESCRIPTION, src/, R/, inst/ etc..) resides. Used only in \emph{dev-mode}. }
\item{silent}{ Controls what happens if a test fails. Like \code{silent} in \code{\link{try}}, \code{TRUE} causes the error message to be suppressed and \code{FALSE} to be returned, otherwise the error is returned. }
\item{showProgress}{ Output 'Running test <n> ...\\r' at the start of each test? }
\item{memtest}{ Measure and report memory usage of tests rather than time taken. Intended for and tested on Linux. }
\item{memtest}{ Measure and report memory usage of tests (1:gc before ps, 2:gc after ps) rather than time taken (0) by default. Intended for and tested on Linux. See PR #5515 for more details. }
}
\details{
Runs a series of tests. These can be used to see features and examples of usage, too. Running test.data.table will tell you the full location of the test file(s) to open.
Expand Down

0 comments on commit 997c4ab

Please sign in to comment.