fuzz.go 815 B

12345678910111213141516171819202122232425262728293031
  1. // +build gofuzz
  2. package sdp
  3. // Fuzz implements a randomized fuzz test of the sdp
  4. // parser using go-fuzz.
  5. //
  6. // To run the fuzzer, first download go-fuzz:
  7. // `go get github.com/dvyukov/go-fuzz/...`
  8. //
  9. // Then build the testing package:
  10. // `go-fuzz-build`
  11. //
  12. // And run the fuzzer on the corpus:
  13. // `go-fuzz`
  14. func Fuzz(data []byte) int {
  15. // Check that unmarshalling any byte slice does not panic.
  16. var sd SessionDescription
  17. if err := sd.Unmarshal(data); err != nil {
  18. return 0
  19. }
  20. // Check that we can marshal anything we unmarshalled.
  21. _, err := sd.Marshal()
  22. if err != nil {
  23. panic("failed to marshal") // nolint
  24. }
  25. // It'd be nice to check that if we round trip Marshal then Unmarshal,
  26. // we get the original back. Right now, though, we frequently don't,
  27. // and we'd need to fix that first.
  28. return 1
  29. }