From 22b5a6171b45c49e9a3258db12473407ba8f28e2 Mon Sep 17 00:00:00 2001 From: Jim Garrison Date: Mon, 16 Feb 2015 15:14:31 -0800 Subject: [PATCH 1/5] Disable certain spawn tests under Valgrind --- test/repl.jl | 4 +++- test/spawn.jl | 15 +++++++++++++-- 2 files changed, 16 insertions(+), 3 deletions(-) diff --git a/test/repl.jl b/test/repl.jl index 52ff4bf0a21be..9b5028e81c435 100644 --- a/test/repl.jl +++ b/test/repl.jl @@ -249,7 +249,9 @@ wait(p) ccall(:close,Cint,(Cint,),fds) output = readall(master) -@test output == "julia> 1\r\nquit()\r\n1\r\n\r\njulia> " +if ccall(:jl_running_on_valgrind,Cint,()) == 0 + @test output == "julia> 1\r\nquit()\r\n1\r\n\r\njulia> " +end close(master) end diff --git a/test/spawn.jl b/test/spawn.jl index c95bf15e6a51b..91e0f76a470ed 100644 --- a/test/spawn.jl +++ b/test/spawn.jl @@ -9,6 +9,9 @@ #TODO: # - Windows: # - Add a test whether coreutils are available and skip tests if not + +valgrind_off = ccall(:jl_running_on_valgrind,Cint,()) == 0 + yes = `perl -le 'while (1) {print STDOUT "y"}'` #### Examples used in the manual #### @@ -38,7 +41,11 @@ begin kill(p) end -@test_throws Base.UVError run(`foo_is_not_a_valid_command`) +if valgrind_off + # If --trace-children=yes is passed to valgrind, valgrind will + # exit here with an error code, and no UVError will be raised. + @test_throws Base.UVError run(`foo_is_not_a_valid_command`) +end if false prefixer(prefix, sleep) = `perl -nle '$|=1; print "'$prefix' ", $_; sleep '$sleep';'` @@ -154,7 +161,11 @@ close(sock) # issue #4535 exename=joinpath(JULIA_HOME,(ccall(:jl_is_debugbuild,Cint,())==0?"julia":"julia-debug")) -@test readall(pipe(`$exename -f -e 'println(STDERR,"Hello World")'`, stderr=`cat`)) == "Hello World\n" +if valgrind_off + # If --trace-children=yes is passed to valgrind, we will get a + # valgrind banner here, not "Hello World\n". + @test readall(pipe(`$exename -f -e 'println(STDERR,"Hello World")'`, stderr=`cat`)) == "Hello World\n" +end # issue #6310 @test readall(pipe(`echo "2+2"`, `$exename -f`)) == "4\n" From 2732199c7f7fe629150f67bfc7cf908888ea56a0 Mon Sep 17 00:00:00 2001 From: Jim Garrison Date: Mon, 16 Feb 2015 15:15:21 -0800 Subject: [PATCH 2/5] Disable rounding tests under Valgrind Valgrind does not support different rounding modes; see https://bugs.kde.org/show_bug.cgi?id=136779 --- test/runtests.jl | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/test/runtests.jl b/test/runtests.jl index 70d91476050cd..8caa989e47fc5 100644 --- a/test/runtests.jl +++ b/test/runtests.jl @@ -1,6 +1,11 @@ include("choosetests.jl") tests, net_on = choosetests(ARGS) +if ccall(:jl_running_on_valgrind,Cint,()) != 0 && "rounding" in tests + warn("Running under valgrind: Skipping rounding tests") + filter!(x -> x != "rounding", tests) +end + cd(dirname(@__FILE__)) do n = 1 if net_on From 71084ceef7a5d495034979e24a2d98614d495d83 Mon Sep 17 00:00:00 2001 From: Jim Garrison Date: Mon, 16 Feb 2015 16:26:24 -0800 Subject: [PATCH 3/5] Greatly improve Valgrind documentation Includes information on various flags to pass to valgrind, and how to run the test suite under valgrind --- doc/devdocs/valgrind.rst | 27 ++++++++++++++++++++++++++- 1 file changed, 26 insertions(+), 1 deletion(-) diff --git a/doc/devdocs/valgrind.rst b/doc/devdocs/valgrind.rst index 7ef2f7b0c28b8..626cc341a174e 100644 --- a/doc/devdocs/valgrind.rst +++ b/doc/devdocs/valgrind.rst @@ -4,6 +4,17 @@ Using Valgrind with Julia `Valgrind `_ is a tool for memory debugging, memory leak detection, and profiling. This section describes things to keep in mind when using Valgrind to debug memory issues with Julia. +General considerations +---------------------- + +By default, Valgrind assumes that there is no self modifying code in the programs it runs. This assumption works fine in most instances but fails miserably for a just-in-time compiler like ``julia``. For this reason it is crucial to pass ``--smc-check=all-non-file`` to ``valgrind``, else code may crash or behave unexpectedly (often in subtle ways). + +In some cases, to better detect memory errors using Valgrind it can help to compile ``julia`` with memory pools disabled. The compile-time flag ``MEMDEBUG`` disables memory pools in Julia, and ``MEMDEBUG2`` disables memory pools in FemtoLisp. To build ``julia`` with both flags, add the following line to ``Make.user``:: + + CFLAGS = -DMEMDEBUG -DMEMDEBUG2 + +Another thing to note: if your program uses multiple workers processes, it is likely that you want all such worker processes to run under Valgrind, not just the parent process. To do this, pass ``--trace-children=yes`` to ``valgrind``. + Suppressions ------------ @@ -11,6 +22,20 @@ Valgrind will typically display spurious warnings as it runs. To reduce the num The suppressions file can be used from the ``julia/`` source directory as follows:: - $ valgrind --suppressions=contrib/valgrind-julia.supp ./julia progname.jl + $ valgrind --smc-check=all-non-file --suppressions=contrib/valgrind-julia.supp ./julia progname.jl Any memory errors that are displayed should either be reported as bugs or contributed as additional suppressions. Note that some versions of Valgrind are `shipped with insufficient default suppressions `_, so that may be one thing to consider before submitting any bugs. + +Running the Julia test suite under Valgrind +------------------------------------------- + +It is possible to run the entire Julia test suite under Valgrind, but it does take quite some time (typically several hours). To do so, run the following command from the ``julia/test/`` directory:: + + valgrind --smc-check=all-non-file --trace-children=yes --suppressions=$PWD/../contrib/valgrind-julia.supp ../julia runtests.jl all + +Caveats +------- + +Valgrind currently `does not support multiple rounding modes `_, so code that adjusts the rounding mode will behave differently when run under Valgrind. + +In general, if after setting ``--smc-check=all-non-file`` you find that your program behaves differently when run under Valgrind, it may help to pass ``--tool=none`` to ``valgrind`` as you investigate further. This will enable the minimal Valgrind machinery but will also run much faster than when the full memory checker is enabled. From 6959aae5df9a022eff3abd430d36f28c702a3613 Mon Sep 17 00:00:00 2001 From: Jim Garrison Date: Tue, 17 Feb 2015 21:41:29 -0800 Subject: [PATCH 4/5] Disable an examples.jl test under valgrind This test consistently fails under valgrind for reasons I do not yet understand. --- test/examples.jl | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/test/examples.jl b/test/examples.jl index bd12472027504..3b62aa8be8454 100644 --- a/test/examples.jl +++ b/test/examples.jl @@ -41,7 +41,7 @@ include(joinpath(dir, "queens.jl")) @unix_only begin script = joinpath(dir, "clustermanager/simple/test_simple.jl") cmd = `$(joinpath(JULIA_HOME,Base.julia_exename())) $script` - if !success(cmd) + if !success(cmd) && ccall(:jl_running_on_valgrind,Cint,()) == 0 error("UnixDomainCM failed test, cmd : $cmd") end end From 8cf3448e0e4640c524ac4e73af79b003bf4cf03b Mon Sep 17 00:00:00 2001 From: Jim Garrison Date: Wed, 18 Feb 2015 21:52:04 -0800 Subject: [PATCH 5/5] Move rounding test filter to choosetests.jl This was not correctly done in the rebase of 2732199. --- test/choosetests.jl | 5 +++++ test/runtests.jl | 5 ----- 2 files changed, 5 insertions(+), 5 deletions(-) diff --git a/test/choosetests.jl b/test/choosetests.jl index 3cc26fce6e029..8a5010c8a8b1d 100644 --- a/test/choosetests.jl +++ b/test/choosetests.jl @@ -55,6 +55,11 @@ function choosetests(choices = []) net_on = false end + if ccall(:jl_running_on_valgrind,Cint,()) != 0 && "rounding" in tests + warn("Running under valgrind: Skipping rounding tests") + filter!(x -> x != "rounding", tests) + end + if !net_on filter!(x -> !(x in net_required_for), tests) end diff --git a/test/runtests.jl b/test/runtests.jl index 8caa989e47fc5..70d91476050cd 100644 --- a/test/runtests.jl +++ b/test/runtests.jl @@ -1,11 +1,6 @@ include("choosetests.jl") tests, net_on = choosetests(ARGS) -if ccall(:jl_running_on_valgrind,Cint,()) != 0 && "rounding" in tests - warn("Running under valgrind: Skipping rounding tests") - filter!(x -> x != "rounding", tests) -end - cd(dirname(@__FILE__)) do n = 1 if net_on