]> git.saurik.com Git - apple/dyld.git/blob - unit-tests/test-cases/lazy-binding-reg-params/main.c
dyld-45.3.tar.gz
[apple/dyld.git] / unit-tests / test-cases / lazy-binding-reg-params / main.c
1 /*
2 * Copyright (c) 2005 Apple Computer, Inc. All rights reserved.
3 *
4 * @APPLE_LICENSE_HEADER_START@
5 *
6 * This file contains Original Code and/or Modifications of Original Code
7 * as defined in and that are subject to the Apple Public Source License
8 * Version 2.0 (the 'License'). You may not use this file except in
9 * compliance with the License. Please obtain a copy of the License at
10 * http://www.opensource.apple.com/apsl/ and read it before using this
11 * file.
12 *
13 * The Original Code and all software distributed under the License are
14 * distributed on an 'AS IS' basis, WITHOUT WARRANTY OF ANY KIND, EITHER
15 * EXPRESS OR IMPLIED, AND APPLE HEREBY DISCLAIMS ALL SUCH WARRANTIES,
16 * INCLUDING WITHOUT LIMITATION, ANY WARRANTIES OF MERCHANTABILITY,
17 * FITNESS FOR A PARTICULAR PURPOSE, QUIET ENJOYMENT OR NON-INFRINGEMENT.
18 * Please see the License for the specific language governing rights and
19 * limitations under the License.
20 *
21 * @APPLE_LICENSE_HEADER_END@
22 */
23 #include <stdbool.h>
24 #include <stdio.h> // fprintf(), NULL
25 #include <stdlib.h> // exit(), EXIT_SUCCESS
26 #include <dlfcn.h>
27 #include <sys/sysctl.h>
28
29 #include "test.h" // PASS(), FAIL(), XPASS(), XFAIL()
30
31
32 ///
33 /// rdar://problem/4132378 support __attribute__((regparm()))
34 ///
35 /// The stub binding helper for dyld needs to preserve registers
36 ///
37
38
39 #include "foo.h"
40
41
42 static bool inttest()
43 {
44 return dointtest(123,456,789,4444,55555);
45 }
46
47 static bool floattest()
48 {
49 #if __ppc__ || __ppc64__
50 return dofloattest(1.0,2.0,3.0,4.0,5.0,6.0,7.0,8.0,9.0,10.0,11.0,12.0,13.0);
51 #elif __i386__
52 return true;
53 #else
54 #error unknown architecture
55 #endif
56 }
57
58 static bool vectorSupport()
59 {
60 #if __ppc__
61 uint32_t value;
62 size_t size=sizeof(uint32_t);
63 int err = sysctlbyname("hw.optional.altivec", &value, &size, NULL, 0);
64 //fprintf(stderr, "sysctlbyname() = %d\n", err);
65 return ( err == 0 );
66 #else
67 return true;
68 #endif
69 }
70
71
72 static bool vectortest()
73 {
74 vFloat p1 = { 1.1, 1.2, 1.3, 1.4 };
75 vFloat p2 = { 2.1, 2.2, 2.3, 2.4 };
76 vFloat p3 = { 3.1, 3.2, 3.3, 3.4 };
77 vFloat p4 = { 4.1, 4.2, 4.3, 4.4 };
78 vFloat p5 = { 5.1, 5.2, 5.3, 5.4 };
79 return dovectortest(p1, p2, p3, p4, p5);
80 }
81
82 int main()
83 {
84 if ( ! inttest() ) {
85 FAIL("lazy-binding-reg-params int parameters");
86 return EXIT_SUCCESS;
87 }
88
89 if ( ! floattest() ) {
90 FAIL("lazy-binding-reg-params float parameters");
91 return EXIT_SUCCESS;
92 }
93
94 if ( vectorSupport() && ! vectortest() ) {
95 FAIL("lazy-binding-reg-params vector parameters");
96 return EXIT_SUCCESS;
97 }
98
99 PASS("lazy-binding-reg-params");
100 return EXIT_SUCCESS;
101 }