ó
ŠwÛjc           @   sÉ   d  Z  d d l a d d l Z d d l Z d d l Z d d l Z d d l m Z d a	 d e j
 f d „  ƒ  YZ d e j
 f d „  ƒ  YZ d	 e j
 f d
 „  ƒ  YZ d d „ Z e d k rÅ e ƒ  n  d S(   sÕ   Generic thread tests.

Meant to be used by dummy_thread and thread.  To allow for different modules
to be used, test_main() can be called with the module to use as the thread
implementation as its sole argument.

iÿÿÿÿN(   t   test_supporti    t	   LockTestsc           B   s_   e  Z d  Z d „  Z d „  Z d „  Z d „  Z d „  Z d „  Z d „  Z	 d „  Z
 d	 „  Z RS(
   s   Test lock objects.c         C   s   t  j ƒ  |  _ d  S(   N(   t   _threadt   allocate_lockt   lock(   t   self(    (    sŒ   /home/sim/yocto/scarthgap/build/tmp/work/x86_64-linux/python-native/2.7.18/recipe-sysroot-native/usr/lib/python2.7/test/test_dummy_thread.pyt   setUp   s    c         C   s   |  j  |  j j ƒ  d ƒ d  S(   Ns(   Lock object is not initialized unlocked.(   t   assertFalseR   t   locked(   R   (    (    sŒ   /home/sim/yocto/scarthgap/build/tmp/work/x86_64-linux/python-native/2.7.18/recipe-sysroot-native/usr/lib/python2.7/test/test_dummy_thread.pyt   test_initlock   s    c         C   s7   |  j  j ƒ  |  j  j ƒ  |  j |  j  j ƒ  d ƒ d  S(   Ns%   Lock object did not release properly.(   R   t   acquiret   releaseR   R   (   R   (    (    sŒ   /home/sim/yocto/scarthgap/build/tmp/work/x86_64-linux/python-native/2.7.18/recipe-sysroot-native/usr/lib/python2.7/test/test_dummy_thread.pyt   test_release   s    c         C   s   |  j  t j |  j j ƒ d  S(   N(   t   assertRaisesR   t   errorR   R   (   R   (    (    sŒ   /home/sim/yocto/scarthgap/build/tmp/work/x86_64-linux/python-native/2.7.18/recipe-sysroot-native/usr/lib/python2.7/test/test_dummy_thread.pyt   test_improper_release%   s    c         C   s    |  j  |  j j d ƒ d ƒ d  S(   Ni    s)   Conditional acquiring of the lock failed.(   t
   assertTrueR   R
   (   R   (    (    sŒ   /home/sim/yocto/scarthgap/build/tmp/work/x86_64-linux/python-native/2.7.18/recipe-sysroot-native/usr/lib/python2.7/test/test_dummy_thread.pyt   test_cond_acquire_success)   s    c         C   s0   |  j  j d ƒ |  j |  j  j d ƒ d ƒ d  S(   Ni    s=   Conditional acquiring of a locked lock incorrectly succeeded.(   R   R
   R   (   R   (    (    sŒ   /home/sim/yocto/scarthgap/build/tmp/work/x86_64-linux/python-native/2.7.18/recipe-sysroot-native/usr/lib/python2.7/test/test_dummy_thread.pyt   test_cond_acquire_fail.   s    c         C   s*   |  j  j ƒ  |  j |  j  j ƒ  d ƒ d  S(   Ns   Uncondional locking failed.(   R   R
   R   R   (   R   (    (    sŒ   /home/sim/yocto/scarthgap/build/tmp/work/x86_64-linux/python-native/2.7.18/recipe-sysroot-native/usr/lib/python2.7/test/test_dummy_thread.pyt   test_uncond_acquire_success5   s    c         C   s<   |  j  |  j j d ƒ t d ƒ |  j  |  j j ƒ  t ƒ d  S(   Ni   s*   Unconditional locking did not return True.(   t   assertIsR   R
   t   True(   R   (    (    sŒ   /home/sim/yocto/scarthgap/build/tmp/work/x86_64-linux/python-native/2.7.18/recipe-sysroot-native/usr/lib/python2.7/test/test_dummy_thread.pyt   test_uncond_acquire_return_val;   s    c         C   s¢   d „  } |  j  j ƒ  t t j ƒ  ƒ } t j | |  j  t f ƒ t j rW Hd t GHn  |  j  j ƒ  t t j ƒ  ƒ } t j r‡ d GHn  |  j	 | | t d ƒ d  S(   Nc         S   s   t  j | ƒ |  j ƒ  d S(   s:   Hold on to lock for a set amount of time before unlocking.N(   t   timet   sleepR   (   t	   to_unlockt   delay(    (    sŒ   /home/sim/yocto/scarthgap/build/tmp/work/x86_64-linux/python-native/2.7.18/recipe-sysroot-native/usr/lib/python2.7/test/test_dummy_thread.pyt   delay_unlockC   s    s@   *** Waiting for thread to release the lock (approx. %s sec.) ***t   dones+   Blocking by unconditional acquiring failed.(
   R   R
   t   intR   R   t   start_new_threadt   DELAYR    t   verboset   assertGreaterEqual(   R   R   t
   start_timet   end_time(    (    sŒ   /home/sim/yocto/scarthgap/build/tmp/work/x86_64-linux/python-native/2.7.18/recipe-sysroot-native/usr/lib/python2.7/test/test_dummy_thread.pyt   test_uncond_acquire_blockingA   s    				(   t   __name__t
   __module__t   __doc__R   R	   R   R   R   R   R   R   R$   (    (    (    sŒ   /home/sim/yocto/scarthgap/build/tmp/work/x86_64-linux/python-native/2.7.18/recipe-sysroot-native/usr/lib/python2.7/test/test_dummy_thread.pyR      s   								t	   MiscTestsc           B   s;   e  Z d  Z d „  Z d „  Z d „  Z d „  Z d „  Z RS(   s   Miscellaneous tests.c         C   s   |  j  t t j ƒ d  S(   N(   R   t
   SystemExitR   t   exit(   R   (    (    sŒ   /home/sim/yocto/scarthgap/build/tmp/work/x86_64-linux/python-native/2.7.18/recipe-sysroot-native/usr/lib/python2.7/test/test_dummy_thread.pyt	   test_exitY   s    c         C   s6   |  j  t j ƒ  t d ƒ |  j t j ƒ  d d ƒ d  S(   Ns*   _thread.get_ident() returned a non-integeri    s   _thread.get_ident() returned 0(   t   assertIsInstanceR   t	   get_identR   t   assertNotEqual(   R   (    (    sŒ   /home/sim/yocto/scarthgap/build/tmp/work/x86_64-linux/python-native/2.7.18/recipe-sysroot-native/usr/lib/python2.7/test/test_dummy_thread.pyt
   test_ident]   s    c         C   s    |  j  t j ƒ  t j d ƒ d  S(   NsR   _thread.LockType is not an instance of what is returned by _thread.allocate_lock()(   R,   R   R   t   LockType(   R   (    (    sŒ   /home/sim/yocto/scarthgap/build/tmp/work/x86_64-linux/python-native/2.7.18/recipe-sysroot-native/usr/lib/python2.7/test/test_dummy_thread.pyt   test_LockTyped   s    c         C   s)   d „  } |  j  t t j | t ƒ  ƒ d  S(   Nc           S   s   t  j ƒ  d  S(   N(   R   t   interrupt_main(    (    (    sŒ   /home/sim/yocto/scarthgap/build/tmp/work/x86_64-linux/python-native/2.7.18/recipe-sysroot-native/usr/lib/python2.7/test/test_dummy_thread.pyt   call_interruptm   s    (   R   t   KeyboardInterruptR   R   t   tuple(   R   R3   (    (    sŒ   /home/sim/yocto/scarthgap/build/tmp/work/x86_64-linux/python-native/2.7.18/recipe-sysroot-native/usr/lib/python2.7/test/test_dummy_thread.pyt   test_interrupt_mainj   s    	c         C   s   |  j  t t j ƒ d  S(   N(   R   R4   R   R2   (   R   (    (    sŒ   /home/sim/yocto/scarthgap/build/tmp/work/x86_64-linux/python-native/2.7.18/recipe-sysroot-native/usr/lib/python2.7/test/test_dummy_thread.pyt   test_interrupt_in_mainr   s    (   R%   R&   R'   R+   R/   R1   R6   R7   (    (    (    sŒ   /home/sim/yocto/scarthgap/build/tmp/work/x86_64-linux/python-native/2.7.18/recipe-sysroot-native/usr/lib/python2.7/test/test_dummy_thread.pyR(   V   s   				t   ThreadTestsc           B   s    e  Z d  Z d „  Z d „  Z RS(   s   Test thread creation.c         C   s  t  t  d „ } t j d ƒ } t j | | t t f ƒ | j ƒ  } |  j | d oZ | d d ƒ t j | t ƒ  i | d 6t d 6t d 6ƒ | j ƒ  } |  j | d o¯ | d d ƒ t j | | t f i t d 6ƒ | j ƒ  } |  j | d où | d d	 ƒ d  S(
   Nc         S   s   |  j  | | f ƒ d S(   s<   Use to test _thread.start_new_thread() passes args properly.N(   t   put(   t   queuet   arg1t   arg2(    (    sŒ   /home/sim/yocto/scarthgap/build/tmp/work/x86_64-linux/python-native/2.7.18/recipe-sysroot-native/usr/lib/python2.7/test/test_dummy_thread.pyt
   arg_tester|   s    i   i    s7   Argument passing for thread creation using tuple failedR:   R;   R<   s8   Argument passing for thread creation using kwargs failedsG   Argument passing for thread creation using both tuple and kwargs failed(   t   Falset   QueueR   R   R   t   getR   R5   (   R   R=   t   testing_queuet   result(    (    sŒ   /home/sim/yocto/scarthgap/build/tmp/work/x86_64-linux/python-native/2.7.18/recipe-sysroot-native/usr/lib/python2.7/test/test_dummy_thread.pyt   test_arg_passingz   s     c         C   sÐ   d „  } d } t  j  | ƒ } t j r: Hd t | f GHn  xN t | ƒ D]@ } t rk t t j ƒ  d ƒ } n d } t j | | | f ƒ qG Wt	 j
 t ƒ t j r© d GHn  |  j | j ƒ  | d | t f ƒ d  S(   Nc         S   s$   t  j | ƒ |  j t j ƒ  ƒ d S(   s@   Wait for ``delay`` seconds and then put something into ``queue``N(   R   R   R9   R   R-   (   R:   R   (    (    sŒ   /home/sim/yocto/scarthgap/build/tmp/work/x86_64-linux/python-native/2.7.18/recipe-sysroot-native/usr/lib/python2.7/test/test_dummy_thread.pyt
   queue_mark’   s    i   sJ   *** Testing multiple thread creation (will take approx. %s to %s sec.) ***i   i    R   s2   Not all %s threads executed properly after %s sec.(   R?   R    R    R   t   xranget   roundt   randomR   R   R   R   t   assertEqualt   qsize(   R   RD   t   thread_countRA   t   countt   local_delay(    (    sŒ   /home/sim/yocto/scarthgap/build/tmp/work/x86_64-linux/python-native/2.7.18/recipe-sysroot-native/usr/lib/python2.7/test/test_dummy_thread.pyt   test_multi_creation�   s&    				(   R%   R&   R'   RC   RM   (    (    (    sŒ   /home/sim/yocto/scarthgap/build/tmp/work/x86_64-linux/python-native/2.7.18/recipe-sysroot-native/usr/lib/python2.7/test/test_dummy_thread.pyR8   w   s   	c         C   sB   |  r |  a  d a n  t j r+ Hd t  GHn  t j t t t ƒ d  S(   Ni   s"   *** Using %s as _thread module ***(   R   R   R    R    t   run_unittestR   R(   R8   (   t   imported_module(    (    sŒ   /home/sim/yocto/scarthgap/build/tmp/work/x86_64-linux/python-native/2.7.18/recipe-sysroot-native/usr/lib/python2.7/test/test_dummy_thread.pyt	   test_main«   s    		t   __main__(   R'   t   dummy_threadR   R   R?   RG   t   unittestt   testR    R   t   TestCaseR   R(   R8   t   NoneRP   R%   (    (    (    sŒ   /home/sim/yocto/scarthgap/build/tmp/work/x86_64-linux/python-native/2.7.18/recipe-sysroot-native/usr/lib/python2.7/test/test_dummy_thread.pyt   <module>   s   D!4
