Add test for SO_EE_OFFENDER
Modelled after the cmsg tests, this wraps the C macro into a function, and then compares the results to the Rust implementation in libc.
This commit is contained in:
parent
a9a6ef13a1
commit
06938add2d
|
@ -52,3 +52,8 @@ harness = false
|
||||||
name = "cmsg"
|
name = "cmsg"
|
||||||
path = "test/cmsg.rs"
|
path = "test/cmsg.rs"
|
||||||
harness = true
|
harness = true
|
||||||
|
|
||||||
|
[[test]]
|
||||||
|
name = "errqueue"
|
||||||
|
path = "test/errqueue.rs"
|
||||||
|
harness = true
|
||||||
|
|
|
@ -10,6 +10,9 @@ fn do_cc() {
|
||||||
if cfg!(unix) && !target.contains("wasi") {
|
if cfg!(unix) && !target.contains("wasi") {
|
||||||
cc::Build::new().file("src/cmsg.c").compile("cmsg");
|
cc::Build::new().file("src/cmsg.c").compile("cmsg");
|
||||||
}
|
}
|
||||||
|
if target.contains("android") || target.contains("linux") {
|
||||||
|
cc::Build::new().file("src/errqueue.c").compile("errqueue");
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
fn do_ctest() {
|
fn do_ctest() {
|
||||||
|
|
|
@ -0,0 +1,10 @@
|
||||||
|
#include <time.h>
|
||||||
|
#include <linux/errqueue.h>
|
||||||
|
|
||||||
|
// SO_EE_OFFENDER is defined as a macro in linux/errqueue.h. This file wraps
|
||||||
|
// that macro in a function so we can test the reimplementation in this package
|
||||||
|
// is equivalent.
|
||||||
|
|
||||||
|
struct sockaddr *so_ee_offender(struct sock_extended_err *ee) {
|
||||||
|
return SO_EE_OFFENDER(ee);
|
||||||
|
}
|
|
@ -0,0 +1,22 @@
|
||||||
|
//! Compare libc's SO_EE_OFFENDER function against the actual C macro
|
||||||
|
|
||||||
|
extern crate libc;
|
||||||
|
|
||||||
|
#[cfg(any(target_os = "linux", target_os = "android"))]
|
||||||
|
mod t {
|
||||||
|
use libc::{self, sock_extended_err, sockaddr};
|
||||||
|
|
||||||
|
extern "C" {
|
||||||
|
pub fn so_ee_offender(ee: *const sock_extended_err) -> *mut sockaddr;
|
||||||
|
}
|
||||||
|
|
||||||
|
#[test]
|
||||||
|
fn test_cmsg_data() {
|
||||||
|
for l in 0..128 {
|
||||||
|
let ee = l as *const sock_extended_err;
|
||||||
|
unsafe {
|
||||||
|
assert_eq!(libc::SO_EE_OFFENDER(ee), so_ee_offender(ee));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
Loading…
Reference in New Issue