Skip to content

ctest-next: miscellaneous filtering bug fixes #4613

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

Merged
merged 1 commit into from
Aug 11, 2025

Conversation

mbyx
Copy link
Contributor

@mbyx mbyx commented Aug 3, 2025

Description

Prepares for porting libc-test platforms to use ctest-next by fixing numerous bugs. #4600 and #4610 both depend on this PR, so this should be merged first.

Fixes:

  • Excludes libc-test from MSRV checks since it will use ctest-next in the future, which is a edition 2024 crate.
  • Modify translate_expr to support translating [ty; 3usize] properly.
  • Adds a new test that for now always passes, but will be gradually used as the test for ctest-next backed platforms.
  • Moves filtering ffi_items to the TranslateHelper since template.rs does the test filtering for consistency.
  • Fixes a bug where unions were not being skipped properly.
  • Fixes a bug where structs that were skipped for testing were not recognized as structs when testing a different item with that same struct as a field that shouldn't be skipped.
  • A bug where sometimes pointers to structs would be translated as struct const StructName*, and sometimes the struct label would not be applied at all.

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 A-CI Area: CI-related items ctest Issues relating to the ctest crate labels Aug 3, 2025
@mbyx mbyx force-pushed the ctest-next-bug-fix branch 3 times, most recently from 51cf365 to d1382d3 Compare August 3, 2025 13:18
@mbyx mbyx marked this pull request as ready for review August 3, 2025 13:26
@mbyx mbyx force-pushed the ctest-next-bug-fix branch 3 times, most recently from 9d9d43f to e96f64c Compare August 3, 2025 14:21
Comment on lines +483 to 537
filtered_ffi_items: FfiItems,
ffi_items: &'a FfiItems,
Copy link
Contributor

Choose a reason for hiding this comment

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

Does this need to keep the unfiltered ffi_items at all anymore? It seems cleaner to only keep the filtered items here, if possible.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

It's to fix one of the bugs, if say a struct T1Bar is skipped for testing it won't be in filtered_ffi_items, but if some other test for a different struct returns a *const T1Bar, then it would fail to realize that T1Bar is a struct, since originally we were using the filtered_ffi_items in c_type.

@mbyx mbyx force-pushed the ctest-next-bug-fix branch 2 times, most recently from 38c56f1 to a0c27ab Compare August 7, 2025 07:32
@mbyx mbyx requested a review from tgross35 August 7, 2025 07:42
Copy link
Contributor

@tgross35 tgross35 left a comment

Choose a reason for hiding this comment

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

For the tests I left a few comments at #4600 (comment) before realizing they were part of this PR, could you apply them here?

Comment on lines 521 to 578
let skipped: Vec<_> = self
.filtered_ffi_items
.$field
.extract_if(.., |item| {
self.generator
.skips
.iter()
.any(|f| f(&MapInput::$variant(item)))
|| (self.generator.skip_private && !item.public)
})
.collect();
if verbose {
skipped
.iter()
.for_each(|item| eprintln!("Skipping {} \"{}\"", $label, item.ident()));
}
Copy link
Contributor

Choose a reason for hiding this comment

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

No need to collect to an intermediate Vec:

let skipped = self
    .filtered_ffi_items
    // ...
    .extract_if(/* ... */);
for item in skipped {
    if verbose {
        eprintln!("...");
    }
}

Also, put the self.generator.skip_private && !item.public check before checking self.generator.skips, so it doesn't need to test all the skips if there is an easy return.

Comment on lines 565 to 610
// For structs/unions/aliases, their type is the same as their identifier.
MapInput::Alias(a) => (a.ident(), cdecl::named(a.ident(), cdecl::Constness::Mut)),
MapInput::Struct(s) => (s.ident(), cdecl::named(s.ident(), cdecl::Constness::Mut)),
MapInput::Union(u) => (u.ident(), cdecl::named(u.ident(), cdecl::Constness::Mut)),
// FIXME(ctest): For some specific primitives such as c_uint, they don't exist on the
// C side and have to be manually translated. If they are removed to use `std::ffi`,
// then this becomes unneeded (although it won't break).
MapInput::Alias(a) => (a.ident(), cdecl::named(a.ident(), Constness::Mut)),
MapInput::Struct(s) => (s.ident(), cdecl::named(s.ident(), Constness::Mut)),
MapInput::Union(u) => (u.ident(), cdecl::named(u.ident(), Constness::Mut)),
Copy link
Contributor

Choose a reason for hiding this comment

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

What is the FIXME here? This part doesn't have to do with primitives.

Comment on lines 366 to 384
// This is done to deal with things like 3usize.
syn::Expr::Index(i) => {
let base = translate_expr(&i.expr);
let index = translate_expr(&i.index);
format!("{base}[{index}]")
}
syn::Expr::Lit(l) => match &l.lit {
syn::Lit::Int(i) => i.base10_digits().to_string(),
_ => l.to_token_stream().to_string(),
},
Copy link
Contributor

Choose a reason for hiding this comment

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

Is that comment above the right block? For the integer parts, you can turn e.g. 3usize into ((size_t)(3)) to keep the type around.

Could you make sure this is tested in ctest-next/src/tests.rs?

Copy link
Contributor

@tgross35 tgross35 left a comment

Choose a reason for hiding this comment

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

(updating the status)

@mbyx mbyx force-pushed the ctest-next-bug-fix branch from a0c27ab to 0bf97d4 Compare August 11, 2025 09:25
@mbyx mbyx requested a review from tgross35 August 11, 2025 09:45
Copy link
Contributor

@tgross35 tgross35 left a comment

Choose a reason for hiding this comment

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

Looks great, thank you for including a test for the indexing bit!

@mbyx mbyx force-pushed the ctest-next-bug-fix branch from 0bf97d4 to 2cc9412 Compare August 11, 2025 12:21
@tgross35 tgross35 force-pushed the ctest-next-bug-fix branch from 2cc9412 to d325012 Compare August 11, 2025 16:12
@tgross35 tgross35 enabled auto-merge August 11, 2025 16:13
@tgross35 tgross35 added this pull request to the merge queue Aug 11, 2025
@github-merge-queue github-merge-queue bot removed this pull request from the merge queue due to a conflict with the base branch Aug 11, 2025
@mbyx mbyx force-pushed the ctest-next-bug-fix branch from d325012 to 6b304ae Compare August 11, 2025 18:30
@mbyx mbyx requested a review from tgross35 August 11, 2025 18:37
@tgross35 tgross35 enabled auto-merge August 11, 2025 20:05
@tgross35 tgross35 added this pull request to the merge queue Aug 11, 2025
Merged via the queue into rust-lang:main with commit d8cc878 Aug 11, 2025
78 of 100 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
A-CI Area: CI-related items ctest Issues relating to the ctest crate
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants