Repository navigation
test_pack_unpack_roundtrip_for_nans failing on RISC-V buildbot #133304
Copy link
Copy link
Closed
Labels
testsTests in the Lib/test dirTests in the Lib/test dirtopic-C-APItype-bugAn unexpected behavior, bug, or errorAn unexpected behavior, bug, or error
Description
Bug report
Bug description:
The test_capi module's test_float are failing on RISC-V build bot
======================================================================
FAIL: test_pack_unpack_roundtrip_for_nans (test.test_capi.test_float.CAPIFloatTest.test_pack_unpack_roundtrip_for_nans) (data=b'\x7f\x93\x16\x02', size=4, endian=0)
----------------------------------------------------------------------
Traceback (most recent call last):
File "/home/ubuntu/buildarea/3.x.onder-riscv64.installed/build/target/lib/python3.14/test/test_capi/test_float.py", line 216, in test_pack_unpack_roundtrip_for_nans
self.assertTrue(math.isnan(value))
~~~~~~~~~~~~~~~^^^^^^^^^^^^^^^^^^^
AssertionError: False is not true
======================================================================
FAIL: test_pack_unpack_roundtrip_for_nans (test.test_capi.test_float.CAPIFloatTest.test_pack_unpack_roundtrip_for_nans) (data=b'\x7f\x93\x16\x02', size=4, endian=1)
----------------------------------------------------------------------
Traceback (most recent call last):
File "/home/ubuntu/buildarea/3.x.onder-riscv64.installed/build/target/lib/python3.14/test/test_capi/test_float.py", line 216, in test_pack_unpack_roundtrip_for_nans
self.assertTrue(math.isnan(value))
~~~~~~~~~~~~~~~^^^^^^^^^^^^^^^^^^^
AssertionError: False is not true
======================================================================
FAIL: test_pack_unpack_roundtrip_for_nans (test.test_capi.test_float.CAPIFloatTest.test_pack_unpack_roundtrip_for_nans) (data=b'\xff\xd5n\x92', size=4, endian=0)
----------------------------------------------------------------------
Traceback (most recent call last):
File "/home/ubuntu/buildarea/3.x.onder-riscv64.installed/build/target/lib/python3.14/test/test_capi/test_float.py", line 217, in test_pack_unpack_roundtrip_for_nans
self.assertEqual(data1, data2)
~~~~~~~~~~~~~~~~^^^^^^^^^^^^^^
AssertionError: b'\xff\xd5n\x92' != b'\x7f\xc0\x00\x00'
======================================================================
FAIL: test_pack_unpack_roundtrip_for_nans (test.test_capi.test_float.CAPIFloatTest.test_pack_unpack_roundtrip_for_nans) (data=b'\xff\xd5n\x92', size=4, endian=1)
----------------------------------------------------------------------
Traceback (most recent call last):
File "/home/ubuntu/buildarea/3.x.onder-riscv64.installed/build/target/lib/python3.14/test/test_capi/test_float.py", line 217, in test_pack_unpack_roundtrip_for_nans
self.assertEqual(data1, data2)
~~~~~~~~~~~~~~~~^^^^^^^^^^^^^^
AssertionError: b'\x92n\xd5\xff' != b'\x00\x00\xc0\x7f'
======================================================================
FAIL: test_pack_unpack_roundtrip_for_nans (test.test_capi.test_float.CAPIFloatTest.test_pack_unpack_roundtrip_for_nans) (data=b'\xff\x94\x9e\x8f', size=4, endian=0)
----------------------------------------------------------------------
Traceback (most recent call last):
File "/home/ubuntu/buildarea/3.x.onder-riscv64.installed/build/target/lib/python3.14/test/test_capi/test_float.py", line 216, in test_pack_unpack_roundtrip_for_nans
self.assertTrue(math.isnan(value))
~~~~~~~~~~~~~~~^^^^^^^^^^^^^^^^^^^
AssertionError: False is not true
======================================================================CPython versions tested on:
CPython main branch
Operating systems tested on:
Linux
Linked PRs
Reactions are currently unavailable
Metadata
Metadata
Assignees
Labels
testsTests in the Lib/test dirTests in the Lib/test dirtopic-C-APItype-bugAn unexpected behavior, bug, or errorAn unexpected behavior, bug, or error
Activity
furkanonder commentedon May 2, 2025
bisect to 6157135
CC: @skirpichev @vstinner
skirpichev commentedon May 2, 2025
An example:
Here lost all payload of quiet nan together with a sign bit. For signaling nan - lost payload means it's not a nan anymore, that explains
math.isnan()'s failures.Seems to be a platform bug, which reveal new patch. I suspect bad things happens in the PyFloat_Unpack4(), after we return
float x.skirpichev commentedon May 2, 2025
Ok, indeed the culpit is "If a NaN value is converted to a different floating-point type, the result is the canonical NaN of the new type" from RISC-V spec. (also: "The canonical NaN has a positive sign and all significand bits clear except the MSB, a.k.a. the quiet bit.") N.B. we unset MSB bit (after L2188) for signaling nans - making a positive infinities for risc-v...
I see following options: 1) filter out this non-IEEE platform in this test (not sure how to do this properly), 2) copy sign bit & payload from
xafter L2188 in PyFloat_Pack4().pythongh-133304: workaround for RISC-V in PyFloat_Pack4()
skirpichev commentedon May 3, 2025
PR is ready: #133328 (implements option (2) workaround).
gh-133304: workaround for RISC-V in PyFloat_Pack4/Unpack4() (#133328)
vstinner commentedon May 3, 2025
Fixed by f16f06f.
vstinner commentedon May 3, 2025
Thanks @furkanonder for the report and thanks @skirpichev for the fix!
furkanonder commentedon May 5, 2025
You're welcome. Thanks for the merge!
pythongh-133304: workaround for RISC-V in PyFloat_Pack4/Unpack4() (py…