blob: fe076b134f2663600cf0ae5675750d5d50d50899 [file] [log] [blame]
Skip Montanaro4533f602001-08-20 20:28:48 +00001# Very rudimentary test of threading module
2
Tim Peters84d54892005-01-08 06:03:17 +00003import test.test_support
Barry Warsaw04f357c2002-07-23 19:04:11 +00004from test.test_support import verbose
Skip Montanaro4533f602001-08-20 20:28:48 +00005import random
Gregory P. Smith8856dda2008-06-01 23:48:47 +00006import re
Collin Winter50b79ce2007-06-06 00:17:35 +00007import sys
Skip Montanaro4533f602001-08-20 20:28:48 +00008import threading
Tim Peters711906e2005-01-08 07:30:42 +00009import thread
Skip Montanaro4533f602001-08-20 20:28:48 +000010import time
Tim Peters84d54892005-01-08 06:03:17 +000011import unittest
Jeffrey Yasskin3414ea92008-02-23 19:40:54 +000012import weakref
Skip Montanaro4533f602001-08-20 20:28:48 +000013
Antoine Pitrouc747d3a2009-11-09 16:47:50 +000014from test import lock_tests
15
Tim Peters84d54892005-01-08 06:03:17 +000016# A trivial mutable counter.
17class Counter(object):
18 def __init__(self):
19 self.value = 0
20 def inc(self):
21 self.value += 1
22 def dec(self):
23 self.value -= 1
24 def get(self):
25 return self.value
Skip Montanaro4533f602001-08-20 20:28:48 +000026
27class TestThread(threading.Thread):
Tim Peters84d54892005-01-08 06:03:17 +000028 def __init__(self, name, testcase, sema, mutex, nrunning):
29 threading.Thread.__init__(self, name=name)
30 self.testcase = testcase
31 self.sema = sema
32 self.mutex = mutex
33 self.nrunning = nrunning
34
Skip Montanaro4533f602001-08-20 20:28:48 +000035 def run(self):
Jeffrey Yasskin510eab52008-03-21 18:48:04 +000036 delay = random.random() / 10000.0
Skip Montanaro4533f602001-08-20 20:28:48 +000037 if verbose:
Jeffrey Yasskin510eab52008-03-21 18:48:04 +000038 print 'task %s will run for %.1f usec' % (
Benjamin Petersoncbae8692008-08-18 17:45:09 +000039 self.name, delay * 1e6)
Tim Peters84d54892005-01-08 06:03:17 +000040
Jeffrey Yasskin510eab52008-03-21 18:48:04 +000041 with self.sema:
42 with self.mutex:
43 self.nrunning.inc()
44 if verbose:
45 print self.nrunning.get(), 'tasks are running'
46 self.testcase.assert_(self.nrunning.get() <= 3)
Tim Peters84d54892005-01-08 06:03:17 +000047
Jeffrey Yasskin510eab52008-03-21 18:48:04 +000048 time.sleep(delay)
49 if verbose:
Benjamin Petersoncbae8692008-08-18 17:45:09 +000050 print 'task', self.name, 'done'
Tim Peters84d54892005-01-08 06:03:17 +000051
Jeffrey Yasskin510eab52008-03-21 18:48:04 +000052 with self.mutex:
53 self.nrunning.dec()
54 self.testcase.assert_(self.nrunning.get() >= 0)
55 if verbose:
56 print '%s is finished. %d tasks are running' % (
Benjamin Petersoncbae8692008-08-18 17:45:09 +000057 self.name, self.nrunning.get())
Skip Montanaro4533f602001-08-20 20:28:48 +000058
Tim Peters84d54892005-01-08 06:03:17 +000059class ThreadTests(unittest.TestCase):
Skip Montanaro4533f602001-08-20 20:28:48 +000060
Tim Peters84d54892005-01-08 06:03:17 +000061 # Create a bunch of threads, let each do some work, wait until all are
62 # done.
63 def test_various_ops(self):
64 # This takes about n/3 seconds to run (about n/3 clumps of tasks,
65 # times about 1 second per clump).
66 NUMTASKS = 10
67
68 # no more than 3 of the 10 can run at once
69 sema = threading.BoundedSemaphore(value=3)
70 mutex = threading.RLock()
71 numrunning = Counter()
72
73 threads = []
74
75 for i in range(NUMTASKS):
76 t = TestThread("<thread %d>"%i, self, sema, mutex, numrunning)
77 threads.append(t)
Benjamin Petersond8a89722008-08-18 16:40:03 +000078 self.failUnlessEqual(t.ident, None)
Gregory P. Smith8856dda2008-06-01 23:48:47 +000079 self.assert_(re.match('<TestThread\(.*, initial\)>', repr(t)))
Tim Peters84d54892005-01-08 06:03:17 +000080 t.start()
81
82 if verbose:
83 print 'waiting for all tasks to complete'
84 for t in threads:
Tim Peters711906e2005-01-08 07:30:42 +000085 t.join(NUMTASKS)
Benjamin Peterson0fbcf692008-06-11 17:27:50 +000086 self.assert_(not t.is_alive())
Benjamin Petersond8a89722008-08-18 16:40:03 +000087 self.failIfEqual(t.ident, 0)
Benjamin Peterson61611f82009-03-31 21:40:18 +000088 self.assertFalse(t.ident is None)
Gregory P. Smith8856dda2008-06-01 23:48:47 +000089 self.assert_(re.match('<TestThread\(.*, \w+ -?\d+\)>', repr(t)))
Tim Peters84d54892005-01-08 06:03:17 +000090 if verbose:
91 print 'all tasks done'
92 self.assertEqual(numrunning.get(), 0)
93
Benjamin Peterson61611f82009-03-31 21:40:18 +000094 def test_ident_of_no_threading_threads(self):
95 # The ident still must work for the main thread and dummy threads.
96 self.assertFalse(threading.currentThread().ident is None)
97 def f():
98 ident.append(threading.currentThread().ident)
99 done.set()
100 done = threading.Event()
101 ident = []
102 thread.start_new_thread(f, ())
103 done.wait()
104 self.assertFalse(ident[0] is None)
Antoine Pitroue3199832009-11-08 00:36:33 +0000105 # Kill the "immortal" _DummyThread
106 del threading._active[ident[0]]
Benjamin Peterson61611f82009-03-31 21:40:18 +0000107
Andrew MacIntyre93e3ecb2006-06-13 19:02:35 +0000108 # run with a small(ish) thread stack size (256kB)
Andrew MacIntyre92913322006-06-13 15:04:24 +0000109 def test_various_ops_small_stack(self):
110 if verbose:
Andrew MacIntyre93e3ecb2006-06-13 19:02:35 +0000111 print 'with 256kB thread stack size...'
Andrew MacIntyre16ee33a2006-08-06 12:37:03 +0000112 try:
113 threading.stack_size(262144)
114 except thread.error:
115 if verbose:
116 print 'platform does not support changing thread stack size'
117 return
Andrew MacIntyre92913322006-06-13 15:04:24 +0000118 self.test_various_ops()
119 threading.stack_size(0)
120
121 # run with a large thread stack size (1MB)
122 def test_various_ops_large_stack(self):
123 if verbose:
124 print 'with 1MB thread stack size...'
Andrew MacIntyre16ee33a2006-08-06 12:37:03 +0000125 try:
126 threading.stack_size(0x100000)
127 except thread.error:
128 if verbose:
129 print 'platform does not support changing thread stack size'
130 return
Andrew MacIntyre92913322006-06-13 15:04:24 +0000131 self.test_various_ops()
132 threading.stack_size(0)
133
Tim Peters711906e2005-01-08 07:30:42 +0000134 def test_foreign_thread(self):
135 # Check that a "foreign" thread can use the threading module.
136 def f(mutex):
Antoine Pitrouc747d3a2009-11-09 16:47:50 +0000137 # Calling current_thread() forces an entry for the foreign
Tim Peters711906e2005-01-08 07:30:42 +0000138 # thread to get made in the threading._active map.
Antoine Pitrouc747d3a2009-11-09 16:47:50 +0000139 threading.current_thread()
Tim Peters711906e2005-01-08 07:30:42 +0000140 mutex.release()
141
142 mutex = threading.Lock()
143 mutex.acquire()
144 tid = thread.start_new_thread(f, (mutex,))
145 # Wait for the thread to finish.
146 mutex.acquire()
147 self.assert_(tid in threading._active)
148 self.assert_(isinstance(threading._active[tid],
149 threading._DummyThread))
150 del threading._active[tid]
Tim Peters84d54892005-01-08 06:03:17 +0000151
Tim Peters4643c2f2006-08-10 22:45:34 +0000152 # PyThreadState_SetAsyncExc() is a CPython-only gimmick, not (currently)
153 # exposed at the Python level. This test relies on ctypes to get at it.
154 def test_PyThreadState_SetAsyncExc(self):
155 try:
156 import ctypes
157 except ImportError:
158 if verbose:
159 print "test_PyThreadState_SetAsyncExc can't import ctypes"
160 return # can't do anything
161
162 set_async_exc = ctypes.pythonapi.PyThreadState_SetAsyncExc
163
164 class AsyncExc(Exception):
165 pass
166
167 exception = ctypes.py_object(AsyncExc)
168
169 # `worker_started` is set by the thread when it's inside a try/except
170 # block waiting to catch the asynchronously set AsyncExc exception.
171 # `worker_saw_exception` is set by the thread upon catching that
172 # exception.
173 worker_started = threading.Event()
174 worker_saw_exception = threading.Event()
175
176 class Worker(threading.Thread):
177 def run(self):
178 self.id = thread.get_ident()
179 self.finished = False
180
181 try:
182 while True:
183 worker_started.set()
184 time.sleep(0.1)
185 except AsyncExc:
186 self.finished = True
187 worker_saw_exception.set()
188
189 t = Worker()
Benjamin Petersoncbae8692008-08-18 17:45:09 +0000190 t.daemon = True # so if this fails, we don't hang Python at shutdown
Tim Peters08574772006-08-11 00:49:01 +0000191 t.start()
Tim Peters4643c2f2006-08-10 22:45:34 +0000192 if verbose:
193 print " started worker thread"
Tim Peters4643c2f2006-08-10 22:45:34 +0000194
195 # Try a thread id that doesn't make sense.
196 if verbose:
197 print " trying nonsensical thread id"
Tim Peters08574772006-08-11 00:49:01 +0000198 result = set_async_exc(ctypes.c_long(-1), exception)
Tim Peters4643c2f2006-08-10 22:45:34 +0000199 self.assertEqual(result, 0) # no thread states modified
200
201 # Now raise an exception in the worker thread.
202 if verbose:
203 print " waiting for worker thread to get started"
204 worker_started.wait()
205 if verbose:
206 print " verifying worker hasn't exited"
207 self.assert_(not t.finished)
208 if verbose:
209 print " attempting to raise asynch exception in worker"
Tim Peters08574772006-08-11 00:49:01 +0000210 result = set_async_exc(ctypes.c_long(t.id), exception)
Tim Peters4643c2f2006-08-10 22:45:34 +0000211 self.assertEqual(result, 1) # one thread state modified
212 if verbose:
213 print " waiting for worker to say it caught the exception"
214 worker_saw_exception.wait(timeout=10)
215 self.assert_(t.finished)
216 if verbose:
217 print " all OK -- joining worker"
218 if t.finished:
219 t.join()
220 # else the thread is still running, and we have no way to kill it
221
Gregory P. Smith9922a9a2010-02-28 18:40:12 +0000222 def test_limbo_cleanup(self):
223 # Issue 7481: Failure to start thread should cleanup the limbo map.
224 def fail_new_thread(*args):
225 raise thread.error()
226 _start_new_thread = threading._start_new_thread
227 threading._start_new_thread = fail_new_thread
228 try:
229 t = threading.Thread(target=lambda: None)
230 try:
231 t.start()
232 assert False
233 except thread.error:
234 self.assertFalse(
235 t in threading._limbo,
236 "Failed to cleanup _limbo map on failure of Thread.start()."
237 )
238 finally:
239 threading._start_new_thread = _start_new_thread
240
Amaury Forgeot d'Arc025c3472007-11-29 23:35:25 +0000241 def test_finalize_runnning_thread(self):
242 # Issue 1402: the PyGILState_Ensure / _Release functions may be called
243 # very late on python exit: on deallocation of a running thread for
244 # example.
245 try:
246 import ctypes
247 except ImportError:
248 if verbose:
249 print("test_finalize_with_runnning_thread can't import ctypes")
250 return # can't do anything
251
252 import subprocess
253 rc = subprocess.call([sys.executable, "-c", """if 1:
254 import ctypes, sys, time, thread
255
Jeffrey Yasskin510eab52008-03-21 18:48:04 +0000256 # This lock is used as a simple event variable.
257 ready = thread.allocate_lock()
258 ready.acquire()
259
Amaury Forgeot d'Arc025c3472007-11-29 23:35:25 +0000260 # Module globals are cleared before __del__ is run
261 # So we save the functions in class dict
262 class C:
263 ensure = ctypes.pythonapi.PyGILState_Ensure
264 release = ctypes.pythonapi.PyGILState_Release
265 def __del__(self):
266 state = self.ensure()
267 self.release(state)
268
269 def waitingThread():
270 x = C()
Jeffrey Yasskin510eab52008-03-21 18:48:04 +0000271 ready.release()
Amaury Forgeot d'Arc025c3472007-11-29 23:35:25 +0000272 time.sleep(100)
273
274 thread.start_new_thread(waitingThread, ())
Jeffrey Yasskin510eab52008-03-21 18:48:04 +0000275 ready.acquire() # Be sure the other thread is waiting.
Amaury Forgeot d'Arc025c3472007-11-29 23:35:25 +0000276 sys.exit(42)
277 """])
278 self.assertEqual(rc, 42)
279
Amaury Forgeot d'Arcd7a26512008-04-03 23:07:55 +0000280 def test_finalize_with_trace(self):
281 # Issue1733757
282 # Avoid a deadlock when sys.settrace steps into threading._shutdown
283 import subprocess
284 rc = subprocess.call([sys.executable, "-c", """if 1:
285 import sys, threading
286
287 # A deadlock-killer, to prevent the
288 # testsuite to hang forever
289 def killer():
290 import os, time
291 time.sleep(2)
292 print 'program blocked; aborting'
293 os._exit(2)
294 t = threading.Thread(target=killer)
Benjamin Petersoncbae8692008-08-18 17:45:09 +0000295 t.daemon = True
Amaury Forgeot d'Arcd7a26512008-04-03 23:07:55 +0000296 t.start()
297
298 # This is the trace function
299 def func(frame, event, arg):
Benjamin Peterson0fbcf692008-06-11 17:27:50 +0000300 threading.current_thread()
Amaury Forgeot d'Arcd7a26512008-04-03 23:07:55 +0000301 return func
302
303 sys.settrace(func)
304 """])
305 self.failIf(rc == 2, "interpreted was blocked")
306 self.failUnless(rc == 0, "Unexpected error")
307
Antoine Pitrou9aece752009-10-27 12:48:52 +0000308 def test_join_nondaemon_on_shutdown(self):
309 # Issue 1722344
310 # Raising SystemExit skipped threading._shutdown
311 import subprocess
312 p = subprocess.Popen([sys.executable, "-c", """if 1:
313 import threading
314 from time import sleep
315
316 def child():
317 sleep(1)
318 # As a non-daemon thread we SHOULD wake up and nothing
319 # should be torn down yet
320 print "Woke up, sleep function is:", sleep
321
322 threading.Thread(target=child).start()
323 raise SystemExit
324 """],
325 stdout=subprocess.PIPE,
326 stderr=subprocess.PIPE)
327 stdout, stderr = p.communicate()
328 self.assertEqual(stdout.strip(),
329 "Woke up, sleep function is: <built-in function sleep>")
330 stderr = re.sub(r"^\[\d+ refs\]", "", stderr, re.MULTILINE).strip()
331 self.assertEqual(stderr, "")
Amaury Forgeot d'Arcd7a26512008-04-03 23:07:55 +0000332
Gregory P. Smith95cd5c02008-01-22 01:20:42 +0000333 def test_enumerate_after_join(self):
334 # Try hard to trigger #1703448: a thread is still returned in
335 # threading.enumerate() after it has been join()ed.
336 enum = threading.enumerate
337 old_interval = sys.getcheckinterval()
Gregory P. Smith95cd5c02008-01-22 01:20:42 +0000338 try:
Jeffrey Yasskin510eab52008-03-21 18:48:04 +0000339 for i in xrange(1, 100):
340 # Try a couple times at each thread-switching interval
341 # to get more interleavings.
342 sys.setcheckinterval(i // 5)
Gregory P. Smith95cd5c02008-01-22 01:20:42 +0000343 t = threading.Thread(target=lambda: None)
344 t.start()
345 t.join()
346 l = enum()
347 self.assertFalse(t in l,
348 "#1703448 triggered after %d trials: %s" % (i, l))
349 finally:
350 sys.setcheckinterval(old_interval)
351
Jeffrey Yasskin3414ea92008-02-23 19:40:54 +0000352 def test_no_refcycle_through_target(self):
353 class RunSelfFunction(object):
Jeffrey Yasskina885c152008-02-23 20:40:35 +0000354 def __init__(self, should_raise):
Jeffrey Yasskin3414ea92008-02-23 19:40:54 +0000355 # The links in this refcycle from Thread back to self
356 # should be cleaned up when the thread completes.
Jeffrey Yasskina885c152008-02-23 20:40:35 +0000357 self.should_raise = should_raise
Jeffrey Yasskin3414ea92008-02-23 19:40:54 +0000358 self.thread = threading.Thread(target=self._run,
359 args=(self,),
360 kwargs={'yet_another':self})
361 self.thread.start()
362
363 def _run(self, other_ref, yet_another):
Jeffrey Yasskina885c152008-02-23 20:40:35 +0000364 if self.should_raise:
365 raise SystemExit
Jeffrey Yasskin3414ea92008-02-23 19:40:54 +0000366
Jeffrey Yasskina885c152008-02-23 20:40:35 +0000367 cyclic_object = RunSelfFunction(should_raise=False)
Jeffrey Yasskin3414ea92008-02-23 19:40:54 +0000368 weak_cyclic_object = weakref.ref(cyclic_object)
369 cyclic_object.thread.join()
370 del cyclic_object
Jeffrey Yasskin8b9091f2008-03-28 04:11:18 +0000371 self.assertEquals(None, weak_cyclic_object(),
372 msg=('%d references still around' %
373 sys.getrefcount(weak_cyclic_object())))
Jeffrey Yasskin3414ea92008-02-23 19:40:54 +0000374
Jeffrey Yasskina885c152008-02-23 20:40:35 +0000375 raising_cyclic_object = RunSelfFunction(should_raise=True)
376 weak_raising_cyclic_object = weakref.ref(raising_cyclic_object)
377 raising_cyclic_object.thread.join()
378 del raising_cyclic_object
Jeffrey Yasskin8b9091f2008-03-28 04:11:18 +0000379 self.assertEquals(None, weak_raising_cyclic_object(),
380 msg=('%d references still around' %
381 sys.getrefcount(weak_raising_cyclic_object())))
Jeffrey Yasskina885c152008-02-23 20:40:35 +0000382
Gregory P. Smith95cd5c02008-01-22 01:20:42 +0000383
Jesse Noller5e62ca42008-07-16 20:03:47 +0000384class ThreadJoinOnShutdown(unittest.TestCase):
385
386 def _run_and_join(self, script):
387 script = """if 1:
388 import sys, os, time, threading
389
390 # a thread, which waits for the main program to terminate
391 def joiningfunc(mainthread):
392 mainthread.join()
393 print 'end of thread'
394 \n""" + script
395
396 import subprocess
397 p = subprocess.Popen([sys.executable, "-c", script], stdout=subprocess.PIPE)
398 rc = p.wait()
Benjamin Petersonf5668f12008-07-17 12:57:22 +0000399 data = p.stdout.read().replace('\r', '')
400 self.assertEqual(data, "end of main\nend of thread\n")
Jesse Noller5e62ca42008-07-16 20:03:47 +0000401 self.failIf(rc == 2, "interpreter was blocked")
402 self.failUnless(rc == 0, "Unexpected error")
403
404 def test_1_join_on_shutdown(self):
405 # The usual case: on exit, wait for a non-daemon thread
406 script = """if 1:
407 import os
408 t = threading.Thread(target=joiningfunc,
409 args=(threading.current_thread(),))
410 t.start()
411 time.sleep(0.1)
412 print 'end of main'
413 """
414 self._run_and_join(script)
415
416
417 def test_2_join_in_forked_process(self):
418 # Like the test above, but from a forked interpreter
419 import os
420 if not hasattr(os, 'fork'):
421 return
422 script = """if 1:
423 childpid = os.fork()
424 if childpid != 0:
425 os.waitpid(childpid, 0)
426 sys.exit(0)
427
428 t = threading.Thread(target=joiningfunc,
429 args=(threading.current_thread(),))
430 t.start()
431 print 'end of main'
432 """
433 self._run_and_join(script)
434
435 def test_3_join_in_forked_from_thread(self):
436 # Like the test above, but fork() was called from a worker thread
437 # In the forked process, the main Thread object must be marked as stopped.
438 import os
439 if not hasattr(os, 'fork'):
440 return
Gregory P. Smith08067492008-09-30 20:41:13 +0000441 # Skip platforms with known problems forking from a worker thread.
442 # See http://bugs.python.org/issue3863.
443 if sys.platform in ('freebsd4', 'freebsd5', 'freebsd6', 'os2emx'):
444 print >>sys.stderr, ('Skipping test_3_join_in_forked_from_thread'
445 ' due to known OS bugs on'), sys.platform
446 return
Jesse Noller5e62ca42008-07-16 20:03:47 +0000447 script = """if 1:
448 main_thread = threading.current_thread()
449 def worker():
450 childpid = os.fork()
451 if childpid != 0:
452 os.waitpid(childpid, 0)
453 sys.exit(0)
454
455 t = threading.Thread(target=joiningfunc,
456 args=(main_thread,))
457 print 'end of main'
458 t.start()
459 t.join() # Should not block: main_thread is already stopped
460
461 w = threading.Thread(target=worker)
462 w.start()
463 """
464 self._run_and_join(script)
465
466
Collin Winter50b79ce2007-06-06 00:17:35 +0000467class ThreadingExceptionTests(unittest.TestCase):
468 # A RuntimeError should be raised if Thread.start() is called
469 # multiple times.
470 def test_start_thread_again(self):
471 thread = threading.Thread()
472 thread.start()
473 self.assertRaises(RuntimeError, thread.start)
474
Collin Winter50b79ce2007-06-06 00:17:35 +0000475 def test_joining_current_thread(self):
Benjamin Peterson0fbcf692008-06-11 17:27:50 +0000476 current_thread = threading.current_thread()
477 self.assertRaises(RuntimeError, current_thread.join);
Collin Winter50b79ce2007-06-06 00:17:35 +0000478
479 def test_joining_inactive_thread(self):
480 thread = threading.Thread()
481 self.assertRaises(RuntimeError, thread.join)
482
483 def test_daemonize_active_thread(self):
484 thread = threading.Thread()
485 thread.start()
Benjamin Petersoncbae8692008-08-18 17:45:09 +0000486 self.assertRaises(RuntimeError, setattr, thread, "daemon", True)
Collin Winter50b79ce2007-06-06 00:17:35 +0000487
488
Antoine Pitrouc747d3a2009-11-09 16:47:50 +0000489class LockTests(lock_tests.LockTests):
490 locktype = staticmethod(threading.Lock)
491
492class RLockTests(lock_tests.RLockTests):
493 locktype = staticmethod(threading.RLock)
494
495class EventTests(lock_tests.EventTests):
496 eventtype = staticmethod(threading.Event)
497
498class ConditionAsRLockTests(lock_tests.RLockTests):
499 # An Condition uses an RLock by default and exports its API.
500 locktype = staticmethod(threading.Condition)
501
502class ConditionTests(lock_tests.ConditionTests):
503 condtype = staticmethod(threading.Condition)
504
505class SemaphoreTests(lock_tests.SemaphoreTests):
506 semtype = staticmethod(threading.Semaphore)
507
508class BoundedSemaphoreTests(lock_tests.BoundedSemaphoreTests):
509 semtype = staticmethod(threading.BoundedSemaphore)
510
511
Tim Peters84d54892005-01-08 06:03:17 +0000512def test_main():
Antoine Pitrouc747d3a2009-11-09 16:47:50 +0000513 test.test_support.run_unittest(LockTests, RLockTests, EventTests,
514 ConditionAsRLockTests, ConditionTests,
515 SemaphoreTests, BoundedSemaphoreTests,
516 ThreadTests,
Jesse Noller5e62ca42008-07-16 20:03:47 +0000517 ThreadJoinOnShutdown,
518 ThreadingExceptionTests,
519 )
Tim Peters84d54892005-01-08 06:03:17 +0000520
521if __name__ == "__main__":
522 test_main()