Skip to content

Commit

Permalink
feat(test): update fuzz tests
Browse files Browse the repository at this point in the history
  • Loading branch information
6cdh committed Mar 12, 2024
1 parent f4b2e97 commit b5a2fe7
Show file tree
Hide file tree
Showing 2 changed files with 28 additions and 33 deletions.
15 changes: 8 additions & 7 deletions fuzztest/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,22 +4,23 @@ The directory contains the scripts that test the implementation to avoid the pro

## Resource

* ~6 minutes to run
* ~300M generated files
* Racket 8.11.1 (cs)
* ~3 minutes to run
* 288M generated files

## Run

```shell
$ cd fuzztest
# 30s
# 18s
$ racket gen_cases.rkt
cpu time: 26531 real time: 26835 gc time: 1069
5114173 cases generated
cpu time: 17972 real time: 18077 gc time: 475
5156699 cases generated
$ cd ..
$ tree-sitter generate
# 3 minutes
# 92s
$ tree-sitter parse fuzztest/case.txt > fuzztest/res1.txt
# 2 minutes
# 50s
$ cd fuzztest && racket postprocess.rkt
# should show nothing
$ sdiff -s <(cat -n expect.txt) <(cat -n res.txt)
Expand Down
46 changes: 20 additions & 26 deletions fuzztest/gen_cases.rkt
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@

;; all characters that can appear in a valid number/exflonum
;; remove some insignificant parts to improve performance
;; (define alphabet-char "abdefilnost")
(define alphabet-char "abdefilnostx")
(define special-char "#./@+-")
;; (define numeric-char "0123456789")
Expand All @@ -24,31 +23,26 @@
(with-handlers ([exn:fail? (lambda _ (void))])
(when (> i 0)
(define case-str (list->string case))
;; ".0@.0" should be a number according the document,
;; but it's actually a symbol.
;; It's a bug of Racket reader, and will fix in new Racket release.
;; we skip these cases.
(when (not (string-contains? case-str "@."))
(with-handlers ([exn:fail? void])
(with-input-from-string case-str
(lambda ()
(define fst (read))
(define snd (read))
(when (eof-object? snd)
(cond [(symbol? fst)
(set! cnt (add1 cnt))
(displayln case-str case-port)
(displayln "symbol" expect-port)]
[(number? fst)
(set! cnt (add1 cnt))
(displayln case-str case-port)
(displayln "number" expect-port)]
;; it's here for possible future change that
;; split extflonum from number
[(extflonum? fst)
(set! cnt (add1 cnt))
(displayln case-str case-port)
(displayln "number" expect-port)]))))))))
(with-handlers ([exn:fail? void])
(with-input-from-string case-str
(lambda ()
(define fst (read))
(define snd (read))
(when (eof-object? snd)
(cond [(symbol? fst)
(set! cnt (add1 cnt))
(displayln case-str case-port)
(displayln "symbol" expect-port)]
[(number? fst)
(set! cnt (add1 cnt))
(displayln case-str case-port)
(displayln "number" expect-port)]
;; it's here for possible future change that
;; split extflonum from number
[(extflonum? fst)
(set! cnt (add1 cnt))
(displayln case-str case-port)
(displayln "number" expect-port)])))))))
(when (< i max-len)
(for ([c all-char])
(gen (add1 i) (cons c case)))))
Expand Down

0 comments on commit b5a2fe7

Please sign in to comment.