forked from kata-containers/agent
-
Notifications
You must be signed in to change notification settings - Fork 0
/
pause_test.go
42 lines (32 loc) · 860 Bytes
/
pause_test.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
//
// Copyright (c) 2017 HyperHQ Inc.
//
// SPDX-License-Identifier: Apache-2.0
//
package main
import (
"fmt"
"os"
"os/exec"
"syscall"
"testing"
"github.com/stretchr/testify/assert"
)
func TestForkPauseBin(t *testing.T) {
skipUnlessRoot(t)
cmd := &exec.Cmd{
Path: selfBinPath,
Env: []string{fmt.Sprintf("%s=%s", pauseBinKey, pauseBinValue)},
}
cmd.SysProcAttr = &syscall.SysProcAttr{
Cloneflags: syscall.CLONE_NEWPID,
}
err := cmd.Start()
assert.Nil(t, err, "Failed to fork pause binary: %s", err)
_, err = os.Stat(fmt.Sprintf("/proc/%d/ns/pid", cmd.Process.Pid))
assert.Nil(t, err, "Failed to stat pidns of pid %d: %s", cmd.Process.Pid, err)
err = cmd.Process.Kill()
assert.Nil(t, err, "Failed to kill pause binary: %s", err)
_, err = cmd.Process.Wait()
assert.Nil(t, err, "Failed to wait killed pause binary: %s", err)
}