• File: test_bsd.cpython-37.pyc
  • Full Path: /home3/farmfre2/public_html/ALFA_DATA/alfasymlink/root/opt/alt/python37/lib64/python3.7/site-packages/psutil/tests/__pycache__/test_bsd.cpython-37.pyc
  • Date Modified: 04/24/2023 7:25 PM
  • File size: 19.48 KB
  • MIME-type: text/x-bytecode.python
  • Charset: 8 bit
B

=_P@sdZddlZddlZddlZddlZddlZddlmZddlmZddlmZddlm	Z	ddl
mZddl
mZdd	l
m
Z
dd
l
mZddl
mZddl
mZdd
l
mZddl
mZddl
mZerddlmZeZedkredrdndZndZdZddZddZeedGddde
ZeedGddde
ZeedGddde
Zee	dGd d!d!e
Zeed"Gd#d$d$e
Z e!d%krdd&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)getpagesizemuseTFcCshtd|}tr(||ddd}nts0trF||ddd}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
rfindrrint
ValueError)cmdlineresultrH/opt/alt/python37/lib64/python3.7/site-packages/psutil/tests/test_bsd.pysysctl-srcCs@td}x&|dD]}||rPqWtdt|dS)z+Thin wrapper around 'muse' cmdline utility.r
zline not foundr)r
split
startswithrr)Zfieldoutlinerrrr<s
zBSD onlyc@seZdZdZeddZeddZee	dddZ
d	d
Zeeddd
dZ
eeddddZddZdS)BSDTestCasez)Generic tests common to all BSD variants.cCstj|_dS)N)rpid)clsrrr
setUpClassPszBSDTestCase.setUpClasscCst|jdS)N)rr")r#rrr
tearDownClassTszBSDTestCase.tearDownClassz -o lstart doesn't work on NETBSDcCsPtd|j}|dd}t|j}tdt	|}|
||dS)Nzps -o lstart -p %sZSTARTEDz%a %b %e %H:%M:%S %Y)r
r"replacestrippsutilProcessZcreate_timetimeZstrftimeZ	localtimeassertEqual)selfoutputZstart_psZstart_psutilrrrtest_process_create_timeXsz$BSDTestCase.test_process_create_timecCsdd}xtjddD]}t|j}||j\}}}}||j|||j|t|j|dkrz|	d|j|ft|j
|dkr|	d|j
|fqWdS)NcSstd|}|d}|d|d}|dd\}}}}|dkrRd}t|d}t|d}t|d}||||fS)Nz
df -k "%s"rrZnoner&i)r
r(rpopr)pathrlinesr devtotalusedfreerrrdfds


z"BSDTestCase.test_disks.<locals>.dfF)allizpsutil=%s, df=%s)r)Zdisk_partitionsZ
disk_usageZ
mountpointr,Zdevicer5absr7Zfailr6)r-r8partZusager4r5r6r7rrr
test_disksas
zBSDTestCase.test_disksrzsysctl cmd not availablecCs td}|tjdd|dS)Nzhw.ncpuT)Zlogical)rr,r)	cpu_count)r-systrrrtest_cpu_count_logical|sz"BSDTestCase.test_cpu_count_logicalcCstd}||tjdS)Nz
hw.physmem)rr,r)virtual_memoryr5)r-numrrrtest_virtual_memory_totalsz%BSDTestCase.test_virtual_memory_totalc	CsxztD]j\}}ytd|}Wntk
r:YqX|j|jd|k|dd|kr||jtt	
d|dqWdS)Nzifconfig %sZRUNNING)msgmtuz	mtu (\d+)r)r)Znet_if_statsitemsr
RuntimeErrorr,ZisuprDrrefindall)r-nameZstatsrrrrtest_net_if_statsszBSDTestCase.test_net_if_statsN)__name__
__module____qualname____doc__classmethodr$r%r
skipIfrr/r<rr?rBrJrrrrr!Ls	r!zFREEBSD onlyc@sfeZdZeddZeddZeddZddZd	d
Z	ddZ
ed
dZeddZdS)FreeBSDPsutilTestCasecCstj|_dS)N)rr")r#rrrr$sz FreeBSDPsutilTestCase.setUpClasscCst|jdS)N)rr")r#rrrr%sz#FreeBSDPsutilTestCase.tearDownClasscCstd|j}t|jjdd}|ddd}x||r|}|}|dd\}}}}	}
|}|d||f|j|t	|
|j
|jds6||d	|jq6WdS)
Nzprocstat -v %sF)Zgroupedrrz%s-%s[
)
r
r"r)r*Zmemory_mapsrr1r,ZaddrrZrssr2r)r-rmapsr3r fields_startstopZpermsZresmaprrrtest_memory_mapssz&FreeBSDPsutilTestCase.test_memory_mapscCs<td|j}|t|j|ddddS)Nzprocstat -b %srr)r
r"r,r)r*Zexer)r-rrrrtest_exeszFreeBSDPsutilTestCase.test_execCsLtd|j}|dt|jd|dddddS)Nzprocstat -c %s rrr)r
r"r,joinr)r*rr)r-rrrrtest_cmdlinesz"FreeBSDPsutilTestCase.test_cmdlinecCstd|j}|dddd\}}}}}}t|j}|}	|}
||	jt	|||	j
t	|||	jt	|||
jt	|||
j
t	|||
jt	|dS)Nzprocstat -s %srrr)r
r"rr)r*uidsgidsr,realrZ	effectiveZsaved)r-rZeuidZruidZsuidZegidZrgidZsgidprbrcrrrtest_uids_gidss&z$FreeBSDPsutilTestCase.test_uids_gidscCsg}td|j}t|j}x|dD]}|}d|krtt|d}|j	}|
|||dq*d|kr*t|d}|j}|
|||dq*Wt
|dkrtddS)Nzprocstat -r %srz voluntary contextr\z involuntary contextrz)couldn't find lines match in procstat out)r
r"r)r*rlowerr(rZnum_ctx_switchesZ	voluntaryr,appendZinvoluntarylenrF)r-testedrrer pstat_valuepsutil_valuerrrtest_ctx_switchess"

z'FreeBSDPsutilTestCase.test_ctx_switchescCsg}td|j}t|j}x|dD]}|}d|krtd|ddd}|j	}|
|||dq*d|kr*td|ddd}|j}|
|||dq*Wt
|dkrtd	dS)
Nzprocstat -r %srz	user timez0.r\.zsystem timerz)couldn't find lines match in procstat out)r
r"r)r*rrgr(floatZ	cpu_timesuserr,rhsystemrirF)r-rjrrer rkrlrrrtest_cpu_timess"

z$FreeBSDPsutilTestCase.test_cpu_timesN)
rKrLrMrOr$r%r	r[r]r`rfrmrrrrrrrQs
rQc@seZdZeddZddZeddZeddZed	d
Z	eddZ
ed
dZeddZe
edddZe
ededdZe
ededdZe
ededdZe
ededdZe
ededdZe
ededdZd d!Zd"d#Zd$d%Zed&d'Zd(d)Zd*d+Zd,d-Zd.d/Ze
ed0d1d2Z e
ed0d3d4Z!e
ed5d6d7Z"d8d9Z#d:S);FreeBSDSystemTestCasecCsRtdd}td|}|s,td|dd|ddD\}}}|||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.partsr5r6r7rrrparse_swapinfosz$FreeBSDSystemTestCase.parse_swapinfocCsd}ytt|}Wntk
r2|dYnX|tj|d}t|}t|ddd}t|ddd}|tj	||tj
|dS)Nzdev.cpu.0.freqz#frequencies not supported by kernelzdev.cpu.0.freq_levelsr/r\)rrrFskipTestr,r)Zcpu_freqcurrentrmaxmin)r-sensor
sysctl_resultZmax_freqZmin_freqrrr!test_cpu_frequency_against_sysctlsz7FreeBSDSystemTestCase.test_cpu_frequency_against_sysctlcCs&tdt}|jtj|tddS)Nzvm.stats.vm.v_active_count)delta)rPAGESIZEassertAlmostEqualr)r@activer)r-r>rrrtest_vmem_activesz&FreeBSDSystemTestCase.test_vmem_activecCs&tdt}|jtj|tddS)Nzvm.stats.vm.v_inactive_count)r)rrrr)r@inactiver)r-r>rrrtest_vmem_inactivesz(FreeBSDSystemTestCase.test_vmem_inactivecCs&tdt}|jtj|tddS)Nzvm.stats.vm.v_wire_count)r)rrrr)r@wiredr)r-r>rrrtest_vmem_wired$sz%FreeBSDSystemTestCase.test_vmem_wiredcCs&tdt}|jtj|tddS)Nzvm.stats.vm.v_cache_count)r)rrrr)r@cachedr)r-r>rrrtest_vmem_cached*sz&FreeBSDSystemTestCase.test_vmem_cachedcCs&tdt}|jtj|tddS)Nzvm.stats.vm.v_free_count)r)rrrr)r@r7r)r-r>rrrtest_vmem_free0sz$FreeBSDSystemTestCase.test_vmem_freecCs"td}|jtj|tddS)Nzvfs.bufspace)r)rrr)r@buffersr)r-r>rrrtest_vmem_buffers6sz'FreeBSDSystemTestCase.test_vmem_bufferszmuse not installedcCstd}|tj|dS)NZTotal)rr,r)r@r5)r-rArrrtest_muse_vmem_total>sz*FreeBSDSystemTestCase.test_muse_vmem_totalcCs"td}|jtj|tddS)NZActive)r)rrr)r@rr)r-rArrrtest_muse_vmem_activeCsz+FreeBSDSystemTestCase.test_muse_vmem_activecCs"td}|jtj|tddS)NZInactive)r)rrr)r@rr)r-rArrrtest_muse_vmem_inactiveJsz-FreeBSDSystemTestCase.test_muse_vmem_inactivecCs"td}|jtj|tddS)NZWired)r)rrr)r@rr)r-rArrrtest_muse_vmem_wiredQsz*FreeBSDSystemTestCase.test_muse_vmem_wiredcCs"td}|jtj|tddS)NZCache)r)rrr)r@rr)r-rArrrtest_muse_vmem_cachedXsz+FreeBSDSystemTestCase.test_muse_vmem_cachedcCs"td}|jtj|tddS)NZFree)r)rrr)r@r7r)r-rArrrtest_muse_vmem_free_sz)FreeBSDSystemTestCase.test_muse_vmem_freecCs"td}|jtj|tddS)NZBuffer)r)rrr)r@rr)r-rArrrtest_muse_vmem_buffersfsz,FreeBSDSystemTestCase.test_muse_vmem_bufferscCs|jtjtddddS)Nzvm.stats.sys.v_swtchi)r)rr)	cpu_statsctx_switchesr)r-rrrtest_cpu_stats_ctx_switchesmsz1FreeBSDSystemTestCase.test_cpu_stats_ctx_switchescCs|jtjtddddS)Nzvm.stats.sys.v_intri)r)rr)r
interruptsr)r-rrrtest_cpu_stats_interruptsqsz/FreeBSDSystemTestCase.test_cpu_stats_interruptscCs|jtjtddddS)Nzvm.stats.sys.v_softi)r)rr)rZsoft_interruptsr)r-rrrtest_cpu_stats_soft_interruptsusz4FreeBSDSystemTestCase.test_cpu_stats_soft_interruptscCs|jtjtddddS)Nzvm.stats.sys.v_syscalli@
)r)rr)rZsyscallsr)r-rrrtest_cpu_stats_syscallsysz-FreeBSDSystemTestCase.test_cpu_stats_syscallscCs(|\}}}|jtj|tddS)N)r)rxrr)swap_memoryr7r)r-r5r6r7rrrtest_swapmem_freesz'FreeBSDSystemTestCase.test_swapmem_freecCs(|\}}}|jtj|tddS)N)r)rxrr)rr6r)r-r5r6r7rrrtest_swapmem_usedsz'FreeBSDSystemTestCase.test_swapmem_usedcCs(|\}}}|jtj|tddS)N)r)rxrr)rr5r)r-r5r6r7rrrtest_swapmem_totalsz(FreeBSDSystemTestCase.test_swapmem_totalcCsLtd}||ddd}|d|d}t|}||tdS)Nzsysctl kern.boottimez sec = ,)rrrr,r)	boot_time)r-sZbtimerrrtest_boot_times
z$FreeBSDSystemTestCase.test_boot_timez
no batterycCsdd}td}tdd|dD}t}t|ddd	}|d
}||j||dkrt||j	tj
n|||j	|dS)NcSs(t|d\}}t|d\}}d||fS)N<z%d:%02d)divmod)Zsecsmrhrrr
secs2hourssz>FreeBSDSystemTestCase.test_sensors_battery.<locals>.secs2hoursz
acpiconf -i 0cSs(g|] }|dd|ddfqS)	rr\)r)rtxrrr
<listcomp>sz>FreeBSDSystemTestCase.test_sensors_battery.<locals>.<listcomp>rzRemaining capacity:%r&zRemaining time:unknown)r
dictrr)sensors_batteryrr'r,percentsecsleftZPOWER_TIME_UNLIMITED)r-rrrVZmetricsrZremaining_timerrrtest_sensors_batterysz*FreeBSDSystemTestCase.test_sensors_batterycCsl|tjtd|tjtddktj}|dkrT|tddn||tdddS)Nzhw.acpi.battery.lifezhw.acpi.aclinerrzhw.acpi.battery.timer\r)r,r)rrrZ
power_pluggedr)r-rrrr#test_sensors_battery_against_sysctls

z9FreeBSDSystemTestCase.test_sensors_battery_against_sysctlzhas batteryc	Cs@|ttdtdtdWdQRX|tdS)Nzhw.acpi.battery.lifezhw.acpi.battery.timezhw.acpi.acline)ZassertRaisesrFrZassertIsNoner)r)r-rrrtest_sensors_battery_no_batterys
z5FreeBSDSystemTestCase.test_sensors_battery_no_batteryc	Cstd}xt|D]}d|}yttt|dd}Wntk
rZ|dYnX|jt	d|j
|ddd|}ttt|dd}|t	d|j|qWdS)	NTzdev.cpu.%s.temperaturer\z$temperatures not supported by kernelZcoretemprT)rzdev.cpu.%s.coretemp.tjmax)
r)r=rangerrorrFrzrZsensors_temperaturesr{r,Zhigh)r-Znum_cpusZcpur~rrrr(test_sensors_temperatures_against_sysctls

z>FreeBSDSystemTestCase.test_sensors_temperatures_against_sysctlN)$rKrLrMstaticmethodrxrr	rrrrrrr
rPMUSE_AVAILABLErrrrrrrrrrrrrrrrrrrrrrrrrssB
	
rszOPENBSD onlyc@seZdZddZdS)OpenBSDTestCasecCs6td}tj|d}tjt}|||dS)Nz
kern.boottimez%a %b %d %H:%M:%S %Y)rdatetimeZstrptimeZ
fromtimestampr)rr,)r-rZsys_btZ	psutil_btrrrrszOpenBSDTestCase.test_boot_timeN)rKrLrMrrrrrrsrzNETBSD onlyc@s`eZdZeddZddZddZddZd	d
ZddZ	d
dZ
ddZddZddZ
dS)NetBSDTestCasec	CsRtdd2}x*|D]"}||rt|ddSqWWdQRXtd|dS)Nz
/proc/meminfoZrtriz
can't find %s)openrrrr)Zlook_forfr rrr
parse_meminfos


"zNetBSDTestCase.parse_meminfocCs|tj|ddS)Nz	MemTotal:)r,r)r@r5r)r-rrrtest_vmem_totalszNetBSDTestCase.test_vmem_totalcCs |jtj|dtddS)NzMemFree:)r)rr)r@r7rr)r-rrrrszNetBSDTestCase.test_vmem_freecCs |jtj|dtddS)NzBuffers:)r)rr)r@rrr)r-rrrrsz NetBSDTestCase.test_vmem_bufferscCs |jtj|dtddS)Nz
MemShared:)r)rr)r@Zsharedrr)r-rrrtest_vmem_sharedszNetBSDTestCase.test_vmem_sharedcCs |jtj|dtddS)Nz
SwapTotal:)r)rr)rr5rr)r-rrrrsz!NetBSDTestCase.test_swapmem_totalcCs |jtj|dtddS)Nz	SwapFree:)r)rr)rr7rr)r-rrrrsz NetBSDTestCase.test_swapmem_freecCs"t}||j|j|jdS)N)r)rr,r6r5r7)r-Zsmemrrrrsz NetBSDTestCase.test_swapmem_usedc	Csbtdd8}x0|D] }|drt|d}PqWtdWdQRX|jtj|dddS)Nz
/proc/statrbsintrrzcouldn't find linei)r)	rrrrrrr)rr)r-rr rrrrrs

z(NetBSDTestCase.test_cpu_stats_interruptsc	Csbtdd8}x0|D] }|drt|d}PqWtdWdQRX|jtj|dddS)Nz
/proc/statrsctxtrzcouldn't find linei)r)	rrrrrrr)rr)r-rr rrrrr*s

z*NetBSDTestCase.test_cpu_stats_ctx_switchesN)rKrLrMrrrrrrrrrrrrrrrrsr__main__)
run_from_name)%rNrosrGr+r)rrrrZpsutil.testsrrrr	r
rrr
rZpsutil._psutil_posixrrgetuidrrrrPr!rQrsrrrKZpsutil.tests.runnerr__file__rrrr<module>
sPKYrB