tests: Add “make check-valgrind” to run the unit tests under Valgrind #17639

pull practicalswift wants to merge 1 commits into bitcoin:master from practicalswift:make-check-valgrind changing 2 files +28 −0
  1. practicalswift commented at 5:14 pm on November 30, 2019: contributor

    Add make check-valgrind to run the unit tests under Valgrind.

    Fix uninitialized read in CWallet::CreateTransaction(...) which is required for make valgrind-check to pass. Update: Fixed by the merge of #17568.

    Reviewers of this PR might be interested in the related PR #17633 (“tests: Add option –valgrind to run the functional tests under Valgrind”).

    Hopefully this will help kill the uninitialized read bug class :)

  2. fanquake added the label Tests on Nov 30, 2019
  3. fanquake commented at 5:17 pm on November 30, 2019: member
    Instead of https://github.com/bitcoin/bitcoin/pull/17639/commits/8c6edc2c7d069a3633042c842d74cd6a999c865f, you can cherry-pick from #17568, which already fixes the uninitialized read issue and adds a test.
  4. practicalswift force-pushed on Nov 30, 2019
  5. practicalswift commented at 5:22 pm on November 30, 2019: contributor
    @fanquake Done! :)
  6. DrahtBot commented at 6:33 pm on November 30, 2019: member

    The following sections might be updated with supplementary metadata relevant to reviewers and maintainers.

    Conflicts

    No conflicts as of last run.

  7. practicalswift force-pushed on Dec 1, 2019
  8. practicalswift renamed this:
    tests: Add "make check-valgrind" to run the unit tests under Valgrind. Fix uninitialized read in CWallet::CreateTransaction(...).
    tests: Add "make check-valgrind" to run the unit tests under Valgrind
    on Dec 1, 2019
  9. in src/Makefile.test.include:432 in 947a91870d outdated
    427+check-valgrind: $(TEST_BINARY) test_bitcoin_qt
    428+else
    429+check-valgrind: $(TEST_BINARY)
    430+endif
    431+endif
    432+	@echo "Using the valgrind memory error detector: expect an ~50x slowdown, valgrind 3.14 or later required"
    


    fanquake commented at 1:45 pm on December 2, 2019:
    What creates the requirement for 3.14+?

    practicalswift commented at 1:57 pm on December 2, 2019:
    --exit-on-first-error was introduced in Valgrind 3.14.

    jonatack commented at 12:47 pm on December 18, 2019:

    “~50x slowdown”: looking through the manual and SE comments, I see a wide range of perf reports. The manual’s Running your program under Memcheck section states “Your program will run much slower (eg. 20 to 30 times) than normal, and use a lot more memory.” Replies to this SE question both mention a factor of 10 slowdown.

    Perhaps “expect a 10-50x slowdown and ~2x memory usage, vagrind 3.14 or later required”

    This also avoids the awkward “a” or “an” question before the “~50x”.


    practicalswift commented at 4:02 pm on December 29, 2019:
    That’s better. Thanks! Now updated. Please re-review :)
  10. fanquake commented at 1:52 pm on December 2, 2019: member
    Concept ACK - Unfortunately Valgrind support on macOS is somewhat limited (even building the master branch).
  11. in src/Makefile.test.include:631 in 947a91870d outdated
    429+check-valgrind: $(TEST_BINARY)
    430+endif
    431+endif
    432+	@echo "Using the valgrind memory error detector: expect an ~50x slowdown, valgrind 3.14 or later required"
    433+	@echo "Running $(TEST_BINARY) under valgrind -- this will take a quite a while ..."
    434+	valgrind --suppressions=$(top_builddir)/contrib/valgrind.supp --gen-suppressions=all --exit-on-first-error=yes --error-exitcode=1 --quiet $(TEST_BINARY)
    


    MarcoFalke commented at 3:59 pm on December 3, 2019:
    I’d rather keep running the tests in parallel, even more so that valgrind causes a slowdown. See https://github.com/bitcoin/bitcoin/blob/master/ci/test/wrap-valgrind.sh

    practicalswift commented at 9:56 am on December 5, 2019:
    I’m not sure how to do run the tests in parallel under Valgrind in a way that a.) prints generated suppressions to the user, and b.) does not potentially introduce false positives due to resource exhaustion. Perhaps introducing parallelism can be tackled in a follow up PR?

    MarcoFalke commented at 6:25 pm on December 18, 2019:

    a) The suppression should be printed when the test case fails, no?

    b) I think we can’t prevent OOM in general due to users setting too high -j in make check. Do you have any hints when this could lead to false positives instead of a killed process or frozen machine?


    MarcoFalke commented at 6:38 pm on December 18, 2019:
    Also, note that the same OOM “protection” does not exist for the functional tests when run with --valgrind or so

    practicalswift commented at 4:08 pm on December 29, 2019:
    I think these things would be nice to have but I’m afraid I won’t have time to add that to this PR any time soon. I suggest we go with this simple version to start with and then someone can add parallellism in a follow-up PR. Makes sense? :)
  12. fjahr commented at 0:48 am on December 17, 2019: member

    Concept ACK

    Also unfortunately not able to test because of valgrind/macOS shenanigans at the moment.

  13. jonatack commented at 1:23 pm on December 17, 2019: member
    Would someone please add a Review Club label to this PR? Thanks :)
  14. fanquake added the label Review club on Dec 17, 2019
  15. practicalswift commented at 3:19 pm on December 17, 2019: contributor

    Welcome all review club members! Unfortunately I cannot attend your meeting today but you should know that I’m a huge fan of what you are doing: by reviewing you’re helping to make Bitcoin Core harder, better, faster and stronger! :)

    Looking forward to reading your reviews/feedback!

    Remember: given enough eyeballs all bugs are shallow :)

  16. in src/Makefile.test.include:436 in 947a91870d outdated
    431+endif
    432+	@echo "Using the valgrind memory error detector: expect an ~50x slowdown, valgrind 3.14 or later required"
    433+	@echo "Running $(TEST_BINARY) under valgrind -- this will take a quite a while ..."
    434+	valgrind --suppressions=$(top_builddir)/contrib/valgrind.supp --gen-suppressions=all --exit-on-first-error=yes --error-exitcode=1 --quiet $(TEST_BINARY)
    435+if ENABLE_BENCH
    436+	@echo "Running $(BENCH_BINARY) -evals=1 -scaling=0 under valgrind -- this will take quite a while ..."
    


    jonatack commented at 12:15 pm on December 18, 2019:

    nits noticed while testing on the command line:

    • I think “quite a” is a bit verbose here and in line 440 – “this may take a while” on its own is fine

    • s/while …/while…/


    practicalswift commented at 4:02 pm on December 29, 2019:
    Yes, that’s better. Thanks! Now updated. Please re-review :)
  17. jonatack commented at 12:57 pm on December 18, 2019: member

    Concept ACK 947a91870d568e1cb450d18739b6fa1cbb28e78b. Running make check-valgrind (with valgrind 3.14 on debian) outputs the following. After 15 minutes I see nothing further, so if the tests are running as expected, I’m not sure who will have the patience to run them. Perhaps I’m missing a configuration?

    0bitcoin ((HEAD detached at origin/pr/17639))$ make check-valgrind
    1make -C src/ check-valgrind
    2make[1]: Entering directory '/home/jon/projects/bitcoin/bitcoin/src'
    3make[2]: Entering directory '/home/jon/projects/bitcoin/bitcoin'
    4make[2]: Leaving directory '/home/jon/projects/bitcoin/bitcoin'
    5Using the valgrind memory error detector: expect an ~50x slowdown, valgrind 3.14 or later required
    6Running test/test_bitcoin under valgrind -- this will take a quite a while ...
    7valgrind --suppressions=../contrib/valgrind.supp --gen-suppressions=all --exit-on-first-error=yes --error-exitcode=1 --quiet test/test_bitcoin
    8Running 387 test cases...
    

    EDIT: I debugged this extensively by running valgrind --gen-suppressions=all --verbose --exit-on-first-error=yes --error-exitcode=1 --suppressions=contrib/valgrind.supp src/test/test_bitcoin --log_level=test_suite. The issue for me was that the suppressions file needed additions to make it through the unit tests.

  18. practicalswift force-pushed on Dec 29, 2019
  19. practicalswift commented at 4:08 pm on December 29, 2019: contributor
    @jonatack Thanks for reviewing. Would you mind re-reviewing the updated version? :)
  20. in src/Makefile.test.include:631 in 6497d25403 outdated
    429+check-valgrind: $(TEST_BINARY)
    430+endif
    431+endif
    432+	@echo "Using the valgrind memory error detector: expect a 10-50x slowdown and ~2x memory usage. valgrind 3.14 or later required."
    433+	@echo "Running $(TEST_BINARY) under valgrind -- this will take a a while..."
    434+	valgrind --suppressions=$(top_builddir)/contrib/valgrind.supp --gen-suppressions=all --exit-on-first-error=yes --error-exitcode=1 --quiet $(TEST_BINARY)
    


    jonatack commented at 4:35 pm on December 29, 2019:

    To have valgrind make it through the unit tests, I had to debug rather extensively my suppressions file by running valgrind --gen-suppressions=all --verbose --exit-on-first-error=yes --error-exitcode=1 --suppressions=contrib/valgrind.supp src/test/test_bitcoin --log_level=test_suite and adding suppressions. It takes 60-90 minutes for a run, so it’s a long process..

    • Is the suppressions file for a project supposed to be portable across platforms (presumably yes, as there is one file for this project), or is it normal for it to be a configuration adventure for each user?

    • I found running valgrind directly more informative for debugging and feedback, particularly with flags like --verbose and --log_level=test_suite. I did not try running make check-valgrind with those options yet but wonder if it is a convenience feature, or adding other value that I’m misunderstanding? I do intend to retest and re-review.


    practicalswift commented at 5:07 pm on December 29, 2019:

    @jonatack

    I don’t think you’re doing anything wrong: Valgrind is super slow :)

    Is the suppressions file for a project supposed to be portable across platforms, or is it normal for it to be a config adventure for each user?

    I think the current set of suppressions has been tested and updated by at least me and @MarcoFalke for various configurations, but more additions are welcome :) Please submit your local changes upstreams :)

    The suppressions are not necessarily portable across distributions, or across versions of the same distribution.

    I found running valgrind directly more informative for debugging and feedback, particularly with flags like –verbose and –log_level=test_suite. I did not try running make check-valgrind with those options yet but wonder if it is a convenience feature, or adding other value that I’m misunderstanding? I do intend to retest and re-review.

    I usually run with --log_level=test_suite when debugging a found error, but I’m afraid enabling it by default for make check-valgrind would make the output too verbose. Generally I think check-type commands should be silent unless an error is found, and hopefully the most common scenario is that of no Valgrind errors :)

  21. practicalswift force-pushed on Jan 8, 2020
  22. practicalswift commented at 12:35 pm on January 8, 2020: contributor
    Rebased! :)
  23. Binh0103 approved
  24. fanquake deleted a comment on Jan 19, 2020
  25. jonatack commented at 1:43 pm on February 17, 2020: member
    ACK 2a57a15 mod comment
  26. in src/Makefile.test.include:632 in 2a57a15299 outdated
    627+endif
    628+endif
    629+	@echo "Using the valgrind memory error detector: expect a 10-50x slowdown and ~2x memory usage. valgrind 3.14 or later required."
    630+	@echo "Running $(TEST_BINARY) under valgrind -- this will take a a while..."
    631+	valgrind --suppressions=$(top_builddir)/contrib/valgrind.supp --gen-suppressions=all --exit-on-first-error=yes --error-exitcode=1 --quiet $(TEST_BINARY)
    632+if ENABLE_BENCH
    


    jonatack commented at 1:45 pm on February 17, 2020:

    Retested this PR and wonder if it would not be better to remove the –quiet flags… make check isn’t quiet either, make check-valgrind takes a long time (~90 minutes) to run so some output is reassuring, and the additional output is useful:

    0Using the valgrind memory error detector: expect a 10-50x slowdown and ~2x memory usage. valgrind 3.14 or later required.
    1Running test/test_bitcoin under valgrind -- this will take a a while...
    2valgrind --suppressions=../contrib/valgrind.supp --gen-suppressions=all --exit-on-first-error=yes --error-exitcode=1 test/test_bitcoin
    3==36831== Memcheck, a memory error detector
    4==36831== Copyright (C) 2002-2017, and GNU GPL'd, by Julian Seward et al.
    5==36831== Using Valgrind-3.16.0.GIT and LibVEX; rerun with -h for copyright info
    6==36831== Command: test/test_bitcoin
    7==36831== 
    8Running 391 test cases...
    

    practicalswift commented at 2:03 pm on February 17, 2020:
    Adjusted accordingly :)
  27. practicalswift force-pushed on Feb 17, 2020
  28. practicalswift commented at 2:04 pm on February 17, 2020: contributor
    @jonatack No longer using --quiet as requested. Would you mind re-reviewing? :)
  29. in src/Makefile.test.include:631 in 8942642e83 outdated
    626+check-valgrind: $(TEST_BINARY)
    627+endif
    628+endif
    629+	@echo "Using the valgrind memory error detector: expect a 10-50x slowdown and ~2x memory usage. valgrind 3.14 or later required."
    630+	@echo "Running $(TEST_BINARY) under valgrind -- this will take a a while..."
    631+	valgrind --suppressions=$(top_builddir)/contrib/valgrind.supp --gen-suppressions=all --exit-on-first-error=yes --error-exitcode=1 $(TEST_BINARY)
    


    jonatack commented at 3:46 pm on February 17, 2020:
    nit: lines 629-631 don’t appear to be in a conditional, unless I’m misreading; should they be indented?

    practicalswift commented at 7:09 pm on February 17, 2020:
    This is not indentation due to being a conditional. It is the standard Makefile indentation we’re following - see %.cpp.test: %.cpp indentation below as an example :)
  30. jonatack commented at 4:08 pm on February 17, 2020: member

    ACK 8942642e mod indentation nit (sorry for the iterative reviewing :)

    I’ve never been able to get fully through any of the suites with valgrind yet because of missing suppressions (and may propose adding some). Therefore, to test this PR I needed to remove L629-631 (the unit tests) to see the bench tests, and then L632-635 (the bench tests) to see the qt tests. This is how I tested.

    Edit: progress! valgrinded all the way through the bench and qt suites :)

  31. tests: Add "make check-valgrind" to run the unit tests under Valgrind 61fdd7950c
  32. practicalswift force-pushed on Feb 17, 2020
  33. practicalswift commented at 7:27 pm on February 17, 2020: contributor

    Updated. Removed usage of --exit-on-first-error and thus the requirement of a very recent valgrind version.

    After thinking about it I came to the conclusion that it is better to optimise for maximum number of valgrind testers than optimising for the rare case that a memory error is found.

    Please re-review :)

  34. jonatack referenced this in commit 3fd6cd188e on Feb 19, 2020
  35. jonatack commented at 2:23 pm on February 19, 2020: member

    ACK 61fdd79 – see https://gist.github.com/jonatack/1c0e0b9324ee4cc6c6bd6044c0b1c366 for output of running make check-valgrind.

    Thanks to the updated valgrind suppressions in PR #18178 (review welcome), this PR now runs for me with no errors related to our dependencies.

  36. practicalswift commented at 1:16 pm on March 7, 2020: contributor

    Any chance we can move forward with this PR?

    I’ll leave it open for a while to allow for ACK:s and close if no interest is shown :)

  37. practicalswift commented at 8:12 am on March 10, 2020: contributor
    Closing due to lack of interest :)
  38. practicalswift closed this on Mar 10, 2020

  39. practicalswift deleted the branch on Apr 10, 2021
  40. DrahtBot locked this on Aug 18, 2022

github-metadata-mirror

This is a metadata mirror of the GitHub repository bitcoin/bitcoin. This site is not affiliated with GitHub. Content is generated from a GitHub metadata backup.
generated: 2024-11-21 09:12 UTC

This site is hosted by @0xB10C
More mirrored repositories can be found on mirror.b10c.me