public inbox for git-commits@fedoraproject.org
help / color / mirror / Atom feed
* [rpms/hugo] epel8: Backport fix to image tests on alternate arches.
@ 2026-11-06  5:42 Elliott Sales de Andrade
  0 siblings, 0 replies; only message in thread
From: Elliott Sales de Andrade @ 2026-11-06  5:42 UTC (permalink / raw)
  To: git-commits

A new commit has been pushed.

Repo   : rpms/hugo
Branch : epel8
Commit : e64dfc80fd81760e26f48a6de9902dad92a81090
Author : Elliott Sales de Andrade <quantum.analyst@gmail.com>
Date   : 2019-10-22T00:33:33-04:00
Stats  : +145/-0 in 2 file(s)
URL    : https://src.fedoraproject.org/rpms/hugo/c/e64dfc80fd81760e26f48a6de9902dad92a81090?branch=epel8

Log:
Backport fix to image tests on alternate arches.

---
diff --git a/6396.patch b/6396.patch
new file mode 100644
index 0000000..b1994b8
--- /dev/null
+++ b/6396.patch
@@ -0,0 +1,142 @@
+From 7b2d87787cb57019e818581693cadd0cdc289999 Mon Sep 17 00:00:00 2001
+From: Anthony Fok <foka@debian.org>
+Date: Mon, 7 Oct 2019 12:35:00 -0600
+Subject: [PATCH] resources: Fix image test error on s390x, ppc64* and arm64
+
+In TestImageOperationsGolden, tolerate slight floating-point rounding
+differences due to the use or non-use of "fused multiply and add" (FMA)
+instruction on different architectures.
+
+Special thanks to @disintegration for the solution in goldenEqual();
+see https://github.com/disintegration/gift/issues/20
+
+Fixes #6387
+---
+ resources/image_test.go | 83 ++++++++++++++++++++++++++++++++++++++---
+ 1 file changed, 78 insertions(+), 5 deletions(-)
+
+diff --git a/resources/image_test.go b/resources/image_test.go
+index 169f19522e..4b88b7aa12 100644
+--- a/resources/image_test.go
++++ b/resources/image_test.go
+@@ -15,6 +15,7 @@ package resources
+ 
+ import (
+ 	"fmt"
++	"image"
+ 	"io/ioutil"
+ 	"math/big"
+ 	"math/rand"
+@@ -22,6 +23,7 @@ import (
+ 	"path"
+ 	"path/filepath"
+ 	"regexp"
++	"runtime"
+ 	"strconv"
+ 	"sync"
+ 	"testing"
+@@ -478,6 +480,47 @@ func BenchmarkImageExif(b *testing.B) {
+ 
+ }
+ 
++// usesFMA indicates whether "fused multiply and add" (FMA) instruction is
++// used.  The command "grep FMADD go/test/codegen/floats.go" can help keep
++// the FMA-using architecture list updated.
++var usesFMA = runtime.GOARCH == "s390x" ||
++	runtime.GOARCH == "ppc64" ||
++	runtime.GOARCH == "ppc64le" ||
++	runtime.GOARCH == "arm64"
++
++// goldenEqual compares two NRGBA images.  It is used in golden tests only.
++// A small tolerance is allowed on architectures using "fused multiply and add"
++// (FMA) instruction to accommodate for floating-point rounding differences
++// with control golden images that were generated on amd64 architecture.
++// See https://golang.org/ref/spec#Floating_point_operators
++// and https://github.com/gohugoio/hugo/issues/6387 for more information.
++//
++// Borrowed from https://github.com/disintegration/gift/blob/a999ff8d5226e5ab14b64a94fca07c4ac3f357cf/gift_test.go#L598-L625
++// Copyright (c) 2014-2019 Grigory Dryapak
++// Licensed under the MIT License.
++func goldenEqual(img1, img2 *image.NRGBA) bool {
++	maxDiff := 0
++	if usesFMA {
++		maxDiff = 1
++	}
++	if !img1.Rect.Eq(img2.Rect) {
++		return false
++	}
++	if len(img1.Pix) != len(img2.Pix) {
++		return false
++	}
++	for i := 0; i < len(img1.Pix); i++ {
++		diff := int(img1.Pix[i]) - int(img2.Pix[i])
++		if diff < 0 {
++			diff = -diff
++		}
++		if diff > maxDiff {
++			return false
++		}
++	}
++	return true
++}
++
+ func TestImageOperationsGolden(t *testing.T) {
+ 	c := qt.New(t)
+ 	c.Parallel()
+@@ -580,21 +623,51 @@ func TestImageOperationsGolden(t *testing.T) {
+ 		}
+ 		fi2 := dirinfos2[i]
+ 		c.Assert(fi1.Name(), qt.Equals, fi2.Name())
+-		c.Assert(fi1, eq, fi2)
++
+ 		f1, err := os.Open(filepath.Join(dir1, fi1.Name()))
+ 		c.Assert(err, qt.IsNil)
+ 		f2, err := os.Open(filepath.Join(dir2, fi2.Name()))
+ 		c.Assert(err, qt.IsNil)
+ 
+-		hash1, err := helpers.MD5FromReader(f1)
++		img1, _, err := image.Decode(f1)
+ 		c.Assert(err, qt.IsNil)
+-		hash2, err := helpers.MD5FromReader(f2)
++		img2, _, err := image.Decode(f2)
+ 		c.Assert(err, qt.IsNil)
+ 
++		nrgba1 := image.NewNRGBA(img1.Bounds())
++		gift.New().Draw(nrgba1, img1)
++		nrgba2 := image.NewNRGBA(img2.Bounds())
++		gift.New().Draw(nrgba2, img2)
++
++		if !goldenEqual(nrgba1, nrgba2) {
++			switch fi1.Name() {
++			case "gohugoio8_hu7f72c00afdf7634587afaa5eff2a25b2_73538_4c320010919da2d8b63ed24818b4d8e1.png",
++				"gohugoio8_hu7f72c00afdf7634587afaa5eff2a25b2_73538_9d4c2220235b3c2d9fa6506be571560f.png",
++				"gohugoio8_hu7f72c00afdf7634587afaa5eff2a25b2_73538_c74bb417b961e09cf1aac2130b7b9b85.png":
++				c.Log("expectedly differs from golden due to dithering:", fi1.Name())
++			default:
++				t.Errorf("resulting image differs from golden: %s", fi1.Name())
++			}
++		}
++
++		if !usesFMA {
++			c.Assert(fi1, eq, fi2)
++
++			_, err = f1.Seek(0, 0)
++			c.Assert(err, qt.IsNil)
++			_, err = f2.Seek(0, 0)
++			c.Assert(err, qt.IsNil)
++
++			hash1, err := helpers.MD5FromReader(f1)
++			c.Assert(err, qt.IsNil)
++			hash2, err := helpers.MD5FromReader(f2)
++			c.Assert(err, qt.IsNil)
++
++			c.Assert(hash1, qt.Equals, hash2)
++		}
++
+ 		f1.Close()
+ 		f2.Close()
+-
+-		c.Assert(hash1, qt.Equals, hash2)
+ 	}
+ 
+ }

diff --git a/hugo.spec b/hugo.spec
index 621241f..d8fd95d 100644
--- a/hugo.spec
+++ b/hugo.spec
@@ -32,6 +32,8 @@ Patch0002:      0001-Fix-tests-against-latest-emoji-package.patch
 Patch0003:      https://github.com/gohugoio/hugo/pull/6403.patch
 # Fix test susceptible to inconsistent directory order.
 Patch0004:      https://github.com/gohugoio/hugo/pull/6385.patch
+# Fix image tests on other arches.
+Patch0005:      https://github.com/gohugoio/hugo/pull/6396.patch
 
 BuildRequires:  golang(github.com/alecthomas/chroma)
 BuildRequires:  golang(github.com/alecthomas/chroma/formatters)
@@ -134,6 +136,7 @@ BuildRequires:  rubygem-asciidoctor
 %patch0002 -p1
 %patch0003 -p1
 %patch0004 -p1
+%patch0005 -p1
 
 # Replace blackfriday import path to avoid conflict with v2
 # Depend on unversioned tdewolff/minify until Go modules are supported in Fedora

^ permalink raw reply related	[flat|nested] only message in thread

only message in thread, other threads:[~2026-11-06  5:42 UTC | newest]

Thread overview: (only message) (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2026-11-06  5:42 [rpms/hugo] epel8: Backport fix to image tests on alternate arches Elliott Sales de Andrade

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox