gfT8dZddlZddlZddlZddlZddlZddlZddlZddlm Z ddlm Z ddlm Z ddl m Z ddl mZddl mZdd lmZdd lmZdd lmZdd lmZdd lmZddlmZddlmZddlmZddlmZddlmZddlmZddlmZddlmZddlmZddlmZddlm Z ddlm!Z!ddlm"Z"ddlm#Z#ddlm$Z$ddlm%Z%ddlm&Z&ddlm'Z'dd lm(Z(dd!lm)Z)dd"lm*Z*dd#lm+Z+ddlZddlZGd$d%eZ,Gd&d'eZ-Gd(d)eZ.Gd*d+eZ/Gd,d-eZ0e#Gd.d/e'Z1Gd0d1eZ2Gd2d3eZ3e4d4krdd5l5m6Z6e6e7dSdS)6z3 Tests for testing utils (psutil.tests namespace). N)FREEBSD)NETBSD)POSIX) open_binary) open_text) supports_ipv6) bind_socket)bind_unix_socket) call_until)chdir) CI_TESTING)create_sockets) get_free_port)HAS_CONNECTIONS_UNIX) is_namedtuple)mock)process_namespace)PsutilTestCase) PYTHON_EXE) reap_children)retry)retry_on_failure) safe_mkdir) safe_rmpath) serialrun)system_namespace)tcp_socketpair) terminate)TestMemoryLeak)unittest)unix_socketpair) wait_for_file) wait_for_pidc:eZdZejddZejddZejddZejddZejddZ ejddZ dS) TestRetryDecoratorz time.sleepctdddfd}ttd||d||jddS)NretriesintervallogfuncBrddz dSNr(rpopqueues}/builddir/build/BUILD/imunify360-venv-2.3.5/opt/imunify360/venv/lib64/python3.11/site-packages/psutil/tests/test_testutils.pyfooz2TestRetryDecorator.test_retry_success..fooC2  A 1)rlistrange assertEqual call_countselfsleepr4r2s @r3test_retry_successz%TestRetryDecorator.test_retry_success?s q1T 2 2 2     3 2  U1XX """ )1-----r6ctdddfd}ttd|t|||jddS)Nr'r(r)cBrddz dSr.r/r1sr3r4z2TestRetryDecorator.test_retry_failure..fooQr5r6)rr8r9 assertRaisesZeroDivisionErrorr:r;r<s @r3test_retry_failurez%TestRetryDecorator.test_retry_failureNs q1T 2 2 2     3 2  U1XX +S111 )1-----r6cttdd}|t|||jddS)Nr() exceptionr+ctN) TypeErrorr6r3r4z2TestRetryDecorator.test_exception_arg..foo^sOr6r)r ValueErrorrCrJr:r;r=r>r4s r3test_exception_argz%TestRetryDecorator.test_exception_arg\s` a 0 0 0   1 0  )S))) )1-----r6ctdddd}|t|||jddS)Nr'r)cddz dSr.rKrKr6r3r4z4TestRetryDecorator.test_no_interval_arg..fooi EEEEr6rrrCrDr:r;rMs r3test_no_interval_argz'TestRetryDecorator.test_no_interval_argese q4 5 5 5   6 5  +S111 )1-----r6ctdddd}|t|||jddS)Nr'r(r)cddz dSr.rKrKr6r3r4z0TestRetryDecorator.test_retries_arg..foosrQr6rRrMs r3test_retries_argz#TestRetryDecorator.test_retries_argpse q1T 2 2 2   3 2  +S111 )1-----r6cL|ttdddS)Nr'r()r*timeout)rCrLr)r=r>s r3test_retries_and_timeout_argsz0TestRetryDecorator.test_retries_and_timeout_argszs% *eQBBBBBr6N) __name__ __module__ __qualname__rpatchr?rErNrSrVrYrKr6r3r%r%=sTZ  . . .TZ  . . .TZ ...TZ ...TZ ...TZ CCCCCr6r%c2eZdZdZdZdZdZdZdZdS)TestSyncTestUtilscRttjtt jdz}t jdtdg5| tj t|ddddS#1swxYwYdS)Nipsutil.tests.retry.__iter__r return_value) r#osgetpidmaxpsutilpidsrr]iterrC NoSuchProcess)r=nopids r3test_wait_for_pidz#TestSyncTestUtils.test_wait_for_pidsRY[[!!!FKMM""U* Z5D!II N N N I I   f2L% H H H I I I I I I I I I I I I I I I I I Is('BB #B c|}t|d5}|ddddn #1swxYwYt|tj|rJdS)Nwr4 get_testfnopenwriter"rdpathexistsr=testfnfs r3test_wait_for_filez$TestSyncTestUtils.test_wait_for_files"" &#   ! GGENNN               f7>>&)))))))AA A c|}t|d5 dddn #1swxYwYt|dtj|rJdS)NrnT)empty)rprqr"rdrsrtr=rvs r3test_wait_for_file_emptyz*TestSyncTestUtils.test_wait_for_file_emptys"" &#                    fD))))7>>&)))))))s 377c|}tjdtdg5|t t |ddddS#1swxYwYdS)Nrarrb)rprr]rirCIOErrorr"r|s r3test_wait_for_file_no_filez,TestSyncTestUtils.test_wait_for_file_no_files"" Z5D!II N N N > >   g}f = = = > > > > > > > > > > > > > > > > > >s"A((A,/A,c |}t|d5}|ddddn #1swxYwYt|dtj|sJdS)Nrnr4F)deleterorus r3test_wait_for_file_no_deletez.TestSyncTestUtils.test_wait_for_file_no_deletes"" &#   ! GGENNN               fU++++w~~f%%%%%%%rycTtdd}||ddS)NcdS)Nr(rKrKr6r3z3TestSyncTestUtils.test_call_until..sr6zret == 1r()r r:)r=rets r3test_call_untilz!TestSyncTestUtils.test_call_untils/J// a     r6N) rZr[r\rlrxr}rrrrKr6r3r_r_sqIII ******>>> &&&!!!!!r6r_c,eZdZdZdZdZdZdZdS)TestFSTestUtilsctt5}||jdddddS#1swxYwYdS)Nrt)r__file__r:moder=rws r3test_open_textzTestFSTestUtils.test_open_texts x  +A   QVT * * * + + + + + + + + + + + + + + + + + +>AActt5}||jdddddS#1swxYwYdS)Nrb)rrr:rrs r3test_open_binaryz TestFSTestUtils.test_open_binarys  " " +a   QVT * * * + + + + + + + + + + + + + + + + + +rc|}t|tj|sJt|tj|sJdSrI)rprrdrsisdirr|s r3test_safe_mkdirzTestFSTestUtils.test_safe_mkdirsg""6w}}V$$$$$6w}}V$$$$$$$r6c|}t|dt|tj|rJt|t j|t|tj|rJtj dttj d5}| t5t|dddn #1swxYwY|jsJ ddddS#1swxYwYdS)Nrnzpsutil.tests.os.stat) side_effect)rprqcloserrdrsrtmkdirrr]OSErrorerrnoEINVALrCcalled)r=rvms r3test_safe_rmpathz TestFSTestUtils.test_safe_rmpaths"" VS!!!F7>>&)))))F F7>>&))))) Z.$+EL"$=$=??? BC""7++ $ $F### $ $ $ $ $ $ $ $ $ $ $ $ $ $ $8OO8O                   s6(ED ED# #E&D# ' EEEc|}tj}tj|t |5|tjtj||dddn #1swxYwY|tj|dSrI)rprdgetcwdrr r:rsjoin)r=rvbases r3 test_chdirzTestFSTestUtils.test_chdirs""y{{  6]] F F   RY[["',,tV*D*D E E E F F F F F F F F F F F F F F F d+++++s ABB!$B!N)rZr[r\rrrrrrKr6r3rrs_++++++%%%&,,,,,r6rcVeZdZdZdZeje ddZdZ dS)TestProcessUtilsc |}tj|j}|sJt |rJtjjrJtjjrJdSrI) spawn_testprocrgProcesspid is_runningrtests _pids_started_subprocesses_started)r=subpps r3test_reap_childrenz#TestProcessUtils.test_reap_childrens|""$$ N48 $ $||~~~<<>>!!!<----<555555r6c|\}}||j|j|sJ|sJt j}|||gt jd}|t|d| ||| |||| tj || |jt||rJ|sJt||rJdS)NT) recursive)spawn_children_pairassertNotEqualrrrgrchildrenr:lenassertInppidrdrer)r=child grandchildrs r3test_spawn_children_pairz)TestProcessUtils.test_spawn_children_pairs 4466z EIz~666!!!!!$$&&&&&>##,,.. E7+++>##,,t,<< X*** eX&&& j(+++ ry{{333 **EI666%##%%%%%$$&&&&&*((*******r6 POSIX onlyc|\}}||tjdSrI) spawn_zombier:statusrg STATUS_ZOMBIE)r=parentzombies r3test_spawn_zombiez"TestProcessUtils.test_spawn_zombies>**,, &*>?????r6c|}t|||t|tj|j}t|||t|t ddg}tj|tj tj }t|||t||j}t|||t|tra| \}}t|t|||||dSdS)Nz-czimport time; time.sleep(60);)stdoutstderr) rrassertProcessGonergrrrPopen subprocessPIPErr)r=rcmdrrrs r3test_terminatezTestProcessUtils.test_terminates    ! !!  q!!!! N4..004 5 5!  q!!!! 4!?@ LZ_Z_ M M M!  q!!!! !!##'# q!!!#  +!..00NFF f    f     " "6 * * *  " "6 * * * * *  + +r6N) rZr[r\rrr skipIfrrrrKr6r3rrsp666+++*X_Y --@@.-@+++++r6rceZdZdZeje ddZdZeje deje pe ddZ dZ dS) TestNetUtilsct}tjtd|f5}||d|ddddS#1swxYwYdS)Nraddrr()r contextlibclosingr r: getsockname)r=portss r3r zTestNetUtils.bind_sockets   "d < < < = = 7   Q]]__Q/ 6 6 6 7 7 7 7 7 7 7 7 7 7 7 7 7 7 7 7 7 7s/A//A36A3rc(|}t|}tj|5||jt j||jt j || |tj |sJtjtj|jsJ dddn #1swxYwY|}t|t j}tj|5||jt jddddS#1swxYwYdS)N)type)rpr rrr:familysocketAF_UNIXr SOCK_STREAMrrdrsrtstatS_ISSOCKst_mode SOCK_DGRAM)r=namesocks r3test_bind_unix_socketz"TestNetUtils.test_bind_unix_sockets  %%   % % 8 8   T[&. 9 9 9   TY(: ; ; ;   T--// 6 6 67>>$'' ' ''=!677 7 77 7  8 8 8 8 8 8 8 8 8 8 8 8 8 8 8  6+<===   % % ; ;   TY(9 : : : ; ; ; ; ; ; ; ; ; ; ; ; ; ; ; ; ; ;s$CDD  D &FF F cdtf}ttj|\}}t j|5t j|5||||||| ||dddn #1swxYwYddddS#1swxYwYdS)Nz 127.0.0.1r) rrrAF_INETrrr:r getpeernamer)r=rserverclients r3tcp_tcp_socketpairzTestNetUtils.tcp_tcp_socketpair.s]__-'TBBB   ' ' @ @#F++ @ @  !3!3!5!5t<<<  !3!3!5!5t<<<##F$6$6$8$8$???  @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @s7C5A9C C5C! !C5$C! %C55C9<C9z*/var/run/log UNIX socket opened by defaultc|tj}|}|drJ|}t |\}} t j|sJtj t j |j sJ| ||z d| t|dd| ||| ||||dS#||wxYw)Nunix)kindr)rgrnum_fds connectionsrpr!rdrsrtrrrr:rrrr)r=rrrrrs r3test_unix_socketpairz!TestNetUtils.test_unix_socketpair9sk N  ))++==f=-----  (.. 7>>$'' ' ''=!677 7 77   QYY[[72A 6 6 6   SF!;!;<.funbs JJJ!OJJJJJr6rr )times warmup_times)executer:)r=rrs @r3 test_timeszTestMemLeakClass.test_timesas]     aj S 444 UR(((((r6cn|t|jdd|t|jdd|t|jdd|t|jdd |t|jd d dS) NcdSNrrKrKr6r3rz1TestMemLeakClass.test_param_err..iAr6rr cdSrrKrKr6r3rz1TestMemLeakClass.test_param_err..jrr6cdSrrKrKr6r3rz1TestMemLeakClass.test_param_err..krr6)r cdSrrKrKr6r3rz1TestMemLeakClass.test_param_err..lrr6) tolerancecdSrrKrKr6r3rz1TestMemLeakClass.test_param_err..mrr6)r*)rCrLrr=s r3test_param_errzTestMemLeakClass.test_param_errhs *dlIIQGGG *dlIIRHHH *dlIIBOOO *dlIILLL *dlIIrJJJJJr6z skipped on CIclg}|fd} |td|j|d~dS#~wxYw)Nc6|ddzdSNxxxxxxxxxxxxxxxxxxxxxxxxiappendlss r3rz+TestMemLeakClass.test_leak_mem..funts IIho & & & & &r6z extra-mem2r)assertRaisesRegexAssertionErrorr)r=r$rs r3 test_leak_memzTestMemLeakClass.test_leak_memosf ' ' ' '   " ">;#'<B # @ @ @FFFFs$03czfd}gtrdnd}td|zj|dS)Nctt}|j|dSrI)rqr addCleanuprr")rwboxr=s r3rz1TestMemLeakClass.test_unclosed_files..funs5XA OOAG $ $ $ JJqMMMMMr6fdhandlez unclosed )rr&r'r)r=rrr,s` @r3test_unclosed_filesz$TestMemLeakClass.test_unclosed_files~si       *tt( ~{T/A#|S 2 2 2 2 2r6cfd}gd}|||dd|t|dzdS)Nc8ddzdSrr!r#sr3rz,TestMemLeakClass.test_tolerance..funs IIho & & & & &r6dri )r r rr()rr:r)r=rr r$s @r3test_tolerancezTestMemLeakClass.test_tolerancesp ' ' ' ' '  SA0  2 2 2 R%!),,,,,r6c~d}|t||t5|t|dddn #1swxYwYd}|t5|t|ddddS#1swxYwYdS)Ncddz dSr.rKrKr6r3rz0TestMemLeakClass.test_execute_w_exc..funs EEEEr6cdSrIrKrKr6r3rz0TestMemLeakClass.test_execute_w_exc..funs Dr6) execute_w_excrDrCrr')r=rs r3test_execute_w_excz#TestMemLeakClass.test_execute_w_excsF    ,c222   0 1 1 - -   w , , , - - - - - - - - - - - - - - -      ~ . . 7 7   0# 6 6 6 7 7 7 7 7 7 7 7 7 7 7 7 7 7 7 7 7 7s#A!!A%(A% B22B69B6N) rZr[r\rrrr rr r(r/r3r8rKr6r3rr^s)))KKKX_Z11  21  2 2 2--- 7 7 7 7 7r6rceZdZdZdZdS)TestTestingUtilsc2tj}t|}|d||jDdd}|||dS)Nc*g|]}|ddk|S)r(rrK.0xs r3 z;TestTestingUtils.test_process_namespace..s!@@@Q1qr6r)rgrrtestrigettersr:r)r=rnsrs r3test_process_namespacez'TestTestingUtils.test_process_namespaces~ N   q ! !  @@"''"*--@@@CAF )))))r6ct}d||jDdd}||t jdS)Nc*g|]}|ddk|S)r( net_if_addrsrKr=s r3r@z:TestTestingUtils.test_system_namespace..s&HHHQ11G1Gq1G1G1Gr6r)rrirBr:rgrG)r=rCrs r3test_system_namespacez&TestTestingUtils.test_system_namespacesc   HH"''"*--HHHKAN  3 5 566666r6N)rZr[r\rDrHrKr6r3r:r:s2***77777r6r:ceZdZdZdS)TestOtherUtilscttjdddddsJttrJdS)Nr4za b cr(rr7)rr namedtupletuplers r3test_is_namedtuplez!TestOtherUtils.test_is_namedtuplesPC[3E7CCAq!LLMMMMM )))))))r6N)rZr[r\rNrKr6r3rJrJs#*****r6rJ__main__) run_from_name)8__doc__rrrrdrrrrgrrrpsutil._commonrrr psutil.testsr r r r r rrrrrrrrrrrrrrrrrrr r!r"r#r%r_rrrrr:rJrZpsutil.tests.runnerrPrrKr6r3rUs &&&&&&$$$$$$(((((($$$$$$))))))############''''''&&&&&&------&&&&&&******''''''######&&&&&&))))))######$$$$$$""""""))))))''''''""""""''''''!!!!!!((((((&&&&&&%%%%%% ?C?C?C?C?C?C?C?CD$!$!$!$!$!$!$!$!N*,*,*,*,*,n*,*,*,ZA+A+A+A+A+~A+A+A+HDADADADADA>DADADAN =7=7=7=7=7~=7=7 =7@ 7 7 7 7 7~ 7 7 7*****^*** z111111M(r6