B =_^@sdZddlmZddlZddlZddlZddlZddlZddlZddl Z ddl Z ddl Z ddl Z ddl Z ddlZddlZddlZddlmZddlmZddlmZddlmZddlmZdd lmZdd lmZdd lmZdd 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.Zd3d4Z?ej@d5d6ZAej@d7d8ZBe)Ce d9Gd:d;d;eZDe)Ce d9Gdd?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*c Cspddl}|dd}tr"t|d}ttjtj}t|*t| | t t d|ddSQRXdS)Nrascii256s)fcntlrbytessocketAF_INET SOCK_DGRAM contextlibclosing inet_ntoaioctlfileno SIOCGIFADDRstructpack)ifnamer sr/J/opt/alt/python37/lib64/python3.7/site-packages/psutil/tests/test_linux.pyget_ipv4_addressBs    r1c Cspddl}|dd}tr"t|d}ttjtj}t|*t| | t t d|ddSQRXdS)Nrrrrrr)r rr!r"r#r$r%r&r'r(r)SIOCGIFNETMASKr+r,)r-r r.r/r/r0get_ipv4_netmaskOs    r3c Cspddl}|dd}tr"t|d}ttjtj}t|*t| | t t 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 |}t tj |S)Nz/proc/net/if_inet6rtzcould not find interface %rr:) open readlinessplit ValueErrorrangelenappendjoinr"Z inet_ptonAF_INET6 inet_ntop) r-flinefieldsZ unformattedgroupsiZ formattedZpackedr/r/r0get_ipv6_addressis   rIc sddl}|dd}tr"t|d}ttjtj}t|`|| t t d|}trfddnddl }|jdfdd |d d Ddd SQRXdS) NrrrrcSs|S)Nr/)xr/r/r0ordszget_mac_address..ordcsg|]}d|qS)z%02x:r/).0char)rKr/r0 sz#get_mac_address..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< startswith collections namedtupleintr=rA)outlinesrE_totalusedrXntr/r/r0 free_swaps    rccCstdddid}|d}xT|D]L}|dr dd|d d D\}}}}td d }||||||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..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..open_mockz builtins.openz__builtin__.openT)create side_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..open_mockz builtins.openz__builtin__.openT)r|r}N)r:rrr~)ryrr{rrr/)rryrzr0mock_open_exceptions  rz LINUX onlyc@seZdZddZeddZeddZeddZed d Zed d Z ed dZ eddZ ddZ 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)Nz free 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/r0 test_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/r0 test_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 CsdtdtdD}tjdd*}tdt}|j sDt | t |d|d}|j dslt |d t|j|d t|j|d t|j|d t|j|d t|j|dt|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)recordalwaysrdrzpsutil/_pslinux.pyz#memory stats couldn't be determinedcachedrfrrrr)rtextwrapdedentencodewarningscatch_warnings simplefilterrrcalledAssertionError assertEqualr?filenameendswithassertInstrmessagerrrrfrrslab)rrwsretwr/r/r0test_warnings_on_misses=s4   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 CsvtdtdX}tjdd}t}WdQRX|js@t | |j d|d}| dt |jWdQRXdS)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)rrrrrrrrrrrrrrr)rrrrrr/r/r0 test_avail_old_comes_from_kernelws z8TestSystemVirtualMemory.test_avail_old_comes_from_kernelc CsvtdtdX}tjdd}t}WdQRX|js@t | |j d|d}| dt |jWdQRXdS)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)rrrrrrrrrrrrrrr)rrrrrr/r/r0test_avail_old_missing_fieldss  z5TestSystemVirtualMemory.test_avail_old_missing_fieldsc CstdtdltdttjdNtj 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}|js@t||j d||j d||j d ||j d ||j d ||jd ||jd ||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..open_mockz builtins.openz__builtin__.openT)r|r}iiiipiTii iXi )r:rrr~rrrrrr`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 d d Z d dZ ddZ 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`r swap_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 Cstjddd}tjddx}tdt}|js:t| t |d|d}|j dsbt| d t|j| |jd| |jdWdQRXWdQRXdS) Nzpsutil._common.openT)r|)rrrdrzpsutil/_pslinux.pyz9'sin' and 'sout' swap memory stats couldn't be determined)rr~rrrrrrrrr?rrrrrsinsout)rrrrrr/r/r0test_missing_sin_sout8s   z*TestSystemSwapMemory.test_missing_sin_soutc Cstdttjd}tjddx}tdt}|j s>t | t |d|d}|j dsft |d t|j| |jd| |jdWdQRXWdQRXdS) Nz /proc/vmstatzno such file or directoryT)rrrdrzpsutil/_pslinux.pyzK'sin' and 'sout' swap memory stats couldn't be determined and were set to 0)rrrrrrrrrrrrr?rrrrrrr)rrrrrr/r/r0test_no_vmstat_mockedGs   z*TestSystemSwapMemory.test_no_vmstat_mockedc Cs|stdStd}t}WdQRX|jr:tddl m }| \}}}}}}}||9}||9}| |j ||j|j|tddS)Nz!/proc/meminfo has no swap metricsz"psutil._pslinux.cext.linux_sysinfor)r)rrskiprr~rrrrZpsutil._psutil_linuxZ _psutil_linuxZ linux_sysinforr`rrXr)rrswapZcextr_r`rXZunit_multiplierr/r/r0test_meminfo_against_sysinfoZs    z1TestSystemSwapMemory.test_meminfo_against_sysinfoc Cs,tdd}t|jstWdQRXdS)Nz /proc/meminfo)rrrrr)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)r steal)rrrZguest)rrrZ guest_nice) r cpu_times_fieldsrefindallosunamernror\r<r assertNotIn)rrFZ kernel_verZkernel_ver_infor/r/r0 test_fields{s   zTestSystemCPUTimes.test_fieldsN)rrrrr/r/r/r0rxsrc@seZdZeejd dddZeejd dddZ ee d  d d d Z ee 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..)rlistdirr?rrr)rZlscountr/r/r0test_against_sysdev_cpu_nums z5TestSystemCPUCountLogical.test_against_sysdev_cpu_numZnprocznproc utility not availablecCs$ttd}|tjdd|dS)Nz nproc --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..rWT)r)rr?r<rrr)rr]rr/r/r0test_against_lscpusz,TestSystemCPUCountLogical.test_against_lscpuc Csddl}|j}tjdtd}||j||js>ttjddd:}| |j||j d||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=rrr assertIsNoneZ call_count call_argsr:rrrrtr)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 CsPtj}tjdgd}tj}|js.tWdQRX|dk rL|||dS)Nz glob.glob)r)rrcpu_count_physicalrr~rrr)rZmeth_1rZmeth_2r/r/r0 test_method_2s   z(TestSystemCPUCountPhysical.test_method_2c Cs\tjdgd0}tjddd}|tjWdQRXWdQRX|jsNt|jsXtdS)Nz glob.glob)rzpsutil._common.openT)r|)rr~rrrrrr)rm1m2r/r/r0test_emulate_nones $ z,TestSystemCPUCountPhysical.test_emulate_noneN) rrrrrrrrrr/r/r/r0rs rc@szeZdZee dddZee dddZee dddZee ddd Z ee dd d Z d S) TestSystemCPUFrequencyz not supportedc s@fdd}tjjtjd|ddts2tWdQRXdS)Ncs|drdS|SdS)Nz&/sys/devices/system/cpu/cpufreq/policyF)rY)r) orig_existsr/r0path_exists_mocks zMTestSystemCPUFrequency.test_emulate_use_second_file..path_exists_mockzos.path.existsT)r}r|)rrrrr~rcpu_freqr)rrr/)rr0test_emulate_use_second_files   z3TestSystemCPUFrequency.test_emulate_use_second_filec sfdd}gtjjztjd|dvttjt}|sFt sNt | |j d| |j dx0tjddD] }| |j d| |j dqxWWdQRXWdttjttXdS)Ncs,|drdS|dkr d|SdS)Nz/sys/devices/system/cpu/Fz /proc/cpuinfo)rYr@)r)flagsos_path_existsr/r0rs   zITestSystemCPUFrequency.test_emulate_use_cpuinfo..path_exists_mockzos.path.exists)r}gT)percpu) rrrrr~rrrrrrmaxmin)rrrfreqr/)r r r0test_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.open_mockz builtins.openz__builtin__.open)r}zos.path.existsT)rg@@gg@g@) r:rrr~rrrcurrentr r )rr{rrr/)rzr0test_emulate_datas     z(TestSystemCPUFrequency.test_emulate_datac sfdd}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|drtd S|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)rrYrrrt)rurvrwn)rzr/r0r{9s,                   z@TestSystemCPUFrequency.test_emulate_multi_cpu..open_mockz builtins.openz__builtin__.open)r}zos.path.existsT)rz!psutil._pslinux.cpu_count_logicalr)r rgY@ggi@gr@rdgy@g@@g@) r:rrr~rrrrr r )rr{rrr/)rzr0test_emulate_multi_cpu7s$    z-TestSystemCPUFrequency.test_emulate_multi_cpuc sfdd}ttrdnd}tj||dPtjddd6tjd d dt}||jd WdQRXWdQRXWdQRXdS) NcsR|drttjdn6|dr,tdS|dkr>tdS|f||SdS)Nz/scaling_cur_freqrLz/cpuinfo_cur_freqs200000z /proc/cpuinfoscpu MHz : 200)rrrrrrrt)rurvrw)rzr/r0r{hs    zOTestSystemCPUFrequency.test_emulate_no_scaling_cur_freq_file..open_mockz builtins.openz__builtin__.open)r}zos.path.existsT)rz!psutil._pslinux.cpu_count_logicalrd)r:rrr~rrrr)rr{rrr/)rzr0%test_emulate_no_scaling_cur_freq_filees   z.ifconfigTF)Zpernicnowrapr3i)rr4r-ir.r/ r0r1r2) rnet_io_countersr"r'rr3r4r-r.r/r0r1r2)rr5Znior)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"rBZ SOCK_STREAMZ addCleanupcloseZbinderrorrnet_connections)rZ supports_ipv6rCr.r/r/r0test_emulate_ipv6_unsupported s z6TestSystemNetConnections.test_emulate_ipv6_unsupportedc Cs6tdtd}tjdd|js(tWdQRXdS)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)r:)rrrrr=rr)rrr/r/r0test_emulate_unixs   z*TestSystemNetConnections.test_emulate_unixN)rrrrr~r=r>r?r/r/r/r0r9 s  r9c@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..dfF)all)r) rdisk_partitionsZ disk_usageZ mountpointrr`rrXrra)rrDpartZusagerCr`rarXr/r/r0test_against_df-s    z(TestSystemDiskPartitions.test_against_dfc Cstdd}|}WdQRXd|krPxtD]}|jdkr0Pq0W|dn|ttd}t j d|ddX}t j d d gd <}t}|j st |j st |st | |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/rIZrw)rr)r:rrrFZfstypeZfailrrrsrrr~rrr)rrDrrGrrrrr/r/r0 test_zfs_fsFs$       z$TestSystemDiskPartitions.test_zfs_fsc CsTzFtjddd.}|ttWdQRX|js:tWdQRXWddt_XdS)Nzos.path.realpathz /non/existent)rz/proc) rr~ assertRaisesrrrFrr PROCFS_PATH)rrr/r/r0test_emulate_realpath_fail^s  z3TestSystemDiskPartitions.test_emulate_realpath_failN) rrrrrhasattrrrrHrKrNr/r/r/r0r@*sr@c@sDeZdZddZddZddZddZd d Zd d Zd dZ dS)TestSystemDiskIoCountersc Cstddtjdddtjdd}||jd||jd ||jd t ||j d ||j d ||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)r6rdrrr8rerr7)rrr~rdisk_io_countersr read_countread_merged_count read_bytes SECTOR_SIZE read_time write_countwrite_merged_count write_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 ||j d ||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)r6rdrrr8rerrQrRr7)rrr~rrSrrTrUrVrWrXrYrZr[r\r])rrr/r/r0test_emulate_kernel_2_6_fulls  z5TestSystemDiskIoCounters.test_emulate_kernel_2_6_fullc Cstddtjdddtjdd}||jd||jd t||j d ||j d t||j d ||j d ||j d ||jd ||jd WdQRXWdQRXdS) Nz/proc/diskstatsz 3 1 hda 1 2 3 4z!psutil._pslinux.is_storage_deviceT)rF)r6rdrrr8r)rrr~rrSrrTrVrWrYr[rUrXrZr\r])rrr/r/r0test_emulate_kernel_2_6_limiteds  z8TestSystemDiskIoCounters.test_emulate_kernel_2_6_limitedc Cstdtdtjdddltjddd}|t|d||d j d ||d j d ||d j d ||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)rT)perdiskr6rnvme0n1rdZ nvme0n1p1re) rrrrr~rrSrr?rTrY)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)rar6cSs|dkS)Nrbr/)rur/r/r0is_storage_deviceszSTestSystemDiskIoCounters.test_emulate_exclude_partitions..is_storage_deviceT)r|r}rdre) rrrrr~rrSrrrTrY)rrrdr/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..existsT)razpsutil._pslinux.os.path.exists)r|r})rrSrr~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..existszpsutil._pslinux.os.path.existsT)r|r})rr~rLNotImplementedErrorrrS)rrr/r/r0test_emulate_not_impls z.TestSystemDiskIoCounters.test_emulate_not_implN) rrrr^r_r`rcrerfrhr/r/r/r0rPjs rPc@sReZdZddZddZddZddZd d Zd d Ze d dZ ddZ dS)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 t j|j t t jd d | t t j|j t t jd d | t t j|j t t jd d |t _|t d |tt d t jd d }|t|d t jd d }|ttt|d ttj|dd$}|d|d|dWdQRX|t d |tt jd d d |tt d |tttt jd d d WdQRXWdt|t t X|t jddS)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..open_mockz builtins.openz__builtin__.open)r}T)r rzcpu 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~rrrLrr cpu_percentcpu_times_percentrMrsumroassertNotEqualshutilZrmtree)rZ my_procfsrDr{rZper_cpu_percentZper_cpu_times_percentr/)rzr0test_no_procfs_on_importsN         (  z!TestMisc.test_no_procfs_on_importc Cs,tdtd8}t|js(ttjddttjddWdQRXtdtd}t}|jszttjdd}t}tjdd}| |d| t |d| t |d| t |d| t t t |d| t t t |d| |j d| |jdWdQRXdS)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)r z 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@)rrrrrrorrrprrrqrorruser)rrroZcpu_percent_percpurpZcpu_times_percent_percpur/r/r0test_cpu_steal_decrease<s4      z TestMisc.test_cpu_steal_decreasec Cs8tjddd }|ttjj|js*tWdQRXdS)Nzpsutil._common.openT)r|) rr~rLr'rrrjrr)rrr/r/r0test_boot_time_mockedes  zTestMisc.test_boot_time_mockedc Cstjddgd&}|tdjd|js2tWdQRXtjddgd&}|tdjd|jsntWdQRXtjddgd&}|tdjd|jstWdQRXdS) Nzpsutil._pslinux.cext.users) giampaolozpts/2z:0ghATr)rrZ localhost)rxzpts/2z:0.0ghATr)rxzpts/2fooghATrry)rr~rrZusersZhostrr)rrr/r/r0test_users_mockedls   zTestMisc.test_users_mockedcCs|}t|z|t_|ttj|ttj|jttjdd|ttj |ttj |ttj |ttj |ttj |tjtjWddt_XdS)NT)r z/proc)rlrrmrrMrLrrrrjr=r8r&rFZ 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/r0rz)TestMisc.test_issue_687..)keyrd)rstartrr{threadsrr?sortedr}rrpidZas_dictrZpidsstop)rtprtidZptr/r/r0test_issue_687s zTestMisc.test_issue_687c Cs6tdd"}ttst|js(tWdQRXdS)Nz/proc/%s/statusrL)rrZ pid_existsrgetpidrr)rrr/r/r0test_pid_exists_no_proc_statuss z'TestMisc.test_pid_exists_no_proc_statusN) rrrrkrtrvrwrzr|rrrr/r/r/r0ris=)riz no batteryc@sfeZdZeed dddZddZddZd d Z d d Z d dZ ddZ ddZ ddZdS)TestSensorsBatteryZacpizacpi utility not availablecCsDtd}t|dddd}tj}|j||dddS)Nzacpi -brrdr!rL)r) rr\r<rireplacersensors_batterypercentr)rr]Z acpi_valuerr/r/r0 test_percents zTestSensorsBattery.test_percentc sjfdd}ttrdnd}tj||d6}|tjd|tjtj |j s\t WdQRXdS)Ncs2|ds|drtdS|f||SdS)Nz AC0/onlinez AC/online1)rrrrt)rurvrw)rzr/r0r{s z@TestSensorsBattery.test_emulate_power_plugged..open_mockz builtins.openz__builtin__.open)r}T) r:rrr~rrr power_pluggedZsecsleftZPOWER_TIME_UNLIMITEDrr)rr{rrr/)rzr0test_emulate_power_pluggeds  z-TestSensorsBattery.test_emulate_power_pluggedc sVfdd}ttrdnd}tj||d"}|tjd|jsHt WdQRXdS)NcsN|ds|dr"ttjdn(|dr:ttdS|f||SdS)Nz AC0/onlinez AC/onlinerLz/statusZcharging)rrrrrrrsr)rurvrw)rzr/r0r{s  zBTestSensorsBattery.test_emulate_power_plugged_2..open_mockz builtins.openz__builtin__.open)r}T) r:rrr~rrrrrr)rr{rrr/)rzr0test_emulate_power_plugged_2s   z/TestSensorsBattery.test_emulate_power_plugged_2c sVfdd}ttrdnd}tj||d"}|tjd|jsHt WdQRXdS)Ncs2|ds|drtdS|f||SdS)Nz AC0/onlinez AC/online0)rrrrt)rurvrw)rzr/r0r{s zDTestSensorsBattery.test_emulate_power_not_plugged..open_mockz builtins.openz__builtin__.open)r}F) r:rrr~rrrrrr)rr{rrr/)rzr0test_emulate_power_not_pluggeds   z1TestSensorsBattery.test_emulate_power_not_pluggedc sVfdd}ttrdnd}tj||d"}|tjd|jsHt WdQRXdS)NcsN|ds|dr"ttjdn(|dr:ttdS|f||SdS)Nz AC0/onlinez AC/onlinerLz/statusZ discharging)rrrrrrrsr)rurvrw)rzr/r0r{s  zFTestSensorsBattery.test_emulate_power_not_plugged_2..open_mockz builtins.openz__builtin__.open)r}F) r:rrr~rrrrrr)rr{rrr/)rzr0 test_emulate_power_not_plugged_2s   z3TestSensorsBattery.test_emulate_power_not_plugged_2c sTfdd}ttrdnd}tj||d }|tj|jsFt WdQRXdS)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..open_mockz builtins.openz__builtin__.open)r}) r:rrr~rrrrrr)rr{rrr/)rzr0test_emulate_power_undetermineds   z2TestSensorsBattery.test_emulate_power_undeterminedc Cs6tdd"}|tjd|js(tWdQRXdS)Nz(/sys/class/power_supply/BAT0/energy_fullrr)rrrrrrr)rrr/r/r0test_emulate_energy_full_0s z-TestSensorsBattery.test_emulate_energy_full_0c CshtdttjdLtdttjd.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_availc CsntdttjdRtdttjd4tdttjd|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 sxfdd}ttrdnd}tjddgd.}tj||d}|tWdQRXWdQRX|jsjt|jsttdS) Ncs\|drttdS|dr0ttdS|drHttdS|f||SdS)Nz /energy_nowZ60000000z /power_now0z /energy_fullZ60000001)rrrrsr)rurvrw)rzr/r0r{9s   z5TestSensorsBatteryEmulated.test_it..open_mockz builtins.openz__builtin__.openz os.listdirZBAT0)r)r}) r:rrr~ZassertIsNotNonerrrr)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)rrrrsrrt)rurvrw)rzr/r0r{Ps        zCTestSensorsTemperatures.test_emulate_class_hwmon..open_mockz builtins.openz__builtin__.open)r}z glob.globz/sys/class/hwmon/hwmon0/temp1)rrurrg>@gD@gI@) r:rrr~rsensors_temperaturesrrrhighcritical)rr{rtempr/)rzr0test_emulate_class_hwmonOs   z0TestSensorsTemperatures.test_emulate_class_hwmonc sfdd}dd}ttr dnd}tj||djtjdd |d Ntd d }||jd ||jd||j d||j dWdQRXWdQRXdS)Ncsl|drtdS|dr(tdS|dr@ttdS|drXttdS|f||SdS) NZ0_temps50000rs30000Z0_typertyperu)rrrrtrsr)rurvrw)rzr/r0r{ks      zETestSensorsTemperatures.test_emulate_class_thermal..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..glob_mockz builtins.openz__builtin__.open)r}z glob.globT)r|r}rurrLg>@gI@) r:rrr~rrrrrrr)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)rrrrsr)rurvrw)rzr/r0r{s   z4TestSensorsFans.test_emulate_data..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 d Z d d Z ddZ ddZddZddZddZddZddZee dddZdd Zd!d"Zd#d$Zd%S)& TestProcesscCs|}td|}||}tddd|t|j}t d| }|j dd}|j |j tdd |Dd d |j |jtd d |Dd d |j |jtd d |Dd d dS)Nzk import time with open("%s", "w") as f: time.sleep(10) cSs tdS)Nrl)rrr/r/r/r0r~rz3TestProcess.test_memory_full_info..z'%s' not in retg?F)ZgroupedcSsg|]}|j|jqSr/)Z private_dirtyZ private_clean)rMrJr/r/r0rOsz5TestProcess.test_memory_full_info..i)rcSsg|] }|jqSr/)pss)rMrJr/r/r0rOscSsg|] }|jqSr/)r)rMrJr/r/r0rOs)rlrrZpyrunrrr{rtimeZsleepmemory_full_info memory_mapsrussrqrr)rtestfnsrcZsprocrrmapsr/r/r0test_memory_full_infos      z!TestProcess.test_memory_full_infoc CsptdttdJ}t}|}|j s8t | |j d| |j d| |jdWdQRXdS)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<)rrrrrrrr{rrrrrrr)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) rr{rr open_filesrrabspathr')ZfnamerZ giveup_atfiler/r/r0 get_test_files   z7TestProcess.test_open_files_mode..get_test_filerrrzr+zw+za+rJzx+)rlr:rmoderr)rrrr/r/r0test_open_files_modes*         z TestProcess.test_open_files_modec Cst}|}t|dt|jdt|tjdt t j dd }|}|r\t |j sft WdQRXtjdt t jdd }||g|j st WdQRXWdQRXdS)Nrzlen(ret) != %izpsutil._pslinux.os.readlinkrL)r})rr{rr:rlrr?rr~OSErrorrrrrZEINVALr)rrfilesrr/r/r0test_open_files_file_gone sz%TestProcess.test_open_files_file_gonec Cst}|}t|dbt|jdt|tr.open_mockz builtins.openz__builtin__.open)r}cs4|dtr ttjdn|f||SdS)Nz /proc/%s/taskrL)rYrrrrZEPERM)rurvrw)rzr/r0r{s) r:rrr~rr{rrrrrL AccessDenied)rr{rrrr/)rzr0test_threads_mockedls     zTestProcess.test_threads_mockedc Cstjdttjdd}tjdtddd`}t}|j sFt |j sPt | |dtjddd| tj tjWdQRXWdQRXWdQRXdS) Nzpsutil._pslinux.readlinkrL)r}zpsutil.Process.cmdlinerzpsutil._pslinux.os.path.lexistsF)r)rr~rrrrrr{rrrrrL ZombieProcess)rrrrr/r/r0test_exe_mockeds     zTestProcess.test_exe_mockedc CsZtdtttjd6}t}|t | WdQRX|j sLt WdQRXdS)Nz/proc/%s/smapsrL) rrrrrrrr{rLrrrr)rrrr/r/r0test_issue_1014s  zTestProcess.test_issue_1014z not supportedc CstjdttjddD}t}||tj }| tj WdQRX|j sVt WdQRX||jj|j||jj|dS)Nzpsutil._pslinux.prlimitrL)r})rr~rrZENOSYSrr{rurLrZrlimitZ RLIMIT_NOFILErrr exceptionr)rrrrr/r/r0test_rlimit_zombieszTestProcess.test_rlimit_zombiec Cstjdttjdd@}t}||tj }| WdQRX|j sRt WdQRX| |jj|j| |jj|dS)Nzpsutil._pslinux.os.readlinkrL)r})rr~rrrrr{rurLrrrrrrr)rrrrr/r/r0test_cwd_zombieszTestProcess.test_cwd_zombiec*Cs\ddlm}dddddddddddddddd d ddddd ddddddddddddddddd ddd g*}d |}tdt|t}| | d| | tj | | d| |d|t|}| |jd|| |jd|| |jd|| |jd|| |jd|| |dWdQRXdS)Nr) CLOCK_TICKSrz(cat)Z1234567rhz /proc/%s/statcatrdrrrr8rerQ)rrrArrrrrr{rrustatusZ STATUS_ZOMBIEppidZ create_timerjrrusystem children_userchildren_systemZiowaitZcpu_num)rrrvrxrZcpur/r/r0test_stat_file_parsingst z"TestProcess.test_stat_file_parsingc Cstdttdt}|| j d|| j d|| 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 BiiiiiirrR)rrrrrrrr{rnum_ctx_switches voluntary involuntary num_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 d Z d d Z ddZ ddZ 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)rr{proc)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/r0 test_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 CsR|d}td}|jjWdQRXdt|krD|jrNtn |jsNtdS)NzCpus_allowed_list:zpsutil._pslinux.per_cpu_timesr) rrr~rrrrrr)rrrr/r/r0test_cpu_affinity_eligible_cpus`s     z8TestProcessAgainstStatus.test_cpu_affinity_eligible_cpusN)rrr__doc__ classmethodrrrrrrrrrrrrr/r/r/r0rs  rc@seZdZddZddZdS) TestUtilsc Cs<tjddd$}|tjdd|js.tWdQRXdS)Nz os.readlinkz foo (deleted))rrry)rr~rrrreadlinkrr)rrr/r/r0 test_readlinkrszTestUtils.test_readlinkc Csx|}t|d}|dWdQRX|tjj|ddd|tjj|ddd|tjj|dd d d dS) NZwtzfoo F)ZbinaryryTsfooz??r)Zfallback)rlr:rnrrrr)rrrDr/r/r0test_catws zTestUtils.test_catN)rrrrrr/r/r/r0rosr__main__) run_from_name)]rZ __future__rrZr%rZglobrrrrrsr"r+rrrrrZpsutil._compatrrrrZ psutil.testsrr r r r r rrrrrrrrrrrrrrrdirname__file__ZHEREr*Z SIOCGIFCONFrQr2r4rWZEMPTY_TEMPERATURESr1r3r5rIrTrcrgrkrpcontextmanagerrrrrrrrrrrrr r%r,r9r@rPrirrrrrrrrZpsutil.tests.runnerr r/r/r/r0s                              .]? )- ? ?  }ArR