Skip to content

ctest: add suport for C enum #4658

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

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open

Conversation

mbyx
Copy link
Contributor

@mbyx mbyx commented Aug 15, 2025

Description

Adds the ability to specify whether a type alias and a set of constants that use that type alias maps to a C enum, as well as the ability to skip them.

Sources

Checklist

  • Relevant tests in libc-test/semver have been updated
  • No placeholder or unstable values like *LAST or *MAX are
    included (see #3131)
  • Tested locally (cd libc-test && cargo test --target mytarget);
    especially relevant for platforms that may not be checked in CI

@rustbot rustbot added ctest Issues relating to the ctest crate S-waiting-on-review labels Aug 15, 2025
@mbyx
Copy link
Contributor Author

mbyx commented Aug 15, 2025

The signededness of a C enum is implementation defined, so should that test be skipped for all C enums?

/// let mut cfg = TestGenerator::new();
/// cfg.c_enum(|e| e == "pid_type");
/// ```
pub fn c_enum(&mut self, f: impl Fn(&str) -> bool + 'static) -> &mut Self {
Copy link
Contributor

@tgross35 tgross35 Aug 15, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Could this take &Type rather than &str? To match rename_alias.

Maybe the name alias_is_c_enum would be a bit more descriptive, there are a handful of ways to represent C enums https://mdaverde.com/posts/rust-bindgen-enum/

@tgross35
Copy link
Contributor

The signededness of a C enum is implementation defined, so should that test be skipped for all C enums?

repr(C) should generally match. I know there might be some problems with that, but have you run into any here?

Could you add a test in ctest-test to ensure this catches incorrect item values and things like the wrong repr type?

@mbyx
Copy link
Contributor Author

mbyx commented Aug 15, 2025

If I use an unsigned type in simple.h for the enum, it fails on the signededness test on windows. If I use a signed type it fails on linux. This isn't really a problem in the actual ports because the windows port doesn't use enums, but these integration tests are run on all platforms.

@tgross35
Copy link
Contributor

I think that's actually an important catch; the fallback here

(@ty) => { $crate::c_uint };
should probably be updated so the type is signed on Windows.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
ctest Issues relating to the ctest crate S-waiting-on-review
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants