Uname: Linux web3.us.cloudlogin.co 5.10.226-xeon-hst #2 SMP Fri Sep 13 12:28:44 UTC 2024 x86_64
Software: Apache
PHP version: 8.1.31 [ PHP INFO ] PHP os: Linux
Server Ip: 162.210.96.117
Your Ip: 18.119.108.166
User: edustar (269686) | Group: tty (888)
Safe Mode: OFF
Disable Function:
NONE

name : test_posix.cpython-310.pyc
o

ab\[�@s�dZddlmZddlmZddlmZddlmZddlmZe�	d�Z
ddlZddlZddl
Z
ddlZddlZddlZddlZddlZddlZddlZddlZddlZej�e��ejd	�Ze�ejd
kd�Zdd
�Ze�e�d�Z Gdd�dej!�Z"Gdd�dej!�Z#Gdd�d�Z$e�e%ed�d�Gdd�dej!e$��Z&e�e%ed�d�Gdd�dej!e$��Z'e�ejdkd�Gdd �d ej!��Z(d!d"�Z)e*d#kr�e�+�dSdS)$zTest posix functions�)�support)�
import_helper)�	os_helper)�warnings_helper)�assert_python_ok�posixNz-dummy-symlink�z(test is only meaningful on 32-bit buildsc
Cs`ttd�sdSzt�d�WdSty/}z|jtjkr$WYd}~dSWYd}~dSd}~ww)N�sched_getschedulerFrT)�hasattrrr	�OSError�errno�ENOSYS)�e�r�8/usr/local/python-3.10/lib/python3.10/test/test_posix.py�_supports_scheds
�
���rzrequires POSIX scheduler APIc@s�
eZdZdd�Zdd�Zdd�Ze�ee	d�d�d	d
��Z
e�ee	d�d�d
d��Ze�ee	d�d�dd��Ze�ee	d�d�dd��Z
e�ee	d�d�dd��Ze�ee	d�d�dd��Ze�ee	d�d�dd��Ze�ee	d�d �d!d"��Ze�ee	d#�d$�d%d&��Ze�ee	d'�d(�d)d*��Ze�ee	d+�d,�d-d.��Ze�eed/d0�ejvd1�e�eed2�d3�d4d5���Ze�ee	d6�d7�e�eed2�d3�d8d9���Ze�eed2�d3�d:d;��Ze�ee	d<�d=�d>d?��Ze�ee	d@�dA�dBdC��Ze�ee	dD�dE�dFdG��Ze�ee	dD�dE�e�ee	dH�dI�dJdK���Ze�ee	dD�dE�edLdM���Z e�ee	dN�dO�dPdQ��Z!e�ee	dR�dS�dTdU��Z"e�ee	dR�dS�e�ee	dV�dW�dXdY���Z#e�ee	dR�dS�edZd[���Z$e�ee	d\�d]�d^d_��Z%e�ee	d\�d]�d`da��Z&e�ee	db�dc�ddde��Z'e�ee	db�dc�dfdg��Z(e�ej)ejvdh�didj��Z*e�ej)ej+vdk�dldm��Z,e�ee	dn�do�dpdq��Z-e�ee	dn�do�edrds���Z.e�ee	dt�du�dvdw��Z/e�ee	dt�du�edxdy���Z0e�ee	dz�d{�d|d}��Z1e�ee	d~�d�d�d���Z2e�ee	d��d��d�d���Z3e�eed��d��e4�5d�d�d��d�d����Z6e�ee	d��d��d�d���Z7e�ee	d��d��d�d���Z8e�ee	d��d��d�d���Z9d�d��Z:e�ee	d��d��d�d���Z;e�ee	d���onee<d��d��d�d���Z=e�ee	d��d��d�d���Z>d�d��Z?e�ee	d��d��d�d���Z@e�ee	d��d��d�d���ZAe�ee	d��d��d�d���ZBe�ee	d��d��d�d���ZCd�d��ZDd�d��ZEd�d��ZFd�d��ZGe�e	jHejvd¡d�dĄ�ZIe�ee	dŃdơd�dȄ�ZJe�ee	dɃdʡd�d̄�ZKe�ee	d̓dΡd�dЄ�ZLe�ee	dуdҡd�dԄ�ZMe�eedՃd֡e4�5d�d�dסd�dل��ZNe4jOe�eedՃd֡e4�5d�d�dסd�dۄ���ZPe�ee	d܃dݡd�d߄�ZQd�d�ZRe�ee	d�d�d�d��ZSe�ee	d�d�d�d��ZTe�ee	d�d�d�d��ZUd�d�ZVd�d�ZWe�ee	d�d�d�d��ZXe�ee	d�d��e�eeYd��d��e�eed��d��d�d�����ZZe�eed��d��e�eed��d���d�d���Z[e�ej\ej]v�d��d�d��Z^e�ej_ej]v�d��d�d��Z`e�eed���o�ejaej]v�d��d	�d
��Zbe�ej<ej]v�d��d�d
��Zce�ej)ej]v�d��d�d��Zde�ejeej]v�d��d�d��Zfe�ejgej]v�d��d�d��Zhe�eed���oKejiej]v�oKee<d���d��d�d��Zje�ejkej]v�d��d�d��Zle�ee�d��otejmej]v�d��d�d ��Zne�ejoej]v�d!��d"�d#��Zpe�eeq�d$��d%�e�ee�d&��d'��d(�d)���Zre�ejsej]v�d*��d+�d,��Zte�ejuej]v�d-��d.�d/��Zve�ejwej]v�d0��d1�d2��Zxe�ee	�d3��d4�Zye�ee	�d5��d6�Zzey�d7�d8��Z{eye�ee	�d9��d:��d;�d<���Z|e}�d=�d>��Z~e�ee	�d?��d@��dA�dB��Zez�dC�dD��Z�ez�dE�dF��Z��dG�dH�Z�e�ee�dI��dJ��dK�dL��Z��dM�dN�Z��dO�dP�Z��dQ�dR�Z�e�ee�dS��dT��dU�dV��Z�d0S(W�PosixTestercCs\ttjd��Wd�n1swYtjg|_t��|_|j��t�	ddt
�dS)N�wb�ignorez.* potential security risk .*)�openr�TESTFN�teardown_filesrZcheck_warnings�_warnings_manager�	__enter__�warnings�filterwarnings�RuntimeWarning��selfrrr�setUp.s�


�zPosixTester.setUpcCs*|jD]}t�|�q|j�ddd�dS�N)rr�unlinkr�__exit__)rZ
teardown_filerrr�tearDown8s
zPosixTester.tearDowncCs>gd�}|D]}tt|d�}|dur|�|�t|d�qdS)N)�ctermid�getcwd�getcwdb�uname�times�
getloadavg�getegid�geteuid�getgid�	getgroups�getpid�getpgrp�getppid�getuid�sync�)�getattrr�assertRaises�	TypeError)rZNO_ARG_FUNCTIONS�nameZ
posix_funcrrr�testNoArgFunctions=s��zPosixTester.testNoArgFunctions�	getresuidztest needs posix.getresuid()cC�2t��}|�t|�d�|D]}|�|d�qdS�N�r)rr9�assertEqual�len�assertGreaterEqual)rZuser_ids�valrrr�test_getresuidL�
�zPosixTester.test_getresuid�	getresgidztest needs posix.getresgid()cCr:r;)rrCr=r>r?)rZ	group_idsr@rrr�test_getresgidTrBzPosixTester.test_getresgid�	setresuidztest needs posix.setresuid()cC�0t��}|�tj|��|�t�ddd��dS�N���)rr9�assertIsNonerE)r�current_user_idsrrr�test_setresuid\�zPosixTester.test_setresuidcC�@t��}d|vr|ddddf}|jttjg|�R�dSdS�Nrr3rH)rr9r5rrE)rrJZnew_user_idsrrr�test_setresuid_exceptiond�
�z$PosixTester.test_setresuid_exception�	setresgidztest needs posix.setresgid()cCrFrG)rrCrIrQ)r�current_group_idsrrr�test_setresgidmrLzPosixTester.test_setresgidcCrMrN)rrCr5rrQ)rrRZ
new_group_idsrrr�test_setresgid_exceptionurPz$PosixTester.test_setresgid_exception�
initgroupsztest needs os.initgroups()c
Cs�|�ttj�|�ttjd�|�ttjdd�|�ttjddt��t��dkrkz
t�t���j	}Wnt
y?t�d��wzt�|d�Wnt
yc}z|�|jtj�WYd}~dSd}~ww|�d�dSdS)Nr<�foorzneed a pwd entry�
z+Expected OSError to be raised by initgroups)r5r6rrU�object�osr1�pwd�getpwuid�pw_name�KeyError�unittest�SkipTestrr=r�EPERM�fail)rr7rrrr�test_initgroups~s$
����zPosixTester.test_initgroups�statvfsztest needs posix.statvfs()cCs|�t�tj��dSr )�
assertTruerrcrY�curdirrrrr�test_statvfs��zPosixTester.test_statvfs�fstatvfsztest needs posix.fstatvfs()cCsLttj�}z|�t�|����|�t�|����W|��dS|��wr )	rrrrdrrh�filenorc�close�r�fprrr�
test_fstatvfs�s

zPosixTester.test_fstatvfs�	ftruncateztest needs posix.ftruncate()cCsHttjd�}z|�d�|��t�|��d�W|��dS|��w)N�w+�testr)	rrr�write�flushrrnrirjrkrrr�test_ftruncate�s
zPosixTester.test_ftruncate�truncateztest needs posix.truncate()cCsPttjd��}|�d�|��Wd�n1swYt�tjd�dS)N�wrpr)rrrrqrrrrtrkrrr�
test_truncate�s


�zPosixTester.test_truncate�execveNz/test needs execve() to support the fd parameter�forkztest needs os.fork()c	Cs�t�tjtj�}z8t��}|dkr*t�tj�tj�d�t	�
|tjddgtj�ntj
|dd�Wt�|�dSWt�|�dSt�|�w)Nr�-c�pass��exitcode)rYr�sys�
executable�O_RDONLYrx�chdir�path�splitrrw�environr�wait_processrj)rrl�pidrrr�test_fexecve�s�zPosixTester.test_fexecve�waitidztest needs posix.waitid()cCsjt��}|dkr#t�tj�tj�d�t�tjtjddgtj	�dSt�
tj|tj�}|�
||j�dS)Nrryrz)rYrxr�r�r�r}r~rrwr�r��P_PID�WEXITEDr=�si_pid)rr��resrrr�test_waitid�szPosixTester.test_waitidcCs,|jtdd��t�dd��Wd�n1swY|jtdd��tjdd�Wd�n1s6wY|jtdd��tjdd	�Wd�n1sSwY|jtdd��tjd
d�Wd�n1spwY|jtdd��tjdd�Wd�n1s�wY|jtdd��tjdd	�Wd�n1s�wY|jtdd��tjdd�Wd�n1s�wY|jtd
d��tjddd�d�Wd�n1s�wY|jtd
d��tjdd�dd�Wd�n	1�swYd}td|�dS)NzPositional args not allowed)�msgcS�dSr rrrrr�<lambda>��z3PosixTester.test_register_at_fork.<locals>.<lambda>zArgs must be callable�)�beforeZthree)�after_in_childsFive)�after_in_parentzArgs must not be NonezInvalid arg was allowedcSsdS)Nr<rrrrrr��r�)r�r�cSr�r rrrrrr��r��)r�r�a�if 1:
            import os

            r, w = os.pipe()
            fin_r, fin_w = os.pipe()

            os.register_at_fork(before=lambda: os.write(w, b'A'))
            os.register_at_fork(after_in_parent=lambda: os.write(w, b'C'))
            os.register_at_fork(after_in_child=lambda: os.write(w, b'E'))
            os.register_at_fork(before=lambda: os.write(w, b'B'),
                                after_in_parent=lambda: os.write(w, b'D'),
                                after_in_child=lambda: os.write(w, b'F'))

            pid = os.fork()
            if pid == 0:
                # At this point, after-forkers have already been executed
                os.close(w)
                # Wait for parent to tell us to exit
                os.read(fin_r, 1)
                os._exit(0)
            else:
                try:
                    os.close(w)
                    with open(r, "rb") as f:
                        data = f.read()
                        assert len(data) == 6, data
                        # Check before-fork callbacks
                        assert data[:2] == b'BA', data
                        # Check after-fork callbacks
                        assert sorted(data[2:]) == list(b'CDEF'), data
                        assert data.index(b'C') < data.index(b'D'), data
                        assert data.index(b'E') < data.index(b'F'), data
                finally:
                    os.write(fin_w, b'!')
            ry)r5r6rY�register_at_forkr)r�coderrr�test_register_at_fork�s:���������#z!PosixTester.test_register_at_fork�lockfztest needs posix.lockf()c	Cspt�tjtjtjB�}z&t�|d�t�|dtj�t	�
|t	jd�t	�
|t	jd�Wt�
|�dSt�
|�w)N�testr�)rYrrr�O_WRONLY�O_CREATrq�lseek�SEEK_SETrr��F_LOCK�F_ULOCKrj�r�fdrrr�
test_lockfszPosixTester.test_lockf�preadztest needs posix.pread()c	Cszt�tjtjtjB�}z+t�|d�t�|dtj�|�	dt
�|dd��|�	dt
�|d��Wt�
|�dSt�
|�w)Nr�rsesr�r3ste)rYrrr�O_RDWRr�rqr�r�r=rr��readrjr�rrr�
test_preadszPosixTester.test_pread�preadvztest needs posix.preadv()c	Csxt�tjtjtjB�}z*t�|d�dd�dD�}|�t�	||d�d�|�gd�t
|��Wt�|�dSt�|�w)N�test1tt2t3t5t6t6t8cS�g|]}t|��qSr��	bytearray��.0�irrr�
<listcomp>-�z+PosixTester.test_preadv.<locals>.<listcomp>��r<r�r<�
�st1tt2st3ts5t)rYrrrr�r�rqr=rr��listrj)rr��bufrrr�test_preadv(szPosixTester.test_preadv�	RWF_HIPRIztest needs posix.RWF_HIPRIc
Cs�t�tjtjtjB�}z_z&t�|d�dd�dD�}|�t�	||dtj
�d�|�gd�t|��Wn(ty@|�
d�Yn#tyZ}z|jtjtjhvrUt�d	���d}~wwWt�|�dSWt�|�dSt�|�w)
Nr�cSr�rr�r�rrrr�9r�z1PosixTester.test_preadv_flags.<locals>.<listcomp>r�r<r�r�zpreadv2 not availablez0RWF_HIPRI is not supported by the current system)rYrrrr�r�rqr=rr�r�r��NotImplementedError�skipTestrr�EINVAL�ENOTSUPr^r_rj)rr�r��instrrr�test_preadv_flags3s$
����
zPosixTester.test_preadv_flagsc	Cs�t�tjtjtjB�}z@td�gd}|�t��}t�	||d�Wd�n1s*wY|�
|jjtj
�|�
t|d�dd�Wt�|�dSt�|�w�N���r�)rYrrrr�r�r�r5rr�r=�	exceptionrr��bytesrj�rr�r��cmrrr�test_preadv_overflow_32bitsIs�z'PosixTester.test_preadv_overflow_32bits�pwriteztest needs posix.pwrite()c	Csrt�tjtjtjB�}z't�|d�t�|dtj�t	�
|dd�|�dt	�|d��Wt�
|�dSt�
|�w)Nr�r�xxr3stxxtr�)rYrrrr�r�rqr�r�rr�r=r�rjr�rrr�test_pwriteVszPosixTester.test_pwrite�pwritevztest needs posix.pwritev()c	Cs�t�tjtjtjB�}z7t�|d�t�|dtj�t�	|gd�d�}|�
|d�t�|dtj�|�
dt�|d��Wt�
|�dSt�
|�w)Nr�r�stest1stt2st3r�r�sxxtest1tt2t3�d)rYrrrr�r�rqr�r�r�r=rr�rj�rr��nrrr�test_pwritevaszPosixTester.test_pwritevzos.RWF_SYNCztest needs os.RWF_SYNCc	Cs�t�tjtjtjB�}z9t�|d�t�|dtj�t�	|gd�dtj
�}|�|d�t�|dtj�|�dt�
|d��Wt�|�dSt�|�w)Nr�rr�r�r�s
xxtest1tt2r�)rYrrrr�r�rqr�r�r��RWF_SYNCr=rr�rjr�rrr�test_pwritev_flagsoszPosixTester.test_pwritev_flagsc	Cs�t�tjtjtjB�}z2|�t��}t�|ddgdd�Wd�n1s(wY|�	|j
jtj�Wt�
|�dSt�
|�w)N�xr�r�r)rYrrrr�r�r5rr�r=r�rr�rj�rr�r�rrr�test_pwritev_overflow_32bits~s�z(PosixTester.test_pwritev_overflow_32bits�posix_fallocatez"test needs posix.posix_fallocate()c
Cs�t�tjtjtjB�}z0z	t�|dd�Wnty3}z|j	t	j
kr.tj�
d�r.t�d���d}~wwWt�|�dSt�|�w)Nrr�)Zsunos�freebsd�netbsdZopenbsdZgnukfreebsdz test may fail on ZFS filesystems)rYrrrr�r�rr�rrr�r}�platform�
startswithr^r_rj)rr�r�rrr�test_posix_fallocate�s�
���z PosixTester.test_posix_fallocatec
CsJz
t�ddd�WdSty$}z|jtjkr�WYd}~dSd}~ww)N����rr�)rr�rr�EBADF�rr�rrr�test_posix_fallocate_errno�s���z&PosixTester.test_posix_fallocate_errno�
posix_fadvisez test needs posix.posix_fadvise()c	Cs@t�tjtj�}zt�|ddtj�Wt�|�dSt�|�w�Nr)	rYrrrrrr��POSIX_FADV_WILLNEEDrjr�rrr�test_posix_fadvise�szPosixTester.test_posix_fadvisec
CsNzt�dddtj�WdSty&}z|jtjkr�WYd}~dSd}~ww)Nr�r)rr�r�rrr�r�rrr�test_posix_fadvise_errno�s���z$PosixTester.test_posix_fadvise_errnoz!test needs fd support in os.utimec	CsNt��}t�tjtj�}z�t�|�t�|d�|�t	tj|d�|�t	tj||df�|�t	tj|d|f�t�|t
|�t
|�f�t�|||f�|jttj|||f||fd�|jttj||dfdd�|jttj|d|dfd�t�|t
|�t
|t
|�d�f�tj|t
|�t
|t
|�d�fd�Wt�|�dSt�|�w)N�NN)�nsr�e��A)
�timerYrrrrr�utimer5r6�int�
ValueErrorrj)r�nowr�rrr�test_utime_with_fd�s 
$(zPosixTester.test_utime_with_fdz.test needs follow_symlinks support in os.utimecCs�t��}tjtjddd�|jttjtjddd�|jttjtj|dfdd�|jttjtjd|fdd�tjtjt|�t|�fdd�tjtj||fdd�tjtjdd�dS)NF��follow_symlinksr��r�rr�rrr5r6r��rr�rrr�test_utime_nofollow_symlinks�s ����z(PosixTester.test_utime_nofollow_symlinks�writevztest needs posix.writev()c	Cs�t�tjtjtjB�}zFt�|d�}|�|d�t�|dtj	�|�dt
�|d��zt
�|g�}Wn	ty;Ynw|�|d�Wt�
|�dSWt�
|�dSt�
|�w)Nr�r�r�
test1tt2t3)rYrrrr�r�r�r=r�r�rr�rrj)rr�r��sizerrr�test_writev�s��zPosixTester.test_writevc	Cs�t�tjtjtjB�}z1|�t��}t�|ddgd�Wd�n1s'wY|�	|j
jtj�Wt�
|�dSt�
|�w)Nr�r�r�)rYrrrr�r�r5rr�r=r�rr�rjr�rrr�test_writev_overflow_32bits�s�z'PosixTester.test_writev_overflow_32bits�readvztest needs posix.readv()c	Cs�t�tjtjtjB�}zTt�|d�t�|dtj�dd�dD�}|�	t
�||�d�|�	gd�dd�|D��zt
�|g�}Wn	tyIYnw|�	|d�Wt�
|�dSWt�
|�dSt�
|�w)	Nr�rcSr�rr�r�rrrr�r�z*PosixTester.test_readv.<locals>.<listcomp>r�r�r�cSr�r)r�r�rrrr�r�)rYrrrr�r�rqr�r�r=rr�rrj)rr�r�r�rrr�
test_readv�s ��zPosixTester.test_readvc	Cs�t�tjtjtjB�}z?td�gd}|�t��}t�	||�Wd�n1s)wY|�
|jjtj
�|�
t|d�dd�Wt�|�dSt�|�wr�)rYrrrr�r�r�r5rr�r=r�rr�r�rjr�rrr�test_readv_overflow_32bitss�z&PosixTester.test_readv_overflow_32bits�dupztest needs posix.dup()cCsHttj�}zt�|���}|�|t�t�	|�W|�	�dS|�	�wr )
rrrrr�ri�assertIsInstancer�rYrj)rrlr�rrr�test_dup s
zPosixTester.test_dup�confstrztest needs posix.confstr()cCs.|�ttjd�|�tt�d��dkd�dS)NZ
CS_garbage�CS_PATHrT)r5r�rrr=r>rrrr�test_confstr+szPosixTester.test_confstr�dup2ztest needs posix.dup2()cCsRttj�}ttj�}zt�|��|���W|��|��dS|��|��wr )rrrrrrirj)r�fp1�fp2rrr�	test_dup21s

�
zPosixTester.test_dup2�	O_CLOEXECzneeds os.O_CLOEXECr���cCs8t�tjtjtjB�}|�tj|�|�t�	|��dSr )
rYrrrrr�
addCleanuprj�assertFalse�get_inheritabler�rrr�test_oscloexec<szPosixTester.test_oscloexec�O_EXLOCKztest needs posix.O_EXLOCKcCs�t�tjtjtjBtjB�}|�ttjtjtjtjBtj	B�t�
|�ttd�rOt�tjtjtj
BtjB�}|�ttjtjtjtjBtj	B�t�
|�dSdS)N�O_SHLOCK)rYrrrr�rr�r5r�
O_NONBLOCKrjr
rrr�rrr�
test_osexlockCs ��

���zPosixTester.test_osexlockrztest needs posix.O_SHLOCKcCs�t�tjtjtjBtjB�}t�tjtjtjBtjB�}t�|�t�|�tt	d�rQt�tjtjtjBtjB�}|�
ttjtjtjtj
BtjB�t�|�dSdS)Nr)rYrrrr�rr�rjr
rr5rrrr)r�fd1�fd2r�rrr�
test_osshlockSs"��


���zPosixTester.test_osshlock�fstatztest needs posix.fstat()cCsfttj�}z(|�t�|����|�t�|����|�t	dtjt
|����W|��dS|��w�Nz4should be string, bytes, os.PathLike or integer, not)rrrrdrrri�stat�assertRaisesRegexr6�floatrjrkrrr�
test_fstatds
�zPosixTester.test_fstatc	Cs�|�t�tj��|�t�t�tj���|�tdtjt	t�tj���|�
tdtjd�|�
tdtjttj��|�
tdtjtt�tj���dSr)
rdrrrrrY�fsencodeZassertWarnsRegex�DeprecationWarningr�rr6r�rrrr�	test_statrs$����zPosixTester.test_stat�mkfifozdon't have mkfifo()c
Cs�tjdkrtj�dtj�}ntj}t�|�|�tj|�zt	�
|tjtj
B�WntyB}z
|�d|�WYd}~nd}~ww|�t�t	�|�j��dS)N�vxworksz/fifos/�posix.mkfifo(): %s)r}r�rYr��joinrrr!r
rrr�S_IRUSR�S_IWUSR�PermissionErrorr�rd�S_ISFIFO�st_mode)rZ	fifo_pathrrrr�test_mkfifo�s

��zPosixTester.test_mkfifo�mknod�S_IFIFOzdon't have mknod()/S_IFIFOc
Cs�t�tj�tjtjBtjB}z
t�tj|d�Wnt	y8}z|�
|jtjtj
tjf�WYd}~nd}~ww|�t�t�tj�j��t�tj�z
tjtj|ddd�WdSt	yy}z|�
|jtjtj
tjf�WYd}~dSd}~ww)Nr)r��modeZdevice�dir_fd)rr!rrr)r"r#rr(r�assertInrr`r��EACCESrdr%r&)rr*rrrr�
test_mknod�s$&���(��zPosixTester.test_mknod�makedevztest needs posix.makedev()cCs`t�tj�}|j}|�|t�|�|d�t�|�}|�|t�|�|d�|�	t�|�|�|�
ttjt|��|�
ttj�|�
t
tftjd�t�|�}|�|t�|�|d�|�	t�|�|�|�
ttjt|��|�
ttj�|�
t
tftjd�|�	t�||�|�|�
ttjt|�|�|�
ttj|t|��|�
ttj|�|�
ttj�dS)NrrH)rrrr�st_devr�r�r?�majorr=r5r6rr��
OverflowError�minorr/)r�st�devr1r3rrr�test_makedev�s.

zPosixTester.test_makedevc
	s����fdd�}t��}t��}|�||�|||�|�d|�|||�|�|d�|||�tjdkr;|dv}n|dk}|rltjdkrHdnd}|�||�|||�|�dd�|||�|�||�|||�n;t��d	vrwt�d
����t	|�dd�|||���t	|�dd�|||�dt�
�vr���t	|�dd�|||�ttfD]"}	��t
|�|	|�|�|||���t
|�||	|��|||�q�dS)z/Common code for chown, fchown and lchown tests.cs4�dur���}��|j|���|j|�dSdSr )r=�st_uid�st_gid)�uid�gidr��first_paramr�	stat_funcrr�
check_stat�s
�z6PosixTester._test_all_chown_common.<locals>.check_statrHr)rr3rlr�)zHP-UXZSunOSz1Skipping because of non-standard chown() behaviorN)rYr1r,r}r��systemr^r_r5rr-�strrr6)
rZ
chown_funcr<r=r>r9r:Zis_rootZ	big_value�trr;r�_test_all_chown_common�sF











�z"PosixTester._test_all_chown_common�chownztest needs os.chown()cCsFt�tj�|�ttjtjdd�t�tj�|�	tjtjtj
�dSrG)rYr!rrr5rrrC�create_empty_filerBrrrrr�
test_chown
szPosixTester.test_chown�fchownztest needs os.fchown()cCsRt�tj�ttjd�}z|��}|�tj|t	tdd��W|�
�dS|�
�w)Nrur)rYr!rrrrirBrrFr4rj)rZ	test_filer�rrr�test_fchowns

�zPosixTester.test_fchown�lchownztest needs os.lchown()cCs8t�tj�t�ttj�|�tjtjt	tdd��dS)N�lstat)
rYr!rr�symlink�_DUMMY_SYMLINKrBrrHr4rrrr�test_lchown!s

�zPosixTester.test_lchownr�ztest needs posix.chdir()cCs"t�tj�|�ttjtj�dSr )rr�rYrer5rrrrrrr�
test_chdir)szPosixTester.test_chdircCs|�tjt�tj��dSr )r,rrr�listdirrYrerrrr�test_listdir.szPosixTester.test_listdircCs|�tjt���dSr )r,rrrrNrrrr�test_listdir_default1rgz PosixTester.test_listdir_defaultcCs|�t�tj�t�d��dS�N�.)r,rYrrrrrNrrrr�test_listdir_bytes6szPosixTester.test_listdir_bytesc	CsxttfD]5}|�t��t�|d��}Wd�n1swY|�t�t	j
�|�|D]
}|�t|�t
�q.qdSrQ)r��
memoryviewZassertWarnsrrrNr,rYrrrZassertIs�typer�)r�cls�namesr7rrr�test_listdir_bytes_like;s���z#PosixTester.test_listdir_bytes_likez)test needs fd support for posix.listdir()cCsdt�t��tj�}|�tj|�|�tt�d��tt�|���|�tt�d��tt�|���dS)N�.)	rrr%rr
rjr=�sortedrN�r�frrr�test_listdir_fdCs��zPosixTester.test_listdir_fd�accessztest needs posix.access()cCs|�t�tjtj��dSr )rdrr^rrrY�R_OKrrrr�test_accessRszPosixTester.test_access�umaskztest needs posix.umask()cCs$t�d�}|�|t�t�|�dSr�)rrar�r�)rZold_maskrrr�
test_umaskVs
zPosixTester.test_umask�strerrorztest needs posix.strerror()cCs|�t�d��dSr�)rdrrcrrrr�
test_strerror\szPosixTester.test_strerror�pipeztest needs posix.pipe()cCs$t��\}}t�|�t�|�dSr )rrerYrj)r�reader�writerrrr�	test_pipeas
zPosixTester.test_pipe�pipe2ztest needs os.pipe2()�cCs�|�ttjd�|�ttjdd�t�d�\}}t�|�t�|�t�tjtjB�\}}|�tj|�|�tj|�|�t�	|��|�t�	|��|�t�
|��|�t�
|��|�ttj|d�zt�
|dtj�WdStyzYdSw)NZDEADBEEFrr3r�)r5r6rYrirjrrr
rr�get_blockingrr�rqrZ
PIPE_MAX_SIZE)r�rrurrr�
test_pipe2gs$

�zPosixTester.test_pipe2cCs8ddl}|�ttj|jd�|�ttj|jd�dS�Nrr3)�	_testcapir5r2rYriZINT_MAXZUINT_MAX)rrorrr�test_pipe2_c_limits�szPosixTester.test_pipe2_c_limitsr�ztest needs posix.utime()cCs�t��}t�tjd�|�ttjtjd�|�ttjtj|df�|�ttjtjd|f�t�tjt|�t|�f�t�tj||f�dS)Nr�r�r�rrr�
test_utime�s
�

�

�zPosixTester.test_utimec
Kst�|�}|�t|d��|jtjB}z|||fi|��Wn ty>}z|jtjkr-�d}|�	|�WYd}~nd}~wwzFt�|�}|�
|jtjB|j�zt|d�}	Wntyq}
z|�
|
jtj�WYd}
~
nd}
~
wwWt
�||j�dSWt
�||j�dSt
�||j�w)N�st_flags�2chflag UF_IMMUTABLE not supported by underlying fsro)rYrrdr
rr�UF_IMMUTABLErr�
EOPNOTSUPPr�r=rr`r�chflags)rZchflags_funcZtarget_file�kwargsr4�flags�errr�Znew_str�rrrr�_test_chflags_regular_file�s2
��
����"z&PosixTester._test_chflags_regular_filervztest needs os.chflags()cCs|�tjtj�dSr )rzrrvrrrrrr�test_chflags�szPosixTester.test_chflags�lchflagsztest needs os.lchflags()cCs(|�tjtj�|jtjtjdd�dS�NFr�)rzrr|rrrvrrrr�test_lchflags_regular_file�s
�z&PosixTester.test_lchflags_regular_filec
Cst�tj�}|�t|d��t�tjt�|j�	t�t�
t�}dd�}tj|fD]]}|j
tjB}z|t|�Wn tyX}z|jtjkrG�d}|�|�WYd}~nd}~wwz&t�tj�}t�
t�}	|�|j
|j
�|�|j
tjB|	j
�W|t|j
�q)|t|j
�wdS)NrrcSstj||dd�Sr})rrv)r�rxrrr�chflags_nofollow�sz;PosixTester.test_lchflags_symlink.<locals>.chflags_nofollowrs)rYrrrrdr
rJrKr�appendrIrr|rrrtrrrur�r=)
rZ	testfn_stZdummy_symlink_str�fnrxryr�Z
new_testfn_stZnew_dummy_symlink_strrr�test_lchflags_symlink�s4
��
��z!PosixTester.test_lchflags_symlinkcCsLtjdkrt}nt}tj��D]\}}|�t|�|�|�t|�|�qdS)N�nt)	rYr7r@r�rr��itemsr=rU)rZ	item_type�k�vrrr�test_environ�s
�zPosixTester.test_environcCsJ|�t��t�dd�Wd�n1swY|�t��t�dd�Wd�n1s1wY|�t��t�dd�Wd�n1sLwY|�t��t�dd�Wd�n1sgwY|�t��t�d	d
�Wd�n1s�wY|�t��t�dd�Wd�dS1s�wYdS)
NzFRUITVEGETABLEZcabbagesFRUITVEGETABLEscabbageZFRUITzorangeVEGETABLE=cabbagesFRUITsorangeVEGETABLE=cabbagezFRUIT=ORANGEZlemonsFRUIT=ORANGEslemon)r5r�rY�putenvrrrr�test_putenv�s$�����"�zPosixTester.test_putenvr%ztest needs posix.getcwd()c	s�d}t��}tj�tj�d}z+zt�|�t�|�WnYWt�|�t�|�dSWt�|�t�|�dSt�|�t�|�w)Nz8getcwd-test-directory-0123456789abcdef-01234567890abcdefz.getcwd)	rYr%r��abspathrr�mkdirr��rmtree)r�dirnamere�	base_pathr)Z_create_and_do_getcwdr�test_getcwd_long_pathnames�s

�

�z&PosixTester.test_getcwd_long_pathnames�getgrouplistztest needs posix.getgrouplist()r[ztest needs pwd.getpwuid()r1ztest needs os.getuid()cCs<t�t���d}t�t���d}|�|t�||��dS)Nrr<)rZr[rYr1r,rr�)r�user�grouprrr�test_getgrouplistszPosixTester.test_getgrouplistr*ztest needs os.getegid()�popenztest needs os.popen()cCst�d��}|����}|��}Wd�n1swYz
tdd�|��D��}Wnty8t�}Ynw|dus?|sDt�	d��t
jdkrkddl}|�
d�pSd}td	d�|�d
�dd�D��dkrkt�	d
��|�t���}|�|p}|t��hk�dS)Nzid -G 2>/dev/nullcs��|]}t|�VqdSr �r�)r��grrr�	<genexpr>(��z-PosixTester.test_getgroups.<locals>.<genexpr>zneed working 'id -G'�darwinrZMACOSX_DEPLOYMENT_TARGETz10.3csr�r r�)r�r�rrrr�2r�rYr�)r�rz$getgroups(2) is broken prior to 10.6)rYr�r��striprj�setr�r�r^r_r}r��	sysconfigZget_config_var�tuple�symmetric_differencerr-rdr*)rZidg�groups�retZ
idg_groupsr�ZdtZsymdiffrrr�test_getgroups s$
�
�

$
zPosixTester.test_getgroupsz)test needs dir_fd support for os.access()c	CsJt�t��tj�}z|�tjtjtj	|d��Wt�
|�dSt�
|�w�N�r+)rrr%rrdr^rrrYr_rjr[rrr�test_access_dir_fd>szPosixTester.test_access_dir_fdz'test needs dir_fd support in os.chmod()c	Cs�t�tjtj�t�t��tj	�}z*tjtjtjtj
B|d�t�tj�}|�|dtj@tjtj
B�Wt�
|�dSt�
|�w)Nr�r)rY�chmodrrrr"rrr%rr#r=�S_IRWXUrj)rr\�srrr�test_chmod_dir_fdFs zPosixTester.test_chmod_dir_fdz'test needs dir_fd support in os.chown()c	Csdt�tj�t�tj�t�t��tj�}ztjtjt	�
�t	��|d�Wt�|�dSt�|�wr�)
rr!rrDrrr%rrCrYr1r,rjr[rrr�test_chown_dir_fdSszPosixTester.test_chown_dir_fdz&test needs dir_fd support in os.stat()c	Cst�tj�ttjd��
}|�d�Wd�n1swYt�t��tj�}zQt�tj�}tjtj|d�}|�	||�tjtjdd�}|�	||�|j
tdtjtjt��d�|j
tdtjtjt|�d�|j
ttjtjdd�Wt�|�dSt�|�w)Nru�	testline
r�zshould be integer or None, notl F�x:^V)rr!rrrqrr%rrr=rr6rr5r2rj)r�outfiler\�s1�s2rrr�test_stat_dir_fd_s*���
�zPosixTester.test_stat_dir_fdz'test needs dir_fd support in os.utime()c	Cs�t�t��tj�}z�t��}tjtjd|d�tjtj|d�|jt	tjtj||d�|jt	tjtjd|d�|jt	tjtj|df|d�|jt	tjtjd|f|d�|jt	tjtj|df|d�tjtjt
|�t
|�f|d�tjtj||f|d�tjtjt
|�t
|t
|�d�f|d�tjtj|t
|�t
|t
|�d�fd�tjtjvr�ztjtjd|d�Wnt
y�YnwWt�|�dSWt�|�dSWt�|�dSt�|�w)Nr�r��xr�)r+r(F)r�r+)rrr%rr�r�rrr5r6r�rY�supports_follow_symlinksr�rj)rr\r�rrr�test_utime_dir_fdusT������
�

���	��zPosixTester.test_utime_dir_fdz&test needs dir_fd support in os.link()c
Cs�t�t��tj�}z]ztjtjtjd||d�Wnty2}z
|�d|�WYd}~n)d}~ww|�	t�
tj�dt�
tjd�d�Wt�|�t�tjd�dSWt�|�t�tjd�dSt�|�t�tjd�w)N�link��
src_dir_fd�
dst_dir_fdzposix.link(): %sr3)
rrr%rr�rrr$r�r=rrjr!�rr\rrrr�test_link_dir_fd�s&
����
�

�zPosixTester.test_link_dir_fdz'test needs dir_fd support in os.mkdir()c
Cstt�t��tj�}z"tjtjd|d�t�tjd�Wt�|�t�	tjd�dSt�|�t�	tjd�w)N�dirr�)
rrr%rr�rrrrjr�r[rrr�test_mkdir_dir_fd�s

�zPosixTester.test_mkdir_dir_fdzAtest requires both stat.S_IFIFO and dir_fd support for os.mknod()c
Cs�t�tj�tjtjBtjB}t�t�	�tj
�}zIztjtj|d|d�WntyD}z|�
|jtjtjtjf�WYd}~nd}~ww|�t�t�tj�j��Wt�|�dSWt�|�dSt�|�w)Nrr�)rr!rrr)r"r#rrr%rr(rr,rr`r�r-rdr%r&rj)rr*r\rrrr�test_mknod_dir_fd�s&���zPosixTester.test_mknod_dir_fdz&test needs dir_fd support in os.open()c	Cs�t�tj�ttjd��
}|�d�Wd�n1swYt�t��tj�}tjtjtj|d�}zt�|d�j	dd�}|�
d|�Wt�|�t�|�dSt�|�t�|�w)Nrur�r��	�utf-8��encoding)rr!rrrqrr%rr��decoder=rj)rr��a�br�rrr�test_open_dir_fd�s�

�zPosixTester.test_open_dir_fd�readlinkz*test needs dir_fd support in os.readlink()c
Cs�t�tjtjd�t�t��tj�}z$|�t�	tjd�tj	tjd|d��Wt�
tjd�t�|�dSt�
tjd�t�|�w�Nr�r�)rYrJrrrrr%rr=r�r!rjr[rrr�test_readlink_dir_fd�s��z PosixTester.test_readlink_dir_fdz(test needs dir_fd support in os.rename()c	Cs�t�tj�t�tjd�t�t��tj�}z,ztjtjdtj||d�Wnt�tjdtj��t�	tj�Wt�
|�dSt�
|�w)NZrenr�)rr!rrDrrr%r�renamerrjr[rrr�test_rename_dir_fd�szPosixTester.test_rename_dir_fd�SIGCHLDz2CLD_XXXX be placed in si_code for a SIGCHLD signal�
waitid_resultztest needs os.waitid_resultcCs(tjtjtjtjtjtjdSr )rY�
CLD_EXITED�
CLD_KILLED�
CLD_DUMPED�CLD_TRAPPED�CLD_STOPPED�
CLD_CONTINUEDrrrr�test_cld_xxxx_constants�s
z#PosixTester.test_cld_xxxx_constantsz)test needs dir_fd support in os.symlink()c
Cs�t�t��tj�}z)tjtjtjd|d�|�t�tjd�tj�Wt�	|�t�
tjd�dSt�	|�t�
tjd�wr�)rrr%rrJrrr=r�rjr!r[rrr�test_symlink_dir_fd�s��

�zPosixTester.test_symlink_dir_fdz(test needs dir_fd support in os.unlink()c	Cs�t�t��tj�}t�tjd�t�tjd�z,ztjtjd|d�Wnt�tjd��|�	t
tjtjd�Wt�|�dSt�|�w)N�delr�r�)rrr%rrrDrrr!r5rrjr[rrr�test_unlink_dir_fdszPosixTester.test_unlink_dir_fdz(test needs dir_fd support in os.mkfifo()c
Cs�t�tj�t�t��tj�}z>ztjtjtj	tj
B|d�Wnty8}z
|�d|�WYd}~nd}~ww|�
t�t�tj�j��Wt�|�dSt�|�w)Nr�r )rr!rrrr%rrrr"r#r$r�rdr%r&rjr�rrr�test_mkfifo_dir_fds
���zPosixTester.test_mkfifo_dir_fd�sched_yieldzdon't have scheduling support�sched_setaffinityz!don't have sched affinity supportcC�t��dSr )rr�rrrr�test_sched_yield)szPosixTester.test_sched_yield�sched_get_priority_maxz!requires sched_get_priority_max()cCsptj}t�|�}t�|�}|�|t�|�|t�|�||�tjdkr6|�	t
tjd�|�	t
tjd�dSdS)Nr�i��)r�SCHED_RR�sched_get_priority_minr�r�r�r?r}r�r5r)rZpol�lo�hirrr�test_sched_priority.s


�zPosixTester.test_sched_priorityc
Cs�dd�tj��D�}t�d�}|�||�z	t�t���}Wnty7}z
|jtj	kr-�WYd}~nd}~ww|�||�|�
ttjd�|�
ttjd�t�d�}|�|j
t�tj�d�s�zt�d||�t�d|�Wnty�}z
|jtj	kr~�WYd}~nd}~ww|�
ttjd|�|�
ttjd||�|�
ttjd|d�|�
ttjdd�t�d�}|�
ttjd|�d}t�|�}|�
ttjd|�tj|d�}|�
ttjd|�dS)	NcSsg|]\}}|�d�r|�qS)ZSCHED_�r�)r�r7Zschedrrrr�@s
�zDPosixTester.test_get_and_set_scheduler_and_param.<locals>.<listcomp>rrH�r�r��+l���)�sched_priority)r�__dict__r�r	r,rYr0rrr`r5�sched_getparamr�r�r�r}r�r��sched_setscheduler�sched_setparamr6�sched_paramr2)rZpossible_schedulersZmine�parentrZparamZlargerrr�$test_get_and_set_scheduler_and_param>sJ
���
���

z0PosixTester.test_get_and_set_scheduler_and_param�sched_rr_get_intervalzno functionc
Cstzt�d�}Wnty%}z|jtjkr�|�d�WYd}~nd}~ww|�|t�|�|d�|�	|d�dS)Nrz only works on SCHED_RR processesgg�?)
rr�rrr�r�r�rr?�
assertLess)r�intervalrrrr�test_sched_rr_get_intervalgs��z&PosixTester.test_sched_rr_get_intervalcCsht�d�}|�|t�|�t|�d�|�ttjd�|D]}|�|t�|�|d�|�	|d�qdS)Nrr3rHr)
r�sched_getaffinityr�r�r?r>r5rr�r�)r�maskZcpurrr�test_sched_getaffinityvs
�z"PosixTester.test_sched_getaffinitycCs�t�d�}t|�dkr|��t�d|�|�t�d�|�|�ttjdg�|�ttjddg�|�ttjdt	t
d��|�ttjddd>g�|�ttjd|�dS)Nrr3i����Z0X�rH)rr�r>�popr�r=r5rr��mapr�r2)rr�rrr�test_sched_setaffinity�s
z"PosixTester.test_sched_setaffinitycCstjtjtjtjdSr )r�	RTLD_LAZY�RTLD_NOW�RTLD_GLOBAL�
RTLD_LOCALrrrr�test_rtld_constants�s
zPosixTester.test_rtld_constants�	SEEK_HOLEz(test needs an OS that reports file holesc
Cs�ttjd��^}|�d�|��|��}|��}z7t|�D]}|�|t	�
||t	j��|�|t	�
||t	j
��q|�tt	j
||t	j�|�tt	j
||t	j
�Wnty[t�d��wWd�dS1sgwYdS)Nzr+bshellozOSError raised!)rrrrqrr�tellri�ranger=rYr��	SEEK_DATAZassertLessEqualr�r5rr^r_)rrlr�Zfnor�rrr�
test_fs_holes�s 	

��"�zPosixTester.test_fs_holescCs�dD]A}tt|d�}|durqdtjfD]'}z|d|�Wqty;}z|�d�|�t|��WYd}~qCd}~ww|�d|�qdS)zf
        Test functions that call path_error2(), providing two filenames in their exceptions.
        )r��replacer�NZnoodly2Zdoesnotexistfilenamez'doesnotexistfilename' -> '{}'z#No valid path_error2() test for os.)	r4rYrrrr,�formatr@ra)rr7�function�dstrrrr�test_path_error2�s����zPosixTester.test_path_error2c	Cs�tj}|d}|�tj|�t�|�d}z*|�t��t�|tjtj	B�}Wd�n1s0wYW|dur?t�
|�n|durJt�
|�ww|�tj�
|��|�ttj|�|�tj�
|��t|d��
�|�ttj|�dS)N�r)rrr
r!r5r�rYrr�r�rjrr��existsr�r�rr�Zfn_with_NULr�rrr�test_path_with_null_character�s*
��
���z)PosixTester.test_path_with_null_characterc	Cs�t�tj�}|d}|�tj|�t�|�d}z*|�t��t�|tj	tj
B�}Wd�n1s3wYW|durBt�|�n|durMt�|�ww|�tj
�|��|�ttj|�|�tj
�|��t|d���|�ttj|�dS)Nr�r)rYrrrr
r!r5r�rr�r�rjrr�rr�rrrrr�test_path_with_null_byte�s*
��
���z$PosixTester.test_path_with_null_byte�
pidfd_openzpidfd_open unavailablecCs�|�t��
}t�d�Wd�n1swY|jjtjkr&|�d�t|jt	�r5|�d|j���|�
|jjtj�t�t�t�
�d��dS)NrHz"system does not support pidfd_openzpidfd_open syscall blocked: r)r5rrYr
r�rr
r��
isinstancer$r=r�rjr.)rr�rrr�test_pidfd_open�s�
zPosixTester.test_pidfd_open)��__name__�
__module__�__qualname__rr#r8r^�
skipUnlessr
rrArDrKrOrSrTrbrfrmrsrvr4rY�supports_fdr�r�r�r�r�r�r��requires_32br�r�r�r�r�r�r�r�r�r�r�r�r�r�r�r�r�r�rrrZrequires_linux_versionr
rrrrr'rr.r6rBrErGrLrMrOrPrSrXrNr]r`rbrdrhrmZcpython_onlyrprqrzr{r~r�r�r�r�rZr�r�r^�supports_dir_fdr�r�r�rCr�r�r�r�r�r�r�r(r�rr�r�r�r�r��signalr�rJr�r!r�rr�Zrequires_sched_hZrequires_sched_affinityr�r��requires_schedr�r�r�r�r�r�rrr	rrrrrr,s
�
�
�
�
�
�
�
�
�
�



	
<








	�
�
�
�



	
�
	�
�
	�
�
�


�

D
	


�


�





 	
#�
#	
��
�

���
(

�rc@sPeZdZdd�Zdd�Ze�eed�d�dd��Z	e�eed	�d
�dd��Z
d
S)�PosixGroupsTestercCsLt��dkrt�d��ttd�st�d��tjdkrt�d��t��|_dS)Nrznot enough privilegesr-zneed posix.getgroupsr�zgetgroups(2) is broken on OSX)	rr1r^r_r
r}r�r-�saved_groupsrrrrr�s




zPosixGroupsTester.setUpcCsNttd�r
t�|j�dSttd�r%t�t���j}t�||jd�dSdS)N�	setgroupsrUr)	r
rrrrZr[r1r\rU�rr7rrrr#�s

�zPosixGroupsTester.tearDownrUztest needs posix.initgroups()cCsDt|jpdg�d}t�t���j}t�||�|�|t�	��dSrn)
�maxrrZr[rr1r\rUr,r-)rr�r7rrrrbsz!PosixGroupsTester.test_initgroupsrztest needs posix.setgroups()cCs6dgttd��fD]}t�|�|�|t���q	dS)Nr�)r�r�rrZassertListEqualr-)rr�rrr�test_setgroupss
�z PosixGroupsTester.test_setgroupsN)r
rrrr#r^rr
rrbrrrrrr�s	�
�rc@s,eZdZejddddfZdZdd�Zdd	�Zd
d�Z	dd
�Z
dd�Zdd�Zdd�Z
dd�Zdd�Zdd�Zdd�Ze�eed�d�dd��Zd d!�Zd"d#�Ze�eed�d�d$d%��Zd&d'�Zee�ej�d(�d)�d*d+���Zee�ej�d(�d)�d,d-���Z d.d/�Z!d0d1�Z"d2d3�Z#d4d5�Z$d6d7�Z%dS)8�_PosixSpawnMixin�-I�-SryrzNcGstjddg|�RS)Nrr)r}r~�r�argsrrr�python_argssz_PosixSpawnMixin.python_argscCs�tj}|�tj|�d|�d�}|�d|�}|�|d|tj�}tj	|dd�t
|dd��}|�|��t
|��Wd�dS1sCwYdS)N�2if 1:
            import os
            with open(zO, "w") as pidfile:
                pidfile.write(str(os.getpid()))
            ryrr{r�r�)rrr
r!r"�
spawn_funcrYr�rr�rr=r�r@)rZpidfile�scriptr!r�r\rrr�test_returns_pid#s�"�z!_PosixSpawnMixin.test_returns_pidc
Cs�d}z|�||gtj�}Wnttfy)}z|�|j|�WYd}~dSd}~wwt�|d�\}}|�||�|�|d�dS)N�no_such_executabler)	r$rYr��FileNotFoundErrorr$r=�filename�waitpid�assertNotEqual)rr'r��excZpid2�statusrrr�test_no_such_executable1s���z(_PosixSpawnMixin.test_no_such_executablecCs�tj}|�tj|�d|�d�}|�d|�}|�|d|itj�ddi��}tj	|dd�t
|dd	��}|�|��d�Wd�dS1sGwYdS)
Nr#z^, "w", encoding="utf-8") as envfile:
                envfile.write(os.environ['foo'])
        ryrrVZbarr{r�r�)
rrr
r!r"r$rYr�rr�rr=r�)rZenvfiler%r!r�r\rrr�test_specify_environment@s��"�z)_PosixSpawnMixin.test_specify_environmentcCs.|j|jd|jtjdd�}tj|dd�dS�Nr��file_actionsr{�r$�NOOP_PROGRAMrYr�rr��rr�rrr�test_none_file_actionsO��z'_PosixSpawnMixin.test_none_file_actionscCs.|j|jd|jtjgd�}tj|dd�dSr0r3r5rrr�test_empty_file_actionsXr7z(_PosixSpawnMixin.test_empty_file_actionscC�0|jtjtjddgtjdd�}tj|dd�dS)NryrzF�Zresetidsrr{�r$r}r~rYr�rr�r5rrr�test_resetids_explicit_defaulta�
�z/_PosixSpawnMixin.test_resetids_explicit_defaultcCr9)NryrzTr:rr{r;r5rrr�
test_resetidsjr=z_PosixSpawnMixin.test_resetidscCsN|�t��|jtjtjddgtjdd�Wd�dS1s wYdS)Nryrzr:�r5r6r$r}r~rYr�rrrr�test_resetids_wrong_types�
�"�z)_PosixSpawnMixin.test_resetids_wrong_typecCs4|jtjtjddgtjt��d�}tj|dd�dS)Nryrz�Z	setpgrouprr{)r$r}r~rYr�r/rr�r5rrr�test_setpgroupys
�z_PosixSpawnMixin.test_setpgroupcCsN|�t��|jtjtjddgtjdd�Wd�dS1s wYdS)NryrzZ023rBr?rrrr�test_setpgroup_wrong_type�rAz*_PosixSpawnMixin.test_setpgroup_wrong_type�pthread_sigmaskzneed signal.pthread_sigmask()cCs>t�d�}|jtjtjd|gtjtjgd�}t	j
|dd�dS)N�I            import signal
            signal.raise_signal(signal.SIGUSR1)ry�Z
setsigmaskrr{)�textwrap�dedentr$r}r~rYr�r�SIGUSR1rr�)rr�r�rrr�test_setsigmask�s

�z _PosixSpawnMixin.test_setsigmaskcC��|�t��|jtjtjddgtjdd�Wd�n1swY|�t��|jtjtjddgtjdgd�Wd�n1sDwY|�t��|jtjtjddgtjtj	tj	dgd�Wd�dS1sowYdS)Nryrz�"rG�jr3�
r5r6r$r}r~rYr�r�r�NSIGrrrr�test_setsigmask_wrong_type�s(
��
��
��"�z+_PosixSpawnMixin.test_setsigmask_wrong_typec	
Cst��\}}|�tj|�z[t�|d�t�d|�d��}z|jtj	tj	d|gtj
dd�}Wn3tyH}z|�d|���WYd}~nd}~wt
ya}z|�d|���WYd}~nd}~wwWt�|�nt�|�wtj|dd	�t�|d
�}t|�}t�t���}|�||�dS)NTz0
                import os
                fd = z`
                sid = os.getsid(0)
                os.write(fd, str(sid).encode())
            ry)�setsidzsetsid is not supported: zsetsid failed with: rr{r�)rYrer
rj�set_inheritablerHrIr$r}r~r�r�r�r$rr�r�r��getsidr.r+)	rZrfdZwfdr�r�r,�outputZ	child_sidZ
parent_sidrrr�test_setsid�s4
�

�����z_PosixSpawnMixin.test_setsidc
Csvt�tjtj�}t�d�}z|jtjtjd|gtj	tjgd�}Wt�tj|�nt�tj|�wt
j|tjd�dS)NrFry��	setsigdefr{)rrJ�SIG_IGNrHrIr$r}r~rYr�rr�)rZoriginal_handlerr�r�rrr�test_setsigdef�s

� z_PosixSpawnMixin.test_setsigdefcCrL)NryrzrMrWrNr3rOrrrr�test_setsigdef_wrong_type�s$
��
��
�"�z*_PosixSpawnMixin.test_setsigdef_wrong_typer�zbpo-34685: test can fail on BSDcCsft�d�}t�|�}t�d|�d|�d��}|jtjtjd|gtjdt�	|�fd�}t
j|dd�dS�NrzF            import os, sys
            if os.sched_getscheduler(0) != zV:
                sys.exit(101)
            if os.sched_getparam(0).sched_priority != z:
                sys.exit(102)ry)Z	schedulerr{�rYr	r�rHrIr$r}r~r�r�rr��rZpolicy�priorityr�r�rrr�test_setscheduler_only_param��

�
�
�z-_PosixSpawnMixin.test_setscheduler_only_paramcCsft�d�}t�|�}t�d|�d|�d��}|jtjtjd|gtj|t�	|�fd�}t
j|dd�dSr\r]r^rrr�test_setscheduler_with_policy�raz._PosixSpawnMixin.test_setscheduler_with_policycCs\tjdtj�t�tjdftjdftjddfg}|j|j	d|j	tj
|d�}tj|dd�dS)Nr<rr3r�r1r{)
rY�POSIX_SPAWN_OPENr��realpath�__file__r�POSIX_SPAWN_CLOSE�POSIX_SPAWN_DUP2r$r4r�rr�)rr2r�rrr�test_multiple_file_actionss
��z+_PosixSpawnMixin.test_multiple_file_actionsc
CsR|j}|�t��|j|d|tjdgd�Wd�n1s wY|�t��|j|d|tjdgd�Wd�n1sBwY|�t��|j|d|tjdgd�Wd�n1sdwY|�t��|j|d|tjdgd�Wd�n1s�wY|�t��|j|d|tjtjfgd�Wd�n1s�wY|�t��|j|d|tjtjddfgd�Wd�n1s�wY|�t��|j|d|tjtjdfgd�Wd�n1s�wY|�t��|j|d|tjtjdt	d	tj
dfgd�Wd�dS1�s"wYdS)
Nrr1rr )i90r3r�r<r)r4r5r6r$rYr�rfr�rcrerr rrr�test_bad_file_actionssX������������
����$�z&_PosixSpawnMixin.test_bad_file_actionscCs�tj}|�tj|�d}tjd|tjtjBtjBt	j
t	jBfg}|�d|�}|j
|d|tj|d�}tj|dd�t|dd��}|�|��d	�Wd�dS1sSwYdS)
N�Oif 1:
            import sys
            sys.stdout.write("hello")
            r3ryrr1r{r�r��hello)rrr
r!rYrcr�r��O_TRUNCrr"r#r"r$r�rr�rr=r�)rr�r%r2r!r�r\rrr�test_open_file7s 
���"�z_PosixSpawnMixin.test_open_filecCs�tj}|�tj|�d|�d�}|�d|�}|j|d|tjtjdfgd�}t	j
|dd�t|dd��}|�|�
�d	tj�Wd�dS1sJwYdS)
Nz�if 1:
            import os
            try:
                os.fstat(0)
            except OSError as e:
                with open(zq, 'w', encoding='utf-8') as closefile:
                    closefile.write('is closed %d' % e.errno)
            ryrr1r{r�r�zis closed %d)rrr
r!r"r$rYr�rfrr�rr=r�rr�)rZ	closefiler%r!r�r\rrr�test_close_fileKs�
�"�z _PosixSpawnMixin.test_close_filecCs�tj}|�tj|�d}t|d��*}tj|��dfg}|�d|�}|j	|d|tj
|d�}tj|dd�Wd�n1s>wYt|dd	��}|�
|��d
�Wd�dS1s]wYdS)Nrjrr3ryrr1r{r�r�rk)rrr
r!rrYrgrir"r$r�rr�r=r�)rZdupfiler%Z	childfiler2r!r�r\rrrr^s���"�z_PosixSpawnMixin.test_dup2)&r
rrr}r~r4r$r"r&r.r/r6r8r<r>r@rCrDr^rr
rrKrQrVrZr[rZskipIfr�r�r`rbrhrirmrnrrrrrrsP					�

�
��r�posix_spawnztest needs os.posix_spawnc@seZdZeedd�ZdS)�TestPosixSpawnroN)r
rrr4rr$rrrrrpqsrp�posix_spawnpztest needs os.posix_spawnpc@s&eZdZeedd�Zejdd��ZdS)�TestPosixSpawnPrqNcCs�t��}|�tj|�d}tj�||�}t�t	j
|�z
tj�|tjdf�}Wnt
y3|}Ynw|ddddf}t�d|f�}d|f}t|d|i�dS)Nzposix_spawnp_test_program.exe�PATHrrryrzz�
            import os
            from test import support

            args = %a
            pid = os.posix_spawnp(args[0], args, os.environ)

            support.wait_process(pid, exitcode=0)
        )�tempfile�mkdtempr
rr�rYr�r!rJr}r~�pathsepr�r]rHrIr)r�temp_dirZprogramZprogram_fullpathr�Z
spawn_argsr�r!rrr�test_posix_spawnpzs ��
z!TestPosixSpawnP.test_posix_spawnp)	r
rrr4rr$rZskip_unless_symlinkrxrrrrrrvsrrr�ztest weak linking on macOSc@s�eZdZdd�Zdd�Zdd�Zdd�Zd	d
�Zdd�Zd
d�Z	dd�Z
dd�Zdd�Zdd�Z
dd�Zdd�Zdd�Zdd�Zdd �Zd!S)"�TestPosixWeaklinkingcsRddl}ddl}|����fdd��D�|_tdd�|��d�d�D��|_dS)Nrcs"h|]
}|�d�r�|r|�qS)ZHAVE_r�)r�Znm�Zconfig_varsrr�	<setcomp>�s"z-TestPosixWeaklinking.setUp.<locals>.<setcomp>csr�r r�)r��partrrrr��r�z-TestPosixWeaklinking.setUp.<locals>.<genexpr>rY)r�r�Zget_config_vars�	availabler��mac_verr�)rr�r�rrzrr�s
&zTestPosixWeaklinking.setUpcCs||jvr
t�|�d���dS)Nz not weak-linked)r}r^r_rrrr�_verify_available�s
�z&TestPosixWeaklinking._verify_availablecCsd|�d�|jdkr|�ttd�d�|�ttd�d�dS|�ttd�d�|�ttd�d�dS)	NZHAVE_PWRITEV)r�rr�zos.pwritev is not availabler�zos.readv is not availablezos.pwritev is availablezos.readv is available)rr~rdr
rYrrrrrr��s

z!TestPosixWeaklinking.test_pwritevcC�t|�d�|jdkr|�dtj�dS|�dtj�|�td��tj	ddd�Wd�dS1s3wYdS)NZHAVE_FSTATAT�r�r��dir_fd unavailable�filerr�)
rr~r,r�_have_functions�assertNotInrr�rYrrrrrr��

"�zTestPosixWeaklinking.test_statcCs�|�d�|jdkr|�dtj�dS|�dtj�|�td��tj	dtj
dd�Wd�n1s4wY|�td��tj	dtj
dd	�Wd�n1sSwY|�td
��tj	dtj
dd�Wd�dS1sswYdS)
NZHAVE_FACCESSATr�r�r�rr�zfollow_symlinks unavailableFr�zeffective_ids unavailableT)Z
effective_ids)rr~r,rr�r�rr�rYr^r_rrrrr`�s

��"�z TestPosixWeaklinking.test_accesscCs�|�d�|jdkr|�dtj�dS|�dtj�|�dtj�|�td��tj	dddd�Wd�dS1s;wYdS)	NZ
HAVE_FCHMODATr�ZHAVE_LCHMODr�r�i�rr�)
rr~r,rr�r�rr�rYr�rrrr�
test_chmod�s

"�zTestPosixWeaklinking.test_chmodcCs�|�d�|jdkr|�dtj�dS|�dtj�|�dtj�|�td��tj	ddddd�Wd�dS1s<wYdS)NZ
HAVE_FCHOWNATr�ZHAVE_LCHOWNr�r�rr�)
rr~r,rr�r�rr�rYrCrrrrrE�s

"�zTestPosixWeaklinking.test_chownc	Cs|�d�|jdkr|�dtj�dS|�dtj�|�td��tj	dddd�Wd�n1s3wY|�td��tj	dddd	�Wd�n1sQwY|�td��tj	ddddd
�Wd�n1spwYt
����}tj�
|d�}tj�
|d�}tj�
|d�}t|d��
}|�d
�Wd�n1s�wYt�d|�|�t��tj	||dd�Wd�n1s�wY|�t��tj	||dd�Wd�n1s�wYWd�dSWd�dS1s�wYdS)NZHAVE_LINKATr�zsrc_dir_fd unavailable�source�targetr�r�zdst_dir_fd unavailable�r�r�r�ru�dataTr�F)rr~r,rr�r�rr�rYr�rrwr�r!rrqrJr5�FileExistsError)rr�Z	link_pathZtarget_path�source_pathrlrrr�	test_link�s<

���
����"�zTestPosixWeaklinking.test_linkcCs�|�d�|jdkr|�dtj�dS|�dtj�|�td��
t�	d�Wd�n1s0wY|�td��t�
d�Wd�dS1sLwYdS)NZHAVE_FDOPENDIRr�zClistdir: path should be string, bytes, os.PathLike or None, not intrzCscandir: path should be string, bytes, os.PathLike or None, not int)rr~r,rr�r�rr6rYrN�scandirrrrr�test_listdir_scandirs

�"�z)TestPosixWeaklinking.test_listdir_scandircCr�)NZHAVE_MKDIRATr�r�r�rr�)
rr~r,rr�r�rr�rYr�rrrr�
test_mkdir!r�zTestPosixWeaklinking.test_mkdircCs*|�d�|jdkr|�dtj�dS|�dtj�|�td��tj	dddd�Wd�n1s3wY|�td��tj	dddd�Wd�n1sQwY|�td��tj
dddd�Wd�n1sowY|�td��tj
dddd�Wd�dS1s�wYdS)	NZ
HAVE_RENAMEATr�z%src_dir_fd and dst_dir_fd unavailabler�r�rr�r�)rr~r,rr�r�rr�rYr�rrrrr�test_rename_replace,s 

���"�z(TestPosixWeaklinking.test_rename_replacecCs�|�d�|jdkr|�dtj�dS|�dtj�|�td��tj	ddd�Wd�n1s2wY|�td��tj
ddd�Wd�dS1sPwYdS)NZ
HAVE_UNLINKATr�r�r�rr�)rr~r,rr�r�rr�rYr!�rmdirrrrr�test_unlink_rmdir@s

�"�z&TestPosixWeaklinking.test_unlink_rmdircCsx|�d�|jdkr|�dtj�dS|�dtj�|�td��tj	dtj
dd�Wd�dS1s5wYdS)NZHAVE_OPENATr�r�r�rr�)rr~r,rr�r�rr�rYrrrrrr�	test_openNs

"�zTestPosixWeaklinking.test_opencCr�)NZHAVE_READLINKATr�r�r�rr�)
rr~r,rr�r�rr�rYr�rrrr�
test_readlinkYr�z"TestPosixWeaklinking.test_readlinkcCsv|�d�|jdkr|�dtj�dS|�dtj�|�td��tj	dddd�Wd�dS1s4wYdS)NZHAVE_SYMLINKATr�r�r�r�rr�)
rr~r,rr�r�rr�rYrJrrrr�test_symlinkds

"�z!TestPosixWeaklinking.test_symlinkcCs�|�d�|�d�|jdkr|�dtj�|�dtj�dS|�dtj�|�dtj�|�td��tj	ddd�Wd�dS1sFwYdS)NZ
HAVE_FUTIMENSZHAVE_UTIMENSAT)r�rWr�r�rr�)
rr~r,rr�r�rr�rYr�rrrrrqos


"�zTestPosixWeaklinking.test_utimeN)r
rrrrr�rr`r�rEr�r�r�r�r�r�r�r�rqrrrrry�s"
'rycCr�r )r�
reap_childrenrrrr�tearDownModule~sr��__main__),�__doc__rprZtest.supportrrrZtest.support.script_helperr�
import_modulerrr}rr�rYr�rZrrtr^rrHr�r!�
gettempdirrrKr�maxsizerrrZTestCaserrrr
rprrryr�r
�mainrrrr�<module>sl
��
Q$]$c�
© 2025 GrazzMean