Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 1 addition & 3 deletions ctest/src/generator.rs
Original file line number Diff line number Diff line change
Expand Up @@ -930,16 +930,14 @@ impl TestGenerator {
self
}

// FIXME(ctest): should arrays be handled differently?

/// Configures whether the ABI roundtrip tests for a type are emitted.
///
/// The closure is passed the name of a Rust type and returns whether the
/// tests are generated.
///
/// By default all types undergo ABI roundtrip tests. Arrays cannot undergo
/// an ABI roundtrip because they cannot be returned by C functions, and
/// have to be manually skipped here.
/// are automatically skipped.
///
/// # Examples
/// ```no_run
Expand Down
4 changes: 4 additions & 0 deletions ctest/src/template.rs
Original file line number Diff line number Diff line change
Expand Up @@ -257,6 +257,10 @@ impl TestTemplate {
helper: &TranslateHelper,
) -> Result<(), TranslationError> {
for alias in helper.filtered_ffi_items.aliases() {
// Arrays cannot be roundtripped, and are automatically skipped.
if let syn::Type::Array(_) = alias.ty {
continue;
}
let c_ty = helper.c_type(alias)?;
self.add_roundtrip_test(helper, alias.ident(), &[], &c_ty, true);
}
Expand Down
2 changes: 1 addition & 1 deletion ctest/tests/basic.rs
Original file line number Diff line number Diff line change
Expand Up @@ -101,7 +101,7 @@ fn test_skip_simple() {
let (mut gen_, out_dir) = default_generator(1, Some("simple.h")).unwrap();
gen_.skip_const(|c| c.ident() == "B" || c.ident() == "A")
.skip_c_enum(|e| e == "Color")
.skip_alias(|a| a.ident() == "Byte")
.skip_alias(|a| a.ident() == "Byte" || a.ident() == "gregset_t")
.skip_struct(|s| s.ident() == "Person")
.skip_union(|u| u.ident() == "Word")
.skip_fn(|f| f.ident() == "calloc")
Expand Down
2 changes: 2 additions & 0 deletions ctest/tests/input/simple.h
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,8 @@

typedef uint8_t Byte;

typedef unsigned long gregset_t[32];

Byte byte = 0x42;

struct Person
Expand Down
6 changes: 6 additions & 0 deletions ctest/tests/input/simple.out.with-renames.c
Original file line number Diff line number Diff line change
Expand Up @@ -62,6 +62,12 @@ CTEST_EXTERN uint64_t ctest_size_of__Byte(void) { return sizeof(Byte); }
// Return the alignment of a type.
CTEST_EXTERN uint64_t ctest_align_of__Byte(void) { return CTEST_ALIGNOF(Byte); }

// Return the size of a type.
CTEST_EXTERN uint64_t ctest_size_of__gregset_t(void) { return sizeof(gregset_t); }

// Return the alignment of a type.
CTEST_EXTERN uint64_t ctest_align_of__gregset_t(void) { return CTEST_ALIGNOF(gregset_t); }

// Return the size of a type.
CTEST_EXTERN uint64_t ctest_size_of__Color(void) { return sizeof(enum Color); }

Expand Down
18 changes: 18 additions & 0 deletions ctest/tests/input/simple.out.with-renames.rs
Original file line number Diff line number Diff line change
Expand Up @@ -186,6 +186,23 @@ mod generated_tests {
check_same(rust_align, c_align, "Byte align");
}

/// Compare the size and alignment of the type in Rust and C, making sure they are the same.
pub fn ctest_size_align_gregset_t() {
extern "C" {
fn ctest_size_of__gregset_t() -> u64;
fn ctest_align_of__gregset_t() -> u64;
}

let rust_size = size_of::<gregset_t>() as u64;
let c_size = unsafe { ctest_size_of__gregset_t() };

let rust_align = align_of::<gregset_t>() as u64;
let c_align = unsafe { ctest_align_of__gregset_t() };

check_same(rust_size, c_size, "gregset_t size");
check_same(rust_align, c_align, "gregset_t align");
}

/// Compare the size and alignment of the type in Rust and C, making sure they are the same.
pub fn ctest_size_align_Color() {
extern "C" {
Expand Down Expand Up @@ -996,6 +1013,7 @@ fn run_all() {
ctest_const_BLUE();
ctest_const_GREEN();
ctest_size_align_Byte();
ctest_size_align_gregset_t();
ctest_size_align_Color();
ctest_size_align_Person();
ctest_size_align_Word();
Expand Down
5 changes: 4 additions & 1 deletion ctest/tests/input/simple.rs
Original file line number Diff line number Diff line change
@@ -1,7 +1,10 @@
use std::ffi::{c_char, c_int, c_void};
use std::ffi::{c_char, c_int, c_ulong, c_void};

pub type Byte = u8;

// This should be automatically skipped for roundtripping.
pub type gregset_t = [c_ulong; 32];

#[repr(C)]
pub struct Person {
pub name: *const c_char,
Expand Down
Loading