Skip to content

Instantly share code, notes, and snippets.

@kragen
Created November 30, 2017 20:35
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save kragen/4b8644be70871c829448676900507c7d to your computer and use it in GitHub Desktop.
Save kragen/4b8644be70871c829448676900507c7d to your computer and use it in GitHub Desktop.
how Hypothesis found a bug in my Adler-32 implementation
user@debian ~/dumpulse $ make test
cc -fPIC -g -Os -Wall -Wpedantic -std=c89 -o dumpulse.o -c dumpulse.c
cc -shared dumpulse_so.o dumpulse.o -o dumpulse.so
py.test-3 test.py
===================================== test session starts =====================================
platform linux -- Python 3.5.2, pytest-2.8.7, py-1.4.31, pluggy-0.3.1
rootdir: /home/user/dumpulse, inifile:
plugins: hypothesis-3.0.1
collected 1 items
test.py F
========================================== FAILURES ===========================================
____________________________________ TestDumpulse.runTest _____________________________________
self = <hypothesis.stateful.DumpulseTest.TestCase testMethod=runTest>
def runTest(self):
> run_state_machine_as_test(state_machine_class)
/usr/lib/python3/dist-packages/hypothesis/stateful.py:176:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
/usr/lib/python3/dist-packages/hypothesis/stateful.py:105: in run_state_machine_as_test
breaker.run(state_machine_factory(), print_steps=True)
/usr/lib/python3/dist-packages/hypothesis/stateful.py:226: in run
state_machine.execute_step(value)
/usr/lib/python3/dist-packages/hypothesis/stateful.py:465: in execute_step
result = rule.function(self, **data)
test.py:58: in try_health_check
settings = client.variable_settings(health_check)
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
health_report_bytes = b'\x12\xa4\x04(\x00\xf6\x00\x00y\xcd\x00\xff\x97U\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\...00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00'
def variable_settings(health_report_bytes):
"""Returns a list of (variable number, timestamp, sender, value) tuples.
Raises ValueError if this is not a valid health report packet.
"""
settings, expected, received = parse_health_report(health_report_bytes)
if expected != received:
> raise ValueError(health_report_bytes, expected, received)
E ValueError: (b'\x12\xa4\x04(\x00\xf6\x00\x00y\xcd\x00\xff\x97U\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00', 313721896, 312738856)
client.py:54: ValueError
------------------------------------ Captured stdout call -------------------------------------
Step #1: v1 = new_server()
Step #2: v2 = new_server()
Step #3: v3 = try_health_check(instance=v1)
Step #4: v4 = try_health_check(instance=v1)
Step #5: v5 = send_invalid_packet(packet=b'', instance=v1)
Step #6: v6 = send_invalid_packet(packet=b'', instance=v1)
Step #7: v7 = new_server()
Step #8: v8 = send_invalid_packet(packet=b'', instance=v1)
Step #9: v9 = new_server()
Step #10: v10 = valid_variable_set_packet(value=0, when=0, sender=0, variable=0, instance=v1)
Step #11: v11 = valid_variable_set_packet(value=0, when=246, sender=0, variable=0, instance=v1)
Step #12: v12 = valid_variable_set_packet(value=0, when=38741, sender=0, variable=2, instance=v1)
Step #13: v13 = new_server()
Step #14: v14 = valid_variable_set_packet(value=255, when=31181, sender=0, variable=1, instance=v1)
Step #15: v15 = try_health_check(instance=v1)
================================== 1 failed in 60.24 seconds ==================================
Makefile:11: recipe for target 'test' failed
make: *** [test] Error 1
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment