|
Zbigniew Jędrzejewski-Szmek |
b80d66 |
From 847364f5123f108884f8c59fb05d7ff941693dfb Mon Sep 17 00:00:00 2001
|
|
Zbigniew Jędrzejewski-Szmek |
4100d9 |
From: =?UTF-8?q?Zbigniew=20J=C4=99drzejewski-Szmek?= <zbyszek@in.waw.pl>
|
|
Zbigniew Jędrzejewski-Szmek |
4100d9 |
Date: Fri, 21 Dec 2018 22:49:53 +0100
|
|
Zbigniew Jędrzejewski-Szmek |
4100d9 |
Subject: [PATCH] test-json: check absolute and relative difference in floating
|
|
Zbigniew Jędrzejewski-Szmek |
4100d9 |
point test
|
|
Zbigniew Jędrzejewski-Szmek |
4100d9 |
|
|
Zbigniew Jędrzejewski-Szmek |
4100d9 |
The test fails under valgrind, so there was an exception for valgrind.
|
|
Zbigniew Jędrzejewski-Szmek |
4100d9 |
Unfortunately that check only works when valgrind-devel headers are
|
|
Zbigniew Jędrzejewski-Szmek |
4100d9 |
available during build. But it is possible to have just valgrind installed,
|
|
Zbigniew Jędrzejewski-Szmek |
4100d9 |
or simply install it after the build, and then "valgrind test-json" would
|
|
Zbigniew Jędrzejewski-Szmek |
4100d9 |
fail.
|
|
Zbigniew Jędrzejewski-Szmek |
4100d9 |
|
|
Zbigniew Jędrzejewski-Szmek |
4100d9 |
It also seems that even without valgrind, this fails on some arm32 CPUs.
|
|
Zbigniew Jędrzejewski-Szmek |
4100d9 |
Let's do the usual-style test for absolute and relative differences.
|
|
Zbigniew Jędrzejewski-Szmek |
4100d9 |
---
|
|
Zbigniew Jędrzejewski-Szmek |
4100d9 |
src/test/test-json.c | 16 +++++++---------
|
|
Zbigniew Jędrzejewski-Szmek |
4100d9 |
1 file changed, 7 insertions(+), 9 deletions(-)
|
|
Zbigniew Jędrzejewski-Szmek |
4100d9 |
|
|
Zbigniew Jędrzejewski-Szmek |
4100d9 |
diff --git a/src/test/test-json.c b/src/test/test-json.c
|
|
Zbigniew Jędrzejewski-Szmek |
b80d66 |
index 5aa4d19dbe..cd6269f798 100644
|
|
Zbigniew Jędrzejewski-Szmek |
4100d9 |
--- a/src/test/test-json.c
|
|
Zbigniew Jędrzejewski-Szmek |
4100d9 |
+++ b/src/test/test-json.c
|
|
Zbigniew Jędrzejewski-Szmek |
4100d9 |
@@ -1,9 +1,6 @@
|
|
Zbigniew Jędrzejewski-Szmek |
4100d9 |
/* SPDX-License-Identifier: LGPL-2.1+ */
|
|
Zbigniew Jędrzejewski-Szmek |
4100d9 |
|
|
Zbigniew Jędrzejewski-Szmek |
4100d9 |
#include <math.h>
|
|
Zbigniew Jędrzejewski-Szmek |
4100d9 |
-#if HAVE_VALGRIND_VALGRIND_H
|
|
Zbigniew Jędrzejewski-Szmek |
4100d9 |
-#include <valgrind/valgrind.h>
|
|
Zbigniew Jędrzejewski-Szmek |
4100d9 |
-#endif
|
|
Zbigniew Jędrzejewski-Szmek |
4100d9 |
|
|
Zbigniew Jędrzejewski-Szmek |
4100d9 |
#include "alloc-util.h"
|
|
Zbigniew Jędrzejewski-Szmek |
4100d9 |
#include "fd-util.h"
|
|
Zbigniew Jędrzejewski-Szmek |
4100d9 |
@@ -45,12 +42,13 @@ static void test_tokenizer(const char *data, ...) {
|
|
Zbigniew Jędrzejewski-Szmek |
4100d9 |
|
|
Zbigniew Jędrzejewski-Szmek |
4100d9 |
d = va_arg(ap, long double);
|
|
Zbigniew Jędrzejewski-Szmek |
4100d9 |
|
|
Zbigniew Jędrzejewski-Szmek |
4100d9 |
-#if HAVE_VALGRIND_VALGRIND_H
|
|
Zbigniew Jędrzejewski-Szmek |
4100d9 |
- if (!RUNNING_ON_VALGRIND)
|
|
Zbigniew Jędrzejewski-Szmek |
4100d9 |
-#endif
|
|
Zbigniew Jędrzejewski-Szmek |
4100d9 |
- /* Valgrind doesn't support long double calculations and automatically downgrades to 80bit:
|
|
Zbigniew Jędrzejewski-Szmek |
4100d9 |
- * http://www.valgrind.org/docs/manual/manual-core.html#manual-core.limits */
|
|
Zbigniew Jędrzejewski-Szmek |
4100d9 |
- assert_se(fabsl(d - v.real) < 0.001L);
|
|
Zbigniew Jędrzejewski-Szmek |
4100d9 |
+ /* Valgrind doesn't support long double calculations and automatically downgrades to 80bit:
|
|
Zbigniew Jędrzejewski-Szmek |
4100d9 |
+ * http://www.valgrind.org/docs/manual/manual-core.html#manual-core.limits.
|
|
Zbigniew Jędrzejewski-Szmek |
b80d66 |
+ * Some architectures might not support long double either.
|
|
Zbigniew Jędrzejewski-Szmek |
4100d9 |
+ */
|
|
Zbigniew Jędrzejewski-Szmek |
4100d9 |
+
|
|
Zbigniew Jędrzejewski-Szmek |
b80d66 |
+ assert_se(fabsl(d - v.real) < 1e-10 ||
|
|
Zbigniew Jędrzejewski-Szmek |
b80d66 |
+ fabsl((d - v.real) / v.real) < 1e-10);
|
|
Zbigniew Jędrzejewski-Szmek |
4100d9 |
|
|
Zbigniew Jędrzejewski-Szmek |
4100d9 |
} else if (t == JSON_TOKEN_INTEGER) {
|
|
Zbigniew Jędrzejewski-Szmek |
4100d9 |
intmax_t i;
|
|
Zbigniew Jędrzejewski-Szmek |
4100d9 |
--
|
|
Zbigniew Jędrzejewski-Szmek |
4100d9 |
2.19.2
|
|
Zbigniew Jędrzejewski-Szmek |
4100d9 |
|