]>
git.proxmox.com Git - rustc.git/blob - 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.
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.
11 // Helper functions used only in tests
17 // These functions are used in the unit tests for C ABI calls.
20 rust_dbg_extern_identity_u32(uint32_t u
) {
25 rust_dbg_extern_identity_u64(uint64_t u
) {
30 rust_dbg_extern_identity_double(double u
) {
35 rust_dbg_extern_identity_u8(char u
) {
39 typedef void *(*dbg_callback
)(void*);
42 rust_dbg_call(dbg_callback cb
, void *data
) {
46 void rust_dbg_do_nothing() { }
54 rust_dbg_extern_return_TwoU8s() {
62 rust_dbg_extern_identity_TwoU8s(struct TwoU8s u
) {
72 rust_dbg_extern_return_TwoU16s() {
80 rust_dbg_extern_identity_TwoU16s(struct TwoU16s u
) {
90 rust_dbg_extern_return_TwoU32s() {
98 rust_dbg_extern_identity_TwoU32s(struct TwoU32s u
) {
108 rust_dbg_extern_return_TwoU64s() {
116 rust_dbg_extern_identity_TwoU64s(struct TwoU64s u
) {
126 rust_dbg_extern_identity_TwoDoubles(struct TwoDoubles u
) {
139 // MSVC doesn't allow empty structs or unions
145 rust_dbg_extern_empty_struct(struct ManyInts v1
, struct Empty e
, struct ManyInts v2
) {
146 assert(v1
.arg1
== v2
.arg1
+ 1);
147 assert(v1
.arg2
== v2
.arg2
+ 1);
148 assert(v1
.arg3
== v2
.arg3
+ 1);
149 assert(v1
.arg4
== v2
.arg4
+ 1);
150 assert(v1
.arg5
== v2
.arg5
+ 1);
151 assert(v1
.arg6
.one
== v2
.arg6
.one
+ 1);
152 assert(v1
.arg6
.two
== v2
.arg6
.two
+ 1);
157 rust_get_test_int() {
162 rust_get_null_ptr() {
166 /* Debug helpers strictly to verify ABI conformance.
168 * FIXME (#2665): move these into a testcase when the testsuite
169 * understands how to have explicit C files included.
186 rust_dbg_abi_1(struct quad q
) {
187 struct quad qq
= { q
.c
+ 1,
195 rust_dbg_abi_2(struct floats f
) {
196 struct floats ff
= { f
.c
+ 1.0,
203 rust_dbg_static_mut
= 3;
206 rust_dbg_static_mut_check_four() {
207 assert(rust_dbg_static_mut
== 4);
216 uint64_t get_x(struct S s
) {
220 uint64_t get_y(struct S s
) {
224 uint64_t get_z(struct S s
) {
228 uint64_t get_c_many_params(void *a
, void *b
, void *c
, void *d
, struct quad f
) {
232 // Calculates the average of `(x + y) / n` where x: i64, y: f64. There must be exactly n pairs
233 // passed as variadic arguments.
234 double rust_interesting_average(uint64_t n
, ...) {
239 for(i
= 0; i
< n
; i
+= 1) {
240 sum
+= (double)va_arg(pairs
, int64_t);
241 sum
+= va_arg(pairs
, double);
247 int32_t rust_int8_to_int32(int8_t x
) {