testutils

package
v1.1.0 Latest Latest
Warning

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

Go to latest
Published: Apr 29, 2024 License: Apache-2.0 Imports: 24 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

View Source
var (
	ParentStartsRe = regexp.MustCompile(`parent:\t\t\(pid:(\d+), tid:(\d+), ppid:(\d+)\)\tstarts`)
	Child1Re       = regexp.MustCompile(`Child 1:\t\(pid:(\d+), tid:(\d+), ppid:(\d+)\)\t`)
	Thread1Re      = regexp.MustCompile(`Thread 1:\t\(pid:(\d+), tid:(\d+), ppid:(\d+)\)\t`)
)

Functions

func CaptureLog

func CaptureLog(tb testing.TB, l *logrus.Logger)

CaptureLog redirects logrus output to testing.Log

func CopyFile added in v0.10.0

func CopyFile(toPath, fromPath string, perm os.FileMode) error

func DoneWithExportFile added in v0.8.4

func DoneWithExportFile(t testing.TB) error

DoneWithExportFile: marks the export file to be deleted It is the tester's responsibility to call this function

func GetExportFilename

func GetExportFilename(t testing.TB) (string, error)

GetExportFilename return export filename for test

func GetSpecFromTemplate

func GetSpecFromTemplate(
	tmplname string,
	data interface{},
) (string, error)

GetSpecFromTemplate creates a file bsed on the given template

func GetTgRuntimeConf added in v0.8.4

func GetTgRuntimeConf() (*confmap.TetragonConfValue, error)

func KeepExportFile

func KeepExportFile(t testing.TB) error

KeepExportFile: marks the export file to be kept

func MockPipedFile added in v0.9.0

func MockPipedFile(t *testing.T, filename string)

MockPipedFile mocks the file being piped into stdin, similarly as what you can do with `cat file | cmd`. It restores the original os.Stdin in t.Cleanup. It's using a goroutine to copy the file content to the writer of the pipe.

func ReadTgRuntimeConf added in v0.8.4

func ReadTgRuntimeConf(mapDir string) (*confmap.TetragonConfValue, error)

func RedirectStdoutExecuteCmd added in v0.9.0

func RedirectStdoutExecuteCmd(t *testing.T, cmd *cobra.Command) []byte

RedirectStdoutExecuteCmd redirects stdout, executes the command and returns the result of the command.

func RepoRootPath added in v0.9.0

func RepoRootPath(fname string) string

RepoRootPath retrieves the repository root path (useful to find scripts and other files)

Types

type CmdBufferedPipes

type CmdBufferedPipes struct {
	P                  *CmdPipes
	StdoutRd, StderrRd *bufio.Reader
}

CmdBufferedPipes wraps stdout and stderr in a bufio.Reader

func NewCmdBufferedPipes

func NewCmdBufferedPipes(cmd *exec.Cmd) (*CmdBufferedPipes, error)

func (*CmdBufferedPipes) Close

func (cbp *CmdBufferedPipes) Close()

func (*CmdBufferedPipes) ParseAndLogCmdOutput

func (cbp *CmdBufferedPipes) ParseAndLogCmdOutput(
	t *testing.T,
	parseOut LineParser,
	parseErr LineParser,
) *sync.WaitGroup

ParseAndLogCmdOutput will log command output using t.Log, and also call the lineparser functions for each line. This will happen in two goroutines. It returns a waitgroup for them finishing.

type CmdPipes

type CmdPipes struct {
	Stdout, Stderr io.ReadCloser
	Stdin          io.WriteCloser
}

CmdPipes maintains pipes for stdout, stderr, and stdin

func NewCmdPipes

func NewCmdPipes(cmd *exec.Cmd) (*CmdPipes, error)

NewCmdPipes returns a new CmdPipes

func (*CmdPipes) Close

func (cp *CmdPipes) Close()

Close closes all the pipes

type ExportFile

type ExportFile struct {
	*os.File
	// contains filtered or unexported fields
}

func CreateExportFile

func CreateExportFile(tb testing.TB) (*ExportFile, error)

CreateExportFile creates an export file for a test. It returns an ExportFile that has a .Close() method, that will be called by the observer loop. This function is responsible to delete the file. For a file to be deleted, the tester should call DoneWithExportFile() if the test was successful.

func (*ExportFile) Close

func (f *ExportFile) Close() error

Close() is called by the observer loop when it exits, and is responsible for deleting the file.

type LineParser

type LineParser = func(line string) error

type LogCapturer

type LogCapturer struct {
	TB  testing.TB
	Log *logrus.Logger
}

func (LogCapturer) Write

func (tl LogCapturer) Write(p []byte) (n int, err error)

type LseekPipeCmd added in v0.9.0

type LseekPipeCmd struct {
	Cmd   *exec.Cmd
	Pipes *CmdBufferedPipes
}

func NewLseekPipe added in v0.9.0

func NewLseekPipe(t *testing.T, ctx context.Context) *LseekPipeCmd

starts a new lseek-pipe command

func (*LseekPipeCmd) Close added in v0.9.0

func (lp *LseekPipeCmd) Close() error

func (*LseekPipeCmd) Lseek added in v0.9.0

func (lp *LseekPipeCmd) Lseek(fd int, offset int64, whence int) string

func (*LseekPipeCmd) Pid added in v0.9.0

func (lp *LseekPipeCmd) Pid() int

type ThreadTesterInfo added in v0.10.0

type ThreadTesterInfo struct {
	ParentPid, ParentTid                     uint32
	Child1Pid, Child1Tid, ParentChild1Pid    uint32
	Thread1Pid, Thread1Tid, ParentThread1Pid uint32
}

func (*ThreadTesterInfo) AssertPidsTids added in v0.10.0

func (tti *ThreadTesterInfo) AssertPidsTids(t *testing.T)

func (*ThreadTesterInfo) ParseLine added in v0.10.0

func (tti *ThreadTesterInfo) ParseLine(l string) error

Directories

Path Synopsis
Package perfring provides utilities to do tests using the perf ringbuffer directly
Package perfring provides utilities to do tests using the perf ringbuffer directly

Jump to

Keyboard shortcuts

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