@@ -3,26 +3,29 @@ package main
3
3
import (
4
4
"bytes"
5
5
"encoding/json"
6
+ "fmt"
6
7
"io/ioutil"
7
8
"os"
8
9
"os/exec"
9
10
"path/filepath"
10
11
"runtime"
11
12
"testing"
13
+ "time"
12
14
13
15
"github.com/docker/docker/integration-cli/checker"
14
16
"github.com/go-check/check"
15
17
"github.com/opencontainers/runtime-spec/specs-go"
16
18
)
17
19
18
20
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*"
26
29
)
27
30
28
31
var (
@@ -63,6 +66,7 @@ type RunVSuite struct {
63
66
initrdPath string
64
67
bundlePath string
65
68
configPath string
69
+ logPath string
66
70
}
67
71
68
72
var _ = check .Suite (& RunVSuite {})
@@ -110,12 +114,23 @@ func (s *RunVSuite) SetUpSuite(c *check.C) {
110
114
111
115
func (s * RunVSuite ) TearDownSuite (c * check.C ) {}
112
116
113
- func (s * RunVSuite ) SetUpTest (c * check.C ) {}
117
+ func (s * RunVSuite ) SetUpTest (c * check.C ) {
118
+ s .logPath = c .MkDir ()
119
+ }
114
120
115
121
func (s * RunVSuite ) TearDownTest (c * check.C ) {
116
122
// FIXME: Use runv kill/delete to do reliable garbage collection
117
123
// 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
+ }
121
136
}
0 commit comments