forked from dvyukov/go-fuzz
-
Notifications
You must be signed in to change notification settings - Fork 1
/
test.go
149 lines (127 loc) · 2.28 KB
/
test.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
// Copyright 2015 Dmitry Vyukov. All rights reserved.
// Use of this source code is governed by Apache 2 LICENSE that can be found in the LICENSE file.
package test
import (
"bytes"
)
func Fuzz(data []byte) int {
if len(data) == 1 {
if data[0] == '!' || data[0] == '#' {
panic("bingo 0")
}
if data[0] == '0' || data[0] == '9' {
for {
c := make(chan bool)
close(c)
}
}
if data[0] == 'a' || data[0] == 'z' {
data := make([]byte, 128<<30-1)
_ = data
}
if data[0] == 'b' {
// new coverage
}
if data[0] == 'c' {
// new coverage
}
}
// Test for crash minimization.
if bytes.IndexByte(data, 'x') != -1 {
if bytes.IndexByte(data, 'y') != -1 {
panic("xy")
}
}
// Test for input minimization.
if bytes.Index(data, []byte("input ")) != -1 {
if bytes.Index(data, []byte("minimization ")) != -1 {
if bytes.Index(data, []byte("test")) != -1 {
}
}
}
if len(data) >= 14 && bytes.HasPrefix(data, []byte("0123456789")) {
x := int(data[10]) + int(data[11])<<8 + int(data[12])<<16 + int(data[13])<<24
if x == 0 || x == -1 {
panic("bingo 1")
}
if x == 255 || x == 256 {
for {
c := make(chan bool)
close(c)
}
}
if x == 1<<16-1 || x == 1<<16 {
data := make([]byte, 128<<30-1)
_ = data
}
if x == '1' {
// new coverage
}
if x == '2' {
// new coverage
}
}
return 0
}
// Compilation tests, go-fuzz-build previously failed on these code patterns.
// Test for issue #35.
const X = 1 << 129
func foo(x float64) bool {
return x < X
}
func test1() bool {
var x uint64
var y uint
return x == 1<<y
}
func test11() bool {
var x uint64
var y uint
return x < (1<<uint64(y))-1
}
func Pow(x, y float64) float64 {
switch {
case x == -1:
return 1
case (Abs(x) < 1) == IsInf(y, 1):
return 0
default:
return 1
}
}
func Abs(x float64) float64 {
return x
}
func IsInf(x float64, v int) bool {
return x != 0
}
func test2(p *int) bool {
return p == nil
}
type ChanDir int
const (
SEND ChanDir = 1 << iota
RECV
)
func test3(x ChanDir) bool {
return x == SEND|RECV
}
type MyBool bool
func test4(x, y MyBool) MyBool {
if x && y {
return true
}
if true && y {
return true
}
if x && true {
return true
}
return false
}
func bla() error {
return nil
}
func test5() bool {
return nil == bla()
}