zimg/zimg-s390x-unit-tests.patch

61 lines
1.6 KiB
Diff

From b2bee8460a0f6ecf049e27d0a2090c87e871d951 Mon Sep 17 00:00:00 2001
From: Mike Gorse <mgorse@suse.com>
Date: Wed, 22 Sep 2021 11:57:47 -0500
Subject: [PATCH] FIx unit tests on big endian systems
---
test/extra/sha1/config.h | 6 ++++++
test/graph/filter_validator.cpp | 8 ++++++++
2 files changed, 14 insertions(+)
diff --git a/test/extra/sha1/config.h b/test/extra/sha1/config.h
index ea853f0..7bc4e00 100644
--- a/test/extra/sha1/config.h
+++ b/test/extra/sha1/config.h
@@ -1,3 +1,5 @@
+#include <endian.h>
+
#ifndef LITTLE_ENDIAN
#define LITTLE_ENDIAN 4321
#endif
@@ -7,5 +9,9 @@
#endif
#ifndef BYTE_ORDER
+#if defined(__BYTE_ORDER) && (__BYTE_ORDER == __BIG_ENDIAN)
+ #define BYTE_ORDER BIG_ENDIAN
+#else
#define BYTE_ORDER LITTLE_ENDIAN
#endif
+#endif
diff --git a/test/graph/filter_validator.cpp b/test/graph/filter_validator.cpp
index f0d6859..d768ebf 100644
--- a/test/graph/filter_validator.cpp
+++ b/test/graph/filter_validator.cpp
@@ -13,6 +13,8 @@
#include "gtest/gtest.h"
+#include <endian.h>
+
extern "C" {
#include "sha1/sha1.h"
}
@@ -40,7 +42,13 @@ void hash_buffer(const AuditBuffer<T> &buf, unsigned p, unsigned width, unsigned
for (unsigned i = 0; i < height; ++i) {
const unsigned char *ptr = static_cast<const unsigned char *>(image_buffer[p][i]);
+#if (__BYTE_ORDER == __LITTLE_ENDIAN)
SHA1Update(&sha_ctx, ptr, width * sizeof(T));
+#else
+ for (unsigned j = 0; j < width; j++)
+ for (int k = sizeof(T) - 1; k >= 0; k--)
+ SHA1Update(&sha_ctx, ptr + (j * sizeof(T)) + k, 1);
+#endif
}
SHA1Final(digest, &sha_ctx);
--
2.32.0