summaryrefslogtreecommitdiff
path: root/tests/modules/basics.c
diff options
context:
space:
mode:
authorOran Agra <oran@redislabs.com>2021-11-01 13:41:35 +0200
committerGitHub <noreply@github.com>2021-11-01 13:41:35 +0200
commitf1f3cceb50ac97187f9dca37b041583a5f6ee6aa (patch)
tree552e89e51adfaff8a2b20a0bd96eb3a9722c86bd /tests/modules/basics.c
parent155c29100663c15b26938663aed1405ad3b482cd (diff)
downloadredis-f1f3cceb50ac97187f9dca37b041583a5f6ee6aa.tar.gz
fix valgrind issues with long double module test (#9709)
The module test in reply.tcl was introduced by #8521 but didn't run until recently (see #9639) and then it started failing with valgrind. This is because valgrind uses 64 bit long double (unlike most other platforms that have at least 80 bits) But besides valgrind, the tests where also incompatible with ARM32, which also uses 64 bit long doubles. We now use appropriate value to avoid issues with either valgrind or ARM32 In all the double tests, i use 3.141, which is safe since since addReplyDouble uses `%.17Lg` which is able to represent this value without adding any digits due to precision loss. In the long double, since we use `%.17Lf` in ld2string, it preserves 17 significant digits, rather than 17 digit after the decimal point (like in `%.17Lg`). So to make these similar, i use value lower than 1 (no digits left of the period) Lastly, we have the same issue with TCL (no long doubles) so we read raw protocol in that test. Note that the only error before this fix (in both valgrind and ARM32 is this: ``` *** [err]: RM_ReplyWithLongDouble: a float reply in tests/unit/moduleapi/reply.tcl Expected '3.141' to be equal to '3.14100000000000001' (context: type eval line 2 cmd {assert_equal 3.141 [r rw.longdouble 3.141]} proc ::test) ``` so the changes to debug.c and scripting.tcl aren't really needed, but i consider them a cleanup (i.e. scripting.c validated a different constant than the one that's sent to it from debug.c). Another unrelated change is to add the RESP version to the repeated tests in reply.tcl
Diffstat (limited to 'tests/modules/basics.c')
-rw-r--r--tests/modules/basics.c2
1 files changed, 1 insertions, 1 deletions
diff --git a/tests/modules/basics.c b/tests/modules/basics.c
index e1d2c2115..7f4383759 100644
--- a/tests/modules/basics.c
+++ b/tests/modules/basics.c
@@ -285,7 +285,7 @@ int TestCallResp3Double(RedisModuleCtx *ctx, RedisModuleString **argv, int argc)
/* we compare strings, since comparing doubles directly can fail in various architectures, e.g. 32bit */
char got[30], expected[30];
sprintf(got, "%.17g", d);
- sprintf(expected, "%.17g", 3.14159265359);
+ sprintf(expected, "%.17g", 3.141);
if (strcmp(got, expected) != 0) goto fail;
RedisModule_ReplyWithSimpleString(ctx,"OK");
return REDISMODULE_OK;