Skip to content

Commit

Permalink
valgrind (#4666)
Browse files Browse the repository at this point in the history
  • Loading branch information
mattdowle committed Aug 7, 2020
1 parent 4f76162 commit 5144c5e
Show file tree
Hide file tree
Showing 10 changed files with 166 additions and 119 deletions.
1 change: 1 addition & 0 deletions .dev/.bash_aliases
Expand Up @@ -11,6 +11,7 @@ alias gdm='git difftool master &> /dev/null'
alias Rdevel='~/build/R-devel/bin/R --vanilla'
alias Rdevel-strict-gcc='~/build/R-devel-strict-gcc/bin/R --vanilla'
alias Rdevel-strict-clang='~/build/R-devel-strict-clang/bin/R --vanilla'
alias Rdevel-valgrind='~/build/R-devel-valgrind/bin/R --vanilla'
alias Rdevel32='~/build/32bit/R-devel/bin/R --vanilla'
alias R310='~/build/R-3.1.0/bin/R --vanilla'
alias revdepsh='cd ~/build/revdeplib/ && export TZ=UTC && export R_LIBS_SITE=none && export R_LIBS=~/build/revdeplib/ && export _R_CHECK_FORCE_SUGGESTS_=false'
Expand Down
30 changes: 15 additions & 15 deletions .dev/CRAN_Release.cmd
Expand Up @@ -368,29 +368,29 @@ print(Sys.time()); started.at<-proc.time(); try(test.data.table()); print(Sys.ti
###############################################

cd ~/build
rm -rf R-devel # easiest way to remove ASAN from compiled packages in R-devel/library
# to avoid "ASan runtime does not come first in initial library list" error; no need for LD_PRELOAD
tar xvf R-devel.tar.gz
cd R-devel
./configure --without-recommended-packages --disable-byte-compiled-packages --disable-openmp --with-valgrind-instrumentation=1 CC="gcc" CFLAGS="-O0 -g -Wall -pedantic" LIBS="-lpthread"
mkdir R-devel-valgrind # separate build to avoid differences in installed packages, and
# to avoid "ASan runtime does not come first in initial library list" error; no need for LD_PRELOAD
tar xvf R-devel.tar.gz -C R-devel-valgrind --strip-components 1
cd R-devel-valgrind
./configure --without-recommended-packages --with-valgrind-instrumentation=2 --with-system-valgrind-headers CC="gcc" CFLAGS="-O2 -g -Wall -pedantic"
make
cd ~/GitHub/data.table
vi ~/.R/Makevars # make the -O0 -g line active, for info on source lines with any problems
Rdevel CMD INSTALL data.table_1.13.1.tar.gz
Rdevel -d "valgrind --tool=memcheck --leak-check=full --track-origins=yes --show-leak-kinds=definite"
vi ~/.R/Makevars # make the -O2 -g line active, for info on source lines with any problems
Rdevel-valgrind CMD INSTALL data.table_1.13.1.tar.gz
R_DONT_USE_TK=true Rdevel-valgrind -d "valgrind --tool=memcheck --leak-check=full --track-origins=yes --show-leak-kinds=definite,possible --gen-suppressions=all --suppressions=./.dev/valgrind.supp -s"
# the default for --show-leak-kinds is 'definite,possible' which we're setting explicitly here as a reminder. CRAN uses the default too.
# including 'reachable' (as 'all' does) generates too much output from R itself about by-design permanent blocks
# gctorture(TRUE) # very slow, many days
# gctorture2(step=100)
print(Sys.time()); require(data.table); print(Sys.time()); started.at<-proc.time(); try(test.data.table()); print(Sys.time()); print(timetaken(started.at))
# 3m require; 62m test
print(Sys.time()); require(data.table); print(Sys.time()); started.at<-proc.time(); try(test.data.table(script="*.Rraw")); print(Sys.time()); print(timetaken(started.at))
# 3m require; 62m test # level 1 -O0
# 1m require; 33m test # level 2 -O2
q() # valgrind output printed after q()

# Investigated and ignore :
# Tests 648 and 1262 (see their comments) have single precision issues under valgrind that don't occur on CRAN, even Solaris.
# Old comment from gsumm.c ... // long double usage here used to result in test 648 failing when run under valgrind
// http://valgrind.org/docs/manual/manual-core.html#manual-core.limits"
# Precision issues under valgrind are now avoided using test_longdouble in tests.Rraw, and exact_NaN in froll.Rraw
# Ignore all "set address range perms" warnings :
# http://stackoverflow.com/questions/13558067/what-does-this-valgrind-warning-mean-warning-set-address-range-perms
# Ignore heap summaries around test 1705 and 1707/1708 due to the fork() test opening/closing, I guess.
# Tests 1729.4, 1729.8, 1729.11, 1729.13 again have precision issues under valgrind only.
# Leaks for tests 1738.5, 1739.3 but no data.table .c lines are flagged, rather libcairo.so
# and libfontconfig.so via GEMetricInfo and GEStrWidth in libR.so

Expand Down
24 changes: 24 additions & 0 deletions .dev/valgrind.supp
@@ -0,0 +1,24 @@
{
<fontconfig>
Memcheck:Leak
...
obj:*/libfontconfig.so.*
...
}

{
<pango>
Memcheck:Leak
...
obj:*libpango*.so.*
...
}

{
<gobject>
Memcheck:Leak
...
obj:*libgobject*.so.*
...
}

2 changes: 1 addition & 1 deletion .travis.yml
Expand Up @@ -8,7 +8,7 @@ r:

os:
- linux
- osx # Takes 13m (+9m linux = 22m total); #3357; #3326; #3331. When off it's to speed up dev cycle; CRAN_Release.cmd has a reminder to turn back on.
# - osx # Takes 13m (+9m linux = 22m total); #3357; #3326; #3331. When off it's to speed up dev cycle; CRAN_Release.cmd has a reminder to turn back on.

brew_packages:
- llvm
Expand Down
8 changes: 6 additions & 2 deletions R/test.data.table.R
Expand Up @@ -23,8 +23,11 @@ test.data.table = function(script="tests.Rraw", verbose=FALSE, pkg=".", silent=F
scripts = dir(fulldir, "*.Rraw.*")
scripts = scripts[!grepl("bench|other", scripts)]
scripts = gsub("[.]bz2$","",scripts)
for (fn in scripts) {test.data.table(script=fn, verbose=verbose, pkg=pkg, silent=silent, showProgress=showProgress); cat("\n");}
return(invisible())
return(sapply(scripts, function(fn) {
err = try(test.data.table(script=fn, verbose=verbose, pkg=pkg, silent=silent, showProgress=showProgress))
cat("\n");
identical(err, TRUE)
}))
# nocov end
}

Expand Down Expand Up @@ -137,6 +140,7 @@ test.data.table = function(script="tests.Rraw", verbose=FALSE, pkg=".", silent=F
cat("\n", date(), # so we can tell exactly when these tests ran on CRAN to double-check the result is up to date
" endian==", .Platform$endian,
", sizeof(long double)==", .Machine$sizeof.longdouble,
", longdouble.digits==", .Machine$longdouble.digits, # 64 normally, 53 for example under valgrind where some high accuracy tests need turning off, #4639
", sizeof(pointer)==", .Machine$sizeof.pointer,
", TZ==", if (is.na(tz)) "unset" else paste0("'",tz,"'"),
", Sys.timezone()=='", suppressWarnings(Sys.timezone()), "'",
Expand Down
21 changes: 14 additions & 7 deletions inst/tests/froll.Rraw
Expand Up @@ -9,6 +9,13 @@ if (exists("test.data.table", .GlobalEnv, inherits=FALSE)) {
froll = data.table:::froll
}

exact_NaN = isTRUE(capabilities()["long.double"]) && identical(as.integer(.Machine$longdouble.digits), 64L)
if (!exact_NaN) {
cat("\n**** Skipping 7 NaN/NA algo='exact' tests because .Machine$longdouble.digits==", .Machine$longdouble.digits, " (!=64); e.g. under valgrind\n\n", sep="")
# for Matt when he runs valgrind it is 53, but 64 when running regular R
# froll.c uses long double and appears to require full long double accuracy in the algo='exact'
}

## rolling features

#### atomic vectors input and single window returns atomic vectors
Expand Down Expand Up @@ -192,7 +199,7 @@ expected = list(
c(rep(NA_real_,4), seq(1.5,2,0.25), rep(NA_real_, 1))
)
test(6000.040, ans1, expected)
test(6000.041, ans2, expected)
if (exact_NaN) test(6000.041, ans2, expected)
ans1 = frollmean(d, 3, align="right", na.rm=TRUE)
ans2 = frollmean(d, 3, align="right", algo="exact", na.rm=TRUE)
expected = list(
Expand All @@ -208,7 +215,7 @@ expected = list(
c(rep(NA_real_,3), seq(1.5,2,0.25), rep(NA_real_, 2))
)
test(6000.044, ans1, expected)
test(6000.045, ans2, expected)
if (exact_NaN) test(6000.045, ans2, expected)
ans1 = frollmean(d, 3, align="center", na.rm=TRUE) # x even, n odd
ans2 = frollmean(d, 3, align="center", algo="exact", na.rm=TRUE)
expected = list(
Expand All @@ -224,7 +231,7 @@ expected = list(
c(rep(NA_real_,3), 1.625, 1.875, rep(NA_real_, 3))
)
test(6000.048, ans1, expected)
test(6000.049, ans2, expected)
if (exact_NaN) test(6000.049, ans2, expected)
ans1 = frollmean(d, 4, align="center", na.rm=TRUE) # x even, n even
ans2 = frollmean(d, 4, align="center", algo="exact", na.rm=TRUE)
expected = list(
Expand All @@ -241,7 +248,7 @@ expected = list(
c(rep(NA_real_,3), 1.5, 1.75, 2, rep(NA_real_, 3))
)
test(6000.052, ans1, expected)
test(6000.053, ans2, expected)
if (exact_NaN) test(6000.053, ans2, expected)
ans1 = frollmean(de, 3, align="center", na.rm=TRUE) # x odd, n odd
ans2 = frollmean(de, 3, align="center", algo="exact", na.rm=TRUE)
expected = list(
Expand All @@ -257,7 +264,7 @@ expected = list(
c(rep(NA_real_, 3), 1.625, 1.875, rep(NA_real_,4))
)
test(6000.056, ans1, expected)
test(6000.057, ans2, expected)
if (exact_NaN) test(6000.057, ans2, expected)
ans1 = frollmean(de, 4, align="center", na.rm=TRUE) # x odd, n even
ans2 = frollmean(de, 4, align="center", algo="exact", na.rm=TRUE)
expected = list(
Expand All @@ -273,7 +280,7 @@ expected = list(
c(rep(NA_real_, 2), 1.5, 1.75, 2, rep(NA_real_,3))
)
test(6000.060, ans1, expected)
test(6000.061, ans2, expected)
if (exact_NaN) test(6000.061, ans2, expected)
ans1 = frollmean(d, 3, align="left", na.rm=TRUE)
ans2 = frollmean(d, 3, align="left", algo="exact", na.rm=TRUE)
expected = list(
Expand All @@ -289,7 +296,7 @@ ans1 = frollmean(d, 2:3)
ans2 = frollmean(d, 2:3, algo="exact")
expected = list(c(NA, NA, NA, 1.75, NA, NA), rep(NA_real_, 6), c(NA, 0.875, 1.125, NA, NA, NA), c(NA, NA, 1, NA, NA, NA))
test(6000.064, ans1, expected)
test(6000.065, ans2, expected)
if (exact_NaN) test(6000.065, ans2, expected)
ans1 = frollmean(d, 2:3, na.rm=TRUE)
ans2 = frollmean(d, 2:3, algo="exact", na.rm=TRUE)
expected = list(c(NA, 0.5, 1.5, 1.75, 2, 3), c(NA, NA, 1, 1.75, 1.75, 2.5), c(NA, 0.875, 1.125, 1.25, NaN, NaN), c(NA, NA, 1, 1.125, 1.25, NaN))
Expand Down

0 comments on commit 5144c5e

Please sign in to comment.