]> git.lizzy.rs Git - rust.git/blob - src/rt/rust_test_helpers.c
Move runtime files to C instead of C++
[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 "rust_globals.h"
14
15 // These functions are used in the unit tests for C ABI calls.
16
17 uint32_t
18 rust_dbg_extern_identity_u32(uint32_t u) {
19     return u;
20 }
21
22 uint64_t
23 rust_dbg_extern_identity_u64(uint64_t u) {
24     return u;
25 }
26
27 double
28 rust_dbg_extern_identity_double(double u) {
29     return u;
30 }
31
32 char
33 rust_dbg_extern_identity_u8(char u) {
34     return u;
35 }
36
37 typedef void *(*dbg_callback)(void*);
38
39 void *
40 rust_dbg_call(dbg_callback cb, void *data) {
41     return cb(data);
42 }
43
44 void rust_dbg_do_nothing() { }
45
46 struct TwoU8s {
47     uint8_t one;
48     uint8_t two;
49 };
50
51 struct TwoU8s
52 rust_dbg_extern_return_TwoU8s() {
53     struct TwoU8s s;
54     s.one = 10;
55     s.two = 20;
56     return s;
57 }
58
59 struct TwoU8s
60 rust_dbg_extern_identity_TwoU8s(struct TwoU8s u) {
61     return u;
62 }
63
64 struct TwoU16s {
65     uint16_t one;
66     uint16_t two;
67 };
68
69 struct TwoU16s
70 rust_dbg_extern_return_TwoU16s() {
71     struct TwoU16s s;
72     s.one = 10;
73     s.two = 20;
74     return s;
75 }
76
77 struct TwoU16s
78 rust_dbg_extern_identity_TwoU16s(struct TwoU16s u) {
79     return u;
80 }
81
82 struct TwoU32s {
83     uint32_t one;
84     uint32_t two;
85 };
86
87 struct TwoU32s
88 rust_dbg_extern_return_TwoU32s() {
89     struct TwoU32s s;
90     s.one = 10;
91     s.two = 20;
92     return s;
93 }
94
95 struct TwoU32s
96 rust_dbg_extern_identity_TwoU32s(struct TwoU32s u) {
97     return u;
98 }
99
100 struct TwoU64s {
101     uint64_t one;
102     uint64_t two;
103 };
104
105 struct TwoU64s
106 rust_dbg_extern_return_TwoU64s() {
107     struct TwoU64s s;
108     s.one = 10;
109     s.two = 20;
110     return s;
111 }
112
113 struct TwoU64s
114 rust_dbg_extern_identity_TwoU64s(struct TwoU64s u) {
115     return u;
116 }
117
118 struct TwoDoubles {
119     double one;
120     double two;
121 };
122
123 struct TwoDoubles
124 rust_dbg_extern_identity_TwoDoubles(struct TwoDoubles u) {
125     return u;
126 }
127
128 intptr_t
129 rust_get_test_int() {
130   return 1;
131 }
132
133 /* Debug helpers strictly to verify ABI conformance.
134  *
135  * FIXME (#2665): move these into a testcase when the testsuite
136  * understands how to have explicit C files included.
137  */
138
139 struct quad {
140     uint64_t a;
141     uint64_t b;
142     uint64_t c;
143     uint64_t d;
144 };
145
146 struct floats {
147     double a;
148     uint8_t b;
149     double c;
150 };
151
152 struct quad
153 rust_dbg_abi_1(struct quad q) {
154     struct quad qq = { q.c + 1,
155                        q.d - 1,
156                        q.a + 1,
157                        q.b - 1 };
158     return qq;
159 }
160
161 struct floats
162 rust_dbg_abi_2(struct floats f) {
163     struct floats ff = { f.c + 1.0,
164                          0xff,
165                          f.a - 1.0 };
166     return ff;
167 }
168
169 int
170 rust_dbg_static_mut;
171
172 int rust_dbg_static_mut = 3;
173
174 void
175 rust_dbg_static_mut_check_four() {
176     assert(rust_dbg_static_mut == 4);
177 }