@@ -23,9 +23,11 @@ import (
23
23
"log"
24
24
"os"
25
25
"path/filepath"
26
+ "runtime"
26
27
"strings"
27
28
"testing"
28
29
"time"
30
+ "unsafe"
29
31
30
32
"golang.org/x/tools/go/loader"
31
33
"golang.org/x/tools/go/ssa"
@@ -138,13 +140,7 @@ func init() {
138
140
}
139
141
}
140
142
141
- // Specific GOARCH to use for a test case in go.tools/go/ssa/interp/testdata/.
142
- // Defaults to amd64 otherwise.
143
- var testdataArchs = map [string ]string {
144
- "width32.go" : "386" ,
145
- }
146
-
147
- func run (t * testing.T , input string ) bool {
143
+ func run (t * testing.T , input string ) {
148
144
// The recover2 test case is broken on Go 1.14+. See golang/go#34089.
149
145
// TODO(matloob): Fix this.
150
146
if filepath .Base (input ) == "recover2.go" {
@@ -157,16 +153,15 @@ func run(t *testing.T, input string) bool {
157
153
158
154
ctx := build .Default // copy
159
155
ctx .GOROOT = "testdata" // fake goroot
160
- ctx .GOOS = "linux"
161
- ctx .GOARCH = "amd64"
162
- if arch , ok := testdataArchs [ filepath .Base (input )]; ok {
163
- ctx . GOARCH = arch
156
+ ctx .GOOS = runtime . GOOS
157
+ ctx .GOARCH = runtime . GOARCH
158
+ if filepath .Base (input ) == "width32.go" && unsafe . Sizeof ( int ( 0 )) > 4 {
159
+ t . Skipf ( "skipping: width32.go checks behavior for a 32-bit int" )
164
160
}
165
161
166
162
conf := loader.Config {Build : & ctx }
167
163
if _ , err := conf .FromArgs ([]string {input }, true ); err != nil {
168
- t .Errorf ("FromArgs(%s) failed: %s" , input , err )
169
- return false
164
+ t .Fatalf ("FromArgs(%s) failed: %s" , input , err )
170
165
}
171
166
172
167
conf .Import ("runtime" )
@@ -188,8 +183,7 @@ func run(t *testing.T, input string) bool {
188
183
189
184
iprog , err := conf .Load ()
190
185
if err != nil {
191
- t .Errorf ("conf.Load(%s) failed: %s" , input , err )
192
- return false
186
+ t .Fatalf ("conf.Load(%s) failed: %s" , input , err )
193
187
}
194
188
195
189
bmode := ssa .InstantiateGenerics | ssa .SanityCheckFunctions
@@ -205,6 +199,9 @@ func run(t *testing.T, input string) bool {
205
199
interp .CapturedOutput = new (bytes.Buffer )
206
200
207
201
sizes := types .SizesFor ("gc" , ctx .GOARCH )
202
+ if sizes .Sizeof (types .Typ [types .Int ]) < 4 {
203
+ panic ("bogus SizesFor" )
204
+ }
208
205
hint = fmt .Sprintf ("To trace execution, run:\n %% go build golang.org/x/tools/cmd/ssadump && ./ssadump -build=C -test -run --interp=T %s\n " , input )
209
206
var imode interp.Mode // default mode
210
207
// imode |= interp.DisableRecover // enable for debugging
@@ -223,17 +220,6 @@ func run(t *testing.T, input string) bool {
223
220
if false {
224
221
t .Log (input , time .Since (start )) // test profiling
225
222
}
226
-
227
- return true
228
- }
229
-
230
- func printFailures (failures []string ) {
231
- if failures != nil {
232
- fmt .Println ("The following tests failed:" )
233
- for _ , f := range failures {
234
- fmt .Printf ("\t %s\n " , f )
235
- }
236
- }
237
223
}
238
224
239
225
// TestTestdataFiles runs the interpreter on testdata/*.go.
@@ -242,25 +228,20 @@ func TestTestdataFiles(t *testing.T) {
242
228
if err != nil {
243
229
log .Fatal (err )
244
230
}
245
- var failures []string
246
231
for _ , input := range testdataTests {
247
- if ! run ( t , filepath . Join ( cwd , "testdata" , input ) ) {
248
- failures = append ( failures , input )
249
- }
232
+ t . Run ( input , func ( t * testing. T ) {
233
+ run ( t , filepath . Join ( cwd , "testdata" , input ) )
234
+ })
250
235
}
251
- printFailures (failures )
252
236
}
253
237
254
238
// TestGorootTest runs the interpreter on $GOROOT/test/*.go.
255
239
func TestGorootTest (t * testing.T ) {
256
- var failures []string
257
-
258
240
for _ , input := range gorootTestTests {
259
- if ! run ( t , filepath . Join ( build . Default . GOROOT , "test" , input ) ) {
260
- failures = append ( failures , input )
261
- }
241
+ t . Run ( input , func ( t * testing. T ) {
242
+ run ( t , filepath . Join ( build . Default . GOROOT , "test" , input ) )
243
+ })
262
244
}
263
- printFailures (failures )
264
245
}
265
246
266
247
// TestTypeparamTest runs the interpreter on runnable examples
@@ -274,54 +255,47 @@ func TestTypeparamTest(t *testing.T) {
274
255
// Skip known failures for the given reason.
275
256
// TODO(taking): Address these.
276
257
skip := map [string ]string {
277
- "chans.go" : "interp tests do not support runtime.SetFinalizer" ,
278
- "issue23536.go" : "unknown reason" ,
279
- "issue376214.go" : "unknown issue with variadic cast on bytes" ,
280
- "issue48042.go" : "interp tests do not handle reflect.Value.SetInt" ,
281
- "issue47716.go" : "interp tests do not handle unsafe.Sizeof" ,
282
- "issue50419.go" : "interp tests do not handle dispatch to String() correctly" ,
283
- "issue51733.go" : "interp does not handle unsafe casts" ,
284
- "ordered.go" : "math.NaN() comparisons not being handled correctly" ,
285
- "orderedmap.go" : "interp tests do not support runtime.SetFinalizer" ,
286
- "stringer.go" : "unknown reason" ,
287
- "issue48317.go" : "interp tests do not support encoding/json" ,
288
- "issue48318.go" : "interp tests do not support encoding/json" ,
289
- "issue58513.go" : "interp tests do not support runtime.Caller" ,
258
+ "chans.go" : "interp tests do not support runtime.SetFinalizer" ,
259
+ "issue23536.go" : "unknown reason" ,
260
+ "issue48042.go" : "interp tests do not handle reflect.Value.SetInt" ,
261
+ "issue47716.go" : "interp tests do not handle unsafe.Sizeof" ,
262
+ "issue50419.go" : "interp tests do not handle dispatch to String() correctly" ,
263
+ "issue51733.go" : "interp does not handle unsafe casts" ,
264
+ "ordered.go" : "math.NaN() comparisons not being handled correctly" ,
265
+ "orderedmap.go" : "interp tests do not support runtime.SetFinalizer" ,
266
+ "stringer.go" : "unknown reason" ,
267
+ "issue48317.go" : "interp tests do not support encoding/json" ,
268
+ "issue48318.go" : "interp tests do not support encoding/json" ,
269
+ "issue58513.go" : "interp tests do not support runtime.Caller" ,
290
270
}
291
271
// Collect all of the .go files in dir that are runnable.
292
272
dir := filepath .Join (build .Default .GOROOT , "test" , "typeparam" )
293
273
list , err := os .ReadDir (dir )
294
274
if err != nil {
295
275
t .Fatal (err )
296
276
}
297
- var inputs []string
298
277
for _ , entry := range list {
299
278
if entry .IsDir () || ! strings .HasSuffix (entry .Name (), ".go" ) {
300
279
continue // Consider standalone go files.
301
280
}
302
- if reason := skip [entry .Name ()]; reason != "" {
303
- t .Logf ("skipping %q due to %s." , entry .Name (), reason )
304
- continue
305
- }
306
- input := filepath .Join (dir , entry .Name ())
307
- src , err := os .ReadFile (input )
308
- if err != nil {
309
- t .Fatal (err )
310
- }
311
- // Only build test files that can be compiled, or compiled and run.
312
- if bytes .HasPrefix (src , []byte ("// run" )) && ! bytes .HasPrefix (src , []byte ("// rundir" )) {
313
- inputs = append (inputs , input )
314
- } else {
315
- t .Logf ("Not a `// run` file: %s" , entry .Name ())
316
- }
317
- }
318
-
319
- var failures []string
320
- for _ , input := range inputs {
321
- t .Log ("running" , input )
322
- if ! run (t , input ) {
323
- failures = append (failures , input )
324
- }
281
+ t .Run (entry .Name (), func (t * testing.T ) {
282
+ input := filepath .Join (dir , entry .Name ())
283
+ src , err := os .ReadFile (input )
284
+ if err != nil {
285
+ t .Fatal (err )
286
+ }
287
+
288
+ // Only build test files that can be compiled, or compiled and run.
289
+ if ! bytes .HasPrefix (src , []byte ("// run" )) || bytes .HasPrefix (src , []byte ("// rundir" )) {
290
+ t .Logf ("Not a `// run` file: %s" , entry .Name ())
291
+ return
292
+ }
293
+
294
+ if reason := skip [entry .Name ()]; reason != "" {
295
+ t .Skipf ("skipping: %s" , reason )
296
+ }
297
+
298
+ run (t , input )
299
+ })
325
300
}
326
- printFailures (failures )
327
301
}
0 commit comments