Commit Graph

192 Commits

Author SHA1 Message Date
Malcolm Smith 872c0714fc
gh-71052: Change Android's `sys.platform` from "linux" to "android"
Co-authored-by: Erlend E. Aasland <erlend.aasland@protonmail.com>
2024-03-11 19:25:39 +00:00
Petr Viktorin 879f4546bf
gh-110850: Add PyTime_t C API (GH-115215)
* gh-110850: Add PyTime_t C API

Add PyTime_t API:

* PyTime_t type.
* PyTime_MIN and PyTime_MAX constants.
* PyTime_AsSecondsDouble(), PyTime_Monotonic(),
  PyTime_PerfCounter() and PyTime_GetSystemClock() functions.

Co-authored-by: Victor Stinner <vstinner@python.org>
2024-02-12 18:13:10 +01:00
Victor Stinner 46d77610fc
gh-106316: Remove pytime.h header file (#106317)
Remove the "cpython/pytime.h" header file: it only contained private
functions. Move functions to the internal pycore_time.h header file.

Move tests from _testcapi to _testinternalcapi. Rename also test
methods to have the same name than tested C functions.

No longer export these functions:

* _PyTime_Add()
* _PyTime_As100Nanoseconds()
* _PyTime_FromMicrosecondsClamp()
* _PyTime_FromTimespec()
* _PyTime_FromTimeval()
* _PyTime_GetPerfCounterWithInfo()
* _PyTime_MulDiv()
2023-07-01 22:27:18 +00:00
Benjamin Peterson 9e8b86de4e
Remove space. (GH-97807)
Automerge-Triggered-By: GH:benjaminp
2022-10-03 17:12:36 -07:00
Christian Heimes 760ec8940a
gh-90473: WASI: skip gethostname tests (GH-93092)
- WASI's ``gethostname()`` is a stub that always fails with OSError
  ``ENOTSUP``
- skip mailcap ``test`` if subprocess is not available
- WASI process_time clock does not work.
2022-05-23 10:39:57 +02:00
Christian Heimes ef1327e3b6
bpo-40280: Skip more tests on Emscripten (GH-31947)
- lchmod, lchown are not fully implemented
- skip umask tests
- cannot fstat unlinked or renamed files yet
- ignore musl libc issues that affect Emscripten
2022-03-17 12:09:57 +01:00
Christian Heimes a4674f0194
bpo-40280: Detect presence of time.tzset and thread_time clock (GH-31898) 2022-03-15 21:55:35 +01:00
Christian Heimes 2cf7f865f0
bpo-46587: Skip tests if strftime does not support glibc extension (GH-31873)
Co-authored-by: Victor Stinner <vstinner@python.org>
2022-03-15 10:41:04 +01:00
Nikita Sobolev c27a33132b
bpo-46530: add `"thread_time"` to `test_time.test_get_clock_info` (#30913) 2022-01-27 21:43:00 -08:00
Victor Stinner a847785b40
bpo-43869: Time Epoch is the same on all platforms (GH-30664) 2022-01-19 11:27:11 +01:00
Jakub Kulík 427a490c49
bpo-46099: Fix pthread_getcpuclockid test on Solaris (GH-30140)
Co-authored-by: Andrew Svetlov <andrew.svetlov@gmail.com>
2021-12-18 15:26:24 +02:00
Christian Clauss 745c9d9dfc
Fix typos in the Lib directory (GH-28775)
Fix typos in the Lib directory as identified by codespell.

Co-authored-by: Terry Jan Reedy <tjreedy@udel.edu>
2021-10-06 16:13:48 -07:00
Victor Stinner 09796f2f14
bpo-41710: Add _PyTime_AsTimespec_clamp() (GH-28629)
Add the _PyTime_AsTimespec_clamp() function: similar to
_PyTime_AsTimespec(), but clamp to _PyTime_t min/max and don't raise
an exception.

PyThread_acquire_lock_timed() now uses _PyTime_AsTimespec_clamp() to
remove the Py_UNREACHABLE() code path.

* Add _PyTime_AsTime_t() function.
* Add PY_TIME_T_MIN and PY_TIME_T_MAX constants.
* Replace _PyTime_AsTimeval_noraise() with _PyTime_AsTimeval_clamp().
* Add pytime_divide_round_up() function.
* Fix integer overflow in pytime_divide().
* Add pytime_divmod() function.
2021-09-30 02:11:41 +02:00
Ronald Oussoren 41761933c1
bpo-41100: Support macOS 11 and Apple Silicon (GH-22855)
Co-authored-by:  Lawrence D’Anna <lawrence_danna@apple.com>

* Add support for macOS 11 and Apple Silicon (aka arm64)
   
  As a side effect of this work use the system copy of libffi on macOS, and remove the vendored copy

* Support building on recent versions of macOS while deploying to older versions

  This allows building installers on macOS 11 while still supporting macOS 10.9.
2020-11-08 10:05:27 +01:00
Hai Shi 3ddc634cd5
bpo-40275: Use new test.support helper submodules in tests (GH-21219) 2020-06-30 15:46:06 +02:00
Pablo Galindo 293dd23477
Remove binding of captured exceptions when not used to reduce the chances of creating cycles (GH-17246)
Capturing exceptions into names can lead to reference cycles though the __traceback__ attribute of the exceptions in some obscure cases that have been reported previously and fixed individually. As these variables are not used anyway, we can remove the binding to reduce the chances of creating reference cycles.

See for example GH-13135
2019-11-19 21:34:03 +00:00
Paul Monson 9cd39b16e2 bpo-37552: Skip failing tests in strptime/strftime with UCRT version 17763.615 (#14460)
A bug in MSVC UCRT version 17763.615 (which has been fixed in newer versions) is causing test failures in some strptime/strftime tests when the default code page is c65001. This change selectively skips the tests affected by this.
2019-07-18 15:56:59 +02:00
Matthias Bussonnier e2500610c6 bpo-36895: remove time.clock() as per removal notice. (GH-13270)
`time.clock()` was deprecated in 3.3, and marked for removal removal in
3.8; this thus remove it from the time module.
2019-05-12 18:34:44 -07:00
Victor Stinner d246a6766b
bpo-36454: Fix test_time.test_monotonic() (GH-12929)
Change test_time.test_monotonic() to test only the lower bound of elapsed time
after a sleep command rather than the upper bound. This prevents unnecessary
test failures on slow buildbots. Patch by Victor Stinner.
2019-04-24 00:15:12 +02:00
pxinwr f1464f4d2e bpo-31904: Port the time module on VxWorks (GH-12305)
time.clock() is not available on VxWorks.
2019-04-15 11:06:21 +02:00
Michael Felt e2926b7248 bpo-34373: fix test_mktime and test_pthread_getcpuclickid tests on AIX (GH-8726)
* Fix test_mktime on AIX by adding code to get mktime to behave the
  same way as it does on other *nix systems
* Fix test_pthread_getcpuclickid in AIX by adjusting the test case
  expectations when running on AIX in 32-bit mode

Patch by Michael Felt.
2018-12-28 23:57:37 +10:00
Victor Stinner 48498dd57f
bpo-33723: Remove busy loop from test_time (GH-10773)
The "busy loops" of test_process_time() and test_thread_time() are
not reliable and fail randomly on Windows: remove them.
2018-11-28 18:30:10 +01:00
Victor Stinner 65c216e74f
bpo-33723: Fix test_time.test_thread_time() (GH-10724)
Tolerate up to 30 ms, instead of 15 min, in other threads.
2018-11-26 21:19:29 +01:00
Srinivas Thatiparthy (శ్రీనివాస్ తాటిపర్తి) 90d0cfb222 bpo-35202: Remove unused imports in tests. (GH-10561) 2018-11-16 17:32:58 +02:00
Benjamin Peterson e1a34ceb54
closes bpo-34654: Tolerate + at the beginning of large years. (GH-9238) 2018-09-12 16:21:36 -07:00
Gregory P. Smith 76be0fffff
bpo-13312: Avoid int underflow in time year. (GH-8912)
Avoids an integer underflow in the time module's year handling code.
2018-08-24 18:08:50 -07:00
Bo Bayles 938045f335 bpo-34179: Make sure decimal context doesn't affect other tests. (#8376) 2018-07-21 19:54:14 +02:00
Victor Stinner e78dace8dc
bpo-33723: Fix test_time.test_process_time() (GH-8358)
The test failed on my laptop because the busy loop took 15.9 ms
whereas the test expects at least 20 ms. Modify test_process_time()
as test_thread_time() has been modified recently: only require 15 ms
instead of 20 ms.
2018-07-21 03:31:51 +02:00
Victor Stinner d6345def68
bpo-33723: Fix test_time.test_thread_time() (GH-8267)
The test failed on AMD64 Debian root 3.x buildbot because the busy
loop of 100 ms only increased time.thread_time() by 19.9 ms which is
smaller than 20 ms. Modify the test to tolerate a delta of at least
15 ms instead of 20 ms.
2018-07-12 15:25:22 +02:00
Antoine Pitrou 4bd41c9b52
bpo-32025: Add time.thread_time() (#4410)
* bpo-32025: Add time.thread_time()

* Add missing #endif

* Add NEWS blurb

* Add docs and whatsnew

* Address review comments

* Review comments
2017-11-15 22:52:21 +01:00
Victor Stinner c29b585fd4
bpo-31784: Implement PEP 564: add time.time_ns() (#3989)
Add new time functions:

* time.clock_gettime_ns()
* time.clock_settime_ns()
* time.monotonic_ns()
* time.perf_counter_ns()
* time.process_time_ns()
* time.time_ns()

Add new _PyTime functions:

* _PyTime_FromTimespec()
* _PyTime_FromNanosecondsObject()
* _PyTime_FromTimeval()

Other changes:

* Add also os.times() tests to test_os.
* pytime_fromtimeval() and pytime_fromtimeval() now return
  _PyTime_MAX or _PyTime_MIN on overflow, rather than undefined
  behaviour
* _PyTime_FromNanoseconds() parameter type changes from long long to
  _PyTime_t
2017-11-02 07:28:27 -07:00
Victor Stinner 884d13a55f time.clock() now emits a DeprecationWarning (GH-4020)
bpo-31803: time.clock() and time.get_clock_info('clock') now emit a
DeprecationWarning warning.

Replace time.clock() with time.perf_counter() in tests and demos.

Remove also hasattr(time, 'monotonic') in test_time since time.monotonic()
is now always available since Python 3.5.
2017-10-17 14:46:45 -07:00
Pablo Galindo 2c15b29aea bpo-31786: Make functions in the select module blocking when timeout is a small negative value. (#4003) 2017-10-17 17:14:41 +03:00
Benjamin Peterson 86566702f3 weaken pthread_getcpuclockid test (more bpo-31596) (#3904)
There just isn't much we can assert in a portable way.
2017-10-05 22:50:42 -07:00
pdox e14679c784 closes bpo-31596: Add an interface for pthread_getcpuclockid(3) (#3756) 2017-10-05 00:01:56 -07:00
Han Lee 829dacce4f bpo-26669: Fix nan arg value error in pytime.c (#3085)
* Fix #26669

* Modify NaN check function and error message

* Fix pytime.c when arg is nan

* fix whitespace
2017-09-08 16:05:05 -07:00
Antoine Pitrou a6a4dc816d bpo-31370: Remove support for threads-less builds (#3385)
* Remove Setup.config
* Always define WITH_THREAD for compatibility.
2017-09-07 18:56:24 +02:00
Serhiy Storchaka f7eae0adfc [security] bpo-13617: Reject embedded null characters in wchar* strings. (#2302)
Based on patch by Victor Stinner.

Add private C API function _PyUnicode_AsUnicode() which is similar to
PyUnicode_AsUnicode(), but checks for null characters.
2017-06-28 08:30:06 +03:00
Victor Stinner 717a32b755 Fix typo in test_time.py 2016-08-17 11:07:21 +02:00
Victor Stinner c60542b12b pytime: add _PyTime_check_mul_overflow() macro to avoid undefined behaviour
Overflow test in test_FromSecondsObject() fails on FreeBSD 10.0 buildbot which
uses clang. clang implements more aggressive optimization which gives
different result than GCC on undefined behaviours.

Check if a multiplication will overflow, instead of checking if a
multiplicatin had overflowed, to avoid undefined behaviour.

Add also debug information if the test on overflow fails.
2015-09-10 15:55:07 +02:00
Victor Stinner 350b51839a Fix test_time on platform with 32-bit time_t type
Filter also values for check_float_rounding().
2015-09-10 11:45:06 +02:00
Victor Stinner 4237d3474c Fix test_time on platform with 32-bit time_t type
Filter values which would overflow when converted to a C time_t type.
2015-09-10 10:10:39 +02:00
Victor Stinner 9c72f9b30a Fix test_time on Windows
* Filter values which would overflow on conversion to the C long type
  (for timeval.tv_sec).
* Adjust also the message of OverflowError on PyTime conversions
* test_time: add debug information if a timestamp conversion fails
2015-09-10 09:10:14 +02:00
Victor Stinner 3e2c8d84c6 test_time: rewrite PyTime API rounding tests
Drop all hardcoded tests. Instead, reimplement each function in Python, usually
using decimal.Decimal for the rounding mode.

Add much more values to the dataset. Test various timestamp units from
picroseconds to seconds, in integer and float.

Enhance also _PyTime_AsSecondsDouble().
2015-09-09 22:32:48 +02:00
Victor Stinner 7667f58151 Issue #23517: fromtimestamp() and utcfromtimestamp() methods of
datetime.datetime now round microseconds to nearest with ties going to nearest
even integer (ROUND_HALF_EVEN), as round(float), instead of rounding towards
-Infinity (ROUND_FLOOR).

pytime API: replace _PyTime_ROUND_HALF_UP with _PyTime_ROUND_HALF_EVEN. Fix
also _PyTime_Divide() for negative numbers.

_PyTime_AsTimeval_impl() now reuses _PyTime_Divide() instead of reimplementing
rounding modes.
2015-09-09 01:02:23 +02:00
Steve Dower 45fd95155f Merge from 3.5 2015-09-06 22:31:26 -07:00
Steve Dower e5b5895b5b Issue #24917: time_strftime() buffer over-read. 2015-09-06 19:20:51 -07:00
Larry Hastings 62b24624dd Backing out 09b62202d9b7; the tests fail on Linux, and it needs a re-think. 2015-09-06 00:31:02 -07:00
Steve Dower 643d6d3135 Issue #24917: Backed out changeset 09b62202d9b7 2015-09-05 23:12:18 -07:00
Steve Dower dcaf4ccf3f Issue #24917: Backed out changeset 09b62202d9b7 2015-09-05 23:11:53 -07:00