Skip to content

Commit

Permalink
let unit test work after importing runc-dmz
Browse files Browse the repository at this point in the history
Signed-off-by: lifubang <[email protected]>
  • Loading branch information
lifubang committed Aug 15, 2023
1 parent 7adf5a5 commit 7c7e825
Show file tree
Hide file tree
Showing 2 changed files with 45 additions and 0 deletions.
19 changes: 19 additions & 0 deletions libcontainer/integration/utils_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,16 @@ func init() {
// Figure out path to get-images.sh. Note it won't work
// in case the compiled test binary is moved elsewhere.
_, ex, _, _ := runtime.Caller(0)
// make and copy runc-dmg
rootDir, err := filepath.Abs(filepath.Join(filepath.Dir(ex), "..", ".."))
if err != nil {
panic(err)
}
nowPath := getExeDir()
dmzMake, err := exec.Command("gcc", "-o", filepath.Join(nowPath, "integration.test-dmz"), "-static", filepath.Join(rootDir, "contrib/cmd/runc-dmz/runc-dmz.c")).CombinedOutput()
if err != nil {
panic(fmt.Errorf("make runc-dmz error %w (output: %s)", err, dmzMake))
}
getImages, err := filepath.Abs(filepath.Join(filepath.Dir(ex), "..", "..", "tests", "integration", "get-images.sh"))
if err != nil {
panic(err)
Expand All @@ -48,6 +58,15 @@ func init() {
}
}

func getExeDir() string {
exePath, err := os.Executable()
if err != nil {
panic(err)
}
res, _ := filepath.EvalSymlinks(filepath.Dir(exePath))
return res
}

func ptrInt(v int) *int {
return &v
}
Expand Down
26 changes: 26 additions & 0 deletions libcontainer/nsenter/nsenter_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,8 @@ import (
"io"
"os"
"os/exec"
"path/filepath"
"runtime"
"strings"
"testing"

Expand All @@ -16,6 +18,29 @@ import (
"golang.org/x/sys/unix"
)

func init() {
_, ex, _, _ := runtime.Caller(0)
// make and copy runc-dmg
rootDir, err := filepath.Abs(filepath.Join(filepath.Dir(ex), "..", ".."))
if err != nil {
panic(err)
}
nowPath := getExeDir()
dmzMake, err := exec.Command("gcc", "-o", filepath.Join(nowPath, "nsenter.test-dmz"), "-static", filepath.Join(rootDir, "contrib/cmd/runc-dmz/runc-dmz.c")).CombinedOutput()
if err != nil {
panic(fmt.Errorf("make runc-dmz error %w (output: %s)", err, dmzMake))
}
}

func getExeDir() string {
exePath, err := os.Executable()
if err != nil {
panic(err)
}
res, _ := filepath.EvalSymlinks(filepath.Dir(exePath))
return res
}

func TestNsenterValidPaths(t *testing.T) {
args := []string{"nsenter-exec"}
parent, child := newPipe(t)
Expand All @@ -24,6 +49,7 @@ func TestNsenterValidPaths(t *testing.T) {
// join pid ns of the current process
fmt.Sprintf("pid:/proc/%d/ns/pid", os.Getpid()),
}
fmt.Printf("=========os.Args[0] %s\n", os.Args[0])
cmd := &exec.Cmd{
Path: os.Args[0],
Args: args,
Expand Down

0 comments on commit 7c7e825

Please sign in to comment.