Skip to content

Commit

Permalink
Add tests for packed unions
Browse files Browse the repository at this point in the history
  • Loading branch information
chrysn authored and fw-immunant committed Jan 18, 2022
1 parent 6a5c3a9 commit 6674d78
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 2 deletions.
4 changes: 2 additions & 2 deletions tests/unions/src/test_unions.rs
Original file line number Diff line number Diff line change
Expand Up @@ -9,12 +9,12 @@ extern "C" {
fn entry(_: c_uint, _: *mut c_int);
}

const BUFFER_SIZE: usize = 18;
const BUFFER_SIZE: usize = 19;

pub fn test_buffer() {
let mut buffer = [0; BUFFER_SIZE];
let mut rust_buffer = [0; BUFFER_SIZE];
let expected_buffer = [12, 12, 0, 1, 2, 3, 4, 0, 5, 6, 7, 8, 0, 8, 9, 10, 12, 17];
let expected_buffer = [12, 12, 0, 5, 1, 2, 3, 4, 0, 5, 6, 7, 8, 0, 8, 9, 10, 12, 18];

unsafe {
entry(BUFFER_SIZE as u32, buffer.as_mut_ptr());
Expand Down
6 changes: 6 additions & 0 deletions tests/unions/src/unions.c
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,11 @@ union union_with_anon_struct {
};
};

union __attribute__((packed)) packed_union {
int as_int;
char as_chars[5];
};

void entry(const unsigned int buffer_size, int buffer[const])
{
int i = 0;
Expand All @@ -35,6 +40,7 @@ void entry(const unsigned int buffer_size, int buffer[const])
buffer[i++] = sizeof(union my_union);
buffer[i++] = sizeof(union my_union_flipped);
buffer[i++] = sizeof(union empty_union);
buffer[i++] = sizeof(union packed_union);
buffer[i++] = u1.as_int;
buffer[i++] = u2.as_int;
buffer[i++] = u3.as_chars[0];
Expand Down

0 comments on commit 6674d78

Please sign in to comment.