gf';|dZddlZddlZddlZddlZddlZddlZddlZddlmZddlm Z ddlm Z ddlm Z ddlm Z ddlm Z dd lmZdd lmZdd lmZdd lmZdd lmZddlmZddlmZddlmZddlmZddlmZddlmZddlmZddlmZe rddlZddlZddlmZd%dZ dZ!dZ"dZ#dZ$ej%e dGddeZ&ej%e dGdd eZ'ej%e dGd!d"eZ(e)d#krdd$l*m+Z+e+e,dSdS)&zPOSIX specific tests.N)AIX)BSD)LINUX)MACOS)OPENBSD)POSIX)SUNOS) CI_TESTING)spawn_testproc)HAS_NET_IO_COUNTERS)mock)PsutilTestCase) PYTHON_EXE)retry_on_failure)sh)skip_on_access_denied) terminate)unittest)which) getpagesizecdg}tr|d|%|dt|gn9tst r|dn|dtr%t d}|||}|d|gt|}tr| }n| d d}g}|D]L}| } t|}n#t$rYnwxYw||M||S|d S) z| Wrapper for calling the ps command with a little bit of cross-platform support for a narrow range of features. psz --no-headersNz-pz-Aax)commandcommstartstimez-or) rappendextendstrr rsetgetr splitlinesstripint ValueError)fmtpidcmdfmt_mapoutput all_outputlines y/builddir/build/BUILD/imunify360-venv-2.3.5/opt/imunify360/venv/lib64/python3.11/site-packages/psutil/tests/test_posix.pyrr-s &C # >"""  D#c((#$$$$  C  JJt     JJt    $;<<kk#s##JJc{ WWF )""$$""$$QRR(J  zz|| t99DD    D  $ {!}s%D55 EEchd}trd}t||dS)Nrrr)r rsplitr)fields r/ps_namer4is3 E  eS>>   ! !! $$cFd}tstrd}t||S)Nrargs)rr rr2s r/ps_argsr8ps) E e eS>>r5c8d}trd}t||S)Nrssrssizerrr2s r/ps_rssr=ws" E  eS>>r5c8d}trd}t||S)Nvszvsizer<r2s r/ps_vszrA~s" E  eS>>r5z POSIX onlyceZdZdZedZedZdZdZdZ dZ dZ e e d Ze e d Zd Zd Zd ZdZejepeddZdZdZejedejeddZdS) TestProcesszBCompare psutil results against 'ps' command line utility (mainly).c`ttddgtjj|_dS)Nz-Ez-O)stdin)r r subprocessPIPEr)clss r/ setUpClasszTestProcess.setUpClasss0 *dD!9'18888; r5c.t|jdSN)rr)rHs r/ tearDownClasszTestProcess.tearDownClasss#'r5ctd|j}tj|j}|||dS)Nppid)rr)psutilProcessrO assertEqual)selfppid_ps ppid_psutils r/ test_ppidzTestProcess.test_ppidsLVTX&&nTX..3355  +.....r5ctd|j}tj|jj}|||dS)Nuid)rr)rPrQuidsrealrR)rSuid_ps uid_psutils r/test_uidzTestProcess.test_uidsOE48$$^DH--22449  ,,,,,r5ctd|j}tj|jj}|||dS)Nrgid)rr)rPrQgidsrZrR)rSgid_ps gid_psutils r/test_gidzTestProcess.test_gidsOFDH%%^DH--22449  ,,,,,r5ctd|j}tj|j}|||dS)Nuser)rr)rPrQusernamerR)rS username_psusername_psutils r/ test_usernamezTestProcess.test_usernamesL**  .22;;== o66666r5c@tj}tjdt5}||t|j |j sJ ddddS#1swxYwYdS)Nzpsutil.pwd.getpwuid side_effect) rPrQr patchKeyErrorrRrfr!rYrZcalled)rSpfuns r/test_username_no_resolutionz'TestProcess.test_username_no_resolutions N   Z-8 D D D    QZZ\\3qvvxx}+=+= > > >:  :                   sABBBctjdt|j}t j|jddz }|||dS)N皙?r)timesleepr=r)rPrQ memory_inforR)rSrss_ps rss_psutils r/test_rss_memoryzTestProcess.test_rss_memoryc 3!!^DH--99;;A>E  ,,,,,r5ctjdt|j}t j|jddz }|||dS)Nrtrru)rvrwrAr)rPrQrxrR)rSvsz_ps vsz_psutils r/test_vsz_memoryzTestProcess.test_vsz_memoryr|r5ct|j}tj|}t j|j}tj dd|}tj dd|}tj dd|}tj dd|}| ||dS)Nz\d.\dz\d) r4r)ospathbasenamelowerrPrQnameresubrR)rSname_ps name_psutils r/ test_namezTestProcess.test_names$(##'""7++1133nTX..3355;;== &2w//fXr;77 &G,,fUB 44  +.....r5cBd}gd}tjd|5tjd|5tj}||ddddn #1swxYwYddddS#1swxYwYdS)Nlong-program-name)long-program-name-extendedfoobarpsutil._psplatform.Process.name return_value"psutil._psplatform.Process.cmdliner)r rmrPrQrRr)rSrcmdlinerps r/test_name_longzTestProcess.test_name_longsX#>>> Z9%)+++ I I@)0222 I IN$$  +GHHH I I I I I I I I I I I I I I I I I I I I I I I I I I I I I I I I Is4B??? @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @s5*B# ? ? ? ? ? ? @sA7BBct|j}dtj|j}|||dS)N )r8r)joinrPrQrrR)rS ps_cmdlinepsutil_cmdlines r/ test_cmdlinezTestProcess.test_cmdlinesVTX&& &.":":"B"B"D"DEE ^44444r5znot reliable on SUNOSznot reliable on AIXctd|j}tj}|||dS)Nnice)rr)rPrQrrR)rSps_nice psutil_nices r/ test_nicezTestProcess.test_nicesJVTX&&n&&++--  +.....r5N)__name__ __module__ __qualname____doc__ classmethodrJrMrVr]rcrirrrrr{rrrrrrskipIfrrrrrr rrr5r/rCrCsLL<<[<[/// --- --- 777 ------ / / / I I I @ @ @ @ @ @X_U\c#>?? O O@? O @ @ @555X_U344X_S/00//1054///r5rCceZdZdZedZejedeje d deje ddZ eje oe j ded Zd Zd Zd Zd ZejededZdS)TestSystemAPIszTest some system APIs.cttdtjts t rdvrddttz dkrDfdDfdDz}|dt|zdSdS)Nr)rrcg|]}|v| Srr).0xpids_pss r/ z,TestSystemAPIs.test_pids..4s#EEEAW4D4D!4D4D4Dr5cg|]}|v| Srr)rr pids_psutils r/rz,TestSystemAPIs.test_pids..5s#EEE0D0D!0D0D0Dr5z difference: ) sortedrrPpidsrrinsertrfailr!)rS differencerrs @@r/ test_pidszTestSystemAPIs.test_pids'sE##kmm   !G ! 0 0 NN1a  w<<#k** *Q . .EEEE[EEEEEEEWEEEFJ IIns:6 7 7 7 7 7 / .r5zunreliable on SUNOSifconfigzno ifconfig cmdz not supportedc td}tjdD]K}|D]}||rn|d|d|LdS)Nz ifconfig -aT)perniczcouldn't find z nic in 'ifconfig -a' output )rrPnet_io_counterskeysr1 startswithr)rSr,nicr.s r/test_nic_nameszTestSystemAPIs.test_nic_names:sM"")666;;== & &C  & &??3''E VV%&&&  & &r5zunreliable on CIctd}|s|d|d}d|D}d|D}|t |t t jt jD]8}||j |||j |9dS)Nwhozno users on this system cBg|]}|dS)rr1rrs r/rz-TestSystemAPIs.test_users..Os$---!1---r5cBg|]}|dS)rrrs r/rz-TestSystemAPIs.test_users..Ps$111aQWWYYq\111r5) rr%skipTestr1rRrrPusersrrterminal)rSoutlinesr terminalsus r/ test_userszTestSystemAPIs.test_usersHsiiyy{{ ;-- 9:: : $--u---115111  US%8%8999 1 1A MM!&% ( ( ( MM!*i 0 0 0 0 1 1r5c tjdttjd5}|tt jjtj |j sJ ddddS#1swxYwYdS)Nzpsutil._psposix.os.killrrk) r rmOSErrorerrnoEBADFrrP_psposix pid_existsrgetpidrorSms r/test_pid_exists_let_raisez(TestSystemAPIs.test_pid_exists_let_raiseVsZ1$+EK$<$<>>> AB   gv'A29;; O O O8OO8O                  ABB Bc tjdttjd5}|tt jjtj |j sJ ddddS#1swxYwYdS)Npsutil._psposix.os.waitpidrrk) r rmrrrrrPrwait_pidrrrors r/test_os_waitpid_let_raisez(TestSystemAPIs.test_os_waitpid_let_raise_sZ4$+EK$<$<>>> AB   gv'? M M M8OO8O                  rc8tjdttjd5}|t jjt jj tj d|j sJ ddddS#1swxYwYdS)Nrrrkg{Gz?)timeout) r rmrrEINTRrrPrTimeoutExpiredrrrrors r/test_os_waitpid_eintrz$TestSystemAPIs.test_os_waitpid_eintrgs Z4$+EK$<$<>>> AB   .(")++t  E E E8OO8O                   sABBBctjdd5}|ttjjtj|j sJ ddddS#1swxYwYdS)Nr)rr) r rmrr'rPrrrrrors r/test_os_waitpid_bad_ret_statusz-TestSystemAPIs.test_os_waitpid_bad_ret_statusps Z4%,... 12   j$o6  E E E8OO8O                   sAA++A/2A/zunreliable on AIXcd}d}tjdD]}tj|j} ||j\}}}}||j||||j||||j||||j |d#t$r8} t|  } d| vsd| vsd | vrYd} ~ d} ~ wwxYwdS) Nctd|z}|dd}|}t|ddz}t|ddz}t|ddz}t |ddd }||||fS) Nzdf -k %srrru%r)rr%r1r&floatreplace)devicerr.fieldstotalusedfreepercents r/dfz*TestSystemAPIs.test_disk_usage..df|sZ&())//11C99T??1%DZZ\\Fq NNT)Evay>>D(Dvay>>D(DF1I--c26677G4w/ /r5i@F)all)deltarzno such file or directoryzraw devices not supportedzpermission denied) rPdisk_partitions disk_usage mountpointrassertAlmostEqualrrrr RuntimeErrorr!r) rSr tolerancepartusagerrrrerrs r/test_disk_usagezTestSystemAPIs.test_disk_usageysS 0 0 0$ *u555 H HD%do66E H-/R __*tT7&&u{E&KKK&&uz4y&III&&uz4y&III&&u}gQ&GGGG   #hhnn&&.#553s::+s22HHHH   H HsC D -C>=C>>DN)rrrrrrrrr rr rr rPrrrrrrrr rr5r/rr#s|  888$X_U122X_z***,=>>X_,,o>> & &?>?>32 &X_Z6  $68JKK 1 1LK 1X_S-..HH/.HHHr5rceZdZdZdS)TestMiscct}||d||tj||tjdS)Nr)r assertGreaterrRresourcemmapPAGESIZE)rSpagesizes r/test_getpagesizezTestMisc.test_getpagesizes^== 8Q''' 8#7#9#9::: 4=11111r5N)rrrr)rr5r/r"r"s#22222r5r"__main__) run_from_namerL)-rrrrrrFrvrPrrrrrrr psutil.testsr r r r rrrrrrrrr&r%psutil._psutil_posixrrr4r8r=rArrCrr"rpsutil.tests.runnerr+__file__rr5r/r0sN  ######'''''',,,,,,''''''######))))))......""""""!!!!!!1KKKOOO000000....x%%%UL))Z/Z/Z/Z/Z/.Z/Z/*)Z/zUL))vHvHvHvHvH^vHvH*)vHrUL))22222~22*)2 z111111M(r5