@@ -59,9 +59,10 @@ const (
5959)
6060
6161var (
62- skipTuntap bool
63- testDataPath = "./testdata"
64- testDataBin = filepath .Join (testDataPath , "bin" )
62+ skipTuntap bool
63+ testDataPath = "./testdata"
64+ testDataLogPath = filepath .Join (testDataPath , "logs" )
65+ testDataBin = filepath .Join (testDataPath , "bin" )
6566
6667 testRootfs = filepath .Join (testDataPath , "root-drive.img" )
6768)
@@ -72,6 +73,10 @@ func init() {
7273 if val := os .Getenv (testDataPathEnv ); val != "" {
7374 testDataPath = val
7475 }
76+
77+ if err := os .MkdirAll (testDataLogPath , 0777 ); err != nil {
78+ panic (err )
79+ }
7580}
7681
7782// Ensure that we can create a new machine
@@ -106,9 +111,12 @@ func TestJailerMicroVMExecution(t *testing.T) {
106111 }
107112 fctesting .RequiresRoot (t )
108113
114+ logPath := filepath .Join (testDataLogPath , "TestJailerMicroVMExecution" )
115+ err := os .MkdirAll (logPath , 0777 )
116+ require .NoError (t , err , "unable to create %s path" , logPath )
117+
109118 jailerUID := 123
110119 jailerGID := 100
111- var err error
112120 if v := os .Getenv (sudoUID ); v != "" {
113121 if jailerUID , err = strconv .Atoi (v ); err != nil {
114122 t .Fatalf ("Failed to parse %q" , sudoUID )
@@ -156,13 +164,21 @@ func TestJailerMicroVMExecution(t *testing.T) {
156164 require .NoError (t , err , "failed to open fifo writer file" )
157165 defer func () {
158166 fw .Close ()
167+ exec .Command ("cp" , capturedLog , logPath ).Run ()
159168 os .Remove (capturedLog )
160169 os .Remove (socketPath )
161170 os .Remove (logFifo )
162171 os .Remove (metricsFifo )
163172 os .RemoveAll (tmpDir )
164173 }()
165174
175+ logFd , err := os .OpenFile (
176+ filepath .Join (logPath , "TestJailerMicroVMExecution.log" ),
177+ os .O_CREATE | os .O_RDWR ,
178+ 0666 )
179+ require .NoError (t , err , "failed to create log file" )
180+ defer logFd .Close ()
181+
166182 cfg := Config {
167183 Debug : true ,
168184 SocketPath : socketPath ,
@@ -193,6 +209,8 @@ func TestJailerMicroVMExecution(t *testing.T) {
193209 ChrootBaseDir : jailerTestPath ,
194210 ExecFile : getFirecrackerBinaryPath (),
195211 ChrootStrategy : NewNaiveChrootStrategy (jailerFullRootPath , vmlinuxPath ),
212+ Stdout : logFd ,
213+ Stderr : logFd ,
196214 },
197215 FifoLogWriter : fw ,
198216 }
0 commit comments