congo

package module
v0.0.0-...-5bd2ef4 Latest Latest
Warning

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

Go to latest
Published: Mar 7, 2019 License: MIT Imports: 26 Imported by: 0

README

Congo

screenshot

Congo is a test generation framework for Go. It adopts concolic testing to generate test cases that will achieve better test coverage than randomly generated ones.

Congo is still under development and not stable or sufficient for practical use now.

Dependencies

Congo requires Z3 to solve symbolic constraints. The latest version is recommended.

Congo assumes that z3.h exists in the default include path and libz3 exists in the default library path. If you placed Z3 headers or libraries in a custom directory, you may have to set CGO_CFLAGS or CGO_LDFLAGS to specify the correct path to them. Please refer to the cgo documentation for more information.

Install

$ go get -u github.com/ajalab/congo/...

Usage

$ congo -f <function name> [-o <output file name>] <package>

You can specify the package by package path (e.g., github.com/ajalab/congo) or file name (e.g., foo.go), but the second pattern is available when GO111MODULE=on.

If -o option is not specified, Congo will output the generated test code to stdout. However, you may not use redirection to generate test files like congo -f Foo foo.go > foo_test.go, because it first creates empty foo_test.go, which will prevent the go compiler from building your package.

Currently Congo generates a separate package (*_test) for a target package. This means you cannot specify unexported functions (starting with a lower letter).

Features

The following types and operations are currently supported.

  • booleans and logical operators
  • integers (int, uint, int8, ...) and basic arithmetic operators. Congo treats an integer as a bit-vector.
  • strings (only concatenation, checking equality, and computing length)
  • pointers of above types. Congo supports pointer dereference and store. Congo detects panic caused by nil pointer dereference.
  • function calls within the target package.

Unsupported Features

Though Congo is being enthusiastically developed, lots of features that you will need are not supported yet.

  • struct
  • floating points
  • arrays and slices
  • maps
  • channels
  • goroutines
  • ...

Internals

See INTERNALS.md for details on how Congo works.

License

Congo is licensed under the MIT License.

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Config

type Config struct {
	// FuncNames is a list of functions that we generate tests for.
	FuncNames []string
	// Runner is the path to the Go file that calls the target function.
	// Automatically generated if empty string is specified.
	Runner string
	ExecuteOption
}

Config specifies the (optional) parameters for concolic execution. Options are ignored when a field has the zero value.

type Congo

type Congo struct {
	// contains filtered or unexported fields
}

Congo is a type that contains the program and dict of targets (keys are names of target function).

func Load

func Load(config *Config, targetPackagePath string) (*Congo, error)

Load loads the target program. targetPackagePath is either - a file path (e.g., foo/bar.go) to the target package - an import path (e.g, github.com/ajalab/congo).

func (*Congo) DumpRunnerAST

func (c *Congo) DumpRunnerAST(dest io.Writer) error

DumpRunnerAST dumps the runner AST file into dest.

func (*Congo) DumpSSA

func (c *Congo) DumpSSA(dest io.Writer) error

DumpSSA dumps the SSA-format code into dest.

func (*Congo) Execute

func (c *Congo) Execute(funcName string) (*ExecuteResult, error)

Execute executes concolic execution. The iteration time is bounded by maxExec and stopped when minCoverage is accomplished.

func (*Congo) Funcs

func (c *Congo) Funcs() []string

Funcs returns the list of function names that Congo loaded as execution target.

func (*Congo) Run

func (c *Congo) Run(funcName string, values []interface{}) (*interp.CongoInterpResult, error)

Run runs the program by the interpreter provided by interp module.

func (*Congo) Target

func (c *Congo) Target(name string) *Target

Target returns the target which has the given name.

type ExecuteOption

type ExecuteOption struct {
	MaxExec     uint    `key:"maxexec"`
	MinCoverage float64 `key:"cover"`
}

ExecuteOption is a type that contains options to perform concolic execution on a target function.

func (*ExecuteOption) Fill

func (eo *ExecuteOption) Fill(src *ExecuteOption, overwrite bool) *ExecuteOption

Fill fills the fields in ExecuteOption with those in src.

type ExecuteResult

type ExecuteResult struct {
	Coverage    float64 // achieved coverage.
	SymbolTypes []types.Type
	RunResults  []*RunResult
	// contains filtered or unexported fields
}

ExecuteResult is a type that contains the result of Execute. TODO(ajalab): ReturnValues has type []interp.value so it is meaningless to make this property public. We use reflection to extract values from interp.value for now.

func (*ExecuteResult) GenerateTest

func (r *ExecuteResult) GenerateTest() (*ast.File, error)

GenerateTest generates test module for the program.

type Program

type Program struct {
	// contains filtered or unexported fields
}

Program is a type that contains information of the target program.

type RunResult

type RunResult struct {
	// contains filtered or unexported fields
}

RunResult is a type that contains the result of Run.

type Target

type Target struct {
	*ExecuteOption
	// contains filtered or unexported fields
}

Target is a type that contains the single target of concolic testing (function and set of symbols).

Directories

Path Synopsis
cmd
Package ssa/interp defines an interpreter for the SSA representation of Go programs.
Package ssa/interp defines an interpreter for the SSA representation of Go programs.

Jump to

Keyboard shortcuts

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