Add fuzzer version of randomized prevector test #18529

pull sipa wants to merge 5 commits into bitcoin:master from sipa:202004_prevector_fuzz changing 2 files +270 −0
  1. sipa commented at 11:52 pm on April 4, 2020: member

    The current prevector test effectively randomly generates a number of operations to perform on a prevector and a normal vector, and checks consistency between the two.

    By converting this into a fuzzer the operations can be targetted rather than random.

  2. fanquake added the label Tests on Apr 4, 2020
  3. MarcoFalke commented at 0:29 am on April 5, 2020: member

    The fuzz tests are not shipped on our website, nor are they run as part of make check. The existing unit test runs in a few milliseconds. So I’d slightly prefer to keep the unit tests for end users on odd compilers/platforms, which would otherwise be left standing in the rain. If you are worries about code duplication of the prevector_tester class, you may put it in ./src/test/util/, which is a library available to all tests.

    Concept ACK on the new fuzzing harness.

  4. in src/test/fuzz/prevector.cpp:223 in a8c3f233a1 outdated
    218+            }
    219+            test.insert_range(prov.ConsumeIntegralInRange<size_t>(0, test.size()), values, values + num);
    220+            break;
    221+        }
    222+        case 6: {
    223+            int del = std::min<int>(test.size(), 1 + prov.ConsumeIntegralInRange<int>(0, 3));
    


    MarcoFalke commented at 0:35 am on April 5, 2020:

    Could this be combined with case 3 and generalized?

    0            int del = prov.ConsumeIntegralInRange<int>(1, test.size());
    

    sipa commented at 10:01 pm on April 6, 2020:
    Indeed, done (and the del range can start at 0 even).
  5. in src/test/fuzz/prevector.cpp:30 in a8c3f233a1 outdated
    25+    pretype pre_vector_alt;
    26+
    27+    typedef typename pretype::size_type Size;
    28+
    29+public:
    30+    void test() {
    


    MarcoFalke commented at 0:35 am on April 5, 2020:

    Can the test method be made read-only? If yes, I think case 15 can be removed?

    0    void test() const {
    

    sipa commented at 10:02 pm on April 6, 2020:

    Right, my thinking was that the fuzzer should be allowed to find intermediate failures too, but I think that’s pointless. A shorter fuzzer input (which runs test once at the end) would accomplish the same.

    Done.

  6. MarcoFalke approved
  7. MarcoFalke commented at 0:37 am on April 5, 2020: member
    ACK on the fuzzer
  8. in src/test/fuzz/prevector.cpp:54 in a8c3f233a1 outdated
    49+        }
    50+        for (const T& v : const_pre_vector) {
    51+             assert(v == real_vector[pos++]);
    52+        }
    53+        for (const T& v : reverse_iterate(const_pre_vector)) {
    54+             assert(v == real_vector[--pos]);
    


    MarcoFalke commented at 0:41 am on April 5, 2020:

    I think the assert-side-effects linter complains about this, so you might have two options:

    • Disable the linter for the fuzz tests
    • Remove the side effect
     0Assertions should not have side effects:
     1
     2src/test/fuzz/prevector.cpp:             assert(v == real_vector[pos++]);
     3
     4src/test/fuzz/prevector.cpp:             assert(v == real_vector[--pos]);
     5
     6src/test/fuzz/prevector.cpp:             assert(v == real_vector[pos++]);
     7
     8src/test/fuzz/prevector.cpp:             assert(v == real_vector[--pos]);
     9
    10^---- failure generated from test/lint/lint-assertions.sh
    

    sipa commented at 10:02 pm on April 6, 2020:
    Fixed by removing the side effect.
  9. Make a fuzzer-based copy of the prevector randomized test 55608455cb
  10. Assert immediately rather than caching failure eda8309bfc
  11. Only run sanity check once at the end 402ad5aaca
  12. Merge and generalize case 3 and case 6 c2ccadc26a
  13. Reorder the test instructions by number b1d24d1d03
  14. in src/Makefile.test.include:630 in a8c3f233a1 outdated
    622@@ -623,6 +623,12 @@ test_fuzz_parse_univalue_LDADD = $(FUZZ_SUITE_LD_COMMON)
    623 test_fuzz_parse_univalue_LDFLAGS = $(RELDFLAGS) $(AM_LDFLAGS) $(LIBTOOL_APP_LDFLAGS)
    624 test_fuzz_parse_univalue_SOURCES = $(FUZZ_SUITE) test/fuzz/parse_univalue.cpp
    625 
    626+test_fuzz_prevector_CPPFLAGS = $(AM_CPPFLAGS) $(BITCOIN_INCLUDES)
    627+test_fuzz_prevector_CXXFLAGS = $(AM_CXXFLAGS) $(PIE_FLAGS)
    628+test_fuzz_prevector_LDADD = $(FUZZ_SUITE_LD_COMMON)
    629+test_fuzz_prevector_LDFLAGS = $(RELDFLAGS) $(AM_LDFLAGS) $(LIBTOOL_APP_LDFLAGS)
    630+test_fuzz_prevector_SOURCES = $(FUZZ_SUITE) test/fuzz/prevector.cpp
    


    MarcoFalke commented at 2:36 am on April 5, 2020:

    Needs rebase, sorry

    0test_fuzz_prevector_SOURCES = test/fuzz/prevector.cpp
    

    sipa commented at 10:03 pm on April 6, 2020:
    No worries, done.
  15. sipa force-pushed on Apr 6, 2020
  16. sipa commented at 10:07 pm on April 6, 2020: member
    @MarcoFalke Rebased, addressed your comments, and removed removal of the existing unit test (I’ve duplicated instead of creating a common shared class, as I expect the two to diverge - the existing test is much more suited as an approach for fuzzing, while we may want a few static cases instead as unit tests).
  17. sipa renamed this:
    Convert randomized prevector test into fuzzer
    Add fuzzer version of randomized prevector test
    on Apr 6, 2020
  18. MarcoFalke commented at 6:55 pm on April 9, 2020: member

    ACK b1d24d1d031a2b2ce67bf846bafa1c3a499b7553 🍬

    Signature:

     0-----BEGIN PGP SIGNED MESSAGE-----
     1Hash: SHA512
     2
     3ACK b1d24d1d031a2b2ce67bf846bafa1c3a499b7553 🍬
     4-----BEGIN PGP SIGNATURE-----
     5
     6iQGzBAEBCgAdFiEE+rVPoUahrI9sLGYTzit1aX5ppUgFAlwqrYAACgkQzit1aX5p
     7pUjr+Qv/Xzpe1YkQG9BnrvlnlXx+mop66tdFHH3YXUWm8vaz9MPrQx3aWk1AW0xP
     8m8PcmwXxne6sl7ohdn4GKcM5LT1qbczArzQ409CRvyXsUOVXouuH0O2mVRxao2WE
     9ge+MivCWX9TUlieUBnXlb7Aa9BKprE8RlrCcpEPZ2mXtv/gtzjuzrt98kCJGOjRb
    10pN7cuwQegAXhWnEeZjzGW9WFzORN9aBQGWd9AxQT5ARt5zU2FPrDtRfNGLkIj0tF
    110qCzmocq79NeMhugnSBGJMps66uGLjceUEd1jxntJUmjMJW/9LvNUS2IjjCu2GLW
    12aoogrsLtJGgAr/W/FOvvbFF5prgFEKhmtHPGcOIBEafbXHoS0AfVxlOOMekEijMF
    13YmTOs8mb2hOEa9K5tsFi1S5eCYZnH7ZIUF1fqzyiExbnLhuPKecgy1K0lLiOud1c
    14D+dk5L+9PU6u6X12QBl/w+j3b9kt8X+Cjse+UrZhiOWtBsicl/BKVxg45yzaH2BT
    15pHj6SgM2
    16=BYOH
    17-----END PGP SIGNATURE-----
    
  19. MarcoFalke merged this on Apr 9, 2020
  20. MarcoFalke closed this on Apr 9, 2020

  21. sidhujag referenced this in commit 284cdf7e08 on Apr 13, 2020
  22. Fabcien referenced this in commit 3c8f5fb298 on Jan 21, 2021
  23. in src/test/fuzz/prevector.cpp:200 in b1d24d1d03
    195+            break;
    196+        case 1:
    197+            test.resize(std::max(0, std::min(30, (int)test.size() + prov.ConsumeIntegralInRange<int>(0, 4) - 2)));
    198+            break;
    199+        case 2:
    200+            test.insert(prov.ConsumeIntegralInRange<size_t>(0, test.size()), 1 + prov.ConsumeBool(), prov.ConsumeIntegral<int>());
    


    MarcoFalke commented at 9:56 am on July 16, 2021:
    post-merge question: Is there a reason to limit the number of elements inserted in this case to 1 or 2?
  24. kittywhiskers referenced this in commit 47187036e1 on May 7, 2022
  25. kittywhiskers referenced this in commit 92741cf791 on May 7, 2022
  26. kittywhiskers referenced this in commit eb9df116e4 on Jun 14, 2022
  27. kittywhiskers referenced this in commit aa29192aef on Jun 14, 2022
  28. kittywhiskers referenced this in commit d9b97cc807 on Jun 18, 2022
  29. kittywhiskers referenced this in commit 079beb50d1 on Jul 4, 2022
  30. kittywhiskers referenced this in commit e4fe35ca3c on Jul 4, 2022
  31. kittywhiskers referenced this in commit 144ff55a65 on Jul 6, 2022
  32. kittywhiskers referenced this in commit 26ea6762d3 on Jul 6, 2022
  33. PastaPastaPasta referenced this in commit eefdae1a53 on Jul 12, 2022
  34. knst referenced this in commit b0c1fe7e5f on Jul 21, 2022
  35. DrahtBot locked this on Aug 18, 2022


sipa MarcoFalke

Labels
Tests


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-06-18 04:12 UTC

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