blob: c0f9eca7b6265b912d54dcc1c87537b50aa88740 [file] [log] [blame]
Alex Crichtone8606192015-09-10 20:19:44 -07001#![allow(bad_style, unused_imports)]
Alex Crichton0df7c102015-09-10 16:35:37 -07002
Alex Crichton8e5f0cd2015-09-09 22:46:19 -07003extern crate libc;
4extern crate libc_test;
5
Alex Crichtonc8b895c2015-09-10 13:24:15 -07006use std::any::{Any, TypeId};
Alex Crichton16083062015-09-09 22:59:24 -07007use std::mem;
8
Alex Crichtona9adfbf2015-09-09 23:21:27 -07009use libc::*;
Alex Crichtona9adfbf2015-09-09 23:21:27 -070010
Alex Crichton0df7c102015-09-10 16:35:37 -070011trait Pretty {
12 fn pretty(&self) -> String;
13}
14
15impl<T> Pretty for *const T {
16 fn pretty(&self) -> String { format!("{:?}", self) }
17}
18impl<T> Pretty for *mut T {
19 fn pretty(&self) -> String { format!("{:?}", self) }
20}
21macro_rules! p {
22 ($($i:ident)*) => ($(
23 impl Pretty for $i {
24 fn pretty(&self) -> String { format!("{} ({:#x})", self, self) }
25 }
26 )*)
27}
28p! { i8 i16 i32 i64 u8 u16 u32 u64 usize isize }
29
30fn same<T: Eq + Pretty>(rust: T, c: T, attr: &str) {
Alex Crichton3e5155b2015-09-09 23:46:19 -070031 if rust != c {
Alex Crichton0df7c102015-09-10 16:35:37 -070032 panic!("bad {}: rust: {} != c {}", attr, rust.pretty(), c.pretty());
Alex Crichton3e5155b2015-09-09 23:46:19 -070033 }
34}
35
Alex Crichtonf81e3d32015-09-11 15:27:09 -070036#[allow(deprecated)]
Alex Crichtonc8b895c2015-09-10 13:24:15 -070037fn align<T: Any>() -> u64 {
38 // TODO: apparently these three types have less alignment in Rust on x86
39 // than they do in C this difference should.. probably be reconciled.
40 //
41 // Perhaps #27195?
42 if cfg!(target_pointer_width = "32") {
43 if TypeId::of::<T>() == TypeId::of::<f64>() ||
44 TypeId::of::<T>() == TypeId::of::<i64>() ||
45 TypeId::of::<T>() == TypeId::of::<u64>() {
46 return 8
47 }
48 }
Alex Crichtonf81e3d32015-09-11 15:27:09 -070049 mem::min_align_of::<T>() as u64
Alex Crichtonc8b895c2015-09-10 13:24:15 -070050}
51
Alex Crichton3e5155b2015-09-09 23:46:19 -070052macro_rules! offset_of {
53 ($ty:ident, $field:ident) => (
54 (&((*(0 as *const $ty)).$field)) as *const _ as u64
55 )
56}
57
Alex Crichton8e5f0cd2015-09-09 22:46:19 -070058include!(concat!(env!("OUT_DIR"), "/all.rs"));
Alex Crichton5a284332015-09-13 23:33:33 -070059
60fn main() {
61 println!("RUNNING ALL TESTS");
62 run_all();
63 println!("PASSED");
64}