|
1 | | -#![feature(plugin, custom_attribute, custom_inner_attributes)] |
| 1 | +#![feature(plugin, custom_attribute)] |
2 | 2 | #![plugin(c2rust_xcheck_plugin)] |
3 | | -#![cross_check(none)] |
4 | 3 |
|
5 | 4 | #[macro_use] |
6 | 5 | extern crate c2rust_xcheck_runtime; |
7 | 6 |
|
8 | 7 | mod xcheck; |
9 | 8 | pub use xcheck::rb_xcheck; // Export rb_xcheck for the runtime |
10 | 9 |
|
11 | | -use c2rust_xcheck_runtime::xcheck::{FUNCTION_ARG_TAG, FUNCTION_ENTRY_TAG, FUNCTION_EXIT_TAG}; |
12 | | -use xcheck::{expect_no_xchecks, expect_xcheck}; |
13 | | - |
14 | | -#[test] |
15 | | -fn test_entry() { |
16 | | - #[cross_check(yes)] |
17 | | - fn abcd() {} |
18 | | - |
19 | | - abcd(); |
20 | | - expect_xcheck(FUNCTION_ENTRY_TAG, 0x7c93ee4f_u64); |
21 | | - expect_xcheck(FUNCTION_EXIT_TAG, 0x7c93ee4f_u64); |
22 | | - expect_no_xchecks(); |
23 | | -} |
24 | | - |
25 | | -#[test] |
26 | | -#[should_panic] |
27 | | -fn test_no_xcheck() { |
28 | | - #[cross_check(none)] |
29 | | - fn abcd() {} |
30 | | - |
31 | | - abcd(); |
32 | | - expect_xcheck(FUNCTION_ENTRY_TAG, 0x7c93ee4f_u64); |
33 | | - expect_xcheck(FUNCTION_EXIT_TAG, 0x7c93ee4f_u64); |
34 | | - expect_no_xchecks(); |
35 | | -} |
36 | | - |
37 | | -#[test] |
38 | | -fn test_custom_fn_name() { |
39 | | - #[cross_check(yes, entry(djb2 = "djb2"))] |
40 | | - fn abcd() {} |
41 | | - |
42 | | - abcd(); |
43 | | - expect_xcheck(FUNCTION_ENTRY_TAG, 0x7c95b527_u64); |
44 | | - expect_xcheck(FUNCTION_EXIT_TAG, 0x7c93ee4f_u64); |
45 | | - expect_no_xchecks(); |
46 | | -} |
47 | | - |
48 | | -#[test] |
49 | | -fn test_custom_fn_id() { |
50 | | - #[cross_check(yes, entry(fixed = 0x12345678))] |
51 | | - fn abcd() {} |
52 | | - |
53 | | - abcd(); |
54 | | - expect_xcheck(FUNCTION_ENTRY_TAG, 0x12345678_u64); |
55 | | - expect_xcheck(FUNCTION_EXIT_TAG, 0x7c93ee4f_u64); |
56 | | - expect_no_xchecks(); |
57 | | -} |
58 | | - |
59 | | -#[test] |
60 | | -fn test_entry_disabled() { |
61 | | - #[cross_check(yes, entry(disabled))] |
62 | | - fn abcd() {} |
63 | | - |
64 | | - abcd(); |
65 | | - expect_xcheck(FUNCTION_EXIT_TAG, 0x7c93ee4f_u64); |
66 | | - expect_no_xchecks(); |
67 | | -} |
68 | | - |
69 | | -#[test] |
70 | | -fn test_exit_disabled() { |
71 | | - #[cross_check(yes, exit(disabled))] |
72 | | - fn abcd() {} |
73 | | - |
74 | | - abcd(); |
75 | | - expect_xcheck(FUNCTION_ENTRY_TAG, 0x7c93ee4f_u64); |
76 | | - expect_no_xchecks(); |
77 | | -} |
78 | | - |
79 | | -#[test] |
80 | | -fn test_all_args_default() { |
81 | | - #[cross_check(yes, all_args)] |
82 | | - fn abcd(_a: u8, _b: u64) {} |
83 | | - |
84 | | - abcd(0x7fu8, 1u64); |
85 | | - expect_xcheck(FUNCTION_ENTRY_TAG, 0x7c93ee4f_u64); |
86 | | - expect_xcheck(FUNCTION_ARG_TAG, 0x7f_u64); |
87 | | - expect_xcheck(FUNCTION_ARG_TAG, 0x0f0f0f0f_0f0f0f0f_u64); |
88 | | - expect_xcheck(FUNCTION_EXIT_TAG, 0x7c93ee4f_u64); |
89 | | - expect_no_xchecks(); |
90 | | -} |
91 | | - |
92 | | -#[test] |
93 | | -fn test_all_args_fixed() { |
94 | | - #[cross_check(yes, all_args(fixed = 0x1234))] |
95 | | - fn abcd(_a: u8, _b: u64) {} |
96 | | - |
97 | | - abcd(0x7fu8, 1u64); |
98 | | - expect_xcheck(FUNCTION_ENTRY_TAG, 0x7c93ee4f_u64); |
99 | | - expect_xcheck(FUNCTION_ARG_TAG, 0x1234_u64); |
100 | | - expect_xcheck(FUNCTION_ARG_TAG, 0x1234_u64); |
101 | | - expect_xcheck(FUNCTION_EXIT_TAG, 0x7c93ee4f_u64); |
102 | | - expect_no_xchecks(); |
103 | | -} |
104 | | - |
105 | | -#[test] |
106 | | -fn test_all_args_disabled() { |
107 | | - #[cross_check(yes, all_args(disabled))] |
108 | | - fn abcd(_a: u8, _b: u64) {} |
109 | | - |
110 | | - abcd(0x7fu8, 1u64); |
111 | | - expect_xcheck(FUNCTION_ENTRY_TAG, 0x7c93ee4f_u64); |
112 | | - expect_xcheck(FUNCTION_EXIT_TAG, 0x7c93ee4f_u64); |
113 | | - expect_no_xchecks(); |
114 | | -} |
115 | | - |
116 | | -#[test] |
117 | | -fn test_args_override() { |
118 | | - #[cross_check(yes, args(_a(fixed = 0x1234), _b(none)))] |
119 | | - fn abcd(_a: u8, _b: u64) {} |
120 | | - |
121 | | - abcd(0x7fu8, 1u64); |
122 | | - expect_xcheck(FUNCTION_ENTRY_TAG, 0x7c93ee4f_u64); |
123 | | - expect_xcheck(FUNCTION_ARG_TAG, 0x1234_u64); |
124 | | - expect_xcheck(FUNCTION_EXIT_TAG, 0x7c93ee4f_u64); |
125 | | - expect_no_xchecks(); |
126 | | -} |
127 | | - |
128 | | -#[test] |
129 | | -fn test_args_as_type() { |
130 | | - #[cross_check(yes, args(_a(as_type = "u8")))] |
131 | | - fn abcd(_a: u32) {} |
132 | | - |
133 | | - abcd(0x1234u32); |
134 | | - expect_xcheck(FUNCTION_ENTRY_TAG, 0x7c93ee4f_u64); |
135 | | - expect_xcheck(FUNCTION_ARG_TAG, 0x34_u64); |
136 | | - expect_xcheck(FUNCTION_EXIT_TAG, 0x7c93ee4f_u64); |
137 | | - expect_no_xchecks(); |
| 10 | +#[cross_check(none)] |
| 11 | +mod tests { |
| 12 | + use c2rust_xcheck_runtime::xcheck::{FUNCTION_ARG_TAG, FUNCTION_ENTRY_TAG, FUNCTION_EXIT_TAG}; |
| 13 | + use super::xcheck::{expect_no_xchecks, expect_xcheck}; |
| 14 | + |
| 15 | + #[test] |
| 16 | + fn test_entry() { |
| 17 | + #[cross_check(yes)] |
| 18 | + fn abcd() {} |
| 19 | + |
| 20 | + abcd(); |
| 21 | + expect_xcheck(FUNCTION_ENTRY_TAG, 0x7c93ee4f_u64); |
| 22 | + expect_xcheck(FUNCTION_EXIT_TAG, 0x7c93ee4f_u64); |
| 23 | + expect_no_xchecks(); |
| 24 | + } |
| 25 | + |
| 26 | + #[test] |
| 27 | + #[should_panic] |
| 28 | + fn test_no_xcheck() { |
| 29 | + #[cross_check(none)] |
| 30 | + fn abcd() {} |
| 31 | + |
| 32 | + abcd(); |
| 33 | + expect_xcheck(FUNCTION_ENTRY_TAG, 0x7c93ee4f_u64); |
| 34 | + expect_xcheck(FUNCTION_EXIT_TAG, 0x7c93ee4f_u64); |
| 35 | + expect_no_xchecks(); |
| 36 | + } |
| 37 | + |
| 38 | + #[test] |
| 39 | + fn test_custom_fn_name() { |
| 40 | + #[cross_check(yes, entry(djb2 = "djb2"))] |
| 41 | + fn abcd() {} |
| 42 | + |
| 43 | + abcd(); |
| 44 | + expect_xcheck(FUNCTION_ENTRY_TAG, 0x7c95b527_u64); |
| 45 | + expect_xcheck(FUNCTION_EXIT_TAG, 0x7c93ee4f_u64); |
| 46 | + expect_no_xchecks(); |
| 47 | + } |
| 48 | + |
| 49 | + #[test] |
| 50 | + fn test_custom_fn_id() { |
| 51 | + #[cross_check(yes, entry(fixed = 0x12345678))] |
| 52 | + fn abcd() {} |
| 53 | + |
| 54 | + abcd(); |
| 55 | + expect_xcheck(FUNCTION_ENTRY_TAG, 0x12345678_u64); |
| 56 | + expect_xcheck(FUNCTION_EXIT_TAG, 0x7c93ee4f_u64); |
| 57 | + expect_no_xchecks(); |
| 58 | + } |
| 59 | + |
| 60 | + #[test] |
| 61 | + fn test_entry_disabled() { |
| 62 | + #[cross_check(yes, entry(disabled))] |
| 63 | + fn abcd() {} |
| 64 | + |
| 65 | + abcd(); |
| 66 | + expect_xcheck(FUNCTION_EXIT_TAG, 0x7c93ee4f_u64); |
| 67 | + expect_no_xchecks(); |
| 68 | + } |
| 69 | + |
| 70 | + #[test] |
| 71 | + fn test_exit_disabled() { |
| 72 | + #[cross_check(yes, exit(disabled))] |
| 73 | + fn abcd() {} |
| 74 | + |
| 75 | + abcd(); |
| 76 | + expect_xcheck(FUNCTION_ENTRY_TAG, 0x7c93ee4f_u64); |
| 77 | + expect_no_xchecks(); |
| 78 | + } |
| 79 | + |
| 80 | + #[test] |
| 81 | + fn test_all_args_default() { |
| 82 | + #[cross_check(yes, all_args)] |
| 83 | + fn abcd(_a: u8, _b: u64) {} |
| 84 | + |
| 85 | + abcd(0x7fu8, 1u64); |
| 86 | + expect_xcheck(FUNCTION_ENTRY_TAG, 0x7c93ee4f_u64); |
| 87 | + expect_xcheck(FUNCTION_ARG_TAG, 0x7f_u64); |
| 88 | + expect_xcheck(FUNCTION_ARG_TAG, 0x0f0f0f0f_0f0f0f0f_u64); |
| 89 | + expect_xcheck(FUNCTION_EXIT_TAG, 0x7c93ee4f_u64); |
| 90 | + expect_no_xchecks(); |
| 91 | + } |
| 92 | + |
| 93 | + #[test] |
| 94 | + fn test_all_args_fixed() { |
| 95 | + #[cross_check(yes, all_args(fixed = 0x1234))] |
| 96 | + fn abcd(_a: u8, _b: u64) {} |
| 97 | + |
| 98 | + abcd(0x7fu8, 1u64); |
| 99 | + expect_xcheck(FUNCTION_ENTRY_TAG, 0x7c93ee4f_u64); |
| 100 | + expect_xcheck(FUNCTION_ARG_TAG, 0x1234_u64); |
| 101 | + expect_xcheck(FUNCTION_ARG_TAG, 0x1234_u64); |
| 102 | + expect_xcheck(FUNCTION_EXIT_TAG, 0x7c93ee4f_u64); |
| 103 | + expect_no_xchecks(); |
| 104 | + } |
| 105 | + |
| 106 | + #[test] |
| 107 | + fn test_all_args_disabled() { |
| 108 | + #[cross_check(yes, all_args(disabled))] |
| 109 | + fn abcd(_a: u8, _b: u64) {} |
| 110 | + |
| 111 | + abcd(0x7fu8, 1u64); |
| 112 | + expect_xcheck(FUNCTION_ENTRY_TAG, 0x7c93ee4f_u64); |
| 113 | + expect_xcheck(FUNCTION_EXIT_TAG, 0x7c93ee4f_u64); |
| 114 | + expect_no_xchecks(); |
| 115 | + } |
| 116 | + |
| 117 | + #[test] |
| 118 | + fn test_args_override() { |
| 119 | + #[cross_check(yes, args(_a(fixed = 0x1234), _b(none)))] |
| 120 | + fn abcd(_a: u8, _b: u64) {} |
| 121 | + |
| 122 | + abcd(0x7fu8, 1u64); |
| 123 | + expect_xcheck(FUNCTION_ENTRY_TAG, 0x7c93ee4f_u64); |
| 124 | + expect_xcheck(FUNCTION_ARG_TAG, 0x1234_u64); |
| 125 | + expect_xcheck(FUNCTION_EXIT_TAG, 0x7c93ee4f_u64); |
| 126 | + expect_no_xchecks(); |
| 127 | + } |
| 128 | + |
| 129 | + #[test] |
| 130 | + fn test_args_as_type() { |
| 131 | + #[cross_check(yes, args(_a(as_type = "u8")))] |
| 132 | + fn abcd(_a: u32) {} |
| 133 | + |
| 134 | + abcd(0x1234u32); |
| 135 | + expect_xcheck(FUNCTION_ENTRY_TAG, 0x7c93ee4f_u64); |
| 136 | + expect_xcheck(FUNCTION_ARG_TAG, 0x34_u64); |
| 137 | + expect_xcheck(FUNCTION_EXIT_TAG, 0x7c93ee4f_u64); |
| 138 | + expect_no_xchecks(); |
| 139 | + } |
138 | 140 | } |
0 commit comments