Your IP : 3.145.179.30


Current Path : /usr/lib64/python3.6/site-packages/psutil/tests/__pycache__/
Upload File :
Current File : //usr/lib64/python3.6/site-packages/psutil/tests/__pycache__/test_bsd.cpython-36.pyc

3

��JZcE�@s�dZddlZddlZddlZddlZddlZddlmZddlmZddlmZddlm	Z	ddl
mZddl
mZdd	l
m
Z
dd
l
mZddl
mZddl
mZdd
l
mZddl
mZddl
mZer�ejd�Zej�dkr�ed�Zq�dZndZdd�Zdd�Zejed�Gdd�dej��Zejed�Gdd�dej��Zeje	d�Gdd�dej��Zejed�Gd d!�d!ej��Ze d"k�r�ee!�dS)#z$Tests specific to all BSD platforms.�N)�BSD)�FREEBSD)�NETBSD)�OPENBSD)�get_test_subprocess)�HAS_BATTERY)�MEMORY_TOLERANCE)�
reap_children)�retry_before_failing)�run_test_module_by_name)�sh)�unittest)�which�SC_PAGE_SIZE�museFcCshtd|�}tr(||jd�dd�}nts0trF||jd�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� /usr/lib64/python3.6/test_bsd.py�sysctl+srcCs@td�}x&|jd�D]}|j|�rPqWtd��t|j�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��Zeje	d�dd��Z
d	d
�Zejed�d�d
d��Z
ejed�d�dd��Zdd�ZdS)�BSDSpecificTestCasez)Generic tests common to all BSD variants.cCst�j|_dS)N)r�pid)�clsrrr�
setUpClassNszBSDSpecificTestCase.setUpClasscCs
t�dS)N)r	)r#rrr�
tearDownClassRsz!BSDSpecificTestCase.tearDownClassz -o lstart doesn't work on NETBSDcCsPtd|j�}|jdd�j�}tj|j�j�}tjdtj	|��}|j
||�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_timeVsz,BSDSpecificTestCase.test_process_create_timecCs�dd�}x�tjdd�D]�}tj|j�}||j�\}}}}|j|j|�|j|j|�t|j|�d	krz|j	d|j|f�t|j
|�dkr|j	d|j
|f�qWdS)NcSs�td|�j�}|jd�}|jd�|jd�}|j�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�dfbs


z*BSDSpecificTestCase.test_disks.<locals>.dfF)�all�
izpsutil=%s, df=%si(i�i(i�)r)Zdisk_partitionsZ
disk_usageZ
mountpointr,Zdevicer5�absr7Zfailr6)r-r8�partZusager4r5r6r7rrr�
test_disks_s
zBSDSpecificTestCase.test_disksrzsysctl cmd not availablecCs td�}|jtjdd�|�dS)Nzhw.ncpuT)Zlogical)rr,r)�	cpu_count)r-�systrrr�test_cpu_count_logicalzsz*BSDSpecificTestCase.test_cpu_count_logicalcCstd�}|j|tj�j�dS)Nz
hw.physmem)rr,r)�virtual_memoryr5)r-�numrrr�test_virtual_memory_totalsz-BSDSpecificTestCase.test_virtual_memory_totalcCs�xztj�j�D]j\}}ytd|�}Wntk
r:YqX|j|jd|k|d�d|kr|j|jtt	j
d|�d��qWdS)Nzifconfig %sZRUNNING)�msg�mtuz	mtu (\d+)r)r)Znet_if_stats�itemsr�RuntimeErrorr,ZisuprEr�re�findall)r-�nameZstatsrrrr�test_net_if_stats�sz%BSDSpecificTestCase.test_net_if_statsN)�__name__�
__module__�__qualname__�__doc__�classmethodr$r%r
�skipIfrr/r=rr@rCrKrrrrr!Js	r!zFREEBSD onlyc@s�eZdZedd��Zedd��Ze�dd��Zdd�Zd	d
�Z	dd�Z
e�d
d��Ze�dd��Ze�dd��Z
e�dd��Ze�dd��Ze�dd��Ze�dd��Ze�dd��Zejed�dd��Zejed�e�d d!���Zejed�e�d"d#���Zejed�e�d$d%���Zejed�e�d&d'���Zejed�e�d(d)���Zejed�e�d*d+���Zd,d-�Zd.d/�Zd0d1�Zd2d3�Z d4d5�Z!eje"d6�d7d8��Z#eje"d6�d9d:��Z$eje"d;�d<d=��Z%d>S)?�FreeBSDSpecificTestCasecCst�j|_dS)N)rr")r#rrrr$�sz"FreeBSDSpecificTestCase.setUpClasscCs
t�dS)N)r	)r#rrrr%�sz%FreeBSDSpecificTestCase.tearDownClasscCs�td|j�}tj|j�jdd�}|jd�dd�}x||r�|j�}|j�}|dd�\}}}}	}
|j�}|jd||f|j�|jt	|
�|j
�|jjd�s6|j|d	|j�q6WdS)
Nzprocstat -v %sF)Zgroupedrr�z%s-%s�[r:)
rr"r)r*Zmemory_mapsrr1r,ZaddrrZrssr2r)r-r�mapsr3r �fields�_�start�stopZperms�res�maprrr�test_proc_memory_maps�sz-FreeBSDSpecificTestCase.test_proc_memory_mapscCs<td|j�}|jtj|j�j�|jd�dj�d�dS)Nzprocstat -b %srr���)rr"r,r)r*Zexer)r-rrrr�
test_proc_exe�sz%FreeBSDSpecificTestCase.test_proc_execCsLtd|j�}|jdjtj|j�j��dj|jd�dj�dd���dS)Nzprocstat -c %s� rrr)rr"r,�joinr)r*rr)r-rrrr�test_proc_cmdline�sz)FreeBSDSpecificTestCase.test_proc_cmdlinecCs�td|j�}|jd�dj�dd�\}}}}}}tj|j�}|j�}	|j�}
|j|	jt	|��|j|	j
t	|��|j|	jt	|��|j|
jt	|��|j|
j
t	|��|j|
jt	|��dS)Nzprocstat -s %srrr�)rr"rr)r*�uids�gidsr,�realrZ	effectiveZsaved)r-rZeuidZruidZsuidZegidZrgidZsgid�prcrdrrr�test_proc_uids_gids�s&z+FreeBSDSpecificTestCase.test_proc_uids_gidscCs�g}td|j�}tj|j�}x�|jd�D]�}|j�j�}d|krtt|j�d�}|j�j	}|j
||�|jd�q*d|kr*t|j�d	�}|j�j}|j
||�|jd�q*Wt
|�dkr�td��dS)
Nzprocstat -r %srz voluntary contextrz involuntary contextrz)couldn't find lines match in procstat outr]r])rr"r)r*r�lowerr(rZnum_ctx_switchesZ	voluntaryr,�appendZinvoluntary�lenrG)r-�testedrrfr �pstat_value�psutil_valuerrr�test_proc_ctx_switches�s"

z.FreeBSDSpecificTestCase.test_proc_ctx_switchescCs�g}td|j�}tj|j�}x�|jd�D]�}|j�j�}d|kr�td|j�d
jd�d�}|j�j	}|j
||�|jd�q*d|kr*td|j�djd�d
�}|j�j}|j
||�|jd�q*Wt
|�dkr�td	��dS)Nzprocstat -r %srz	user timez0.r�.zsystem timerz)couldn't find lines match in procstat outr]r]r]r])rr"r)r*rrhr(�floatZ	cpu_times�userr,ri�systemrjrG)r-rkrrfr rlrmrrr�test_proc_cpu_times�s"

z+FreeBSDSpecificTestCase.test_proc_cpu_timescCs&td�t}|jtj�j|td�dS)Nzvm.stats.vm.v_active_count)�delta)r�PAGESIZE�assertAlmostEqualr)rA�activer)r-r?rrr�test_vmem_active�sz(FreeBSDSpecificTestCase.test_vmem_activecCs&td�t}|jtj�j|td�dS)Nzvm.stats.vm.v_inactive_count)rt)rrurvr)rA�inactiver)r-r?rrr�test_vmem_inactive�sz*FreeBSDSpecificTestCase.test_vmem_inactivecCs&td�t}|jtj�j|td�dS)Nzvm.stats.vm.v_wire_count)rt)rrurvr)rA�wiredr)r-r?rrr�test_vmem_wired�sz'FreeBSDSpecificTestCase.test_vmem_wiredcCs&td�t}|jtj�j|td�dS)Nzvm.stats.vm.v_cache_count)rt)rrurvr)rA�cachedr)r-r?rrr�test_vmem_cachedsz(FreeBSDSpecificTestCase.test_vmem_cachedcCs&td�t}|jtj�j|td�dS)Nzvm.stats.vm.v_free_count)rt)rrurvr)rAr7r)r-r?rrr�test_vmem_free	sz&FreeBSDSpecificTestCase.test_vmem_freecCs"td�}|jtj�j|td�dS)Nzvfs.bufspace)rt)rrvr)rA�buffersr)r-r?rrr�test_vmem_bufferssz)FreeBSDSpecificTestCase.test_vmem_bufferszmuse not installedcCstd�}|jtj�j|�dS)NZTotal)rr,r)rAr5)r-rBrrr�test_muse_vmem_totalsz,FreeBSDSpecificTestCase.test_muse_vmem_totalcCs"td�}|jtj�j|td�dS)NZActive)rt)rrvr)rArwr)r-rBrrr�test_muse_vmem_activesz-FreeBSDSpecificTestCase.test_muse_vmem_activecCs"td�}|jtj�j|td�dS)NZInactive)rt)rrvr)rAryr)r-rBrrr�test_muse_vmem_inactive#sz/FreeBSDSpecificTestCase.test_muse_vmem_inactivecCs"td�}|jtj�j|td�dS)NZWired)rt)rrvr)rAr{r)r-rBrrr�test_muse_vmem_wired*sz,FreeBSDSpecificTestCase.test_muse_vmem_wiredcCs"td�}|jtj�j|td�dS)NZCache)rt)rrvr)rAr}r)r-rBrrr�test_muse_vmem_cached1sz-FreeBSDSpecificTestCase.test_muse_vmem_cachedcCs"td�}|jtj�j|td�dS)NZFree)rt)rrvr)rAr7r)r-rBrrr�test_muse_vmem_free8sz+FreeBSDSpecificTestCase.test_muse_vmem_freecCs"td�}|jtj�j|td�dS)NZBuffer)rt)rrvr)rAr�r)r-rBrrr�test_muse_vmem_buffers?sz.FreeBSDSpecificTestCase.test_muse_vmem_bufferscCs|jtj�jtd�dd�dS)Nzvm.stats.sys.v_swtchi�)rt)rvr)�	cpu_stats�ctx_switchesr)r-rrr�test_cpu_stats_ctx_switchesFsz3FreeBSDSpecificTestCase.test_cpu_stats_ctx_switchescCs|jtj�jtd�dd�dS)Nzvm.stats.sys.v_intri�)rt)rvr)r��
interruptsr)r-rrr�test_cpu_stats_interruptsJsz1FreeBSDSpecificTestCase.test_cpu_stats_interruptscCs|jtj�jtd�dd�dS)Nzvm.stats.sys.v_softi�)rt)rvr)r�Zsoft_interruptsr)r-rrr�test_cpu_stats_soft_interruptsNsz6FreeBSDSpecificTestCase.test_cpu_stats_soft_interruptscCs|jtj�jtd�dd�dS)Nzvm.stats.sys.v_syscalli�)rt)rvr)r�Zsyscallsr)r-rrr�test_cpu_stats_syscallsRsz/FreeBSDSpecificTestCase.test_cpu_stats_syscallscCsLtd�}||jd�dd�}|d|jd��}t|�}|j|tj��dS)Nzsysctl kern.boottimez sec = ��,)rrrr,r)�	boot_time)r-�sZbtimerrr�test_boot_time\s
z&FreeBSDSpecificTestCase.test_boot_timez
no batterycCs�dd�}td�}tdd�|jd�D��}tj�}t|djdd	��}|d
}|j|j|�|dkrt|j|j	tj
�n|j||j	�|�dS)NcSs(t|d�\}}t|d�\}}d||fS)N�<z%d:%02d)�divmod)Zsecs�mr��hrrr�
secs2hoursgsz@FreeBSDSpecificTestCase.test_sensors_battery.<locals>.secs2hoursz
acpiconf -i 0cSs(g|] }|jd�d|jd�df�qS)�	rrr])r)�.0�xrrr�
<listcomp>msz@FreeBSDSpecificTestCase.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_batteryesz,FreeBSDSpecificTestCase.test_sensors_batterycCsl|jtj�jtd��|jtj�jtd�dk�tj�j}|dkrT|jtd�d�n|j|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_sysctlxs

z;FreeBSDSpecificTestCase.test_sensors_battery_against_sysctlzhas batteryc	Cs@|jt��td�td�td�WdQRX|jtj��dS)Nzhw.acpi.battery.lifezhw.acpi.battery.timezhw.acpi.acline)ZassertRaisesrGrZassertIsNoner)r�)r-rrr�test_sensors_battery_no_battery�s
z7FreeBSDSpecificTestCase.test_sensors_battery_no_batteryN)&rLrMrNrPr$r%r
r\r^rargrnrsrxrzr|r~rr�r
rQ�MUSE_AVAILABLEr�r�r�r�r�r�r�r�r�r�r�r�rr�r�r�rrrrrR�sF

	rRzOPENBSD onlyc@seZdZdd�ZdS)�OpenBSDSpecificTestCasecCs6td�}tjj|d�}tjjtj��}|j||�dS)Nz
kern.boottimez%a %b %d %H:%M:%S %Y)r�datetimeZstrptimeZ
fromtimestampr)r�r,)r-r�Zsys_btZ	psutil_btrrrr��sz&OpenBSDSpecificTestCase.test_boot_timeN)rLrMrNr�rrrrr��sr�zNETBSD onlyc@s`eZdZedd��Zdd�Zdd�Zdd�Zd	d
�Zdd�Z	d
d�Z
dd�Zdd�Zdd�Z
dS)�NetBSDSpecificTestCasecCsRtdd��2}x*|D]"}|j|�rt|j�d�dSqWWdQRXtd|��dS)Nz
/proc/meminfo�rbriz
can't find %s)�openrrrr)Zlook_for�fr rrr�
parse_meminfo�s


"z$NetBSDSpecificTestCase.parse_meminfocCs|jtj�j|jd��dS)Nz	MemTotal:)r,r)rAr5r�)r-rrr�test_vmem_total�sz&NetBSDSpecificTestCase.test_vmem_totalcCs |jtj�j|jd�td�dS)NzMemFree:)rt)rvr)rAr7r�r)r-rrrr�sz%NetBSDSpecificTestCase.test_vmem_freecCs |jtj�j|jd�td�dS)NzBuffers:)rt)rvr)rAr�r�r)r-rrrr��sz(NetBSDSpecificTestCase.test_vmem_bufferscCs |jtj�j|jd�td�dS)Nz
MemShared:)rt)rvr)rAZsharedr�r)r-rrr�test_vmem_shared�sz'NetBSDSpecificTestCase.test_vmem_sharedcCs |jtj�j|jd�td�dS)Nz
SwapTotal:)rt)rvr)�swap_memoryr5r�r)r-rrr�test_swapmem_total�sz)NetBSDSpecificTestCase.test_swapmem_totalcCs |jtj�j|jd�td�dS)Nz	SwapFree:)rt)rvr)r�r7r�r)r-rrr�test_swapmem_free�sz(NetBSDSpecificTestCase.test_swapmem_freecCs"tj�}|j|j|j|j�dS)N)r)r�r,r6r5r7)r-Zsmemrrr�test_swapmem_used�sz(NetBSDSpecificTestCase.test_swapmem_usedcCsbtdd��8}x0|D] }|jd�rt|j�d�}PqWtd��WdQRX|jtj�j|dd�dS)Nz
/proc/statr�sintrrzcouldn't find linei�)rt)	r�rrrrrvr)r�r�)r-r�r r�rrrr��s

z0NetBSDSpecificTestCase.test_cpu_stats_interruptscCsbtdd��8}x0|D] }|jd�rt|j�d�}PqWtd��WdQRX|jtj�j|dd�dS)Nz
/proc/statr�sctxtrzcouldn't find linei�)rt)	r�rrrrrvr)r�r�)r-r�r r�rrrr��s

z2NetBSDSpecificTestCase.test_cpu_stats_ctx_switchesN)rLrMrN�staticmethodr�r�rr�r�r�r�r�r�r�rrrrr��sr��__main__)"rOr��osrHr+r)rrrrZpsutil.testsrrrr	r
rrr
r�sysconfru�getuidr�rrrQZTestCaser!rRr�r�rL�__file__rrrr�<module>	sL


K


B


?>