From 9cd5292e1862d3b2d6a4955f908501c41d20cc59 Mon Sep 17 00:00:00 2001 From: William Brown Date: May 31 2017 01:22:03 +0000 Subject: Ticket 49268 - master branch fails on big endian systems Bug Description: We had a number of tests that did not function on a bigendian system, or a system with different pagesizes Fix Description: Correct the tests to set the page size to a known value. Fix the hashtest to use correct endianness for inputs. https://pagure.io/389-ds-base/issue/49268 Author: wibrown Review by: mreynolds, lslebodn (Thanks!) --- diff --git a/configure.ac b/configure.ac index ce1589c..03c1eea 100644 --- a/configure.ac +++ b/configure.ac @@ -39,7 +39,7 @@ AC_PROG_LIBTOOL AC_HEADER_DIRENT AC_HEADER_STDC AC_HEADER_SYS_WAIT -AC_CHECK_HEADERS([arpa/inet.h errno.h fcntl.h malloc.h netdb.h netinet/in.h stdlib.h string.h strings.h sys/file.h sys/socket.h sys/time.h syslog.h unistd.h mntent.h sys/sysinfo.h]) +AC_CHECK_HEADERS([arpa/inet.h errno.h fcntl.h malloc.h netdb.h netinet/in.h stdlib.h string.h strings.h sys/file.h sys/socket.h sys/time.h syslog.h unistd.h mntent.h sys/sysinfo.h sys/endian.h endian.h]) # These are *required* headers without option. AC_CHECK_HEADERS([inttypes.h], [], AC_MSG_ERROR([unable to locate required header inttypes.h])) diff --git a/src/libsds/external/csiphash/csiphash.c b/src/libsds/external/csiphash/csiphash.c index 60066f9..d7a3c94 100644 --- a/src/libsds/external/csiphash/csiphash.c +++ b/src/libsds/external/csiphash/csiphash.c @@ -32,31 +32,21 @@ #include #include /* for size_t */ -#if defined(__BYTE_ORDER__) && defined(__ORDER_LITTLE_ENDIAN__) && \ - __BYTE_ORDER__ == __ORDER_LITTLE_ENDIAN__ -# define _le64toh(x) ((uint64_t)(x)) -#elif defined(_WIN32) -/* Windows is always little endian, unless you're on xbox360 - http://msdn.microsoft.com/en-us/library/b0084kay(v=vs.80).aspx */ -# define _le64toh(x) ((uint64_t)(x)) -#elif defined(__APPLE__) -# include -# define _le64toh(x) OSSwapLittleToHostInt64(x) +#include + +#if defined(HAVE_SYS_ENDIAN_H) +# include +#elif defined(HAVE_ENDIAN_H) +# include #else +# error platform header for endian detection not found. +#endif /* See: http://sourceforge.net/p/predef/wiki/Endianness/ */ -# if defined(__FreeBSD__) || defined(__NetBSD__) || defined(__OpenBSD__) -# include -# else -# include -# endif -# if defined(__BYTE_ORDER) && defined(__LITTLE_ENDIAN) && \ - __BYTE_ORDER == __LITTLE_ENDIAN -# define _le64toh(x) ((uint64_t)(x)) -# else -# define _le64toh(x) le64toh(x) -# endif - +#if defined(__BYTE_ORDER) && defined(__LITTLE_ENDIAN) && __BYTE_ORDER == __LITTLE_ENDIAN +# define _le64toh(x) ((uint64_t)(x)) +#else +# define _le64toh(x) le64toh(x) #endif diff --git a/src/libsds/test/test_sds_csiphash.c b/src/libsds/test/test_sds_csiphash.c index 2973504..6e0a662 100644 --- a/src/libsds/test/test_sds_csiphash.c +++ b/src/libsds/test/test_sds_csiphash.c @@ -14,6 +14,14 @@ #include "test_sds.h" +#if defined(HAVE_SYS_ENDIAN_H) +# include +#elif defined(HAVE_ENDIAN_H) +# include +#else +# error platform header for endian detection not found. +#endif + static void test_siphash(void **state __attribute__((unused))) { @@ -26,7 +34,7 @@ test_siphash(void **state __attribute__((unused))) { uint64_t test_b = 13042610424265326907U; // Initial simple test - value = 5; + value = htole64(5); hashout = sds_siphash13(&value, sizeof(uint64_t), key); assert_true(hashout == test_a); diff --git a/test/libslapd/spal/meminfo.c b/test/libslapd/spal/meminfo.c index 776141a..ff82826 100644 --- a/test/libslapd/spal/meminfo.c +++ b/test/libslapd/spal/meminfo.c @@ -33,6 +33,11 @@ test_libslapd_util_cachesane(void **state __attribute__((unused))) { slapi_pal_meminfo *mi = spal_meminfo_get(); uint64_t request = 0; mi->system_available_bytes = 0; + /* + * PPC 64 has a large page size, so we trigger the 16 page min. + * As a result, we set the pagesize to 4k just for this test. + */ + mi->pagesize_bytes = 4096; assert_true(util_is_cachesize_sane(mi, &request) == UTIL_CACHESIZE_ERROR); // Set the values to known quantities @@ -47,6 +52,16 @@ test_libslapd_util_cachesane(void **state __attribute__((unused))) { assert_true(util_is_cachesize_sane(mi, &request) == UTIL_CACHESIZE_REDUCED); assert_true(request <= 75000); + /* + * we need to test the minimum reduction function. We make a request that gets + * reduced, but falls under the threshold of 16 * page. So we expect the result + * to be 16 * pagesize. + */ + mi->system_available_bytes = 65536; + request = 65537; + assert_true(util_is_cachesize_sane(mi, &request) == UTIL_CACHESIZE_REDUCED); + assert_true(request == (16 * mi->pagesize_bytes)); + spal_meminfo_destroy(mi); }