관리-도구
편집 파일: test_process.cpython-38.pyc
U �Mgn� � @ s d Z ddlZddlZddlZddlZddlZddlZddlZddlZddl Z ddl Z ddlZddlZddl Z ddlZddlZddlmZ ddlmZ ddlmZ ddlmZ ddlmZ ddlmZ dd lmZ dd lmZ ddlmZ ddlmZ dd lmZ ddlmZ ddlmZ ddlmZ ddlm Z ddlm!Z! ddl"m#Z# ddl"m$Z$ ddl"m%Z% ddl"m&Z& ddl"m'Z' ddl"m(Z( ddl"m)Z) ddl"m*Z* ddl"m+Z+ ddl"m,Z, ddl"m-Z- ddl"m.Z. ddl"m/Z/ dd l"m0Z0 dd!l"m1Z1 dd"l"m2Z2 dd#l"m3Z3 dd$l"m4Z4 dd%l"m5Z5 dd&l"m6Z6 dd'l"m7Z7 dd(l"m8Z8 dd)l"m9Z9 dd*l"m:Z: dd+l"m;Z; dd,l"m<Z< dd-l"m=Z= dd.l"m>Z> dd/l"m?Z? dd0l"m@Z@ dd1l"mAZA dd2l"mBZB G d3d4� d4e4�ZCe�r�e�D� dk�r�G d5d6� d6eC�ZEG d7d8� d8e4�ZFdS )9�Tests for psutil.Process class.� N)�AIX)�BSD)�LINUX)�MACOS)�NETBSD)�OPENBSD)�OSX)�POSIX)�SUNOS)�WINDOWS)� open_text)�PY3)�FileNotFoundError)�long)�redirect_stderr)�super)�APPVEYOR)� CI_TESTING)�GITHUB_ACTIONS)�GLOBAL_TIMEOUT)�HAS_CPU_AFFINITY)�HAS_ENVIRON)� HAS_IONICE)�HAS_MEMORY_MAPS)�HAS_PROC_CPU_NUM)�HAS_PROC_IO_COUNTERS)� HAS_RLIMIT)�HAS_THREADS)�MACOS_11PLUS)�PYPY)� PYTHON_EXE)�PYTHON_EXE_ENV)� QEMU_USER)�PsutilTestCase)� ThreadTask)� call_until)�copyload_shared_lib)�create_c_exe)� create_py_exe)�mock)�process_namespace)�pytest�� reap_children)�retry_on_failure)�sh)�skip_on_access_denied)�skip_on_not_implemented)�wait_for_pidc @ s e Zd ZdZdd� Zdd� Zdd� Zdd � Zd d� Ze j je dd �dd� �Z dd� Ze j jedd �dd� �Zdd� Zdd� Zdd� Zdd� Zdd� Ze j jedd �d d!� �Ze j jedd �d"d#� �Ze j je d$d �d%d&� �Zd'd(� Ze j je d)d �d*d+� �Ze j je d$d �eed,�d-d.� ��Z e j je! d$d �e j je d/d �d0d1� ��Z"e j je! d$d �e j je# d2d �d3d4� ��Z$e j je% d$d �d5d6� �Z&e j je% d$d �d7d8� �Z'e j je% d$d �d9d:� �Z(e j je% d$d �d;d<� �Z)e j je% d$d �d=d>� �Z*d?d@� Z+e j je# dAd �dBdC� �Z,e j je- d$d �dDdE� �Z.e/� e0e1d,�e j je- d$d �dFdG� ���Z2e/� dHdI� �Z3dJdK� Z4e j je5 d$d �dLdM� �Z6e j je5 d$d �dNdO� �Z7dPdQ� Z8dRdS� Z9e j jedd �dTdU� �Z:dVdW� Z;e j je<dXd �dYdZ� �Z=d[d\� Z>e j je<�ped]d �e j jed^d �d_d`� ��Z?e j je@dad �e j jeAdbd �e j je<dXd �e j jedcd �ddde� ����ZBe j je d)d �dfdg� �ZCe j je d)d �dhdi� �ZDdjdk� ZEe j jedd �dldm� �ZFdndo� ZGdpdq� ZHdrds� ZIe j jeJ d$d �dtdu� �ZKe j jeJ d$d �dvdw� �ZLe j jeJ d$d �dxdy� �ZMe j jeNdzd �e j jeOd{d �d|d}� ��ZPe j jeNdzd �e j jeOd{d �d~d� ��ZQe j je d)d �d�d�� �ZReed,�e j jeS�p�ed�d �d�d�� ��ZTd�d�� ZUd�d�� ZVd�d�� ZWe j jedd �e/� d�d�� ��ZXd�d�� ZYd�d�� ZZd�d�� Z[d�d�� Z\d�d�� Z]d�d�� Z^d�d�� Z_d�d�� Z`d�d�� Zad�d�� Zbd�d�� Zce j je d)d �d�d�� �Zde j je d)d �d�d�� �Zee j je d)d �d�d�� �Zfd�d�� Zgd�d�� Zhe j jei d$d �d�d�� �Zje j jei d$d �e j je d)d �e j jekd�d �e j jed�d �d�d�� ����Zld�S )��TestProcessr c O sD | j ||�}zt�|j�W S tjk r> | �|j� � Y nX d S �N)�spawn_testproc�psutil�Process�pid� NoSuchProcessZ assertPidGone)�self�args�kwargs�sproc� r? �I/opt/hc_python/lib64/python3.8/site-packages/psutil/tests/test_process.py�spawn_psprocS s zTestProcess.spawn_psprocc C s: t �� }|jt�� kst�t�t�� d|_W 5 Q R X d S )N�! ) r7 r8 r9 �os�getpid�AssertionErrorr, �raises�AttributeError�r; �pr? r? r@ �test_pid] s zTestProcess.test_pidc C sJ | � � }|�� |�� }tr,|tjks<t�n|tj ks<t�| �|� d S r5 ) rA �kill�waitr �signal�SIGTERMrE �SIGKILL�assertProcessGone�r; rI �coder? r? r@ � test_killc s zTestProcess.test_killc C sJ | � � }|�� |�� }tr,|tjks<t�n|tj ks<t�| �|� d S r5 )rA � terminaterL r rM rN rE rP rQ r? r? r@ �test_terminatem s zTestProcess.test_terminatec C sX t r tjntj}| �� }|�|� |�� }tr<||ksJt�n|| ksJt�| � |� d S r5 ) r rM rO rN rA �send_signalrL r rE rP )r; �sigrI rR r? r? r@ �test_send_signalw s zTestProcess.test_send_signalz not POSIX��reasonc C s� t j}| �� }tjdttjd�d��( t� t j�� |�|� W 5 Q R X W 5 Q R X | �� }tjdttj d�d��( t� t j�� |�|� W 5 Q R X W 5 Q R X d S )Nzpsutil.os.kill� ��side_effect)rM rN rA r* �patch�OSError�errnoZESRCHr, rF r7 r: rV �EPERM�AccessDenied)r; rW rI r? r? r@ �test_send_signal_mocked� s � �z#TestProcess.test_send_signal_mockedc C s� t ddg}| �|�}|�� }|dks(t�| �|� t ddg}| j|tjd�}|�� }|dks`t�| �|� t ddg}| �|�}|�� }|dks�t�| �|� t dd g}| �|�}|�� }|dks�t�| �|� d S ) N�-c�passr z1 / 0)�stderr� zimport sys; sys.exit(5);� zimport os; os._exit(5);)r! rA rL rE rP � subprocess�PIPE)r; �cmdrI rR r? r? r@ �test_wait_exited� s( zTestProcess.test_wait_exitedzfails on NETBSDc C s. | � � }tr�|�tj� t�tj�� |j dd� W 5 Q R X |�tj � t�tj�� |j dd� W 5 Q R X |�tj� |� � tj ks�t�|� � tj ks�t�n�|� � t�tj�� |j dd� W 5 Q R X |�� t�tj�� |j dd� W 5 Q R X |�� |� � tjk�st�|� � tjk�s*t�d S )N���MbP?)�timeout)rA r rV rM �SIGSTOPr, rF r7 �TimeoutExpiredrL �SIGCONTrN rE �suspend�resumerT rH r? r? r@ �test_wait_stopped� s( zTestProcess.test_wait_stoppedc C s� | � � \}}t�tj�� |�d� W 5 Q R X t�tj�� |�d� W 5 Q R X |�� |�� |�� }|�� }tr�|tj ks�t �|d ks�t �n|tj ks�t �|tj ks�t �d S )N�{�G�z�?)�spawn_children_pairr, rF r7 rp rL rT r rM rN rE )r; �child� grandchildZ child_retZgrandchild_retr? r? r@ �test_wait_non_children� s z"TestProcess.test_wait_non_childrenc C sx | � � }|�� t�tj�� |�d� W 5 Q R X t�tj�� |�d� W 5 Q R X t�t�� |�d� W 5 Q R X d S )Nru r ���)rA �namer, rF r7 rp rL � ValueErrorrH r? r? r@ �test_wait_timeout� s zTestProcess.test_wait_timeoutc C s� | � � }t�tj�� |�d� W 5 Q R X |�� t�� t }t�� |k rvz|�d�}W q�W q> tjk rr Y q>X q>| � d��t r�|tj ks�t �n|tjks�t �| �|� d S )Nr rn )rA r, rF r7 rp rL rK �timer �failr rM rO rE rN rP )r; rI Zstop_atrR r? r? r@ �test_wait_timeout_nonblocking� s z)TestProcess.test_wait_timeout_nonblockingc C sz t �� }|jdd� |jdd� td�D ]*}|jd d�}t|t�sFt�|dks(t�q(t�t �� |jdd� W 5 Q R X d S )Nrm )�interval�d � rz ) r7 r8 �cpu_percent�range� isinstance�floatrE r, rF r| )r; rI �_�percentr? r? r@ �test_cpu_percent� s zTestProcess.test_cpu_percentc C s4 t jdd d��}t�� �� |js&t�W 5 Q R X d S )Nzpsutil.cpu_count)Zreturn_value)r* r^ r7 r8 r� �calledrE )r; �mr? r? r@ �test_cpu_percent_numcpus_none s z)TestProcess.test_cpu_percent_numcpus_nonezQEMU user not supportedc C s� t �� �� }|jdkst|��|jdks0t|��|jdksBt|��|jdksTt|��trj|j dksjt|��|j D ]}t�dt� t||��� qpd S )Nr� z%H:%M:%S)r7 r8 � cpu_times�userrE �system� children_user�children_systemr Ziowait�_fieldsr~ �strftime� localtime�getattr)r; �timesr{ r? r? r@ �test_cpu_times s zTestProcess.test_cpu_timesc C s� t �� �� d d� \}}t�� d d� \}}t||g�t||g� dkrZ| �d||f ��t||g�t||g� dkr�| �d||f ��d S )N� 皙�����?zexpected: %s, found: %s)r7 r8 r� rC r� �max�minr )r; � user_timeZkernel_time�utimeZktimer? r? r@ �test_cpu_times_2 s zTestProcess.test_cpu_times_2z not supportedc C sP t �� }|�� }|dkst�t �� dkr4|dks4t�|�� tt �� �ksLt�d S �Nr rg )r7 r8 Zcpu_numrE � cpu_countr� )r; rI �numr? r? r@ �test_cpu_num) s zTestProcess.test_cpu_numc C sZ | � � }t�� }|�� }t|| �}|dkr@| �d|||f ��t�dt�|�� �� d S )Nr� z'expected: %s, found: %s, difference: %sz%Y %m %d %H:%M:%S)rA r~ �create_time�absr r� r� )r; rI �nowr� � differencer? r? r@ �test_create_time2 s ��zTestProcess.test_create_timez POSIX onlyc C sX t �� �� }|d k rTztj�td��}W n tk rF t� d��Y nX ||ksTt �d S )N�ttyzcan't rely on `tty` CLI)r7 r8 �terminalrC �path�realpathr0 �RuntimeErrorr, �skiprE )r; r� r� r? r? r@ � test_terminalD s zTestProcess.test_terminal)Zonly_ifc C s� t �� }|�� }ttd��}|�� W 5 Q R X |�� }ts�ts�|j|jksNt �|j |j ks^t �tr�|j|jksrt �|j |j ks�t �n |j|jks�t �|j|jks�t �|�� }t| �� d��.}tr�|�tdd d�� n|�dd � W 5 Q R X |�� }|j |j k�st �|j|jk�st �|j|jk�s,t �|j|jk�s>t �t�rh|j |j k�sVt �|j|jk�sht �tt|��D ]>}t�r�|dk�r��qt|| dk�s�t �|| dk�stt ��qtd S )N�rb�wb�xi@B �asciir� r )r7 r8 Zio_counters�openr! �readr r Z read_countrE Zwrite_countr Z read_charsZwrite_chars� read_bytes�write_bytes� get_testfnr �write�bytesr� �len)r; rI Zio1�fZio2�ir? r? r@ �test_io_countersP s>