@@ -39,52 +39,54 @@ func TestSource(t *testing.T) {
39
39
sampleValue1 := func (v []int64 ) int64 {
40
40
return v [1 ]
41
41
}
42
-
42
+ negProfile := testProfile .Copy ()
43
+ for _ , sample := range negProfile .Sample {
44
+ for i , v := range sample .Value {
45
+ sample .Value [i ] = - v
46
+ }
47
+ }
43
48
for _ , tc := range []testcase {
44
49
{
45
50
rpt : New (
46
- testProfile1 .Copy (),
51
+ testProfile .Copy (),
47
52
& Options {
48
53
OutputFormat : List ,
49
54
Symbol : regexp .MustCompile (`.` ),
50
55
TrimPath : "/some/path" ,
51
56
52
57
SampleValue : sampleValue1 ,
53
- SampleUnit : testProfile1 .SampleType [1 ].Unit ,
58
+ SampleUnit : testProfile .SampleType [1 ].Unit ,
54
59
},
55
60
),
56
61
want : path + "source.rpt" ,
57
62
},
58
63
{
59
64
rpt : New (
60
- testProfile1 .Copy (),
65
+ testProfile .Copy (),
61
66
& Options {
62
67
OutputFormat : Dot ,
63
68
CallTree : true ,
64
69
Symbol : regexp .MustCompile (`.` ),
65
70
TrimPath : "/some/path" ,
66
71
67
72
SampleValue : sampleValue1 ,
68
- SampleUnit : testProfile1 .SampleType [1 ].Unit ,
73
+ SampleUnit : testProfile .SampleType [1 ].Unit ,
69
74
},
70
75
),
71
76
want : path + "source.dot" ,
72
77
},
73
78
{
74
79
rpt : New (
75
- testProfile2 .Copy (),
80
+ negProfile .Copy (),
76
81
& Options {
77
- OutputFormat : Dot ,
78
- CallTree : true ,
82
+ OutputFormat : List ,
79
83
Symbol : regexp .MustCompile (`.` ),
80
- TrimPath : "/some/path" ,
81
-
82
- SampleValue : sampleValue1 ,
83
- SampleUnit : testProfile2 .SampleType [1 ].Unit ,
84
+ SampleValue : sampleValue1 ,
85
+ SampleUnit : negProfile .SampleType [1 ].Unit ,
84
86
},
85
87
),
86
88
wantNegSampleErr : true ,
87
- want : path + "source_neg_samples.dot " ,
89
+ want : path + "source_neg_samples.rpt " ,
88
90
},
89
91
} {
90
92
var b bytes.Buffer
@@ -203,7 +205,7 @@ var testL = []*profile.Location{
203
205
},
204
206
}
205
207
206
- var testProfile1 = & profile.Profile {
208
+ var testProfile = & profile.Profile {
207
209
PeriodType : & profile.ValueType {Type : "cpu" , Unit : "millisecond" },
208
210
Period : 10 ,
209
211
DurationNanos : 10e9 ,
@@ -238,41 +240,6 @@ var testProfile1 = &profile.Profile{
238
240
Mapping : testM ,
239
241
}
240
242
241
- var testProfile2 = & profile.Profile {
242
- PeriodType : & profile.ValueType {Type : "cpu" , Unit : "millisecond" },
243
- Period : 10 ,
244
- DurationNanos : 10e9 ,
245
- SampleType : []* profile.ValueType {
246
- {Type : "samples" , Unit : "count" },
247
- {Type : "cpu" , Unit : "cycles" },
248
- },
249
- Sample : []* profile.Sample {
250
- {
251
- Location : []* profile.Location {testL [0 ]},
252
- Value : []int64 {1 , 1 },
253
- },
254
- {
255
- Location : []* profile.Location {testL [2 ], testL [1 ], testL [0 ]},
256
- Value : []int64 {1 , 10 },
257
- },
258
- {
259
- Location : []* profile.Location {testL [4 ], testL [2 ], testL [0 ]},
260
- Value : []int64 {1 , - 100 },
261
- },
262
- {
263
- Location : []* profile.Location {testL [3 ], testL [0 ]},
264
- Value : []int64 {1 , 1000 },
265
- },
266
- {
267
- Location : []* profile.Location {testL [4 ], testL [3 ], testL [0 ]},
268
- Value : []int64 {1 , 10000 },
269
- },
270
- },
271
- Location : testL ,
272
- Function : testF ,
273
- Mapping : testM ,
274
- }
275
-
276
243
func TestDisambiguation (t * testing.T ) {
277
244
parent1 := & graph.Node {Info : graph.NodeInfo {Name : "parent1" }}
278
245
parent2 := & graph.Node {Info : graph.NodeInfo {Name : "parent2" }}
@@ -356,7 +323,7 @@ func TestLegendActiveFilters(t *testing.T) {
356
323
}
357
324
358
325
func TestComputeTotal (t * testing.T ) {
359
- p1 := testProfile1 .Copy ()
326
+ p1 := testProfile .Copy ()
360
327
p1 .Sample = []* profile.Sample {
361
328
{
362
329
Location : []* profile.Location {testL [0 ]},
@@ -372,7 +339,7 @@ func TestComputeTotal(t *testing.T) {
372
339
},
373
340
}
374
341
375
- p2 := testProfile1 .Copy ()
342
+ p2 := testProfile .Copy ()
376
343
p2 .Sample = []* profile.Sample {
377
344
{
378
345
Location : []* profile.Location {testL [0 ]},
@@ -388,7 +355,7 @@ func TestComputeTotal(t *testing.T) {
388
355
},
389
356
}
390
357
391
- p3 := testProfile1 .Copy ()
358
+ p3 := testProfile .Copy ()
392
359
p3 .Sample = []* profile.Sample {
393
360
{
394
361
Location : []* profile.Location {testL [0 ]},
@@ -425,11 +392,11 @@ func TestComputeTotal(t *testing.T) {
425
392
}
426
393
427
394
testcases := []struct {
428
- desc string
429
- prof * profile.Profile
430
- value , meanDiv func (v []int64 ) int64
431
- wantTotal int64
432
- wantUnexpNegSamples bool
395
+ desc string
396
+ prof * profile.Profile
397
+ value , meanDiv func (v []int64 ) int64
398
+ wantTotal int64
399
+ wantHasNegativeSamples bool
433
400
}{
434
401
{
435
402
desc : "no diff base, all positive values, index 1" ,
@@ -453,8 +420,8 @@ func TestComputeTotal(t *testing.T) {
453
420
value : func (v []int64 ) int64 {
454
421
return v [1 ]
455
422
},
456
- wantTotal : 111 ,
457
- wantUnexpNegSamples : true ,
423
+ wantTotal : 111 ,
424
+ wantHasNegativeSamples : true ,
458
425
},
459
426
{
460
427
desc : "diff base, some negative values" ,
@@ -468,12 +435,12 @@ func TestComputeTotal(t *testing.T) {
468
435
469
436
for _ , tc := range testcases {
470
437
t .Run (tc .desc , func (t * testing.T ) {
471
- gotTotal , gotUnexpNegSamples := computeTotal (tc .prof , tc .value , tc .meanDiv )
438
+ gotTotal , gotHasNegativeSamples := computeTotal (tc .prof , tc .value , tc .meanDiv )
472
439
if gotTotal != tc .wantTotal {
473
440
t .Errorf ("got total %d, want %v" , gotTotal , tc .wantTotal )
474
441
}
475
- if gotUnexpNegSamples != tc .wantUnexpNegSamples {
476
- t .Errorf ("got unexpected negative samples %v, want %v" , gotUnexpNegSamples , tc .wantUnexpNegSamples )
442
+ if gotHasNegativeSamples != tc .wantHasNegativeSamples {
443
+ t .Errorf ("got unexpected negative samples %v, want %v" , gotHasNegativeSamples , tc .wantHasNegativeSamples )
477
444
}
478
445
})
479
446
}
0 commit comments