Merge lp:~michihenning/unity/valgrind-tests into lp:unity/phablet

Proposed by Michi Henning
Status: Merged
Approved by: Michał Sawicz
Approved revision: no longer in the source branch.
Merged at revision: 622
Proposed branch: lp:~michihenning/unity/valgrind-tests
Merge into: lp:unity/phablet
Diff against target: 74 lines (+47/-0)
3 files modified
CMakeLists.txt (+18/-0)
CTestCustom.cmake.in (+16/-0)
valgrind-suppress (+13/-0)
To merge this branch: bzr merge lp:~michihenning/unity/valgrind-tests
Reviewer Review Type Date Requested Status
PS Jenkins bot (community) continuous-integration Approve
Jussi Pakkanen (community) Approve
Michał Sawicz Needs Information
Review via email: mp+159066@code.launchpad.net

Commit message

Added valgrind target to cmake. To suppress valgrind testing for tests that don't need it, add the test to be omitted to CTestCustom.cmake.in.

Description of the change

Added valgrind target to cmake. To suppress valgrind testing for tests that don't need it, add the test to be omitted to CTestCustom.cmake.in.

To post a comment you must log in.
Revision history for this message
PS Jenkins bot (ps-jenkins) wrote :
review: Approve (continuous-integration)
Revision history for this message
Michał Sawicz (saviq) wrote :

There's no need for the valgrind build-dep, it's only needed when you run the valgrind target, no?

review: Needs Information
Revision history for this message
Jussi Pakkanen (jpakkane) wrote :
Revision history for this message
Michi Henning (michihenning) wrote :

> There's no need for the valgrind build-dep, it's only needed when you run the
> valgrind target, no?

OK, I didn't know what our policy was for packages that are not essential for the build and only needed for testing. I've removed the dependency on valgrind.

Revision history for this message
Michi Henning (michihenning) wrote :

> Instead of suppressing g_ memory functions you might want to do this:
>
> http://stackoverflow.com/questions/4254610/valgrind-reports-memory-possibly-
> lost-when-using-glib-data-types

That would be nice. My question is how to set the environment variables. Currently, I have:

 set(MEMORYCHECK_COMMAND_OPTIONS
        "--suppressions=${CMAKE_SOURCE_DIR}/valgrind-suppress --leak-check=full --num-callers=40 --error-exitcode=3"
 )
 add_custom_target(valgrind DEPENDS NightlyMemCheck)

This is pretty much straight from the cmake doc. The cmake doc is silent on how to run the memory check with the environment variables set. The cmake set(ENV{VAR} "value") construct doesn't work because that runs at configure time, not build time.

Do you have any suggestions? I'd rather not write yet another script...

Revision history for this message
Michał Sawicz (saviq) wrote :

W dniu 22.04.2013 13:41, Michi Henning pisze:
> That would be nice. My question is how to set the environment variables. Currently, I have:

Hey,

http://www.cmake.org/cmake/help/v2.8.9/cmake.html#command:set_target_properties

Should help.
--
Michał Sawicz <email address hidden>
Canonical Services Ltd.

Revision history for this message
Michał Sawicz (saviq) wrote :

W dniu 22.04.2013 13:43, Michał Sawicz pisze:
> Should help.

And since the doc isn't really verbose about the topic:

add_custom_target(foo)
set_target_properties(foo PROPERTIES ENVIRONMENT "VAR=value")

--
Michał Sawicz <email address hidden>
Canonical Services Ltd.

Revision history for this message
Michi Henning (michihenning) wrote :

> And since the doc isn't really verbose about the topic:
>
> add_custom_target(foo)
> set_target_properties(foo PROPERTIES ENVIRONMENT "VAR=value")

Thanks for that. According to the doc, the ENVIRONMENT property applies only to tests, not targets.

I just tried this:

    add_custom_target(valgrind DEPENDS NightlyMemCheck)
    set_target_properties(valgrind PROPERTIES ENVIRONMENT "G_DEBUG=gc-friendly")
    set_target_properties(valgrind PROPERTIES ENVIRONMENT "G_SLICE=always-malloc")

but that doesn't work. When I try to use NightlyMemCheck instead of the valgrind to attach the property, it fails for both set_target_properties and set_tests_properties :-(

Revision history for this message
Michał Sawicz (saviq) wrote :

W dniu 22.04.2013 14:02, Michi Henning pisze:
> Thanks for that. According to the doc, the ENVIRONMENT property applies only to tests, not targets.

Oh?

In that case I defer to Jussi...
--
Michał Sawicz <email address hidden>
Canonical Services Ltd.

Revision history for this message
Jussi Pakkanen (jpakkane) wrote :

If you want to

a) not have the environment variables set when running regular tests
b) have them set when running Valgrind

then the only way I can think of is to set them when invoking make/ninja. Something like this:

G_DEBUG=.. G_SLICE=.. make valgrind

Since valgrind is a non-standard target, you need to have a custom invocation command somewhere in Jenkins. Just change that.

The only alternative I can think of goes into the realm of unspeakable evil along the lines of

add_custom_command(valgrind COMMAND G_DEBUG=.. G_SLICE=.. make NightlyMemCheck)

I'm not sure if this works (whether CMake passes the entire thing to shell without thinking) but I sincerely hope that is does not as this is awful in so many different ways.

Revision history for this message
PS Jenkins bot (ps-jenkins) wrote :
review: Approve (continuous-integration)
Revision history for this message
Michi Henning (michihenning) wrote :

> If you want to
>
> a) not have the environment variables set when running regular tests
> b) have them set when running Valgrind
>
> then the only way I can think of is to set them when invoking make/ninja.
> Something like this:
>
> G_DEBUG=.. G_SLICE=.. make valgrind
>
> Since valgrind is a non-standard target, you need to have a custom invocation
> command somewhere in Jenkins. Just change that.

Hmmm... I'd rather not have to type all that every time I want to run the tests with leak checking.

> The only alternative I can think of goes into the realm of unspeakable evil
> along the lines of

Yes, not pretty.

So, what to do now? We can leave it as is and put up with the suppression we'll have to add periodically. Or we can throw out the the NightlyMemCheck thing and write our own custom target with a Python wrapper to set the variables and then run the executable with valgrind. But doing that won't be trivial either, I suspect...

Revision history for this message
Jussi Pakkanen (jpakkane) wrote :

I would merge this as-is. It's better than nothing and there does not seem to be an obvious clean solution for the corner cases. If a good solution pops up, we can fix it later.

Revision history for this message
Michał Sawicz (saviq) wrote :

@Jussi can you vote / approve in that case?

Revision history for this message
Jussi Pakkanen (jpakkane) wrote :

Whoops, sorry.

review: Approve
Revision history for this message
PS Jenkins bot (ps-jenkins) wrote :
review: Needs Fixing (continuous-integration)
Revision history for this message
Albert Astals Cid (aacid) wrote :

autolanding got stuck

Revision history for this message
PS Jenkins bot (ps-jenkins) wrote :
review: Needs Fixing (continuous-integration)
Revision history for this message
PS Jenkins bot (ps-jenkins) :
review: Approve (continuous-integration)

Preview Diff

[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
1=== modified file 'CMakeLists.txt'
2--- CMakeLists.txt 2013-04-18 18:21:23 +0000
3+++ CMakeLists.txt 2013-04-22 11:43:26 +0000
4@@ -43,6 +43,23 @@
5 add_custom_target(cppcheck COMMAND cppcheck --enable=all -q --error-exitcode=2
6 ${CMAKE_SOURCE_DIR}/src ${CMAKE_SOURCE_DIR}/tests)
7
8+#
9+# Definitions for testing with valgrind.
10+#
11+
12+configure_file(CTestCustom.cmake.in CTestCustom.cmake) # Tests in CTestCustom.cmake are skipped for valgrind
13+
14+find_program(MEMORYCHECK_COMMAND NAMES valgrind)
15+if (MEMORYCHECK_COMMAND)
16+ set(MEMORYCHECK_COMMAND_OPTIONS
17+ "--suppressions=${CMAKE_SOURCE_DIR}/valgrind-suppress --leak-check=full --num-callers=40 --error-exitcode=3"
18+ )
19+ add_custom_target(valgrind DEPENDS NightlyMemCheck)
20+else()
21+ message(WARNING "Cannot find valgrind: valgrind target will not be available")
22+endif()
23+
24+
25 include(FindPkgConfig)
26 find_package(Qt5Qml)
27 find_package(Qt5Quick)
28@@ -104,6 +121,7 @@
29 set(LIBS ${UNITY_API_LIB} ${OTHER_API_LIBS})
30
31 # Tests
32+include(CTest)
33 enable_testing()
34
35 # Autopilot tests
36
37=== added file 'CTestCustom.cmake.in'
38--- CTestCustom.cmake.in 1970-01-01 00:00:00 +0000
39+++ CTestCustom.cmake.in 2013-04-22 11:43:26 +0000
40@@ -0,0 +1,16 @@
41+#
42+# Tests listed here will not be run by the valgrind target.
43+#
44+
45+SET(CTEST_CUSTOM_MEMCHECK_IGNORE
46+ cleanincludes
47+ testAnimationControllerWithSignals
48+ testCarousel
49+ testClock
50+ testCrossFadeImage
51+ testIndicatorItem
52+ testMathLocal
53+ testRatingStars
54+ testSideStage
55+ testTimeLocal
56+ whitespace)
57
58=== added file 'valgrind-suppress'
59--- valgrind-suppress 1970-01-01 00:00:00 +0000
60+++ valgrind-suppress 2013-04-22 11:43:26 +0000
61@@ -0,0 +1,13 @@
62+{
63+ g_main_leak
64+ Memcheck:Leak
65+ fun:memalign
66+ fun:posix_memalign
67+ obj:/lib/x86_64-linux-gnu/libglib-2.0.so.0.3600.0
68+ fun:g_slice_alloc
69+ fun:g_slice_alloc0
70+ fun:g_thread_self
71+ fun:g_main_context_acquire
72+ fun:g_main_context_push_thread_default
73+ ...
74+}

Subscribers

People subscribed via source and target branches