| 1 |
|
| 2 |
""" File containing darwin platform tests |
| 3 |
""" |
| 4 |
|
| 5 |
import py, sys, platform |
| 6 |
if sys.platform != 'darwin': |
| 7 |
py.test.skip("Darwin only") |
| 8 |
|
| 9 |
from rpython.tool.udir import udir |
| 10 |
from rpython.translator.platform.darwin import Darwin_i386, Darwin_x86_64, Darwin_PowerPC, Darwin_arm64 |
| 11 |
from rpython.translator.platform.test.test_platform import TestPlatform as BasicTest |
| 12 |
from rpython.translator.tool.cbuild import ExternalCompilationInfo |
| 13 |
|
| 14 |
if platform.machine() == 'i386': |
| 15 |
if sys.maxint <= 2147483647: |
| 16 |
host_factory = Darwin_i386 |
| 17 |
else: |
| 18 |
host_factory = Darwin_x86_64 |
| 19 |
elif platform.machine() == 'x86_64': |
| 20 |
host_factory = Darwin_x86_64 |
| 21 |
elif platform.machine() == 'arm64': |
| 22 |
host_factory = Darwin_arm64 |
| 23 |
else: |
| 24 |
host_factory = Darwin_PowerPC |
| 25 |
|
| 26 |
def is_x86(): |
| 27 |
return platform.machine() == 'i386' or platform.machine() == 'x86_64' |
| 28 |
|
| 29 |
class TestDarwin(BasicTest): |
| 30 |
platform = host_factory() |
| 31 |
|
| 32 |
def test_frameworks(self): |
| 33 |
objcfile = udir.join('test_simple.m') |
| 34 |
objcfile.write(r''' |
| 35 |
#import <Foundation/Foundation.h> |
| 36 |
#include "test.h" |
| 37 |
|
| 38 |
int main (int argc, const char * argv[]) { |
| 39 |
NSAutoreleasePool *pool = [[NSAutoreleasePool alloc] init]; |
| 40 |
NSArray *args = [[NSProcessInfo processInfo] arguments]; |
| 41 |
NSCountedSet *cset = [[NSCountedSet alloc] initWithArray:args]; |
| 42 |
|
| 43 |
printf("%d\n", XXX_STUFF); |
| 44 |
|
| 45 |
[cset release]; |
| 46 |
[pool release]; |
| 47 |
return 0; |
| 48 |
} |
| 49 |
''') |
| 50 |
includedir = py.path.local(__file__).dirpath().join('include') |
| 51 |
eci = ExternalCompilationInfo(frameworks=('Cocoa',), |
| 52 |
include_dirs=(includedir,)) |
| 53 |
executable = self.platform.compile([objcfile], eci) |
| 54 |
res = self.platform.execute(executable) |
| 55 |
self.check_res(res) |
| 56 |
|
| 57 |
def test_frameworks_with_makefile(self): |
| 58 |
from StringIO import StringIO |
| 59 |
tmpdir = udir.join('fw_mk' + self.__class__.__name__).ensure(dir=1) |
| 60 |
objcfile = tmpdir.join('test_simple.m') |
| 61 |
objcfile.write(r''' |
| 62 |
#import <Foundation/Foundation.h> |
| 63 |
int main (int argc, const char * argv[]) { |
| 64 |
NSAutoreleasePool *pool = [[NSAutoreleasePool alloc] init]; |
| 65 |
NSArray *args = [[NSProcessInfo processInfo] arguments]; |
| 66 |
NSCountedSet *cset = [[NSCountedSet alloc] initWithArray:args]; |
| 67 |
|
| 68 |
printf("%d\n", 23); |
| 69 |
|
| 70 |
[cset release]; |
| 71 |
[pool release]; |
| 72 |
return 0; |
| 73 |
} |
| 74 |
''') |
| 75 |
eci = ExternalCompilationInfo(frameworks=('Cocoa',)) |
| 76 |
mk = self.platform.gen_makefile([objcfile], eci, path=tmpdir) |
| 77 |
|
| 78 |
out = StringIO() |
| 79 |
mk.write(out) |
| 80 |
assert "-framework Cocoa" in out.getvalue() |
| 81 |
|
| 82 |
mk.write() |
| 83 |
self.platform.execute_makefile(mk) |
| 84 |
res = self.platform.execute(tmpdir.join('test_simple')) |
| 85 |
self.check_res(res, expected="23\n") |
| 86 |
|
| 87 |
|
| 88 |
@py.test.skip("i386 not supported any more") |
| 89 |
def test_64_32_results(self): |
| 90 |
py.test.skip("i386 not supported any more") |
| 91 |
if not is_x86(): |
| 92 |
py.test.skip("i386 only") |
| 93 |
plat32 = Darwin_i386() |
| 94 |
plat64 = Darwin_x86_64() |
| 95 |
cfile = udir.join('test_int_size.c') |
| 96 |
cfile.write(r''' |
| 97 |
#include <stdio.h> |
| 98 |
#include <limits.h> |
| 99 |
|
| 100 |
int main() { |
| 101 |
printf("%d\n", INT_MAX < LONG_MAX); |
| 102 |
return 0; |
| 103 |
} |
| 104 |
''') |
| 105 |
eci = ExternalCompilationInfo() |
| 106 |
executable = plat32.compile([cfile], eci) |
| 107 |
res = plat32.execute(executable) |
| 108 |
self.check_res(res, '0\n') |
| 109 |
if host_factory == Darwin_x86_64: |
| 110 |
executable = plat64.compile([cfile], eci) |
| 111 |
res = plat64.execute(executable) |
| 112 |
self.check_res(res, '1\n') |
| 113 |
|
| 114 |
def test_longsize(self): |
| 115 |
if not is_x86(): |
| 116 |
py.test.skip("i386 only") |
| 117 |
cfile = udir.join('test_int_size.c') |
| 118 |
cfile.write(r''' |
| 119 |
#include <stdio.h> |
| 120 |
#include <limits.h> |
| 121 |
|
| 122 |
int main() { |
| 123 |
printf("%ld\n", LONG_MAX); |
| 124 |
return 0; |
| 125 |
} |
| 126 |
''') |
| 127 |
eci = ExternalCompilationInfo() |
| 128 |
executable = self.platform.compile([cfile], eci) |
| 129 |
res = self.platform.execute(executable) |
| 130 |
self.check_res(res, str(sys.maxint) + '\n') |
| 131 |
|
| 132 |
@py.test.skip("i386 not supported any more") |
| 133 |
def test_32bit_makefile(self): |
| 134 |
if not is_x86(): |
| 135 |
py.test.skip("i386 only") |
| 136 |
plat32 = Darwin_i386() |
| 137 |
plat64 = Darwin_x86_64() |
| 138 |
eci = ExternalCompilationInfo() |
| 139 |
cfile_content =r''' |
| 140 |
#include <stdio.h> |
| 141 |
#include <limits.h> |
| 142 |
|
| 143 |
int main() { |
| 144 |
printf("%d\n", INT_MAX < LONG_MAX); |
| 145 |
return 0; |
| 146 |
} |
| 147 |
''' |
| 148 |
|
| 149 |
tmpdir = udir.join('32_makefile' + self.__class__.__name__).ensure(dir=1) |
| 150 |
cfile = tmpdir.join('test_int_size.c') |
| 151 |
cfile.write(cfile_content) |
| 152 |
mk = plat32.gen_makefile([cfile], ExternalCompilationInfo(), |
| 153 |
path=tmpdir) |
| 154 |
mk.write() |
| 155 |
plat32.execute_makefile(mk) |
| 156 |
res = plat32.execute(tmpdir.join('test_int_size')) |
| 157 |
self.check_res(res, '0\n') |
| 158 |
if host_factory == Darwin_x86_64: |
| 159 |
tmpdir = udir.join('64_makefile' + self.__class__.__name__).ensure(dir=1) |
| 160 |
cfile = tmpdir.join('test_int_size.c') |
| 161 |
cfile.write(cfile_content) |
| 162 |
mk = plat64.gen_makefile([cfile], ExternalCompilationInfo(), |
| 163 |
path=tmpdir) |
| 164 |
mk.write() |
| 165 |
plat64.execute_makefile(mk) |
| 166 |
res = plat64.execute(tmpdir.join('test_int_size')) |
| 167 |
self.check_res(res, '1\n') |