diff options
author | Daniel Baumann <daniel.baumann@progress-linux.org> | 2024-04-16 19:23:18 +0000 |
---|---|---|
committer | Daniel Baumann <daniel.baumann@progress-linux.org> | 2024-04-16 19:23:18 +0000 |
commit | 43a123c1ae6613b3efeed291fa552ecd909d3acf (patch) | |
tree | fd92518b7024bc74031f78a1cf9e454b65e73665 /src/cmd/compile/internal/ssa/fmahash_test.go | |
parent | Initial commit. (diff) | |
download | golang-1.20-43a123c1ae6613b3efeed291fa552ecd909d3acf.tar.xz golang-1.20-43a123c1ae6613b3efeed291fa552ecd909d3acf.zip |
Adding upstream version 1.20.14.upstream/1.20.14upstream
Signed-off-by: Daniel Baumann <daniel.baumann@progress-linux.org>
Diffstat (limited to 'src/cmd/compile/internal/ssa/fmahash_test.go')
-rw-r--r-- | src/cmd/compile/internal/ssa/fmahash_test.go | 57 |
1 files changed, 57 insertions, 0 deletions
diff --git a/src/cmd/compile/internal/ssa/fmahash_test.go b/src/cmd/compile/internal/ssa/fmahash_test.go new file mode 100644 index 0000000..8bdb3bf --- /dev/null +++ b/src/cmd/compile/internal/ssa/fmahash_test.go @@ -0,0 +1,57 @@ +// Copyright 2022 The Go Authors. All rights reserved. +// Use of this source code is governed by a BSD-style +// license that can be found in the LICENSE file. + +package ssa_test + +import ( + "internal/testenv" + "os" + "path/filepath" + "regexp" + "runtime" + "testing" +) + +// TestFmaHash checks that the hash-test machinery works properly for a single case. +// It also runs ssa/check and gccheck to be sure that those are checked at least a +// little in each run.bash. It does not check or run the generated code. +// The test file is however a useful example of fused-vs-cascaded multiply-add. +func TestFmaHash(t *testing.T) { + switch runtime.GOOS { + case "linux", "darwin": + default: + t.Skipf("Slow test, usually avoid it, os=%s not linux or darwin", runtime.GOOS) + } + switch runtime.GOARCH { + case "amd64", "arm64": + default: + t.Skipf("Slow test, usually avoid it, arch=%s not amd64 or arm64", runtime.GOARCH) + } + + testenv.MustHaveGoBuild(t) + gocmd := testenv.GoToolPath(t) + tmpdir, err := os.MkdirTemp("", "x") + if err != nil { + t.Error(err) + } + defer os.RemoveAll(tmpdir) + source := filepath.Join("testdata", "fma.go") + output := filepath.Join(tmpdir, "fma.exe") + cmd := testenv.Command(t, gocmd, "build", "-o", output, source) + // The hash-dependence on file path name is dodged by specifying "all hashes ending in 1" plus "all hashes ending in 0" + // i.e., all hashes. This will print all the FMAs; this test is only interested in one of them (that should appear near the end). + cmd.Env = append(cmd.Env, "GOCOMPILEDEBUG=fmahash=1/0", "GOOS=linux", "GOARCH=arm64", "HOME="+tmpdir) + t.Logf("%v", cmd) + t.Logf("%v", cmd.Env) + b, e := cmd.CombinedOutput() + if e != nil { + t.Error(e) + } + s := string(b) // Looking for "GOFMAHASH triggered main.main:24" + re := "fmahash(0?) triggered POS=.*fma.go:29:..;.*fma.go:18:.." + match := regexp.MustCompile(re) + if !match.MatchString(s) { + t.Errorf("Expected to match '%s' with \n-----\n%s-----", re, s) + } +} |