summaryrefslogtreecommitdiffstats
path: root/Lib/test
diff options
context:
space:
mode:
authorpdox <pdox@alum.mit.edu>2017-10-05 07:01:56 (GMT)
committerBenjamin Peterson <benjamin@python.org>2017-10-05 07:01:56 (GMT)
commite14679c78464d1e0e16786c2a0e9bcebe49e842b (patch)
tree066f524eae0f2de963387477482575462393a6c8 /Lib/test
parent55fd06605b5d4fb6442645f1532aa05953bd93bc (diff)
downloadcpython-e14679c78464d1e0e16786c2a0e9bcebe49e842b.zip
cpython-e14679c78464d1e0e16786c2a0e9bcebe49e842b.tar.gz
cpython-e14679c78464d1e0e16786c2a0e9bcebe49e842b.tar.bz2
closes bpo-31596: Add an interface for pthread_getcpuclockid(3) (#3756)
Diffstat (limited to 'Lib/test')
-rw-r--r--Lib/test/test_time.py20
1 files changed, 20 insertions, 0 deletions
diff --git a/Lib/test/test_time.py b/Lib/test/test_time.py
index b2aedc3..1456748 100644
--- a/Lib/test/test_time.py
+++ b/Lib/test/test_time.py
@@ -7,6 +7,7 @@ import platform
import sys
import sysconfig
import time
+import threading
import unittest
try:
import _testcapi
@@ -80,6 +81,25 @@ class TimeTestCase(unittest.TestCase):
b = time.clock_gettime(time.CLOCK_MONOTONIC)
self.assertLessEqual(a, b)
+ @unittest.skipUnless(hasattr(time, 'pthread_getcpuclockid'),
+ 'need time.pthread_getcpuclockid()')
+ @unittest.skipUnless(hasattr(time, 'clock_gettime'),
+ 'need time.clock_gettime()')
+ @unittest.skipUnless(hasattr(time, 'CLOCK_THREAD_CPUTIME_ID'),
+ 'need time.CLOCK_THREAD_CPUTIME_ID')
+ def test_pthread_getcpuclockid(self):
+ clk_id = time.pthread_getcpuclockid(threading.get_ident())
+ self.assertTrue(type(clk_id) is int)
+ self.assertNotEqual(clk_id, time.CLOCK_THREAD_CPUTIME_ID)
+ # This should suffice to show that both calls are measuring the same clock.
+ t1 = time.clock_gettime(clk_id)
+ t2 = time.clock_gettime(time.CLOCK_THREAD_CPUTIME_ID)
+ t3 = time.clock_gettime(clk_id)
+ t4 = time.clock_gettime(time.CLOCK_THREAD_CPUTIME_ID)
+ self.assertLessEqual(t1, t2)
+ self.assertLessEqual(t2, t3)
+ self.assertLessEqual(t3, t4)
+
@unittest.skipUnless(hasattr(time, 'clock_getres'),
'need time.clock_getres()')
def test_clock_getres(self):