Fossil SCM

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

Keyboard Shortcuts

Open search /
Next entry (timeline) j
Previous entry (timeline) k
Open focused entry Enter
Show this help ?
Toggle theme Top nav button