Explorar o código

fix golden tests on arm64, ppc64le, s390x

Grigory Dryapak %!s(int64=6) %!d(string=hai) anos
pai
achega
3315d80b86
Modificáronse 4 ficheiros con 23 adicións e 9 borrados
  1. 4 4
      adjust_test.go
  2. 2 2
      effects_test.go
  3. 3 3
      resize_test.go
  4. 14 0
      utils_test.go

+ 4 - 4
adjust_test.go

@@ -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)
 		}
 	}

+ 2 - 2
effects_test.go

@@ -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)
 		}
 	}

+ 3 - 3
resize_test.go

@@ -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)
 		}
 	}

+ 14 - 0
utils_test.go

@@ -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
 }