Skip to content

Commit 997c4ab

Browse files
committed
memtest can be 1 (gc before ps) or 2 (gc after ps); thanks Jan
1 parent c211009 commit 997c4ab

File tree

2 files changed

+9
-6
lines changed

2 files changed

+9
-6
lines changed

R/test.data.table.R

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,8 @@
11
test.data.table = function(script="tests.Rraw", verbose=FALSE, pkg=".", silent=FALSE, showProgress=interactive()&&!silent,
2-
memtest=as.logical(Sys.getenv("TEST_DATA_TABLE_MEMTEST", "FALSE"))) {
2+
memtest=Sys.getenv("TEST_DATA_TABLE_MEMTEST", 0)) {
33
stopifnot(isTRUEorFALSE(verbose), isTRUEorFALSE(silent), isTRUEorFALSE(showProgress))
4+
memtest = as.integer(memtest)
5+
stopifnot(length(memtest)==1L, memtest %in% 0:2)
46
if (exists("test.data.table", .GlobalEnv, inherits=FALSE)) {
57
# package developer
68
# nocov start
@@ -124,7 +126,7 @@ test.data.table = function(script="tests.Rraw", verbose=FALSE, pkg=".", silent=F
124126
on.exit(setwd(owd))
125127

126128
if (memtest) {
127-
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")
129+
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)
128130
if (is.na(ps_mem())) stopf("memtest intended for Linux. Step through ps_mem() to see what went wrong.")
129131
}
130132

@@ -277,8 +279,9 @@ test = function(num,x,y=TRUE,error=NULL,warning=NULL,message=NULL,output=NULL,no
277279
took = proc.time()[3L]-lasttime # so that prep time between tests is attributed to the following test
278280
timings[as.integer(num), `:=`(time=time+took, nTest=nTest+1L), verbose=FALSE]
279281
if (memtest) {
280-
gc() # force gc so we can find tests that use relatively larger amounts of RAM
282+
if (memtest==1L) gc() # see #5515 for before/after
281283
timings[as.integer(num), RSS:=max(ps_mem(),RSS), verbose=FALSE]
284+
if (memtest==2L) gc()
282285
}
283286
assign("lasttime", proc.time()[3L], parent.frame(), inherits=TRUE) # after gc() to exclude gc() time from next test when memtest
284287
} )
@@ -293,7 +296,7 @@ test = function(num,x,y=TRUE,error=NULL,warning=NULL,message=NULL,output=NULL,no
293296
# not be flushed to the output upon segfault, depending on OS).
294297
} else {
295298
# not `test.data.table` but developer running tests manually; i.e. `cc(F); test(...)`
296-
memtest = FALSE # nocov
299+
memtest = 0L # nocov
297300
filename = NA_character_ # nocov
298301
foreign = FALSE # nocov ; assumes users of 'cc(F); test(...)' has LANGUAGE=en
299302
showProgress = FALSE # nocov

man/test.data.table.Rd

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -8,15 +8,15 @@
88
test.data.table(script = "tests.Rraw", verbose = FALSE, pkg = ".",
99
silent = FALSE,
1010
showProgress = interactive() && !silent,
11-
memtest = as.logical(Sys.getenv("TEST_DATA_TABLE_MEMTEST", "FALSE")))
11+
memtest = Sys.getenv("TEST_DATA_TABLE_MEMTEST", 0))
1212
}
1313
\arguments{
1414
\item{script}{ Run arbitrary R test script. }
1515
\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. }
1616
\item{pkg}{ Root directory name under which all package content (ex: DESCRIPTION, src/, R/, inst/ etc..) resides. Used only in \emph{dev-mode}. }
1717
\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. }
1818
\item{showProgress}{ Output 'Running test <n> ...\\r' at the start of each test? }
19-
\item{memtest}{ Measure and report memory usage of tests rather than time taken. Intended for and tested on Linux. }
19+
\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. }
2020
}
2121
\details{
2222
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.

0 commit comments

Comments
 (0)