HOME


sh-3ll 1.0
DIR:/usr/local/lib64/python3.6/site-packages/psutil/tests/__pycache__/
Upload File :
Current File : //usr/local/lib64/python3.6/site-packages/psutil/tests/__pycache__/test_memleaks.cpython-36.pyc
3

�[g3<�@sdZddlmZddlZddlZddlZddlZddlZddlmZddlm	Z	ddlm
Z
ddlmZddlmZdd	lm
Z
dd
lmZddlmZddlmZdd
lmZddlmZddlmZddlmZddlmZddlmZddlmZddlmZddlmZddlmZddlmZddlmZddlmZddlm Z ddlm!Z!ddlm"Z"ddlm#Z#ddlm$Z$ddlm%Z%dd lm&Z&dd!lm'Z'ej(j)Z)ej*�Z+d"Z,d#d$�Z-Gd%d&�d&e�Z.Gd'd(�d(e.�Z/e#j0j1e
d)d*�Gd+d,�d,e��Z2Gd-d.�d.e�Z3dS)/a�Tests for detecting function memory leaks (typically the ones
implemented in C). It does so by calling a function many times and
checking whether process memory usage keeps increasing between
calls or over time.
Note that this may produce false positives (especially on Windows
for some reason).
PyPy appears to be completely unstable for this framework, probably
because of how its JIT handles memory, so tests are skipped.
�)�print_functionN)�LINUX)�MACOS)�OPENBSD)�POSIX)�SUNOS)�WINDOWS)�ProcessLookupError)�super)�HAS_CPU_AFFINITY)�HAS_CPU_FREQ)�HAS_ENVIRON)�
HAS_IONICE)�HAS_MEMORY_MAPS)�HAS_NET_IO_COUNTERS)�HAS_PROC_CPU_NUM)�HAS_PROC_IO_COUNTERS)�
HAS_RLIMIT)�HAS_SENSORS_BATTERY)�HAS_SENSORS_FANS)�HAS_SENSORS_TEMPERATURES)�	QEMU_USER)�TestMemoryLeak)�create_sockets)�
get_testfn)�process_namespace)�pytest)�skip_on_access_denied)�spawn_testproc)�system_namespace)�	terminate�cCsdd�}|S)zsDecorator for those Linux functions which are implemented in pure
    Python, and which we want to run faster.
    cstj���fdd��}|S)NcsFtr2|jj}zt|j_�|f|�|�S||j_Xn�|f|�|�SdS)N)r�	__class__�times�	FEW_TIMES)�self�args�kwargs�before)�fun��F/usr/local/lib64/python3.6/site-packages/psutil/tests/test_memleaks.py�wrapperDsz5fewtimes_if_linux.<locals>.decorator.<locals>.wrapper)�	functools�wraps)r)r,r*)r)r+�	decoratorCsz$fewtimes_if_linux.<locals>.decoratorr*)r/r*r*r+�fewtimes_if_linux>sr0c@s0eZdZdZeZdd�Ze�dd��Ze�dd��Z	e�dd	��Z
e�d
d��Zej
jedd
�e�dd���Zej
jedd
�e�dd���Ze�dd��Zdd�Zdd�Zej
jedd
�dd��Zej
jedd
�dd��Zej
jedd
�e�dd���Zej
jedd
�d d!��Ze�d"d#��Ze�eed$�d%d&���Zej
jed'd
�d(d)��Z ej
jedd
�e�d*d+���Z!e�d,d-��Z"e�eed$�d.d/���Z#e�d0d1��Z$e�ej
je%dd
�d2d3���Z&e�d4d5��Z'e�d6d7��Z(ej
jedd
�e�d8d9���Z)d:d;�Z*e�d<d=��Z+ej
je,dd
�d>d?��Z-ej
je,dd
�d@dA��Z.e�dBdC��Z/ej
je0dd
�e�dDdE���Z1ej
je2dFd
�ej
je3dd
�dGdH���Z4ej
je2dFd
�ej
je3dd
�dIdJ���Z5e�ej
jedKd
�dLdM���Z6ej
je7dd
�dNdO��Z8ej
jed'd
�dPdQ��Z9dRS)S�TestProcessObjectLeaksz$Test leaks of Process class methods.cCs td�}|j||j|j�dS)N)r�test_class_coverageZgettersZsetters)r%�nsr*r*r+�
test_coverage_sz$TestProcessObjectLeaks.test_coveragecCs|j|jj�dS)N)�execute�proc�name)r%r*r*r+�	test_namecsz TestProcessObjectLeaks.test_namecCs|j|jj�dS)N)r5r6�cmdline)r%r*r*r+�test_cmdlinegsz#TestProcessObjectLeaks.test_cmdlinecCs|j|jj�dS)N)r5r6Zexe)r%r*r*r+�test_exekszTestProcessObjectLeaks.test_execCs|j|jj�dS)N)r5r6�ppid)r%r*r*r+�	test_ppidosz TestProcessObjectLeaks.test_ppidz
POSIX only)�reasoncCs|j|jj�dS)N)r5r6Zuids)r%r*r*r+�	test_uidsssz TestProcessObjectLeaks.test_uidscCs|j|jj�dS)N)r5r6Zgids)r%r*r*r+�	test_gidsxsz TestProcessObjectLeaks.test_gidscCs|j|jj�dS)N)r5r6�status)r%r*r*r+�test_status}sz"TestProcessObjectLeaks.test_statuscCs|j|jj�dS)N)r5r6�nice)r%r*r*r+�	test_nice�sz TestProcessObjectLeaks.test_nicecs tj���j��fdd��dS)Ncs�jj��S)N)r6rCr*)�nicenessr%r*r+�<lambda>�sz6TestProcessObjectLeaks.test_nice_set.<locals>.<lambda>)�thisprocrCr5)r%r*)rEr%r+�
test_nice_set�sz$TestProcessObjectLeaks.test_nice_setz
not supportedcCs|j|jj�dS)N)r5r6�ionice)r%r*r*r+�test_ionice�sz"TestProcessObjectLeaks.test_ionicecsZtr"tj���j��fdd��n4�j�fdd��tjtjtj	�dd�}�j
t|�dS)Ncs�jj��S)N)r6rIr*)r%�valuer*r+rF�sz8TestProcessObjectLeaks.test_ionice_set.<locals>.<lambda>cs�jjtj�S)N)r6rI�psutilZIOPRIO_CLASS_NONEr*)r%r*r+rF�s�r���)rrGrIr5r-�partial�cextZproc_ioprio_set�os�getpid�
execute_w_exc�OSError)r%r)r*)r%rKr+�test_ionice_set�sz&TestProcessObjectLeaks.test_ionice_setcCs|j|jj�dS)N)r5r6Zio_counters)r%r*r*r+�test_io_counters�sz'TestProcessObjectLeaks.test_io_counterszworthless on POSIXcCstj�j�|j|jj�dS)N)rL�Process�usernamer5r6)r%r*r*r+�
test_username�sz$TestProcessObjectLeaks.test_usernamecCs|j|jj�dS)N)r5r6Zcreate_time)r%r*r*r+�test_create_time�sz'TestProcessObjectLeaks.test_create_time)Zonly_ifcCs|j|jj�dS)N)r5r6Znum_threads)r%r*r*r+�test_num_threads�sz'TestProcessObjectLeaks.test_num_threadszWINDOWS onlycCs|j|jj�dS)N)r5r6Znum_handles)r%r*r*r+�test_num_handles�sz'TestProcessObjectLeaks.test_num_handlescCs|j|jj�dS)N)r5r6Znum_fds)r%r*r*r+�test_num_fds�sz#TestProcessObjectLeaks.test_num_fdscCs|j|jj�dS)N)r5r6Znum_ctx_switches)r%r*r*r+�test_num_ctx_switches�sz,TestProcessObjectLeaks.test_num_ctx_switchescCs|j|jj�dS)N)r5r6�threads)r%r*r*r+�test_threads�sz#TestProcessObjectLeaks.test_threadscCs|j|jj�dS)N)r5r6�	cpu_times)r%r*r*r+�test_cpu_times�sz%TestProcessObjectLeaks.test_cpu_timescCs|j|jj�dS)N)r5r6Zcpu_num)r%r*r*r+�test_cpu_num�sz#TestProcessObjectLeaks.test_cpu_numcCs|j|jj�dS)N)r5r6Zmemory_info)r%r*r*r+�test_memory_info�sz'TestProcessObjectLeaks.test_memory_infocCs|j|jj�dS)N)r5r6Zmemory_full_info)r%r*r*r+�test_memory_full_info�sz,TestProcessObjectLeaks.test_memory_full_infocCs|j|jj�dS)N)r5r6�terminal)r%r*r*r+�
test_terminal�sz$TestProcessObjectLeaks.test_terminalcCs$trtn|j}|j|jj|d�dS)N)r#)rr$r#r5r6�resume)r%r#r*r*r+�test_resume�sz"TestProcessObjectLeaks.test_resumecCs|j|jj�dS)N)r5r6�cwd)r%r*r*r+�test_cwd�szTestProcessObjectLeaks.test_cwdcCs|j|jj�dS)N)r5r6�cpu_affinity)r%r*r*r+�test_cpu_affinity�sz(TestProcessObjectLeaks.test_cpu_affinitycs4tj���j��fdd���jt�fdd��dS)Ncs�jj��S)N)r6rlr*)�affinityr%r*r+rF�sz>TestProcessObjectLeaks.test_cpu_affinity_set.<locals>.<lambda>cs�jjdg�S)NrMrN)r6rlr*)r%r*r+rF�s)rGrlr5rS�
ValueError)r%r*)rnr%r+�test_cpu_affinity_set�sz,TestProcessObjectLeaks.test_cpu_affinity_setc	Cs*tt�d��|j|jj�WdQRXdS)N�w)�openrr5r6Z
open_files)r%r*r*r+�test_open_files�sz&TestProcessObjectLeaks.test_open_filescCs|j|jj�dS)N)r5r6Zmemory_maps)r%r*r*r+�test_memory_maps�sz'TestProcessObjectLeaks.test_memory_mapsz
LINUX onlycs�j�fdd��dS)Ncs�jjtj�S)N)r6�rlimitrL�
RLIMIT_NOFILEr*)r%r*r+rF�sz4TestProcessObjectLeaks.test_rlimit.<locals>.<lambda>)r5)r%r*)r%r+�test_rlimit�sz"TestProcessObjectLeaks.test_rlimitcs<tjtj���j��fdd���jttf�fdd��dS)Ncs�jjtj��S)N)r6rurLrvr*)�limitr%r*r+rF�sz8TestProcessObjectLeaks.test_rlimit_set.<locals>.<lambda>cs�jjd�S)NrMrN)r6rur*)r%r*r+rF�s)rGrurLrvr5rSrTro)r%r*)rxr%r+�test_rlimit_set�sz&TestProcessObjectLeaks.test_rlimit_setzworthless on WINDOWScs6t��&trdnd��j��fdd��WdQRXdS)N�inet�allcs�jj��S)N)r6�net_connectionsr*)�kindr%r*r+rFsz=TestProcessObjectLeaks.test_net_connections.<locals>.<lambda>)rrr5)r%r*)r}r%r+�test_net_connections�sz+TestProcessObjectLeaks.test_net_connectionscCs|j|jj�dS)N)r5r6�environ)r%r*r*r+�test_environsz#TestProcessObjectLeaks.test_environcCs|jdd��dS)NcSstjtj��S)N)rP�	proc_inforQrRr*r*r*r+rFsz7TestProcessObjectLeaks.test_proc_info.<locals>.<lambda>)r5)r%r*r*r+�test_proc_info
sz%TestProcessObjectLeaks.test_proc_infoN):�__name__�
__module__�__qualname__�__doc__rGr6r4r0r8r:r;r=r�mark�skipifrr?r@rBrDrHrrJrUrrVrYrZrrr[rr\r]r^r`rbrrcrdrergrirkrrmrprsrrtrrrwryr~r
r�r�r*r*r*r+r1Zsd
	r1cspeZdZdZe�fdd��Ze�fdd��Zdd�Zerhdd	�Z	d
d�Z
dd
�Zdd�Zdd�Z
dd�Z�ZS)�TestTerminatedProcessLeaksz�Repeat the tests above looking for leaks occurring when dealing
    with terminated processes raising NoSuchProcess exception.
    The C functions are still invoked but will follow different code
    paths. We'll check those code paths.
    cs:t�j�t�|_tj|jj�|_|jj�|jj	�dS)N)
r
�
setUpClassr�subprLrW�pidr6�kill�wait)�cls)r"r*r+r�s


z%TestTerminatedProcessLeaks.setUpClasscst�j�t|j�dS)N)r
�
tearDownClassr r�)r�)r"r*r+r�s
z(TestTerminatedProcessLeaks.tearDownClasscCs&y
|�Wntjk
r YnXdS)N)rL�
NoSuchProcess)r%r)r*r*r+�call#s
zTestTerminatedProcessLeaks.callcCs|j|jj�dS)N)r5r6r�)r%r*r*r+�	test_kill+sz$TestTerminatedProcessLeaks.test_killcCs|j|jj�dS)N)r5r6r )r%r*r*r+�test_terminate.sz)TestTerminatedProcessLeaks.test_terminatecCs|j|jj�dS)N)r5r6Zsuspend)r%r*r*r+�test_suspend1sz'TestTerminatedProcessLeaks.test_suspendcCs|j|jj�dS)N)r5r6rh)r%r*r*r+ri4sz&TestTerminatedProcessLeaks.test_resumecCs|j|jj�dS)N)r5r6r�)r%r*r*r+�	test_wait7sz$TestTerminatedProcessLeaks.test_waitcs�fdd�}�j|�dS)Ncs(ytj�jj�Stk
r"YnXdS)N)rPr�r6r�r	r*)r%r*r+r�<sz7TestTerminatedProcessLeaks.test_proc_info.<locals>.call)r5)r%r�r*)r%r+r�:sz)TestTerminatedProcessLeaks.test_proc_info)r�r�r�r��classmethodr�r�r�rr�r�r�rir�r��
__classcell__r*r*)r"r+r�sr�zWINDOWS only)r>c@seZdZdd�Zdd�ZdS)�TestProcessDualImplementationcCs|jdd��dS)NcSstjtj�dd�S)NT)�use_peb)rP�proc_cmdlinerQrRr*r*r*r+rFHszETestProcessDualImplementation.test_cmdline_peb_true.<locals>.<lambda>)r5)r%r*r*r+�test_cmdline_peb_trueGsz3TestProcessDualImplementation.test_cmdline_peb_truecCs|jdd��dS)NcSstjtj�dd�S)NF)r�)rPr�rQrRr*r*r*r+rFKszFTestProcessDualImplementation.test_cmdline_peb_false.<locals>.<lambda>)r5)r%r*r*r+�test_cmdline_peb_falseJsz4TestProcessDualImplementation.test_cmdline_peb_falseN)r�r�r�r�r�r*r*r*r+r�Esr�c@sPeZdZdZdd�Ze�dd��Ze�dd��Ze�dd	��Ze�d
d��Z	e�dd
��Z
e�ejj
eorej�dkdd�ejj
edd�dd����Zejj
edd�dd��Zdd�Zejj
edd�dd��Zdd�Zdd�Zejj
ed d�d!d"��Zejj
e�oejjd#�d$d�e�d%d&���Z e�d'd(��Z!e�ejj
e"dd�d)d*���Z#e�ejj
e�onej$�d+kd,d�d-d.���Z%d/d0�Z&ejj
ed d�d1d2��Z'e�ejj
e(dd�d3d4���Z)e�ejj
e*dd�d5d6���Z+e�ejj
e,dd�d7d8���Z-e�d9d:��Z.d;d<�Z/d=d>�Z0e�rLd?d@�Z1dAdB�Z2dCdD�Z3dEdF�Z4dGdH�Z5dIS)J�TestModuleFunctionsLeaksz&Test leaks of psutil module functions.cCst�}|j||j�dS)N)rr2r{)r%r3r*r*r+r4Vsz&TestModuleFunctionsLeaks.test_coveragecCs|jdd��dS)NcSstjdd�S)NT)�logical)rL�	cpu_countr*r*r*r+rF^sz9TestModuleFunctionsLeaks.test_cpu_count.<locals>.<lambda>)r5)r%r*r*r+�test_cpu_count\sz'TestModuleFunctionsLeaks.test_cpu_countcCs|jdd��dS)NcSstjdd�S)NF)r�)rLr�r*r*r*r+rFbsz?TestModuleFunctionsLeaks.test_cpu_count_cores.<locals>.<lambda>)r5)r%r*r*r+�test_cpu_count_cores`sz-TestModuleFunctionsLeaks.test_cpu_count_corescCs|jtj�dS)N)r5rLra)r%r*r*r+rbdsz'TestModuleFunctionsLeaks.test_cpu_timescCs|jdd��dS)NcSstjdd�S)NT)Zpercpu)rLrar*r*r*r+rFjsz=TestModuleFunctionsLeaks.test_per_cpu_times.<locals>.<lambda>)r5)r%r*r*r+�test_per_cpu_timeshsz+TestModuleFunctionsLeaks.test_per_cpu_timescCs|jtj�dS)N)r5rLZ	cpu_stats)r%r*r*r+�test_cpu_statslsz'TestModuleFunctionsLeaks.test_cpu_statsZarm64zskipped due to #1892)r>z
not supportedcCs|jtj�dS)N)r5rLZcpu_freq)r%r*r*r+�
test_cpu_freqpsz&TestModuleFunctionsLeaks.test_cpu_freqzWINDOWS onlycCstj�|jtj�dS)N)rL�
getloadavgr5)r%r*r*r+�test_getloadavgysz(TestModuleFunctionsLeaks.test_getloadavgcCs|jtj�dS)N)r5rLZvirtual_memory)r%r*r*r+�test_virtual_memory�sz,TestModuleFunctionsLeaks.test_virtual_memoryz&worthless on SUNOS (uses a subprocess)cCs|jtj�dS)N)r5rLZswap_memory)r%r*r*r+�test_swap_memory�sz)TestModuleFunctionsLeaks.test_swap_memorycCs$trtn|j}|jdd�|d�dS)NcSstjtj��S)N)rLZ
pid_existsrQrRr*r*r*r+rF�sz:TestModuleFunctionsLeaks.test_pid_exists.<locals>.<lambda>)r#)rr$r#r5)r%r#r*r*r+�test_pid_exists�sz(TestModuleFunctionsLeaks.test_pid_existscCs$trtn|j}|jdd�|d�dS)NcSs
tjd�S)N�.)rL�
disk_usager*r*r*r+rF�sz:TestModuleFunctionsLeaks.test_disk_usage.<locals>.<lambda>)r#)rr$r#r5)r%r#r*r*r+�test_disk_usage�sz(TestModuleFunctionsLeaks.test_disk_usagezQEMU user not supportedcCs|jtj�dS)N)r5rLZdisk_partitions)r%r*r*r+�test_disk_partitions�sz-TestModuleFunctionsLeaks.test_disk_partitionsz/proc/diskstatsz3/proc/diskstats not available on this Linux versioncCs|jdd��dS)NcSstjdd�S)NF)�nowrap)rLZdisk_io_countersr*r*r*r+rF�sz@TestModuleFunctionsLeaks.test_disk_io_counters.<locals>.<lambda>)r5)r%r*r*r+�test_disk_io_counters�sz.TestModuleFunctionsLeaks.test_disk_io_counterscCs|jtj�dS)N)r5rLZpids)r%r*r*r+�	test_pids�sz"TestModuleFunctionsLeaks.test_pidscCs|jdd��dS)NcSstjdd�S)NF)r�)rLZnet_io_countersr*r*r*r+rF�sz?TestModuleFunctionsLeaks.test_net_io_counters.<locals>.<lambda>)r5)r%r*r*r+�test_net_io_counters�sz-TestModuleFunctionsLeaks.test_net_io_countersrzneed root accessc
Cs0tjdd�t��|jdd��WdQRXdS)Nr{)r}cSstjdd�S)Nr{)r})rLr|r*r*r*r+rF�sz?TestModuleFunctionsLeaks.test_net_connections.<locals>.<lambda>)rLr|rr5)r%r*r*r+r~�sz-TestModuleFunctionsLeaks.test_net_connectionscCs"trdn|j}|jtj|d�dS)N�Pi)�	tolerancei@)rr�r5rLZnet_if_addrs)r%r�r*r*r+�test_net_if_addrs�sz*TestModuleFunctionsLeaks.test_net_if_addrscCs|jtj�dS)N)r5rLZnet_if_stats)r%r*r*r+�test_net_if_stats�sz*TestModuleFunctionsLeaks.test_net_if_statscCs|jtj�dS)N)r5rLZsensors_battery)r%r*r*r+�test_sensors_battery�sz-TestModuleFunctionsLeaks.test_sensors_batterycCs|jtj�dS)N)r5rLZsensors_temperatures)r%r*r*r+�test_sensors_temperatures�sz2TestModuleFunctionsLeaks.test_sensors_temperaturescCs|jtj�dS)N)r5rLZsensors_fans)r%r*r*r+�test_sensors_fans�sz*TestModuleFunctionsLeaks.test_sensors_fanscCs|jtj�dS)N)r5rLZ	boot_time)r%r*r*r+�test_boot_time�sz'TestModuleFunctionsLeaks.test_boot_timecCs|jtj�dS)N)r5rLZusers)r%r*r*r+�
test_users�sz#TestModuleFunctionsLeaks.test_userscCs|jdd��dS)NcSs
tjd�S)NF)rLZ
_set_debugr*r*r*r+rF�sz9TestModuleFunctionsLeaks.test_set_debug.<locals>.<lambda>)r5)r%r*r*r+�test_set_debug�sz'TestModuleFunctionsLeaks.test_set_debugcCs|jtj�dS)N)r5rPZwinservice_enumerate)r%r*r*r+�test_win_service_iter�sz.TestModuleFunctionsLeaks.test_win_service_itercCsdS)Nr*)r%r*r*r+�test_win_service_get�sz-TestModuleFunctionsLeaks.test_win_service_getcs&ttj��j��|j�fdd��dS)Ncs
tj��S)N)rPZwinservice_query_configr*)r7r*r+rF�szFTestModuleFunctionsLeaks.test_win_service_get_config.<locals>.<lambda>)�nextrL�win_service_iterr7r5)r%r*)r7r+�test_win_service_get_config�sz4TestModuleFunctionsLeaks.test_win_service_get_configcs&ttj��j��|j�fdd��dS)Ncs
tj��S)N)rPZwinservice_query_statusr*)r7r*r+rF�szFTestModuleFunctionsLeaks.test_win_service_get_status.<locals>.<lambda>)r�rLr�r7r5)r%r*)r7r+�test_win_service_get_status�sz4TestModuleFunctionsLeaks.test_win_service_get_statuscs&ttj��j��|j�fdd��dS)Ncs
tj��S)N)rPZwinservice_query_descrr*)r7r*r+rF�szKTestModuleFunctionsLeaks.test_win_service_get_description.<locals>.<lambda>)r�rLr�r7r5)r%r*)r7r+� test_win_service_get_description�sz9TestModuleFunctionsLeaks.test_win_service_get_descriptionN)6r�r�r�r�r4r0r�r�rbr�r�rr�r�r�platform�machinerr�rr�r�rr�r�r�rr�rrQ�path�existsr�r�rr��getuidr~r�r�rr�rr�rr�r�r�r�r�r�r�r�r�r*r*r*r+r�SsV(r�)4r��
__future__rr-rQr�rLZpsutil._commonrrrrrrZpsutil._compatr	r
Zpsutil.testsrrr
rrrrrrrrrrrrrrrrrrr Z_psplatformrPrWrGr$r0r1r�r�r�r�r�r*r*r*r+�<module>s\66