Victor Stinner | 91c9987 | 2019-05-14 22:01:51 +0200 | [diff] [blame] | 1 | #ifndef Py_BUILD_CORE_MODULE |
| 2 | # define Py_BUILD_CORE_MODULE |
| 3 | #endif |
| 4 | |
Miss Islington (bot) | 4062841 | 2019-06-06 05:42:53 -0700 | [diff] [blame] | 5 | /* Always enable assertion (even in release mode) */ |
| 6 | #undef NDEBUG |
| 7 | |
Antoine Pitrou | 8e60577 | 2011-04-25 21:21:07 +0200 | [diff] [blame] | 8 | #include <Python.h> |
Miss Islington (bot) | 4062841 | 2019-06-06 05:42:53 -0700 | [diff] [blame] | 9 | #include "pycore_initconfig.h" /* _PyConfig_InitCompatConfig() */ |
| 10 | #include "pycore_pystate.h" /* _PyRuntime */ |
Victor Stinner | bab0db6 | 2019-05-18 03:21:27 +0200 | [diff] [blame] | 11 | #include <Python.h> |
Victor Stinner | b4d1e1f | 2017-11-30 22:05:00 +0100 | [diff] [blame] | 12 | #include "pythread.h" |
Eric Snow | e377416 | 2017-05-22 19:46:40 -0700 | [diff] [blame] | 13 | #include <inttypes.h> |
Antoine Pitrou | 8e60577 | 2011-04-25 21:21:07 +0200 | [diff] [blame] | 14 | #include <stdio.h> |
Nick Coghlan | bc77eff | 2018-03-25 20:44:30 +1000 | [diff] [blame] | 15 | #include <wchar.h> |
Antoine Pitrou | 8e60577 | 2011-04-25 21:21:07 +0200 | [diff] [blame] | 16 | |
Nick Coghlan | 7d270ee | 2013-10-17 22:35:35 +1000 | [diff] [blame] | 17 | /********************************************************* |
| 18 | * Embedded interpreter tests that need a custom exe |
| 19 | * |
| 20 | * Executed via 'EmbeddingTests' in Lib/test/test_capi.py |
| 21 | *********************************************************/ |
| 22 | |
Victor Stinner | 96c8475 | 2019-09-26 16:17:34 +0200 | [diff] [blame] | 23 | /* Use path starting with "./" avoids a search along the PATH */ |
| 24 | #define PROGRAM_NAME L"./_testembed" |
| 25 | |
Nick Coghlan | 7d270ee | 2013-10-17 22:35:35 +1000 | [diff] [blame] | 26 | static void _testembed_Py_Initialize(void) |
| 27 | { |
Victor Stinner | 96c8475 | 2019-09-26 16:17:34 +0200 | [diff] [blame] | 28 | Py_SetProgramName(PROGRAM_NAME); |
Nick Coghlan | 7d270ee | 2013-10-17 22:35:35 +1000 | [diff] [blame] | 29 | Py_Initialize(); |
| 30 | } |
| 31 | |
| 32 | |
| 33 | /***************************************************** |
Martin Panter | 8f26565 | 2016-04-19 04:03:41 +0000 | [diff] [blame] | 34 | * Test repeated initialisation and subinterpreters |
Nick Coghlan | 7d270ee | 2013-10-17 22:35:35 +1000 | [diff] [blame] | 35 | *****************************************************/ |
| 36 | |
| 37 | static void print_subinterp(void) |
Antoine Pitrou | 8e60577 | 2011-04-25 21:21:07 +0200 | [diff] [blame] | 38 | { |
Eric Snow | e377416 | 2017-05-22 19:46:40 -0700 | [diff] [blame] | 39 | /* Output information about the interpreter in the format |
| 40 | expected in Lib/test/test_capi.py (test_subinterps). */ |
Antoine Pitrou | 8e60577 | 2011-04-25 21:21:07 +0200 | [diff] [blame] | 41 | PyThreadState *ts = PyThreadState_Get(); |
Eric Snow | e377416 | 2017-05-22 19:46:40 -0700 | [diff] [blame] | 42 | PyInterpreterState *interp = ts->interp; |
| 43 | int64_t id = PyInterpreterState_GetID(interp); |
Eric Snow | d1c3c13 | 2017-05-24 17:19:47 -0700 | [diff] [blame] | 44 | printf("interp %" PRId64 " <0x%" PRIXPTR ">, thread state <0x%" PRIXPTR ">: ", |
Eric Snow | e377416 | 2017-05-22 19:46:40 -0700 | [diff] [blame] | 45 | id, (uintptr_t)interp, (uintptr_t)ts); |
Antoine Pitrou | 8e60577 | 2011-04-25 21:21:07 +0200 | [diff] [blame] | 46 | fflush(stdout); |
| 47 | PyRun_SimpleString( |
| 48 | "import sys;" |
| 49 | "print('id(modules) =', id(sys.modules));" |
| 50 | "sys.stdout.flush()" |
| 51 | ); |
| 52 | } |
| 53 | |
Steve Dower | ea74f0c | 2017-01-01 20:25:03 -0800 | [diff] [blame] | 54 | static int test_repeated_init_and_subinterpreters(void) |
Antoine Pitrou | 8e60577 | 2011-04-25 21:21:07 +0200 | [diff] [blame] | 55 | { |
| 56 | PyThreadState *mainstate, *substate; |
| 57 | PyGILState_STATE gilstate; |
| 58 | int i, j; |
| 59 | |
Ned Deily | 939231b | 2016-08-16 00:17:42 -0400 | [diff] [blame] | 60 | for (i=0; i<15; i++) { |
Antoine Pitrou | 8e60577 | 2011-04-25 21:21:07 +0200 | [diff] [blame] | 61 | printf("--- Pass %d ---\n", i); |
Nick Coghlan | 7d270ee | 2013-10-17 22:35:35 +1000 | [diff] [blame] | 62 | _testembed_Py_Initialize(); |
Antoine Pitrou | 8e60577 | 2011-04-25 21:21:07 +0200 | [diff] [blame] | 63 | mainstate = PyThreadState_Get(); |
| 64 | |
| 65 | PyEval_InitThreads(); |
| 66 | PyEval_ReleaseThread(mainstate); |
| 67 | |
| 68 | gilstate = PyGILState_Ensure(); |
| 69 | print_subinterp(); |
| 70 | PyThreadState_Swap(NULL); |
| 71 | |
| 72 | for (j=0; j<3; j++) { |
| 73 | substate = Py_NewInterpreter(); |
| 74 | print_subinterp(); |
| 75 | Py_EndInterpreter(substate); |
| 76 | } |
| 77 | |
| 78 | PyThreadState_Swap(mainstate); |
| 79 | print_subinterp(); |
| 80 | PyGILState_Release(gilstate); |
Antoine Pitrou | 8e60577 | 2011-04-25 21:21:07 +0200 | [diff] [blame] | 81 | |
| 82 | PyEval_RestoreThread(mainstate); |
| 83 | Py_Finalize(); |
| 84 | } |
Steve Dower | ea74f0c | 2017-01-01 20:25:03 -0800 | [diff] [blame] | 85 | return 0; |
Nick Coghlan | 7d270ee | 2013-10-17 22:35:35 +1000 | [diff] [blame] | 86 | } |
| 87 | |
| 88 | /***************************************************** |
| 89 | * Test forcing a particular IO encoding |
| 90 | *****************************************************/ |
| 91 | |
| 92 | static void check_stdio_details(const char *encoding, const char * errors) |
| 93 | { |
| 94 | /* Output info for the test case to check */ |
| 95 | if (encoding) { |
| 96 | printf("Expected encoding: %s\n", encoding); |
| 97 | } else { |
| 98 | printf("Expected encoding: default\n"); |
| 99 | } |
| 100 | if (errors) { |
| 101 | printf("Expected errors: %s\n", errors); |
| 102 | } else { |
| 103 | printf("Expected errors: default\n"); |
| 104 | } |
| 105 | fflush(stdout); |
| 106 | /* Force the given IO encoding */ |
| 107 | Py_SetStandardStreamEncoding(encoding, errors); |
| 108 | _testembed_Py_Initialize(); |
| 109 | PyRun_SimpleString( |
| 110 | "import sys;" |
| 111 | "print('stdin: {0.encoding}:{0.errors}'.format(sys.stdin));" |
| 112 | "print('stdout: {0.encoding}:{0.errors}'.format(sys.stdout));" |
| 113 | "print('stderr: {0.encoding}:{0.errors}'.format(sys.stderr));" |
| 114 | "sys.stdout.flush()" |
| 115 | ); |
| 116 | Py_Finalize(); |
| 117 | } |
| 118 | |
Steve Dower | ea74f0c | 2017-01-01 20:25:03 -0800 | [diff] [blame] | 119 | static int test_forced_io_encoding(void) |
Nick Coghlan | 7d270ee | 2013-10-17 22:35:35 +1000 | [diff] [blame] | 120 | { |
| 121 | /* Check various combinations */ |
| 122 | printf("--- Use defaults ---\n"); |
| 123 | check_stdio_details(NULL, NULL); |
| 124 | printf("--- Set errors only ---\n"); |
Victor Stinner | b2bef62 | 2014-03-18 02:38:12 +0100 | [diff] [blame] | 125 | check_stdio_details(NULL, "ignore"); |
Nick Coghlan | 7d270ee | 2013-10-17 22:35:35 +1000 | [diff] [blame] | 126 | printf("--- Set encoding only ---\n"); |
Victor Stinner | 9e4994d | 2018-08-28 23:26:33 +0200 | [diff] [blame] | 127 | check_stdio_details("iso8859-1", NULL); |
Nick Coghlan | 7d270ee | 2013-10-17 22:35:35 +1000 | [diff] [blame] | 128 | printf("--- Set encoding and errors ---\n"); |
Victor Stinner | 9e4994d | 2018-08-28 23:26:33 +0200 | [diff] [blame] | 129 | check_stdio_details("iso8859-1", "replace"); |
Nick Coghlan | 7d270ee | 2013-10-17 22:35:35 +1000 | [diff] [blame] | 130 | |
| 131 | /* Check calling after initialization fails */ |
| 132 | Py_Initialize(); |
| 133 | |
| 134 | if (Py_SetStandardStreamEncoding(NULL, NULL) == 0) { |
| 135 | printf("Unexpected success calling Py_SetStandardStreamEncoding"); |
| 136 | } |
| 137 | Py_Finalize(); |
Steve Dower | ea74f0c | 2017-01-01 20:25:03 -0800 | [diff] [blame] | 138 | return 0; |
Nick Coghlan | 7d270ee | 2013-10-17 22:35:35 +1000 | [diff] [blame] | 139 | } |
| 140 | |
Victor Stinner | 9e87e77 | 2017-11-24 12:09:24 +0100 | [diff] [blame] | 141 | /********************************************************* |
| 142 | * Test parts of the C-API that work before initialization |
| 143 | *********************************************************/ |
| 144 | |
Nick Coghlan | bc77eff | 2018-03-25 20:44:30 +1000 | [diff] [blame] | 145 | /* The pre-initialization tests tend to break by segfaulting, so explicitly |
| 146 | * flushed progress messages make the broken API easier to find when they fail. |
| 147 | */ |
| 148 | #define _Py_EMBED_PREINIT_CHECK(msg) \ |
| 149 | do {printf(msg); fflush(stdout);} while (0); |
| 150 | |
Victor Stinner | 9e87e77 | 2017-11-24 12:09:24 +0100 | [diff] [blame] | 151 | static int test_pre_initialization_api(void) |
| 152 | { |
Victor Stinner | a9df651 | 2019-03-05 23:31:54 +0100 | [diff] [blame] | 153 | /* the test doesn't support custom memory allocators */ |
| 154 | putenv("PYTHONMALLOC="); |
| 155 | |
Nick Coghlan | 4274609 | 2017-11-26 14:19:13 +1000 | [diff] [blame] | 156 | /* Leading "./" ensures getpath.c can still find the standard library */ |
Nick Coghlan | bc77eff | 2018-03-25 20:44:30 +1000 | [diff] [blame] | 157 | _Py_EMBED_PREINIT_CHECK("Checking Py_DecodeLocale\n"); |
Nick Coghlan | 4274609 | 2017-11-26 14:19:13 +1000 | [diff] [blame] | 158 | wchar_t *program = Py_DecodeLocale("./spam", NULL); |
Victor Stinner | 9e87e77 | 2017-11-24 12:09:24 +0100 | [diff] [blame] | 159 | if (program == NULL) { |
| 160 | fprintf(stderr, "Fatal error: cannot decode program name\n"); |
| 161 | return 1; |
| 162 | } |
Nick Coghlan | bc77eff | 2018-03-25 20:44:30 +1000 | [diff] [blame] | 163 | _Py_EMBED_PREINIT_CHECK("Checking Py_SetProgramName\n"); |
Victor Stinner | 9e87e77 | 2017-11-24 12:09:24 +0100 | [diff] [blame] | 164 | Py_SetProgramName(program); |
| 165 | |
Nick Coghlan | bc77eff | 2018-03-25 20:44:30 +1000 | [diff] [blame] | 166 | _Py_EMBED_PREINIT_CHECK("Initializing interpreter\n"); |
Victor Stinner | 9e87e77 | 2017-11-24 12:09:24 +0100 | [diff] [blame] | 167 | Py_Initialize(); |
Nick Coghlan | bc77eff | 2018-03-25 20:44:30 +1000 | [diff] [blame] | 168 | _Py_EMBED_PREINIT_CHECK("Check sys module contents\n"); |
| 169 | PyRun_SimpleString("import sys; " |
| 170 | "print('sys.executable:', sys.executable)"); |
| 171 | _Py_EMBED_PREINIT_CHECK("Finalizing interpreter\n"); |
Victor Stinner | 9e87e77 | 2017-11-24 12:09:24 +0100 | [diff] [blame] | 172 | Py_Finalize(); |
| 173 | |
Nick Coghlan | bc77eff | 2018-03-25 20:44:30 +1000 | [diff] [blame] | 174 | _Py_EMBED_PREINIT_CHECK("Freeing memory allocated by Py_DecodeLocale\n"); |
Victor Stinner | 9e87e77 | 2017-11-24 12:09:24 +0100 | [diff] [blame] | 175 | PyMem_RawFree(program); |
| 176 | return 0; |
| 177 | } |
| 178 | |
Nick Coghlan | bc77eff | 2018-03-25 20:44:30 +1000 | [diff] [blame] | 179 | |
| 180 | /* bpo-33042: Ensure embedding apps can predefine sys module options */ |
| 181 | static int test_pre_initialization_sys_options(void) |
| 182 | { |
Nick Coghlan | 69f5c73 | 2018-03-30 15:36:42 +1000 | [diff] [blame] | 183 | /* We allocate a couple of the options dynamically, and then delete |
Nick Coghlan | bc77eff | 2018-03-25 20:44:30 +1000 | [diff] [blame] | 184 | * them before calling Py_Initialize. This ensures the interpreter isn't |
| 185 | * relying on the caller to keep the passed in strings alive. |
| 186 | */ |
Nick Coghlan | 69f5c73 | 2018-03-30 15:36:42 +1000 | [diff] [blame] | 187 | const wchar_t *static_warnoption = L"once"; |
| 188 | const wchar_t *static_xoption = L"also_not_an_option=2"; |
Nick Coghlan | bc77eff | 2018-03-25 20:44:30 +1000 | [diff] [blame] | 189 | size_t warnoption_len = wcslen(static_warnoption); |
| 190 | size_t xoption_len = wcslen(static_xoption); |
Nick Coghlan | 69f5c73 | 2018-03-30 15:36:42 +1000 | [diff] [blame] | 191 | wchar_t *dynamic_once_warnoption = \ |
| 192 | (wchar_t *) calloc(warnoption_len+1, sizeof(wchar_t)); |
| 193 | wchar_t *dynamic_xoption = \ |
| 194 | (wchar_t *) calloc(xoption_len+1, sizeof(wchar_t)); |
Nick Coghlan | bc77eff | 2018-03-25 20:44:30 +1000 | [diff] [blame] | 195 | wcsncpy(dynamic_once_warnoption, static_warnoption, warnoption_len+1); |
| 196 | wcsncpy(dynamic_xoption, static_xoption, xoption_len+1); |
| 197 | |
| 198 | _Py_EMBED_PREINIT_CHECK("Checking PySys_AddWarnOption\n"); |
| 199 | PySys_AddWarnOption(L"default"); |
| 200 | _Py_EMBED_PREINIT_CHECK("Checking PySys_ResetWarnOptions\n"); |
| 201 | PySys_ResetWarnOptions(); |
| 202 | _Py_EMBED_PREINIT_CHECK("Checking PySys_AddWarnOption linked list\n"); |
| 203 | PySys_AddWarnOption(dynamic_once_warnoption); |
| 204 | PySys_AddWarnOption(L"module"); |
| 205 | PySys_AddWarnOption(L"default"); |
| 206 | _Py_EMBED_PREINIT_CHECK("Checking PySys_AddXOption\n"); |
| 207 | PySys_AddXOption(L"not_an_option=1"); |
| 208 | PySys_AddXOption(dynamic_xoption); |
| 209 | |
| 210 | /* Delete the dynamic options early */ |
| 211 | free(dynamic_once_warnoption); |
| 212 | dynamic_once_warnoption = NULL; |
| 213 | free(dynamic_xoption); |
| 214 | dynamic_xoption = NULL; |
| 215 | |
| 216 | _Py_EMBED_PREINIT_CHECK("Initializing interpreter\n"); |
| 217 | _testembed_Py_Initialize(); |
| 218 | _Py_EMBED_PREINIT_CHECK("Check sys module contents\n"); |
| 219 | PyRun_SimpleString("import sys; " |
| 220 | "print('sys.warnoptions:', sys.warnoptions); " |
| 221 | "print('sys._xoptions:', sys._xoptions); " |
| 222 | "warnings = sys.modules['warnings']; " |
| 223 | "latest_filters = [f[0] for f in warnings.filters[:3]]; " |
| 224 | "print('warnings.filters[:3]:', latest_filters)"); |
| 225 | _Py_EMBED_PREINIT_CHECK("Finalizing interpreter\n"); |
| 226 | Py_Finalize(); |
| 227 | |
| 228 | return 0; |
| 229 | } |
| 230 | |
| 231 | |
| 232 | /* bpo-20891: Avoid race condition when initialising the GIL */ |
Victor Stinner | b4d1e1f | 2017-11-30 22:05:00 +0100 | [diff] [blame] | 233 | static void bpo20891_thread(void *lockp) |
| 234 | { |
| 235 | PyThread_type_lock lock = *((PyThread_type_lock*)lockp); |
| 236 | |
| 237 | PyGILState_STATE state = PyGILState_Ensure(); |
| 238 | if (!PyGILState_Check()) { |
| 239 | fprintf(stderr, "PyGILState_Check failed!"); |
| 240 | abort(); |
| 241 | } |
| 242 | |
| 243 | PyGILState_Release(state); |
| 244 | |
| 245 | PyThread_release_lock(lock); |
| 246 | |
| 247 | PyThread_exit_thread(); |
| 248 | } |
| 249 | |
| 250 | static int test_bpo20891(void) |
| 251 | { |
Victor Stinner | a9df651 | 2019-03-05 23:31:54 +0100 | [diff] [blame] | 252 | /* the test doesn't support custom memory allocators */ |
| 253 | putenv("PYTHONMALLOC="); |
| 254 | |
Victor Stinner | b4d1e1f | 2017-11-30 22:05:00 +0100 | [diff] [blame] | 255 | /* bpo-20891: Calling PyGILState_Ensure in a non-Python thread before |
| 256 | calling PyEval_InitThreads() must not crash. PyGILState_Ensure() must |
| 257 | call PyEval_InitThreads() for us in this case. */ |
| 258 | PyThread_type_lock lock = PyThread_allocate_lock(); |
| 259 | if (!lock) { |
| 260 | fprintf(stderr, "PyThread_allocate_lock failed!"); |
| 261 | return 1; |
| 262 | } |
| 263 | |
| 264 | _testembed_Py_Initialize(); |
| 265 | |
| 266 | unsigned long thrd = PyThread_start_new_thread(bpo20891_thread, &lock); |
| 267 | if (thrd == PYTHREAD_INVALID_THREAD_ID) { |
| 268 | fprintf(stderr, "PyThread_start_new_thread failed!"); |
| 269 | return 1; |
| 270 | } |
| 271 | PyThread_acquire_lock(lock, WAIT_LOCK); |
| 272 | |
| 273 | Py_BEGIN_ALLOW_THREADS |
| 274 | /* wait until the thread exit */ |
| 275 | PyThread_acquire_lock(lock, WAIT_LOCK); |
| 276 | Py_END_ALLOW_THREADS |
| 277 | |
| 278 | PyThread_free_lock(lock); |
| 279 | |
| 280 | return 0; |
| 281 | } |
| 282 | |
Victor Stinner | 209abf7 | 2018-06-22 19:14:51 +0200 | [diff] [blame] | 283 | static int test_initialize_twice(void) |
| 284 | { |
| 285 | _testembed_Py_Initialize(); |
| 286 | |
| 287 | /* bpo-33932: Calling Py_Initialize() twice should do nothing |
| 288 | * (and not crash!). */ |
| 289 | Py_Initialize(); |
| 290 | |
| 291 | Py_Finalize(); |
| 292 | |
| 293 | return 0; |
| 294 | } |
| 295 | |
Victor Stinner | fb47bca | 2018-07-20 17:34:23 +0200 | [diff] [blame] | 296 | static int test_initialize_pymain(void) |
| 297 | { |
| 298 | wchar_t *argv[] = {L"PYTHON", L"-c", |
Victor Stinner | cab5d07 | 2019-05-17 19:01:14 +0200 | [diff] [blame] | 299 | (L"import sys; " |
| 300 | L"print(f'Py_Main() after Py_Initialize: " |
| 301 | L"sys.argv={sys.argv}')"), |
Victor Stinner | fb47bca | 2018-07-20 17:34:23 +0200 | [diff] [blame] | 302 | L"arg2"}; |
| 303 | _testembed_Py_Initialize(); |
| 304 | |
| 305 | /* bpo-34008: Calling Py_Main() after Py_Initialize() must not crash */ |
| 306 | Py_Main(Py_ARRAY_LENGTH(argv), argv); |
| 307 | |
| 308 | Py_Finalize(); |
| 309 | |
| 310 | return 0; |
| 311 | } |
| 312 | |
Victor Stinner | 9e87e77 | 2017-11-24 12:09:24 +0100 | [diff] [blame] | 313 | |
Victor Stinner | 00b137c | 2018-11-13 19:59:26 +0100 | [diff] [blame] | 314 | static void |
| 315 | dump_config(void) |
| 316 | { |
Victor Stinner | 23bace2 | 2019-04-18 11:37:26 +0200 | [diff] [blame] | 317 | (void) PyRun_SimpleStringFlags( |
| 318 | "import _testinternalcapi, json; " |
| 319 | "print(json.dumps(_testinternalcapi.get_configs()))", |
| 320 | 0); |
Victor Stinner | 00b137c | 2018-11-13 19:59:26 +0100 | [diff] [blame] | 321 | } |
| 322 | |
| 323 | |
Victor Stinner | 022be02 | 2019-05-22 23:58:50 +0200 | [diff] [blame] | 324 | static int test_init_initialize_config(void) |
Victor Stinner | 56b29b6 | 2018-07-26 18:57:56 +0200 | [diff] [blame] | 325 | { |
| 326 | _testembed_Py_Initialize(); |
| 327 | dump_config(); |
| 328 | Py_Finalize(); |
| 329 | return 0; |
| 330 | } |
| 331 | |
| 332 | |
Miss Islington (bot) | 4c227e6 | 2019-07-01 11:28:55 -0700 | [diff] [blame] | 333 | static void config_set_string(PyConfig *config, wchar_t **config_str, const wchar_t *str) |
| 334 | { |
| 335 | PyStatus status = PyConfig_SetString(config, config_str, str); |
| 336 | if (PyStatus_Exception(status)) { |
| 337 | PyConfig_Clear(config); |
| 338 | Py_ExitStatusException(status); |
| 339 | } |
| 340 | } |
| 341 | |
| 342 | |
| 343 | static void config_set_argv(PyConfig *config, Py_ssize_t argc, wchar_t * const *argv) |
| 344 | { |
| 345 | PyStatus status = PyConfig_SetArgv(config, argc, argv); |
| 346 | if (PyStatus_Exception(status)) { |
| 347 | PyConfig_Clear(config); |
| 348 | Py_ExitStatusException(status); |
| 349 | } |
| 350 | } |
| 351 | |
| 352 | |
| 353 | static void |
| 354 | config_set_wide_string_list(PyConfig *config, PyWideStringList *list, |
| 355 | Py_ssize_t length, wchar_t **items) |
| 356 | { |
| 357 | PyStatus status = PyConfig_SetWideStringList(config, list, length, items); |
| 358 | if (PyStatus_Exception(status)) { |
| 359 | PyConfig_Clear(config); |
| 360 | Py_ExitStatusException(status); |
| 361 | } |
| 362 | } |
| 363 | |
| 364 | |
| 365 | static void config_set_program_name(PyConfig *config) |
| 366 | { |
Victor Stinner | 96c8475 | 2019-09-26 16:17:34 +0200 | [diff] [blame] | 367 | const wchar_t *program_name = PROGRAM_NAME; |
Miss Islington (bot) | 4c227e6 | 2019-07-01 11:28:55 -0700 | [diff] [blame] | 368 | config_set_string(config, &config->program_name, program_name); |
| 369 | } |
| 370 | |
| 371 | |
| 372 | static void init_from_config_clear(PyConfig *config) |
| 373 | { |
| 374 | PyStatus status = Py_InitializeFromConfig(config); |
| 375 | PyConfig_Clear(config); |
| 376 | if (PyStatus_Exception(status)) { |
| 377 | Py_ExitStatusException(status); |
| 378 | } |
| 379 | } |
| 380 | |
| 381 | |
Victor Stinner | 022be02 | 2019-05-22 23:58:50 +0200 | [diff] [blame] | 382 | static int check_init_compat_config(int preinit) |
| 383 | { |
Victor Stinner | 331a6a5 | 2019-05-27 16:39:22 +0200 | [diff] [blame] | 384 | PyStatus status; |
Victor Stinner | 022be02 | 2019-05-22 23:58:50 +0200 | [diff] [blame] | 385 | |
| 386 | if (preinit) { |
Victor Stinner | 331a6a5 | 2019-05-27 16:39:22 +0200 | [diff] [blame] | 387 | PyPreConfig preconfig; |
Victor Stinner | bdace21 | 2019-10-01 00:46:42 +0200 | [diff] [blame^] | 388 | _PyPreConfig_InitCompatConfig(&preconfig); |
Victor Stinner | 022be02 | 2019-05-22 23:58:50 +0200 | [diff] [blame] | 389 | |
Victor Stinner | 331a6a5 | 2019-05-27 16:39:22 +0200 | [diff] [blame] | 390 | status = Py_PreInitialize(&preconfig); |
| 391 | if (PyStatus_Exception(status)) { |
| 392 | Py_ExitStatusException(status); |
Victor Stinner | 022be02 | 2019-05-22 23:58:50 +0200 | [diff] [blame] | 393 | } |
| 394 | } |
| 395 | |
Victor Stinner | 331a6a5 | 2019-05-27 16:39:22 +0200 | [diff] [blame] | 396 | PyConfig config; |
Victor Stinner | 6e12838 | 2019-09-28 04:50:43 +0200 | [diff] [blame] | 397 | |
| 398 | status = _PyConfig_InitCompatConfig(&config); |
| 399 | if (PyStatus_Exception(status)) { |
| 400 | Py_ExitStatusException(status); |
| 401 | } |
| 402 | |
Miss Islington (bot) | 4c227e6 | 2019-07-01 11:28:55 -0700 | [diff] [blame] | 403 | config_set_program_name(&config); |
| 404 | init_from_config_clear(&config); |
Victor Stinner | 022be02 | 2019-05-22 23:58:50 +0200 | [diff] [blame] | 405 | |
| 406 | dump_config(); |
| 407 | Py_Finalize(); |
| 408 | return 0; |
| 409 | } |
| 410 | |
| 411 | |
| 412 | static int test_preinit_compat_config(void) |
| 413 | { |
| 414 | return check_init_compat_config(1); |
| 415 | } |
| 416 | |
| 417 | |
| 418 | static int test_init_compat_config(void) |
| 419 | { |
| 420 | return check_init_compat_config(0); |
| 421 | } |
| 422 | |
| 423 | |
Victor Stinner | 56b29b6 | 2018-07-26 18:57:56 +0200 | [diff] [blame] | 424 | static int test_init_global_config(void) |
| 425 | { |
| 426 | /* FIXME: test Py_IgnoreEnvironmentFlag */ |
| 427 | |
| 428 | putenv("PYTHONUTF8=0"); |
| 429 | Py_UTF8Mode = 1; |
| 430 | |
| 431 | /* Test initialization from global configuration variables (Py_xxx) */ |
| 432 | Py_SetProgramName(L"./globalvar"); |
| 433 | |
| 434 | /* Py_IsolatedFlag is not tested */ |
| 435 | Py_NoSiteFlag = 1; |
| 436 | Py_BytesWarningFlag = 1; |
| 437 | |
| 438 | putenv("PYTHONINSPECT="); |
| 439 | Py_InspectFlag = 1; |
| 440 | |
| 441 | putenv("PYTHONOPTIMIZE=0"); |
| 442 | Py_InteractiveFlag = 1; |
| 443 | |
| 444 | putenv("PYTHONDEBUG=0"); |
| 445 | Py_OptimizeFlag = 2; |
| 446 | |
| 447 | /* Py_DebugFlag is not tested */ |
| 448 | |
| 449 | putenv("PYTHONDONTWRITEBYTECODE="); |
| 450 | Py_DontWriteBytecodeFlag = 1; |
| 451 | |
| 452 | putenv("PYTHONVERBOSE=0"); |
| 453 | Py_VerboseFlag = 1; |
| 454 | |
| 455 | Py_QuietFlag = 1; |
| 456 | Py_NoUserSiteDirectory = 1; |
| 457 | |
| 458 | putenv("PYTHONUNBUFFERED="); |
| 459 | Py_UnbufferedStdioFlag = 1; |
| 460 | |
Victor Stinner | 54b43bb | 2019-05-16 18:30:15 +0200 | [diff] [blame] | 461 | Py_FrozenFlag = 1; |
| 462 | |
Victor Stinner | 56b29b6 | 2018-07-26 18:57:56 +0200 | [diff] [blame] | 463 | /* FIXME: test Py_LegacyWindowsFSEncodingFlag */ |
| 464 | /* FIXME: test Py_LegacyWindowsStdioFlag */ |
| 465 | |
Victor Stinner | 56b29b6 | 2018-07-26 18:57:56 +0200 | [diff] [blame] | 466 | Py_Initialize(); |
| 467 | dump_config(); |
| 468 | Py_Finalize(); |
| 469 | return 0; |
| 470 | } |
| 471 | |
| 472 | |
| 473 | static int test_init_from_config(void) |
| 474 | { |
Victor Stinner | 331a6a5 | 2019-05-27 16:39:22 +0200 | [diff] [blame] | 475 | PyPreConfig preconfig; |
Victor Stinner | bdace21 | 2019-10-01 00:46:42 +0200 | [diff] [blame^] | 476 | _PyPreConfig_InitCompatConfig(&preconfig); |
Victor Stinner | 2000495 | 2019-03-26 02:31:11 +0100 | [diff] [blame] | 477 | |
| 478 | putenv("PYTHONMALLOC=malloc_debug"); |
Victor Stinner | b16b4e4 | 2019-05-17 15:20:52 +0200 | [diff] [blame] | 479 | preconfig.allocator = PYMEM_ALLOCATOR_MALLOC; |
Victor Stinner | 2000495 | 2019-03-26 02:31:11 +0100 | [diff] [blame] | 480 | |
| 481 | putenv("PYTHONUTF8=0"); |
| 482 | Py_UTF8Mode = 0; |
| 483 | preconfig.utf8_mode = 1; |
| 484 | |
Victor Stinner | bdace21 | 2019-10-01 00:46:42 +0200 | [diff] [blame^] | 485 | PyStatus status = Py_PreInitialize(&preconfig); |
Victor Stinner | 331a6a5 | 2019-05-27 16:39:22 +0200 | [diff] [blame] | 486 | if (PyStatus_Exception(status)) { |
| 487 | Py_ExitStatusException(status); |
Victor Stinner | 2000495 | 2019-03-26 02:31:11 +0100 | [diff] [blame] | 488 | } |
| 489 | |
Victor Stinner | 331a6a5 | 2019-05-27 16:39:22 +0200 | [diff] [blame] | 490 | PyConfig config; |
Victor Stinner | 6e12838 | 2019-09-28 04:50:43 +0200 | [diff] [blame] | 491 | |
| 492 | status = _PyConfig_InitCompatConfig(&config); |
| 493 | if (PyStatus_Exception(status)) { |
| 494 | Py_ExitStatusException(status); |
| 495 | } |
Victor Stinner | 56b29b6 | 2018-07-26 18:57:56 +0200 | [diff] [blame] | 496 | config.install_signal_handlers = 0; |
| 497 | |
| 498 | /* FIXME: test use_environment */ |
| 499 | |
| 500 | putenv("PYTHONHASHSEED=42"); |
| 501 | config.use_hash_seed = 1; |
| 502 | config.hash_seed = 123; |
| 503 | |
Victor Stinner | bab0db6 | 2019-05-18 03:21:27 +0200 | [diff] [blame] | 504 | /* dev_mode=1 is tested in test_init_dev_mode() */ |
Victor Stinner | 56b29b6 | 2018-07-26 18:57:56 +0200 | [diff] [blame] | 505 | |
| 506 | putenv("PYTHONFAULTHANDLER="); |
| 507 | config.faulthandler = 1; |
| 508 | |
| 509 | putenv("PYTHONTRACEMALLOC=0"); |
| 510 | config.tracemalloc = 2; |
| 511 | |
| 512 | putenv("PYTHONPROFILEIMPORTTIME=0"); |
| 513 | config.import_time = 1; |
| 514 | |
| 515 | config.show_ref_count = 1; |
| 516 | config.show_alloc_count = 1; |
| 517 | /* FIXME: test dump_refs: bpo-34223 */ |
| 518 | |
| 519 | putenv("PYTHONMALLOCSTATS=0"); |
| 520 | config.malloc_stats = 1; |
| 521 | |
Victor Stinner | 56b29b6 | 2018-07-26 18:57:56 +0200 | [diff] [blame] | 522 | putenv("PYTHONPYCACHEPREFIX=env_pycache_prefix"); |
Miss Islington (bot) | 4c227e6 | 2019-07-01 11:28:55 -0700 | [diff] [blame] | 523 | config_set_string(&config, &config.pycache_prefix, L"conf_pycache_prefix"); |
Victor Stinner | 56b29b6 | 2018-07-26 18:57:56 +0200 | [diff] [blame] | 524 | |
| 525 | Py_SetProgramName(L"./globalvar"); |
Miss Islington (bot) | 4c227e6 | 2019-07-01 11:28:55 -0700 | [diff] [blame] | 526 | config_set_string(&config, &config.program_name, L"./conf_program_name"); |
Victor Stinner | 56b29b6 | 2018-07-26 18:57:56 +0200 | [diff] [blame] | 527 | |
Miss Islington (bot) | 4c227e6 | 2019-07-01 11:28:55 -0700 | [diff] [blame] | 528 | wchar_t* argv[] = { |
Victor Stinner | 2f54908 | 2019-03-29 15:13:46 +0100 | [diff] [blame] | 529 | L"python3", |
Miss Islington (bot) | 4c227e6 | 2019-07-01 11:28:55 -0700 | [diff] [blame] | 530 | L"-W", |
| 531 | L"cmdline_warnoption", |
| 532 | L"-X", |
| 533 | L"cmdline_xoption", |
Victor Stinner | 01de89c | 2018-11-14 17:39:45 +0100 | [diff] [blame] | 534 | L"-c", |
| 535 | L"pass", |
Victor Stinner | 2f54908 | 2019-03-29 15:13:46 +0100 | [diff] [blame] | 536 | L"arg2", |
Victor Stinner | 01de89c | 2018-11-14 17:39:45 +0100 | [diff] [blame] | 537 | }; |
Miss Islington (bot) | 4c227e6 | 2019-07-01 11:28:55 -0700 | [diff] [blame] | 538 | config_set_argv(&config, Py_ARRAY_LENGTH(argv), argv); |
Victor Stinner | cab5d07 | 2019-05-17 19:01:14 +0200 | [diff] [blame] | 539 | config.parse_argv = 1; |
Victor Stinner | 01de89c | 2018-11-14 17:39:45 +0100 | [diff] [blame] | 540 | |
Miss Islington (bot) | 4c227e6 | 2019-07-01 11:28:55 -0700 | [diff] [blame] | 541 | wchar_t* xoptions[3] = { |
| 542 | L"config_xoption1=3", |
| 543 | L"config_xoption2=", |
| 544 | L"config_xoption3", |
Victor Stinner | 01de89c | 2018-11-14 17:39:45 +0100 | [diff] [blame] | 545 | }; |
Miss Islington (bot) | 4c227e6 | 2019-07-01 11:28:55 -0700 | [diff] [blame] | 546 | config_set_wide_string_list(&config, &config.xoptions, |
| 547 | Py_ARRAY_LENGTH(xoptions), xoptions); |
Victor Stinner | 01de89c | 2018-11-14 17:39:45 +0100 | [diff] [blame] | 548 | |
Miss Islington (bot) | 4c227e6 | 2019-07-01 11:28:55 -0700 | [diff] [blame] | 549 | wchar_t* warnoptions[1] = { |
| 550 | L"config_warnoption", |
Victor Stinner | 01de89c | 2018-11-14 17:39:45 +0100 | [diff] [blame] | 551 | }; |
Miss Islington (bot) | 4c227e6 | 2019-07-01 11:28:55 -0700 | [diff] [blame] | 552 | config_set_wide_string_list(&config, &config.warnoptions, |
| 553 | Py_ARRAY_LENGTH(warnoptions), warnoptions); |
Victor Stinner | 01de89c | 2018-11-14 17:39:45 +0100 | [diff] [blame] | 554 | |
Victor Stinner | 331a6a5 | 2019-05-27 16:39:22 +0200 | [diff] [blame] | 555 | /* FIXME: test pythonpath_env */ |
Victor Stinner | 56b29b6 | 2018-07-26 18:57:56 +0200 | [diff] [blame] | 556 | /* FIXME: test home */ |
| 557 | /* FIXME: test path config: module_search_path .. dll_path */ |
| 558 | |
| 559 | putenv("PYTHONVERBOSE=0"); |
| 560 | Py_VerboseFlag = 0; |
| 561 | config.verbose = 1; |
| 562 | |
| 563 | Py_NoSiteFlag = 0; |
| 564 | config.site_import = 0; |
| 565 | |
| 566 | Py_BytesWarningFlag = 0; |
| 567 | config.bytes_warning = 1; |
| 568 | |
| 569 | putenv("PYTHONINSPECT="); |
| 570 | Py_InspectFlag = 0; |
| 571 | config.inspect = 1; |
| 572 | |
| 573 | Py_InteractiveFlag = 0; |
| 574 | config.interactive = 1; |
| 575 | |
| 576 | putenv("PYTHONOPTIMIZE=0"); |
| 577 | Py_OptimizeFlag = 1; |
| 578 | config.optimization_level = 2; |
| 579 | |
Victor Stinner | 9851227 | 2018-08-01 03:07:00 +0200 | [diff] [blame] | 580 | /* FIXME: test parser_debug */ |
Victor Stinner | 56b29b6 | 2018-07-26 18:57:56 +0200 | [diff] [blame] | 581 | |
| 582 | putenv("PYTHONDONTWRITEBYTECODE="); |
| 583 | Py_DontWriteBytecodeFlag = 0; |
| 584 | config.write_bytecode = 0; |
| 585 | |
| 586 | Py_QuietFlag = 0; |
| 587 | config.quiet = 1; |
| 588 | |
Victor Stinner | cab5d07 | 2019-05-17 19:01:14 +0200 | [diff] [blame] | 589 | config.configure_c_stdio = 1; |
Victor Stinner | 54b43bb | 2019-05-16 18:30:15 +0200 | [diff] [blame] | 590 | |
Victor Stinner | 56b29b6 | 2018-07-26 18:57:56 +0200 | [diff] [blame] | 591 | putenv("PYTHONUNBUFFERED="); |
| 592 | Py_UnbufferedStdioFlag = 0; |
Victor Stinner | 9851227 | 2018-08-01 03:07:00 +0200 | [diff] [blame] | 593 | config.buffered_stdio = 0; |
Victor Stinner | 56b29b6 | 2018-07-26 18:57:56 +0200 | [diff] [blame] | 594 | |
Victor Stinner | dfe0dc7 | 2018-08-29 11:47:29 +0200 | [diff] [blame] | 595 | putenv("PYTHONIOENCODING=cp424"); |
| 596 | Py_SetStandardStreamEncoding("ascii", "ignore"); |
Victor Stinner | 01de89c | 2018-11-14 17:39:45 +0100 | [diff] [blame] | 597 | #ifdef MS_WINDOWS |
| 598 | /* Py_SetStandardStreamEncoding() sets Py_LegacyWindowsStdioFlag to 1. |
| 599 | Force it to 0 through the config. */ |
| 600 | config.legacy_windows_stdio = 0; |
| 601 | #endif |
Miss Islington (bot) | 4c227e6 | 2019-07-01 11:28:55 -0700 | [diff] [blame] | 602 | config_set_string(&config, &config.stdio_encoding, L"iso8859-1"); |
| 603 | config_set_string(&config, &config.stdio_errors, L"replace"); |
Victor Stinner | dfe0dc7 | 2018-08-29 11:47:29 +0200 | [diff] [blame] | 604 | |
Victor Stinner | 56b29b6 | 2018-07-26 18:57:56 +0200 | [diff] [blame] | 605 | putenv("PYTHONNOUSERSITE="); |
| 606 | Py_NoUserSiteDirectory = 0; |
| 607 | config.user_site_directory = 0; |
| 608 | |
Miss Islington (bot) | 4c227e6 | 2019-07-01 11:28:55 -0700 | [diff] [blame] | 609 | config_set_string(&config, &config.check_hash_pycs_mode, L"always"); |
Victor Stinner | 56b29b6 | 2018-07-26 18:57:56 +0200 | [diff] [blame] | 610 | |
Victor Stinner | 54b43bb | 2019-05-16 18:30:15 +0200 | [diff] [blame] | 611 | Py_FrozenFlag = 0; |
| 612 | config.pathconfig_warnings = 0; |
| 613 | |
Miss Islington (bot) | 4c227e6 | 2019-07-01 11:28:55 -0700 | [diff] [blame] | 614 | init_from_config_clear(&config); |
| 615 | |
Victor Stinner | 56b29b6 | 2018-07-26 18:57:56 +0200 | [diff] [blame] | 616 | dump_config(); |
| 617 | Py_Finalize(); |
| 618 | return 0; |
| 619 | } |
| 620 | |
| 621 | |
Victor Stinner | bab0db6 | 2019-05-18 03:21:27 +0200 | [diff] [blame] | 622 | static int check_init_parse_argv(int parse_argv) |
Victor Stinner | ae239f6 | 2019-05-16 17:02:56 +0200 | [diff] [blame] | 623 | { |
Victor Stinner | 331a6a5 | 2019-05-27 16:39:22 +0200 | [diff] [blame] | 624 | PyStatus status; |
Victor Stinner | ae239f6 | 2019-05-16 17:02:56 +0200 | [diff] [blame] | 625 | |
Victor Stinner | 331a6a5 | 2019-05-27 16:39:22 +0200 | [diff] [blame] | 626 | PyConfig config; |
Victor Stinner | 6e12838 | 2019-09-28 04:50:43 +0200 | [diff] [blame] | 627 | |
Victor Stinner | 331a6a5 | 2019-05-27 16:39:22 +0200 | [diff] [blame] | 628 | status = PyConfig_InitPythonConfig(&config); |
| 629 | if (PyStatus_Exception(status)) { |
| 630 | Py_ExitStatusException(status); |
Victor Stinner | 6d1c467 | 2019-05-20 11:02:00 +0200 | [diff] [blame] | 631 | } |
Victor Stinner | ae239f6 | 2019-05-16 17:02:56 +0200 | [diff] [blame] | 632 | |
Miss Islington (bot) | 4c227e6 | 2019-07-01 11:28:55 -0700 | [diff] [blame] | 633 | config.parse_argv = parse_argv; |
| 634 | |
| 635 | wchar_t* argv[] = { |
Victor Stinner | cab5d07 | 2019-05-17 19:01:14 +0200 | [diff] [blame] | 636 | L"./argv0", |
| 637 | L"-E", |
Victor Stinner | ae239f6 | 2019-05-16 17:02:56 +0200 | [diff] [blame] | 638 | L"-c", |
Victor Stinner | cab5d07 | 2019-05-17 19:01:14 +0200 | [diff] [blame] | 639 | L"pass", |
Victor Stinner | ae239f6 | 2019-05-16 17:02:56 +0200 | [diff] [blame] | 640 | L"arg1", |
Victor Stinner | cab5d07 | 2019-05-17 19:01:14 +0200 | [diff] [blame] | 641 | L"-v", |
| 642 | L"arg3", |
Victor Stinner | ae239f6 | 2019-05-16 17:02:56 +0200 | [diff] [blame] | 643 | }; |
Miss Islington (bot) | 4c227e6 | 2019-07-01 11:28:55 -0700 | [diff] [blame] | 644 | config_set_argv(&config, Py_ARRAY_LENGTH(argv), argv); |
| 645 | init_from_config_clear(&config); |
Victor Stinner | ae239f6 | 2019-05-16 17:02:56 +0200 | [diff] [blame] | 646 | |
Victor Stinner | ae239f6 | 2019-05-16 17:02:56 +0200 | [diff] [blame] | 647 | dump_config(); |
| 648 | Py_Finalize(); |
| 649 | return 0; |
| 650 | } |
| 651 | |
| 652 | |
Victor Stinner | bab0db6 | 2019-05-18 03:21:27 +0200 | [diff] [blame] | 653 | static int test_init_parse_argv(void) |
Victor Stinner | cab5d07 | 2019-05-17 19:01:14 +0200 | [diff] [blame] | 654 | { |
Victor Stinner | bab0db6 | 2019-05-18 03:21:27 +0200 | [diff] [blame] | 655 | return check_init_parse_argv(1); |
Victor Stinner | cab5d07 | 2019-05-17 19:01:14 +0200 | [diff] [blame] | 656 | } |
| 657 | |
| 658 | |
Victor Stinner | bab0db6 | 2019-05-18 03:21:27 +0200 | [diff] [blame] | 659 | static int test_init_dont_parse_argv(void) |
Victor Stinner | cab5d07 | 2019-05-17 19:01:14 +0200 | [diff] [blame] | 660 | { |
Victor Stinner | bab0db6 | 2019-05-18 03:21:27 +0200 | [diff] [blame] | 661 | return check_init_parse_argv(0); |
Victor Stinner | cab5d07 | 2019-05-17 19:01:14 +0200 | [diff] [blame] | 662 | } |
| 663 | |
| 664 | |
Victor Stinner | 425717f | 2019-05-20 16:38:48 +0200 | [diff] [blame] | 665 | static void set_most_env_vars(void) |
Victor Stinner | 56b29b6 | 2018-07-26 18:57:56 +0200 | [diff] [blame] | 666 | { |
| 667 | putenv("PYTHONHASHSEED=42"); |
Victor Stinner | 25d13f3 | 2019-03-06 12:51:53 +0100 | [diff] [blame] | 668 | putenv("PYTHONMALLOC=malloc"); |
Victor Stinner | 56b29b6 | 2018-07-26 18:57:56 +0200 | [diff] [blame] | 669 | putenv("PYTHONTRACEMALLOC=2"); |
| 670 | putenv("PYTHONPROFILEIMPORTTIME=1"); |
| 671 | putenv("PYTHONMALLOCSTATS=1"); |
| 672 | putenv("PYTHONUTF8=1"); |
| 673 | putenv("PYTHONVERBOSE=1"); |
| 674 | putenv("PYTHONINSPECT=1"); |
| 675 | putenv("PYTHONOPTIMIZE=2"); |
| 676 | putenv("PYTHONDONTWRITEBYTECODE=1"); |
| 677 | putenv("PYTHONUNBUFFERED=1"); |
| 678 | putenv("PYTHONPYCACHEPREFIX=env_pycache_prefix"); |
| 679 | putenv("PYTHONNOUSERSITE=1"); |
| 680 | putenv("PYTHONFAULTHANDLER=1"); |
Victor Stinner | dfe0dc7 | 2018-08-29 11:47:29 +0200 | [diff] [blame] | 681 | putenv("PYTHONIOENCODING=iso8859-1:replace"); |
Victor Stinner | 425717f | 2019-05-20 16:38:48 +0200 | [diff] [blame] | 682 | } |
| 683 | |
| 684 | |
| 685 | static void set_all_env_vars(void) |
| 686 | { |
| 687 | set_most_env_vars(); |
| 688 | |
| 689 | putenv("PYTHONWARNINGS=EnvVar"); |
| 690 | putenv("PYTHONPATH=/my/path"); |
Victor Stinner | 56b29b6 | 2018-07-26 18:57:56 +0200 | [diff] [blame] | 691 | } |
| 692 | |
| 693 | |
Victor Stinner | 20e1e25 | 2019-05-23 04:12:27 +0200 | [diff] [blame] | 694 | static int test_init_compat_env(void) |
Victor Stinner | 56b29b6 | 2018-07-26 18:57:56 +0200 | [diff] [blame] | 695 | { |
| 696 | /* Test initialization from environment variables */ |
| 697 | Py_IgnoreEnvironmentFlag = 0; |
Victor Stinner | 6d1c467 | 2019-05-20 11:02:00 +0200 | [diff] [blame] | 698 | set_all_env_vars(); |
Victor Stinner | 56b29b6 | 2018-07-26 18:57:56 +0200 | [diff] [blame] | 699 | _testembed_Py_Initialize(); |
| 700 | dump_config(); |
| 701 | Py_Finalize(); |
| 702 | return 0; |
| 703 | } |
| 704 | |
| 705 | |
Victor Stinner | 20e1e25 | 2019-05-23 04:12:27 +0200 | [diff] [blame] | 706 | static int test_init_python_env(void) |
| 707 | { |
Victor Stinner | 331a6a5 | 2019-05-27 16:39:22 +0200 | [diff] [blame] | 708 | PyStatus status; |
Victor Stinner | 20e1e25 | 2019-05-23 04:12:27 +0200 | [diff] [blame] | 709 | |
| 710 | set_all_env_vars(); |
| 711 | |
Victor Stinner | 331a6a5 | 2019-05-27 16:39:22 +0200 | [diff] [blame] | 712 | PyConfig config; |
Victor Stinner | 6e12838 | 2019-09-28 04:50:43 +0200 | [diff] [blame] | 713 | |
Victor Stinner | 331a6a5 | 2019-05-27 16:39:22 +0200 | [diff] [blame] | 714 | status = PyConfig_InitPythonConfig(&config); |
| 715 | if (PyStatus_Exception(status)) { |
| 716 | Py_ExitStatusException(status); |
Victor Stinner | 20e1e25 | 2019-05-23 04:12:27 +0200 | [diff] [blame] | 717 | } |
Victor Stinner | 20e1e25 | 2019-05-23 04:12:27 +0200 | [diff] [blame] | 718 | |
Miss Islington (bot) | 4c227e6 | 2019-07-01 11:28:55 -0700 | [diff] [blame] | 719 | config_set_program_name(&config); |
| 720 | init_from_config_clear(&config); |
| 721 | |
Victor Stinner | 20e1e25 | 2019-05-23 04:12:27 +0200 | [diff] [blame] | 722 | dump_config(); |
| 723 | Py_Finalize(); |
| 724 | return 0; |
| 725 | } |
| 726 | |
| 727 | |
Victor Stinner | 6d1c467 | 2019-05-20 11:02:00 +0200 | [diff] [blame] | 728 | static void set_all_env_vars_dev_mode(void) |
Victor Stinner | 25d13f3 | 2019-03-06 12:51:53 +0100 | [diff] [blame] | 729 | { |
Victor Stinner | 25d13f3 | 2019-03-06 12:51:53 +0100 | [diff] [blame] | 730 | putenv("PYTHONMALLOC="); |
| 731 | putenv("PYTHONFAULTHANDLER="); |
| 732 | putenv("PYTHONDEVMODE=1"); |
| 733 | } |
| 734 | |
| 735 | |
Victor Stinner | b35be4b | 2019-03-05 17:37:44 +0100 | [diff] [blame] | 736 | static int test_init_env_dev_mode(void) |
| 737 | { |
| 738 | /* Test initialization from environment variables */ |
| 739 | Py_IgnoreEnvironmentFlag = 0; |
Victor Stinner | 6d1c467 | 2019-05-20 11:02:00 +0200 | [diff] [blame] | 740 | set_all_env_vars_dev_mode(); |
Victor Stinner | b35be4b | 2019-03-05 17:37:44 +0100 | [diff] [blame] | 741 | _testembed_Py_Initialize(); |
| 742 | dump_config(); |
| 743 | Py_Finalize(); |
| 744 | return 0; |
| 745 | } |
| 746 | |
| 747 | |
Victor Stinner | 25d13f3 | 2019-03-06 12:51:53 +0100 | [diff] [blame] | 748 | static int test_init_env_dev_mode_alloc(void) |
| 749 | { |
| 750 | /* Test initialization from environment variables */ |
| 751 | Py_IgnoreEnvironmentFlag = 0; |
Victor Stinner | 6d1c467 | 2019-05-20 11:02:00 +0200 | [diff] [blame] | 752 | set_all_env_vars_dev_mode(); |
Victor Stinner | 25d13f3 | 2019-03-06 12:51:53 +0100 | [diff] [blame] | 753 | putenv("PYTHONMALLOC=malloc"); |
| 754 | _testembed_Py_Initialize(); |
| 755 | dump_config(); |
| 756 | Py_Finalize(); |
| 757 | return 0; |
| 758 | } |
| 759 | |
| 760 | |
Victor Stinner | bab0db6 | 2019-05-18 03:21:27 +0200 | [diff] [blame] | 761 | static int test_init_isolated_flag(void) |
Victor Stinner | 56b29b6 | 2018-07-26 18:57:56 +0200 | [diff] [blame] | 762 | { |
Victor Stinner | 331a6a5 | 2019-05-27 16:39:22 +0200 | [diff] [blame] | 763 | PyStatus status; |
Victor Stinner | 2000495 | 2019-03-26 02:31:11 +0100 | [diff] [blame] | 764 | |
Victor Stinner | 331a6a5 | 2019-05-27 16:39:22 +0200 | [diff] [blame] | 765 | /* Test PyConfig.isolated=1 */ |
| 766 | PyConfig config; |
Victor Stinner | 6e12838 | 2019-09-28 04:50:43 +0200 | [diff] [blame] | 767 | |
Victor Stinner | 331a6a5 | 2019-05-27 16:39:22 +0200 | [diff] [blame] | 768 | status = PyConfig_InitPythonConfig(&config); |
| 769 | if (PyStatus_Exception(status)) { |
| 770 | Py_ExitStatusException(status); |
Victor Stinner | 6d1c467 | 2019-05-20 11:02:00 +0200 | [diff] [blame] | 771 | } |
Victor Stinner | 56b29b6 | 2018-07-26 18:57:56 +0200 | [diff] [blame] | 772 | |
Victor Stinner | cad1f74 | 2019-03-05 02:01:27 +0100 | [diff] [blame] | 773 | Py_IsolatedFlag = 0; |
Victor Stinner | 2000495 | 2019-03-26 02:31:11 +0100 | [diff] [blame] | 774 | config.isolated = 1; |
Victor Stinner | cad1f74 | 2019-03-05 02:01:27 +0100 | [diff] [blame] | 775 | |
Miss Islington (bot) | 4c227e6 | 2019-07-01 11:28:55 -0700 | [diff] [blame] | 776 | config_set_program_name(&config); |
Victor Stinner | bab0db6 | 2019-05-18 03:21:27 +0200 | [diff] [blame] | 777 | set_all_env_vars(); |
Miss Islington (bot) | 4c227e6 | 2019-07-01 11:28:55 -0700 | [diff] [blame] | 778 | init_from_config_clear(&config); |
| 779 | |
Victor Stinner | 56b29b6 | 2018-07-26 18:57:56 +0200 | [diff] [blame] | 780 | dump_config(); |
| 781 | Py_Finalize(); |
| 782 | return 0; |
| 783 | } |
| 784 | |
| 785 | |
Victor Stinner | 331a6a5 | 2019-05-27 16:39:22 +0200 | [diff] [blame] | 786 | /* PyPreConfig.isolated=1, PyConfig.isolated=0 */ |
Victor Stinner | 6da20a4 | 2019-03-27 00:26:18 +0100 | [diff] [blame] | 787 | static int test_preinit_isolated1(void) |
| 788 | { |
Victor Stinner | 331a6a5 | 2019-05-27 16:39:22 +0200 | [diff] [blame] | 789 | PyPreConfig preconfig; |
Victor Stinner | bdace21 | 2019-10-01 00:46:42 +0200 | [diff] [blame^] | 790 | _PyPreConfig_InitCompatConfig(&preconfig); |
Victor Stinner | 6e12838 | 2019-09-28 04:50:43 +0200 | [diff] [blame] | 791 | |
Victor Stinner | 6da20a4 | 2019-03-27 00:26:18 +0100 | [diff] [blame] | 792 | preconfig.isolated = 1; |
| 793 | |
Victor Stinner | bdace21 | 2019-10-01 00:46:42 +0200 | [diff] [blame^] | 794 | PyStatus status = Py_PreInitialize(&preconfig); |
Victor Stinner | 331a6a5 | 2019-05-27 16:39:22 +0200 | [diff] [blame] | 795 | if (PyStatus_Exception(status)) { |
| 796 | Py_ExitStatusException(status); |
Victor Stinner | 6da20a4 | 2019-03-27 00:26:18 +0100 | [diff] [blame] | 797 | } |
| 798 | |
Victor Stinner | 331a6a5 | 2019-05-27 16:39:22 +0200 | [diff] [blame] | 799 | PyConfig config; |
Victor Stinner | 6e12838 | 2019-09-28 04:50:43 +0200 | [diff] [blame] | 800 | |
| 801 | status = _PyConfig_InitCompatConfig(&config); |
| 802 | if (PyStatus_Exception(status)) { |
| 803 | Py_ExitStatusException(status); |
| 804 | } |
Miss Islington (bot) | 4c227e6 | 2019-07-01 11:28:55 -0700 | [diff] [blame] | 805 | config_set_program_name(&config); |
Victor Stinner | bab0db6 | 2019-05-18 03:21:27 +0200 | [diff] [blame] | 806 | set_all_env_vars(); |
Miss Islington (bot) | 4c227e6 | 2019-07-01 11:28:55 -0700 | [diff] [blame] | 807 | init_from_config_clear(&config); |
| 808 | |
Victor Stinner | 6da20a4 | 2019-03-27 00:26:18 +0100 | [diff] [blame] | 809 | dump_config(); |
| 810 | Py_Finalize(); |
| 811 | return 0; |
| 812 | } |
| 813 | |
| 814 | |
Victor Stinner | 331a6a5 | 2019-05-27 16:39:22 +0200 | [diff] [blame] | 815 | /* PyPreConfig.isolated=0, PyConfig.isolated=1 */ |
Victor Stinner | 6da20a4 | 2019-03-27 00:26:18 +0100 | [diff] [blame] | 816 | static int test_preinit_isolated2(void) |
| 817 | { |
Victor Stinner | 331a6a5 | 2019-05-27 16:39:22 +0200 | [diff] [blame] | 818 | PyPreConfig preconfig; |
Victor Stinner | bdace21 | 2019-10-01 00:46:42 +0200 | [diff] [blame^] | 819 | _PyPreConfig_InitCompatConfig(&preconfig); |
Victor Stinner | 6e12838 | 2019-09-28 04:50:43 +0200 | [diff] [blame] | 820 | |
Victor Stinner | 6da20a4 | 2019-03-27 00:26:18 +0100 | [diff] [blame] | 821 | preconfig.isolated = 0; |
| 822 | |
Victor Stinner | bdace21 | 2019-10-01 00:46:42 +0200 | [diff] [blame^] | 823 | PyStatus status = Py_PreInitialize(&preconfig); |
Victor Stinner | 331a6a5 | 2019-05-27 16:39:22 +0200 | [diff] [blame] | 824 | if (PyStatus_Exception(status)) { |
| 825 | Py_ExitStatusException(status); |
Victor Stinner | 6da20a4 | 2019-03-27 00:26:18 +0100 | [diff] [blame] | 826 | } |
| 827 | |
Victor Stinner | 331a6a5 | 2019-05-27 16:39:22 +0200 | [diff] [blame] | 828 | /* Test PyConfig.isolated=1 */ |
| 829 | PyConfig config; |
Victor Stinner | bdace21 | 2019-10-01 00:46:42 +0200 | [diff] [blame^] | 830 | |
Victor Stinner | 6e12838 | 2019-09-28 04:50:43 +0200 | [diff] [blame] | 831 | status = _PyConfig_InitCompatConfig(&config); |
| 832 | if (PyStatus_Exception(status)) { |
| 833 | Py_ExitStatusException(status); |
| 834 | } |
Victor Stinner | 6da20a4 | 2019-03-27 00:26:18 +0100 | [diff] [blame] | 835 | |
| 836 | Py_IsolatedFlag = 0; |
| 837 | config.isolated = 1; |
| 838 | |
Miss Islington (bot) | 4c227e6 | 2019-07-01 11:28:55 -0700 | [diff] [blame] | 839 | config_set_program_name(&config); |
Victor Stinner | bab0db6 | 2019-05-18 03:21:27 +0200 | [diff] [blame] | 840 | set_all_env_vars(); |
Miss Islington (bot) | 4c227e6 | 2019-07-01 11:28:55 -0700 | [diff] [blame] | 841 | init_from_config_clear(&config); |
| 842 | |
Victor Stinner | 6da20a4 | 2019-03-27 00:26:18 +0100 | [diff] [blame] | 843 | dump_config(); |
| 844 | Py_Finalize(); |
| 845 | return 0; |
| 846 | } |
| 847 | |
| 848 | |
Victor Stinner | 6d1c467 | 2019-05-20 11:02:00 +0200 | [diff] [blame] | 849 | static int test_preinit_dont_parse_argv(void) |
| 850 | { |
Victor Stinner | 331a6a5 | 2019-05-27 16:39:22 +0200 | [diff] [blame] | 851 | PyPreConfig preconfig; |
Victor Stinner | bdace21 | 2019-10-01 00:46:42 +0200 | [diff] [blame^] | 852 | PyPreConfig_InitIsolatedConfig(&preconfig); |
Victor Stinner | 6d1c467 | 2019-05-20 11:02:00 +0200 | [diff] [blame] | 853 | |
| 854 | preconfig.isolated = 0; |
| 855 | |
| 856 | /* -X dev must be ignored by isolated preconfiguration */ |
| 857 | wchar_t *argv[] = {L"python3", |
| 858 | L"-E", |
| 859 | L"-I", |
| 860 | L"-X", L"dev", |
| 861 | L"-X", L"utf8", |
| 862 | L"script.py"}; |
Victor Stinner | bdace21 | 2019-10-01 00:46:42 +0200 | [diff] [blame^] | 863 | PyStatus status = Py_PreInitializeFromArgs(&preconfig, |
| 864 | Py_ARRAY_LENGTH(argv), argv); |
Victor Stinner | 331a6a5 | 2019-05-27 16:39:22 +0200 | [diff] [blame] | 865 | if (PyStatus_Exception(status)) { |
Miss Islington (bot) | 4c227e6 | 2019-07-01 11:28:55 -0700 | [diff] [blame] | 866 | Py_ExitStatusException(status); |
Victor Stinner | 6d1c467 | 2019-05-20 11:02:00 +0200 | [diff] [blame] | 867 | } |
| 868 | |
Victor Stinner | 331a6a5 | 2019-05-27 16:39:22 +0200 | [diff] [blame] | 869 | PyConfig config; |
Victor Stinner | 6d1c467 | 2019-05-20 11:02:00 +0200 | [diff] [blame] | 870 | |
Victor Stinner | 331a6a5 | 2019-05-27 16:39:22 +0200 | [diff] [blame] | 871 | status = PyConfig_InitIsolatedConfig(&config); |
| 872 | if (PyStatus_Exception(status)) { |
Miss Islington (bot) | 4c227e6 | 2019-07-01 11:28:55 -0700 | [diff] [blame] | 873 | PyConfig_Clear(&config); |
| 874 | Py_ExitStatusException(status); |
Victor Stinner | 6d1c467 | 2019-05-20 11:02:00 +0200 | [diff] [blame] | 875 | } |
| 876 | |
| 877 | config.isolated = 0; |
| 878 | |
| 879 | /* Pre-initialize implicitly using argv: make sure that -X dev |
| 880 | is used to configure the allocation in preinitialization */ |
Miss Islington (bot) | 4c227e6 | 2019-07-01 11:28:55 -0700 | [diff] [blame] | 881 | config_set_argv(&config, Py_ARRAY_LENGTH(argv), argv); |
| 882 | config_set_program_name(&config); |
| 883 | init_from_config_clear(&config); |
Victor Stinner | 6d1c467 | 2019-05-20 11:02:00 +0200 | [diff] [blame] | 884 | |
| 885 | dump_config(); |
| 886 | Py_Finalize(); |
| 887 | return 0; |
Victor Stinner | 6d1c467 | 2019-05-20 11:02:00 +0200 | [diff] [blame] | 888 | } |
| 889 | |
| 890 | |
| 891 | static int test_preinit_parse_argv(void) |
| 892 | { |
Victor Stinner | 331a6a5 | 2019-05-27 16:39:22 +0200 | [diff] [blame] | 893 | PyStatus status; |
| 894 | PyConfig config; |
Victor Stinner | 6d1c467 | 2019-05-20 11:02:00 +0200 | [diff] [blame] | 895 | |
Victor Stinner | 331a6a5 | 2019-05-27 16:39:22 +0200 | [diff] [blame] | 896 | status = PyConfig_InitPythonConfig(&config); |
| 897 | if (PyStatus_Exception(status)) { |
Miss Islington (bot) | 4c227e6 | 2019-07-01 11:28:55 -0700 | [diff] [blame] | 898 | PyConfig_Clear(&config); |
| 899 | Py_ExitStatusException(status); |
Victor Stinner | 6d1c467 | 2019-05-20 11:02:00 +0200 | [diff] [blame] | 900 | } |
| 901 | |
| 902 | /* Pre-initialize implicitly using argv: make sure that -X dev |
| 903 | is used to configure the allocation in preinitialization */ |
| 904 | wchar_t *argv[] = {L"python3", L"-X", L"dev", L"script.py"}; |
Miss Islington (bot) | 4c227e6 | 2019-07-01 11:28:55 -0700 | [diff] [blame] | 905 | config_set_argv(&config, Py_ARRAY_LENGTH(argv), argv); |
| 906 | config_set_program_name(&config); |
| 907 | init_from_config_clear(&config); |
Victor Stinner | 6d1c467 | 2019-05-20 11:02:00 +0200 | [diff] [blame] | 908 | |
| 909 | dump_config(); |
| 910 | Py_Finalize(); |
| 911 | return 0; |
Victor Stinner | 6d1c467 | 2019-05-20 11:02:00 +0200 | [diff] [blame] | 912 | } |
| 913 | |
| 914 | |
| 915 | |
| 916 | |
Victor Stinner | bab0db6 | 2019-05-18 03:21:27 +0200 | [diff] [blame] | 917 | static void set_all_global_config_variables(void) |
| 918 | { |
| 919 | Py_IsolatedFlag = 0; |
| 920 | Py_IgnoreEnvironmentFlag = 0; |
| 921 | Py_BytesWarningFlag = 2; |
| 922 | Py_InspectFlag = 1; |
| 923 | Py_InteractiveFlag = 1; |
| 924 | Py_OptimizeFlag = 1; |
| 925 | Py_DebugFlag = 1; |
| 926 | Py_VerboseFlag = 1; |
| 927 | Py_QuietFlag = 1; |
| 928 | Py_FrozenFlag = 0; |
| 929 | Py_UnbufferedStdioFlag = 1; |
| 930 | Py_NoSiteFlag = 1; |
| 931 | Py_DontWriteBytecodeFlag = 1; |
| 932 | Py_NoUserSiteDirectory = 1; |
| 933 | #ifdef MS_WINDOWS |
| 934 | Py_LegacyWindowsStdioFlag = 1; |
| 935 | #endif |
| 936 | } |
| 937 | |
| 938 | |
Victor Stinner | 6d1c467 | 2019-05-20 11:02:00 +0200 | [diff] [blame] | 939 | static int check_preinit_isolated_config(int preinit) |
Victor Stinner | 56b29b6 | 2018-07-26 18:57:56 +0200 | [diff] [blame] | 940 | { |
Victor Stinner | 331a6a5 | 2019-05-27 16:39:22 +0200 | [diff] [blame] | 941 | PyStatus status; |
| 942 | PyPreConfig *rt_preconfig; |
Victor Stinner | cab5d07 | 2019-05-17 19:01:14 +0200 | [diff] [blame] | 943 | |
Victor Stinner | bab0db6 | 2019-05-18 03:21:27 +0200 | [diff] [blame] | 944 | /* environment variables must be ignored */ |
| 945 | set_all_env_vars(); |
| 946 | |
| 947 | /* global configuration variables must be ignored */ |
| 948 | set_all_global_config_variables(); |
| 949 | |
Victor Stinner | 6d1c467 | 2019-05-20 11:02:00 +0200 | [diff] [blame] | 950 | if (preinit) { |
Victor Stinner | 331a6a5 | 2019-05-27 16:39:22 +0200 | [diff] [blame] | 951 | PyPreConfig preconfig; |
Victor Stinner | bdace21 | 2019-10-01 00:46:42 +0200 | [diff] [blame^] | 952 | PyPreConfig_InitIsolatedConfig(&preconfig); |
Victor Stinner | cab5d07 | 2019-05-17 19:01:14 +0200 | [diff] [blame] | 953 | |
Victor Stinner | 331a6a5 | 2019-05-27 16:39:22 +0200 | [diff] [blame] | 954 | status = Py_PreInitialize(&preconfig); |
| 955 | if (PyStatus_Exception(status)) { |
| 956 | Py_ExitStatusException(status); |
Victor Stinner | 6d1c467 | 2019-05-20 11:02:00 +0200 | [diff] [blame] | 957 | } |
| 958 | |
| 959 | rt_preconfig = &_PyRuntime.preconfig; |
| 960 | assert(rt_preconfig->isolated == 1); |
| 961 | assert(rt_preconfig->use_environment == 0); |
Victor Stinner | cab5d07 | 2019-05-17 19:01:14 +0200 | [diff] [blame] | 962 | } |
| 963 | |
Victor Stinner | 331a6a5 | 2019-05-27 16:39:22 +0200 | [diff] [blame] | 964 | PyConfig config; |
Victor Stinner | 6e12838 | 2019-09-28 04:50:43 +0200 | [diff] [blame] | 965 | |
Victor Stinner | 331a6a5 | 2019-05-27 16:39:22 +0200 | [diff] [blame] | 966 | status = PyConfig_InitIsolatedConfig(&config); |
| 967 | if (PyStatus_Exception(status)) { |
| 968 | PyConfig_Clear(&config); |
| 969 | Py_ExitStatusException(status); |
Victor Stinner | cab5d07 | 2019-05-17 19:01:14 +0200 | [diff] [blame] | 970 | } |
Miss Islington (bot) | 4c227e6 | 2019-07-01 11:28:55 -0700 | [diff] [blame] | 971 | config_set_program_name(&config); |
| 972 | init_from_config_clear(&config); |
Victor Stinner | 6d1c467 | 2019-05-20 11:02:00 +0200 | [diff] [blame] | 973 | |
| 974 | rt_preconfig = &_PyRuntime.preconfig; |
| 975 | assert(rt_preconfig->isolated == 1); |
| 976 | assert(rt_preconfig->use_environment == 0); |
| 977 | |
Victor Stinner | cab5d07 | 2019-05-17 19:01:14 +0200 | [diff] [blame] | 978 | dump_config(); |
| 979 | Py_Finalize(); |
| 980 | return 0; |
| 981 | } |
| 982 | |
| 983 | |
Victor Stinner | 6d1c467 | 2019-05-20 11:02:00 +0200 | [diff] [blame] | 984 | static int test_preinit_isolated_config(void) |
| 985 | { |
| 986 | return check_preinit_isolated_config(1); |
| 987 | } |
| 988 | |
| 989 | |
| 990 | static int test_init_isolated_config(void) |
| 991 | { |
| 992 | return check_preinit_isolated_config(0); |
| 993 | } |
| 994 | |
| 995 | |
| 996 | static int check_init_python_config(int preinit) |
Victor Stinner | cab5d07 | 2019-05-17 19:01:14 +0200 | [diff] [blame] | 997 | { |
Victor Stinner | 331a6a5 | 2019-05-27 16:39:22 +0200 | [diff] [blame] | 998 | PyStatus status; |
Victor Stinner | cab5d07 | 2019-05-17 19:01:14 +0200 | [diff] [blame] | 999 | |
Victor Stinner | bab0db6 | 2019-05-18 03:21:27 +0200 | [diff] [blame] | 1000 | /* global configuration variables must be ignored */ |
| 1001 | set_all_global_config_variables(); |
| 1002 | Py_IsolatedFlag = 1; |
| 1003 | Py_IgnoreEnvironmentFlag = 1; |
| 1004 | Py_FrozenFlag = 1; |
| 1005 | Py_UnbufferedStdioFlag = 1; |
| 1006 | Py_NoSiteFlag = 1; |
| 1007 | Py_DontWriteBytecodeFlag = 1; |
| 1008 | Py_NoUserSiteDirectory = 1; |
| 1009 | #ifdef MS_WINDOWS |
| 1010 | Py_LegacyWindowsStdioFlag = 1; |
| 1011 | #endif |
| 1012 | |
Victor Stinner | 6d1c467 | 2019-05-20 11:02:00 +0200 | [diff] [blame] | 1013 | if (preinit) { |
Victor Stinner | 331a6a5 | 2019-05-27 16:39:22 +0200 | [diff] [blame] | 1014 | PyPreConfig preconfig; |
Victor Stinner | bdace21 | 2019-10-01 00:46:42 +0200 | [diff] [blame^] | 1015 | PyPreConfig_InitPythonConfig(&preconfig); |
Victor Stinner | cab5d07 | 2019-05-17 19:01:14 +0200 | [diff] [blame] | 1016 | |
Victor Stinner | 331a6a5 | 2019-05-27 16:39:22 +0200 | [diff] [blame] | 1017 | status = Py_PreInitialize(&preconfig); |
| 1018 | if (PyStatus_Exception(status)) { |
| 1019 | Py_ExitStatusException(status); |
Victor Stinner | 6d1c467 | 2019-05-20 11:02:00 +0200 | [diff] [blame] | 1020 | } |
Victor Stinner | cab5d07 | 2019-05-17 19:01:14 +0200 | [diff] [blame] | 1021 | } |
| 1022 | |
Victor Stinner | 331a6a5 | 2019-05-27 16:39:22 +0200 | [diff] [blame] | 1023 | PyConfig config; |
Victor Stinner | 6e12838 | 2019-09-28 04:50:43 +0200 | [diff] [blame] | 1024 | |
Victor Stinner | 331a6a5 | 2019-05-27 16:39:22 +0200 | [diff] [blame] | 1025 | status = PyConfig_InitPythonConfig(&config); |
| 1026 | if (PyStatus_Exception(status)) { |
| 1027 | Py_ExitStatusException(status); |
Victor Stinner | cab5d07 | 2019-05-17 19:01:14 +0200 | [diff] [blame] | 1028 | } |
Miss Islington (bot) | 4c227e6 | 2019-07-01 11:28:55 -0700 | [diff] [blame] | 1029 | config_set_program_name(&config); |
| 1030 | init_from_config_clear(&config); |
Victor Stinner | cab5d07 | 2019-05-17 19:01:14 +0200 | [diff] [blame] | 1031 | |
Victor Stinner | cab5d07 | 2019-05-17 19:01:14 +0200 | [diff] [blame] | 1032 | dump_config(); |
| 1033 | Py_Finalize(); |
| 1034 | return 0; |
| 1035 | } |
| 1036 | |
| 1037 | |
Victor Stinner | 6d1c467 | 2019-05-20 11:02:00 +0200 | [diff] [blame] | 1038 | static int test_preinit_python_config(void) |
| 1039 | { |
| 1040 | return check_init_python_config(1); |
| 1041 | } |
| 1042 | |
| 1043 | |
| 1044 | static int test_init_python_config(void) |
| 1045 | { |
| 1046 | return check_init_python_config(0); |
| 1047 | } |
| 1048 | |
| 1049 | |
Victor Stinner | bab0db6 | 2019-05-18 03:21:27 +0200 | [diff] [blame] | 1050 | static int test_init_dont_configure_locale(void) |
Victor Stinner | bcfbbd7 | 2019-05-17 22:44:16 +0200 | [diff] [blame] | 1051 | { |
Victor Stinner | 331a6a5 | 2019-05-27 16:39:22 +0200 | [diff] [blame] | 1052 | PyPreConfig preconfig; |
Victor Stinner | bdace21 | 2019-10-01 00:46:42 +0200 | [diff] [blame^] | 1053 | PyPreConfig_InitPythonConfig(&preconfig); |
Victor Stinner | 6e12838 | 2019-09-28 04:50:43 +0200 | [diff] [blame] | 1054 | |
Victor Stinner | bcfbbd7 | 2019-05-17 22:44:16 +0200 | [diff] [blame] | 1055 | preconfig.configure_locale = 0; |
| 1056 | preconfig.coerce_c_locale = 1; |
| 1057 | preconfig.coerce_c_locale_warn = 1; |
| 1058 | |
Victor Stinner | bdace21 | 2019-10-01 00:46:42 +0200 | [diff] [blame^] | 1059 | PyStatus status = Py_PreInitialize(&preconfig); |
Victor Stinner | 331a6a5 | 2019-05-27 16:39:22 +0200 | [diff] [blame] | 1060 | if (PyStatus_Exception(status)) { |
| 1061 | Py_ExitStatusException(status); |
Victor Stinner | bcfbbd7 | 2019-05-17 22:44:16 +0200 | [diff] [blame] | 1062 | } |
| 1063 | |
Victor Stinner | 331a6a5 | 2019-05-27 16:39:22 +0200 | [diff] [blame] | 1064 | PyConfig config; |
Victor Stinner | 6e12838 | 2019-09-28 04:50:43 +0200 | [diff] [blame] | 1065 | |
Victor Stinner | 331a6a5 | 2019-05-27 16:39:22 +0200 | [diff] [blame] | 1066 | status = PyConfig_InitPythonConfig(&config); |
| 1067 | if (PyStatus_Exception(status)) { |
| 1068 | Py_ExitStatusException(status); |
Victor Stinner | 6d1c467 | 2019-05-20 11:02:00 +0200 | [diff] [blame] | 1069 | } |
Miss Islington (bot) | 4c227e6 | 2019-07-01 11:28:55 -0700 | [diff] [blame] | 1070 | config_set_program_name(&config); |
| 1071 | init_from_config_clear(&config); |
Victor Stinner | bcfbbd7 | 2019-05-17 22:44:16 +0200 | [diff] [blame] | 1072 | |
| 1073 | dump_config(); |
| 1074 | Py_Finalize(); |
| 1075 | return 0; |
| 1076 | } |
| 1077 | |
| 1078 | |
Victor Stinner | bab0db6 | 2019-05-18 03:21:27 +0200 | [diff] [blame] | 1079 | static int test_init_dev_mode(void) |
Victor Stinner | cab5d07 | 2019-05-17 19:01:14 +0200 | [diff] [blame] | 1080 | { |
Victor Stinner | 331a6a5 | 2019-05-27 16:39:22 +0200 | [diff] [blame] | 1081 | PyStatus status; |
| 1082 | PyConfig config; |
Victor Stinner | 6e12838 | 2019-09-28 04:50:43 +0200 | [diff] [blame] | 1083 | |
Victor Stinner | 331a6a5 | 2019-05-27 16:39:22 +0200 | [diff] [blame] | 1084 | status = PyConfig_InitPythonConfig(&config); |
| 1085 | if (PyStatus_Exception(status)) { |
| 1086 | Py_ExitStatusException(status); |
Victor Stinner | 6d1c467 | 2019-05-20 11:02:00 +0200 | [diff] [blame] | 1087 | } |
Victor Stinner | 56b29b6 | 2018-07-26 18:57:56 +0200 | [diff] [blame] | 1088 | putenv("PYTHONFAULTHANDLER="); |
| 1089 | putenv("PYTHONMALLOC="); |
Victor Stinner | 2000495 | 2019-03-26 02:31:11 +0100 | [diff] [blame] | 1090 | config.dev_mode = 1; |
Miss Islington (bot) | 4c227e6 | 2019-07-01 11:28:55 -0700 | [diff] [blame] | 1091 | config_set_program_name(&config); |
| 1092 | init_from_config_clear(&config); |
| 1093 | |
Victor Stinner | 56b29b6 | 2018-07-26 18:57:56 +0200 | [diff] [blame] | 1094 | dump_config(); |
| 1095 | Py_Finalize(); |
| 1096 | return 0; |
| 1097 | } |
| 1098 | |
Steve Dower | b82e17e | 2019-05-23 08:45:22 -0700 | [diff] [blame] | 1099 | static PyObject *_open_code_hook(PyObject *path, void *data) |
| 1100 | { |
| 1101 | if (PyUnicode_CompareWithASCIIString(path, "$$test-filename") == 0) { |
| 1102 | return PyLong_FromVoidPtr(data); |
| 1103 | } |
| 1104 | PyObject *io = PyImport_ImportModule("_io"); |
| 1105 | if (!io) { |
| 1106 | return NULL; |
| 1107 | } |
| 1108 | return PyObject_CallMethod(io, "open", "Os", path, "rb"); |
| 1109 | } |
| 1110 | |
| 1111 | static int test_open_code_hook(void) |
| 1112 | { |
| 1113 | int result = 0; |
| 1114 | |
| 1115 | /* Provide a hook */ |
| 1116 | result = PyFile_SetOpenCodeHook(_open_code_hook, &result); |
| 1117 | if (result) { |
| 1118 | printf("Failed to set hook\n"); |
| 1119 | return 1; |
| 1120 | } |
| 1121 | /* A second hook should fail */ |
| 1122 | result = PyFile_SetOpenCodeHook(_open_code_hook, &result); |
| 1123 | if (!result) { |
| 1124 | printf("Should have failed to set second hook\n"); |
| 1125 | return 2; |
| 1126 | } |
| 1127 | |
| 1128 | Py_IgnoreEnvironmentFlag = 0; |
| 1129 | _testembed_Py_Initialize(); |
| 1130 | result = 0; |
| 1131 | |
| 1132 | PyObject *r = PyFile_OpenCode("$$test-filename"); |
| 1133 | if (!r) { |
| 1134 | PyErr_Print(); |
| 1135 | result = 3; |
| 1136 | } else { |
| 1137 | void *cmp = PyLong_AsVoidPtr(r); |
| 1138 | Py_DECREF(r); |
| 1139 | if (cmp != &result) { |
| 1140 | printf("Did not get expected result from hook\n"); |
| 1141 | result = 4; |
| 1142 | } |
| 1143 | } |
| 1144 | |
| 1145 | if (!result) { |
| 1146 | PyObject *io = PyImport_ImportModule("_io"); |
| 1147 | PyObject *r = io |
| 1148 | ? PyObject_CallMethod(io, "open_code", "s", "$$test-filename") |
| 1149 | : NULL; |
| 1150 | if (!r) { |
| 1151 | PyErr_Print(); |
| 1152 | result = 5; |
| 1153 | } else { |
| 1154 | void *cmp = PyLong_AsVoidPtr(r); |
| 1155 | Py_DECREF(r); |
| 1156 | if (cmp != &result) { |
| 1157 | printf("Did not get expected result from hook\n"); |
| 1158 | result = 6; |
| 1159 | } |
| 1160 | } |
| 1161 | Py_XDECREF(io); |
| 1162 | } |
| 1163 | |
| 1164 | Py_Finalize(); |
| 1165 | return result; |
| 1166 | } |
| 1167 | |
| 1168 | static int _audit_hook(const char *event, PyObject *args, void *userdata) |
| 1169 | { |
| 1170 | if (strcmp(event, "_testembed.raise") == 0) { |
| 1171 | PyErr_SetString(PyExc_RuntimeError, "Intentional error"); |
| 1172 | return -1; |
| 1173 | } else if (strcmp(event, "_testembed.set") == 0) { |
| 1174 | if (!PyArg_ParseTuple(args, "n", userdata)) { |
| 1175 | return -1; |
| 1176 | } |
| 1177 | return 0; |
| 1178 | } |
| 1179 | return 0; |
| 1180 | } |
| 1181 | |
| 1182 | static int _test_audit(Py_ssize_t setValue) |
| 1183 | { |
| 1184 | Py_ssize_t sawSet = 0; |
| 1185 | |
| 1186 | Py_IgnoreEnvironmentFlag = 0; |
| 1187 | PySys_AddAuditHook(_audit_hook, &sawSet); |
| 1188 | _testembed_Py_Initialize(); |
| 1189 | |
| 1190 | if (PySys_Audit("_testembed.raise", NULL) == 0) { |
| 1191 | printf("No error raised"); |
| 1192 | return 1; |
| 1193 | } |
| 1194 | if (PySys_Audit("_testembed.nop", NULL) != 0) { |
| 1195 | printf("Nop event failed"); |
| 1196 | /* Exception from above may still remain */ |
| 1197 | PyErr_Clear(); |
| 1198 | return 2; |
| 1199 | } |
| 1200 | if (!PyErr_Occurred()) { |
| 1201 | printf("Exception not preserved"); |
| 1202 | return 3; |
| 1203 | } |
| 1204 | PyErr_Clear(); |
| 1205 | |
| 1206 | if (PySys_Audit("_testembed.set", "n", setValue) != 0) { |
| 1207 | PyErr_Print(); |
| 1208 | printf("Set event failed"); |
| 1209 | return 4; |
| 1210 | } |
| 1211 | |
| 1212 | if (sawSet != 42) { |
| 1213 | printf("Failed to see *userData change\n"); |
| 1214 | return 5; |
| 1215 | } |
| 1216 | return 0; |
| 1217 | } |
| 1218 | |
| 1219 | static int test_audit(void) |
| 1220 | { |
| 1221 | int result = _test_audit(42); |
| 1222 | Py_Finalize(); |
| 1223 | return result; |
| 1224 | } |
| 1225 | |
| 1226 | static volatile int _audit_subinterpreter_interpreter_count = 0; |
| 1227 | |
| 1228 | static int _audit_subinterpreter_hook(const char *event, PyObject *args, void *userdata) |
| 1229 | { |
| 1230 | printf("%s\n", event); |
| 1231 | if (strcmp(event, "cpython.PyInterpreterState_New") == 0) { |
| 1232 | _audit_subinterpreter_interpreter_count += 1; |
| 1233 | } |
| 1234 | return 0; |
| 1235 | } |
| 1236 | |
| 1237 | static int test_audit_subinterpreter(void) |
| 1238 | { |
Steve Dower | b82e17e | 2019-05-23 08:45:22 -0700 | [diff] [blame] | 1239 | Py_IgnoreEnvironmentFlag = 0; |
| 1240 | PySys_AddAuditHook(_audit_subinterpreter_hook, NULL); |
| 1241 | _testembed_Py_Initialize(); |
| 1242 | |
Pablo Galindo | cccc11b | 2019-05-24 00:53:21 +0100 | [diff] [blame] | 1243 | Py_NewInterpreter(); |
| 1244 | Py_NewInterpreter(); |
| 1245 | Py_NewInterpreter(); |
Steve Dower | b82e17e | 2019-05-23 08:45:22 -0700 | [diff] [blame] | 1246 | |
| 1247 | Py_Finalize(); |
| 1248 | |
| 1249 | switch (_audit_subinterpreter_interpreter_count) { |
| 1250 | case 3: return 0; |
| 1251 | case 0: return -1; |
| 1252 | default: return _audit_subinterpreter_interpreter_count; |
| 1253 | } |
| 1254 | } |
Victor Stinner | 56b29b6 | 2018-07-26 18:57:56 +0200 | [diff] [blame] | 1255 | |
Miss Islington (bot) | 746992c | 2019-07-01 16:22:29 -0700 | [diff] [blame] | 1256 | typedef struct { |
| 1257 | const char* expected; |
| 1258 | int exit; |
| 1259 | } AuditRunCommandTest; |
| 1260 | |
| 1261 | static int _audit_hook_run(const char *eventName, PyObject *args, void *userData) |
| 1262 | { |
| 1263 | AuditRunCommandTest *test = (AuditRunCommandTest*)userData; |
| 1264 | if (strcmp(eventName, test->expected)) { |
| 1265 | return 0; |
| 1266 | } |
| 1267 | |
| 1268 | if (test->exit) { |
| 1269 | PyObject *msg = PyUnicode_FromFormat("detected %s(%R)", eventName, args); |
| 1270 | if (msg) { |
| 1271 | printf("%s\n", PyUnicode_AsUTF8(msg)); |
| 1272 | Py_DECREF(msg); |
| 1273 | } |
| 1274 | exit(test->exit); |
| 1275 | } |
| 1276 | |
| 1277 | PyErr_Format(PyExc_RuntimeError, "detected %s(%R)", eventName, args); |
| 1278 | return -1; |
| 1279 | } |
| 1280 | |
| 1281 | static int test_audit_run_command(void) |
| 1282 | { |
| 1283 | AuditRunCommandTest test = {"cpython.run_command"}; |
Victor Stinner | 96c8475 | 2019-09-26 16:17:34 +0200 | [diff] [blame] | 1284 | wchar_t *argv[] = {PROGRAM_NAME, L"-c", L"pass"}; |
Miss Islington (bot) | 746992c | 2019-07-01 16:22:29 -0700 | [diff] [blame] | 1285 | |
| 1286 | Py_IgnoreEnvironmentFlag = 0; |
| 1287 | PySys_AddAuditHook(_audit_hook_run, (void*)&test); |
| 1288 | |
| 1289 | return Py_Main(Py_ARRAY_LENGTH(argv), argv); |
| 1290 | } |
| 1291 | |
| 1292 | static int test_audit_run_file(void) |
| 1293 | { |
| 1294 | AuditRunCommandTest test = {"cpython.run_file"}; |
Victor Stinner | 96c8475 | 2019-09-26 16:17:34 +0200 | [diff] [blame] | 1295 | wchar_t *argv[] = {PROGRAM_NAME, L"filename.py"}; |
Miss Islington (bot) | 746992c | 2019-07-01 16:22:29 -0700 | [diff] [blame] | 1296 | |
| 1297 | Py_IgnoreEnvironmentFlag = 0; |
| 1298 | PySys_AddAuditHook(_audit_hook_run, (void*)&test); |
| 1299 | |
| 1300 | return Py_Main(Py_ARRAY_LENGTH(argv), argv); |
| 1301 | } |
| 1302 | |
| 1303 | static int run_audit_run_test(int argc, wchar_t **argv, void *test) |
| 1304 | { |
| 1305 | PyStatus status; |
| 1306 | PyConfig config; |
Victor Stinner | 6e12838 | 2019-09-28 04:50:43 +0200 | [diff] [blame] | 1307 | |
Miss Islington (bot) | 746992c | 2019-07-01 16:22:29 -0700 | [diff] [blame] | 1308 | status = PyConfig_InitPythonConfig(&config); |
| 1309 | if (PyStatus_Exception(status)) { |
| 1310 | Py_ExitStatusException(status); |
| 1311 | } |
| 1312 | config.argv.length = argc; |
| 1313 | config.argv.items = argv; |
| 1314 | config.parse_argv = 1; |
| 1315 | config.program_name = argv[0]; |
| 1316 | config.interactive = 1; |
| 1317 | config.isolated = 0; |
| 1318 | config.use_environment = 1; |
| 1319 | config.quiet = 1; |
| 1320 | |
| 1321 | PySys_AddAuditHook(_audit_hook_run, test); |
| 1322 | |
| 1323 | status = Py_InitializeFromConfig(&config); |
| 1324 | if (PyStatus_Exception(status)) { |
| 1325 | Py_ExitStatusException(status); |
| 1326 | } |
| 1327 | |
| 1328 | return Py_RunMain(); |
| 1329 | } |
| 1330 | |
| 1331 | static int test_audit_run_interactivehook(void) |
| 1332 | { |
| 1333 | AuditRunCommandTest test = {"cpython.run_interactivehook", 10}; |
Victor Stinner | 96c8475 | 2019-09-26 16:17:34 +0200 | [diff] [blame] | 1334 | wchar_t *argv[] = {PROGRAM_NAME}; |
Miss Islington (bot) | 746992c | 2019-07-01 16:22:29 -0700 | [diff] [blame] | 1335 | return run_audit_run_test(Py_ARRAY_LENGTH(argv), argv, &test); |
| 1336 | } |
| 1337 | |
| 1338 | static int test_audit_run_startup(void) |
| 1339 | { |
| 1340 | AuditRunCommandTest test = {"cpython.run_startup", 10}; |
Victor Stinner | 96c8475 | 2019-09-26 16:17:34 +0200 | [diff] [blame] | 1341 | wchar_t *argv[] = {PROGRAM_NAME}; |
Miss Islington (bot) | 746992c | 2019-07-01 16:22:29 -0700 | [diff] [blame] | 1342 | return run_audit_run_test(Py_ARRAY_LENGTH(argv), argv, &test); |
| 1343 | } |
| 1344 | |
| 1345 | static int test_audit_run_stdin(void) |
| 1346 | { |
| 1347 | AuditRunCommandTest test = {"cpython.run_stdin"}; |
Victor Stinner | 96c8475 | 2019-09-26 16:17:34 +0200 | [diff] [blame] | 1348 | wchar_t *argv[] = {PROGRAM_NAME}; |
Miss Islington (bot) | 746992c | 2019-07-01 16:22:29 -0700 | [diff] [blame] | 1349 | return run_audit_run_test(Py_ARRAY_LENGTH(argv), argv, &test); |
| 1350 | } |
| 1351 | |
Victor Stinner | 91c9987 | 2019-05-14 22:01:51 +0200 | [diff] [blame] | 1352 | static int test_init_read_set(void) |
| 1353 | { |
Victor Stinner | 331a6a5 | 2019-05-27 16:39:22 +0200 | [diff] [blame] | 1354 | PyStatus status; |
| 1355 | PyConfig config; |
Victor Stinner | 6e12838 | 2019-09-28 04:50:43 +0200 | [diff] [blame] | 1356 | |
Victor Stinner | 331a6a5 | 2019-05-27 16:39:22 +0200 | [diff] [blame] | 1357 | status = PyConfig_InitPythonConfig(&config); |
| 1358 | if (PyStatus_Exception(status)) { |
| 1359 | Py_ExitStatusException(status); |
Victor Stinner | 6d1c467 | 2019-05-20 11:02:00 +0200 | [diff] [blame] | 1360 | } |
Victor Stinner | 91c9987 | 2019-05-14 22:01:51 +0200 | [diff] [blame] | 1361 | |
Victor Stinner | 331a6a5 | 2019-05-27 16:39:22 +0200 | [diff] [blame] | 1362 | status = PyConfig_SetBytesString(&config, &config.program_name, |
Victor Stinner | 6d1c467 | 2019-05-20 11:02:00 +0200 | [diff] [blame] | 1363 | "./init_read_set"); |
Victor Stinner | 331a6a5 | 2019-05-27 16:39:22 +0200 | [diff] [blame] | 1364 | if (PyStatus_Exception(status)) { |
Victor Stinner | 91c9987 | 2019-05-14 22:01:51 +0200 | [diff] [blame] | 1365 | goto fail; |
| 1366 | } |
| 1367 | |
Victor Stinner | 331a6a5 | 2019-05-27 16:39:22 +0200 | [diff] [blame] | 1368 | status = PyConfig_Read(&config); |
| 1369 | if (PyStatus_Exception(status)) { |
Victor Stinner | 91c9987 | 2019-05-14 22:01:51 +0200 | [diff] [blame] | 1370 | goto fail; |
| 1371 | } |
| 1372 | |
Miss Islington (bot) | a6427cb | 2019-08-23 09:24:42 -0700 | [diff] [blame] | 1373 | status = PyWideStringList_Insert(&config.module_search_paths, |
| 1374 | 1, L"test_path_insert1"); |
| 1375 | if (PyStatus_Exception(status)) { |
| 1376 | goto fail; |
| 1377 | } |
| 1378 | |
Victor Stinner | 331a6a5 | 2019-05-27 16:39:22 +0200 | [diff] [blame] | 1379 | status = PyWideStringList_Append(&config.module_search_paths, |
Miss Islington (bot) | a6427cb | 2019-08-23 09:24:42 -0700 | [diff] [blame] | 1380 | L"test_path_append"); |
Victor Stinner | 331a6a5 | 2019-05-27 16:39:22 +0200 | [diff] [blame] | 1381 | if (PyStatus_Exception(status)) { |
Victor Stinner | 91c9987 | 2019-05-14 22:01:51 +0200 | [diff] [blame] | 1382 | goto fail; |
| 1383 | } |
| 1384 | |
Victor Stinner | 331a6a5 | 2019-05-27 16:39:22 +0200 | [diff] [blame] | 1385 | /* override executable computed by PyConfig_Read() */ |
Miss Islington (bot) | 4c227e6 | 2019-07-01 11:28:55 -0700 | [diff] [blame] | 1386 | config_set_string(&config, &config.executable, L"my_executable"); |
| 1387 | init_from_config_clear(&config); |
Victor Stinner | 91c9987 | 2019-05-14 22:01:51 +0200 | [diff] [blame] | 1388 | |
Victor Stinner | 91c9987 | 2019-05-14 22:01:51 +0200 | [diff] [blame] | 1389 | dump_config(); |
| 1390 | Py_Finalize(); |
| 1391 | return 0; |
| 1392 | |
| 1393 | fail: |
Victor Stinner | 331a6a5 | 2019-05-27 16:39:22 +0200 | [diff] [blame] | 1394 | Py_ExitStatusException(status); |
Victor Stinner | 91c9987 | 2019-05-14 22:01:51 +0200 | [diff] [blame] | 1395 | } |
| 1396 | |
| 1397 | |
Victor Stinner | af84a88 | 2019-08-23 21:16:51 +0200 | [diff] [blame] | 1398 | static int test_init_sys_add(void) |
| 1399 | { |
| 1400 | PySys_AddXOption(L"sysadd_xoption"); |
| 1401 | PySys_AddXOption(L"faulthandler"); |
| 1402 | PySys_AddWarnOption(L"ignore:::sysadd_warnoption"); |
| 1403 | |
| 1404 | PyConfig config; |
Victor Stinner | 6e12838 | 2019-09-28 04:50:43 +0200 | [diff] [blame] | 1405 | |
Victor Stinner | af84a88 | 2019-08-23 21:16:51 +0200 | [diff] [blame] | 1406 | PyStatus status; |
| 1407 | status = PyConfig_InitPythonConfig(&config); |
| 1408 | if (PyStatus_Exception(status)) { |
| 1409 | goto fail; |
| 1410 | } |
| 1411 | |
| 1412 | wchar_t* argv[] = { |
| 1413 | L"python3", |
| 1414 | L"-W", |
| 1415 | L"ignore:::cmdline_warnoption", |
| 1416 | L"-X", |
| 1417 | L"cmdline_xoption", |
| 1418 | }; |
| 1419 | config_set_argv(&config, Py_ARRAY_LENGTH(argv), argv); |
| 1420 | config.parse_argv = 1; |
| 1421 | |
| 1422 | status = PyWideStringList_Append(&config.xoptions, |
| 1423 | L"config_xoption"); |
| 1424 | if (PyStatus_Exception(status)) { |
| 1425 | goto fail; |
| 1426 | } |
| 1427 | |
| 1428 | status = PyWideStringList_Append(&config.warnoptions, |
| 1429 | L"ignore:::config_warnoption"); |
| 1430 | if (PyStatus_Exception(status)) { |
| 1431 | goto fail; |
| 1432 | } |
| 1433 | |
| 1434 | config_set_program_name(&config); |
| 1435 | init_from_config_clear(&config); |
| 1436 | |
| 1437 | dump_config(); |
| 1438 | Py_Finalize(); |
| 1439 | return 0; |
| 1440 | |
| 1441 | fail: |
| 1442 | PyConfig_Clear(&config); |
| 1443 | Py_ExitStatusException(status); |
| 1444 | } |
| 1445 | |
| 1446 | |
Victor Stinner | 96c8475 | 2019-09-26 16:17:34 +0200 | [diff] [blame] | 1447 | static int test_init_setpath(void) |
| 1448 | { |
| 1449 | char *env = getenv("TESTPATH"); |
| 1450 | if (!env) { |
| 1451 | fprintf(stderr, "missing TESTPATH env var\n"); |
| 1452 | return 1; |
| 1453 | } |
| 1454 | wchar_t *path = Py_DecodeLocale(env, NULL); |
| 1455 | if (path == NULL) { |
| 1456 | fprintf(stderr, "failed to decode TESTPATH\n"); |
| 1457 | return 1; |
| 1458 | } |
| 1459 | Py_SetPath(path); |
| 1460 | PyMem_RawFree(path); |
| 1461 | putenv("TESTPATH="); |
| 1462 | |
| 1463 | Py_Initialize(); |
| 1464 | dump_config(); |
| 1465 | Py_Finalize(); |
| 1466 | return 0; |
| 1467 | } |
| 1468 | |
| 1469 | |
| 1470 | static int test_init_setpath_config(void) |
| 1471 | { |
Victor Stinner | 96c8475 | 2019-09-26 16:17:34 +0200 | [diff] [blame] | 1472 | PyPreConfig preconfig; |
Victor Stinner | bdace21 | 2019-10-01 00:46:42 +0200 | [diff] [blame^] | 1473 | PyPreConfig_InitPythonConfig(&preconfig); |
Victor Stinner | 96c8475 | 2019-09-26 16:17:34 +0200 | [diff] [blame] | 1474 | |
| 1475 | /* Explicitly preinitializes with Python preconfiguration to avoid |
| 1476 | Py_SetPath() implicit preinitialization with compat preconfiguration. */ |
Victor Stinner | bdace21 | 2019-10-01 00:46:42 +0200 | [diff] [blame^] | 1477 | PyStatus status = Py_PreInitialize(&preconfig); |
Victor Stinner | 96c8475 | 2019-09-26 16:17:34 +0200 | [diff] [blame] | 1478 | if (PyStatus_Exception(status)) { |
| 1479 | Py_ExitStatusException(status); |
| 1480 | } |
| 1481 | |
| 1482 | char *env = getenv("TESTPATH"); |
| 1483 | if (!env) { |
| 1484 | fprintf(stderr, "missing TESTPATH env var\n"); |
| 1485 | return 1; |
| 1486 | } |
| 1487 | wchar_t *path = Py_DecodeLocale(env, NULL); |
| 1488 | if (path == NULL) { |
| 1489 | fprintf(stderr, "failed to decode TESTPATH\n"); |
| 1490 | return 1; |
| 1491 | } |
| 1492 | Py_SetPath(path); |
| 1493 | PyMem_RawFree(path); |
| 1494 | putenv("TESTPATH="); |
| 1495 | |
| 1496 | PyConfig config; |
| 1497 | |
| 1498 | status = PyConfig_InitPythonConfig(&config); |
| 1499 | if (PyStatus_Exception(status)) { |
| 1500 | Py_ExitStatusException(status); |
| 1501 | } |
| 1502 | config_set_string(&config, &config.program_name, L"conf_program_name"); |
| 1503 | config_set_string(&config, &config.executable, L"conf_executable"); |
| 1504 | init_from_config_clear(&config); |
| 1505 | |
| 1506 | dump_config(); |
| 1507 | Py_Finalize(); |
| 1508 | return 0; |
| 1509 | } |
| 1510 | |
| 1511 | |
| 1512 | static int test_init_setpythonhome(void) |
| 1513 | { |
| 1514 | char *env = getenv("TESTHOME"); |
| 1515 | if (!env) { |
| 1516 | fprintf(stderr, "missing TESTHOME env var\n"); |
| 1517 | return 1; |
| 1518 | } |
| 1519 | wchar_t *home = Py_DecodeLocale(env, NULL); |
| 1520 | if (home == NULL) { |
| 1521 | fprintf(stderr, "failed to decode TESTHOME\n"); |
| 1522 | return 1; |
| 1523 | } |
| 1524 | Py_SetPythonHome(home); |
| 1525 | PyMem_RawFree(home); |
| 1526 | putenv("TESTHOME="); |
| 1527 | |
| 1528 | Py_Initialize(); |
| 1529 | dump_config(); |
| 1530 | Py_Finalize(); |
| 1531 | return 0; |
| 1532 | } |
| 1533 | |
| 1534 | |
Miss Islington (bot) | c9ed9e6 | 2019-09-29 16:58:57 -0700 | [diff] [blame] | 1535 | static int test_init_warnoptions(void) |
| 1536 | { |
| 1537 | PyStatus status; |
| 1538 | putenv("PYTHONWARNINGS=ignore:::env1,ignore:::env2"); |
| 1539 | |
| 1540 | PySys_AddWarnOption(L"ignore:::PySys_AddWarnOption1"); |
| 1541 | PySys_AddWarnOption(L"ignore:::PySys_AddWarnOption2"); |
| 1542 | |
| 1543 | PyConfig config; |
Miss Islington (bot) | c9ed9e6 | 2019-09-29 16:58:57 -0700 | [diff] [blame] | 1544 | |
| 1545 | status = PyConfig_InitPythonConfig(&config); |
| 1546 | if (PyStatus_Exception(status)) { |
| 1547 | Py_ExitStatusException(status); |
| 1548 | } |
| 1549 | |
| 1550 | config.dev_mode = 1; |
| 1551 | config.bytes_warning = 1; |
| 1552 | |
| 1553 | config_set_program_name(&config); |
| 1554 | |
| 1555 | status = PyWideStringList_Append(&config.warnoptions, |
| 1556 | L"ignore:::PyConfig_BeforeRead"); |
| 1557 | if (PyStatus_Exception(status)) { |
| 1558 | Py_ExitStatusException(status); |
| 1559 | } |
| 1560 | |
| 1561 | wchar_t* argv[] = { |
| 1562 | L"python3", |
| 1563 | L"-Wignore:::cmdline1", |
| 1564 | L"-Wignore:::cmdline2"}; |
| 1565 | config_set_argv(&config, Py_ARRAY_LENGTH(argv), argv); |
| 1566 | config.parse_argv = 1; |
| 1567 | |
| 1568 | status = PyConfig_Read(&config); |
| 1569 | if (PyStatus_Exception(status)) { |
| 1570 | Py_ExitStatusException(status); |
| 1571 | } |
| 1572 | |
| 1573 | status = PyWideStringList_Append(&config.warnoptions, |
| 1574 | L"ignore:::PyConfig_AfterRead"); |
| 1575 | if (PyStatus_Exception(status)) { |
| 1576 | Py_ExitStatusException(status); |
| 1577 | } |
| 1578 | |
| 1579 | status = PyWideStringList_Insert(&config.warnoptions, |
| 1580 | 0, L"ignore:::PyConfig_Insert0"); |
| 1581 | if (PyStatus_Exception(status)) { |
| 1582 | Py_ExitStatusException(status); |
| 1583 | } |
| 1584 | |
| 1585 | init_from_config_clear(&config); |
| 1586 | dump_config(); |
| 1587 | Py_Finalize(); |
| 1588 | return 0; |
| 1589 | } |
| 1590 | |
| 1591 | |
Victor Stinner | 331a6a5 | 2019-05-27 16:39:22 +0200 | [diff] [blame] | 1592 | static void configure_init_main(PyConfig *config) |
Victor Stinner | 9ef5dca | 2019-05-16 17:38:16 +0200 | [diff] [blame] | 1593 | { |
Miss Islington (bot) | 4c227e6 | 2019-07-01 11:28:55 -0700 | [diff] [blame] | 1594 | wchar_t* argv[] = { |
| 1595 | L"python3", L"-c", |
| 1596 | (L"import _testinternalcapi, json; " |
| 1597 | L"print(json.dumps(_testinternalcapi.get_configs()))"), |
| 1598 | L"arg2"}; |
| 1599 | |
Victor Stinner | cab5d07 | 2019-05-17 19:01:14 +0200 | [diff] [blame] | 1600 | config->parse_argv = 1; |
Miss Islington (bot) | 4c227e6 | 2019-07-01 11:28:55 -0700 | [diff] [blame] | 1601 | |
| 1602 | config_set_argv(config, Py_ARRAY_LENGTH(argv), argv); |
| 1603 | config_set_string(config, &config->program_name, L"./python3"); |
Victor Stinner | 9ef5dca | 2019-05-16 17:38:16 +0200 | [diff] [blame] | 1604 | } |
| 1605 | |
| 1606 | |
| 1607 | static int test_init_run_main(void) |
Victor Stinner | 2f54908 | 2019-03-29 15:13:46 +0100 | [diff] [blame] | 1608 | { |
Victor Stinner | 331a6a5 | 2019-05-27 16:39:22 +0200 | [diff] [blame] | 1609 | PyStatus status; |
| 1610 | PyConfig config; |
Victor Stinner | 6e12838 | 2019-09-28 04:50:43 +0200 | [diff] [blame] | 1611 | |
Victor Stinner | 331a6a5 | 2019-05-27 16:39:22 +0200 | [diff] [blame] | 1612 | status = PyConfig_InitPythonConfig(&config); |
| 1613 | if (PyStatus_Exception(status)) { |
| 1614 | Py_ExitStatusException(status); |
Victor Stinner | 6d1c467 | 2019-05-20 11:02:00 +0200 | [diff] [blame] | 1615 | } |
Victor Stinner | 9ef5dca | 2019-05-16 17:38:16 +0200 | [diff] [blame] | 1616 | configure_init_main(&config); |
Miss Islington (bot) | 4c227e6 | 2019-07-01 11:28:55 -0700 | [diff] [blame] | 1617 | init_from_config_clear(&config); |
Victor Stinner | 2f54908 | 2019-03-29 15:13:46 +0100 | [diff] [blame] | 1618 | |
Victor Stinner | 331a6a5 | 2019-05-27 16:39:22 +0200 | [diff] [blame] | 1619 | return Py_RunMain(); |
Victor Stinner | 2f54908 | 2019-03-29 15:13:46 +0100 | [diff] [blame] | 1620 | } |
| 1621 | |
| 1622 | |
Victor Stinner | 9ef5dca | 2019-05-16 17:38:16 +0200 | [diff] [blame] | 1623 | static int test_init_main(void) |
| 1624 | { |
Victor Stinner | 331a6a5 | 2019-05-27 16:39:22 +0200 | [diff] [blame] | 1625 | PyStatus status; |
| 1626 | PyConfig config; |
Victor Stinner | 6d1c467 | 2019-05-20 11:02:00 +0200 | [diff] [blame] | 1627 | |
Victor Stinner | 331a6a5 | 2019-05-27 16:39:22 +0200 | [diff] [blame] | 1628 | status = PyConfig_InitPythonConfig(&config); |
| 1629 | if (PyStatus_Exception(status)) { |
| 1630 | Py_ExitStatusException(status); |
Victor Stinner | 6d1c467 | 2019-05-20 11:02:00 +0200 | [diff] [blame] | 1631 | } |
Victor Stinner | 9ef5dca | 2019-05-16 17:38:16 +0200 | [diff] [blame] | 1632 | configure_init_main(&config); |
| 1633 | config._init_main = 0; |
Miss Islington (bot) | 4c227e6 | 2019-07-01 11:28:55 -0700 | [diff] [blame] | 1634 | init_from_config_clear(&config); |
Victor Stinner | 9ef5dca | 2019-05-16 17:38:16 +0200 | [diff] [blame] | 1635 | |
| 1636 | /* sys.stdout don't exist yet: it is created by _Py_InitializeMain() */ |
| 1637 | int res = PyRun_SimpleString( |
| 1638 | "import sys; " |
| 1639 | "print('Run Python code before _Py_InitializeMain', " |
| 1640 | "file=sys.stderr)"); |
| 1641 | if (res < 0) { |
| 1642 | exit(1); |
| 1643 | } |
| 1644 | |
Victor Stinner | 331a6a5 | 2019-05-27 16:39:22 +0200 | [diff] [blame] | 1645 | status = _Py_InitializeMain(); |
| 1646 | if (PyStatus_Exception(status)) { |
| 1647 | Py_ExitStatusException(status); |
Victor Stinner | 9ef5dca | 2019-05-16 17:38:16 +0200 | [diff] [blame] | 1648 | } |
| 1649 | |
Victor Stinner | 331a6a5 | 2019-05-27 16:39:22 +0200 | [diff] [blame] | 1650 | return Py_RunMain(); |
Victor Stinner | 9ef5dca | 2019-05-16 17:38:16 +0200 | [diff] [blame] | 1651 | } |
| 1652 | |
| 1653 | |
| 1654 | static int test_run_main(void) |
Victor Stinner | 5eb8b07 | 2019-05-15 02:12:48 +0200 | [diff] [blame] | 1655 | { |
Victor Stinner | 331a6a5 | 2019-05-27 16:39:22 +0200 | [diff] [blame] | 1656 | PyStatus status; |
| 1657 | PyConfig config; |
Victor Stinner | 6d1c467 | 2019-05-20 11:02:00 +0200 | [diff] [blame] | 1658 | |
Victor Stinner | 331a6a5 | 2019-05-27 16:39:22 +0200 | [diff] [blame] | 1659 | status = PyConfig_InitPythonConfig(&config); |
| 1660 | if (PyStatus_Exception(status)) { |
Miss Islington (bot) | 4c227e6 | 2019-07-01 11:28:55 -0700 | [diff] [blame] | 1661 | PyConfig_Clear(&config); |
| 1662 | Py_ExitStatusException(status); |
Victor Stinner | 6d1c467 | 2019-05-20 11:02:00 +0200 | [diff] [blame] | 1663 | } |
Victor Stinner | 5eb8b07 | 2019-05-15 02:12:48 +0200 | [diff] [blame] | 1664 | |
| 1665 | wchar_t *argv[] = {L"python3", L"-c", |
Victor Stinner | 9ef5dca | 2019-05-16 17:38:16 +0200 | [diff] [blame] | 1666 | (L"import sys; " |
Victor Stinner | 331a6a5 | 2019-05-27 16:39:22 +0200 | [diff] [blame] | 1667 | L"print(f'Py_RunMain(): sys.argv={sys.argv}')"), |
Victor Stinner | 5eb8b07 | 2019-05-15 02:12:48 +0200 | [diff] [blame] | 1668 | L"arg2"}; |
Miss Islington (bot) | 4c227e6 | 2019-07-01 11:28:55 -0700 | [diff] [blame] | 1669 | config_set_argv(&config, Py_ARRAY_LENGTH(argv), argv); |
| 1670 | config_set_string(&config, &config.program_name, L"./python3"); |
| 1671 | init_from_config_clear(&config); |
Victor Stinner | 6d1c467 | 2019-05-20 11:02:00 +0200 | [diff] [blame] | 1672 | |
Victor Stinner | 331a6a5 | 2019-05-27 16:39:22 +0200 | [diff] [blame] | 1673 | return Py_RunMain(); |
Victor Stinner | 5eb8b07 | 2019-05-15 02:12:48 +0200 | [diff] [blame] | 1674 | } |
| 1675 | |
| 1676 | |
Steve Dower | ea74f0c | 2017-01-01 20:25:03 -0800 | [diff] [blame] | 1677 | /* ********************************************************* |
| 1678 | * List of test cases and the function that implements it. |
Serhiy Storchaka | 13ad3b7 | 2017-09-14 09:38:36 +0300 | [diff] [blame] | 1679 | * |
Steve Dower | ea74f0c | 2017-01-01 20:25:03 -0800 | [diff] [blame] | 1680 | * Names are compared case-sensitively with the first |
| 1681 | * argument. If no match is found, or no first argument was |
| 1682 | * provided, the names of all test cases are printed and |
| 1683 | * the exit code will be -1. |
| 1684 | * |
| 1685 | * The int returned from test functions is used as the exit |
| 1686 | * code, and test_capi treats all non-zero exit codes as a |
Serhiy Storchaka | 13ad3b7 | 2017-09-14 09:38:36 +0300 | [diff] [blame] | 1687 | * failed test. |
Steve Dower | ea74f0c | 2017-01-01 20:25:03 -0800 | [diff] [blame] | 1688 | *********************************************************/ |
| 1689 | struct TestCase |
| 1690 | { |
| 1691 | const char *name; |
| 1692 | int (*func)(void); |
| 1693 | }; |
| 1694 | |
| 1695 | static struct TestCase TestCases[] = { |
Victor Stinner | 5edcf26 | 2019-05-23 00:57:57 +0200 | [diff] [blame] | 1696 | {"test_forced_io_encoding", test_forced_io_encoding}, |
| 1697 | {"test_repeated_init_and_subinterpreters", test_repeated_init_and_subinterpreters}, |
| 1698 | {"test_pre_initialization_api", test_pre_initialization_api}, |
| 1699 | {"test_pre_initialization_sys_options", test_pre_initialization_sys_options}, |
| 1700 | {"test_bpo20891", test_bpo20891}, |
| 1701 | {"test_initialize_twice", test_initialize_twice}, |
| 1702 | {"test_initialize_pymain", test_initialize_pymain}, |
| 1703 | {"test_init_initialize_config", test_init_initialize_config}, |
| 1704 | {"test_preinit_compat_config", test_preinit_compat_config}, |
| 1705 | {"test_init_compat_config", test_init_compat_config}, |
| 1706 | {"test_init_global_config", test_init_global_config}, |
| 1707 | {"test_init_from_config", test_init_from_config}, |
| 1708 | {"test_init_parse_argv", test_init_parse_argv}, |
| 1709 | {"test_init_dont_parse_argv", test_init_dont_parse_argv}, |
Victor Stinner | 20e1e25 | 2019-05-23 04:12:27 +0200 | [diff] [blame] | 1710 | {"test_init_compat_env", test_init_compat_env}, |
| 1711 | {"test_init_python_env", test_init_python_env}, |
Victor Stinner | 5edcf26 | 2019-05-23 00:57:57 +0200 | [diff] [blame] | 1712 | {"test_init_env_dev_mode", test_init_env_dev_mode}, |
| 1713 | {"test_init_env_dev_mode_alloc", test_init_env_dev_mode_alloc}, |
| 1714 | {"test_init_dont_configure_locale", test_init_dont_configure_locale}, |
| 1715 | {"test_init_dev_mode", test_init_dev_mode}, |
| 1716 | {"test_init_isolated_flag", test_init_isolated_flag}, |
| 1717 | {"test_preinit_isolated_config", test_preinit_isolated_config}, |
| 1718 | {"test_init_isolated_config", test_init_isolated_config}, |
| 1719 | {"test_preinit_python_config", test_preinit_python_config}, |
| 1720 | {"test_init_python_config", test_init_python_config}, |
| 1721 | {"test_preinit_isolated1", test_preinit_isolated1}, |
| 1722 | {"test_preinit_isolated2", test_preinit_isolated2}, |
| 1723 | {"test_preinit_parse_argv", test_preinit_parse_argv}, |
| 1724 | {"test_preinit_dont_parse_argv", test_preinit_dont_parse_argv}, |
| 1725 | {"test_init_read_set", test_init_read_set}, |
| 1726 | {"test_init_run_main", test_init_run_main}, |
| 1727 | {"test_init_main", test_init_main}, |
Victor Stinner | af84a88 | 2019-08-23 21:16:51 +0200 | [diff] [blame] | 1728 | {"test_init_sys_add", test_init_sys_add}, |
Victor Stinner | 96c8475 | 2019-09-26 16:17:34 +0200 | [diff] [blame] | 1729 | {"test_init_setpath", test_init_setpath}, |
| 1730 | {"test_init_setpath_config", test_init_setpath_config}, |
| 1731 | {"test_init_setpythonhome", test_init_setpythonhome}, |
Miss Islington (bot) | c9ed9e6 | 2019-09-29 16:58:57 -0700 | [diff] [blame] | 1732 | {"test_init_warnoptions", test_init_warnoptions}, |
Victor Stinner | 5edcf26 | 2019-05-23 00:57:57 +0200 | [diff] [blame] | 1733 | {"test_run_main", test_run_main}, |
Victor Stinner | 96c8475 | 2019-09-26 16:17:34 +0200 | [diff] [blame] | 1734 | |
Steve Dower | b82e17e | 2019-05-23 08:45:22 -0700 | [diff] [blame] | 1735 | {"test_open_code_hook", test_open_code_hook}, |
| 1736 | {"test_audit", test_audit}, |
| 1737 | {"test_audit_subinterpreter", test_audit_subinterpreter}, |
Miss Islington (bot) | 746992c | 2019-07-01 16:22:29 -0700 | [diff] [blame] | 1738 | {"test_audit_run_command", test_audit_run_command}, |
| 1739 | {"test_audit_run_file", test_audit_run_file}, |
| 1740 | {"test_audit_run_interactivehook", test_audit_run_interactivehook}, |
| 1741 | {"test_audit_run_startup", test_audit_run_startup}, |
| 1742 | {"test_audit_run_stdin", test_audit_run_stdin}, |
Victor Stinner | 5edcf26 | 2019-05-23 00:57:57 +0200 | [diff] [blame] | 1743 | {NULL, NULL} |
Steve Dower | ea74f0c | 2017-01-01 20:25:03 -0800 | [diff] [blame] | 1744 | }; |
| 1745 | |
Nick Coghlan | 7d270ee | 2013-10-17 22:35:35 +1000 | [diff] [blame] | 1746 | int main(int argc, char *argv[]) |
| 1747 | { |
Nick Coghlan | 7d270ee | 2013-10-17 22:35:35 +1000 | [diff] [blame] | 1748 | if (argc > 1) { |
Steve Dower | ea74f0c | 2017-01-01 20:25:03 -0800 | [diff] [blame] | 1749 | for (struct TestCase *tc = TestCases; tc && tc->name; tc++) { |
| 1750 | if (strcmp(argv[1], tc->name) == 0) |
| 1751 | return (*tc->func)(); |
| 1752 | } |
Nick Coghlan | 7d270ee | 2013-10-17 22:35:35 +1000 | [diff] [blame] | 1753 | } |
Steve Dower | ea74f0c | 2017-01-01 20:25:03 -0800 | [diff] [blame] | 1754 | |
| 1755 | /* No match found, or no test name provided, so display usage */ |
| 1756 | printf("Python " PY_VERSION " _testembed executable for embedded interpreter tests\n" |
Nick Coghlan | bc77eff | 2018-03-25 20:44:30 +1000 | [diff] [blame] | 1757 | "Normally executed via 'EmbeddingTests' in Lib/test/test_embed.py\n\n" |
Steve Dower | ea74f0c | 2017-01-01 20:25:03 -0800 | [diff] [blame] | 1758 | "Usage: %s TESTNAME\n\nAll available tests:\n", argv[0]); |
| 1759 | for (struct TestCase *tc = TestCases; tc && tc->name; tc++) { |
| 1760 | printf(" %s\n", tc->name); |
| 1761 | } |
| 1762 | |
Nick Coghlan | bc77eff | 2018-03-25 20:44:30 +1000 | [diff] [blame] | 1763 | /* Non-zero exit code will cause test_embed.py tests to fail. |
Steve Dower | ea74f0c | 2017-01-01 20:25:03 -0800 | [diff] [blame] | 1764 | This is intentional. */ |
| 1765 | return -1; |
Antoine Pitrou | 8e60577 | 2011-04-25 21:21:07 +0200 | [diff] [blame] | 1766 | } |