mirror of
https://github.com/disintegration/imaging.git
synced 2025-12-24 12:58:00 +08:00
fix golden tests on arm64, ppc64le, s390x
This commit is contained in:
@@ -234,7 +234,7 @@ func TestAdjustSaturationGolden(t *testing.T) {
|
||||
if err != nil {
|
||||
t.Fatalf("failed to open image: %v", err)
|
||||
}
|
||||
if !compareNRGBA(got, toNRGBA(want), 0) {
|
||||
if !compareNRGBAGolden(got, toNRGBA(want)) {
|
||||
t.Errorf("resulting image differs from golden: %s", name)
|
||||
}
|
||||
}
|
||||
@@ -385,7 +385,7 @@ func TestAdjustContrastGolden(t *testing.T) {
|
||||
if err != nil {
|
||||
t.Fatalf("failed to open image: %v", err)
|
||||
}
|
||||
if !compareNRGBA(got, toNRGBA(want), 0) {
|
||||
if !compareNRGBAGolden(got, toNRGBA(want)) {
|
||||
t.Fatalf("resulting image differs from golden: %s", name)
|
||||
}
|
||||
}
|
||||
@@ -536,7 +536,7 @@ func TestAdjustBrightnessGolden(t *testing.T) {
|
||||
if err != nil {
|
||||
t.Fatalf("failed to open image: %v", err)
|
||||
}
|
||||
if !compareNRGBA(got, toNRGBA(want), 0) {
|
||||
if !compareNRGBAGolden(got, toNRGBA(want)) {
|
||||
t.Fatalf("resulting image differs from golden: %s", name)
|
||||
}
|
||||
}
|
||||
@@ -643,7 +643,7 @@ func TestAdjustGammaGolden(t *testing.T) {
|
||||
if err != nil {
|
||||
t.Fatalf("failed to open image: %v", err)
|
||||
}
|
||||
if !compareNRGBA(got, toNRGBA(want), 0) {
|
||||
if !compareNRGBAGolden(got, toNRGBA(want)) {
|
||||
t.Fatalf("resulting image differs from golden: %s", name)
|
||||
}
|
||||
}
|
||||
|
||||
@@ -99,7 +99,7 @@ func TestBlurGolden(t *testing.T) {
|
||||
if err != nil {
|
||||
t.Fatalf("failed to open image: %v", err)
|
||||
}
|
||||
if !compareNRGBA(got, toNRGBA(want), 0) {
|
||||
if !compareNRGBAGolden(got, toNRGBA(want)) {
|
||||
t.Fatalf("resulting image differs from golden: %s", name)
|
||||
}
|
||||
}
|
||||
@@ -224,7 +224,7 @@ func TestSharpenGolden(t *testing.T) {
|
||||
if err != nil {
|
||||
t.Fatalf("failed to open image: %v", err)
|
||||
}
|
||||
if !compareNRGBA(got, toNRGBA(want), 0) {
|
||||
if !compareNRGBAGolden(got, toNRGBA(want)) {
|
||||
t.Fatalf("resulting image differs from golden: %s", name)
|
||||
}
|
||||
}
|
||||
|
||||
@@ -254,7 +254,7 @@ func TestResizeGolden(t *testing.T) {
|
||||
if err != nil {
|
||||
t.Fatalf("failed to open image: %v", err)
|
||||
}
|
||||
if !compareNRGBA(got, toNRGBA(want), 0) {
|
||||
if !compareNRGBAGolden(got, toNRGBA(want)) {
|
||||
t.Fatalf("resulting image differs from golden: %s", name)
|
||||
}
|
||||
}
|
||||
@@ -382,7 +382,7 @@ func TestFitGolden(t *testing.T) {
|
||||
if err != nil {
|
||||
t.Fatalf("failed to open image: %v", err)
|
||||
}
|
||||
if !compareNRGBA(got, toNRGBA(want), 0) {
|
||||
if !compareNRGBAGolden(got, toNRGBA(want)) {
|
||||
t.Fatalf("resulting image differs from golden: %s", name)
|
||||
}
|
||||
}
|
||||
@@ -487,7 +487,7 @@ func TestFillGolden(t *testing.T) {
|
||||
if err != nil {
|
||||
t.Fatalf("failed to open image: %v", err)
|
||||
}
|
||||
if !compareNRGBA(got, toNRGBA(want), 0) {
|
||||
if !compareNRGBAGolden(got, toNRGBA(want)) {
|
||||
t.Fatalf("resulting image differs from golden: %s", name)
|
||||
}
|
||||
}
|
||||
|
||||
@@ -126,6 +126,20 @@ func compareBytes(a, b []uint8, delta int) bool {
|
||||
return true
|
||||
}
|
||||
|
||||
// compareNRGBAGolden is a special version of compareNRGBA used in golden tests.
|
||||
// All the golden images are generated on amd64 architecture. Due to differences
|
||||
// in floating-point rounding on different architectures, we need to add some
|
||||
// level of tolerance when comparing images on architectures other than amd64.
|
||||
// See https://golang.org/ref/spec#Floating_point_operators for information on
|
||||
// fused multiply and add (FMA) instruction.
|
||||
func compareNRGBAGolden(img1, img2 *image.NRGBA) bool {
|
||||
delta := 0
|
||||
if runtime.GOARCH != "amd64" {
|
||||
delta = 1
|
||||
}
|
||||
return compareNRGBA(img1, img2, delta)
|
||||
}
|
||||
|
||||
func compareFloat64(a, b, delta float64) bool {
|
||||
return math.Abs(a-b) <= delta
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user