
    b                     \    d Z ddlZddlmZ  G d d          ZddZ G d	 d
e          ZdS )z7
Blackbox tests for blackboxtest check output methods.
    N)BlackboxTestCasec                   F    e Zd ZdZ G d de          Zd Zd Zd Zd Z	dS )	TimeoutHelperz
    Timeout class using alarm signal.

    Raise a Timeout exception if a function timeout.
    Usage:

        try:
            with Timeout(3):
                foobar("Request 1")
        except TimeoutHelper.Timeout:
            print("Timeout")
    c                       e Zd ZdS )TimeoutHelper.TimeoutN)__name__
__module____qualname__     C/usr/lib/python3/dist-packages/samba/tests/blackbox/check_output.pyTimeoutr   &   s        r   r   c                     || _         d S N)sec)selfr   s     r   __init__zTimeoutHelper.__init__)   s    r   c                     t          j         t           j        | j                   t          j        | j                   d S r   )signalSIGALRMraise_timeoutalarmr   r   s    r   	__enter__zTimeoutHelper.__enter__,   s1    fnd&8999TXr   c                 .    t          j        d           d S )Nr   )r   r   r   argss     r   __exit__zTimeoutHelper.__exit__0   s    Qr   c                 4    t                                           r   )r   r   r   s     r   r   zTimeoutHelper.raise_timeout3   s    ##%%%r   N)
r   r	   r
   __doc__	Exceptionr   r   r   r   r   r   r   r   r   r      s             )         & & & & &r   r   $  P c                 0    d                     | ||          S )z>Build a command to call gen_output.py to generate large outputz3gen_output.py --data {0} --repeat {1} --retcode {2})format)datarepeatretcodes      r   _make_cmdliner)   7   s%    @GGHNHOQ Q Qr   c                   *    e Zd ZdZd Zd Zd Zd ZdS )CheckOutputTestsa   
    Blackbox tests for check_xxx methods.

    The check_xxx methods in BlackboxTestCase will deadlock
    on large output from command which caused by Popen.wait().

    This is a test case to show the deadlock issue,
    will fix in another commit.
    c                     	 t          d          5  |                     t                                 ddd           dS # 1 swxY w Y   dS # t           j        $ r |                     d           Y dS w xY w)z!Call check_run with large output.
   NTimeout!msg)r   	check_runr)   r   failr   s    r   test_check_run_timeoutz'CheckOutputTests.test_check_run_timeoutI   s    	&r"" 0 0}///0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0$ 	& 	& 	&II*I%%%%%%	&s3   A "A A  AA AA %A65A6c                     	 t          d          5  |                     t          d          d           d d d            d S # 1 swxY w Y   d S # t           j        $ r |                     d           Y d S w xY w)Nr-   r   r(   r.   r/   r   check_exit_coder)   r   r2   r   s    r   .test_check_exit_code_with_large_output_successz?CheckOutputTests.test_check_exit_code_with_large_output_successQ       	&r"" B B$$]1%=%=%=qAAAB B B B B B B B B B B B B B B B B B$ 	& 	& 	&II*I%%%%%%	&3   A %AA AA 
AA %A98A9c                     	 t          d          5  |                     t          d          d           d d d            d S # 1 swxY w Y   d S # t           j        $ r |                     d           Y d S w xY w)Nr-      r5   r.   r/   r6   r   s    r   .test_check_exit_code_with_large_output_failurez?CheckOutputTests.test_check_exit_code_with_large_output_failureX   r9   r:   c                 `   d}d}||z  }t          ||          }	 t          d          5  |                     |          }|                     ||                    d                     d d d            d S # 1 swxY w Y   d S # t          j        $ r |                     d           Y d S w xY w)N@r#   )r&   r'   r-   zutf-8r.   r/   )r)   r   check_outputassertEqualencoder   r2   )r   r&   r'   expectedcmdlineactuals         r   #test_check_output_with_large_outputz4CheckOutputTests.test_check_output_with_large_output_   s&    &=T&999	&r"" C C**733   )A)ABBB	C C C C C C C C C C C C C C C C C C
 $ 	& 	& 	&II*I%%%%%%	&s4   B ?A7*B 7A;;B >A;?B %B-,B-N)r   r	   r
   r    r3   r8   r=   rF   r   r   r   r+   r+   >   sZ         & & && & && & && & & & &r   r+   )r"   r#   r   )r    r   samba.testsr   r   r)   r+   r   r   r   <module>rH      s       ( ( ( ( ( (& & & & & & & &>Q Q Q Q.& .& .& .& .&' .& .& .& .& .&r   