Skip to content

test_pack_unpack_roundtrip_for_nans failing on RISC-V buildbot #133304

Closed

Description

@furkanonder

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

Activity

  1. furkanonder commented on May 2, 2025

    @furkanonder
    ContributorAuthor
  2. self-assigned this
    on May 2, 2025
  3. skirpichev commented on May 2, 2025

    @skirpichev
    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.

  4. skirpichev commented on May 2, 2025

    @skirpichev
    Member

    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().

  5. added a commit that references this issue on May 3, 2025
  6. skirpichev commented on May 3, 2025

    @skirpichev
    Member

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

  7. removed their assignment
    on May 3, 2025
  8. added a commit that references this issue on May 3, 2025
  9. vstinner commented on May 3, 2025

    @vstinner
    Member

    Fixed by f16f06f.

  10. vstinner commented on May 3, 2025

    @vstinner
    Member

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

  11. furkanonder commented on May 5, 2025

    @furkanonder
    ContributorAuthor

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

    You're welcome. Thanks for the merge!

  12. added a commit that references this issue on Jul 12, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    testsTests in the Lib/test dirtopic-C-APItype-bugAn unexpected behavior, bug, or error

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions