
    <e]                         d dl Z d dlZd dlZd dlZd dlZd dlZd dlZd dlmZm	Z	m
Z
 d dlmZ d dlmZ 	 ej         n# e$ r  ej        d          w xY w e
d           d Z G d	 d
ej                  Zedk    r ej                     dS dS )    N)cpython_onlyrequires_subprocessrequires_working_socket)threading_helper)TESTFNzselect.poll not definedT)modulec                 N    g }| D ]\  }}||z  r|                     |            |S )N)append)readyflagmatchfdmodes        %/usr/lib/python3.11/test/test_poll.pyfind_ready_matchingr      s>    E  D$; 	LLL    c                       e Zd Zd Zd Z e            d             Zd Zed             Z	e
j        d             Z ej        ed          e
j        d                         Zd	S )
	PollTestsc                 
   t          j                    }d}d}t          |          }g }g }i }i }t          |          D ]}	t	          j                    \  }
}|                    |
           |                    |
t           j                   |                    |t           j	                   |
                    |
           |
                    |           |||
<   |
||<   g }|r|                                }t          |t           j	                  }|st          d          t          j        |          }t	          j        ||           |                                }t          |t           j                  }|st          d          t          j        |          }
t	          j        |
|          }|                     t          |          |           |
                    |           t	          j        ||
                    t	          j        |
           |                    ||
                    |                    |
           |                    ||
                    ||                     ||g|z             d S )N   s    This is a test.zno pipes ready for writingzno pipes ready for reading)selectpolllenrangeospiperegistermodifyPOLLINPOLLOUTr
   r   RuntimeErrorrandomchoicewritereadassertEqualclose
unregisterremove)selfp	NUM_PIPESMSGMSG_LENreaderswritersr2ww2rirdwrbufsr   ready_writersready_readersbufs                    r   
test_poll1zPollTests.test_poll1!   sF    KMM	!c((y!! 	 	AWYYFBJJrNNNHHR'''JJr6>***NN2NN2CGCGG 	$FFHHE/v~FFM  A"#?@@@}--BHRFFHHE/v}EEM  A"#?@@@}--B'"g&&CSXXw///KKHSW"LL#b'###LL"NN3r7###'  	$* 	uy011111r   c                 F   t          j                    \  }}t          j        |           t          j        |           t          j                    }|                    |           |                                }|                     |d         |t          j        f           t          t          d          5 }|
                                }t          j                    }|                    |           |                                }|                     |d         d         |           d d d            n# 1 swxY w Y   |                                }|                     |d         |t          j        f           t          j        t                     t          j                    }|                     t          |j        |           |                     t          |j        |           t          j                    }|                     t          |j        d           t          j                    } G d d          } G d d          }	|                     t          |j         |            d           |                     t          |j         |	            d           d S )Nr   w   c                       e Zd ZdS ),PollTests.test_poll_unit_tests.<locals>.NopeN)__name__
__module____qualname__ r   r   Noper?   q   s        Dr   rD   c                       e Zd Zd ZdS ).PollTests.test_poll_unit_tests.<locals>.Almostc                     dS )NfilenorC   )r*   s    r   rH   z5PollTests.test_poll_unit_tests.<locals>.Almost.filenou   s    xr   N)r@   rA   rB   rH   rC   r   r   AlmostrF   t   s#                 r   rI   )r   r   r'   r   r   r   r&   POLLNVALopenr   rH   unlinkassertRaises	TypeErrorr(   KeyError)
r*   FDr<   r+   rfr   pollsterrD   rI   s
             r   test_poll_unit_testszPollTests.test_poll_unit_testsR   sz   		A

KMM	

2FFHH1FO4555&# 	*!BAJJqMMMAQqT!Wb)))	* 	* 	* 	* 	* 	* 	* 	* 	* 	* 	* 	* 	* 	* 	* FFHH1FO4555
	& KMM)QZ333)Q\1555 KMM(AL!444 ;==	 	 	 	 	 	 	 		  	  	  	  	  	  	  	  	)X%6BBB)X%6!DDDDDs   8A3D77D;>D;c                 p   d}t          j        |dt           j        d          }|                     |           |j        }t          j                    }|                    |t
          j                   dD ]}|                    |          }|g k    r|d         \  }}|t
          j	        z  r0|
                                }	|	dk    r|                     d           h|t
          j        z  r0|
                                }	|	s d S |                     |	d           |                     d	|z             d S )
Nz?for i in 0 1 2 3 4 5 6 7 8 9; do echo testing...; sleep 1; doneTr   )shellstdoutbufsize)r   i  i  i  i@  i>  rY   rY   rY   rY   rY   rY   rY   rY   rY   r   z6error: pipe seems to be closed, but still returns datas   testing...
z,Unexpected return value from select.poll: %s)
subprocessPopenPIPEenterContextrW   r   r   r   r   POLLHUPreadlinefailr&   )
r*   cmdprocr+   rS   toutfdlistr   flagslines
             r   
test_poll2zPollTests.test_poll2~   sJ   O4
()+ + +$K;==1fm---A 	S 	SD]]4((F"q	IBv~% Szz||3;;IIVWWW& Szz|| EE  777		H6QRRRR%	S 	Sr   c                    t          j                    }|                    d           |                     t          |j        d           d}|dk    r|                     d           |                     t          |j        dd           |                     t          |j        dd           |                     t          |j        dd           |                     t          |j        dd           d S )N   l               zOverflow must have occurredr   rY   )r   r   r   rM   OverflowErrorr`   
ValueErrorr   )r*   rS   xs      r   
test_poll3zPollTests.test_poll3   s    ;==!-@@@66II3444 	*h&7B???-):AwGGG*hoq"===-!WEEEEEr   c                    ddl m}m}m} t	          j                    }|                    d           |                     t          |j        d|dz              |                     t          |j	        d|dz              |                     t          |j        |dz              |                     t          |j        |dz              d S )Nr   )	USHRT_MAXINT_MAXUINT_MAXri   )
	_testcapirp   rq   rr   r   r   r   rM   rk   r   )r*   rp   rq   rr   rS   s        r   test_poll_c_limitszPollTests.test_poll_c_limits   s    ::::::::::;==! 	-):Ay1}MMM-!Y]KKK-!DDD-1EEEEEr   c                    t          j                    \  }}|                     t           j        |           |                     t           j        |           g }t	          d          D ]K}t          j        |          }|                     t           j        |           |                    |           Lt          j                    }|D ]"}|	                    |t          j
                   #t          j        |j                  }|                                 	 t          j        d           |D ]}|                    |           |	                    |t          j                   |                     t&          |j                   t          j        |d           |                                 d S # t          j        |d           |                                 w xY w)N
   )targetg      ?   spam)r   r   
addCleanupr'   r   dupr
   r   r   r   r   	threadingThreadstarttimesleepr(   r    rM   r!   r$   join)r*   rQ   r<   rfdsr3   r   rS   ts           r   test_threaded_pollzPollTests.test_threaded_poll   s   wyy1!$$$!$$$r 	 	ABOOBHb)))KKOOOO;== 	1 	1Bb&-0000HM222				
	JsOOO ( (##B''''a000lHM::: HQ   FFHHHHH HQ   FFHHHHs   A.F4 4+Gz!Threading required for this test.c                 p   dD ]1}t          j                    \  }}t          j                    }|                    |t          j                   t          j        |j        |f          }|                                 |	                    d           | 
                    |                                           t          j        |d           |	                                 |                     |                                           t          j        |           t          j        |           3d S )N)NirY   g      gg0.+)rw   argsg?)timeoutrx   )r   r   r   r   r   r   r{   r|   r}   r   
assertTrueis_aliver$   assertFalser'   )r*   
timeout_msrQ   r<   rS   poll_threads         r   !test_poll_blocks_with_negative_msz+PollTests.test_poll_blocks_with_negative_ms   s    A 	 	J 799DAq{}}Ha///#*(-zmTTTKS)))OOK0022333 HQ   [1133444HQKKKHQKKKK#	 	r   N)r@   rA   rB   r:   rT   r   rg   rn   r   rt   r   reap_threadsr   unittest
skipUnlessr{   r   rC   r   r   r   r      s        /2 /2 /2b'E 'E 'EX S S S8F F F" 	F 	F \	F "  #"6 X$GHH"  #" IH  r   r   __main__)r   rZ   r"   r   r{   r~   r   test.supportr   r   r   r   test.support.os_helperr   r   AttributeErrorSkipTestr   TestCaser   r@   mainrC   r   r   <module>r      sb   
			                      * ) ) ) ) ) ) ) ) ) ) )7
KKK 7 7 7
(
5
6
667  t $ $ $ $  I I I I I! I I IX zHMOOOOO s	   < A