Skip to content
This repository was archived by the owner on Feb 8, 2021. It is now read-only.

Commit 9b87bc8

Browse files
committed
print integration test log when case failed
Signed-off-by: Crazykev <crazykev@zju.edu.cn>
1 parent fd00efa commit 9b87bc8

File tree

9 files changed

+52
-17
lines changed

9 files changed

+52
-17
lines changed

Makefile.am

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -22,5 +22,4 @@ build-runv:
2222
go build -tags "static_build $(HYPER_BULD_TAGS)" -o runv .
2323
test-integration:
2424
cd integration-test/test_data && make
25-
cd integration-test && go test -check.v -test.timeout=120m ${TESTFLAGS} . ; ret=$$? ;\
26-
sync; sleep 20; sync; find /var/log/hyper/ -type f -exec echo -e '\n\nLog of ' {} ':' \; -exec cat {} \; ; exit $$ret
25+
cd integration-test && go test -check.v -test.timeout=120m ${TESTFLAGS} .

integration-test/exec_test.go

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@ import (
1515
)
1616

1717
func (s *RunVSuite) TestExecHelloWorld(c *check.C) {
18+
defer s.PrintLog(c)
1819
ctrName := "testExecHelloWorld"
1920
spec := defaultTestSpec
2021
spec.Process.Args = []string{"sleep", "10"}
@@ -43,6 +44,7 @@ func (s *RunVSuite) TestExecHelloWorld(c *check.C) {
4344
}
4445

4546
func (s *RunVSuite) TestExecWithTty(c *check.C) {
47+
defer s.PrintLog(c)
4648
ctrName := "TestExecWithTty"
4749
spec := defaultTestSpec
4850
spec.Process.Args = []string{"sleep", "10"}
@@ -91,6 +93,7 @@ func (s *RunVSuite) TestExecWithTty(c *check.C) {
9193
}
9294

9395
func (s *RunVSuite) TestExecWithProcessJson(c *check.C) {
96+
defer s.PrintLog(c)
9497
process := specs.Process{
9598
Terminal: false,
9699
User: specs.User{},

integration-test/init_test.go

Lines changed: 26 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -3,26 +3,29 @@ package main
33
import (
44
"bytes"
55
"encoding/json"
6+
"fmt"
67
"io/ioutil"
78
"os"
89
"os/exec"
910
"path/filepath"
1011
"runtime"
1112
"testing"
13+
"time"
1214

1315
"github.com/docker/docker/integration-cli/checker"
1416
"github.com/go-check/check"
1517
"github.com/opencontainers/runtime-spec/specs-go"
1618
)
1719

1820
const (
19-
testDataDir = "test_data"
20-
busyboxTarName = "busybox.tar"
21-
configFileName = "config.json"
22-
kernelName = "kernel"
23-
initrdName = "hyper-initrd.img"
24-
binaryName = "runv"
25-
rootfsName = "rootfs"
21+
testDataDir = "test_data"
22+
busyboxTarName = "busybox.tar"
23+
configFileName = "config.json"
24+
kernelName = "kernel"
25+
initrdName = "hyper-initrd.img"
26+
binaryName = "runv"
27+
rootfsName = "rootfs"
28+
logFileNamePattern = "runv*INFO*"
2629
)
2730

2831
var (
@@ -63,6 +66,7 @@ type RunVSuite struct {
6366
initrdPath string
6467
bundlePath string
6568
configPath string
69+
logPath string
6670
}
6771

6872
var _ = check.Suite(&RunVSuite{})
@@ -110,12 +114,23 @@ func (s *RunVSuite) SetUpSuite(c *check.C) {
110114

111115
func (s *RunVSuite) TearDownSuite(c *check.C) {}
112116

113-
func (s *RunVSuite) SetUpTest(c *check.C) {}
117+
func (s *RunVSuite) SetUpTest(c *check.C) {
118+
s.logPath = c.MkDir()
119+
}
114120

115121
func (s *RunVSuite) TearDownTest(c *check.C) {
116122
// FIXME: Use runv kill/delete to do reliable garbage collection
117123
// after kill/delete functions are stable
118-
exec.Command("pkill", "-9", "runv-namespaced").Run()
119-
exec.Command("pkill", "-9", "qemu").Run()
120-
exec.Command("pkill", "-9", "containerd-nslistener")
124+
killAllRunvComponent(9)
125+
}
126+
127+
func (s *RunVSuite) PrintLog(c *check.C) {
128+
if c.Failed() {
129+
// kill runv gently to enable garbage collection and flush log
130+
killAllRunvComponent(15)
131+
time.Sleep(3 * time.Second)
132+
out, err := exec.Command("sh", "-c", fmt.Sprintf("find %s -type f -name '%s' -exec echo -e '\n\nLog of ' {} ':' \\; -exec cat {} \\;", s.logPath, logFileNamePattern)).CombinedOutput()
133+
c.Assert(err, checker.IsNil)
134+
c.Logf("Test case %s failed, retrieve runv log from directory %s:\n%s", c.TestName(), s.logPath, out)
135+
}
121136
}

integration-test/kill_test.go

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@ import (
99
)
1010

1111
func (s *RunVSuite) TestKillKILL(c *check.C) {
12+
defer s.PrintLog(c)
1213
ctrName := "testKillKILL"
1314
spec := defaultTestSpec
1415
c.Assert(s.addSpec(&spec), checker.IsNil)

integration-test/list_test.go

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,7 @@ type containerState struct {
2121
}
2222

2323
func (s *RunVSuite) TestListSleep(c *check.C) {
24+
defer s.PrintLog(c)
2425
ctrName := "testListSleep"
2526
spec := defaultTestSpec
2627
spec.Process.Args = []string{"sleep", "10"}
@@ -48,6 +49,7 @@ func (s *RunVSuite) TestListSleep(c *check.C) {
4849
}
4950

5051
func (s *RunVSuite) TestListSleepJson(c *check.C) {
52+
defer s.PrintLog(c)
5153
ctrName := "testListSleepJson"
5254
spec := defaultTestSpec
5355
spec.Process.Args = []string{"sleep", "10"}

integration-test/spec_test.go

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@ import (
1313
)
1414

1515
func (s *RunVSuite) TestSpecDefault(c *check.C) {
16+
defer s.PrintLog(c)
1617
expectedSpec := defaultTestSpec
1718
expectedSpec.Process.Terminal = true
1819
expectedSpec.Process.Args = []string{"sh"}

integration-test/start_test.go

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@ import (
1616
)
1717

1818
func (s *RunVSuite) TestStartHelloworld(c *check.C) {
19+
defer s.PrintLog(c)
1920
spec := defaultTestSpec
2021
spec.Process.Args = []string{"echo", "hello"}
2122
c.Assert(s.addSpec(&spec), checker.IsNil)
@@ -26,6 +27,7 @@ func (s *RunVSuite) TestStartHelloworld(c *check.C) {
2627
}
2728

2829
func (s *RunVSuite) TestStartPid(c *check.C) {
30+
defer s.PrintLog(c)
2931
c.Skip("enable this after fixing")
3032
ctrName := "testStartPid"
3133
spec := defaultTestSpec
@@ -80,6 +82,7 @@ func (s *RunVSuite) TestStartPid(c *check.C) {
8082
}
8183

8284
func (s *RunVSuite) TestStartWithTty(c *check.C) {
85+
defer s.PrintLog(c)
8386
ctrName := "TestStartWithTty"
8487
spec := defaultTestSpec
8588
spec.Process.Terminal = true

integration-test/state_test.go

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,7 @@ func (s *RunVSuite) TestStateSleep(c *check.C) {
3131
//TODO: enable this after fixing!!!
3232
//c.Skip("enable this after fixing")
3333

34+
defer s.PrintLog(c)
3435
ctrName := "testStateSleep"
3536
spec := defaultTestSpec
3637
spec.Process.Args = []string{"sleep", "10"}

integration-test/utils.go

Lines changed: 14 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -41,12 +41,15 @@ func ProcessExitCode(err error) (exitCode int) {
4141

4242
func (s *RunVSuite) runvCommandWithError(args ...string) (string, int, error) {
4343
killer := time.AfterFunc(40*time.Second, func() {
44-
exec.Command("pkill", "-9", "runv").Run()
45-
exec.Command("pkill", "-9", "qemu").Run()
46-
exec.Command("pkill", "-9", "containerd-nslistener").Run()
44+
killAllRunvComponent(9)
4745
})
4846

49-
cmdArgs := []string{"--kernel", s.kernelPath, "--initrd", s.initrdPath, "--debug"}
47+
cmdArgs := []string{
48+
"--kernel", s.kernelPath,
49+
"--initrd", s.initrdPath,
50+
"--log_dir", s.logPath,
51+
"--debug",
52+
}
5053
cmdArgs = append(cmdArgs, args...)
5154
cmd := exec.Command(s.binaryPath, cmdArgs...)
5255
out, err := cmd.CombinedOutput()
@@ -79,3 +82,10 @@ func (s *RunVSuite) addSpec(spec *specs.Spec) error {
7982
}
8083
return nil
8184
}
85+
86+
func killAllRunvComponent(signal int) {
87+
sigFlag := fmt.Sprintf("-%d", signal)
88+
exec.Command("pkill", sigFlag, "runv").Run()
89+
exec.Command("pkill", sigFlag, "qemu").Run()
90+
exec.Command("pkill", sigFlag, "containerd-nslistener").Run()
91+
}

0 commit comments

Comments
 (0)