MOON
Server: Apache
System: Linux vps.erhabenn.com.br 3.10.0-1160.119.1.el7.tuxcare.els2.x86_64 #1 SMP Mon Jul 15 12:09:18 UTC 2024 x86_64
User: sonne (1011)
PHP: 8.2.31
Disabled: NONE
Upload Files
File: //opt/alt/python38/lib64/python3.8/site-packages/psutil/tests/__pycache__/test_bsd.cpython-38.pyc
U

�=�_�P�@s�dZddlZddlZddlZddlZddlZddlmZddlmZddlmZddlm	Z	ddl
mZddl
mZdd	l
m
Z
dd
l
mZddl
mZddl
mZdd
l
mZddl
mZddl
mZer�ddlmZe�Ze��dkr�ed�r�dndZndZdZdd�Zdd�Ze�ed�Gdd�de
��Ze�ed�Gdd�de
��Ze�ed�Gdd�de
��Ze�e	d�Gd d!�d!e
��Ze�ed"�Gd#d$�d$e
��Z e!d%k�r�dd&l"m#Z#e#e$�dS)'z$Tests specific to all BSD platforms.�N)�BSD)�FREEBSD)�NETBSD)�OPENBSD)�spawn_testproc)�HAS_BATTERY)�PsutilTestCase)�retry_on_failure)�sh)�TOLERANCE_SYS_MEM)�	terminate)�unittest)�which)�getpagesize�museTFcCsntd|�}tr(||�d�dd�}nts0trF||�d�dd�}z
t|�WStk
rh|YSXdS)zmExpects a sysctl command with an argument and parse the result
    returning only the value of interest.
    zsysctl z: �N�=�)r
r�findrr�int�
ValueError)�cmdline�result�r�H/opt/alt/python38/lib64/python3.8/site-packages/psutil/tests/test_bsd.py�sysctl-s
rcCs>td�}|�d�D]}|�|�rq.qtd��t|��d�S)z+Thin wrapper around 'muse' cmdline utility.r�
zline not foundr)r
�split�
startswithrr)Zfield�out�linerrrr<s
zBSD onlyc@s�eZdZdZedd��Zedd��Ze�e	d�dd��Z
d	d
�Ze�ed�d�d
d��Z
e�ed�d�dd��Zdd�ZdS)�BSDTestCasez)Generic tests common to all BSD variants.cCst�j|_dS�N�r�pid��clsrrr�
setUpClassPszBSDTestCase.setUpClasscCst|j�dSr"�rr$r%rrr�
tearDownClassTszBSDTestCase.tearDownClassz -o lstart doesn't work on NETBSDcCsPtd|j�}|�dd���}t�|j���}t�dt�	|��}|�
||�dS)Nzps -o lstart -p %sZSTARTED�z%a %b %e %H:%M:%S %Y)r
r$�replace�strip�psutil�ProcessZcreate_time�time�strftime�	localtime�assertEqual)�self�outputZstart_psZstart_psutilrrr�test_process_create_timeXs�z$BSDTestCase.test_process_create_timecCs�dd�}tjdd�D]�}t�|j�}||j�\}}}}|�|j|�|�|j|�t|j|�dkrx|�	d|j|f�t|j
|�dkr|�	d|j
|f�qdS)NcSs�td|���}|�d�}|�d�|�d�}|��dd�\}}}}|dkrRd}t|�d}t|�d}t|�d}||||fS)Nz
df -k "%s"rr�Znoner*�)r
r,r�popr)�pathr�linesr �dev�total�used�freerrr�dfds


z"BSDTestCase.test_disks.<locals>.dfF)�alli�zpsutil=%s, df=%s)r-Zdisk_partitionsZ
disk_usageZ
mountpointr2Zdevicer<�absr>Zfailr=)r3r?�partZusager;r<r=r>rrr�
test_disksas
zBSDTestCase.test_disksrzsysctl cmd not availablecCs td�}|�tjdd�|�dS)Nzhw.ncpuT)Zlogical)rr2r-�	cpu_count�r3Zsystrrr�test_cpu_count_logical|sz"BSDTestCase.test_cpu_count_logicalcCstd�}|�|t��j�dS)Nz
hw.physmem)rr2r-�virtual_memoryr<�r3Znumrrr�test_virtual_memory_total�sz%BSDTestCase.test_virtual_memory_totalc	Cs|t����D]j\}}ztd|�}Wntk
r8YqX|j|jd|k|d�d|kr|�|jtt	�
d|�d��qdS)Nzifconfig %sZRUNNING)�msg�mtuz	mtu (\d+)r)r-Znet_if_stats�itemsr
�RuntimeErrorr2ZisuprKr�re�findall)r3�nameZstatsrrrr�test_net_if_stats�s�zBSDTestCase.test_net_if_statsN)�__name__�
__module__�__qualname__�__doc__�classmethodr'r)r
�skipIfrr5rCrrFrIrQrrrrr!Ls





r!zFREEBSD onlyc@sfeZdZedd��Zedd��Ze�dd��Zdd�Zd	d
�Z	dd�Z
e�d
d��Ze�dd��ZdS)�FreeBSDPsutilTestCasecCst�j|_dSr"r#r%rrrr'�sz FreeBSDPsutilTestCase.setUpClasscCst|j�dSr"r(r%rrrr)�sz#FreeBSDPsutilTestCase.tearDownClasscCs�td|j�}t�|j�jdd�}|�d�dd�}|r�|��}|��}|dd�\}}}}	}
|��}|�d||f|j�|�t	|
�|j
�|j�d�s4|�|d	|j�q4dS)
Nzprocstat -v %sF)Zgroupedrr�z%s-%s�[�
)
r
r$r-r.Zmemory_mapsrr8r2ZaddrrZrssr9r)r3r�mapsr:r �fields�_�start�stopZperms�res�maprrr�test_memory_maps�sz&FreeBSDPsutilTestCase.test_memory_mapscCs<td|j�}|�t�|j���|�d�d��d�dS)Nzprocstat -b %srr���)r
r$r2r-r.Zexer�r3rrrr�test_exe�s�zFreeBSDPsutilTestCase.test_execCsLtd|j�}|�d�t�|j����d�|�d�d��dd���dS)Nzprocstat -c %s� rrr)r
r$r2�joinr-r.rrrerrr�test_cmdline�s�z"FreeBSDPsutilTestCase.test_cmdlinecCs�td|j�}|�d�d��dd�\}}}}}}t�|j�}|��}	|��}
|�|	jt	|��|�|	j
t	|��|�|	jt	|��|�|
jt	|��|�|
j
t	|��|�|
jt	|��dS)Nzprocstat -s %srrr�)r
r$rr-r.�uids�gidsr2�realrZ	effectiveZsaved)r3rZeuidZruidZsuidZegidZrgidZsgid�prkrlrrr�test_uids_gids�s&z$FreeBSDPsutilTestCase.test_uids_gidscCs�g}td|j�}t�|j�}|�d�D]�}|����}d|krrt|��d�}|��j	}|�
||�|�d�q(d|kr(t|��d�}|��j}|�
||�|�d�q(t
|�dkr�td��dS)N�procstat -r %srz voluntary contextrdz involuntary contextr�)couldn't find lines match in procstat out)r
r$r-r.r�lowerr,rZnum_ctx_switchesZ	voluntaryr2�appendZinvoluntary�lenrM�r3Ztestedrrnr Zpstat_valueZpsutil_valuerrr�test_ctx_switches�s"

z'FreeBSDPsutilTestCase.test_ctx_switchescCs�g}td|j�}t�|j�}|�d�D]�}|����}d|kr�td|��d�d�d�}|��j	}|�
||�|�d�q(d|kr(td|��d�d�d�}|��j}|�
||�|�d�q(t
|�dkr�td	��dS)
Nrprz	user timez0.rd�.zsystem timerrq)r
r$r-r.rrrr,�floatZ	cpu_times�userr2rs�systemrtrMrurrr�test_cpu_times�s"

z$FreeBSDPsutilTestCase.test_cpu_timesN)
rRrSrTrVr'r)r	rcrfrirorvr{rrrrrX�s




rXc@s�eZdZedd��Zdd�Ze�dd��Ze�dd��Ze�d	d
��Z	e�dd��Z
e�d
d��Ze�dd��Ze
�ed�dd��Ze
�ed�e�dd���Ze
�ed�e�dd���Ze
�ed�e�dd���Ze
�ed�e�dd���Ze
�ed�e�dd���Ze
�ed�e�dd���Zd d!�Zd"d#�Zd$d%�Ze�d&d'��Zd(d)�Zd*d+�Zd,d-�Zd.d/�Ze
�ed0�d1d2��Z e
�ed0�d3d4��Z!e
�ed5�d6d7��Z"d8d9�Z#d:S);�FreeBSDSystemTestCasecCsRtd���d}t�d|�}|s,td|��dd�|dd�D�\}}}|||fS)	Nzswapinfo -krdz\s+zCan't parse swapinfo: %scss|]}t|�dVqdS)r7N)r)�.0rnrrr�	<genexpr>�sz7FreeBSDSystemTestCase.parse_swapinfo.<locals>.<genexpr>rr6)r
�
splitlinesrNrr)r4�partsr<r=r>rrr�parse_swapinfo�sz$FreeBSDSystemTestCase.parse_swapinfocCs�d}ztt|��}Wntk
r2|�d�YnX|�t��j|�d}t|�}t|��d�d�d�}t|��d�d�d�}|�t��j	|�|�t��j
|�dS)Nzdev.cpu.0.freqz#frequencies not supported by kernelzdev.cpu.0.freq_levelsr�/rd)rrrM�skipTestr2r-Zcpu_freq�currentr�max�min)r3�sensor�
sysctl_resultZmax_freqZmin_freqrrr�!test_cpu_frequency_against_sysctlsz7FreeBSDSystemTestCase.test_cpu_frequency_against_sysctlcCs&td�t}|jt��j|td�dS)Nzvm.stats.vm.v_active_count�Zdelta)r�PAGESIZE�assertAlmostEqualr-rG�activerrErrr�test_vmem_actives�z&FreeBSDSystemTestCase.test_vmem_activecCs&td�t}|jt��j|td�dS)Nzvm.stats.vm.v_inactive_countr�)rr�r�r-rG�inactiverrErrr�test_vmem_inactives�z(FreeBSDSystemTestCase.test_vmem_inactivecCs&td�t}|jt��j|td�dS)Nzvm.stats.vm.v_wire_countr�)rr�r�r-rG�wiredrrErrr�test_vmem_wired$s�z%FreeBSDSystemTestCase.test_vmem_wiredcCs&td�t}|jt��j|td�dS)Nzvm.stats.vm.v_cache_countr�)rr�r�r-rG�cachedrrErrr�test_vmem_cached*s�z&FreeBSDSystemTestCase.test_vmem_cachedcCs&td�t}|jt��j|td�dS)Nzvm.stats.vm.v_free_countr�)rr�r�r-rGr>rrErrr�test_vmem_free0s�z$FreeBSDSystemTestCase.test_vmem_freecCs"td�}|jt��j|td�dS)Nzvfs.bufspacer�)rr�r-rG�buffersrrErrr�test_vmem_buffers6s�z'FreeBSDSystemTestCase.test_vmem_bufferszmuse not installedcCstd�}|�t��j|�dS)NZTotal)rr2r-rGr<rHrrr�test_muse_vmem_total>sz*FreeBSDSystemTestCase.test_muse_vmem_totalcCs"td�}|jt��j|td�dS)NZActiver�)rr�r-rGr�rrHrrr�test_muse_vmem_activeCs�z+FreeBSDSystemTestCase.test_muse_vmem_activecCs"td�}|jt��j|td�dS)NZInactiver�)rr�r-rGr�rrHrrr�test_muse_vmem_inactiveJs�z-FreeBSDSystemTestCase.test_muse_vmem_inactivecCs"td�}|jt��j|td�dS)NZWiredr�)rr�r-rGr�rrHrrr�test_muse_vmem_wiredQs�z*FreeBSDSystemTestCase.test_muse_vmem_wiredcCs"td�}|jt��j|td�dS)NZCacher�)rr�r-rGr�rrHrrr�test_muse_vmem_cachedXs�z+FreeBSDSystemTestCase.test_muse_vmem_cachedcCs"td�}|jt��j|td�dS)NZFreer�)rr�r-rGr>rrHrrr�test_muse_vmem_free_s�z)FreeBSDSystemTestCase.test_muse_vmem_freecCs"td�}|jt��j|td�dS)NZBufferr�)rr�r-rGr�rrHrrr�test_muse_vmem_buffersfs�z,FreeBSDSystemTestCase.test_muse_vmem_bufferscCs|jt��jtd�dd�dS)Nzvm.stats.sys.v_swtch��r�)r�r-�	cpu_stats�ctx_switchesr�r3rrr�test_cpu_stats_ctx_switchesms�z1FreeBSDSystemTestCase.test_cpu_stats_ctx_switchescCs|jt��jtd�dd�dS)Nzvm.stats.sys.v_intrr�r�)r�r-r��
interruptsrr�rrr�test_cpu_stats_interruptsqs�z/FreeBSDSystemTestCase.test_cpu_stats_interruptscCs|jt��jtd�dd�dS)Nzvm.stats.sys.v_softr�r�)r�r-r�Zsoft_interruptsrr�rrr�test_cpu_stats_soft_interruptsus�z4FreeBSDSystemTestCase.test_cpu_stats_soft_interruptscCs|jt��jtd�dd�dS)Nzvm.stats.sys.v_syscalli@
r�)r�r-r�Zsyscallsrr�rrr�test_cpu_stats_syscallsys�z-FreeBSDSystemTestCase.test_cpu_stats_syscallscCs(|��\}}}|jt��j|td�dS�Nr�)r�r�r-�swap_memoryr>r�r3r<r=r>rrr�test_swapmem_free�s�z'FreeBSDSystemTestCase.test_swapmem_freecCs(|��\}}}|jt��j|td�dSr�)r�r�r-r�r=rr�rrr�test_swapmem_used�s�z'FreeBSDSystemTestCase.test_swapmem_usedcCs(|��\}}}|jt��j|td�dSr�)r�r�r-r�r<rr�rrr�test_swapmem_total�s�z(FreeBSDSystemTestCase.test_swapmem_totalcCsLtd�}||�d�dd�}|d|�d��}t|�}|�|t���dS)Nzsysctl kern.boottimez sec = ��,)rrrr2r-�	boot_time)r3�sZbtimerrr�test_boot_time�s
z$FreeBSDSystemTestCase.test_boot_timez
no batterycCs�dd�}td�}tdd�|�d�D��}t��}t|d�dd	��}|d
}|�|j|�|dkrt|�|j	tj
�n|�||j	�|�dS)NcSs(t|d�\}}t|d�\}}d||fS)N�<z%d:%02d)�divmod)Zsecs�mr��hrrr�
secs2hours�sz>FreeBSDSystemTestCase.test_sensors_battery.<locals>.secs2hoursz
acpiconf -i 0cSs(g|] }|�d�d|�d�df�qS)�	rrd)r)r}�xrrr�
<listcomp>�s�z>FreeBSDSystemTestCase.test_sensors_battery.<locals>.<listcomp>rzRemaining capacity:�%r*zRemaining time:�unknown)r
�dictrr-�sensors_batteryrr+r2�percent�secsleftZPOWER_TIME_UNLIMITED)r3r�rr]Zmetricsr�Zremaining_timerrr�test_sensors_battery�s�z*FreeBSDSystemTestCase.test_sensors_batterycCsl|�t��jtd��|�t��jtd�dk�t��j}|dkrT|�td�d�n|�|td�d�dS)N�hw.acpi.battery.life�hw.acpi.aclinerr�hw.acpi.battery.timerdr�)r2r-r�r�rZ
power_pluggedr�)r3r�rrr�#test_sensors_battery_against_sysctl�s�
�
z9FreeBSDSystemTestCase.test_sensors_battery_against_sysctlzhas batteryc	Cs@|�t��td�td�td�W5QRX|�t���dS)Nr�r�r�)ZassertRaisesrMrZassertIsNoner-r�r�rrr�test_sensors_battery_no_battery�s
z5FreeBSDSystemTestCase.test_sensors_battery_no_batteryc	Cs�t�d�}t|�D]�}d|}zttt|�dd���}Wntk
rX|�d�YnX|jt�	�d|j
|dd�d|}ttt|�dd���}|�t�	�d|j|�qdS)	NTzdev.cpu.%s.temperaturerdz$temperatures not supported by kernelZcoretempr[r�zdev.cpu.%s.coretemp.tjmax)
r-rD�rangerrxrrMr�r�Zsensors_temperaturesr�r2Zhigh)r3Znum_cpusZcpur�r�rrr�(test_sensors_temperatures_against_sysctl�s$
��z>FreeBSDSystemTestCase.test_sensors_temperatures_against_sysctlN)$rRrSrT�staticmethodr�r�r	r�r�r�r�r�r�r
rW�MUSE_AVAILABLEr�r�r�r�r�r�r�r�r�r�r�r�r�r�r�rr�r�r�r�rrrrr|�sf








	



r|zOPENBSD onlyc@seZdZdd�ZdS)�OpenBSDTestCasecCs6td�}tj�|d�}tj�t���}|�||�dS)Nz
kern.boottimez%a %b %d %H:%M:%S %Y)r�datetime�strptimeZ
fromtimestampr-r�r2)r3r�Zsys_btZ	psutil_btrrrr��szOpenBSDTestCase.test_boot_timeN)rRrSrTr�rrrrr��sr�zNETBSD onlyc@s`eZdZedd��Zdd�Zdd�Zdd�Zd	d
�Zdd�Z	d
d�Z
dd�Zdd�Zdd�Z
dS)�NetBSDTestCasec
Cs^tdd��>}|D]2}|�|�rt|��d�dW5QR�SqW5QRXtd|��dS)Nz
/proc/meminfoZrtrr7z
can't find %s)�openrrrr)Zlook_for�fr rrr�
parse_meminfo�s

0zNetBSDTestCase.parse_meminfocCs|�t��j|�d��dS)Nz	MemTotal:)r2r-rGr<r�r�rrr�test_vmem_total�s�zNetBSDTestCase.test_vmem_totalcCs |jt��j|�d�td�dS)NzMemFree:r�)r�r-rGr>r�rr�rrrr�s
�zNetBSDTestCase.test_vmem_freecCs |jt��j|�d�td�dS)NzBuffers:r�)r�r-rGr�r�rr�rrrr�s
�z NetBSDTestCase.test_vmem_bufferscCs |jt��j|�d�td�dS)Nz
MemShared:r�)r�r-rGZsharedr�rr�rrr�test_vmem_shareds
�zNetBSDTestCase.test_vmem_sharedcCs |jt��j|�d�td�dS)Nz
SwapTotal:r�)r�r-r�r<r�rr�rrrr�s
�z!NetBSDTestCase.test_swapmem_totalcCs |jt��j|�d�td�dS)Nz	SwapFree:r�)r�r-r�r>r�rr�rrrr�s
�z NetBSDTestCase.test_swapmem_freecCs"t��}|�|j|j|j�dSr")r-r�r2r=r<r>)r3Zsmemrrrr�sz NetBSDTestCase.test_swapmem_usedc	Cs`tdd��6}|D]"}|�d�rt|��d�}q<qtd��W5QRX|jt��j|dd�dS)N�
/proc/stat�rbsintrr�couldn't find liner�r�)	r�rrrrr�r-r�r�)r3r�r r�rrrr�s
�z(NetBSDTestCase.test_cpu_stats_interruptsc	Cs`tdd��6}|D]"}|�d�rt|��d�}q<qtd��W5QRX|jt��j|dd�dS)Nr�r�sctxtrr�r�r�)	r�rrrrr�r-r�r�)r3r�r r�rrrr�*s
�z*NetBSDTestCase.test_cpu_stats_ctx_switchesN)rRrSrTr�r�r�r�r�r�r�r�r�r�r�rrrrr��s
r��__main__)�
run_from_name)%rUr��osrNr/r-rrrrZpsutil.testsrrrr	r
rrr
rZpsutil._psutil_posixrr��getuidr�rrrWr!rXr|r�r�rRZpsutil.tests.runnerr��__file__rrrr�<module>
sPKYrB