-
Notifications
You must be signed in to change notification settings - Fork 388
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge branch 'master' into all-use-fmt.Fprintf-to-avoid-raw-string-co…
…ncatentation+io.StringWriter.WriteString
- Loading branch information
Showing
22 changed files
with
352 additions
and
3 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,31 @@ | ||
package gnolang | ||
|
||
import ( | ||
"testing" | ||
) | ||
|
||
var sink any = nil | ||
|
||
var pkgIDPaths = []string{ | ||
"encoding/json", | ||
"math/bits", | ||
"github.com/gnolang/gno/gnovm/pkg/gnolang", | ||
"a", | ||
" ", | ||
"", | ||
"github.com/gnolang/gno/gnovm/pkg/gnolang/vendor/pkg/github.com/gnolang/vendored", | ||
} | ||
|
||
func BenchmarkPkgIDFromPkgPath(b *testing.B) { | ||
b.ReportAllocs() | ||
for i := 0; i < b.N; i++ { | ||
for _, path := range pkgIDPaths { | ||
sink = PkgIDFromPkgPath(path) | ||
} | ||
} | ||
|
||
if sink == nil { | ||
b.Fatal("Benchmark did not run!") | ||
} | ||
sink = nil | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,89 @@ | ||
package gnolang | ||
|
||
import ( | ||
"os" | ||
"path/filepath" | ||
"runtime" | ||
"strings" | ||
"testing" | ||
|
||
"github.com/cockroachdb/apd/v3" | ||
) | ||
|
||
func FuzzConvertUntypedBigdecToFloat(f *testing.F) { | ||
// 1. Firstly add seeds. | ||
seeds := []string{ | ||
"-100000", | ||
"100000", | ||
"0", | ||
} | ||
|
||
check := new(apd.Decimal) | ||
for _, seed := range seeds { | ||
if check.UnmarshalText([]byte(seed)) == nil { | ||
f.Add(seed) | ||
} | ||
} | ||
|
||
f.Fuzz(func(t *testing.T, apdStr string) { | ||
switch { | ||
case strings.HasPrefix(apdStr, ".-"): | ||
return | ||
} | ||
|
||
v := new(apd.Decimal) | ||
if err := v.UnmarshalText([]byte(apdStr)); err != nil { | ||
return | ||
} | ||
if _, err := v.Float64(); err != nil { | ||
return | ||
} | ||
|
||
bd := BigdecValue{ | ||
V: v, | ||
} | ||
dst := new(TypedValue) | ||
typ := Float64Type | ||
ConvertUntypedBigdecTo(dst, bd, typ) | ||
}) | ||
} | ||
|
||
func FuzzParseFile(f *testing.F) { | ||
// 1. Add the corpra. | ||
parseFileDir := filepath.Join("testdata", "corpra", "parsefile") | ||
paths, err := filepath.Glob(filepath.Join(parseFileDir, "*.go")) | ||
if err != nil { | ||
f.Fatal(err) | ||
} | ||
|
||
// Also load in files from gno/gnovm/tests/files | ||
pc, curFile, _, _ := runtime.Caller(0) | ||
curFileDir := filepath.Dir(curFile) | ||
gnovmTestFilesDir, err := filepath.Abs(filepath.Join(curFileDir, "..", "..", "tests", "files")) | ||
if err != nil { | ||
_ = pc // To silence the arbitrary golangci linter. | ||
f.Fatal(err) | ||
} | ||
globGnoTestFiles := filepath.Join(gnovmTestFilesDir, "*.gno") | ||
gnoTestFiles, err := filepath.Glob(globGnoTestFiles) | ||
if err != nil { | ||
f.Fatal(err) | ||
} | ||
if len(gnoTestFiles) == 0 { | ||
f.Fatalf("no files found from globbing %q", globGnoTestFiles) | ||
} | ||
paths = append(paths, gnoTestFiles...) | ||
|
||
for _, path := range paths { | ||
blob, err := os.ReadFile(path) | ||
if err != nil { | ||
f.Fatal(err) | ||
} | ||
f.Add(string(blob)) | ||
} | ||
|
||
// 2. Now run the fuzzer. | ||
f.Fuzz(func(t *testing.T, goFileContents string) { | ||
_, _ = ParseFile("a.go", goFileContents) | ||
}) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
package main | ||
|
||
import | ||
_ "math/big" | ||
) | ||
|
||
func main() { | ||
println("Foo") | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,16 @@ | ||
package main | ||
|
||
import "crypto/rand" | ||
|
||
func init() { | ||
} | ||
|
||
func init() { | ||
} | ||
|
||
func init() { | ||
} | ||
|
||
func it() { | ||
_ = rand.Read | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,22 @@ | ||
package main | ||
|
||
import "testing" | ||
|
||
func TestDummy(t *testing.T) { | ||
testTable := []struct { | ||
name string | ||
}{ | ||
{ | ||
"one", | ||
}, | ||
{ | ||
"two", | ||
}, | ||
} | ||
|
||
for _, testCase := range testTable { | ||
testCase := testCase | ||
|
||
println(testCase.name) | ||
} | ||
} |
10 changes: 10 additions & 0 deletions
10
gnovm/pkg/gnolang/testdata/corpra/parsefile/bug_3014_redefine.go
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,10 @@ | ||
package main | ||
 | ||
var ss = []int{1, 2, 3} | ||
 | ||
func main() { | ||
 for _, s := range ss { | ||
 s := s | ||
 println(s) | ||
 } | ||
} |
21 changes: 21 additions & 0 deletions
21
gnovm/pkg/gnolang/testdata/corpra/parsefile/bug_3014_redefine2.go
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,21 @@ | ||
package main | ||
 | ||
var testTable = []struct { | ||
 name string | ||
}{ | ||
 { | ||
 "one", | ||
 }, | ||
 { | ||
 "two", | ||
 }, | ||
} | ||
 | ||
func main() { | ||
 | ||
 for _, testCase := range testTable { | ||
 testCase := testCase | ||
 | ||
 println(testCase.name) | ||
 } | ||
} |
8 changes: 8 additions & 0 deletions
8
gnovm/pkg/gnolang/testdata/corpra/parsefile/bug_3014_redefine3.go
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,8 @@ | ||
package main | ||
 | ||
func main() { | ||
 for i := 0; i < 3; i++ { | ||
 i := i | ||
 println(i) | ||
 } | ||
} |
11 changes: 11 additions & 0 deletions
11
gnovm/pkg/gnolang/testdata/corpra/parsefile/bug_3014_redefine4.go
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,11 @@ | ||
package main | ||
 | ||
func main() { | ||
 a := 1 | ||
 b := 3 | ||
 println(a, b) // prints 1 3 | ||
 | ||
 // Re-declaration of 'a' is allowed because 'c' is a new variable | ||
 a, c := 2, 5 | ||
 println(a, c) // prints 2 5 | ||
} |
13 changes: 13 additions & 0 deletions
13
gnovm/pkg/gnolang/testdata/corpra/parsefile/bug_3014_redefine5.go
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,13 @@ | ||
package main | ||
 | ||
func main() { | ||
 a := 1 | ||
 println(a) // prints 1 | ||
 | ||
 if true { | ||
 a := 2 // valid: new scope inside the if statement | ||
 println(a) // prints 2 | ||
 } | ||
 | ||
 println(a) // prints 1: outer variable is unchanged | ||
} |
6 changes: 6 additions & 0 deletions
6
gnovm/pkg/gnolang/testdata/corpra/parsefile/bug_3014_redefine6.go
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,6 @@ | ||
package main | ||
 | ||
func main() { | ||
 a, b := 1, 2 | ||
 a, b := 3, 4 | ||
} |
2 changes: 2 additions & 0 deletions
2
gnovm/pkg/gnolang/testdata/fuzz/FuzzConvertUntypedBigdecToFloat/4be24841138e3224
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,2 @@ | ||
go test fuzz v1 | ||
string(".-700000000000000000000000000000000000000") |
2 changes: 2 additions & 0 deletions
2
gnovm/pkg/gnolang/testdata/fuzz/FuzzConvertUntypedBigdecToFloat/94196a9456e79dac
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,2 @@ | ||
go test fuzz v1 | ||
string("200000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000") |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,80 @@ | ||
package transpiler | ||
|
||
import ( | ||
"fmt" | ||
"io" | ||
"io/fs" | ||
"os" | ||
"path/filepath" | ||
"runtime" | ||
"strings" | ||
"testing" | ||
"time" | ||
) | ||
|
||
func FuzzTranspiling(f *testing.F) { | ||
if testing.Short() { | ||
f.Skip("Running in -short mode") | ||
} | ||
|
||
// 1. Derive the seeds from our seedGnoFiles. | ||
breakRoot := filepath.Join("gnolang", "gno") | ||
pc, thisFile, _, _ := runtime.Caller(0) | ||
index := strings.Index(thisFile, breakRoot) | ||
_ = pc // to silence the pedantic golangci linter. | ||
rootPath := thisFile[:index+len(breakRoot)] | ||
examplesDir := filepath.Join(rootPath, "examples") | ||
ffs := os.DirFS(examplesDir) | ||
fs.WalkDir(ffs, ".", func(path string, d fs.DirEntry, err error) error { | ||
if err != nil { | ||
panic(err) | ||
} | ||
if !strings.HasSuffix(path, ".gno") { | ||
return nil | ||
} | ||
file, err := ffs.Open(path) | ||
if err != nil { | ||
panic(err) | ||
} | ||
blob, err := io.ReadAll(file) | ||
file.Close() | ||
if err != nil { | ||
panic(err) | ||
} | ||
f.Add(blob) | ||
return nil | ||
}) | ||
|
||
// 2. Run the fuzzers. | ||
f.Fuzz(func(t *testing.T, gnoSourceCode []byte) { | ||
// 3. Add timings to ensure that if transpiling takes a long time | ||
// to run, that we report this as problematic. | ||
doneCh := make(chan bool, 1) | ||
readyCh := make(chan bool) | ||
go func() { | ||
defer func() { | ||
r := recover() | ||
if r == nil { | ||
return | ||
} | ||
|
||
sr := fmt.Sprintf("%s", r) | ||
if !strings.Contains(sr, "invalid line number ") { | ||
panic(r) | ||
} | ||
}() | ||
close(readyCh) | ||
defer close(doneCh) | ||
_, _ = Transpile(string(gnoSourceCode), "gno", "in.gno") | ||
doneCh <- true | ||
}() | ||
|
||
<-readyCh | ||
|
||
select { | ||
case <-time.After(2 * time.Second): | ||
t.Fatalf("took more than 2 seconds to transpile\n\n%s", gnoSourceCode) | ||
case <-doneCh: | ||
} | ||
}) | ||
} |
2 changes: 2 additions & 0 deletions
2
gnovm/pkg/transpiler/testdata/fuzz/FuzzTranspiling/26ec2c0a22e242fc
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,2 @@ | ||
go test fuzz v1 | ||
[]byte("package\tA\nimport(\"\"//\"\n\"\"/***/)") |
2 changes: 2 additions & 0 deletions
2
gnovm/pkg/transpiler/testdata/fuzz/FuzzTranspiling/54f7287f473abfa5
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,2 @@ | ||
go test fuzz v1 | ||
[]byte("package A\nimport(\"\"//\"\n\"\"/***/)") |
2 changes: 2 additions & 0 deletions
2
gnovm/pkg/transpiler/testdata/fuzz/FuzzTranspiling/703a1cacabb84c6d
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,2 @@ | ||
go test fuzz v1 | ||
[]byte("package A\ncon\x12\n\xec|b\x80\xddQst(\n/*\n\n\n\n\n\n\nka\n*/A)") |
Oops, something went wrong.