6
6
7
7
package counter
8
8
9
- // Missing any tests of concurrent uses of a counter.
10
- // This is a TODO.
9
+ // Builders at
10
+ // https://build.golang.org/?repo=golang.org%2fx%2ftelemetry
11
11
12
12
import (
13
13
"encoding/hex"
14
14
"fmt"
15
- "log"
16
15
"os"
17
16
"path/filepath"
18
17
"reflect"
@@ -26,9 +25,10 @@ import (
26
25
)
27
26
28
27
func TestBasic (t * testing.T ) {
29
- if runtime .GOOS == "openbsd" {
30
- t .Skip ("broken for openbsd" )
28
+ if runtime .GOOS == "openbsd" || runtime . GOOS == "js" || runtime . GOOS == "wasip1" {
29
+ t .Skip ("broken for openbsd etc " )
31
30
}
31
+ t .Logf ("GOOS %s GARCH %s" , runtime .GOOS , runtime .GOARCH )
32
32
setup (t )
33
33
defer restore ()
34
34
var f file
@@ -66,14 +66,19 @@ func TestBasic(t *testing.T) {
66
66
// this is needed in Windows so that the generated testing.go file
67
67
// can clean up the temporary test directory
68
68
func close (f * file ) {
69
+ if f == nil {
70
+ // telemetry might have been off
71
+ return
72
+ }
69
73
f .current .Load ().f .Close ()
70
74
mmap .Munmap (f .current .Load ().mapping )
71
75
}
72
76
73
77
func TestLarge (t * testing.T ) {
74
- if runtime .GOOS == "openbsd" {
75
- t .Skip ("broken for openbsd" )
78
+ if runtime .GOOS == "openbsd" || runtime . GOOS == "js" || runtime . GOOS == "wasip1" {
79
+ t .Skip ("broken for openbsd etc " )
76
80
}
81
+ t .Logf ("GOOS %s GARCH %s" , runtime .GOOS , runtime .GOARCH )
77
82
setup (t )
78
83
defer restore ()
79
84
var f file
@@ -118,6 +123,7 @@ func TestLarge(t *testing.T) {
118
123
}
119
124
120
125
func TestRepeatedNew (t * testing.T ) {
126
+ t .Logf ("GOOS %s GARCH %s" , runtime .GOOS , runtime .GOARCH )
121
127
setup (t )
122
128
defer restore ()
123
129
var f file
@@ -155,6 +161,7 @@ func hexDump(data []byte) string {
155
161
}
156
162
157
163
func TestNewFile (t * testing.T ) {
164
+ t .Logf ("GOOS %s GARCH %s" , runtime .GOOS , runtime .GOARCH )
158
165
setup (t )
159
166
defer restore ()
160
167
year , month , day := time .Now ().Date ()
@@ -209,7 +216,8 @@ func TestNewFile(t *testing.T) {
209
216
}
210
217
days := (then .Sub (now )) / (24 * time .Hour )
211
218
if days <= 7 || days > 14 {
212
- t .Errorf ("days = %d, want 7 < days <= 14" , days )
219
+ // this fails on Solaris, but only once, so print i.
220
+ t .Errorf ("%d: days = %d, want 7 < days <= 14" , i , days )
213
221
}
214
222
close (& f )
215
223
// remove the file for the next iteration of the loop
@@ -218,6 +226,7 @@ func TestNewFile(t *testing.T) {
218
226
}
219
227
220
228
func TestRotate (t * testing.T ) {
229
+ t .Logf ("GOOS %s GARCH %s" , runtime .GOOS , runtime .GOARCH )
221
230
year , month , day := time .Now ().Date ()
222
231
now := time .Date (year , month , day , 0 , 0 , 0 , 0 , time .UTC )
223
232
setup (t )
@@ -272,9 +281,6 @@ func TestRotate(t *testing.T) {
272
281
}
273
282
274
283
func TestStack (t * testing.T ) {
275
- if runtime .GOARCH == "386" && runtime .GOOS == "linux" {
276
- t .Skip ("some bad line numbers for linux-386" )
277
- }
278
284
t .Logf ("GOOS %s GARCH %s" , runtime .GOOS , runtime .GOARCH )
279
285
setup (t )
280
286
defer restore ()
@@ -287,20 +293,19 @@ func TestStack(t *testing.T) {
287
293
if len (names ) != 2 {
288
294
t .Fatalf ("got %d names, want 2" , len (names ))
289
295
}
290
- // each name should be 6 lines, and the two names should
291
- // differ only in the second line. The last few lines should
292
- // be blank.
296
+ // each name should be 4 lines, and the two names should
297
+ // differ only in the second line.
293
298
n0 := strings .Split (names [0 ], "\n " )
294
299
n1 := strings .Split (names [1 ], "\n " )
295
- if len (n0 ) != 6 || len (n1 ) != 6 {
296
- t .Fatalf ("got %d and %d lines, want 6 (%q,%q)" , len (n0 ), len (n1 ), n0 , n1 )
300
+ if len (n0 ) != 4 || len (n1 ) != 4 {
301
+ t .Errorf ("got %d and %d lines, want 4 (%q,%q)" , len (n0 ), len (n1 ), n0 , n1 )
297
302
}
298
- for i := 0 ; i < 6 ; i ++ { // loop generated by copilot (from comment?)
303
+ for i := 0 ; i < 4 && i < len ( n0 ) && i < len ( n1 ); i ++ {
299
304
if i == 1 {
300
305
continue
301
306
}
302
307
if n0 [i ] != n1 [i ] {
303
- t .Fatalf ("line %d differs:\n %s\n %s" , i , n0 [i ], n1 [i ])
308
+ t .Errorf ("line %d differs:\n %s\n %s" , i , n0 [i ], n1 [i ])
304
309
}
305
310
}
306
311
oldnames := make (map [string ]bool )
@@ -318,7 +323,7 @@ func TestStack(t *testing.T) {
318
323
}
319
324
// expect 5 new names, one for each level of recursion
320
325
if len (newnames ) != 5 {
321
- t .Fatalf ("got %d new names, want 5" , len (newnames ))
326
+ t .Errorf ("got %d new names, want 5" , len (newnames ))
322
327
}
323
328
// look inside. old names should have a count of 1, new ones 2
324
329
for _ , ct := range c .Counters () {
@@ -362,78 +367,3 @@ func restore() {
362
367
func (f * file ) New (name string ) * Counter {
363
368
return & Counter {name : name , file : f }
364
369
}
365
-
366
- // This checks the computation of of line numbers for creating
367
- // stack counters. It is named after the strangest system,
368
- // but will provide a timely warning if the runtime changes how it
369
- // computes line numbers.
370
- func TestLinux386 (t * testing.T ) {
371
- t .Logf ("GOOS %s GARCH %s" , runtime .GOOS , runtime .GOARCH )
372
- x := infoFromHere (0 )
373
- if msg , wanted := check (0 , x ); msg != "" {
374
- t .Errorf ("got %q, wanted %s" , msg , wanted )
375
- }
376
- x = deeper ()
377
- if msg , wanted := check (1 , x ); msg != "" {
378
- t .Errorf ("got %q, wanted %s" , msg , wanted )
379
- }
380
- }
381
-
382
- var ans = []string {
383
- "GOOS freebsd GARCH amd64: 3 7" ,
384
- "GOOS linux GARCH amd64: 3 7" ,
385
- "GOOS linux GARCH arm64: 3 7" ,
386
- "GOOS linux GARCH 386: 2 6" ,
387
- "GOOS openbsd GARCH amd64: 3 7" ,
388
- "GOOS windows GARCH amd64: 3 7" ,
389
- "GOOS darwin GARCH amd64: 3 7" ,
390
- "GOOS darwin GARCH arm64: 3 7" ,
391
- }
392
-
393
- func check (n int , got string ) (string , string ) {
394
- const prefix = "golang.org/x/telemetry/counter.TestLinux386:"
395
- start := fmt .Sprintf ("GOOS %s GARCH %s" , runtime .GOOS , runtime .GOARCH )
396
- if ! strings .HasPrefix (got , prefix ) {
397
- return got , "doesn't start with " + prefix
398
- }
399
- for _ , a := range ans {
400
- before , after , ok := strings .Cut (a , ":" )
401
- if ! ok {
402
- return got , "bad ans, no colon"
403
- }
404
- if before == start {
405
- flds := strings .Fields (after )
406
- if prefix + flds [n ] == got {
407
- return "" , ""
408
- }
409
- return got , flds [n ]
410
- }
411
- }
412
- return got , fmt .Sprintf ("%s not found" , start )
413
- }
414
-
415
- func deeper () string {
416
- log .SetFlags (log .Lshortfile )
417
- x := infoFromHere (1 )
418
- return x
419
- }
420
-
421
- // the code from file.go that creates stack counter names
422
- func infoFromHere (w int ) string {
423
- pcs := make ([]uintptr , 4 )
424
- n := runtime .Callers (2 , pcs )
425
- pcs = pcs [:n ]
426
- locs := make ([]string , n )
427
- frs := runtime .CallersFrames (pcs )
428
- for i := 0 ; i < n ; i ++ {
429
- fr , more := frs .Next ()
430
- _ , pcline := fr .Func .FileLine (pcs [i ])
431
- entryptr := fr .Func .Entry ()
432
- _ , entryline := fr .Func .FileLine (entryptr )
433
- locs [i ] = fmt .Sprintf ("%s:%d" , fr .Function , pcline - entryline )
434
- if ! more {
435
- break
436
- }
437
- }
438
- return locs [w ]
439
- }
0 commit comments