| 1 |
//go:build go1.23 |
| 2 |
|
| 3 |
package main |
| 4 |
|
| 5 |
import ( |
| 6 |
"os" |
| 7 |
"path/filepath" |
| 8 |
"strconv" |
| 9 |
"testing" |
| 10 |
) |
| 11 |
|
| 12 |
// The linker randomizes the function layout ( -randlayout ) since Go 1.23. |
| 13 |
func TestCheckMeasuresEveryLayout(t *testing.T) { |
| 14 |
// the tolerance to make the verdict independent of the measurement noise. |
| 15 |
const ignoreNoise = 1e12 |
| 16 |
|
| 17 |
r := newTestRepo(t) |
| 18 |
r.layouts = 2 |
| 19 |
r.write("lib.go", testLibFastRefactored) |
| 20 |
r.write(filepath.Join("benchmarks", "bench_test.go"), testBenchRecordingBinary) |
| 21 |
|
| 22 |
recordDir := t.TempDir() |
| 23 |
t.Setenv(testRecordDirEnv, recordDir) |
| 24 |
out := r.check(ignoreNoise) |
| 25 |
assertStatuses(t, out.verdict, map[string]status{"BenchmarkWork": statusOK}) |
| 26 |
|
| 27 |
entries, err := os.ReadDir(recordDir) |
| 28 |
if err != nil { |
| 29 |
t.Fatal(err) |
| 30 |
} |
| 31 |
ran := map[string]bool{} |
| 32 |
for _, entry := range entries { |
| 33 |
ran[entry.Name()] = true |
| 34 |
} |
| 35 |
for _, side := range []string{"base", "head"} { |
| 36 |
for layout := 0; layout < r.layouts; layout++ { |
| 37 |
name := filepath.Base(binaryPath("", side+".layout"+strconv.Itoa(layout)+".test")) |
| 38 |
if !ran[name] { |
| 39 |
t.Fatalf("%s was not measured: %v", name, ran) |
| 40 |
} |
| 41 |
} |
| 42 |
} |
| 43 |
} |