What to do when bindgen tests fail


#1

I am trying to use bindgen to create a Rust binding for a C API. There is no control over the C header files, they have to be used as they are.

When I run the tests for the resulting generated FFI code:

failures:

---- bindgen_test_layout_atsc_table_eit_event stdout ----
thread 'bindgen_test_layout_atsc_table_eit_event' panicked at 'assertion failed: `(left == right)`
  left: `88`,
 right: `85`: Size of: atsc_table_eit_event', /home/users/russel/Repositories/Git/Masters/Public/Rust_Libdvbv5_Sys/target/debug/build/libdvbv5-sys-fcc87675c741c51c/out/bindings.rs:3:124592
note: Run with `RUST_BACKTRACE=1` for a backtrace.

---- bindgen_test_layout_atsc_table_eit_event__bindgen_ty_2 stdout ----
thread 'bindgen_test_layout_atsc_table_eit_event__bindgen_ty_2' panicked at 'assertion failed: `(left == right)`
  left: `8`,
 right: `5`: Size of: atsc_table_eit_event__bindgen_ty_2', /home/users/russel/Repositories/Git/Masters/Public/Rust_Libdvbv5_Sys/target/debug/build/libdvbv5-sys-fcc87675c741c51c/out/bindings.rs:3:123893

---- bindgen_test_layout_atsc_table_eit_event__bindgen_ty_2__bindgen_ty_1 stdout ----
thread 'bindgen_test_layout_atsc_table_eit_event__bindgen_ty_2__bindgen_ty_1' panicked at 'assertion failed: `(left == right)`
  left: `8`,
 right: `5`: Size of: atsc_table_eit_event__bindgen_ty_2__bindgen_ty_1', /home/users/russel/Repositories/Git/Masters/Public/Rust_Libdvbv5_Sys/target/debug/build/libdvbv5-sys-fcc87675c741c51c/out/bindings.rs:3:121189

---- bindgen_test_layout_max_align_t stdout ----
thread 'bindgen_test_layout_max_align_t' panicked at 'assertion failed: `(left == right)`
  left: `24`,
 right: `32`: Size of: max_align_t', /home/users/russel/Repositories/Git/Masters/Public/Rust_Libdvbv5_Sys/target/debug/build/libdvbv5-sys-fcc87675c741c51c/out/bindings.rs:3:459830


failures:
    bindgen_test_layout_atsc_table_eit_event
    bindgen_test_layout_atsc_table_eit_event__bindgen_ty_2
    bindgen_test_layout_atsc_table_eit_event__bindgen_ty_2__bindgen_ty_1
    bindgen_test_layout_max_align_t

test result: FAILED. 244 passed; 4 failed; 0 ignored; 0 measured; 0 filtered out

Does anyone have any advice as to how to deal with these sorts of errors?


#2

The usual cause of mismatch is generating bindings on 64-bit platform and using them on 32-bit platform.

In that case you can often just ignore the tests (delete them), because rustc will adjust the structs because they are repr(c).

Otherwise investigate what bindgen got wrong and file bugs. You may need to generate bindings to a file and manually fix them.


#3

This is definitely building and using on 64-bit Linux. I believe the test fails do not affect me just now as I amnot using the bits the tests fail on, but the tests need to pass for a publishing of the crate.

I’ll try to do a minimal build showing each fail and send them in a bug report on the bindgen repository issues. Sadly this is not as easy as it sounds as the C header files for this API have massive inter-connection via #include :frowning:


#4

The fun of being inclusive :smirk: