Alex Crichton | e860619 | 2015-09-10 20:19:44 -0700 | [diff] [blame] | 1 | #![allow(bad_style, unused_imports)] |
Alex Crichton | 0df7c10 | 2015-09-10 16:35:37 -0700 | [diff] [blame] | 2 | |
Alex Crichton | 8e5f0cd | 2015-09-09 22:46:19 -0700 | [diff] [blame] | 3 | extern crate libc; |
| 4 | extern crate libc_test; |
| 5 | |
Alex Crichton | c8b895c | 2015-09-10 13:24:15 -0700 | [diff] [blame] | 6 | use std::any::{Any, TypeId}; |
Alex Crichton | 1608306 | 2015-09-09 22:59:24 -0700 | [diff] [blame] | 7 | use std::mem; |
| 8 | |
Alex Crichton | a9adfbf | 2015-09-09 23:21:27 -0700 | [diff] [blame] | 9 | use libc::*; |
Alex Crichton | a9adfbf | 2015-09-09 23:21:27 -0700 | [diff] [blame] | 10 | |
Alex Crichton | 0df7c10 | 2015-09-10 16:35:37 -0700 | [diff] [blame] | 11 | trait Pretty { |
| 12 | fn pretty(&self) -> String; |
| 13 | } |
| 14 | |
| 15 | impl<T> Pretty for *const T { |
| 16 | fn pretty(&self) -> String { format!("{:?}", self) } |
| 17 | } |
| 18 | impl<T> Pretty for *mut T { |
| 19 | fn pretty(&self) -> String { format!("{:?}", self) } |
| 20 | } |
| 21 | macro_rules! p { |
| 22 | ($($i:ident)*) => ($( |
| 23 | impl Pretty for $i { |
| 24 | fn pretty(&self) -> String { format!("{} ({:#x})", self, self) } |
| 25 | } |
| 26 | )*) |
| 27 | } |
| 28 | p! { i8 i16 i32 i64 u8 u16 u32 u64 usize isize } |
| 29 | |
Alex Crichton | 8fc95d2 | 2015-09-14 11:06:20 -0700 | [diff] [blame] | 30 | static mut FAILED: bool = false; |
| 31 | |
Alex Crichton | 0df7c10 | 2015-09-10 16:35:37 -0700 | [diff] [blame] | 32 | fn same<T: Eq + Pretty>(rust: T, c: T, attr: &str) { |
Alex Crichton | 3e5155b | 2015-09-09 23:46:19 -0700 | [diff] [blame] | 33 | if rust != c { |
Alex Crichton | 8fc95d2 | 2015-09-14 11:06:20 -0700 | [diff] [blame] | 34 | println!("bad {}: rust: {} != c {}", attr, rust.pretty(), c.pretty()); |
| 35 | unsafe { FAILED = true; } |
Alex Crichton | 3e5155b | 2015-09-09 23:46:19 -0700 | [diff] [blame] | 36 | } |
| 37 | } |
| 38 | |
Alex Crichton | f81e3d3 | 2015-09-11 15:27:09 -0700 | [diff] [blame] | 39 | #[allow(deprecated)] |
Alex Crichton | c8b895c | 2015-09-10 13:24:15 -0700 | [diff] [blame] | 40 | fn align<T: Any>() -> u64 { |
| 41 | // TODO: apparently these three types have less alignment in Rust on x86 |
| 42 | // than they do in C this difference should.. probably be reconciled. |
| 43 | // |
| 44 | // Perhaps #27195? |
| 45 | if cfg!(target_pointer_width = "32") { |
| 46 | if TypeId::of::<T>() == TypeId::of::<f64>() || |
| 47 | TypeId::of::<T>() == TypeId::of::<i64>() || |
| 48 | TypeId::of::<T>() == TypeId::of::<u64>() { |
| 49 | return 8 |
| 50 | } |
| 51 | } |
Alex Crichton | f81e3d3 | 2015-09-11 15:27:09 -0700 | [diff] [blame] | 52 | mem::min_align_of::<T>() as u64 |
Alex Crichton | c8b895c | 2015-09-10 13:24:15 -0700 | [diff] [blame] | 53 | } |
| 54 | |
Alex Crichton | 3e5155b | 2015-09-09 23:46:19 -0700 | [diff] [blame] | 55 | macro_rules! offset_of { |
| 56 | ($ty:ident, $field:ident) => ( |
| 57 | (&((*(0 as *const $ty)).$field)) as *const _ as u64 |
| 58 | ) |
| 59 | } |
| 60 | |
Alex Crichton | 8e5f0cd | 2015-09-09 22:46:19 -0700 | [diff] [blame] | 61 | include!(concat!(env!("OUT_DIR"), "/all.rs")); |
Alex Crichton | 5a28433 | 2015-09-13 23:33:33 -0700 | [diff] [blame] | 62 | |
| 63 | fn main() { |
| 64 | println!("RUNNING ALL TESTS"); |
| 65 | run_all(); |
Alex Crichton | 8fc95d2 | 2015-09-14 11:06:20 -0700 | [diff] [blame] | 66 | unsafe { |
| 67 | if FAILED { |
| 68 | panic!("some tests failed"); |
| 69 | } else { |
| 70 | println!("PASSED"); |
| 71 | } |
| 72 | } |
Alex Crichton | 5a28433 | 2015-09-13 23:33:33 -0700 | [diff] [blame] | 73 | } |