Skip to content

ctest: Add roundtrip test. #4560

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 1, 2025
Merged

Conversation

mbyx
Copy link
Contributor

@mbyx mbyx commented Jul 23, 2025

Description

Adds a roundtrip test to ctest-next.

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 Jul 23, 2025
@mbyx mbyx force-pushed the ctest-roundtrip-test branch 3 times, most recently from 197138e to 1b660f1 Compare July 26, 2025 16:32
@mbyx mbyx requested a review from tgross35 July 26, 2025 16:35
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.

A handful more comments here, but most are small and I think this should be the last round.

Ok(())
}

fn _add_roundtrip_test(
Copy link
Contributor

Choose a reason for hiding this comment

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

Remove the leading _, that's not a Rust convention. Any chance you have a background in Python? :)

@mbyx mbyx force-pushed the ctest-roundtrip-test branch from 1b660f1 to 3da3f28 Compare July 28, 2025 08:50
@mbyx mbyx force-pushed the ctest-roundtrip-test branch 2 times, most recently from 63e4aa4 to c4d7a7d Compare July 28, 2025 09:03
@mbyx mbyx requested a review from tgross35 July 28, 2025 09:05
Comment on lines 252 to 259
input: MaybeUninit<U>, is_padding_byte: *const bool, expected: *mut u8
) -> U;
}

const SIZE: usize = size_of::<U>();

let is_padding_byte = roundtrip_padding__{{ item.id }}();
let mut expected = [0u8; SIZE];
Copy link
Contributor

Choose a reason for hiding this comment

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

The expected function signature can be updated to be called value_bytes like the C signature, then the expected array can be called c_value_bytes.

Also, this value and c_value_bytes can both be the same type - either a stack array or a vector. Allocating is probably a bit better in case of huge types.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I don't understand what you mean by your second point, that they can be the same type. Which two?

Copy link
Contributor

Choose a reason for hiding this comment

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

expected is a [0u8; SIZE], c_value_bytes is a vec![0u8; SIZE];. They need to store the same amount of data, so might as well make them both a Vec

Copy link
Contributor Author

Choose a reason for hiding this comment

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

There's two different variables called c_value_bytes and its difficult to separate them so that it doesn't matter, so expected needs a different name.

Copy link
Contributor

Choose a reason for hiding this comment

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

I'm sorry, I misread that bit. That name was fine, it didn't need to change. expected or e.g. expected_return would be fine.

Copy link
Contributor

Choose a reason for hiding this comment

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

@mbyx ^ mind changing the name back? After that this is good to go

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Done!

@mbyx mbyx force-pushed the ctest-roundtrip-test branch from c4d7a7d to c7dc200 Compare July 28, 2025 09:25
@mbyx mbyx requested a review from tgross35 July 28, 2025 09:27
@mbyx mbyx force-pushed the ctest-roundtrip-test branch from c7dc200 to 7d65acc Compare August 1, 2025 11:04
@mbyx mbyx force-pushed the ctest-roundtrip-test branch from 7d65acc to 39d53bb Compare August 1, 2025 11:04
@tgross35 tgross35 added this pull request to the merge queue Aug 1, 2025
Merged via the queue into rust-lang:main with commit aa99092 Aug 1, 2025
48 of 52 checks passed
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
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants