task

package
v1.6.1 Latest Latest
Warning

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

Go to latest
Published: Dec 19, 2022 License: Apache-2.0 Imports: 16 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func PrepareAndRunTask

func PrepareAndRunTask(config *TaskPoolConfig, logger *logrus.Logger, connPool *connector.ConnectorPool,
	conn *connector.Connector, taskPoolResult *TaskPoolResult, taskId int)

PrepareAndRunTask:

  1. create and save task config
  2. run task

Types

type BugReport

type BugReport struct {
	ReportTime     string            `json:"reportTime"`
	BugId          int               `json:"bugId"`
	SqlId          int               `json:"sqlId"`
	MutationName   string            `json:"mutationName"`
	IsUpper        bool              `json:"isUpper"` // true: theoretically, OriginResult < NewResult
	OriginalSql    string            `json:"originalSql"`
	OriginalResult *connector.Result `json:"-"`
	MutatedSql     string            `json:"mutatedSql"`
	MutatedResult  *connector.Result `json:"-"`
}

BugReport: output to TaskConfig.GetBugsPath() / BugId - SqlId - MutationName .log and TaskConfig.GetBugsPath() / BugId - SqlId - MutationName .json

func NewBugReport added in v1.2.0

func NewBugReport(bugJsonPath string) (*BugReport, error)

func (*BugReport) SaveBugReport

func (bugReport *BugReport) SaveBugReport(taskBugsPath string) error

BugReport.SaveBugReport: output to TaskConfig.GetTaskBugsPath() / BugId - SqlId - MutationName .log and TaskConfig.GetTaskBugsPath() / BugId - SqlId - MutationName .json.

Note that create if not exists TaskConfig.GetTaskBugsPath()

func (*BugReport) ToString

func (bugReport *BugReport) ToString() string

type TaskConfig

type TaskConfig struct {
	OutputPath string `json:"outputPath"` // default: ./output
	DBMS       string `json:"dbms"`       // default: mysql
	TaskId     int    `json:"taskId"`     // >= 0
	Host       string `json:"host"`
	Port       int    `json:"port"`
	Username   string `json:"username"`
	Password   string `json:"password"`
	DbName     string `json:"dbname"`
	Seed       int64  `json:"seed"`      // <= 0: current time
	DDLPath    string `json:"ddlPath"`   // ddl.sql, can not have ';' in comment
	DMLPath    string `json:"dmlPath"`   // dml.sql, can not hava ';' in comment
	RdGenPath  string `json:"rdGenPath"` // use go-randgen -Z ZZPath -Y YYPath -Q QueriesNum -B --seed Seed if RdGenPath != ""
	ZZPath     string `json:"zzPath"`
	YYPath     string `json:"yyPath"`
	QueriesNum int    `json:"queriesNum"`
	NeedDML    bool   `json:"needDML"` // output dml.sql or not
}

func InitTaskConfig

func InitTaskConfig(config *TaskConfig) (*TaskConfig, error)

InitTaskConfig: check input, assign default value, convert path to abs, create config

func NewTaskConfig

func NewTaskConfig(configJsonPath string) (*TaskConfig, error)

func (*TaskConfig) GetTaskBugsPath

func (taskConfig *TaskConfig) GetTaskBugsPath() string

TaskConfig.GetTaskBugsPath:

path.Join(taskConfig.OutputPath, taskConfig.DBMS, "task-"+strconv.Itoa(taskConfig.TaskId), "bugs")

func (*TaskConfig) GetTaskPath

func (taskConfig *TaskConfig) GetTaskPath() string

TaskConfig.GetTaskPath:

path.Join(taskConfig.OutputPath, taskConfig.DBMS, "task-"+strconv.Itoa(taskConfig.TaskId))

func (*TaskConfig) SaveConfig

func (taskConfig *TaskConfig) SaveConfig(taskInputPath string) error

TaskConfig.SaveConfig: save config into:

path.Join(taskInputPath, "task-"+strconv.Itoa(taskConfig.TaskId)+"-config.json")

You should init taskInputPath yourself.

type TaskPoolConfig

type TaskPoolConfig struct {
	OutputPath  string `json:"outputPath"` // default: ./output
	DBMS        string `json:"dbms"`       // default: mysql
	Host        string `json:"host"`
	Port        int    `json:"port"`
	Username    string `json:"username"`
	Password    string `json:"password"`
	DbPrefix    string `json:"dbPrefix"`
	Seed        int64  `json:"seed"` // <= 0: current time
	RandGenPath string `json:"randGenPath"`
	ZZPath      string `json:"zzPath"`
	YYPath      string `json:"yyPath"`
	QueriesNum  int    `json:"queriesNum"`
	ThreadNum   int    `json:"threadNum"`
	MaxTasks    int    `json:"maxTasks"` // <= 0: no limit
	MaxTimeS    int    `json:"maxTimeS"` // <= 0: no limit
}

func InitTaskPoolConfig

func InitTaskPoolConfig(config *TaskPoolConfig) (*TaskPoolConfig, error)

InitTaskPoolConfig: check input, assign default value, convert path to abs, create config

func NewTaskPoolConfig

func NewTaskPoolConfig(configJsonPath string) (*TaskPoolConfig, error)

func (*TaskPoolConfig) GetTaskPoolPath

func (taskPoolConfig *TaskPoolConfig) GetTaskPoolPath() string

TaskPoolConfig.GetTaskPoolPath:

path.Join(taskPoolConfig.OutputPath, taskPoolConfig.DBMS)

type TaskPoolResult

type TaskPoolResult struct {
	StartTime       string `json:"startTime"`
	TotalTaskNum    int    `json:"totalTaskNum"`
	FinishedTaskNum int    `json:"finishedTaskNum"`
	ErrorTaskNum    int    `json:"errorTaskNum"`
	ErrorTaskIds    []int  `json:"errorTaskIds"`
	BugsNum         int    `json:"bugsNum"`
	BugTaskIds      []int  `json:"bugTaskIds"`
	EndTime         string `json:"endTime"`
	// contains filtered or unexported fields
}

func RunTaskPool

func RunTaskPool(config *TaskPoolConfig) (*TaskPoolResult, error)

RunTaskPool:

  1. init 1.1 init TaskPoolConfig.GetTaskPoolPath() 1.2 create logger, write to TaskPoolConfig.GetTaskPoolPath()/taskpool.log and os.Stdout 1.3 create thread pool with size ThreadNum, fill with *connector.Connector, the database name of each connector is config.DbPrefix + thread id
  2. run, use thread pool(with size ThreadNum) to continuously execute tasks.

Each thread can only perform one task at the same time, see PrepareAndRunTask(). Save taskpool result.

func (*TaskPoolResult) SaveTaskPoolResult

func (taskPoolResult *TaskPoolResult) SaveTaskPoolResult(taskPoolPath string) error

TaskPoolResult.SaveTaskPoolResult: output to taskPoolPath/result.json

type TaskResult

type TaskResult struct {
	StartTime            string `json:"startTime"`
	DDLSqlsNum           int    `json:"ddlSqlsNum"`
	DMLSqlsNum           int    `json:"dmlSqlsNum"`
	EndInitTime          string `json:"endInitTime"`
	Stage1ErrNum         int    `json:"stage1ErrNum"`
	Stage1ExecErrNum     int    `json:"stage1ExecErrNum"`
	Stage2ErrNum         int    `json:"stage2ErrNum"`
	Stage2UnitNum        int    `json:"stage2UnitNum"`
	Stage2UnitErrNum     int    `json:"stage2UnitErrNum"`
	Stage2UnitExecErrNum int    `json:"stage2UnitExecErrNum"`
	ImpoBugsNum          int    `json:"impoBugsNum"`
	SaveBugErrNum        int    `json:"saveBugErrNum"`
	EndTime              string `json:"endTime"`
}

func RunTask

func RunTask(config *TaskConfig, publicConn *connector.Connector, publicLogger *logrus.Logger) (*TaskResult, error)

Run: Basic task for finding logical bugs:

  1. init: 1.1 init TaskConfig.GetTaskPath() 1.2 create logger 1.3 create connector(if publicConn == nil, otherwise just use public Conn) 1.4 go-randgen if TaskConfig.RdGenPath != "" 1.5 read ddl, init database, execute ddl 1.6 read dml

2. run: for each dml sql, do:

2.1 stage1.InitAndExec
2.2 stage2.MutateAllAndExec
2.3 use oracle.Check to detect logical bugs
2.4 save task result

func (*TaskResult) SaveTaskResult

func (taskResult *TaskResult) SaveTaskResult(taskPath string) error

TaskResult.SaveTaskResult: output to taskPath/result.json

Jump to

Keyboard shortcuts

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