@@ -100,14 +100,14 @@ var sdeCPUs = []string{
100
100
101
101
func targetArchMatchesRuntime (target string ) bool {
102
102
if (target == "" ) ||
103
- (target == "x86" && runtime .GOARCH == "amd64" ) ||
104
- (target == "arm" && (runtime .GOARCH == "arm" || runtime .GOARCH == "arm64" )) {
103
+ (target == "x86" && runtime .GOARCH == "amd64" ) ||
104
+ (target == "arm" && (runtime .GOARCH == "arm" || runtime .GOARCH == "arm64" )) {
105
105
return true
106
106
}
107
107
return false
108
108
}
109
109
110
- func valgrindOf (dbAttach bool , supps []string , path string , args ... string ) * exec.Cmd {
110
+ func valgrindOf (ctx context. Context , dbAttach bool , supps []string , path string , args ... string ) (context. Context , * exec.Cmd ) {
111
111
valgrindArgs := []string {"--error-exitcode=99" , "--track-origins=yes" , "--leak-check=full" , "--trace-children=yes" , "--quiet" }
112
112
for _ , supp := range supps {
113
113
valgrindArgs = append (valgrindArgs , "--suppressions=" + * valgrindSuppDir + "/" + supp )
@@ -118,26 +118,26 @@ func valgrindOf(dbAttach bool, supps []string, path string, args ...string) *exe
118
118
valgrindArgs = append (valgrindArgs , path )
119
119
valgrindArgs = append (valgrindArgs , args ... )
120
120
121
- return exec .Command ( "valgrind" , valgrindArgs ... )
121
+ return ctx , exec .CommandContext ( ctx , "valgrind" , valgrindArgs ... )
122
122
}
123
123
124
- func callgrindOf (path string , args ... string ) * exec.Cmd {
124
+ func callgrindOf (ctx context. Context , path string , args ... string ) (context. Context , * exec.Cmd ) {
125
125
valgrindArgs := []string {"-q" , "--tool=callgrind" , "--dump-instr=yes" , "--collect-jumps=yes" , "--callgrind-out-file=" + * buildDir + "/callgrind/callgrind.out.%p" }
126
126
valgrindArgs = append (valgrindArgs , path )
127
127
valgrindArgs = append (valgrindArgs , args ... )
128
128
129
- return exec .Command ( "valgrind" , valgrindArgs ... )
129
+ return ctx , exec .CommandContext ( ctx , "valgrind" , valgrindArgs ... )
130
130
}
131
131
132
- func gdbOf (path string , args ... string ) * exec.Cmd {
132
+ func gdbOf (ctx context. Context , path string , args ... string ) (context. Context , * exec.Cmd ) {
133
133
xtermArgs := []string {"-e" , "gdb" , "--args" }
134
134
xtermArgs = append (xtermArgs , path )
135
135
xtermArgs = append (xtermArgs , args ... )
136
136
137
- return exec .Command ( "xterm" , xtermArgs ... )
137
+ return ctx , exec .CommandContext ( ctx , "xterm" , xtermArgs ... )
138
138
}
139
139
140
- func sdeOf (cpu , path string , args ... string ) (* exec. Cmd , context.CancelFunc ) {
140
+ func sdeOf (ctx context. Context , cpu , path string , args ... string ) (context. Context , context.CancelFunc , * exec. Cmd ) {
141
141
sdeArgs := []string {"-" + cpu }
142
142
// The kernel's vdso code for gettimeofday sometimes uses the RDTSCP
143
143
// instruction. Although SDE has a -chip_check_vsyscall flag that
@@ -152,9 +152,9 @@ func sdeOf(cpu, path string, args ...string) (*exec.Cmd, context.CancelFunc) {
152
152
153
153
// TODO(CryptoAlg-2154):SDE+ASAN tests will hang without exiting if tests pass for an unknown reason.
154
154
// Current workaround is to manually cancel the run after 20 minutes and check the output.
155
- ctx , cancel := context .WithTimeout (context . Background () , 1200 * time .Second )
155
+ ctx , cancel := context .WithTimeout (ctx , 1200 * time .Second )
156
156
157
- return exec .CommandContext (ctx , * sdePath , sdeArgs ... ), cancel
157
+ return ctx , cancel , exec .CommandContext (ctx , * sdePath , sdeArgs ... )
158
158
}
159
159
160
160
var (
@@ -173,23 +173,20 @@ func runTestOnce(test test, mallocNumToFail int64) (passed bool, err error) {
173
173
}
174
174
var cmd * exec.Cmd
175
175
var cancel context.CancelFunc
176
- cancelled := false
176
+
177
+ ctx := context .Background ()
178
+
177
179
if * useValgrind {
178
- cmd = valgrindOf (false , test .ValgrindSupp , prog , args ... )
180
+ ctx , cmd = valgrindOf (ctx , false , test .ValgrindSupp , prog , args ... )
179
181
} else if * useCallgrind {
180
- cmd = callgrindOf (prog , args ... )
182
+ ctx , cmd = callgrindOf (ctx , prog , args ... )
181
183
} else if * useGDB {
182
- cmd = gdbOf (prog , args ... )
184
+ ctx , cmd = gdbOf (ctx , prog , args ... )
183
185
} else if * useSDE {
184
- cmd , cancel = sdeOf (test .cpu , prog , args ... )
186
+ ctx , cancel , cmd = sdeOf (ctx , test .cpu , prog , args ... )
185
187
defer cancel ()
186
-
187
- cmd .Cancel = func () error {
188
- cancelled = true
189
- return cmd .Process .Kill ()
190
- }
191
188
} else {
192
- cmd = exec .Command ( prog , args ... )
189
+ cmd = exec .CommandContext ( ctx , prog , args ... )
193
190
}
194
191
if test .Env != nil || test .numShards != 0 {
195
192
cmd .Env = make ([]string , len (os .Environ ()))
@@ -219,23 +216,30 @@ func runTestOnce(test test, mallocNumToFail int64) (passed bool, err error) {
219
216
}
220
217
221
218
if err := cmd .Wait (); err != nil {
222
- if exitError , ok := err .(* exec.ExitError ); ok {
219
+ var exitError * exec.ExitError
220
+ if errors .As (err , & exitError ) {
223
221
switch exitError .Sys ().(syscall.WaitStatus ).ExitStatus () {
224
222
case 88 :
225
223
return false , errMoreMallocs
226
224
case 89 :
227
225
fmt .Print (string (outBuf .Bytes ()))
228
226
return false , errTestSkipped
229
227
}
230
- if cancelled {
231
- return testPass (outBuf ), errTestHanging
228
+ select {
229
+ case <- ctx .Done ():
230
+ if errors .Is (ctx .Err (), context .DeadlineExceeded ) {
231
+ return testPass (outBuf ), errTestHanging
232
+ } else if ctx .Err () != nil {
233
+ return false , ctx .Err ()
234
+ }
235
+ default :
236
+ // Nothing
232
237
}
233
238
}
234
239
fmt .Print (string (outBuf .Bytes ()))
235
240
return false , err
236
241
}
237
242
238
-
239
243
return testPass (outBuf ), nil
240
244
}
241
245
0 commit comments