Mercurial > core / lisp/lib/rt/fuzz.lisp
changeset 698: |
96958d3eb5b0 |
parent: |
74e563ed4537
|
author: |
Richard Westhaver <ellis@rwest.io> |
date: |
Fri, 04 Oct 2024 22:04:59 -0400 |
permissions: |
-rw-r--r-- |
description: |
fixes |
1 ;;; fuzz.lisp --- RT Fuzz 8 ;; wiki: https://en.wikipedia.org/wiki/Fuzzing 13 (defvar *default-fuzz-generator* 15 (random most-positive-fixnum state))) 18 ((state :initform (make-random-state t) 21 (generator :initform *default-fuzz-generator* 24 :accessor fuzz-generator)) 25 (:documentation "An object which provides invalid, unexpected or random data as inputs to some 28 (defgeneric fuzz (self &key &allow-other-keys) 29 (:method ((self fuzzer) &key &allow-other-keys) 30 (funcall (the function (fuzz-generator self)) (fuzz-state self))) 31 (:method ((self fuzzer) &key count) 34 (dotimes (i count ret) 35 (push (funcall (the function (fuzz-generator self)) (fuzz-state self)) ret))) 38 (defgeneric fuzz* (state generator &key &allow-other-keys) 39 (:method ((state list) (generator function) &key (count 1)) 41 (dotimes (i count ret) 42 (push (funcall generator state) ret)))) 43 (:method ((state vector) (generator function) &key (count 1)) 44 (let ((ret (make-array count :fill-pointer 0))) 45 (dotimes (i count ret) 46 (setf (aref ret i) (funcall generator state))))) 47 (:method ((state hash-table) (generator function) &key (count 1)) 48 (let ((ret (make-hash-table))) 49 (dotimes (i count ret) 50 (destructuring-bind (k v) (funcall generator state) 51 (setf (gethash k ret) v))))) 52 (:method ((state random-state) (generator function) &key (count 1)) 54 (dotimes (i count ret) 55 (push (funcall generator state) ret)))))