U 1g@sdZddlZddlZddlZddlZddlmZddlmZddlmZddlm Z ddlm Z ddlm Z dd lm Z dd lm Z dd lmZdd lmZdd lmZerddlmZddZddZe jje ddGddde Ze jje ddGddde ZdS)zmacOS specific tests.N)MACOS)POSIX) HAS_BATTERY)TOLERANCE_DISK_USAGE)TOLERANCE_SYS_MEM)PsutilTestCase)pytest)retry_on_failure)sh)spawn_testproc) terminate) getpagesizecCs<t|}|d}z t|WStk r6|YSXdS)zmExpects a sysctl command with an argument and parse the result returning only the value of interest. N)r splitint ValueError)ZcmdlineoutresultrE/opt/hc_python/lib64/python3.8/site-packages/psutil/tests/test_osx.pysysctls   rcCsHtd}|dD]}||krq,qtdttd|dtS)z)Wrapper around 'vm_stat' cmdline utility.vm_stat zline not foundz\d+r)r rrrresearchgroupr )fieldrlinerrrr+s rz MACOS onlyreasonc@s,eZdZeddZeddZddZdS) TestProcesscCstj|_dSN)r pidclsrrr setUpClass8szTestProcess.setUpClasscCst|jdSr!)r r"r#rrr tearDownClass<szTestProcess.tearDownClasscCstd|j}|dd}|dd}|dd}t|j}|t dt |ksdt |t dt |ks~t dS) Nzps -o lstart -p %sZSTARTED z%H:%M:%Sz%Y) r r"replacestriprpsutilProcessZ create_timetimestrftime localtimeAssertionError)selfoutputZstart_psZhhmmssyearZ start_psutilrrrtest_process_create_time@s z$TestProcess.test_process_create_timeN)__name__ __module__ __qualname__ classmethodr%r&r6rrrrr 6s   r c@seZdZeddZddZddZejj e o:e dkdd d d Z d d ZeddZeddZeddZeddZeddZeddZddZejj e dd ddZdS) TestSystemAPIscCsdd}tjddD]j}t|j}||j\}}}}|j|ksDt|j|ksRtt|j|t kshtt|j |t kstqdS)NcSstd|}|d}|d|d}|dd\}}}}|dkrRd}t|d}t|d}t|d}||||fS)Nz df -k "%s"rrnoner'i)r r,rpopr)pathrlinesrdevtotalusedfreerrrdfUs      z%TestSystemAPIs.test_disks..dfF)all) r-Zdisk_partitions disk_usageZ mountpointZdevicer2rBabsrDrrC)r3rEpartusagerArBrCrDrrr test_disksQs  zTestSystemAPIs.test_diskscCs td}|tjddkstdS)Nzsysctl hw.logicalcpuTZlogicalrr- cpu_countr2r3numrrrtest_cpu_count_logicallsz%TestSystemAPIs.test_cpu_count_logicalcCs td}|tjddkstdS)Nzsysctl hw.physicalcpuFrLrMrOrrrtest_cpu_count_corespsz#TestSystemAPIs.test_cpu_count_coresarm64zskipped due to #1892rcCsZt}|jddtdks"t|jddtdkss.