From: Zbigniew Jędrzejewski-Szmek Date: Fri, 21 Dec 2018 21:49:53 +0000 (+0100) Subject: test-json: check absolute and relative difference in floating point test X-Git-Tag: archive/raspbian/240-4+rpi1^2~52 X-Git-Url: https://dgit.raspbian.org/?a=commitdiff_plain;h=8613518fa8fd6167d5a62f365c261e7a3fc9fae3;p=systemd.git test-json: check absolute and relative difference in floating point test The test fails under valgrind, so there was an exception for valgrind. Unfortunately that check only works when valgrind-devel headers are available during build. But it is possible to have just valgrind installed, or simply install it after the build, and then "valgrind test-json" would fail. It also seems that even without valgrind, this fails on some arm32 CPUs. Let's do the usual-style test for absolute and relative differences. (cherry picked from commit aa70783f55b369521b94e0985e84bbdaae16b174) (cherry picked from commit 88938bf95b850849d075d7a6ebe37bb1d9780efe) Gbp-Pq: Name test-json-check-absolute-and-relative-difference-in-float.patch --- diff --git a/src/test/test-json.c b/src/test/test-json.c index 5aa4d19d..cd6269f7 100644 --- a/src/test/test-json.c +++ b/src/test/test-json.c @@ -1,9 +1,6 @@ /* SPDX-License-Identifier: LGPL-2.1+ */ #include -#if HAVE_VALGRIND_VALGRIND_H -#include -#endif #include "alloc-util.h" #include "fd-util.h" @@ -45,12 +42,13 @@ static void test_tokenizer(const char *data, ...) { d = va_arg(ap, long double); -#if HAVE_VALGRIND_VALGRIND_H - if (!RUNNING_ON_VALGRIND) -#endif - /* Valgrind doesn't support long double calculations and automatically downgrades to 80bit: - * http://www.valgrind.org/docs/manual/manual-core.html#manual-core.limits */ - assert_se(fabsl(d - v.real) < 0.001L); + /* Valgrind doesn't support long double calculations and automatically downgrades to 80bit: + * http://www.valgrind.org/docs/manual/manual-core.html#manual-core.limits. + * Some architectures might not support long double either. + */ + + assert_se(fabsl(d - v.real) < 1e-10 || + fabsl((d - v.real) / v.real) < 1e-10); } else if (t == JSON_TOKEN_INTEGER) { intmax_t i;