Skip to content
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

Quickcheck falsifying example dump falls over for enums #1712

Open
mikex-oss opened this issue Nov 14, 2024 · 0 comments
Open

Quickcheck falsifying example dump falls over for enums #1712

mikex-oss opened this issue Nov 14, 2024 · 0 comments
Labels
bug Something isn't working or is incorrect dslx DSLX (domain specific language) implementation / front-end

Comments

@mikex-oss
Copy link
Collaborator

mikex-oss commented Nov 14, 2024

Describe the bug
If the input argument is an enum, then when the falsifying example is reported, it segfaults on ValueToInterpValue

[ RUN QUICKCHECK        ] blue_is_always_favorite count: 1000
*** SIGSEGV (@0x8), ... received by PID 929 (TID 929) on cpu 29; stack trace: ***
PC: @     0x5570f910052d  (unknown)  xls::dslx::ValueToInterpValue()
    @     0x5570fc25f021       1888  FailureSignalHandler()
    @     0x7fc603949e80  (unknown)  (unknown)
    @     0x5570f910052d        368  xls::dslx::ValueToInterpValue()
    @     0x5570f8fbd40b       2096  xls::dslx::AbstractTestRunner::ParseAndTest()
    @     0x5570f8f85cd9       1232  main
    @     0x7fc6037da3d4        192  __libc_start_main
    @     0x5570f8f8402a  (unknown)  _start
E1113 19:29:42.758104     929 process_state.cc:806] RAW: Raising signal 11 with default behavior

To Reproduce
Steps to reproduce the behavior:

enum Color : u2 {
    White = u2:0,
    Red = u2:1,
    Green = u2:2,
    Blue = u2:3,
}

fn favorite_color(color: Color) -> Color { Color::Blue }

#[quickcheck]
fn blue_is_always_favorite(color: Color) -> bool { favorite_color(color) == Color::White }

Expected behavior
The quickcheck should properly report the falsifying sample when found.

As a workaround, you can use u2 as the input type for the quickcheck arg, and then cast to the enum, i.e.

enum Color : u2 {
    White = u2:0,
    Red = u2:1,
    Green = u2:2,
    Blue = u2:3,
}

fn favorite_color(color: Color) -> Color { Color::Blue }

#[quickcheck]
fn blue_is_always_favorite(color: u2) -> bool { favorite_color(color as Color) == Color::White }

will properly report:

FailureError: The program being interpreted failed! Found falsifying example after 1 tests: [u2:2]

@mikex-oss mikex-oss added bug Something isn't working or is incorrect dslx DSLX (domain specific language) implementation / front-end labels Nov 14, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working or is incorrect dslx DSLX (domain specific language) implementation / front-end
Projects
Status: No status
Development

No branches or pull requests

1 participant