Match BSD-family IPv4 multicast TTL/loopback ABI to system headers#647
Match BSD-family IPv4 multicast TTL/loopback ABI to system headers#647lopopolo wants to merge 4 commits intorust-lang:masterfrom
Conversation
5e7192c to
7475821
Compare
src/socket.rs
Outdated
| from!(Socket, net::UdpSocket); | ||
|
|
||
| #[cfg(test)] | ||
| mod tests { |
There was a problem hiding this comment.
Can you move this to the other tests in the tests directory?
There was a problem hiding this comment.
thanks, I was wondering why there were so few unit tests in this crate 😅
I've moved this into tests/socket.rs.
src/socket.rs
Outdated
| #[cfg(test)] | ||
| mod tests { | ||
| #[test] | ||
| #[cfg(target_os = "freebsd")] |
There was a problem hiding this comment.
Why run it on FreeBSD only?
There was a problem hiding this comment.
I mentioned this in the comment I left on the original issue #646 (comment), but in case you missed it:
The regression test only is gated on for freebsd because that is the VM I happened to have available for reproduction. I can widen this cfg if you'd like so it covers all of the relevant BSD OSes.
I've widened the cfg so it tests on all relevant BSD OSes.
src/socket.rs
Outdated
| mod tests { | ||
| #[test] | ||
| #[cfg(target_os = "freebsd")] | ||
| fn set_multicast_ttl_v4_matches_std_for_values_above_u8_range() { |
There was a problem hiding this comment.
Can we please fix these terrible AI generated names?
There was a problem hiding this comment.
I've renamed the test to multicast_v4_bsd_abi.
src/socket.rs
Outdated
|
|
||
| let socket2_socket = Socket::new(Domain::IPV4, Type::DGRAM, Some(Protocol::UDP)).unwrap(); | ||
| socket2_socket.set_multicast_ttl_v4(258).unwrap(); | ||
| assert_eq!(socket2_socket.multicast_ttl_v4().unwrap(), std_ttl); |
There was a problem hiding this comment.
Can you use the test macro for this? See the other tests.
There was a problem hiding this comment.
I've factored this out into an assertion helper named assert_multicast_ttl_v4.
There was a problem hiding this comment.
To maintain the part of the test that ensures behavior matches std, the helper accepts either a socket2 Socket or a std UdpSocket via a SocketRef enum which I am using to model an "either" enum. If this isn't acceptable, please let me know what you'd prefer.
lopopolo
left a comment
There was a problem hiding this comment.
thanks for the feedback, new patch incoming.
src/socket.rs
Outdated
| mod tests { | ||
| #[test] | ||
| #[cfg(target_os = "freebsd")] | ||
| fn set_multicast_ttl_v4_matches_std_for_values_above_u8_range() { |
There was a problem hiding this comment.
I've renamed the test to multicast_v4_bsd_abi.
src/socket.rs
Outdated
| #[cfg(test)] | ||
| mod tests { | ||
| #[test] | ||
| #[cfg(target_os = "freebsd")] |
There was a problem hiding this comment.
I mentioned this in the comment I left on the original issue #646 (comment), but in case you missed it:
The regression test only is gated on for freebsd because that is the VM I happened to have available for reproduction. I can widen this cfg if you'd like so it covers all of the relevant BSD OSes.
I've widened the cfg so it tests on all relevant BSD OSes.
src/socket.rs
Outdated
| from!(Socket, net::UdpSocket); | ||
|
|
||
| #[cfg(test)] | ||
| mod tests { |
There was a problem hiding this comment.
thanks, I was wondering why there were so few unit tests in this crate 😅
I've moved this into tests/socket.rs.
src/socket.rs
Outdated
|
|
||
| let socket2_socket = Socket::new(Domain::IPV4, Type::DGRAM, Some(Protocol::UDP)).unwrap(); | ||
| socket2_socket.set_multicast_ttl_v4(258).unwrap(); | ||
| assert_eq!(socket2_socket.multicast_ttl_v4().unwrap(), std_ttl); |
There was a problem hiding this comment.
I've factored this out into an assertion helper named assert_multicast_ttl_v4.
src/socket.rs
Outdated
|
|
||
| let socket2_socket = Socket::new(Domain::IPV4, Type::DGRAM, Some(Protocol::UDP)).unwrap(); | ||
| socket2_socket.set_multicast_ttl_v4(258).unwrap(); | ||
| assert_eq!(socket2_socket.multicast_ttl_v4().unwrap(), std_ttl); |
There was a problem hiding this comment.
To maintain the part of the test that ensures behavior matches std, the helper accepts either a socket2 Socket or a std UdpSocket via a SocketRef enum which I am using to model an "either" enum. If this isn't acceptable, please let me know what you'd prefer.
c07d43c to
92be67d
Compare
|
thanks for the feedback @Thomasdezeeuw. I have tried my best to address it and believe this PR is ready for another review. |
Thomasdezeeuw
left a comment
There was a problem hiding this comment.
I'm sorry, but this is not at all what I wanted and I don't want to review this AI generated code any longer.
Hi Thomas, this is disappointing to hear. Thanks for your time. |
I am trying to debug what was not acceptable here and I think it is because I did not construct the tests like this: Lines 1602 to 1607 in 642df44 I did not find this macro because #647 (comment) was not very specific in terms of which tests to match. Additionally, @Thomasdezeeuw had been providing dismissive feedback in response to AI assistance, so I wrote the commits 92be67d and 7ddafc0 by hand. As someone familiar to Rust but new to this crate, test macro most obviously meant
but the docs do not match the reality of the test file; the macro is defined ~600 lines before the end of the file. When scanning the Lines 381 to 390 in 642df44 which is what I used to model how I addressed the feedback. I also believed divergence from Based on my understanding now, I am guessing that the acceptable test would have been the following: #[cfg(any(
target_os = "dragonfly",
target_os = "freebsd",
target_os = "openbsd",
target_os = "netbsd",
target_os = "solaris",
target_os = "illumos",
target_os = "nto",
))]
test!(IPv4 multicast_ttl_v4, set_multicast_ttl_v4(258), 2);I would have hoped that my good faith contributions could have been either:
For the avoidance of doubt, this comment (and all of them on #647 and #646) are human-authored. |
Refs #646.
BSD-family system headers declare
IP_MULTICAST_TTLandIP_MULTICAST_LOOPasu_char/unsigned char.socket2was usingc_intfor these options on all targets. On FreeBSD 15 this is observable:std::net::UdpSocket::set_multicast_ttl_v4(258)succeeds and stores2, whilesocket2::Socket::set_multicast_ttl_v4(258)returnsEINVAL.