Skip to content

Use valgrind to simplify no-leak regression testing #72

Closed
@vaind

Description

@vaind

Seems like we can detect leaks using valgrind:

dart2native ./test/box_test.dart -o box-test
valgrind --show-mismatched-frees=no ./box-test
==13549== LEAK SUMMARY:
==13549==    definitely lost: 0 bytes in 0 blocks
==13549==    indirectly lost: 0 bytes in 0 blocks
==13549==      possibly lost: 0 bytes in 0 blocks
==13549==    still reachable: 91,012 bytes in 188 blocks
==13549==         suppressed: 0 bytes in 0 blocks

And If I manually comment out a free() call on an ffi.Pointer (e.g. in box.count()), it shows a leak:

==13580== LEAK SUMMARY:
==13580==    definitely lost: 128 bytes in 16 blocks
==13580==    indirectly lost: 0 bytes in 0 blocks
==13580==      possibly lost: 0 bytes in 0 blocks
==13580==    still reachable: 91,012 bytes in 188 blocks
==13580==         suppressed: 0 bytes in 0 blocks

Similarly, when I comment out a call to obx_query_close() and run valgrind on the query-test, it catches a leak of the core resources as well:

==15074== LEAK SUMMARY:
==15074==    definitely lost: 6,200 bytes in 181 blocks
==15074==    indirectly lost: 218,547 bytes in 3,199 blocks
==15074==      possibly lost: 0 bytes in 0 blocks
==15074==    still reachable: 91,012 bytes in 188 blocks
==15074==         suppressed: 0 bytes in 0 blocks

Therefore, it is clear it can help detect leaks that could be potentially introduced in the future code changes. There is also a load of Warning: set address range perms: large range and mismatched free() / delete / delete [] reports but I don't think those are related to our code, at least for the latter. That would require further investigation though.

Goal

Create a script for project developers and CI. The script:

  • compiles all /test/*_test.dart files using dart2native
  • executes each compiled test using valgrind
  • capture the leak summary and show an error to the user if there is a leak (any non-zero "lost" report)

The script should ideally return a non-zero code in case of an error, so it can easily be used in the CI.

Metadata

Metadata

Assignees

No one assigned

    Labels

    good first issueGood for newcomershelp wantedLooking for contributors (ideas, comments, code, etc)

    Type

    No type

    Projects

    No projects

    Milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions