Skip to content

Commit

Permalink
Improve errors of roundtrip tests
Browse files Browse the repository at this point in the history
  • Loading branch information
gnzlbg committed Sep 17, 2019
1 parent b96460d commit ddf07ea
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 5 deletions.
2 changes: 1 addition & 1 deletion Cargo.toml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
[package]
name = "ctest"
version = "0.2.19"
version = "0.2.20"
authors = [
"Alex Crichton <alex@alexcrichton.com>",
"Gonzalo Brito Gadeschi <gonzalobg88@gmail.com>"
Expand Down
18 changes: 14 additions & 4 deletions src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1890,10 +1890,19 @@ impl<'a> Generator<'a> {
# pragma warning(disable:4365)
#endif
{linkage} {cty} __test_roundtrip_{ty}(
{cty} value, int* error, unsigned char* pad
{cty} value, int32_t rust_size, int* error, unsigned char* pad
) {{
volatile unsigned char* p = (volatile unsigned char*)&value;
int size = (int)sizeof({cty});
if (size != rust_size) {{
fprintf(
stderr,
"size of {cty} is %d in C and %d in Rust",
size, rust_size
);
*error = 1;
return value;
}}
int i = 0;
for (i = 0; i < size; ++i) {{
if (pad[i]) {{ continue; }}
Expand Down Expand Up @@ -1935,7 +1944,7 @@ impl<'a> Generator<'a> {
extern {{
#[allow(non_snake_case)]
fn __test_roundtrip_{ty}(
x: U, e: *mut c_int, pad: *const u8
x: U, size: i32, e: *mut c_int, pad: *const u8
) -> U;
}}
let pad = roundtrip_padding_{ty}();
Expand All @@ -1946,15 +1955,16 @@ impl<'a> Generator<'a> {
let mut x: U = uninitialized();
let x_ptr = &mut x as *mut _ as *mut u8;
let y_ptr = &mut y as *mut _ as *mut u8;
for i in 0..size_of::<U>() {{
let sz = size_of::<U>();
for i in 0..sz {{
let c: u8 = (i % 256) as u8;
let c = if c == 0 {{ 42 }} else {{ c }};
let d: u8 = 255_u8 - (i % 256) as u8;
let d = if d == 0 {{ 42 }} else {{ d }};
x_ptr.add(i).write_volatile(c);
y_ptr.add(i).write_volatile(d);
}}
let r: U = __test_roundtrip_{ty}(x, &mut error, pad.as_ptr());
let r: U = __test_roundtrip_{ty}(x, sz as i32, &mut error, pad.as_ptr());
if error == 1 {{
FAILED.store(true, Ordering::SeqCst);
return;
Expand Down

0 comments on commit ddf07ea

Please sign in to comment.