JFIFxxC      C  " }!1AQa"q2#BR$3br %&'()*456789:CDEFGHIJSTUVWXYZcdefghijstuvwxyz w!1AQaq"2B #3RbrJFIFxxC      C  " }!1AQa"q2#BR$3br %&'()*456789:CDEFGHIJSTUVWXYZcdefghijstuvwxyz w!1AQaq"2B #3RbrB =_^@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" inet_ptonAF_INET6 inet_ntop) r-flinefieldsZ unformattedgroupsi formattedZpackedr/r/r0get_ipv6_addressis   rKc 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)rMr/r0 sz#get_mac_address..rr7)r rr!r"r#r$r%r&r(r) SIOCGIFHWADDRr+r, __builtin__rMrA)r-r r.inforTr/)rMr0get_mac_addresszs    rVcCs|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)outlinesrF_totalusedrZntr/r/r0 free_swaps    recCstdddid}|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 -brWzC.UTF-8)rXrYZMemcSsg|] }t|qSr/)r^)rOrLr/r/r0rQsz free_physmem..rZztotal used free shared outputz%can't find 'Mem' in 'free' output: %sN)rr<r[r\r]r=rA)r_r`rFrbrcrZsharedrdr/r/r0 free_physmems   "ricCsVtdddid}x4|dD]&}|}||krt|ddSqWtd|dS) Nz vmstat -srWzC.UTF-8)rXrY rz can't find %r in 'vmstat' output)rr<stripr^r=)statr_rFr/r/r0vmstats rmcCs:td}d|krtdttt|ddS)Nzfree -VUNKNOWNzcan't determine free versionr7.)rrkrSkipTesttuplemapr^r<)r_r/r/r0get_free_version_infos  rsc #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)r|r{r~ patch_pointmr/)r{r|r}r0mock_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/)rxryrz)excr|r}r/r0r~sz&mock_open_exception..open_mockz builtins.openz__builtin__.openT)rrN)r:rrr)r|rr~rrr/)rr|r}r0mock_open_exceptions  rz LINUX onlyc@seZdZddZeddZeddZeddZed d Zed d Z ed dZ eddZ ddZ eddZ ddZddZddZddZdS)TestSystemVirtualMemorycCs&tdd}tj}|||dS)Nz total memoryi)rmpsutilvirtual_memoryrbassertAlmostEqual)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) rsZskipTestrircrrrroutput)rrZ free_valuerr/r/r0 test_useds   z!TestSystemVirtualMemory.test_usedcCs*tdd}tj}|j||tddS)Nz free memoryi)r)rmrrrZrr)rrrr/r/r0 test_frees  z!TestSystemVirtualMemory.test_freecCs*tdd}tj}|j||tddS)Nz buffer memoryi)r)rmrrbuffersrr)rrrr/r/r0 test_bufferss  z$TestSystemVirtualMemory.test_bufferscCs*tdd}tj}|j||tddS)Nz active memoryi)r)rmrractiverr)rrrr/r/r0 test_actives  z#TestSystemVirtualMemory.test_activecCs*tdd}tj}|j||tddS)Nzinactive memoryi)r)rmrrinactiverr)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) rirhrrprrrrr)rrZrrr/r/r0 test_shared#s  z#TestSystemVirtualMemory.test_sharedcCshtd}|d}d|dkr*tdn:t|dd}tj}|j||t d|||fd dS) Nzfree -brY availablerz(free does not support 'available' columnrfr7z %s %s %s)rr) rr<rrpr^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)recordalwaysrfrzpsutil/_pslinux.pyz#memory stats couldn't be determinedcachedrhrrrr)rtextwrapdedentencodewarningscatch_warnings simplefilterrrcalledAssertionError assertEqualr?filenameendswithassertInstrmessagerrrrhrrslab)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/meminforfis MemAvailable:dr)psutil._pslinuxrrr<r^absZ assertLess) rrrZmemsrErFrGabZ 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 )rurwrrr)rxryrz)r}r/r0r~s1 zETestSystemVirtualMemory.test_virtual_memory_mocked..open_mockz builtins.openz__builtin__.openT)rriiiipiTii iXi )r:rrrrrrrrrbrZrrrhrrrr)rr~rrmemr/)r}r0test_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)rEdatar/r/r0meminfo_has_swap_infos z*TestSystemSwapMemory.meminfo_has_swap_infocCs"tj}tj}|j||tdS)N)r)rerbr swap_memoryrr)rrrr/r/r0r$s zTestSystemSwapMemory.test_totalcCs"tj}tj}|j||tdS)N)r)rercrrrr)rrrr/r/r0r*s zTestSystemSwapMemory.test_usedcCs"tj}tj}|j||tdS)N)r)rerZrrrr)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)rrrfrzpsutil/_pslinux.pyz9'sin' and 'sout' swap memory stats couldn't be determined)rrrrrrrrrrr?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)rrrfrzpsutil/_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)rrskiprrrrrrZpsutil._psutil_linuxZ _psutil_linuxZ linux_sysinforrbrrZr)rrswapZcextrarbrZZunit_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+rro)r steal)rrrZguest)rrrZ guest_nice) r cpu_times_fieldsrefindallosunamerqrrr^r<r assertNotIn)rrGZ 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-rf) r:rrkrr^r<rr cpu_count)rrEvaluer/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)rOrLr/r/r0rQszITestSystemCPUCountLogical.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)#)r[)rOrLr/r/r0rQsz@TestSystemCPUCountLogical.test_against_lscpu..rYT)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)rzpsutil._common.openT)rrz /proc/statz /proc/cpuinforb) return_valuerr)r_pslinuxZcpu_count_logicalrrr=rrr assertIsNoneZ call_count call_argsr:rrurwr)rroriginalrrEZ 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 -prYr,rfF)r) rsetr<r[addrrrr?)rr_Zcore_idsrFrGr/r/r0rs  z-TestSystemCPUCountPhysical.test_against_lscpuc CsPtj}tjdgd}tj}|js.tWdQRX|dk rL|||dS)Nz glob.glob)r)rrcpu_count_physicalrrrrr)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)rrrrrrrr)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)r[)r) orig_existsr/r0path_exists_mocks zMTestSystemCPUFrequency.test_emulate_use_second_file..path_exists_mockzos.path.existsT)rr)rrrrrrcpu_freqr)rr r/)r r0test_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)r[r@)r)flagsos_path_existsr/r0r s   zITestSystemCPUFrequency.test_emulate_use_cpuinfo..path_exists_mockzos.path.exists)rgT)percpu) rrrrrrrrr rrmaxmin)rr rfreqr/)r rr0test_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)rzos.path.existsT)rg@@gg@g@) r:rrrrr rcurrentrr)rr~rrr/)r}r0test_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)rr[rurw)rxryrzn)r}r/r0r~9s,                   z@TestSystemCPUFrequency.test_emulate_multi_cpu..open_mockz builtins.openz__builtin__.open)rzos.path.existsT)rz!psutil._pslinux.cpu_count_logicalr)rrgY@ggi@gr@rfgy@g@@g@) r:rrrrr rrrr)rr~rrr/)r}r0test_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_freqrNz/cpuinfo_cur_freqs200000z /proc/cpuinfoscpu MHz : 200)rrrrrurw)rxryrz)r}r/r0r~hs    zOTestSystemCPUFrequency.test_emulate_no_scaling_cur_freq_file..open_mockz builtins.openz__builtin__.open)rzos.path.existsT)rz!psutil._pslinux.cpu_count_logicalrf)r:rrrrr rr)rr~rrr/)r}r0%test_emulate_no_scaling_cur_freq_filees   z.ifconfigTF)Zpernicnowrapr?i)rr@r9ir:r; r<r=r>) rnet_io_countersr'r2rr?r@r9r:r;r<r=r>)rrAZnior5Z ifconfig_retr/)rxr0r6s.  z-TestSystemNetIOCounters.test_against_ifconfigN)rrrrr6r/r/r/r0r8sr8c@s8eZdZejdedejdddddZdd Zd S) TestSystemNetConnectionsz psutil._pslinux.socket.inet_ntop)rzpsutil._pslinux.supports_ipv6F)rcCsRy*ttjtj}||j|dWntjk r@YnXtjdddS)N)z::1rinet6)kind) r"rC SOCK_STREAMZ addCleanupclosebinderrorrnet_connections)r supports_ipv6rDr.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 unix)rG)rrrrrLrr)rrr/r/r0test_emulate_unixs   z*TestSystemNetConnections.test_emulate_unixN)rrrrrr=rNrPr/r/r/r0rE s  rEc@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"rYrr8ZnonerN)rrkr<popr^)rr_r`rFdevrbrcrZr/r/r0df2s   z4TestSystemDiskPartitions.test_against_df..dfF)all)r) rdisk_partitions disk_usage mountpointrrbrrZrrc)rrUpartusagerTrbrcrZr/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/filesystemsr!zfszcouldn't find any ZFS partitionz nodev zfs zpsutil._common.openT)rrz$psutil._pslinux.cext.disk_partitions)z /dev/sdb3/r]rw)rr)r:rrrWfstypeZfailrurvrrrrrr)rrErrZrrrrr/r/r0 test_zfs_fsFs$       z$TestSystemDiskPartitions.test_zfs_fsc CsTzFtjddd.}|ttWdQRX|js:tWdQRXWddt_XdS)Nzos.path.realpathz /non/existent)rz/proc) rr assertRaisesrrrWrr PROCFS_PATH)rrr/r/r0test_emulate_realpath_fail^s  z3TestSystemDiskPartitions.test_emulate_realpath_failN) rrrrrhasattrrrr\rardr/r/r/r0rQ*srQc@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)rBrfrrr8rgrrC)rrrrdisk_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)rBrfrrr8rgrrgrhrC)rrrrrirrjrkrlrmrnrorprqrrrs)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)rBrfrrr8r)rrrrrirrjrlrmrorqrkrnrprrrs)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)perdiskrBrnvme0n1rfZ nvme0n1p1rg) rrrrrrrirr?rjro)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)rwrBcSs|dkS)Nrxr/)rxr/r/r0is_storage_deviceszSTestSystemDiskIoCounters.test_emulate_exclude_partitions..is_storage_deviceT)rrrfrg) rrrrrrrirrrjro)rrrzr/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)rwzpsutil._pslinux.os.path.exists)rr)rrirrrr?)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)rr)rrrbNotImplementedErrorrri)rrr/r/r0test_emulate_not_impls z.TestSystemDiskIoCounters.test_emulate_not_implN) rrrrtrurvryr{r|r~r/r/r/r0rfjs rfc@sReZdZddZddZddZddZd d Zd d Ze d dZ ddZ dS)TestMisccCs(td}t}|t|t|dS)Nz boot time)rmr 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)Nrlrzcpu 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)r[rrr)rxryrz)r}r/r0r~ s  z4TestMisc.test_no_procfs_on_import..open_mockz builtins.openz__builtin__.open)rT)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:rrAwriterrrrrrbrr cpu_percentcpu_times_percentrcrsumrrassertNotEqualshutilrmtree)rZ my_procfsrEr~rZper_cpu_percentZper_cpu_times_percentr/)r}r0test_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)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@)rrrrrrrrrrrrrrruser)rrrZcpu_percent_percpurZcpu_times_percent_percpur/r/r0test_cpu_steal_decrease<s4      z TestMisc.test_cpu_steal_decreasec Cs8tjddd }|ttjj|js*tWdQRXdS)Nzpsutil._common.openT)r) rrrbr2rrrrr)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)rzpts/2z:0.0ghATr)rzpts/2fooghATrr)rrrrZusershostrr)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)rrrrrcrbrrrrrLrDr1rW NoSuchProcessProcess)rZtdirr/r/r0test_procfs_paths zTestMisc.test_procfs_pathcCst}|zjt}|}|t|dt|ddddj}| |j |t|}| | |t Wd|XdS)NrcSs|jS)N)id)rLr/r/r0rz)TestMisc.test_issue_687..)keyrf)rstartrrthreadsrr?sortedrrpidZas_dictrZpidsstop)rtprtidptr/r/r0test_issue_687s zTestMisc.test_issue_687c Cs6tdd"}ttst|js(tWdQRXdS)Nz/proc/%s/statusrN)rrZ pid_existsrgetpidrr)rrr/r/r0test_pid_exists_no_proc_statuss z'TestMisc.test_pid_exists_no_proc_statusN) rrrrrrrrrrrrr/r/r/r0rs=)rz no batteryc@sfeZdZeed dddZddZddZd d Z d d Z d dZ ddZ ddZ ddZdS)TestSensorsBatteryZacpizacpi utility not availablecCsDtd}t|dddd}tj}|j||dddS)Nzacpi -brrfr&rN)r) rr^r<rkreplacersensors_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)rrurw)rxryrz)r}r/r0r~s z@TestSensorsBattery.test_emulate_power_plugged..open_mockz builtins.openz__builtin__.open)rT) r:rrrrrr power_pluggedsecsleftPOWER_TIME_UNLIMITEDrr)rr~rrr/)r}r0test_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/onlinerNz/statusZcharging)rrrrrurvr)rxryrz)r}r/r0r~s  zBTestSensorsBattery.test_emulate_power_plugged_2..open_mockz builtins.openz__builtin__.open)rT) r:rrrrrrrrr)rr~rrr/)r}r0test_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)rrurw)rxryrz)r}r/r0r~s zDTestSensorsBattery.test_emulate_power_not_plugged..open_mockz builtins.openz__builtin__.open)rF) r:rrrrrrrrr)rr~rrr/)r}r0test_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/onlinerNz/statusZ discharging)rrrrrurvr)rxryrz)r}r/r0r~s  zFTestSensorsBattery.test_emulate_power_not_plugged_2..open_mockz builtins.openz__builtin__.open)rF) r:rrrrrrrrr)rr~rrr/)r}r0 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/onlinerNz#/sys/class/power_supply/BAT0/statuss???)r[rrrrurw)rxryrz)r}r/r0r~s     zETestSensorsBattery.test_emulate_power_undetermined..open_mockz builtins.openz__builtin__.open)r) r:rrrrrrrrr)rr~rrr/)r}r0test_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_fullrNz(/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/onlinerNz"/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)rrurvr)rxryrz)r}r/r0r~9s   z5TestSensorsBatteryEmulated.test_it..open_mockz builtins.openz__builtin__.openz os.listdirZBAT0)r)r) r:rrrZassertIsNotNonerrrr)rr~rZmlistdirZmopenr/)r}r0test_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/namerxz /temp1_labellabelz /temp1_inputs30000z /temp1_maxs40000z /temp1_crits50000)rrurvrrw)rxryrz)r}r/r0r~Ps        zCTestSensorsTemperatures.test_emulate_class_hwmon..open_mockz builtins.openz__builtin__.open)rz glob.globz/sys/class/hwmon/hwmon0/temp1)rrxrrg>@gD@gI@) r:rrrrsensors_temperaturesrrrhighcritical)rr~rtempr/)r}r0test_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_typertyperx)rrurwrvr)rxryrz)r}r/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)rz glob.globT)rrrxrrNg>@gI@) r:rrrrrrrrrr)rr~rrrr/)r}r0test_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/namerxz /fan1_labelrz /fan1_input2000)rrurvr)rxryrz)r}r/r0r~s   z4TestSensorsFans.test_emulate_data..open_mockz builtins.openz__builtin__.open)rz glob.globz/sys/class/hwmon/hwmon2/fan1)rrxrri) r:rrrrZ sensors_fansrrr)rr~rZfanr/)r}r0rs   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)Nro)rrr/r/r/r0rrz3TestProcess.test_memory_full_info..z'%s' not in retg?F)ZgroupedcSsg|]}|j|jqSr/)Z private_dirtyZ private_clean)rOrLr/r/r0rQsz5TestProcess.test_memory_full_info..i)rcSsg|] }|jqSr/)pss)rOrLr/r/r0rQscSsg|] }|jqSr/)r)rOrLr/r/r0rQs)rrrZpyrunrrrrtimesleepmemory_full_info memory_mapsrussrrr)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<)rrrrrrrrrrrrrrr)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) rrrr open_filesrrabspathr2)fnamerZ giveup_atfiler/r/r0 get_test_files   z7TestProcess.test_open_files_mode..get_test_filerr!rzr+zw+za+rLzx+)rr: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.readlinkrN)r)rrrr:rrr?rrOSErrorrrrrEINVALr)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)rcs4|dtr ttjdn|f||SdS)Nz /proc/%s/taskrN)r[rrrrEPERM)rxryrz)r}r/r0r~s) r:rrrrrrrrrrb AccessDenied)rr~rrrr/)r}r0test_threads_mockedls     zTestProcess.test_threads_mockedc Cstjdttjdd}tjdtddd`}t}|j sFt |j sPt | |dtjddd| tj tjWdQRXWdQRXWdQRXdS) Nzpsutil._pslinux.readlinkrN)rzpsutil.Process.cmdlinerzpsutil._pslinux.os.path.lexistsF)r)rrrrrrrrrrrrrb ZombieProcess)rrrrr/r/r0test_exe_mockeds     zTestProcess.test_exe_mockedc CsZtdtttjd6}t}|t | WdQRX|j sLt WdQRXdS)Nz/proc/%s/smapsrN) rrrrrrrrrbrrrr)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.prlimitrN)r)rrrrZENOSYSrrrxrbrZrlimitZ 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.readlinkrN)r)rrrrrrrrxrbrrrrrrr)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)Z1234567rjz /proc/%s/statcatrfrrrr8rgrg)rrrArrrrrrrrxstatus STATUS_ZOMBIEppidZ create_timerrrsystem children_userchildren_systemZiowaitZcpu_num)rrryr{rZcpur/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 Biiiiiirrh)rrrrrrrrrnum_ctx_switches voluntary involuntary num_threadsuidsreal effectivesavedgids_proc_get_eligible_cpuslistr>)rrr r r/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)rrproc)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 _psplatform open_textrrrkr[ partitionr^r=)rZ linestartrErFrr/r/r0read_status_file)s   z)TestProcessAgainstStatus.read_status_filecCs |d}||j|dS)NzName:)rrrrx)rrr/r/r0 test_name6s z"TestProcessAgainstStatus.test_namecCsH|d}||dd|d}|dd}||j|dS)NzState:(rf)rjr)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:rfr8)rrqrrr^r<rrr )rrr/r/r0 test_uidsHs z"TestProcessAgainstStatus.test_uidscCs:|d}ttt|dd}||j|dS)NzGid:rfr8)rrqrrr^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:rrf) rrrrr^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) rrrrrrrrr)rrrr/r/r0test_cpu_affinity_eligible_cpus`s     z8TestProcessAgainstStatus.test_cpu_affinity_eligible_cpusN)rrr__doc__ classmethodrrrr r!r"r#r$rr%r&r'r/r/r/r0rs  rc@seZdZddZddZdS) TestUtilsc Cs<tjddd$}|tjdd|js.tWdQRXdS)Nz os.readlinkz foo (deleted))rrr)rrrrrreadlinkrr)rrr/r/r0 test_readlinkrszTestUtils.test_readlinkc Csx|}t|d}|dWdQRX|tjj|ddd|tjj|ddd|tjj|dd d d dS) Nwtzfoo F)binaryrTsfooz??r)fallback)rr:rrrrr)rrrEr/r/r0test_catws zTestUtils.test_catN)rrrr,r0r/r/r/r0r*osr*__main__) run_from_name)]r( __future__rr\r%rglobrurrrr"r+rrrrrZpsutil._compatrrrrZ psutil.testsrr r r r r rrrrrrrrrrrrrrrdirname__file__HEREr*Z SIOCGIFCONFrSr2r4rmZEMPTY_TEMPERATURESr1r3r5rKrVrerirmrscontextmanagerrrrrrrrrrrr r%r/r8rErQrfrrrrrrrr*rZpsutil.tests.runnerr2r/r/r/r0s                              .]? )- ? ?  }ArR