Skip to content

bpo-31904: Add time module support for VxWorks RTOS #12305

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 8 commits into from
Apr 15, 2019
Merged
Show file tree
Hide file tree
Changes from 5 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions Doc/library/time.rst
Original file line number Diff line number Diff line change
Expand Up @@ -153,6 +153,8 @@ Functions
:c:func:`QueryPerformanceCounter`. The resolution is typically better than one
microsecond.

VxWorks doesn't support this fucntion.

.. deprecated:: 3.3
The behaviour of this function depends on the platform: use
:func:`perf_counter` or :func:`process_time` instead, depending on your
Expand Down
8 changes: 6 additions & 2 deletions Lib/test/test_time.py
Original file line number Diff line number Diff line change
Expand Up @@ -88,6 +88,8 @@ def check_ns(sec, ns):
check_ns(time.clock_gettime(time.CLOCK_REALTIME),
time.clock_gettime_ns(time.CLOCK_REALTIME))

@unittest.skipUnless(hasattr(time, 'clock'),
'need time.clock()')
def test_clock(self):
with self.assertWarns(DeprecationWarning):
time.clock()
Expand Down Expand Up @@ -549,8 +551,10 @@ def test_localtime_failure(self):
self.assertRaises(ValueError, time.ctime, float("nan"))

def test_get_clock_info(self):
clocks = ['clock', 'monotonic', 'perf_counter', 'process_time', 'time']

if hasattr(time, 'clock'):
clocks = ['clock', 'monotonic', 'perf_counter', 'process_time', 'time']
else:
clocks = ['monotonic', 'perf_counter', 'process_time', 'time']
for name in clocks:
if name == 'clock':
with self.assertWarns(DeprecationWarning):
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
Add time module support and fix test_time faiures for VxWorks.
19 changes: 12 additions & 7 deletions Modules/timemodule.c
Original file line number Diff line number Diff line change
Expand Up @@ -145,7 +145,7 @@ perf_counter(_Py_clock_info_t *info)
return _PyFloat_FromPyTime(t);
}

#if defined(MS_WINDOWS) || defined(HAVE_CLOCK)
#if (defined(MS_WINDOWS) || defined(HAVE_CLOCK)) && !defined(__VXWORKS__)
#define PYCLOCK
static PyObject*
pyclock(_Py_clock_info_t *info)
Expand Down Expand Up @@ -765,7 +765,7 @@ time_strftime(PyObject *self, PyObject *args)
return NULL;
}

#if defined(_MSC_VER) || (defined(__sun) && defined(__SVR4)) || defined(_AIX)
#if defined(_MSC_VER) || (defined(__sun) && defined(__SVR4)) || defined(_AIX) || defined(__VXWORKS__)
if (buf.tm_year + 1900 < 1 || 9999 < buf.tm_year + 1900) {
PyErr_SetString(PyExc_ValueError,
"strftime() requires year in [1; 9999]");
Expand Down Expand Up @@ -1005,18 +1005,23 @@ time_mktime(PyObject *self, PyObject *tup)
{
return NULL;
}
#ifndef _AIX
buf.tm_wday = -1; /* sentinel; original value ignored */
tt = mktime(&buf);
#else

#if defined(_AIX) || (defined(__VXWORKS__) && !defined(_WRS_CONFIG_LP64))
/* year < 1902 or year > 2037 */
if ((buf.tm_year < 2) || (buf.tm_year > 137)) {
/* Issue #19748: On AIX, mktime() doesn't report overflow error for
* timestamp < -2^31 or timestamp > 2**31-1. */
* timestamp < -2^31 or timestamp > 2**31-1. VxWorks has the same
* issue when working in 32 bit mode. */
PyErr_SetString(PyExc_OverflowError,
"mktime argument out of range");
return NULL;
}
#endif

#ifndef _AIX
buf.tm_wday = -1; /* sentinel; original value ignored */
tt = mktime(&buf);
#else
year = buf.tm_year;
/* year < 1970 - adjust buf.tm_year into legal range */
while (buf.tm_year < 70) {
Expand Down