regression

package module
v0.0.0-...-bacbc25 Latest Latest
Warning

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

Go to latest
Published: Apr 3, 2019 License: Apache-2.0 Imports: 25 Imported by: 2

README

regression-core

regression-core* holds the common functionality used by regression testers.

Functionality provided:

  • Binary download from github releases
  • Binary building from local or remote locations, can specify tag/branch or pull request
  • Command execution and resource retrieval (max memory, wall/system/user time)
  • git server execution
  • Generic server execution
  • Repository cache management

The library should be imported using gopkg.in:

import (
  "gopkg.in/src-d/regression-core.v0
)

...

config := regression.NewConfig()
config.RepositoriesCache = "/tmp/repos"
git := regression.NewGitServer(config)
git.Start()

License

Licensed under the terms of the Apache License Version 2.0. See the LICENSE file for the full license text.

Documentation

Index

Constants

View Source
const (
	Memory = "memory"
	Time   = "time"
)

Variables

View Source
var (
	// ErrReferenceNotFound means that the provided reference is not found
	ErrReferenceNotFound = errors.NewKind("Reference %s not found")
	// ErrInvalidVersion means that the provided version is malformed
	ErrInvalidVersion = errors.NewKind("Version %s is invalid")
)
View Source
var (
	ErrVersionNotFound = errors.NewKind("Version '%s' not found")
	ErrAssetNotFound   = errors.NewKind(
		"Asset named '%s' not found in release '%s'")
)
View Source
var CompareFormat = "%s: %v -> %v (%v), %v\n"
View Source
var ErrBinaryNotFound = errors.NewKind("binary not found in release tarball")

ErrBinaryNotFound is returned when the executable is not found in the release tarball.

View Source
var ErrExtraFile = errors.NewKind("cannot save extra file %s")

ErrExtraFile is returned when there is a problem saving an extra file.

View Source
var ErrNotRun = fmt.Errorf("command still was not executed")

ErrNotRun means that the command was not started

View Source
var ErrRusageNotAvailable = fmt.Errorf("rusage information not available")

ErrRusageNotAvailable means that resource usage could not be collected

View Source
var ErrTarball = errors.NewKind("cannot unpack tarball %s")

ErrTarball is returned when there is a problem with a tarball.

Functions

func CopyFile

func CopyFile(source, destination string, mode os.FileMode) error

CopyFile makes a file copy with the specified permission.

func CreateTempDir

func CreateTempDir() (string, error)

CreateTempDir creates a new temporary directory in the default temp dir.

func Download

func Download(url, path string) error

func GetExtras

func GetExtras(tarball, path string, extras []string, depth int) error

GetExtras extracts the files from the tarball contained in the extras list to the provided path. It can skip directories with the parameter depth.

func IOToFile

func IOToFile(r io.Reader, path string) error

func IsRepo

func IsRepo(version string) bool

IsRepo returns true if the version provided matches the repository format, for example: remote:master.

func Percent

func Percent(a, b int64) float64

Percent returns the percentage difference between to int64.

func RecursiveCopy

func RecursiveCopy(src, dst string) error

RecursiveCopy copies a directory to a destination path. It creates all needed directories if destination path does not exist.

func ToMiB

func ToMiB(i int64) float64

Types

type Binary

type Binary struct {
	Version string
	Path    string
	// contains filtered or unexported fields
}

Binary struct contains information and functionality to prepare and use a binary version.

func NewBinary

func NewBinary(
	config Config,
	tool Tool,
	version string,
	releases *Releases,
) *Binary

NewBinary creates a new Binary structure.

func (*Binary) Download

func (b *Binary) Download() error

Download prepares a binary version if it's still not in the binaries directory.

func (*Binary) ExtraFile

func (b *Binary) ExtraFile(name string) string

ExtraFile returns the path from a file in the cache directory.

func (*Binary) IsRelease

func (b *Binary) IsRelease() bool

IsRelease checks if the version matches the format of a release, for example v0.12.1.

type Build

type Build struct {
	// Version is the reference that will be built
	Version string

	// GoPath is the directory where the temporary path where the tool is built
	GoPath string
	// contains filtered or unexported fields
}

Build structure holds information and functionality to generate binaries from source code.

func NewBuild

func NewBuild(
	config Config,
	tool Tool,
	version string,
) (*Build, error)

NewBuild creates a new Build structure

func (*Build) Build

func (b *Build) Build() (string, string, error)

Build downloads and builds a binary from source code.

type BuildStep

type BuildStep struct {
	// Dir is the path where this command is executed.
	Dir string
	// Command is the executable to run.
	Command string
	// Args caintains the list of options to use with Command.
	Args []string
}

BuildStep describes a command used to build a tool.

type Comparison

type Comparison struct {
	Memory float64
	Wtime  float64
	Stime  float64
	Utime  float64
}

Comparison has the percentages of change between two runs.

type Config

type Config struct {
	// Versions has the list of releases to test
	Versions []string
	// OS holds the operating system
	OS string
	// BinaryCache is the path to the binaries cache
	BinaryCache string `env:"REG_BINARIES" default:"binaries" long:"binaries" description:"Directory to store binaries"`
	// RepositoriesCache is the path to the downloaded repositories
	RepositoriesCache string `env:"REG_REPOS" default:"repos" long:"repos" description:"Directory to store repositories"`
	// GitURL is the git repository url to download the tool
	GitURL string `env:"REG_GITURL" default:"" long:"url" description:"URL to the tool repo"`
	// GitServerPort is the port where the local git server will listen
	GitServerPort int `env:"REG_GITPORT" default:"9418" long:"gitport" description:"Port for local git server"`
	// RepositoriesFile
	RepositoriesFile string `env:"REG_REPOS_FILE" default:"" long:"repos-file" description:"YAML file with the list of repos"`
	// Complexity has the max number of complexity of repos to test
	Complexity int `env:"REG_COMPLEXITY" default:"1" long:"complexity" short:"c" description:"Complexity of the repositories to test"`
	// Repeat is the number of times each test will be run
	Repeat int `env:"REG_REPEAT" default:"3" long:"repeat" short:"n" description:"Number of times a test is run"`
	// ShowRepos when --show-repos is specified
	ShowRepos bool `long:"show-repos" description:"List available repositories to test"`
	// GitHubToken specifies the token to use to use GitHub API
	GitHubToken string `env:"REG_TOKEN" long:"token" short:"t" description:"Token used to connect to the API"`
}

Config holds the general configuration for tests

func NewConfig

func NewConfig() Config

NewConfig returns an empty config with initialized OS.

func (*Config) BinaryPath

func (c *Config) BinaryPath(version, name string) string

VersionPath returns the binary path an specific version.

func (*Config) VersionPath

func (c *Config) VersionPath(version string) string

VersionPath returns the path of the binary cache for an specific version.

type Executor

type Executor struct {
	Executed bool
	// contains filtered or unexported fields
}

Executor structure holds information and functionality to execute commands and get resource usage.

func NewExecutor

func NewExecutor(command string, args ...string) (*Executor, error)

NewExecutor creates a new Executor struct.

func (*Executor) Out

func (e *Executor) Out() (string, error)

Out retrieves stdout+stderr from the executed command.

func (*Executor) Run

func (e *Executor) Run() error

Run executes the command and collects resource usage.

func (*Executor) Rusage

func (e *Executor) Rusage() (*syscall.Rusage, error)

Rusage returns resource usage data.

func (*Executor) Wall

func (e *Executor) Wall() (time.Duration, error)

Wall returns time consumed by the execution.

type GitServer

type GitServer struct {
	*Server
	// contains filtered or unexported fields
}

func NewGitServer

func NewGitServer(config Config) *GitServer

func (*GitServer) Start

func (s *GitServer) Start() error

func (*GitServer) Url

func (s *GitServer) Url(name string) string

type Releases

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

func NewReleases

func NewReleases(owner, repo, token string) *Releases

func (*Releases) Get

func (r *Releases) Get(version, asset, path string) (string, error)

func (*Releases) Latest

func (r *Releases) Latest() (string, error)

Latest return the last version name from github releases

type RepoDescription

type RepoDescription struct {
	Name        string `json:"name"`
	URL         string `json:"url"`
	Description string `json:"description"`
	Complexity  int    `json:"complexity"`
}

RepoDescription holds the information about a single repository

type Repositories

type Repositories struct {
	Repos []RepoDescription
	// contains filtered or unexported fields
}

Repositories struct has the information about a set of repositories and functionality to download them.

func NewRepositories

func NewRepositories(config Config) (*Repositories, error)

NewRepositories creates a new Repositories set. If config.RepositoriesFile is set it will try to load it and use as a load it as the repositories list.

func (*Repositories) Download

func (r *Repositories) Download() error

Download clones all repositories in the list that have equal or lower complexity specified in config.

func (*Repositories) LinksDir

func (r *Repositories) LinksDir() (string, error)

LinksDir returns a path of a temporary directory with repos within the config complexity.

func (*Repositories) Names

func (r *Repositories) Names() []string

Names returns the names of repositories within concurrency level.

func (*Repositories) Path

func (r *Repositories) Path() string

Path returns the repository cache path.

func (*Repositories) ShowRepos

func (r *Repositories) ShowRepos()

ShowRepos prints information about all repositories.

type Result

type Result struct {
	Memory int64
	Wtime  time.Duration
	Stime  time.Duration
	Utime  time.Duration
}

Result struct holds resource usage from a run.

func Average

func Average(rs []*Result) *Result

Average gets the average consumption from a set of results. If the number of results is greater than 2 the first one is discarded as warmup run.

func (*Result) Compare

func (p *Result) Compare(q *Result) Comparison

Compare returns percentage difference between this and another run.

func (*Result) ComparePrint

func (p *Result) ComparePrint(q *Result, allowance float64) bool

ComparePrint does a result comparison, prints the result in human readable form and returns a bool if change is within allowance.

func (*Result) SaveAllCSV

func (p *Result) SaveAllCSV(prefix string) error

func (*Result) SaveCSV

func (p *Result) SaveCSV(series string, path string) error

func (*Result) WriteCSV

func (p *Result) WriteCSV(series string, w io.Writer) error

type Server

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

Server struct describes a daemon.

func NewServer

func NewServer() *Server

NewServer creates a new Server struct.

func (*Server) Alive

func (s *Server) Alive() bool

Alive checks if the process is still running.

func (*Server) Rusage

func (s *Server) Rusage() *syscall.Rusage

Rusage returns usage counters.

func (*Server) Start

func (s *Server) Start(name string, arg ...string) error

Start executes a command in background.

func (*Server) Stop

func (s *Server) Stop() error

Stop kill the daemon.

type Tool

type Tool struct {
	// Name has the tool name.
	Name string
	// BinaryName has the executable name of the tool.
	BinaryName string
	// GitURL holds the git URL to download the project.
	GitURL string
	// ProjectPath is the directory structure inside GOPATH/src where it should
	// be located for building.
	ProjectPath string
	// BuildSteps has the commands needed to build the tool.
	BuildSteps []BuildStep
	// ExtraFiles is a list of files used from the repository.
	ExtraFiles []string
}

Tool describes a project to build and test.

func (Tool) BinName

func (t Tool) BinName() string

func (Tool) DirName

func (t Tool) DirName(os string) string

Jump to

Keyboard shortcuts

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