Skip to content

test_pack_unpack_roundtrip_for_nans failing on RISC-V buildbot #133304

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
furkanonder opened this issue May 2, 2025 · 6 comments
Closed

test_pack_unpack_roundtrip_for_nans failing on RISC-V buildbot #133304

furkanonder opened this issue May 2, 2025 · 6 comments
Labels
tests Tests in the Lib/test dir topic-C-API type-bug An unexpected behavior, bug, or error

Comments

@furkanonder
Copy link
Contributor

furkanonder commented May 2, 2025

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

@furkanonder furkanonder added tests Tests in the Lib/test dir topic-C-API type-bug An unexpected behavior, bug, or error labels May 2, 2025
@furkanonder
Copy link
Contributor Author

bisect to 6157135

CC: @skirpichev @vstinner

@skirpichev skirpichev self-assigned this May 2, 2025
@skirpichev
Copy link
Member

An example:

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'

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
Copy link
Member

skirpichev commented 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 x after L2188 in PyFloat_Pack4().

@skirpichev
Copy link
Member

PR is ready: #133328 (implements option (2) workaround).

@vstinner
Copy link
Member

vstinner commented May 3, 2025

Fixed by f16f06f.

@vstinner vstinner closed this as completed May 3, 2025
@vstinner
Copy link
Member

vstinner commented May 3, 2025

Thanks @furkanonder for the report and thanks @skirpichev for the fix!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
tests Tests in the Lib/test dir topic-C-API type-bug An unexpected behavior, bug, or error
Projects
None yet
Development

No branches or pull requests

3 participants