]> git.lizzy.rs Git - rust.git/blob - src/rt/rust_test_helpers.c
auto merge of #10828 : SimonSapin/rust/ascii_opt, r=pcwalton
[rust.git] / src / rt / rust_test_helpers.c
1 // Copyright 2013 The Rust Project Developers. See the COPYRIGHT
2 // file at the top-level directory of this distribution and at
3 // http://rust-lang.org/COPYRIGHT.
4 //
5 // Licensed under the Apache License, Version 2.0 <LICENSE-APACHE or
6 // http://www.apache.org/licenses/LICENSE-2.0> or the MIT license
7 // <LICENSE-MIT or http://opensource.org/licenses/MIT>, at your
8 // option. This file may not be copied, modified, or distributed
9 // except according to those terms.
10
11 // Helper functions used only in tests
12
13 #include <stdint.h>
14 #include <assert.h>
15
16 // These functions are used in the unit tests for C ABI calls.
17
18 uint32_t
19 rust_dbg_extern_identity_u32(uint32_t u) {
20     return u;
21 }
22
23 uint64_t
24 rust_dbg_extern_identity_u64(uint64_t u) {
25     return u;
26 }
27
28 double
29 rust_dbg_extern_identity_double(double u) {
30     return u;
31 }
32
33 char
34 rust_dbg_extern_identity_u8(char u) {
35     return u;
36 }
37
38 typedef void *(*dbg_callback)(void*);
39
40 void *
41 rust_dbg_call(dbg_callback cb, void *data) {
42     return cb(data);
43 }
44
45 void rust_dbg_do_nothing() { }
46
47 struct TwoU8s {
48     uint8_t one;
49     uint8_t two;
50 };
51
52 struct TwoU8s
53 rust_dbg_extern_return_TwoU8s() {
54     struct TwoU8s s;
55     s.one = 10;
56     s.two = 20;
57     return s;
58 }
59
60 struct TwoU8s
61 rust_dbg_extern_identity_TwoU8s(struct TwoU8s u) {
62     return u;
63 }
64
65 struct TwoU16s {
66     uint16_t one;
67     uint16_t two;
68 };
69
70 struct TwoU16s
71 rust_dbg_extern_return_TwoU16s() {
72     struct TwoU16s s;
73     s.one = 10;
74     s.two = 20;
75     return s;
76 }
77
78 struct TwoU16s
79 rust_dbg_extern_identity_TwoU16s(struct TwoU16s u) {
80     return u;
81 }
82
83 struct TwoU32s {
84     uint32_t one;
85     uint32_t two;
86 };
87
88 struct TwoU32s
89 rust_dbg_extern_return_TwoU32s() {
90     struct TwoU32s s;
91     s.one = 10;
92     s.two = 20;
93     return s;
94 }
95
96 struct TwoU32s
97 rust_dbg_extern_identity_TwoU32s(struct TwoU32s u) {
98     return u;
99 }
100
101 struct TwoU64s {
102     uint64_t one;
103     uint64_t two;
104 };
105
106 struct TwoU64s
107 rust_dbg_extern_return_TwoU64s() {
108     struct TwoU64s s;
109     s.one = 10;
110     s.two = 20;
111     return s;
112 }
113
114 struct TwoU64s
115 rust_dbg_extern_identity_TwoU64s(struct TwoU64s u) {
116     return u;
117 }
118
119 struct TwoDoubles {
120     double one;
121     double two;
122 };
123
124 struct TwoDoubles
125 rust_dbg_extern_identity_TwoDoubles(struct TwoDoubles u) {
126     return u;
127 }
128
129 intptr_t
130 rust_get_test_int() {
131   return 1;
132 }
133
134 /* Debug helpers strictly to verify ABI conformance.
135  *
136  * FIXME (#2665): move these into a testcase when the testsuite
137  * understands how to have explicit C files included.
138  */
139
140 struct quad {
141     uint64_t a;
142     uint64_t b;
143     uint64_t c;
144     uint64_t d;
145 };
146
147 struct floats {
148     double a;
149     uint8_t b;
150     double c;
151 };
152
153 struct quad
154 rust_dbg_abi_1(struct quad q) {
155     struct quad qq = { q.c + 1,
156                        q.d - 1,
157                        q.a + 1,
158                        q.b - 1 };
159     return qq;
160 }
161
162 struct floats
163 rust_dbg_abi_2(struct floats f) {
164     struct floats ff = { f.c + 1.0,
165                          0xff,
166                          f.a - 1.0 };
167     return ff;
168 }
169
170 int
171 rust_dbg_static_mut;
172
173 int rust_dbg_static_mut = 3;
174
175 void
176 rust_dbg_static_mut_check_four() {
177     assert(rust_dbg_static_mut == 4);
178 }