@@ -3,26 +3,29 @@ package main
33import (
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
1820const (
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
2831var (
@@ -63,6 +66,7 @@ type RunVSuite struct {
6366 initrdPath string
6467 bundlePath string
6568 configPath string
69+ logPath string
6670}
6771
6872var _ = check .Suite (& RunVSuite {})
@@ -110,12 +114,23 @@ func (s *RunVSuite) SetUpSuite(c *check.C) {
110114
111115func (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
115121func (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 \n Log 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}
0 commit comments