tetragon

Форк
0
58 строк · 1.2 Кб
1
// SPDX-License-Identifier: Apache-2.0
2
// Copyright Authors of Tetragon
3

4
package testutils
5

6
import (
7
	"context"
8
	"fmt"
9
	"os/exec"
10
	"strings"
11
	"testing"
12
)
13

14
type LseekPipeCmd struct {
15
	Cmd   *exec.Cmd
16
	Pipes *CmdBufferedPipes
17
}
18

19
// starts a new lseek-pipe command
20
//
21
//revive:disable:context-as-argument
22
func NewLseekPipe(t *testing.T, ctx context.Context) *LseekPipeCmd {
23
	bin := RepoRootPath("contrib/tester-progs/lseek-pipe")
24
	cmd := exec.CommandContext(ctx, bin)
25
	pipes, err := NewCmdBufferedPipes(cmd)
26
	if err != nil {
27
		t.Fatal(err)
28
	}
29
	if err := cmd.Start(); err != nil {
30
		pipes.Close()
31
		t.Fatal(err)
32
	}
33

34
	return &LseekPipeCmd{
35
		Cmd:   cmd,
36
		Pipes: pipes,
37
	}
38
}
39

40
//revive:enable:context-as-argument
41

42
func (lp *LseekPipeCmd) Pid() int {
43
	return lp.Cmd.Process.Pid
44
}
45

46
func (lp *LseekPipeCmd) Lseek(fd int, offset int64, whence int) string {
47
	lp.Pipes.P.Stdin.Write([]byte(fmt.Sprintf("%d %d %d\n", fd, offset, whence)))
48
	// NB: read the result from the lseek-pipe program. Doing so means that
49
	// whenever we return, we know that the lseek syscall has been
50
	// executed.
51
	line, _ := lp.Pipes.StdoutRd.ReadString('\n')
52
	return strings.TrimSuffix(line, "\n")
53
}
54

55
func (lp *LseekPipeCmd) Close() error {
56
	lp.Pipes.Close()
57
	return lp.Cmd.Wait()
58
}
59

Использование cookies

Мы используем файлы cookie в соответствии с Политикой конфиденциальности и Политикой использования cookies.

Нажимая кнопку «Принимаю», Вы даете АО «СберТех» согласие на обработку Ваших персональных данных в целях совершенствования нашего веб-сайта и Сервиса GitVerse, а также повышения удобства их использования.

Запретить использование cookies Вы можете самостоятельно в настройках Вашего браузера.