Debian Codegraph @

benchmark_test.go

raw symbols ◀ ▶
Source reconstructed at patch state 0 of 1 — not the installed (fully patched) source.
1 Debian patch touch this file
1 // These tests verify the test running logic.
2
3 package check_test
4
5 import (
6 "time"
7
8 . "github.com/pingcap/check"
9 )
10
11 var benchmarkS = Suite(&BenchmarkS{})
12
13 type BenchmarkS struct{}
14
15 func (s *BenchmarkS) TestCountSuite(c *C) {
16 suitesRun += 1
17 }
18
19 func (s *BenchmarkS) TestBasicTestTiming(c *C) {
20 helper := FixtureHelper{sleepOn: "Test1", sleep: 1000000 * time.Nanosecond}
21 output := String{}
22 runConf := RunConf{Output: &output, Verbose: true}
23 Run(&helper, &runConf)
24
25 expected := "PASS: check_test\\.go:[0-9]+: FixtureHelper\\.Test1\t0\\.001s\n" +
26 "PASS: check_test\\.go:[0-9]+: FixtureHelper\\.Test2\t0\\.000s\n"
27 c.Assert(output.value, Matches, expected)
28 }
29
30 func (s *BenchmarkS) TestStreamTestTiming(c *C) {
31 helper := FixtureHelper{sleepOn: "SetUpSuite", sleep: 1000000 * time.Nanosecond}
32 output := String{}
33 runConf := RunConf{Output: &output, Stream: true}
34 Run(&helper, &runConf)
35
36 expected := "(?s).*\nPASS: check_test\\.go:[0-9]+: FixtureHelper\\.SetUpSuite\t *0\\.001s\n.*"
37 c.Assert(output.value, Matches, expected)
38 }
39
40 func (s *BenchmarkS) TestBenchmark(c *C) {
41 helper := FixtureHelper{sleep: 100000}
42 output := String{}
43 runConf := RunConf{
44 Output: &output,
45 Benchmark: true,
46 BenchmarkTime: 10000000,
47 Filter: "Benchmark1",
48 }
49 Run(&helper, &runConf)
50 c.Check(helper.calls[0], Equals, "SetUpSuite")
51 c.Check(helper.calls[1], Equals, "SetUpTest")
52 c.Check(helper.calls[2], Equals, "Benchmark1")
53 c.Check(helper.calls[3], Equals, "TearDownTest")
54 c.Check(helper.calls[4], Equals, "SetUpTest")
55 c.Check(helper.calls[5], Equals, "Benchmark1")
56 c.Check(helper.calls[6], Equals, "TearDownTest")
57 // ... and more.
58
59 expected := "PASS: check_test\\.go:[0-9]+: FixtureHelper\\.Benchmark1\t *100\t *[12][0-9]{5} ns/op\n"
60 c.Assert(output.value, Matches, expected)
61 }
62
63 func (s *BenchmarkS) TestBenchmarkBytes(c *C) {
64 helper := FixtureHelper{sleep: 100000}
65 output := String{}
66 runConf := RunConf{
67 Output: &output,
68 Benchmark: true,
69 BenchmarkTime: 10000000,
70 Filter: "Benchmark2",
71 }
72 Run(&helper, &runConf)
73
74 expected := "PASS: check_test\\.go:[0-9]+: FixtureHelper\\.Benchmark2\t *100\t *[12][0-9]{5} ns/op\t *[4-9]\\.[0-9]{2} MB/s\n"
75 c.Assert(output.value, Matches, expected)
76 }
77
78 func (s *BenchmarkS) TestBenchmarkMem(c *C) {
79 helper := FixtureHelper{sleep: 100000}
80 output := String{}
81 runConf := RunConf{
82 Output: &output,
83 Benchmark: true,
84 BenchmarkMem: true,
85 BenchmarkTime: 10000000,
86 Filter: "Benchmark3",
87 }
88 Run(&helper, &runConf)
89
90 expected := "PASS: check_test\\.go:[0-9]+: FixtureHelper\\.Benchmark3\t *100\t *[12][0-9]{5} ns/op\t *[0-9]+ B/op\t *[1-9] allocs/op\n"
91 c.Assert(output.value, Matches, expected)
92 }