MOON
Server: Apache
System: Linux server30c.hostingraja.org 3.10.0-962.3.2.lve1.5.63.el7.x86_64 #1 SMP Fri Oct 8 12:03:35 UTC 2021 x86_64
User: jibhires (1887)
PHP: 8.1.30
Disabled: show_source, system, shell_exec, passthru, exec, popen, proc_open, allow_url_fopen, symlink, escapeshellcmd, pcntl_exec
Upload Files
File: //opt/alt/python37/lib64/python3.7/site-packages/psutil/tests/__pycache__/test_bsd.cpython-37.pyc
B

�=�_�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�museTFcCshtd|�}tr(||�d�dd�}nts0trF||�d�dd�}yt|�Stk
rb|SXdS)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/python37/lib64/python3.7/site-packages/psutil/tests/test_bsd.py�sysctl-srcCs@td�}x&|�d�D]}|�|�rPqWtd��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�dS)N)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�timeZstrftimeZ	localtime�assertEqual)�self�outputZstart_psZstart_psutilrrr�test_process_create_timeXsz$BSDTestCase.test_process_create_timecCs�dd�}x�tjdd�D]�}t�|j�}||j�\}}}}|�|j|�|�|j|�t|j|�dkrz|�	d|j|f�t|j
|�dkr|�	d|j
|f�qWdS)NcSs�td|���}|�d�}|�d�|�d�}|��dd�\}}}}|dkrRd}t|�d}t|�d}t|�d}||||fS)Nz
df -k "%s"rr�Znoner&i)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
mountpointr,Zdevicer5�absr7Zfailr6)r-r8�partZusager4r5r6r7rrr�
test_disksas
zBSDTestCase.test_disksrzsysctl cmd not availablecCs td�}|�tjdd�|�dS)Nzhw.ncpuT)Zlogical)rr,r)�	cpu_count)r-�systrrr�test_cpu_count_logical|sz"BSDTestCase.test_cpu_count_logicalcCstd�}|�|t��j�dS)Nz
hw.physmem)rr,r)�virtual_memoryr5)r-�numrrr�test_virtual_memory_total�sz%BSDTestCase.test_virtual_memory_totalc	Cs�xzt����D]j\}}ytd|�}Wntk
r:YqX|j|jd|k|d�d|kr|�|jtt	�
d|�d��qWdS)Nzifconfig %sZRUNNING)�msg�mtuz	mtu (\d+)r)r)Znet_if_stats�itemsr
�RuntimeErrorr,ZisuprDr�re�findall)r-�nameZstatsrrrr�test_net_if_stats�szBSDTestCase.test_net_if_statsN)�__name__�
__module__�__qualname__�__doc__�classmethodr$r%r
�skipIfrr/r<rr?rBrJrrrrr!Ls	r!zFREEBSD onlyc@sfeZdZedd��Zedd��Ze�dd��Zdd�Zd	d
�Z	dd�Z
e�d
d��Ze�dd��ZdS)�FreeBSDPsutilTestCasecCst�j|_dS)N)rr")r#rrrr$�sz FreeBSDPsutilTestCase.setUpClasscCst|j�dS)N)rr")r#rrrr%�sz#FreeBSDPsutilTestCase.tearDownClasscCs�td|j�}t�|j�jdd�}|�d�dd�}x||r�|��}|��}|dd�\}}}}	}
|��}|�d||f|j�|�t	|
�|j
�|j�d�s6|�|d	|j�q6WdS)
Nzprocstat -v %sF)Zgroupedrr�z%s-%s�[�
)
r
r"r)r*Zmemory_mapsrr1r,ZaddrrZrssr2r)r-r�mapsr3r �fields�_�start�stopZpermsZres�maprrr�test_memory_maps�sz&FreeBSDPsutilTestCase.test_memory_mapscCs<td|j�}|�t�|j���|�d�d��d�dS)Nzprocstat -b %srr���)r
r"r,r)r*Zexer)r-rrrr�test_exe�szFreeBSDPsutilTestCase.test_execCsLtd|j�}|�d�t�|j����d�|�d�d��dd���dS)Nzprocstat -c %s� rrr)r
r"r,�joinr)r*rr)r-rrrr�test_cmdline�sz"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�gidsr,�realrZ	effectiveZsaved)r-rZeuidZruidZsuidZegidZrgidZsgid�prbrcrrr�test_uids_gids�s&z$FreeBSDPsutilTestCase.test_uids_gidscCs�g}td|j�}t�|j�}x�|�d�D]�}|����}d|krtt|��d�}|��j	}|�
||�|�d�q*d|kr*t|��d�}|��j}|�
||�|�d�q*Wt
|�dkr�td��dS)Nzprocstat -r %srz voluntary contextr\z involuntary contextrz)couldn't find lines match in procstat out)r
r"r)r*r�lowerr(rZnum_ctx_switchesZ	voluntaryr,�appendZinvoluntary�lenrF)r-�testedrrer �pstat_value�psutil_valuerrr�test_ctx_switches�s"

z'FreeBSDPsutilTestCase.test_ctx_switchescCs�g}td|j�}t�|j�}x�|�d�D]�}|����}d|kr�td|��d�d�d�}|��j	}|�
||�|�d�q*d|kr*td|��d�d�d�}|��j}|�
||�|�d�q*Wt
|�dkr�td	��dS)
Nzprocstat -r %srz	user timez0.r\�.zsystem timerz)couldn't find lines match in procstat out)r
r"r)r*rrgr(�floatZ	cpu_times�userr,rh�systemrirF)r-rjrrer rkrlrrr�test_cpu_times�s"

z$FreeBSDPsutilTestCase.test_cpu_timesN)
rKrLrMrOr$r%r	r[r]r`rfrmrrrrrrrQ�s
rQc@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 -kr\z\s+zCan't parse swapinfo: %scss|]}t|�dVqdS)iN)r)�.0rerrr�	<genexpr>�sz7FreeBSDSystemTestCase.parse_swapinfo.<locals>.<genexpr>rr0)r
�
splitlinesrGrr)r.�partsr5r6r7rrr�parse_swapinfo�sz$FreeBSDSystemTestCase.parse_swapinfocCs�d}ytt|��}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�/r\)rrrF�skipTestr,r)Zcpu_freq�currentr�max�min)r-�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)�delta)r�PAGESIZE�assertAlmostEqualr)r@�activer)r-r>rrr�test_vmem_activesz&FreeBSDSystemTestCase.test_vmem_activecCs&td�t}|jt��j|td�dS)Nzvm.stats.vm.v_inactive_count)r�)rr�r�r)r@�inactiver)r-r>rrr�test_vmem_inactivesz(FreeBSDSystemTestCase.test_vmem_inactivecCs&td�t}|jt��j|td�dS)Nzvm.stats.vm.v_wire_count)r�)rr�r�r)r@�wiredr)r-r>rrr�test_vmem_wired$sz%FreeBSDSystemTestCase.test_vmem_wiredcCs&td�t}|jt��j|td�dS)Nzvm.stats.vm.v_cache_count)r�)rr�r�r)r@�cachedr)r-r>rrr�test_vmem_cached*sz&FreeBSDSystemTestCase.test_vmem_cachedcCs&td�t}|jt��j|td�dS)Nzvm.stats.vm.v_free_count)r�)rr�r�r)r@r7r)r-r>rrr�test_vmem_free0sz$FreeBSDSystemTestCase.test_vmem_freecCs"td�}|jt��j|td�dS)Nzvfs.bufspace)r�)rr�r)r@�buffersr)r-r>rrr�test_vmem_buffers6sz'FreeBSDSystemTestCase.test_vmem_bufferszmuse not installedcCstd�}|�t��j|�dS)NZTotal)rr,r)r@r5)r-rArrr�test_muse_vmem_total>sz*FreeBSDSystemTestCase.test_muse_vmem_totalcCs"td�}|jt��j|td�dS)NZActive)r�)rr�r)r@r�r)r-rArrr�test_muse_vmem_activeCsz+FreeBSDSystemTestCase.test_muse_vmem_activecCs"td�}|jt��j|td�dS)NZInactive)r�)rr�r)r@r�r)r-rArrr�test_muse_vmem_inactiveJsz-FreeBSDSystemTestCase.test_muse_vmem_inactivecCs"td�}|jt��j|td�dS)NZWired)r�)rr�r)r@r�r)r-rArrr�test_muse_vmem_wiredQsz*FreeBSDSystemTestCase.test_muse_vmem_wiredcCs"td�}|jt��j|td�dS)NZCache)r�)rr�r)r@r�r)r-rArrr�test_muse_vmem_cachedXsz+FreeBSDSystemTestCase.test_muse_vmem_cachedcCs"td�}|jt��j|td�dS)NZFree)r�)rr�r)r@r7r)r-rArrr�test_muse_vmem_free_sz)FreeBSDSystemTestCase.test_muse_vmem_freecCs"td�}|jt��j|td�dS)NZBuffer)r�)rr�r)r@r�r)r-rArrr�test_muse_vmem_buffersfsz,FreeBSDSystemTestCase.test_muse_vmem_bufferscCs|jt��jtd�dd�dS)Nzvm.stats.sys.v_swtchi�)r�)r�r)�	cpu_stats�ctx_switchesr)r-rrr�test_cpu_stats_ctx_switchesmsz1FreeBSDSystemTestCase.test_cpu_stats_ctx_switchescCs|jt��jtd�dd�dS)Nzvm.stats.sys.v_intri�)r�)r�r)r��
interruptsr)r-rrr�test_cpu_stats_interruptsqsz/FreeBSDSystemTestCase.test_cpu_stats_interruptscCs|jt��jtd�dd�dS)Nzvm.stats.sys.v_softi�)r�)r�r)r�Zsoft_interruptsr)r-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�Zsyscallsr)r-rrr�test_cpu_stats_syscallsysz-FreeBSDSystemTestCase.test_cpu_stats_syscallscCs(|��\}}}|jt��j|td�dS)N)r�)rxr�r)�swap_memoryr7r)r-r5r6r7rrr�test_swapmem_free�sz'FreeBSDSystemTestCase.test_swapmem_freecCs(|��\}}}|jt��j|td�dS)N)r�)rxr�r)r�r6r)r-r5r6r7rrr�test_swapmem_used�sz'FreeBSDSystemTestCase.test_swapmem_usedcCs(|��\}}}|jt��j|td�dS)N)r�)rxr�r)r�r5r)r-r5r6r7rrr�test_swapmem_total�sz(FreeBSDSystemTestCase.test_swapmem_totalcCsLtd�}||�d�dd�}|d|�d��}t|�}|�|t���dS)Nzsysctl kern.boottimez sec = ��,)rrrr,r)�	boot_time)r-�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)�	rr\)r)rt�xrrr�
<listcomp>�sz>FreeBSDSystemTestCase.test_sensors_battery.<locals>.<listcomp>rzRemaining capacity:�%r&zRemaining time:�unknown)r
�dictrr)�sensors_batteryrr'r,�percent�secsleftZPOWER_TIME_UNLIMITED)r-r�rrVZmetricsr�Zremaining_timerrr�test_sensors_battery�sz*FreeBSDSystemTestCase.test_sensors_batterycCsl|�t��jtd��|�t��jtd�dk�t��j}|dkrT|�td�d�n|�|td�d�dS)Nzhw.acpi.battery.lifezhw.acpi.aclinerrzhw.acpi.battery.timer\r�)r,r)r�r�rZ
power_pluggedr�)r-r�rrr�#test_sensors_battery_against_sysctl�s

z9FreeBSDSystemTestCase.test_sensors_battery_against_sysctlzhas batteryc	Cs@|�t��td�td�td�WdQRX|�t���dS)Nzhw.acpi.battery.lifezhw.acpi.battery.timezhw.acpi.acline)ZassertRaisesrFrZassertIsNoner)r�)r-rrr�test_sensors_battery_no_battery�s
z5FreeBSDSystemTestCase.test_sensors_battery_no_batteryc	Cs�t�d�}x�t|�D]�}d|}yttt|�dd���}Wntk
rZ|�d�YnX|jt�	�d|j
|dd�d|}ttt|�dd���}|�t�	�d|j|�qWdS)	NTzdev.cpu.%s.temperaturer\z$temperatures not supported by kernelZcoretemprT)r�zdev.cpu.%s.coretemp.tjmax)
r)r=�rangerrorrFrzr�Zsensors_temperaturesr{r,Zhigh)r-Znum_cpusZcpur~rrrr�(test_sensors_temperatures_against_sysctl�s

z>FreeBSDSystemTestCase.test_sensors_temperatures_against_sysctlN)$rKrLrM�staticmethodrxr�r	r�r�r�r�r�r�r
rP�MUSE_AVAILABLEr�r�r�r�r�r�r�r�r�r�r�r�r�r�r�rr�r�r�r�rrrrrs�sB
	
rszOPENBSD onlyc@seZdZdd�ZdS)�OpenBSDTestCasecCs6td�}tj�|d�}tj�t���}|�||�dS)Nz
kern.boottimez%a %b %d %H:%M:%S %Y)r�datetimeZstrptimeZ
fromtimestampr)r�r,)r-r�Zsys_btZ	psutil_btrrrr��szOpenBSDTestCase.test_boot_timeN)rKrLrMr�rrrrr��sr�zNETBSD onlyc@s`eZdZedd��Zdd�Zdd�Zdd�Zd	d
�Zdd�Z	d
d�Z
dd�Zdd�Zdd�Z
dS)�NetBSDTestCasec	CsRtdd��2}x*|D]"}|�|�rt|��d�dSqWWdQRXtd|��dS)Nz
/proc/meminfoZrtriz
can't find %s)�openrrrr)Zlook_for�fr rrr�
parse_meminfo�s


"zNetBSDTestCase.parse_meminfocCs|�t��j|�d��dS)Nz	MemTotal:)r,r)r@r5r�)r-rrr�test_vmem_total�szNetBSDTestCase.test_vmem_totalcCs |jt��j|�d�td�dS)NzMemFree:)r�)r�r)r@r7r�r)r-rrrr�szNetBSDTestCase.test_vmem_freecCs |jt��j|�d�td�dS)NzBuffers:)r�)r�r)r@r�r�r)r-rrrr�sz NetBSDTestCase.test_vmem_bufferscCs |jt��j|�d�td�dS)Nz
MemShared:)r�)r�r)r@Zsharedr�r)r-rrr�test_vmem_sharedszNetBSDTestCase.test_vmem_sharedcCs |jt��j|�d�td�dS)Nz
SwapTotal:)r�)r�r)r�r5r�r)r-rrrr�sz!NetBSDTestCase.test_swapmem_totalcCs |jt��j|�d�td�dS)Nz	SwapFree:)r�)r�r)r�r7r�r)r-rrrr�sz NetBSDTestCase.test_swapmem_freecCs"t��}|�|j|j|j�dS)N)r)r�r,r6r5r7)r-Zsmemrrrr�sz NetBSDTestCase.test_swapmem_usedc	Csbtdd��8}x0|D] }|�d�rt|��d�}PqWtd��WdQRX|jt��j|dd�dS)Nz
/proc/stat�rbsintrrzcouldn't find linei�)r�)	r�rrrrr�r)r�r�)r-r�r r�rrrr�s

z(NetBSDTestCase.test_cpu_stats_interruptsc	Csbtdd��8}x0|D] }|�d�rt|��d�}PqWtd��WdQRX|jt��j|dd�dS)Nz
/proc/statr�sctxtrzcouldn't find linei�)r�)	r�rrrrr�r)r�r�)r-r�r r�rrrr�*s

z*NetBSDTestCase.test_cpu_stats_ctx_switchesN)rKrLrMr�r�r�r�r�r�r�r�r�r�r�rrrrr��sr��__main__)�
run_from_name)%rNr��osrGr+r)rrrrZpsutil.testsrrrr	r
rrr
rZpsutil._psutil_posixrr��getuidr�rrrPr!rQrsr�r�rKZpsutil.tests.runnerr��__file__rrrr�<module>
sPKYrB