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

=_^@sdZddlmZddlZddlZddlZddlZddlZddlZddl	Z	ddl
Z
ddlZddlZddl
Z
ddlZddlZddlZddlmZddlmZddlmZddlmZddlmZdd	lmZdd
lmZddlmZddlmZdd
lmZddlmZddlmZddlmZddlm Z ddlm!Z!ddlm"Z"ddlm#Z#ddlm$Z$ddlm%Z%ddlm&Z&ddlm'Z'ddlm(Z(ddlm)Z)ddlm*Z*ej+,ej+-e.Z/dZ0dZ1dZ2dZ3d Z4erd!Z5ed"Z6d#d$Z7d%d&Z8d'd(Z9d)d*Z:d+d,Z;d-d.Z<d/d0Z=d1d2Z>d3d4Z?ej@d5d6ZAej@d7d8ZBe)Ced9Gd:d;d;eZDe)Ced9Gd<d=d=eZEe)Ced9Gd>d?d?eZFe)Ced9Gd@dAdAeZGe)Ced9GdBdCdCeZHe)Ced9GdDdEdEeZIe)Ced9GdFdGdGeZJe)Ced9GdHdIdIeZKe)Ced9GdJdKdKeZLe)Ced9GdLdMdMeZMe)Ced9GdNdOdOeZNe)Ced9GdPdQdQeZOe)Ced9GdRdSdSeZPe)Ced9GdTdUdUeZQe)Ced9GdVdWdWeZRe)Ced9e)CedXGdYdZdZeZSe)Ced9Gd[d\d\eZTe)Ced9Gd]d^d^eZUe)Ced9Gd_d`d`eZVe)Ced9GdadbdbeZWe)Ced9GdcddddeZXe)Ced9GdedfdfeZYeZdgkrddhl[m\Z\e\e.dS)izLinux specific tests.)divisionN)LINUX)
basestring)FileNotFoundError)PY3)u)
call_until)GLOBAL_TIMEOUT)HAS_BATTERY)HAS_CPU_FREQ)HAS_GETLOADAVG)
HAS_RLIMIT)mock)PsutilTestCase)PYPY)
reload_module)retry_on_failure)safe_rmpath)sh)skip_on_not_implemented)
ThreadTask)TOLERANCE_DISK_USAGE)TOLERANCE_SYS_MEM)unittest)whichiii'iiiz/sys/class/hwmon/hwmon*cCspddl}|dd}tr"t|d}ttjtj}t|*t|	|
tt
d|ddSQRXdS)Nrascii256s)fcntlrbytessocketAF_INET
SOCK_DGRAM
contextlibclosing	inet_ntoaioctlfilenoSIOCGIFADDRstructpack)ifnamer sr/J/opt/alt/python37/lib64/python3.7/site-packages/psutil/tests/test_linux.pyget_ipv4_addressBs

r1cCspddl}|dd}tr"t|d}ttjtj}t|*t|	|
tt
d|ddSQRXdS)Nrrrrrr)r rr!r"r#r$r%r&r'r(r)SIOCGIFNETMASKr+r,)r-r r.r/r/r0get_ipv4_netmaskOs

r3cCspddl}|dd}tr"t|d}ttjtj}t|*t|	|
tt
d|ddSQRXdS)Nrrrrrr)r rr!r"r#r$r%r&r'r(r)SIOCGIFBRDADDRr+r,)r-r r.r/r/r0get_ipv4_broadcast\s

r5c		Cstdd:}x2|D]}|}|d|krPqWtd|WdQRX|d}g}x.tdt|dD]}||||dqhWd|}t	tj
|}ttj
|S)Nz/proc/net/if_inet6rtzcould not find interface %rr:)open	readlinessplit
ValueErrorrangelenappendjoinr"Z	inet_ptonAF_INET6	inet_ntop)	r-flinefieldsZunformattedgroupsiZ	formattedZpackedr/r/r0get_ipv6_addressis
rIc	sddl}|dd}tr"t|d}ttjtj}t|`||	t
td|}trfddnddl
}|jdfdd	|d
dDddSQRXdS)
NrrrrcSs|S)Nr/)xr/r/r0ordszget_mac_address.<locals>.ordcsg|]}d|qS)z%02x:r/).0char)rKr/r0
<listcomp>sz#get_mac_address.<locals>.<listcomp>rr7)r rr!r"r#r$r%r&r(r)
SIOCGIFHWADDRr+r,__builtin__rKrA)r-r r.inforRr/)rKr0get_mac_addresszs

rTcCs|tdddid}|d}xJ|D]B}|dr |\}}}}tdd}|t|t|t|Sq Wtd	d|d
S)zQParse 'free' cmd and return swap memory's s total, used and free
    values.
    zfree -bLANGzC.UTF-8)env
ZSwapfreeztotal used freez&can't find 'Swap' in 'free' output:
%sN)rr<
startswithcollections
namedtupleintr=rA)outlinesrE_totalusedrXntr/r/r0	free_swaps


rccCstdddid}|d}xT|D]L}|dr dd|d	d
D\}}}}tdd}||||||Sq Wtd
d|dS)zSParse 'free' cmd and return physical memory's total, used
    and free values.
    zfree -brUzC.UTF-8)rVrWZMemcSsg|]}t|qSr/)r\)rMrJr/r/r0rOsz free_physmem.<locals>.<listcomp>rXztotal used free shared outputz%can't find 'Mem' in 'free' output:
%sN)rr<rYrZr[r=rA)r]r^rEr`rarXsharedrbr/r/r0free_physmems


"rgcCsVtdddid}x4|dD]&}|}||krt|ddSqWtd|dS)	Nz	vmstat -srUzC.UTF-8)rVrW rz can't find %r in 'vmstat' output)rr<stripr\r=)statr]rEr/r/r0vmstatsrkcCs:td}d|krtdttt|ddS)Nzfree -VZUNKNOWNzcan't determine free versionr7.)rrirSkipTesttuplemapr\r<)r]r/r/r0get_free_version_infos
rpc	#sFfdd}ttrdnd}tj|d|d}|VWdQRXdS)zMock open() builtin and forces it to return a certain `content`
    on read() if the path being opened matches `for_path`.
    csL|kr8tr,ttr tStSqHtSn|f||SdS)N)r
isinstancerioStringIOBytesIO)nameargskwargs)contentfor_path	orig_openr/r0	open_mocks

z$mock_open_content.<locals>.open_mockz
builtins.openz__builtin__.openT)createside_effectN)r:rrpatch)ryrxr{patch_pointmr/)rxryrzr0mock_open_contents
rc	#sFfdd}ttrdnd}tj|d|d}|VWdQRXdS)zZMock open() builtin and raises `exc` if the path being opened
    matches `for_path`.
    cs"|krn|f||SdS)Nr/)rurvrw)excryrzr/r0r{sz&mock_open_exception.<locals>.open_mockz
builtins.openz__builtin__.openT)r|r}N)r:rrr~)ryrr{rrr/)rryrzr0mock_open_exceptions
rz
LINUX onlyc@seZdZddZeddZeddZeddZed	d
ZeddZ	ed
dZ
eddZddZeddZ
ddZddZddZddZdS)TestSystemVirtualMemorycCs&tdd}tj}|||dS)Nztotal memoryi)rkpsutilvirtual_memoryr`assertAlmostEqual)selfvmstat_valuepsutil_valuer/r/r0
test_totals
z"TestSystemVirtualMemory.test_totalcCsLtdkr|dt}|j}tj}|j||td|||jfddS)N)rzold free versionz	%s %s 
%s)deltamsg)	rpZskipTestrgrarrrroutput)rrX
free_valuerr/r/r0	test_useds


z!TestSystemVirtualMemory.test_usedcCs*tdd}tj}|j||tddS)Nzfree memoryi)r)rkrrrXrr)rrrr/r/r0	test_frees
z!TestSystemVirtualMemory.test_freecCs*tdd}tj}|j||tddS)Nz
buffer memoryi)r)rkrrbuffersrr)rrrr/r/r0test_bufferss
z$TestSystemVirtualMemory.test_bufferscCs*tdd}tj}|j||tddS)Nz
active memoryi)r)rkrractiverr)rrrr/r/r0test_actives
z#TestSystemVirtualMemory.test_activecCs*tdd}tj}|j||tddS)Nzinactive memoryi)r)rkrrinactiverr)rrrr/r/r0
test_inactives
z%TestSystemVirtualMemory.test_inactivecCsJt}|j}|dkrtdtj}|j||td|||jfddS)Nrz%free does not support 'shared' columnz	%s %s 
%s)rr)	rgrfrrmrrrrr)rrXrrr/r/r0test_shared#s

z#TestSystemVirtualMemory.test_sharedcCshtd}|d}d|dkr*tdn:t|dd}tj}|j||t	d|||fd	dS)
Nzfree -brW	availablerz(free does not support 'available' columnrdr7z	%s %s 
%s)rr)
rr<rrmr\rrrrr)rr]r^rrr/r/r0test_available.s

z&TestSystemVirtualMemory.test_availablec
CsJtdtd*}tjdd}tdt}|	t
|d|d}|dt|j
|d	t|j
|d
t|j
|dt|j
|dt|j
|d
t|j
|dt|j
|	|jd|	|jd|	|jd|	|jd|	|jd|	|jd|	|jdWdQRXWdQRXdS)Nz
/proc/meminfoap                Active(anon):    6145416 kB
                Active(file):    2950064 kB
                Inactive(anon):   574764 kB
                Inactive(file):  1567648 kB
                MemAvailable:         -1 kB
                MemFree:         2057400 kB
                MemTotal:       16325648 kB
                SReclaimable:     346648 kB
                T)recordalwaysrdrz#memory stats couldn't be determinedcachedrfrrrr)rtextwrapdedentencodewarningscatch_warningssimplefilterrrassertEqualr?assertInstrmessagerrrrfrrslab)rrwsretwr/r/r0test_warnings_on_misses=s0	
z/TestSystemVirtualMemory.test_warnings_on_missesc
	Csddlm}ddlm}i}|d4}x,|D]$}|}t|dd||d<q,WWdQRX||}d|kr|d}t|||d}	||	d	dS)
Nr)calculate_avail_vmem)open_binaryz
/proc/meminfordis
MemAvailable:dr)psutil._pslinuxrrr<r\absZ
assertLess)
rrrZmemsrDrErFabZdiff_percentr/r/r0test_avail_old_percentds

&z.TestSystemVirtualMemory.test_avail_old_percentc
CsltdtdN}tjdd}t}WdQRX||j	d|d}|
dt|jWdQRXdS)Nz
/proc/meminfoaL                Active:          9444728 kB
                Active(anon):    6145416 kB
                Active(file):    2950064 kB
                Buffers:          287952 kB
                Cached:          4818144 kB
                Inactive(file):  1578132 kB
                Inactive(anon):   574764 kB
                Inactive(file):  1567648 kB
                MemAvailable:    6574984 kB
                MemFree:         2057400 kB
                MemTotal:       16325648 kB
                Shmem:            577588 kB
                SReclaimable:     346648 kB
                T)rl "rz,inactive memory stats couldn't be determined)
rrrrrrrrrrrrr)rrrrrr/r/r0 test_avail_old_comes_from_kernelwsz8TestSystemVirtualMemory.test_avail_old_comes_from_kernelc
CsltdtdN}tjdd}t}WdQRX||j	d|d}|
dt|jWdQRXdS)Nz
/proc/meminfoa                    Active:          9444728 kB
                    Active(anon):    6145416 kB
                    Buffers:          287952 kB
                    Cached:          4818144 kB
                    Inactive(file):  1578132 kB
                    Inactive(anon):   574764 kB
                    MemFree:         2057400 kB
                    MemTotal:       16325648 kB
                    Shmem:            577588 kB
                    T)rl`LGrz,inactive memory stats couldn't be determined)
rrrrrrrrrrrrr)rrrrrr/r/r0test_avail_old_missing_fieldss
z5TestSystemVirtualMemory.test_avail_old_missing_fieldscCstdtdltdttjdNtj	dd6}t
}||j
d|d}|d	t|jWdQRXWdQRXWdQRXdS)
Nz
/proc/meminfoaT                    Active:          9444728 kB
                    Active(anon):    6145416 kB
                    Active(file):    2950064 kB
                    Buffers:          287952 kB
                    Cached:          4818144 kB
                    Inactive(file):  1578132 kB
                    Inactive(anon):   574764 kB
                    Inactive(file):  1567648 kB
                    MemFree:         2057400 kB
                    MemTotal:       16325648 kB
                    Shmem:            577588 kB
                    SReclaimable:     346648 kB
                    z/proc/zoneinfozno such file or directoryT)rl`LGrz,inactive memory stats couldn't be determined)rrrrrIOErrorerrnoENOENTrrrrrrrrr)rrrrr/r/r0test_avail_old_missing_zoneinfos

z7TestSystemVirtualMemory.test_avail_old_missing_zoneinfoc	sfdd}ttrdnd}tj|d|d}t}||jd||jd||j	d	||j
d
||jd||jd||j
d
||jd||jdWdQRXdS)Ncs0|dkrttdS|f||SdS)Nz
/proc/meminfoa=	                    MemTotal:              100 kB
                    MemFree:               2 kB
                    MemAvailable:          3 kB
                    Buffers:               4 kB
                    Cached:                5 kB
                    SwapCached:            6 kB
                    Active:                7 kB
                    Inactive:              8 kB
                    Active(anon):          9 kB
                    Inactive(anon):        10 kB
                    Active(file):          11 kB
                    Inactive(file):        12 kB
                    Unevictable:           13 kB
                    Mlocked:               14 kB
                    SwapTotal:             15 kB
                    SwapFree:              16 kB
                    Dirty:                 17 kB
                    Writeback:             18 kB
                    AnonPages:             19 kB
                    Mapped:                20 kB
                    Shmem:                 21 kB
                    Slab:                  22 kB
                    SReclaimable:          23 kB
                    SUnreclaim:            24 kB
                    KernelStack:           25 kB
                    PageTables:            26 kB
                    NFS_Unstable:          27 kB
                    Bounce:                28 kB
                    WritebackTmp:          29 kB
                    CommitLimit:           30 kB
                    Committed_AS:          31 kB
                    VmallocTotal:          32 kB
                    VmallocUsed:           33 kB
                    VmallocChunk:          34 kB
                    HardwareCorrupted:     35 kB
                    AnonHugePages:         36 kB
                    ShmemHugePages:        37 kB
                    ShmemPmdMapped:        38 kB
                    CmaTotal:              39 kB
                    CmaFree:               40 kB
                    HugePages_Total:       41 kB
                    HugePages_Free:        42 kB
                    HugePages_Rsvd:        43 kB
                    HugePages_Surp:        44 kB
                    Hugepagesize:          45 kB
                    DirectMap46k:          46 kB
                    DirectMap47M:          47 kB
                    DirectMap48G:          48 kB
                    )rrrtrrr)rurvrw)rzr/r0r{s1zETestSystemVirtualMemory.test_virtual_memory_mocked.<locals>.open_mockz
builtins.openz__builtin__.openT)r|r}iiiipiTii iXi)r:rrr~rrrr`rXrrrfrrrr)rr{rrmemr/)rzr0test_virtual_memory_mockeds7z2TestSystemVirtualMemory.test_virtual_memory_mockedN)__name__
__module____qualname__rrrrrrrrrrrrrrrr/r/r/r0rs'rc@s\eZdZeddZddZeddZeddZd	d
Z	ddZ
d
dZddZdS)TestSystemSwapMemoryc	Cs,td}|}WdQRXd|ko*d|kS)z3Return True if /proc/meminfo provides swap metrics.z
/proc/meminfoNz
SwapTotal:z	SwapFree:)r:read)rDdatar/r/r0meminfo_has_swap_infos
z*TestSystemSwapMemory.meminfo_has_swap_infocCs"tj}tj}|j||tdS)N)r)rcr`rswap_memoryrr)rrrr/r/r0r$s
zTestSystemSwapMemory.test_totalcCs"tj}tj}|j||tdS)N)r)rcrarrrr)rrrr/r/r0r*s
zTestSystemSwapMemory.test_usedcCs"tj}tj}|j||tdS)N)r)rcrXrrrr)rrrr/r/r0r1s
zTestSystemSwapMemory.test_freec
Cstjdddv}tjdd^}tdt}|t|d|d}|	dt
|j||jd||j
dWdQRXWdQRXdS)	Nzpsutil._common.openT)r|)rrrdrz9'sin' and 'sout' swap memory stats couldn't be determined)rr~rrrrrrr?rrrsinsout)rrrrrr/r/r0test_missing_sin_sout8s
z*TestSystemSwapMemory.test_missing_sin_soutc
Cstdttjdv}tjdd^}tdt}|	t
|d|d}|dt|j
|	|jd|	|jdWdQRXWdQRXdS)	Nz/proc/vmstatzno such file or directoryT)rrrdrzK'sin' and 'sout' swap memory stats couldn't be determined and were set to 0)rrrrrrrrrrr?rrrrr)rrrrrr/r/r0test_no_vmstat_mockedGs
z*TestSystemSwapMemory.test_no_vmstat_mockedc	Cs|stdStd}t}WdQRXddlm}|	\}}}}}}}||9}||9}|
|j||j|j
|tddS)Nz!/proc/meminfo has no swap metricsz"psutil._pslinux.cext.linux_sysinfor)r)rrskiprr~rrZpsutil._psutil_linuxZ
_psutil_linuxZ
linux_sysinforr`rrXr)rrswapZcextr_r`rXZunit_multiplierr/r/r0test_meminfo_against_sysinfoZs
z1TestSystemSwapMemory.test_meminfo_against_sysinfoc	Cs"tdd}tWdQRXdS)Nz
/proc/meminfo)rrr)rrr/r/r0#test_emulate_meminfo_has_no_metricsjsz8TestSystemSwapMemory.test_emulate_meminfo_has_no_metricsN)
rrrstaticmethodrrrrrrrrrr/r/r/r0rsrc@seZdZddZdS)TestSystemCPUTimescCstj}tdtdd}ttt	|
d}|dkrL|d|n|d||dkrn|d|n|d||d	kr|d
|n|d
|dS)Nz
\d+\.\d+\.\d+rrl)rsteal)rrrZguest)rrrZ
guest_nice)
r	cpu_times_fieldsrefindallosunamernror\r<rassertNotIn)rrFZ
kernel_verZkernel_ver_infor/r/r0test_fields{s
zTestSystemCPUTimes.test_fieldsN)rrrrr/r/r/r0rxsrc@seZdZeejddddZeejddddZ	ee
d	d
ddZee
d
dddZddZ
dS)TestSystemCPUCountLogicalz/sys/devices/system/cpu/onlinez-/sys/devices/system/cpu/online does not existc	CsVtd}|}WdQRXdt|krRt|ddd}|t|dS)Nz/sys/devices/system/cpu/online-rd)	r:rrirr\r<rr	cpu_count)rrDvaluer/r/r0test_against_sysdev_cpu_onlines

z8TestSystemCPUCountLogical.test_against_sysdev_cpu_onlinez/sys/devices/system/cpuz&/sys/devices/system/cpu does not existcCs0td}tdd|D}|t|dS)Nz/sys/devices/system/cpucSs g|]}td|dk	r|qS)zcpu\d+$N)rsearch)rMrJr/r/r0rOszITestSystemCPUCountLogical.test_against_sysdev_cpu_num.<locals>.<listcomp>)rlistdirr?rrr)rZlscountr/r/r0test_against_sysdev_cpu_nums
z5TestSystemCPUCountLogical.test_against_sysdev_cpu_numZnprocznproc utility not availablecCs$ttd}|tjdd|dS)Nznproc --allT)logical)r\rrrr)rnumr/r/r0test_against_nprocsz,TestSystemCPUCountLogical.test_against_nproclscpuzlscpu utility not availablecCs8td}tdd|dD}|tjdd|dS)Nzlscpu -pcSsg|]}|ds|qS)#)rY)rMrJr/r/r0rOsz@TestSystemCPUCountLogical.test_against_lscpu.<locals>.<listcomp>rWT)r)rr?r<rrr)rr]rr/r/r0test_against_lscpusz,TestSystemCPUCountLogical.test_against_lscpuc
Csddl}|j}tjdtd}||j|tjddd:}||j||jd||j	dddWdQRXt
d	d
}|}WdQRXt
|}tjd|dd}||j|WdQRXtd	d}||j||jWdQRXWdQRXdS)
Nrzpsutil._pslinux.os.sysconf)r}zpsutil._common.openT)r|rz
/proc/statz
/proc/cpuinforb)return_valuer|r)r_pslinuxZcpu_count_logicalrr~r=rassertIsNoneZ
call_count	call_argsr:rrrrtrZcalled)rrZoriginalrrDZcpuinfo_data	fake_filer/r/r0test_emulate_fallbackss$
 
z0TestSystemCPUCountLogical.test_emulate_fallbacksN)rrrrskipIfrpathexistsrrrrrrr/r/r/r0rsrc@s6eZdZeeddddZddZddZd	S)
TestSystemCPUCountPhysicalrzlscpu utility not availablecCs`td}t}x4|dD]&}|ds|d}||dqW|tjddt|dS)Nzlscpu -prWr,rdF)r)	rsetr<rYaddrrrr?)rr]Zcore_idsrErFr/r/r0rs

z-TestSystemCPUCountPhysical.test_against_lscpuc	CsFtj}tjdgd}tj}WdQRX|dk	rB|||dS)Nz	glob.glob)r)rrcpu_count_physicalrr~r)rZmeth_1rZmeth_2r/r/r0
test_method_2s


z(TestSystemCPUCountPhysical.test_method_2c
CsHtjdgd0}tjddd}|tjWdQRXWdQRXdS)Nz	glob.glob)rzpsutil._common.openT)r|)rr~rrrr)rm1m2r/r/r0test_emulate_nones$z,TestSystemCPUCountPhysical.test_emulate_noneN)	rrrrrrrrrr/r/r/r0rs
rc@szeZdZeedddZeedddZeedddZeeddd	Z	eedd
dZ
dS)
TestSystemCPUFrequencyz
not supportedc	s4fdd}tjjtjd|ddWdQRXdS)Ncs|drdS|SdS)Nz&/sys/devices/system/cpu/cpufreq/policyF)rY)r)orig_existsr/r0path_exists_mocks
zMTestSystemCPUFrequency.test_emulate_use_second_file.<locals>.path_exists_mockzos.path.existsT)r}r|)rrrrr~)rrr/)rr0test_emulate_use_second_files

z3TestSystemCPUFrequency.test_emulate_use_second_filec	sfdd}gtjjz~tjd|dfttjt}|	|j
d|	|jdx0tjddD] }|	|j
d|	|jdqhWWdQRXWdttjttXdS)Ncs,|drdS|dkr d|SdS)Nz/sys/devices/system/cpu/Fz
/proc/cpuinfo)rYr@)r)flagsos_path_existsr/r0rs


zITestSystemCPUFrequency.test_emulate_use_cpuinfo.<locals>.path_exists_mockzos.path.exists)r}gT)percpu)rrrrr~rrrcpu_freqrmaxmin)rrrfreqr/)rrr0test_emulate_use_cpuinfos
 
z/TestSystemCPUFrequency.test_emulate_use_cpuinfoc
sfdd}ttrdnd}tj||dftjdddLt}||jd	|jd
krj||jd|j	d
kr||j	dWdQRXWdQRXdS)
Ncs|dr|drtdS|dr<|dr<tdS|drZ|drZtdS|dkrltd	S|f||SdS)
Nz/scaling_cur_freqz&/sys/devices/system/cpu/cpufreq/policys500000z/scaling_min_freqs600000z/scaling_max_freqs700000z
/proc/cpuinfoscpu MHz		: 500)endswithrYrrrt)rurvrw)rzr/r0r{s









z;TestSystemCPUFrequency.test_emulate_data.<locals>.open_mockz
builtins.openz__builtin__.open)r}zos.path.existsT)rg@@gg@g@)
r:rrr~rrrcurrentr	r)rr{rr
r/)rzr0test_emulate_datas

z(TestSystemCPUFrequency.test_emulate_datacsfdd}ttrdnd}tj||dtjdddtjd	d
dtjdd}||djd
|djdkr||djd|dj	dkr||dj	d||djd|djdkr||djd|dj	dkr||dj	dWdQRXWdQRXWdQRXdS)Ncs|}|dr"|dr"tdS|dr@|dr@tdS|dr^|dr^tdS|dr||dr|td	S|dr|drtd
S|dr|drtdS|dkrtd
S|f||SdS)Nz/scaling_cur_freqz'/sys/devices/system/cpu/cpufreq/policy0s100000z/scaling_min_freqs200000z/scaling_max_freqs300000z'/sys/devices/system/cpu/cpufreq/policy1s400000s500000s600000z
/proc/cpuinfoscpu MHz		: 100
cpu MHz		: 400)rrYrrrt)rurvrwn)rzr/r0r{9s,


















z@TestSystemCPUFrequency.test_emulate_multi_cpu.<locals>.open_mockz
builtins.openz__builtin__.open)r}zos.path.existsT)rz!psutil._pslinux.cpu_count_logicalr)rrgY@ggi@gr@rdgy@g@@g@)
r:rrr~rrrr
r	r)rr{rr
r/)rzr0test_emulate_multi_cpu7s$
z-TestSystemCPUFrequency.test_emulate_multi_cpucsfdd}ttrdnd}tj||dPtjddd6tjd	d
dt}||jdWdQRXWdQRXWdQRXdS)NcsR|drttjdn6|dr,tdS|dkr>tdS|f||SdS)Nz/scaling_cur_freqrLz/cpuinfo_cur_freqs200000z
/proc/cpuinfoscpu MHz		: 200)rrrrrrrt)rurvrw)rzr/r0r{hs



zOTestSystemCPUFrequency.test_emulate_no_scaling_cur_freq_file.<locals>.open_mockz
builtins.openz__builtin__.open)r}zos.path.existsT)rz!psutil._pslinux.cpu_count_logicalrd)r:rrr~rrrr
)rr{rr
r/)rzr0%test_emulate_no_scaling_cur_freq_filees

z<TestSystemCPUFrequency.test_emulate_no_scaling_cur_freq_fileN)rrrrrrrrrrrr/r/r/r0rs
.rc@seZdZddZddZdS)TestSystemCPUStatscCs&td}tj}|j||dddS)Nzcontext switchesi)r)rkr	cpu_statsZctx_switchesr)rrrr/r/r0test_ctx_switchess
z$TestSystemCPUStats.test_ctx_switchescCs&td}tj}|j||dddS)N
interruptsi)r)rkrrrr)rrrr/r/r0test_interruptss
z"TestSystemCPUStats.test_interruptsN)rrrrrr/r/r/r0r|src@s"eZdZeedddZdS)TestLoadAvgz
not supportedc	Cst}tdd}|}WdQRX|jt|d|ddd|jt|d|ddd|jt|d|ddddS)Nz
/proc/loadavgrrrd)rr)r
getloadavgr:rr<rfloat)rrrDZ
proc_valuer/r/r0test_getloadavgszTestLoadAvg.test_getloadavgN)rrrrrrrr/r/r/r0rsrc@seZdZddZdS)TestSystemNetIfAddrscCsxtD]\}}x|D]}|jtjkr@||jt|q|jtj	kr||jt
|||jt||j
dk	r||j
t|q|t|dq|jtjkr|jdd}||t|qWqWdS)Nz0.0.0.0%r)rZnet_if_addrsitemsZfamilyZAF_LINKraddressrTr"r#r1Znetmaskr3Z	broadcastr5rBr<rI)rruZaddrsZaddrr r/r/r0test_ipss

zTestSystemNetIfAddrs.test_ipsN)rrrr!r/r/r/r0rsrc@seZdZddZddZdS)TestSystemNetIfStatsc	CsxxrtD]b\}}ytd|}Wntk
r:YqX|j|jd|k|d||jtt	
d|dqWdS)Nzifconfig %sZRUNNING)rz(?i)MTU[: ](\d+)r)rnet_if_statsrrRuntimeErrorrZisupmtur\rr)rrustatsr]r/r/r0test_against_ifconfigsz*TestSystemNetIfStats.test_against_ifconfigc
CsRxLtD]<\}}td|d }||jt|WdQRXqWdS)Nz/sys/class/net/%s/mtur6)	rr#rr:rr%r\rri)rrur&rDr/r/r0test_mtuszTestSystemNetIfStats.test_mtuN)rrrr'r(r/r/r/r0r"sr"c@seZdZeddZdS)TestSystemNetIOCountersc	sfdd}tjddd}x|D]\}y|}Wntk
rNw$YnX|j|j|ddd|j|j|d	dd|j|j|d
dd|j|j|ddd|j|j	|d
dd|j|j
|ddd|j|j|ddd|j|j|dddq$WdS)Ncsi}td}ttd|d|d<ttd|d|d<ttd|d|d<ttd|d	|d
<ttd|d|d<ttd|d	|d
<ttd|d|d<ttd|d|d<|S)Nzifconfig %szRX packets[: ](\d+)rpackets_recvzTX packets[: ](\d+)packets_sentzerrors[: ](\d+)errinrderroutzdropped[: ](\d+)dropindropoutz#RX (?:packets \d+ +)?bytes[: ](\d+)
bytes_recvz#TX (?:packets \d+ +)?bytes[: ](\d+)
bytes_sent)rr\rr)Znicrr])rur/r0ifconfigsz?TestSystemNetIOCounters.test_against_ifconfig.<locals>.ifconfigTF)Zpernicnowrapr0i)rr1r*ir+r,
r-r.r/)
rnet_io_countersrr$rr0r1r*r+r,r-r.r/)rr2Znior&Zifconfig_retr/)rur0r's.z-TestSystemNetIOCounters.test_against_ifconfigN)rrrrr'r/r/r/r0r)sr)c@s8eZdZejdedejdddddZdd	Zd
S)TestSystemNetConnectionsz psutil._pslinux.socket.inet_ntop)r}zpsutil._pslinux.supports_ipv6F)rcCsRy*ttjtj}||j|dWntjk
r@YnXtjdddS)N)z::1rZinet6)kind)	r"rBZSOCK_STREAMZ
addCleanupcloseZbinderrorrnet_connections)rZ
supports_ipv6rCr.r/r/r0test_emulate_ipv6_unsupportedsz6TestSystemNetConnections.test_emulate_ipv6_unsupportedc	Cs,tdtd}tjddWdQRXdS)Nz/proc/net/unixa.                0: 00000003 000 000 0001 03 462170 @/tmp/dbus-Qw2hMPIU3n
                0: 00000003 000 000 0001 03 35010 @/tmp/dbus-tB2X8h69BQ
                0: 00000003 000 000 0001 03 34424 @/tmp/dbus-cHy80Y8O
                000000000000000000000000000000000000000000000000000000
                Zunix)r7)rrrrr:)rrr/r/r0test_emulate_unixs
z*TestSystemNetConnections.test_emulate_unixN)rrrrr~r=r;r<r/r/r/r0r6	sr6c@s>eZdZeeeddeddZddZ	ddZ
d	S)
TestSystemDiskPartitionsstatvfszos.statvfs() not availablecCsrdd}xdtjddD]T}t|j}||j\}}}}||j||j|j|td|j|j	|tdqWdS)NcSsztd|}|d}|d|d}|dd\}}}}|dkrRd}t|t|t|}}}||||fS)Nzdf -P -B 1 "%s"rWrr8ZnonerL)rrir<popr\)rr]r^rEdevr`rarXr/r/r0df2s


z4TestSystemDiskPartitions.test_against_df.<locals>.dfF)all)r)
rdisk_partitionsZ
disk_usageZ
mountpointrr`rrXrra)rrApartZusager@r`rarXr/r/r0test_against_df-s

z(TestSystemDiskPartitions.test_against_dfc
Cstdd}|}WdQRXd|krPxtD]}|jdkr0Pq0W|dn`ttd}t	j
d|dd<}t	j
d	d
gd }t}||djdWdQRXWdQRXdS)
Nz/proc/filesystemsrzfszcouldn't find any ZFS partitionz
nodev	zfs
zpsutil._common.openT)rr|z$psutil._pslinux.cext.disk_partitions)z	/dev/sdb3/rFZrw)rr)r:rrrCZfstypeZfailrrrsrrr~r)rrDrrDrrrrr/r/r0test_zfs_fsFs
z$TestSystemDiskPartitions.test_zfs_fsc
CsJz<tjddd$}|ttWdQRXWdQRXWddt_XdS)Nzos.path.realpathz
/non/existent)rz/proc)rr~assertRaisesrrrCPROCFS_PATH)rrr/r/r0test_emulate_realpath_fail^s
z3TestSystemDiskPartitions.test_emulate_realpath_failN)rrrrrhasattrrrrErHrKr/r/r/r0r=*sr=c@sDeZdZddZddZddZddZd	d
ZddZd
dZ	dS)TestSystemDiskIoCountersc
Cstddtjdddtjdd}||jd||jd	||jd
t	||j
d||jd||jd
||j
dt	||jd||jdWdQRXWdQRXdS)Nz/proc/diskstatsz+   3     0   1 hda 2 3 4 5 6 7 8 9 10 11 12z!psutil._pslinux.is_storage_deviceT)rF)r3rdrrr8rerr4)rrr~rdisk_io_countersr
read_countread_merged_count
read_bytesSECTOR_SIZE	read_timewrite_countwrite_merged_countwrite_bytes
write_time	busy_time)rrr/r/r0test_emulate_kernel_2_4ms
z0TestSystemDiskIoCounters.test_emulate_kernel_2_4c
Cstddtjdddtjdd}||jd||jd	||jd
t	||j
d||jd||jd
||j
dt	||jd||jdWdQRXWdQRXdS)Nz/proc/diskstatsz'   3    0   hda 1 2 3 4 5 6 7 8 9 10 11z!psutil._pslinux.is_storage_deviceT)rF)r3rdrrr8rerrNrOr4)rrr~rrPrrQrRrSrTrUrVrWrXrYrZ)rrr/r/r0test_emulate_kernel_2_6_fulls
z5TestSystemDiskIoCounters.test_emulate_kernel_2_6_fullc
Cstddtjdddtjdd}||jd||jd	t||j	d
||j
dt||jd||jd||j
d||jd||jdWdQRXWdQRXdS)
Nz/proc/diskstatsz   3    1   hda 1 2 3 4z!psutil._pslinux.is_storage_deviceT)rF)r3rdrrr8r)rrr~rrPrrQrSrTrVrXrRrUrWrYrZ)rrr/r/r0test_emulate_kernel_2_6_limiteds
z8TestSystemDiskIoCounters.test_emulate_kernel_2_6_limitedc
Cstdtdtjdddltjddd}|t|d||d	j	d
||dj	d
||d	j
d||dj
dWdQRXWdQRXdS)
Nz/proc/diskstatsz                    3    0   nvme0n1 1 2 3 4 5 6 7 8 9 10 11
                    3    0   nvme0n1p1 1 2 3 4 5 6 7 8 9 10 11
                    z!psutil._pslinux.is_storage_deviceF)rT)perdiskr3rnvme0n1rdZ	nvme0n1p1re)rrrrr~rrPrr?rQrV)rrr/r/r0test_emulate_include_partitionss

z8TestSystemDiskIoCounters.test_emulate_include_partitionsc
Cstdtd8tjdddtjddd}||WdQRXWdQRXdd}tdtdLtjdd	|d
0tjddd}||j	d||j
dWdQRXWdQRXdS)
Nz/proc/diskstatsz                    3    0   nvme0n1 1 2 3 4 5 6 7 8 9 10 11
                    3    0   nvme0n1p1 1 2 3 4 5 6 7 8 9 10 11
                    z!psutil._pslinux.is_storage_deviceF)r)r^r3cSs|dkS)Nr_r/)rur/r/r0is_storage_deviceszSTestSystemDiskIoCounters.test_emulate_exclude_partitions.<locals>.is_storage_deviceT)r|r}rdre)rrrrr~rrPrrrQrV)rrrar/r/r0test_emulate_exclude_partitionss$


z8TestSystemDiskIoCounters.test_emulate_exclude_partitionsc	CsTdd}tjdd}tjdd|dtjdd}WdQRX|t|t|dS)NcSs|dkrdSdS)Nz/proc/diskstatsFTr/)rr/r/r0rsz?TestSystemDiskIoCounters.test_emulate_use_sysfs.<locals>.existsT)r^zpsutil._pslinux.os.path.exists)r|r})rrPrr~rr?)rrZwprocfsZwsysfsr/r/r0test_emulate_use_sysfssz/TestSystemDiskIoCounters.test_emulate_use_sysfsc	Cs6dd}tjdd|d|ttjWdQRXdS)NcSsdS)NFr/)rr/r/r0rsz>TestSystemDiskIoCounters.test_emulate_not_impl.<locals>.existszpsutil._pslinux.os.path.existsT)r|r})rr~rINotImplementedErrorrrP)rrr/r/r0test_emulate_not_implsz.TestSystemDiskIoCounters.test_emulate_not_implN)
rrrr[r\r]r`rbrcrer/r/r/r0rMjsrMc@sReZdZddZddZddZddZd	d
ZddZe	d
dZ
ddZdS)TestMisccCs(td}t}|t|t|dS)Nz	boot time)rkr	boot_timerr\)rrrr/r/r0test_boot_timeszTestMisc.test_boot_timec
s|}t|ttj|dd$}|d|d|dWdQRXztfdd}trldnd	}tj	||d
nt
t|t
tj|jt
tjdd|t
tj|jt
tjdd|t
tj|jt
tjdd|t_|td
|ttd
tjdd}|t|d
tjdd}|ttt|d
ttj|dd$}|d|d|dWdQRX|td
|ttjddd
|ttd
|ttttjddd
WdQRXWdt|t
tX|tjddS)Nrjrzcpu   0 0 0 0 0 0 0 0 0 0
zcpu0  0 0 0 0 0 0 0 0 0 0
zcpu1  0 0 0 0 0 0 0 0 0 0
cs&|drttjd|f||S)Nz/proczrejecting access for test)rYrrr)rurvrw)rzr/r0r{s
z4TestMisc.test_no_procfs_on_import.<locals>.open_mockz
builtins.openz__builtin__.open)r}T)rrzcpu   1 0 0 0 0 0 0 0 0 0
zcpu0  1 0 0 0 0 0 0 0 0 0
zcpu1  1 0 0 0 0 0 0 0 0 0
z/proc)
get_testfnrmkdirr:rrAwriterrr~rrrIrrcpu_percentcpu_times_percentrJrsumroassertNotEqualshutilZrmtree)rZ	my_procfsrDr{rZper_cpu_percentZper_cpu_times_percentr/)rzr0test_no_procfs_on_importsN




(

z!TestMisc.test_no_procfs_on_importc	Cstdtd.}ttjddttjddWdQRXtdtd}t}tjdd}t}tjdd}||d|t|d|t|d|t|d|tt	t|d|tt	t|d|
|jd||jdWdQRXdS)Nz
/proc/statz                cpu   0 0 0 0 0 0 0 1 0 0
                cpu0  0 0 0 0 0 0 0 1 0 0
                cpu1  0 0 0 0 0 0 0 1 0 0
                T)rz                cpu   1 0 0 0 0 0 0 0 0 0
                cpu0  1 0 0 0 0 0 0 0 0 0
                cpu1  1 0 0 0 0 0 0 0 0 0
                rgY@)
rrrrrrlrmrornrorruser)rrrlZcpu_percent_percpurmZcpu_times_percent_percpur/r/r0test_cpu_steal_decrease<s0z TestMisc.test_cpu_steal_decreasec	Cs.tjddd}|ttjjWdQRXdS)Nzpsutil._common.openT)r|)rr~rIr$rrrg)rrr/r/r0test_boot_time_mockedes

zTestMisc.test_boot_time_mockedc	Cstjddgd}|tdjdWdQRXtjddgd}|tdjdWdQRXtjddgd}|tdjdWdQRXdS)	Nzpsutil._pslinux.cext.users)	giampaolozpts/2z:0ghATr)rrZ	localhost)ruzpts/2z:0.0ghATr)ruzpts/2fooghATrrv)rr~rrZusersZhost)rrr/r/r0test_users_mockedls




zTestMisc.test_users_mockedcCs|}t|z|t_|ttj|ttj|jttjdd|ttj	|ttj
|ttj|ttj|ttj
|tjtjWddt_XdS)NT)rz/proc)rirrjrrJrIrrrrgr:r5r#rCZ
NoSuchProcessProcess)rZtdirr/r/r0test_procfs_paths
zTestMisc.test_procfs_pathcCst}|zjt}|}|t|dt|ddddj}|	|j
|t|}|||t
Wd|XdS)NrcSs|jS)N)id)rJr/r/r0<lambda>rz)TestMisc.test_issue_687.<locals>.<lambda>)keyrd)rstartrrxthreadsrr?sortedrzropidZas_dictrZpidsstop)rtpr~tidZptr/r/r0test_issue_687s
zTestMisc.test_issue_687c	Cstdd}WdQRXdS)Nz/proc/%s/statusrL)r)rrr/r/r0test_pid_exists_no_proc_statussz'TestMisc.test_pid_exists_no_proc_statusN)rrrrhrqrsrtrwryrrrr/r/r/r0rfs=)rfz
no batteryc@sfeZdZeeddddZddZddZd	d
Z	ddZ
d
dZddZddZ
ddZdS)TestSensorsBatteryZacpizacpi utility not availablecCsDtd}t|dddd}tj}|j||dddS)Nzacpi -brrdrrL)r)	rr\r<rireplacersensors_batterypercentr)rr]Z
acpi_valuerr/r/r0test_percents
zTestSensorsBattery.test_percentc	s`fdd}ttrdnd}tj||d,}|tjd|tjtj	WdQRXdS)Ncs2|ds|drtdS|f||SdS)Nz
AC0/onlinez	AC/online1)rrrrt)rurvrw)rzr/r0r{s
z@TestSensorsBattery.test_emulate_power_plugged.<locals>.open_mockz
builtins.openz__builtin__.open)r}T)
r:rrr~rrr
power_pluggedZsecsleftZPOWER_TIME_UNLIMITED)rr{rrr/)rzr0test_emulate_power_pluggedsz-TestSensorsBattery.test_emulate_power_pluggedc	sLfdd}ttrdnd}tj||d}|tjdWdQRXdS)NcsN|ds|dr"ttjdn(|dr:ttdS|f||SdS)Nz
AC0/onlinez	AC/onlinerLz/statusZcharging)rrrrrrrsr)rurvrw)rzr/r0r{s

zBTestSensorsBattery.test_emulate_power_plugged_2.<locals>.open_mockz
builtins.openz__builtin__.open)r}T)r:rrr~rrrr)rr{rrr/)rzr0test_emulate_power_plugged_2sz/TestSensorsBattery.test_emulate_power_plugged_2c	sLfdd}ttrdnd}tj||d}|tjdWdQRXdS)Ncs2|ds|drtdS|f||SdS)Nz
AC0/onlinez	AC/online0)rrrrt)rurvrw)rzr/r0r{s
zDTestSensorsBattery.test_emulate_power_not_plugged.<locals>.open_mockz
builtins.openz__builtin__.open)r}F)r:rrr~rrrr)rr{rrr/)rzr0test_emulate_power_not_pluggedsz1TestSensorsBattery.test_emulate_power_not_pluggedc	sLfdd}ttrdnd}tj||d}|tjdWdQRXdS)NcsN|ds|dr"ttjdn(|dr:ttdS|f||SdS)Nz
AC0/onlinez	AC/onlinerLz/statusZdischarging)rrrrrrrsr)rurvrw)rzr/r0r{s

zFTestSensorsBattery.test_emulate_power_not_plugged_2.<locals>.open_mockz
builtins.openz__builtin__.open)r}F)r:rrr~rrrr)rr{rrr/)rzr0 test_emulate_power_not_plugged_2sz3TestSensorsBattery.test_emulate_power_not_plugged_2c	sJfdd}ttrdnd}tj||d}|tjWdQRXdS)NcsJ|ds|dr"ttjdn$|dr6tdS|f||SdS)Nz"/sys/class/power_supply/AC0/onlinez!/sys/class/power_supply/AC/onlinerLz#/sys/class/power_supply/BAT0/statuss???)rYrrrrrrt)rurvrw)rzr/r0r{s



zETestSensorsBattery.test_emulate_power_undetermined.<locals>.open_mockz
builtins.openz__builtin__.open)r})r:rrr~rrrr)rr{rrr/)rzr0test_emulate_power_undetermineds	z2TestSensorsBattery.test_emulate_power_undeterminedc	Cs,tdd}|tjdWdQRXdS)Nz(/sys/class/power_supply/BAT0/energy_fullrr)rrrrr)rrr/r/r0test_emulate_energy_full_0s
z-TestSensorsBattery.test_emulate_energy_full_0cCshtdttjdLtdttjd.tdd|tjdWdQRXWdQRXWdQRXdS)Nz(/sys/class/power_supply/BAT0/energy_fullrLz(/sys/class/power_supply/BAT0/charge_fullz%/sys/class/power_supply/BAT0/capacitys88X)	rrrrrrrrr)rr/r/r0"test_emulate_energy_full_not_avails
z5TestSensorsBattery.test_emulate_energy_full_not_availcCsntdttjdRtdttjd4tdttjd|tjWdQRXWdQRXWdQRXdS)Nz!/sys/class/power_supply/AC/onlinerLz"/sys/class/power_supply/AC0/onlinez#/sys/class/power_supply/BAT0/status)rrrrrrrr)rr/r/r0test_emulate_no_power'sz(TestSensorsBattery.test_emulate_no_powerN)rrrrrrrrrrrrrrrr/r/r/r0rs
rc@seZdZddZdS)TestSensorsBatteryEmulatedc
sdfdd}ttrdnd}tjddgd.}tj||d}|tWdQRXWdQRXdS)	Ncs\|drttdS|dr0ttdS|drHttdS|f||SdS)Nz/energy_nowZ60000000z
/power_now0z/energy_fullZ60000001)rrrrsr)rurvrw)rzr/r0r{9s


z5TestSensorsBatteryEmulated.test_it.<locals>.open_mockz
builtins.openz__builtin__.openz
os.listdirZBAT0)r)r})r:rrr~ZassertIsNotNonerr)rr{rZmlistdirZmopenr/)rzr0test_it8s
"z"TestSensorsBatteryEmulated.test_itN)rrrrr/r/r/r0r5src@seZdZddZddZdS)TestSensorsTemperaturesc
sfdd}ttrdnd}tj||djtjddgdNtd	d
}||jd||jd||j	d
||j
dWdQRXWdQRXdS)Ncs|drttdS|dr0ttdS|drDtdS|drXtdS|d	rltd
S|f||SdS)Nz/nameruz/temp1_labellabelz/temp1_inputs30000z
/temp1_maxs40000z/temp1_crits50000)rrrrsrrt)rurvrw)rzr/r0r{Ps







zCTestSensorsTemperatures.test_emulate_class_hwmon.<locals>.open_mockz
builtins.openz__builtin__.open)r}z	glob.globz/sys/class/hwmon/hwmon0/temp1)rrurrg>@gD@gI@)r:rrr~rsensors_temperaturesrrr
highcritical)rr{rtempr/)rzr0test_emulate_class_hwmonOsz0TestSensorsTemperatures.test_emulate_class_hwmonc
sfdd}dd}ttr dnd}tj||djtjdd	|d
Ntdd}||jd
||jd||j	d||j
dWdQRXWdQRXdS)Ncsl|drtdS|dr(tdS|dr@ttdS|drXttdS|f||SdS)	NZ0_temps50000rs30000Z0_typertyperu)rrrrtrsr)rurvrw)rzr/r0r{ks





zETestSensorsTemperatures.test_emulate_class_thermal.<locals>.open_mockcSs:|dkrgS|dkrgS|dkr&dgS|dkr6ddgSgS)Nz/sys/class/hwmon/hwmon*/temp*_*z&/sys/class/hwmon/hwmon*/device/temp*_*z /sys/class/thermal/thermal_zone*z /sys/class/thermal/thermal_zone0z,/sys/class/thermal/thermal_zone0/trip_point*z2/sys/class/thermal/thermal_zone1/trip_point_0_typez2/sys/class/thermal/thermal_zone1/trip_point_0_tempr/)rr/r/r0	glob_mockwszETestSensorsTemperatures.test_emulate_class_thermal.<locals>.glob_mockz
builtins.openz__builtin__.open)r}z	glob.globT)r|r}rurrLg>@gI@)r:rrr~rrrrr
rr)rr{rrrr/)rzr0test_emulate_class_thermaljsz2TestSensorsTemperatures.test_emulate_class_thermalN)rrrrrr/r/r/r0rLsrc@seZdZddZdS)TestSensorsFansc
sfdd}ttrdnd}tj||dNtjddgd2td	d
}||jd||jdWdQRXWdQRXdS)
Ncs\|drttdS|dr0ttdS|drHttdS|f||SdS)Nz/nameruz/fan1_labelrz/fan1_inputZ2000)rrrrsr)rurvrw)rzr/r0r{s


z4TestSensorsFans.test_emulate_data.<locals>.open_mockz
builtins.openz__builtin__.open)r}z	glob.globz/sys/class/hwmon/hwmon2/fan1)rrurri)	r:rrr~rZsensors_fansrrr
)rr{rZfanr/)rzr0rs
z!TestSensorsFans.test_emulate_dataN)rrrrr/r/r/r0rsrc@seZdZeddZddZeedddZ	dd	Z
d
dZdd
ZddZ
ddZddZddZddZddZddZeedddZdd Zd!d"Zd#d$Zd%S)&TestProcesscCs|}td|}||}tddd|t|j}t	d|
}|jdd}|j|j
tdd	|Dd
d|j|jtdd	|Dd
d|j|jtd
d	|Dd
ddS)Nzk
            import time
            with open("%s", "w") as f:
                time.sleep(10)
            cSs
tdS)Nrl)rrr/r/r/r0r{rz3TestProcess.test_memory_full_info.<locals>.<lambda>z'%s' not in retg?F)ZgroupedcSsg|]}|j|jqSr/)Z
private_dirtyZ
private_clean)rMrJr/r/r0rOsz5TestProcess.test_memory_full_info.<locals>.<listcomp>i)rcSsg|]
}|jqSr/)pss)rMrJr/r/r0rOscSsg|]
}|jqSr/)r)rMrJr/r/r0rOs)rirrZpyrunrrrxrtimeZsleepmemory_full_infomemory_mapsrussrnrr)rtestfnsrcZsprocrrmapsr/r/r0test_memory_full_infos 


z!TestProcess.test_memory_full_infoc	Csftdttd@}t}|}|	|j
d|	|jd|	|jdWdQRXdS)Nz/proc/%s/smapsa                fffff0 r-xp 00000000 00:00 0                  [vsyscall]
                Size:                  1 kB
                Rss:                   2 kB
                Pss:                   3 kB
                Shared_Clean:          4 kB
                Shared_Dirty:          5 kB
                Private_Clean:         6 kB
                Private_Dirty:         7 kB
                Referenced:            8 kB
                Anonymous:             9 kB
                LazyFree:              10 kB
                AnonHugePages:         11 kB
                ShmemPmdMapped:        12 kB
                Shared_Hugetlb:        13 kB
                Private_Hugetlb:       14 kB
                Swap:                  15 kB
                SwapPss:               16 kB
                KernelPageSize:        17 kB
                MMUPageSize:           18 kB
                Locked:                19 kB
                VmFlags: rd ex
                ilii<)
rrgetpidrrrrrxrrrrr)rrrrr/r/r0test_memory_full_info_mockeds
z(TestProcess.test_memory_full_info_mockedzunreliable on PYPYc	Csjdd}|}t|d|||jdWdQRXt|d|||jdWdQRXt|d|||jdWdQRXt|d|||jdWdQRXt|d|||jdWdQRXt|d|||jdWdQRXtrft|t|d	|||jdWdQRXt|t|d
|||jdWdQRXdS)NcSs\t}tt}x:x4|D](}|jtj|kr:|St|kr Pq WqWtddS)Nztimeout looking for test file)	rrxrr	
open_filesrrabspathr$)ZfnamerZ	giveup_atfiler/r/r0
get_test_files
z7TestProcess.test_open_files_mode.<locals>.get_test_filerrrzr+zw+za+rJzx+)rir:rmoderr)rrrr/r/r0test_open_files_modes*z TestProcess.test_open_files_modec
Cst}|}t|dvt|jdt|tjdt	t
jdd}|}WdQRXtjdt	t
jdd}|
|gWdQRXWdQRXdS)Nrzlen(ret) != %izpsutil._pslinux.os.readlinkrL)r})rrxrr:rirr?rr~OSErrorrrZEINVALr)rrfilesrr/r/r0test_open_files_file_gones
z%TestProcess.test_open_files_file_gonec
Csxt}|}t|dPt|jdt|tr<dnd}tj	|t
tjdd}|}WdQRXWdQRXdS)Nrzlen(ret) != %iz
builtins.openz__builtin__.openrL)r})
rrxrr:rirr?rrr~rrr)rrrrrr/r/r0test_open_files_fd_gone sz#TestProcess.test_open_files_fd_gonec	Cs8tjdid }|tjtWdQRXdS)Nz)psutil._pslinux._psposix.get_terminal_map)r)	rr~rrrrxrrZterminal)rrr/r/r0test_terminal_mocked2s
z TestProcess.test_terminal_mockedc	Cst}ttd}tjd|dd}||ddgWdQRXttd}tjd|dd}||dddgWdQRXdS)	Nzfoobarzpsutil._common.openT)rr|rvbarz	foobarrL)	rrxrrrsrrr~rcmdline)rrrrr/r/r0test_cmdline_mocked@s
zTestProcess.test_cmdline_mockedc	Cst}ttd}tjd|dd}||ddgWdQRXttd}tjd|dd}||dddgWdQRXdS)	Nzfoo bar zpsutil._common.openT)rr|rvrz	foo bar  rL)	rrxrrrsrrr~rr)rrrrr/r/r0test_cmdline_spaces_mockedNs
z&TestProcess.test_cmdline_spaces_mockedc	CsJt}ttd}tjd|dd}||ddgWdQRXdS)Nzfoo barzpsutil._common.openT)rr|rvr)	rrxrrrsrrr~rr)rrrrr/r/r0test_cmdline_mixed_separators\sz)TestProcess.test_cmdline_mixed_separatorsc	CsFtjddd.|td|tdWdQRXdS)Nzpsutil._pslinux.os.readlinkz/home/foo (deleted))rz	/home/foo)rr~rrrxexecwd)rr/r/r0!test_readlink_path_deleted_mockedfs
z-TestProcess.test_readlink_path_deleted_mockedc	sfdd}ttrdnd}tj||d}t}||gWdQRXfdd}tj||d|tj	tjWdQRXdS)Ncs4|dtr ttjdn|f||SdS)Nz
/proc/%s/taskrL)rYrrrrr)rurvrw)rzr/r0r{qsz2TestProcess.test_threads_mocked.<locals>.open_mockz
builtins.openz__builtin__.open)r}cs4|dtr ttjdn|f||SdS)Nz
/proc/%s/taskrL)rYrrrrZEPERM)rurvrw)rzr/r0r{s)
r:rrr~rrxr~rrIAccessDenied)rr{rrrr/)rzr0test_threads_mockedlszTestProcess.test_threads_mockedcCstjdttjddn}tjdtdddL}t}|	|dtjddd|
tjtjWdQRXWdQRXWdQRXdS)	Nzpsutil._pslinux.readlinkrL)r}zpsutil.Process.cmdlinerzpsutil._pslinux.os.path.lexistsF)r)rr~rrrrrrxrrrI
ZombieProcess)rrrrr/r/r0test_exe_mockeds
zTestProcess.test_exe_mockedc
CsPtdtttjd,}t}|t	|
WdQRXWdQRXdS)Nz/proc/%s/smapsrL)rrrrrrrrxrIrr)rrrr/r/r0test_issue_1014s
zTestProcess.test_issue_1014z
not supportedc
Cstjdttjdd:}t}||tj	}|
tjWdQRXWdQRX||j
j|j||j
j|dS)Nzpsutil._pslinux.prlimitrL)r})rr~rrZENOSYSrrxrurIrZrlimitZ
RLIMIT_NOFILEr	exceptionr)rrrrr/r/r0test_rlimit_zombies
zTestProcess.test_rlimit_zombiec
Cs|tjdttjdd6}t}||tj	}|
WdQRXWdQRX||jj
|j
||jj|dS)Nzpsutil._pslinux.os.readlinkrL)r})rr~rrrrrxrurIrrrrr)rrrrr/r/r0test_cwd_zombies
zTestProcess.test_cwd_zombiec*Cs\ddlm}dddddddddddddddd	d
dddddddddddddddddddddddddg*}d
|}tdt|t}|	|
d|	|tj|	|
d|	|d|t|}|	|jd||	|jd||	|jd||	|jd||	|jd||	|dWdQRXdS)Nr)CLOCK_TICKSrz(cat)Z1234567rhz
/proc/%s/statcatrdrrrr8rerN)rrrArrrrrrxrrustatusZ
STATUS_ZOMBIEppidZcreate_timergrrrsystem
children_userchildren_systemZiowaitZcpu_num)rrrvrxrZcpur/r/r0test_stat_file_parsingstz"TestProcess.test_stat_file_parsingc	Cstdttdt}||	j
d||	jd||d|
}||jd||jd||jd|}||jd	||jd
||jd||jttdd
WdQRXdS)Nz/proc/%s/statusa                Uid:	1000	1001	1002	1003
                Gid:	1004	1005	1006	1007
                Threads:	66
                Cpus_allowed:	f
                Cpus_allowed_list:	0-7
                voluntary_ctxt_switches:	12
                nonvoluntary_ctxt_switches:	13r
BiiiiiirrO)rrrrrrrrxrnum_ctx_switches	voluntaryinvoluntarynum_threadsuidsrealZ	effectiveZsavedgids_proc_get_eligible_cpuslistr>)rrrrr/r/r0test_status_file_parsings"
z$TestProcess.test_status_file_parsingN)rrrrrrrrrrrrrrrrrrrrr
rrrrr/r/r/r0rs"#%
?rc@sreZdZdZeddZddZddZdd	Zd
dZ	dd
Z
ddZddZe
ddZddZddZdS)TestProcessAgainstStatusa/proc/pid/stat and /proc/pid/status have many values in common.
    Whenever possible, psutil uses /proc/pid/stat (it's faster).
    For all those cases we check that the value found in
    /proc/pid/stat (by psutil) matches the one found in
    /proc/pid/status.
    cCst|_dS)N)rrxproc)clsr/r/r0
setUpClass%sz#TestProcessAgainstStatus.setUpClassc
Cs|tjd|jj^}xJ|D]B}|}||r|dd}yt|St	k
r\|SXqWt	d|WdQRXdS)Nz/proc/%s/status	rz
can't find %r)
r_psplatformZ	open_textrrrirY	partitionr\r=)rZ	linestartrDrErr/r/r0read_status_file)s


z)TestProcessAgainstStatus.read_status_filecCs |d}||j|dS)NzName:)rrrru)rrr/r/r0	test_name6s
z"TestProcessAgainstStatus.test_namecCsH|d}||dd|d}|dd}||j|dS)NzState:(rd)rhr)rfindrfindrrrr)rrr/r/r0test_status:s
z$TestProcessAgainstStatus.test_statuscCs |d}||j|dS)NzPPid:)rrrr)rrr/r/r0	test_ppid@s
z"TestProcessAgainstStatus.test_ppidcCs |d}||j|dS)NzThreads:)rrrr)rrr/r/r0test_num_threadsDs
z)TestProcessAgainstStatus.test_num_threadscCs:|d}ttt|dd}||j|dS)NzUid:rdr8)rrnror\r<rrr)rrr/r/r0	test_uidsHs
z"TestProcessAgainstStatus.test_uidscCs:|d}ttt|dd}||j|dS)NzGid:rdr8)rrnror\r<rrr)rrr/r/r0	test_gidsMs
z"TestProcessAgainstStatus.test_gidscCs@|d}||jj||d}||jj|dS)Nzvoluntary_ctxt_switches:znonvoluntary_ctxt_switches:)rrrrrr)rrr/r/r0test_num_ctx_switchesRs

z.TestProcessAgainstStatus.test_num_ctx_switchescCsN|d}dt|krJtt|d\}}||jtt	||ddS)NzCpus_allowed_list:rrd)
rrror\r<rrZcpu_affinityrr>)rrZmin_Zmax_r/r/r0test_cpu_affinityYs

z*TestProcessAgainstStatus.test_cpu_affinityc	Cs>|d}td}|jjWdQRXdt|kr:ndS)NzCpus_allowed_list:zpsutil._pslinux.per_cpu_timesr)rrr~rrrr)rrrr/r/r0test_cpu_affinity_eligible_cpus`s
z8TestProcessAgainstStatus.test_cpu_affinity_eligible_cpusN)rrr__doc__classmethodrrrrrrrrrrrrr/r/r/r0rs
rc@seZdZddZddZdS)	TestUtilsc	Cs2tjddd}|tjddWdQRXdS)Nzos.readlinkz
foo (deleted))rrrv)rr~rrrreadlink)rrr/r/r0
test_readlinkrszTestUtils.test_readlinkc	Csx|}t|d}|dWdQRX|tjj|ddd|tjj|ddd|tjj|dd	d
d	dS)NZwtzfoo F)ZbinaryrvTsfooz??r)Zfallback)rir:rkrrrr)rrrDr/r/r0test_catwszTestUtils.test_catN)rrrrrr/r/r/r0rosr__main__)
run_from_name)]rZ
__future__rrZr%rZglobrrrrrpr"r+rrrrrZpsutil._compatrrrrZpsutil.testsrr	r
rrr
rrrrrrrrrrrrrrrdirname__file__ZHEREr*ZSIOCGIFCONFrQr2r4rTZEMPTY_TEMPERATURESr1r3r5rIrTrcrgrkrpcontextmanagerrrrrrrrrrrrrr"r)r6r=rMrfrrrrrrrrZpsutil.tests.runnerrr/r/r/r0<module>s


	.]?
)- ?
?
}ArR