Rietveld Code Review Tool
Help | Bug tracker | Discussion group | Source code | Sign in
(79366)

Side by Side Diff: Tools/iOS-test/iOS-test/main.m

Issue 23670: Modifications to support iOS as a development platform
Patch Set: Created 3 years, 8 months ago
Left:
Right:
Use n/p to move between diff chunks; N/P to move between comments. Please Sign in to add in-line comments.
Jump to:
View unified diff | Download patch
OLDNEW
(Empty)
1 //
2 // main.m
3 // A main module for starting Python projects under iOS.
4 //
5
6 #import <Foundation/Foundation.h>
7 #import <UIKit/UIKit.h>
8 #include <Python/Python.h>
9 #include <dlfcn.h>
10
11 int main(int argc, char *argv[]) {
12 int ret = 0;
13 unsigned int i;
14 NSString *tmp_path;
15 NSString *exe;
16 NSString *python_home;
17 wchar_t *wpython_home;
18 const char* main_script;
19 wchar_t** python_argv;
20 @autoreleasepool {
21
22 NSString * resourcePath = [[NSBundle mainBundle] resourcePath];
23
24 // Special environment to avoid writing bytecode because
25 // the process will not have write attribute on the device.
26 putenv("PYTHONDONTWRITEBYTECODE=1");
27
28 python_home = [NSString stringWithFormat:@"%@/Library/Python.framework/R esources", resourcePath, nil];
29 NSLog(@"PythonHome is: %@", python_home);
30 wpython_home = _Py_char2wchar([python_home UTF8String], NULL);
31 Py_SetPythonHome(wpython_home);
32
33 // iOS provides a specific directory for temp files.
34 tmp_path = [NSString stringWithFormat:@"TMP=%@/tmp", resourcePath, nil];
35 putenv((char *)[tmp_path UTF8String]);
36
37 // Since iOS doesn't allow dynamic linking, we have to know
38 // the name of the executable so that we can find the ctypes
39 // test objects. However, sys.argv[0] will be updated to
40 // reflect the script name; the TEST_EXECUTABLE environment
41 // variable provides the mechanism for specifying the filename.
42 exe = [NSString stringWithFormat:@"TEST_EXECUTABLE=%s", argv[0], nil];
43 putenv((char *)[exe UTF8String]);
44
45 NSLog(@"Initializing Python runtime...");
46 Py_Initialize();
47
48 /*******************************************************
49 To tell lldb not to stop on signals, use the following commands:
50 process handle SIGPIPE -n true -p true -s false
51 process handle SIGINT -n true -p true -s false
52 process handle SIGXFSZ -n true -p true -s false
53 process handle SIGUSR1 -n true -p true -s false
54 process handle SIGUSR2 -n true -p true -s false
55 *******************************************************/
56
57 // Arguments to pass to test runner
58 char *test_args[] = {
59 "-j", "1",
60 "-u", "all,-audio,-curses,-largefile,-subprocess,-gui",
61 // "-v", // Verbose test output
62 "-W", // Display test output on failure
63
64 "-x", // Arguments are tests to *exclude*
65 // ARM64 failures
66 // "test_unicode", // # ctypes related; PyUnicode_FromFormat
67
68 // ARMv7 failures
69 // "test_cmath", // math domain error
70 // "test_ctypes", // DL loading?
71 // "test_float", // rounding?
72 // "test_math", // math domain error
73 // "test_numeric_tower", //
74 // "test_strtod", //
75 "test_importlib", // Thread locking problem
76
77 // Fails on BOTH
78 // "test_ctypes", // DL loading?
79 // "test_socket", // Fails due to bad domain? Fails on simula tor, OS/X, too.
80 // "test_threading", // ctypes related; missing symbol PyThreadS tate_SetAsyncExc
81
82 // Hard crash on BOTH
83 "test_bytes" // ctypes related; PyBytes_FromFormat
84
85 };
86
87 // Set the name of the main script
88 main_script = [
89 [[NSBundle mainBundle] pathForResource:@"Library/Application Support /org.python.iOS-test/app/iOS-test/main"
90 ofType:@"py"] cStringUsingEncoding:N SUTF8StringEncoding];
91
92 if (main_script == NULL) {
93 NSLog(@"Unable to locate app/iOS-test/main.py file");
94 exit(-1);
95 }
96
97 // Construct argv for the interpreter
98 int n_test_args = sizeof(test_args) / sizeof (*test_args) + 1;
99
100 python_argv = PyMem_RawMalloc(sizeof(wchar_t*) * n_test_args);
101 python_argv[0] = _Py_char2wchar(main_script, NULL);
102 for (i = 1; i < n_test_args; i++) {
103 python_argv[i] = _Py_char2wchar(test_args[i-1], NULL);
104 }
105
106 PySys_SetArgv(n_test_args, python_argv);
107
108 // If other modules are using thread, we need to initialize them before.
109 PyEval_InitThreads();
110
111 // Start the main.py script
112 NSLog(@"Running %s", main_script);
113
114 @try {
115 FILE* fd = fopen(main_script, "r");
116 if (fd == NULL) {
117 ret = 1;
118 NSLog(@"Unable to open main.py, abort.");
119 } else {
120 ret = PyRun_SimpleFileEx(fd, main_script, 1);
121 if (ret != 0) {
122 NSLog(@"Application quit abnormally!");
123 }
124 }
125 }
126 @catch (NSException *exception) {
127 NSLog(@"Python runtime error: %@", [exception reason]);
128 }
129 @finally {
130 Py_Finalize();
131 }
132
133 PyMem_RawFree(wpython_home);
134 if (python_argv) {
135 for (i = 0; i < argc; i++) {
136 PyMem_RawFree(python_argv[i]);
137 }
138 PyMem_RawFree(python_argv);
139 }
140 NSLog(@"Leaving");
141 }
142
143 exit(ret);
144 return ret;
145 }
OLDNEW
« no previous file with comments | « Tools/iOS-test/iOS-test/iOS-test-Prefix.pch ('k') | Tools/iOS-test/iOS-test.xcodeproj/project.pbxproj » ('j') | no next file with comments »

RSS Feeds Recent Issues | This issue
This is Rietveld 894c83f36cb7+