Make tests much faster by replacing BOOST_CHECK with FAST_CHECK #8650

pull JeremyRubin wants to merge 1 commits into bitcoin:master from JeremyRubin:faster_tests changing 51 files +2329 −2322
  1. JeremyRubin commented at 5:03 am on September 2, 2016: contributor

    unit tests can be really slow under wine because BOOST_CHECK logs something for all tests. This patch makes them faster by only logging tests which fail. PR’d an alternative to #8632.

    Benchmarks

    Wine

    Before:

    real 3m52.840s user 3m52.217s sys 0m0.241s

    Just Prevector:

    real 0m30.358s user 0m29.695s sys 0m0.165s

    After:

    real 0m20.445s user 0m19.888s sys 0m0.193s

    Ubuntu

    Before:

    real 0m20.887s user 0m20.360s sys 0m0.108s

    After:

    real 0m11.894s user 0m11.645s sys 0m0.060s

  2. Make tests much faster by replacing BOOST_CHECK with FAST_CHECK 1af4697f8f
  3. fanquake added the label Tests on Sep 2, 2016
  4. jonasschnelli commented at 6:39 am on September 2, 2016: contributor
  5. laanwj commented at 8:05 am on September 2, 2016: member

    Concept ACK. After:

    0git diff HEAD~1 --name-only | xargs sed -i "s/FAST_CHECK/BOOST_CHECK/g"
    

    There is a remaining diff in test_bitcoin.h:

    0+#define BOOST_CHECK(x) if (!(x)) { BOOST_CHECK_MESSAGE(false, #x); }
    1+#define BOOST_CHECK_EQUAL(x, y) if ((x)!=(y)) { BOOST_CHECK_MESSAGE(false, "(" #x ") != (" #y ")"); }
    2+#define BOOST_CHECK_THROW(expr, ex) try { expr; BOOST_CHECK_MESSAGE(false, "( " #expr " ) did not throw ( " #ex " )"); } catch( ex ) { }
    3+#define BOOST_CHECK_NO_THROW(expr) try { expr;  } catch( ... ) {BOOST_CHECK_MESSAGE(false, "( " #expr " ) threw exception"); }
    4+#define BOOST_CHECK_EXCEPTION(expr, ex, pred) try { expr; BOOST_CHECK_MESSAGE(false, "( " #expr " ) did not throw ( " #ex " )"); } catch( ex& a ) { if (!pred(a)) BOOST_CHECK_MESSAGE(false, "( " #expr " ) did not throw ( " #ex " ) under ( " #pred " )" ); }
    5+#define BOOST_CHECK_EQUAL_COLLECTIONS(l, r, l1, r1) BOOST_CHECK_EQUAL_COLLECTIONS(l, r, l1, r1) 
    6+
    

    Any specific reason for (re-)defining these?

    Oh never mind - these are replaced of course @jonasschnelli has the right definitions. So you define custom testing macros, right.

  6. laanwj commented at 8:54 am on September 2, 2016: member

    Q: What functionality do we lose here, apart from being able to log successful tests (which is arguably unnecessary)? For example I vaguely remember that the BOOST_CHECK_EQUAL does an attempt to print the values, not just the stringified form of the input arguments.

    At some point we likely want to get rid of boost::test completely. as we are trying to eventually remove the dependency on boost, so this is a step in the right direction.

  7. JeremyRubin commented at 5:59 pm on September 2, 2016: contributor

    @laanwj I may be able to make it completely compatible minus the succeeding tests for each macro. You are correct that boost_check_equal does that; this is part of why I did not redefine the container equal one.

    What I’m unsure of is how that affects licensing given those would be a derivative work I believe – perhaps I could break out my macros into a sub-library and keep it boost licensed?

  8. MarcoFalke commented at 11:21 am on September 6, 2016: member
    Trivial rebase required. Also, I was wondering how we could forbid usage of the “legacy” `BOOST_CHECK_* to prevent diverging code.
  9. laanwj commented at 1:34 pm on September 6, 2016: member

    perhaps I could break out my macros into a sub-library and keep it boost licensed?

    Right, that makes sense: if you’re using any boost code then it’s a derivative work, if you’re just using the names of the macros for compatibility it’s not. Do note that the boost license is more permissive than MIT/BSD (no attribution requirement), so including a boost-licensed source file is not a problem.

  10. MarcoFalke commented at 1:41 pm on September 6, 2016: member

    Huh? I didn’t see any boost source code added, so the current pull should be good license wise.

    Fast check is just a wrapper around boost check, which should be fine as long as you don’t distribute fast check as a separate tool.

  11. laanwj commented at 1:43 pm on September 6, 2016: member

    Huh? I didn’t see any boost source code added, so the current pull should be good license wise.

    Yes the current pull is, but (read back a few posts) he is talking about extending the functionality to something completely compatible.

  12. MarcoFalke commented at 1:45 pm on September 6, 2016: member

    @laanwj I don’t see how we lose functionality.

    @ Jeremy Check your mail. It should be trivial to keep the log messages the same as well

    On Friday, September 2, 2016, Wladimir J. van der Laan < notifications@github.com> wrote:

    Q: What functionality do we lose here, apart from being able to log successful tests (which is arguably unnecessary)? For example I vaguely remember that the BOOST_CHECK_EQUAL does an attempt to print the values, not just the stringified form of the input arguments.

    — You are receiving this because you are subscribed to this thread. Reply to this email directly, view it on GitHub, or mute the thread.< https://ci5.googleusercontent.com/proxy/y-3C4A3Q1wrYbmH2Ylkt2A0H5t_g18JH93W1j4X-rMvxva57umGu8LYbGWrx-2KG43iGXvTJzOYsJCFPwGAeUUoshU8yjvuwI0DUJmPFos2gj90HbuEBbw1ji_Lzy2RjVD8YeGwUXfgyHCv6q1DB9eGtazfHQQ=s0-d-e1-ft#https://github.com/notifications/beacon/AGGmv0llHp5MBym3vyMXyqBWvwnwX5n9ks5ql-RjgaJpZM4JzXok.gif>

  13. laanwj commented at 1:46 pm on September 6, 2016: member

    @laanwj I don’t see how we lose functionality.

    That was my question. One thing I noticed was that BOOST_EQUAL no longer prints the contents of what it compares but just stringified variable names (which is much less useful). But I was not sure either if there is more.

  14. MarcoFalke commented at 2:01 pm on September 6, 2016: member
    I see. Fixing this would just require some more code… And when it is 100% compatible, just faster, it could make sense to submit upstream? (The bottleneck, as I understand, lies in boost after all)
  15. JeremyRubin commented at 5:44 pm on September 6, 2016: contributor

    @MarcoFalke @laanwj

    A few notes:

    1. BOOST_CHECK and friends always format the string. This is why part of why it is slow.
    2. We can’t use Marco’s compatibility fix that he emailed me because it is macro-unhygenic
    3. I could just rip the boost macros and replace them with a patched, lighter weight version.
    4. I could just entirely replace boost unit testing and we can not care about preserving functionality completely.

    I think that 4. is probably the best option longer term.

  16. theuni commented at 5:56 pm on September 6, 2016: member

    Concept ACK.

    As far as lost functionality, note that we also lose the checkpoints this way, so if a segfault is introduced, it’s possible that it’s harder to tell where it’s coming from. I suspect that’s part of what makes the macros so expensive to begin with.

    I don’t think those are a huge loss, they’ve never helped me much.

  17. sipa commented at 5:57 pm on September 6, 2016: member
    Oh! I find those checkpoints very useful…
  18. JeremyRubin commented at 8:38 pm on September 6, 2016: contributor

    Ok, here’s what I’m going to do. I’ve just opened up #8671 which does a very minimal change to prevector tests that should fix the underlying issue; while giving more useful debugging output (the rand seeds needed to recreate this test case). I think there’s no reason this can’t merge almost immediately as a much needed stopgap to make the tests just run faster.

    In the meantime, I’ve started working on a boost-free test suite and opened an issue about it #8670. All necessary features should go in there, such as checkpoints being needed by @sipa.

    (@MarcoFalke @laanwj @theuni @jonasschnelli )

  19. JeremyRubin closed this on Sep 6, 2016

  20. MarcoFalke locked this on Sep 8, 2021

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-10-05 01:12 UTC

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