gofuzzgen

package module
v1.1.1 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Mar 18, 2022 License: MIT Imports: 10 Imported by: 0

README

gofuzzgen Go Reference

gofuzzgen is generate template of fuzzing test code

Caution

gofuzzgen is intended to be used for Go1.18 or higher

Install

$ go install github.com/kimuson13/gofuzzgen/cmd/gofuzzgen@latest

Situation to use

When you want to generate a template code of go standard fuzzing test, gofuzzgen help that.

How to use

If you want to generate fuzzing test code with a package, give the package path of interest as the first argument:

$ gofuzzgen github.com/kimuson13/gofuzzgen

To generate fuzzing test code with all packages beneath the current directory:

$ gofuzzgen ./...
Options
  • -o -o can select ouput file name.
    If you type into "hoge" and go package name is "sample", output file name will be hoge_sampel_fuzz_test.go
  • -f -f can select only one function.

Demo

If you are on a directoty like that

$ tree .
sample
├── cmd
│   └── sample
│       └── main.go
├── go.mod
├── go.sum
└── sample.go
$ cat sample.go
package sample

func CanFuzzFunc(a int, b int) {
    return a * b
}

If you run gofuzzgen with no options, result report to stdout.

$ gofuzzgen ./...
// This file is generated by gofuzzgen.
// Only generate fuzzing template.
package sample_test

import "testing"

func FuzzCanFuzzFunc(f *testing.F) {
    testcases := []struct{
        // Add seed corpus here
        arg0 int
        arg1 int
    }

    for _, tc := range testcases {
        f.Add(tc.arg0, tc.arg1)
    }

    f.Fuzz(func(t *testing.T, orig0 int, orig1 int) {
        // implemnt fuzzing test code
    })

}

If you run gofuzzgen with option -o, generate test file.

$ gofuzzgen -o=hoge ./...
$ cat hoge_sample_fuzz_test.go
// This file is generated by gofuzzgen.
// Only generate fuzzing template.
package sample_test

import "testing"

func FuzzCanFuzzFunc(f *testing.F) {
    testcases := []int{
        arg0 int
        arg1 int
    }{
        // Add seed corpus here
    }

    for _, tc := range testcases {
        f.Add(tc.arg0, tc.arg1)
    }

    f.Fuzz(func(t *testing.T, orig0 int, orig1 int) {
        // implemnt fuzzing test code
    })
}

Future Outlook

Overwrite files

Now, gofuzzgen can't over write file that already exist.

No duplicated tests

Now, gofuzzgen generate all functions that can fuzz test whether fuzz test exist or not.

License

The source code is licensed MIT. The website content is licensed CC BY 4.0,see LICENSE.

Documentation

Index

Constants

This section is empty.

Variables

View Source
var Generator = &codegen.Generator{
	Name: "gofuzzgen",
	Doc:  "gofuzzgen generate a go fuzzing test template",
	Run:  run,
	Requires: []*analysis.Analyzer{
		showfuzz.Analyzer,
	},
}

Functions

This section is empty.

Types

type InputData

type InputData struct {
	PkgName   string
	Fuzzables []showfuzz.Event
}

Directories

Path Synopsis
cmd

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL