HEX
Server: Apache
System: Linux zacp120.webway.host 4.18.0-553.50.1.lve.el8.x86_64 #1 SMP Thu Apr 17 19:10:24 UTC 2025 x86_64
User: govancoz (1003)
PHP: 8.3.26
Disabled: exec,system,passthru,shell_exec,proc_close,proc_open,dl,popen,show_source,posix_kill,posix_mkfifo,posix_getpwuid,posix_setpgid,posix_setsid,posix_setuid,posix_setgid,posix_seteuid,posix_setegid,posix_uname
Upload Files
File: //opt/osm/venv/lib/python3.10/site-packages/psutil/tests/__pycache__/test_memleaks.cpython-310.pyc
o

=i�:�@s�dZddlZddlZddlZddlmZddlmZddlmZddlmZddlmZddlm	Z	dd	l
mZdd
l
mZddl
m
Z
ddl
mZdd
l
mZddl
mZddl
mZddl
mZddl
mZddl
mZddl
mZddl
mZddl
mZddl
mZddl
mZddl
mZddl
mZddl
mZddl
mZddl
mZddl
mZddl
m Z ej!j"Z"e�#�Z$dZ%d d!�Z&Gd"d#�d#e�Z'Gd$d%�d%e'�Z(ej)j*e	d&d'�Gd(d)�d)e��Z+Gd*d+�d+e�Z,dS),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.
�N)�LINUX)�MACOS)�OPENBSD)�POSIX)�SUNOS)�WINDOWS)�AARCH64)�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)�TestMemoryLeak)�create_sockets)�
get_testfn)�process_namespace)�pytest)�skip_on_access_denied)�
spawn_subproc)�system_namespace)�	terminate�cCsdd�}|S)zsDecorator for those Linux functions which are implemented in pure
    Python, and which we want to run faster.
    cst����fdd��}|S)NcsVtr |jj}zt|j_�|g|�Ri|��W||j_S||j_w�|g|�Ri|��S�N)r�	__class__�times�	FEW_TIMES)�self�args�kwargs�before��fun��H/opt/osm/venv/lib/python3.10/site-packages/psutil/tests/test_memleaks.py�wrapper=sz5fewtimes_if_linux.<locals>.decorator.<locals>.wrapper)�	functools�wraps)r(r+r)r'r*�	decorator<sz$fewtimes_if_linux.<locals>.decoratorr))r.r)r)r*�fewtimes_if_linux7sr/c@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�dSr)r�test_class_coverageZgettersZsetters�r#�nsr)r)r*�
test_coverageX�z$TestProcessObjectLeaks.test_coveragecC�|�|jj�dSr)�execute�proc�name�r#r)r)r*�	test_name\�z TestProcessObjectLeaks.test_namecCr6r)r7r8Zcmdliner:r)r)r*�test_cmdline`r<z#TestProcessObjectLeaks.test_cmdlinecCr6r)r7r8�exer:r)r)r*�test_exedr<zTestProcessObjectLeaks.test_execCr6r)r7r8Zppidr:r)r)r*�	test_ppidhr<z TestProcessObjectLeaks.test_ppidz
POSIX only��reasoncCr6r)r7r8Zuidsr:r)r)r*�	test_uidsl�z TestProcessObjectLeaks.test_uidscCr6r)r7r8�gidsr:r)r)r*�	test_gidsqrDz TestProcessObjectLeaks.test_gidscCr6r)r7r8�statusr:r)r)r*�test_statusvr<z"TestProcessObjectLeaks.test_statuscCr6r)r7r8�nicer:r)r)r*�	test_nicez�z TestProcessObjectLeaks.test_nicecs t�������fdd��dS)Nc��j���Sr)r8rIr)�Znicenessr#r)r*�<lambda>�z6TestProcessObjectLeaks.test_nice_set.<locals>.<lambda>)�thisprocrIr7r:r)rMr*�
test_nice_set}r5z$TestProcessObjectLeaks.test_nice_set�
not supportedcCr6r)r7r8�ionicer:r)r)r*�test_ionice�r<z"TestProcessObjectLeaks.test_ionicecs\trt�������fdd��dS���fdd��t�tjt�	�dd�}��
t|�dS)Ncs�j���Sr)r8rSr)�r#�valuer)r*rN�rOz8TestProcessObjectLeaks.test_ionice_set.<locals>.<lambda>c��j�tj�Sr)r8rS�psutilZIOPRIO_CLASS_NONEr)r:r)r*rN�����r)rrPrSr7r,�partial�cextZproc_ioprio_set�os�getpid�
execute_w_exc�OSError�r#r(r)rUr*�test_ionice_set�sz&TestProcessObjectLeaks.test_ionice_setcCr6r)r7r8Zio_countersr:r)r)r*�test_io_counters�rDz'TestProcessObjectLeaks.test_io_counterszworthless on POSIXcCst����|�|jj�dSr)rX�Process�usernamer7r8r:r)r)r*�
test_username�sz$TestProcessObjectLeaks.test_usernamecCr6r)r7r8Zcreate_timer:r)r)r*�test_create_time�r<z'TestProcessObjectLeaks.test_create_time)Zonly_ifcCr6r)r7r8Znum_threadsr:r)r)r*�test_num_threads�rDz'TestProcessObjectLeaks.test_num_threads�WINDOWS onlycCr6r)r7r8Znum_handlesr:r)r)r*�test_num_handles�r<z'TestProcessObjectLeaks.test_num_handlescCr6r)r7r8Znum_fdsr:r)r)r*�test_num_fds�rDz#TestProcessObjectLeaks.test_num_fdscCr6r)r7r8Znum_ctx_switchesr:r)r)r*�test_num_ctx_switches�r<z,TestProcessObjectLeaks.test_num_ctx_switchescCr6r)r7r8�threadsr:r)r)r*�test_threads�rDz#TestProcessObjectLeaks.test_threadscCr6r)r7r8�	cpu_timesr:r)r)r*�test_cpu_times�r<z%TestProcessObjectLeaks.test_cpu_timescCr6r)r7r8Zcpu_numr:r)r)r*�test_cpu_num�rDz#TestProcessObjectLeaks.test_cpu_numcCr6r)r7r8Zmemory_infor:r)r)r*�test_memory_info�r<z'TestProcessObjectLeaks.test_memory_infocCr6r)r7r8Zmemory_full_infor:r)r)r*�test_memory_full_info�r<z,TestProcessObjectLeaks.test_memory_full_infocCr6r)r7r8Zterminalr:r)r)r*�
test_terminal�rDz$TestProcessObjectLeaks.test_terminalcCs$trtn|j}|j|jj|d�dS)N�r!)rr"r!r7r8�resume�r#r!r)r)r*�test_resume��z"TestProcessObjectLeaks.test_resumecCr6r)r7r8�cwdr:r)r)r*�test_cwd�r<zTestProcessObjectLeaks.test_cwdcCr6r)r7r8�cpu_affinityr:r)r)r*�test_cpu_affinity�r<z(TestProcessObjectLeaks.test_cpu_affinitycs4t�������fdd����t�fdd��dS)NcrLr�r8r|r)�Zaffinityr#r)r*rN�rOz>TestProcessObjectLeaks.test_cpu_affinity_set.<locals>.<lambda>cs�j�dg�S�NrZr~r)r:r)r*rN�rY)rPr|r7r_�
ValueErrorr:r)rr*�test_cpu_affinity_set�sz,TestProcessObjectLeaks.test_cpu_affinity_setcCs@tt�d��|�|jj�Wd�dS1swYdS)N�w)�openrr7r8Z
open_filesr:r)r)r*�test_open_files�s"�z&TestProcessObjectLeaks.test_open_filescCr6r)r7r8Zmemory_mapsr:r)r)r*�test_memory_maps�rDz'TestProcessObjectLeaks.test_memory_mapsz
LINUX onlycs���fdd��dS)NcrWr�r8�rlimitrX�
RLIMIT_NOFILEr)r:r)r*rN�rYz4TestProcessObjectLeaks.test_rlimit.<locals>.<lambda>�r7r:r)r:r*�test_rlimit�sz"TestProcessObjectLeaks.test_rlimitcs<t�tj������fdd����ttf�fdd��dS)Ncs�j�tj��Srr�r)��limitr#r)r*rN�sz8TestProcessObjectLeaks.test_rlimit_set.<locals>.<lambda>cs�j�d�Sr�)r8r�r)r:r)r*rN�rO)rPr�rXr�r7r_r`r�r:r)r�r*�test_rlimit_set�sz&TestProcessObjectLeaks.test_rlimit_setzworthless on WINDOWScsLt��trdnd�����fdd��Wd�dS1swYdS)NZinet�allcrLr)r8�net_connectionsr)��kindr#r)r*rN�rOz=TestProcessObjectLeaks.test_net_connections.<locals>.<lambda>)rrr7r:r)r�r*�test_net_connections�s"�z+TestProcessObjectLeaks.test_net_connectionscCr6r)r7r8�environr:r)r)r*�test_environ�r<z#TestProcessObjectLeaks.test_environcC�|�dd��dS)NcS�t�t���Sr)r\�	proc_infor]r^r)r)r)r*rNrYz7TestProcessObjectLeaks.test_proc_info.<locals>.<lambda>r�r:r)r)r*�test_proc_infor<z%TestProcessObjectLeaks.test_proc_infoN):�__name__�
__module__�__qualname__�__doc__rPr8r4r/r;r=r?r@r�mark�skipifrrCrFrHrJrQrrTrbrrcrfrgrrrhrrjrkrlrnrprrqrrrsrtrxr{r	r}r�r�r
r�rrr�r�r�rr�r�r)r)r)r*r0Ss�






	











r0csxeZdZdZe�fdd��Ze�fdd��Zdd�Zer8dd	�Z	d
d�Z
dd
�Zdd�Zdd�Z
dd�Z�ZS�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���t�|_t�|jj�|_|j��|j�	�dSr)
�super�
setUpClassr�subprXrd�pidr8�kill�wait��cls�r r)r*r�s


z%TestTerminatedProcessLeaks.setUpClasscst���t|j�dSr)r��
tearDownClassrr�r�r�r)r*r�s
z(TestTerminatedProcessLeaks.tearDownClasscCs$z|�WdStjyYdSwr)rXZ
NoSuchProcessrar)r)r*�calls
�zTestTerminatedProcessLeaks.callcCr6r)r7r8r�r:r)r)r*�	test_kill$rKz$TestTerminatedProcessLeaks.test_killcCr6r)r7r8rr:r)r)r*�test_terminate'rKz)TestTerminatedProcessLeaks.test_terminatecCr6r)r7r8Zsuspendr:r)r)r*�test_suspend*rKz'TestTerminatedProcessLeaks.test_suspendcCr6r)r7r8rvr:r)r)r*rx-rKz&TestTerminatedProcessLeaks.test_resumecCr6r)r7r8r�r:r)r)r*�	test_wait0rKz$TestTerminatedProcessLeaks.test_waitcs�fdd�}��|�dS)Ncs&zt��jj�WStyYdSwr)r\r�r8r��ProcessLookupErrorr)r:r)r*r�5s
�z7TestTerminatedProcessLeaks.test_proc_info.<locals>.callr�)r#r�r)r:r*r�3sz)TestTerminatedProcessLeaks.test_proc_info)r�r�r�r��classmethodr�r�r�rr�r�r�rxr�r��
__classcell__r)r)r�r*r�s�r�rirAc@seZdZdd�Zdd�ZdS)�TestProcessDualImplementationcCr�)NcS�tjt��dd�S)NT�Zuse_peb�r\Zproc_cmdliner]r^r)r)r)r*rNA�zETestProcessDualImplementation.test_cmdline_peb_true.<locals>.<lambda>r�r:r)r)r*�test_cmdline_peb_true@rKz3TestProcessDualImplementation.test_cmdline_peb_truecCr�)NcSr�)NFr�r�r)r)r)r*rNDr�zFTestProcessDualImplementation.test_cmdline_peb_false.<locals>.<lambda>r�r:r)r)r*�test_cmdline_peb_falseCrKz4TestProcessDualImplementation.test_cmdline_peb_falseN)r�r�r�r�r�r)r)r)r*r�>sr�c@s(eZdZdZdd�Ze�dd��Ze�dd��Ze�dd	��Ze�d
d��Z	e�dd
��Z
e�ejj
eo5edd�ejj
edd�dd����Zejj
edd�dd��Zdd�Zejj
edd�dd��Zdd�Zdd�Zdd �Zejj
eo{ej�d!�d"d�e�d#d$���Ze�d%d&��Ze�ejj
e dd�d'd(���Z!e�ejj
eo�e�"�d)kd*d�d+d,���Z#d-d.�Z$d/d0�Z%e�ejj
e&dd�d1d2���Z'e�ejj
e(dd�d3d4���Z)e�ejj
e*dd�d5d6���Z+e�d7d8��Z,d9d:�Z-d;d<�Z.e�rd=d>�Z/d?d@�Z0dAdB�Z1dCdD�Z2dEdF�Z3dGSdGS)H�TestModuleFunctionsLeaksz&Test leaks of psutil module functions.cCst�}|�||j�dSr)rr1r�r2r)r)r*r4Osz&TestModuleFunctionsLeaks.test_coveragecCr�)NcS�tjdd�S)NT�Zlogical�rX�	cpu_countr)r)r)r*rNWrOz9TestModuleFunctionsLeaks.test_cpu_count.<locals>.<lambda>r�r:r)r)r*�test_cpu_countUr<z'TestModuleFunctionsLeaks.test_cpu_countcCr�)NcSr�)NFr�r�r)r)r)r*rN[rOz?TestModuleFunctionsLeaks.test_cpu_count_cores.<locals>.<lambda>r�r:r)r)r*�test_cpu_count_coresYr<z-TestModuleFunctionsLeaks.test_cpu_count_corescC�|�tj�dSr)r7rXror:r)r)r*rp]�z'TestModuleFunctionsLeaks.test_cpu_timescCr�)NcSr�)NT)Zpercpu)rXror)r)r)r*rNcrOz=TestModuleFunctionsLeaks.test_per_cpu_times.<locals>.<lambda>r�r:r)r)r*�test_per_cpu_timesar<z+TestModuleFunctionsLeaks.test_per_cpu_timescCr�r)r7rXZ	cpu_statsr:r)r)r*�test_cpu_statser�z'TestModuleFunctionsLeaks.test_cpu_statszskipped due to #1892rArRcCr�r)r7rXZcpu_freqr:r)r)r*�
test_cpu_freqisz&TestModuleFunctionsLeaks.test_cpu_freqricCst��|�tj�dSr)rX�
getloadavgr7r:r)r)r*�test_getloadavgpsz(TestModuleFunctionsLeaks.test_getloadavgcCr�r)r7rXZvirtual_memoryr:r)r)r*�test_virtual_memoryw�z,TestModuleFunctionsLeaks.test_virtual_memoryz&worthless on SUNOS (uses a subprocess)cCr�r)r7rXZswap_memoryr:r)r)r*�test_swap_memory{r�z)TestModuleFunctionsLeaks.test_swap_memorycC�$trtn|j}|jdd�|d�dS)NcSr�r)rXZ
pid_existsr]r^r)r)r)r*rN�rYz:TestModuleFunctionsLeaks.test_pid_exists.<locals>.<lambda>ru�rr"r!r7rwr)r)r*�test_pid_existsryz(TestModuleFunctionsLeaks.test_pid_existscCr�)NcS�
t�d�S)N�.)rX�
disk_usager)r)r)r*rN��
z:TestModuleFunctionsLeaks.test_disk_usage.<locals>.<lambda>rur�rwr)r)r*�test_disk_usage�ryz(TestModuleFunctionsLeaks.test_disk_usagecCr�r)r7rXZdisk_partitionsr:r)r)r*�test_disk_partitions�r�z-TestModuleFunctionsLeaks.test_disk_partitionsz/proc/diskstatsz3/proc/diskstats not available on this Linux versioncCr�)NcSr��NF)Znowrap)rXZdisk_io_countersr)r)r)r*rN�rOz@TestModuleFunctionsLeaks.test_disk_io_counters.<locals>.<lambda>r�r:r)r)r*�test_disk_io_counters�sz.TestModuleFunctionsLeaks.test_disk_io_counterscCr�r)r7rXZpidsr:r)r)r*�	test_pids�r�z"TestModuleFunctionsLeaks.test_pidscCr�)NcSr�r�)rXZnet_io_countersr)r)r)r*rN�rOz?TestModuleFunctionsLeaks.test_net_io_counters.<locals>.<lambda>r�r:r)r)r*�test_net_io_counters�rDz-TestModuleFunctionsLeaks.test_net_io_countersrzneed root accesscCsFtjdd�t��|�dd��Wd�dS1swYdS)Nr��r�cSr�)Nr�r�)rXr�r)r)r)r*rN�rOz?TestModuleFunctionsLeaks.test_net_connections.<locals>.<lambda>)rXr�rr7r:r)r)r*r��s"�z-TestModuleFunctionsLeaks.test_net_connectionscCs"trdn|j}|jtj|d�dS)Ni@)�	tolerance)rr�r7rXZnet_if_addrs)r#r�r)r)r*�test_net_if_addrs�sz*TestModuleFunctionsLeaks.test_net_if_addrscCr�r)r7rXZnet_if_statsr:r)r)r*�test_net_if_stats�r�z*TestModuleFunctionsLeaks.test_net_if_statscCr�r)r7rXZsensors_batteryr:r)r)r*�test_sensors_battery��z-TestModuleFunctionsLeaks.test_sensors_batterycCr�r)r7rXZsensors_temperaturesr:r)r)r*�test_sensors_temperatures�r�z2TestModuleFunctionsLeaks.test_sensors_temperaturescCr�r)r7rXZsensors_fansr:r)r)r*�test_sensors_fans�r�z*TestModuleFunctionsLeaks.test_sensors_fanscCr�r)r7rXZ	boot_timer:r)r)r*�test_boot_time�r�z'TestModuleFunctionsLeaks.test_boot_timecCr�r)r7rXZusersr:r)r)r*�
test_users�r�z#TestModuleFunctionsLeaks.test_userscCr�)NcSr�)NF)rXZ
_set_debugr)r)r)r*rN�r�z9TestModuleFunctionsLeaks.test_set_debug.<locals>.<lambda>r�r:r)r)r*�test_set_debug�rKz'TestModuleFunctionsLeaks.test_set_debugcCr�r)r7r\Zwinservice_enumerater:r)r)r*�test_win_service_iter�r�z.TestModuleFunctionsLeaks.test_win_service_itercCsdSrr)r:r)r)r*�test_win_service_get�sz-TestModuleFunctionsLeaks.test_win_service_getc�&tt������|��fdd��dS)Nc�
t���Sr)r\Zwinservice_query_configr)�r9r)r*rN�r�zFTestModuleFunctionsLeaks.test_win_service_get_config.<locals>.<lambda>��nextrXZwin_service_iterr9r7r:r)r�r*�test_win_service_get_config��z4TestModuleFunctionsLeaks.test_win_service_get_configcr�)Ncr�r)r\Zwinservice_query_statusr)r�r)r*rN�r�zFTestModuleFunctionsLeaks.test_win_service_get_status.<locals>.<lambda>r�r:r)r�r*�test_win_service_get_status�r�z4TestModuleFunctionsLeaks.test_win_service_get_statuscr�)Ncr�r)r\Zwinservice_query_descrr)r�r)r*rN�r�zKTestModuleFunctionsLeaks.test_win_service_get_description.<locals>.<lambda>r�r:r)r�r*� test_win_service_get_description�r�z9TestModuleFunctionsLeaks.test_win_service_get_descriptionN)4r�r�r�r�r4r/r�r�rpr�r�rr�r�rrr
r�rr�r�rr�r�r�r�rr]�path�existsr�r�rr��getuidr�r�r�rr�rr�rr�r�r�r�r�r�r�r�r�r)r)r)r*r�Lsz






�

�r�)-r�r,r]rXrrrrrrZpsutil.testsrr	r
rrr
rrrrrrrrrrrrrrrrZ_psplatformr\rdrPr"r/r0r�r�r�r�r�r)r)r)r*�<module>sT
66