From 5b616db96266d25cb0749e472cfc78c4944675e2 Mon Sep 17 00:00:00 2001 From: Simon Marchi Date: Wed, 15 Mar 2023 15:44:02 -0400 Subject: [PATCH] Fix: tests: print real values in a fixed format The cli_params_to_string.to_string function converts float values (bt2._RealValueConst) to string using the str function. The format of that seems to differ across platform. On a 32-bit powerpcspe platform, we see this failure in the cli/params/test_params test: -{a=10500000.0, b=10500000.0, c=1.05e-05, d=1.05e-05} +{a=10500000.0, b=10500000.0, c=1.0499999999999999e-05, d=1.0499999999999999e-05} Fix that by doing an explicit string conversion for _RealValueConst objects, with a constant 7 decimal places after the decimal point. The 7 is chosen so that the numbers in tests in cli/params/test_params are not truncated. Change-Id: Ie4fcb8eb422c3d44eeec1201169dc8a995536d4a Signed-off-by: Simon Marchi Reviewed-on: https://review.lttng.org/c/babeltrace/+/9651 Reviewed-by: Michael Jeanson Reviewed-by: Philippe Proulx Tested-by: jenkins --- tests/cli/params/test_params | 4 ++-- tests/utils/python/cli_params_to_string.py | 3 ++- 2 files changed, 4 insertions(+), 3 deletions(-) diff --git a/tests/cli/params/test_params b/tests/cli/params/test_params index c207532a..22ef5401 100755 --- a/tests/cli/params/test_params +++ b/tests/cli/params/test_params @@ -50,9 +50,9 @@ expect_success 'unsigned integer' 'a=+0b110, b=+022, c=+22, d=+0x22' \ expect_success 'string' 'a="avril lavigne", b=patata, c="This\"is\\escaped"' \ '{a=avril lavigne, b=patata, c=This"is\escaped}' expect_success 'float' 'a=1.234, b=17., c=.28, d=-18.28' \ - '{a=1.234, b=17.0, c=0.28, d=-18.28}' + '{a=1.2340000, b=17.0000000, c=0.2800000, d=-18.2800000}' expect_success 'float scientific notation' 'a=10.5e6, b=10.5E6, c=10.5e-6, d=10.5E-6' \ - '{a=10500000.0, b=10500000.0, c=1.05e-05, d=1.05e-05}' + '{a=10500000.0000000, b=10500000.0000000, c=0.0000105, d=0.0000105}' expect_success 'array' 'a=[1, [["hi",]]]' \ '{a=[1, [[hi]]]}' expect_success 'map' 'a=4,a={},b={salut="la gang",comment="ca va",oh={x=2}}' \ diff --git a/tests/utils/python/cli_params_to_string.py b/tests/utils/python/cli_params_to_string.py index 90d61ffd..4ff24987 100644 --- a/tests/utils/python/cli_params_to_string.py +++ b/tests/utils/python/cli_params_to_string.py @@ -19,12 +19,13 @@ def to_string(p): ) elif type(p) is bt2._UnsignedIntegerValueConst: s = str(p) + "u" + elif type(p) is bt2._RealValueConst: + s = "{:.7f}".format(float(p)) elif ( type(p) in ( bt2._StringValueConst, bt2._SignedIntegerValueConst, - bt2._RealValueConst, bt2._BoolValueConst, ) or p is None -- 2.34.1