|
1
|
# |
|
2
|
# Copyright (c) 2026 Dan Mestas |
|
3
|
# |
|
4
|
# This program is free software; you can redistribute it and/or |
|
5
|
# modify it under the terms of the Simplified BSD License (also |
|
6
|
# known as the "2-Clause License" or "FreeBSD License".) |
|
7
|
# |
|
8
|
# This program is distributed in the hope that it will be useful, |
|
9
|
# but without any warranty; without even the implied warranty of |
|
10
|
# merchantability or fitness for a particular purpose. |
|
11
|
# |
|
12
|
############################################################################ |
|
13
|
# |
|
14
|
# Run every input in corpus/corpus.pack, and the sample wiki and markdown pages |
|
15
|
# in this directory, through "fossil test-fuzz". The pack is unpacked |
|
16
|
# into a directory for each fuzz type. See corpus.tcl. |
|
17
|
# |
|
18
|
# The scenario inputs are not inputs to "test-fuzz". They are read by |
|
19
|
# scenario.test. |
|
20
|
# |
|
21
|
|
|
22
|
require_no_open_checkout |
|
23
|
|
|
24
|
test_setup |
|
25
|
|
|
26
|
source [file join $::testfiledir corpus.tcl] |
|
27
|
set fuzzTypes [corpus_unpack [file join $::testfiledir corpus corpus.pack] \ |
|
28
|
[file join [pwd] corpus]] |
|
29
|
test_eq fuzz-corpus-types $fuzzTypes [list delta-accept delta-apply \ |
|
30
|
delta-reject delta-roundtrip manifest manifest-body scenario xfer] |
|
31
|
|
|
32
|
# The corpus types are fuzz types of a fossil with the "test-fuzz-inert" |
|
33
|
# command. Another fossil does not know them, so the tests would check |
|
34
|
# nothing. |
|
35
|
fossil_raw test-fuzz-inert |
|
36
|
set fuzzHaveTypes [expr {[string first "unknown command" $RESULT] < 0}] |
|
37
|
if {!$fuzzHaveTypes} { |
|
38
|
test_skip_part "fuzz-corpus-TYPE: test-fuzz needs the delta, manifest\ |
|
39
|
and xfer fuzz types of a fossil with the test-fuzz-inert command" |
|
40
|
} |
|
41
|
foreach fuzzDir [lsort [glob -nocomplain -types d [file join corpus *]]] { |
|
42
|
set fuzzType [file tail $fuzzDir] |
|
43
|
if {$fuzzType eq "scenario" || !$fuzzHaveTypes} continue |
|
44
|
fossil test-fuzz $fuzzDir |
|
45
|
test fuzz-corpus-$fuzzType {$CODE == 0} |
|
46
|
} |
|
47
|
|
|
48
|
foreach {fuzzType fuzzGlob} {wiki *.wiki markdown *.md wiki2 *.md} { |
|
49
|
foreach fuzzF [lsort [glob \ |
|
50
|
-nocomplain [file join $::testfiledir $fuzzGlob]]] { |
|
51
|
fossil test-fuzz --fuzztype $fuzzType $fuzzF |
|
52
|
test fuzz-$fuzzType-[file tail $fuzzF] {$CODE == 0} |
|
53
|
} |
|
54
|
} |
|
55
|
|
|
56
|
# Every input of the two manifest types must begin with the guard lines, |
|
57
|
# and neither the pack nor any input may be accepted by Fossil as an |
|
58
|
# artifact. Otherwise a repository holding the file would act on it. |
|
59
|
# See corpus.tcl. |
|
60
|
set fuzzGuard "# test-corpus: inert on disk. " |
|
61
|
set fuzzNotInert {} |
|
62
|
foreach fuzzType {manifest manifest-body} { |
|
63
|
foreach fuzzF [lsort [glob -nocomplain [file join corpus $fuzzType *]]] { |
|
64
|
set fuzzFd [open $fuzzF rb] |
|
65
|
set fuzzHead [read $fuzzFd [string length $fuzzGuard]] |
|
66
|
close $fuzzFd |
|
67
|
if {$fuzzHead ne $fuzzGuard} { |
|
68
|
lappend fuzzNotInert $fuzzType/[file tail $fuzzF] |
|
69
|
} |
|
70
|
} |
|
71
|
} |
|
72
|
test fuzz-corpus-manifest-guarded {[llength $fuzzNotInert] == 0} |
|
73
|
|
|
74
|
# The tests below need the "test-fuzz-inert" command and the checks on |
|
75
|
# fuzz types and empty inputs that come with it. |
|
76
|
if {!$fuzzHaveTypes} { |
|
77
|
test_skip "the tests of test-fuzz-inert, empty inputs and fuzz type\ |
|
78
|
names need a fossil with the test-fuzz-inert command" |
|
79
|
} |
|
80
|
file mkdir pack |
|
81
|
file copy [file join $::testfiledir corpus corpus.pack] pack |
|
82
|
fossil test-fuzz-inert pack |
|
83
|
test fuzz-corpus-pack-inert {$CODE == 0} |
|
84
|
foreach fuzzDir [lsort [glob -nocomplain -types d [file join corpus *]]] { |
|
85
|
fossil test-fuzz-inert $fuzzDir |
|
86
|
test fuzz-corpus-[file tail $fuzzDir]-inert {$CODE == 0} |
|
87
|
} |
|
88
|
|
|
89
|
# A fuzzing engine begins with an input of no bytes. |
|
90
|
write_file empty-input "" |
|
91
|
foreach fuzzType {manifest manifest-body xfer} { |
|
92
|
fossil test-fuzz --fuzztype $fuzzType empty-input |
|
93
|
test fuzz-$fuzzType-empty-input {$CODE == 0} |
|
94
|
} |
|
95
|
|
|
96
|
# A directory that is not named for a fuzz type must be refused, so that |
|
97
|
# its files are not quietly run through the wrong target. |
|
98
|
file mkdir not-a-fuzz-type |
|
99
|
write_file [file join not-a-fuzz-type x] "x\n" |
|
100
|
fossil test-fuzz not-a-fuzz-type -expectError |
|
101
|
test fuzz-misnamed-directory {$CODE != 0} |
|
102
|
|
|
103
|
test_cleanup |
|
104
|
|