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

libspdm: simplify extern fn type checking #91

Merged
merged 3 commits into from
Jul 24, 2024
Merged

Conversation

twilfredo
Copy link
Collaborator

This builds on #84 to simplify the testing approach used.

alistair23 and others added 3 commits July 19, 2024 09:37
The libspdm version of libspdm_write_certificate_to_nvm() has changed,
the C header is different as is the bindgen Rust code.

The problem is, we don't get an error that our function no longer
matches. For now this is ok, as libspdm only appended arguments, but in
the future this could cause breakages.

There doesn't appear to be any reasonable way to assert that our
function matches the bindgen version. Moving
libspdm_write_certificate_to_nvm() to libspdm_rs.rs for example causes
errors as there are two copies, but that doesn't help us.

The best solution I can think of is to use a test function to check that
the two functions at least have the same function pointer. This is the
equivilent checks that a C compiler would do using function pointers.

This adds the checks for libspdm_write_certificate_to_nvm(), we also
need to do the check for all other functions next.

Signed-off-by: Alistair Francis <[email protected]>
We don't generate errors or warnings if the function signatures we implement
don't match the version in libspdm. So far this has been ok as libspdm only
appended arguments, but in the future this could cause breakages.

There doesn't appear to be any reasonable way to assert that our
function matches the bindgen version.

The best solution I can think of is to use a test function to check that
the two functions at least have the same function pointer. This is the
equivilent checks that a C compiler would do using function pointers.

This patch adds a macro that can generate that function (somewhat manually)
and then uses that macro for all of the `extern "C"` functions.

Signed-off-by: Alistair Francis <[email protected]>
We don't generate errors or warnings if the function signatures we implement
don't match the version in libspdm. So far this has been ok as libspdm only
appended arguments, but in the future this could cause breakages.

There doesn't appear to be any reasonable way to assert that our
function matches the bindgen version.

This patch adds a macro that can compare a provided function type, to
it's bindgen generated type upon expansion. When using this macro, the
first argument shall specify the local type, that is, the type of the
function as defined within `spdm-utils`. Upon expansion, the macro will
type check bindgen generated function against the provided type.

All of this shall run only in a `test` context, with no runtime
overhead. CI should catch any future failures if `libspdm` has changed.

Signed-off-by: Alistair Francis <[email protected]>
Signed-off-by: Wilfred Mallawa <[email protected]>
@alistair23 alistair23 merged commit bf22885 into master Jul 24, 2024
2 checks passed
@alistair23 alistair23 deleted the wilfred/check-args branch July 24, 2024 02:00
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants