From fded615bea0bb70bb71103dbd29e5ae04baaf4b7 Mon Sep 17 00:00:00 2001 From: pxin Date: Wed, 20 May 2020 17:32:27 +0800 Subject: [PATCH 1/3] Fix os module failures for VxWorks RTOS --- Lib/test/test_os.py | 7 ++++++- Lib/test/test_posix.py | 14 ++++++++++---- .../Tests/2020-05-20-17-28-46.bpo-31904.yt83Ge.rst | 1 + Modules/posixmodule.c | 2 ++ 4 files changed, 19 insertions(+), 5 deletions(-) create mode 100644 Misc/NEWS.d/next/Tests/2020-05-20-17-28-46.bpo-31904.yt83Ge.rst diff --git a/Lib/test/test_os.py b/Lib/test/test_os.py index 362ba9e1042cbc..2bc52b533106c4 100644 --- a/Lib/test/test_os.py +++ b/Lib/test/test_os.py @@ -102,7 +102,12 @@ def test_getcwd_long_path(self): # On Windows, the test can stop when trying to create a path longer # than MAX_PATH if long paths support is disabled: # see RtlAreLongPathsEnabled(). - min_len = 2000 # characters + # + # On VxWorks, PATH_MAX is defined as 1024 bytes. + if sys.platform == 'vxworks': + min_len = 1000 + else: + min_len = 2000 # characters dirlen = 200 # characters dirname = 'python_test_dir_' dirname = dirname + ('a' * (dirlen - len(dirname))) diff --git a/Lib/test/test_posix.py b/Lib/test/test_posix.py index be121ae463dbb3..dde6145809acdd 100644 --- a/Lib/test/test_posix.py +++ b/Lib/test/test_posix.py @@ -35,6 +35,12 @@ def _supports_sched(): return False return True +def _supports_shell(): + if sys.platform == "vxworks": + return False + else: + return True + requires_sched = unittest.skipUnless(_supports_sched(), 'requires POSIX scheduler API') @@ -1028,7 +1034,7 @@ def test_getgrouplist(self): self.assertIn(group, posix.getgrouplist(user, group)) - @unittest.skipUnless(hasattr(os, 'getegid'), "test needs os.getegid()") + @unittest.skipUnless(_supports_shell() and hasattr(os, 'getegid'), "test needs shell support and os.getegid()") def test_getgroups(self): with os.popen('id -G 2>/dev/null') as idg: groups = idg.read().strip() @@ -1078,7 +1084,7 @@ def test_chmod_dir_fd(self): finally: posix.close(f) - @unittest.skipUnless(os.chown in os.supports_dir_fd, "test needs dir_fd support in os.chown()") + @unittest.skipUnless(hasattr(os, 'chown') and (os.chown in os.supports_dir_fd), "test needs dir_fd support in os.chown()") def test_chown_dir_fd(self): support.unlink(support.TESTFN) support.create_empty_file(support.TESTFN) @@ -1166,7 +1172,7 @@ def test_mkdir_dir_fd(self): posix.close(f) support.rmtree(support.TESTFN + 'dir') - @unittest.skipUnless((os.mknod in os.supports_dir_fd) and hasattr(stat, 'S_IFIFO'), + @unittest.skipUnless(hasattr(os, 'mknod') and (os.mknod in os.supports_dir_fd) and hasattr(stat, 'S_IFIFO'), "test requires both stat.S_IFIFO and dir_fd support for os.mknod()") def test_mknod_dir_fd(self): # Test using mknodat() to create a FIFO (the only use specified @@ -1199,7 +1205,7 @@ def test_open_dir_fd(self): posix.close(a) posix.close(b) - @unittest.skipUnless(os.readlink in os.supports_dir_fd, "test needs dir_fd support in os.readlink()") + @unittest.skipUnless(hasattr(os, 'readlink') and (os.readlink in os.supports_dir_fd), "test needs dir_fd support in os.readlink()") def test_readlink_dir_fd(self): os.symlink(support.TESTFN, support.TESTFN + 'link') f = posix.open(posix.getcwd(), posix.O_RDONLY) diff --git a/Misc/NEWS.d/next/Tests/2020-05-20-17-28-46.bpo-31904.yt83Ge.rst b/Misc/NEWS.d/next/Tests/2020-05-20-17-28-46.bpo-31904.yt83Ge.rst new file mode 100644 index 00000000000000..1679801a111066 --- /dev/null +++ b/Misc/NEWS.d/next/Tests/2020-05-20-17-28-46.bpo-31904.yt83Ge.rst @@ -0,0 +1 @@ +Fix os module failures for VxWorks RTOS. diff --git a/Modules/posixmodule.c b/Modules/posixmodule.c index 2ddf30de89a680..cd3455b1f3288d 100644 --- a/Modules/posixmodule.c +++ b/Modules/posixmodule.c @@ -12540,6 +12540,8 @@ os_cpu_count_impl(PyObject *module) ncpu = mpctl(MPC_GETNUMSPUS, NULL, NULL); #elif defined(HAVE_SYSCONF) && defined(_SC_NPROCESSORS_ONLN) ncpu = sysconf(_SC_NPROCESSORS_ONLN); +#elif defined(__VXWORKS__) + ncpu = __builtin_popcount(vxCpuEnabledGet()); #elif defined(__DragonFly__) || \ defined(__OpenBSD__) || \ defined(__FreeBSD__) || \ From 43d2b22a4e89a16eb2f733a25170e562eb016a98 Mon Sep 17 00:00:00 2001 From: pxin Date: Tue, 28 Jul 2020 12:23:00 +0800 Subject: [PATCH 2/3] refine the modification in test_getcwd_long_path() --- Lib/test/test_os.py | 7 +++---- 1 file changed, 3 insertions(+), 4 deletions(-) diff --git a/Lib/test/test_os.py b/Lib/test/test_os.py index 2bc52b533106c4..6295b87b790578 100644 --- a/Lib/test/test_os.py +++ b/Lib/test/test_os.py @@ -102,12 +102,11 @@ def test_getcwd_long_path(self): # On Windows, the test can stop when trying to create a path longer # than MAX_PATH if long paths support is disabled: # see RtlAreLongPathsEnabled(). - # - # On VxWorks, PATH_MAX is defined as 1024 bytes. + min_len = 2000 # characters + # On VxWorks, PATH_MAX is defined as 1024 bytes. Creating a path + # longer than PATH_MAX will fail. if sys.platform == 'vxworks': min_len = 1000 - else: - min_len = 2000 # characters dirlen = 200 # characters dirname = 'python_test_dir_' dirname = dirname + ('a' * (dirlen - len(dirname))) From 2d168fa033a353a6700619cdbd48c8c0723bbcbe Mon Sep 17 00:00:00 2001 From: pxin Date: Thu, 30 Jul 2020 19:10:26 +0800 Subject: [PATCH 3/3] revert test_posix.py and posixmodule.c --- Lib/test/test_posix.py | 14 ++++---------- Modules/posixmodule.c | 2 -- 2 files changed, 4 insertions(+), 12 deletions(-) diff --git a/Lib/test/test_posix.py b/Lib/test/test_posix.py index dde6145809acdd..be121ae463dbb3 100644 --- a/Lib/test/test_posix.py +++ b/Lib/test/test_posix.py @@ -35,12 +35,6 @@ def _supports_sched(): return False return True -def _supports_shell(): - if sys.platform == "vxworks": - return False - else: - return True - requires_sched = unittest.skipUnless(_supports_sched(), 'requires POSIX scheduler API') @@ -1034,7 +1028,7 @@ def test_getgrouplist(self): self.assertIn(group, posix.getgrouplist(user, group)) - @unittest.skipUnless(_supports_shell() and hasattr(os, 'getegid'), "test needs shell support and os.getegid()") + @unittest.skipUnless(hasattr(os, 'getegid'), "test needs os.getegid()") def test_getgroups(self): with os.popen('id -G 2>/dev/null') as idg: groups = idg.read().strip() @@ -1084,7 +1078,7 @@ def test_chmod_dir_fd(self): finally: posix.close(f) - @unittest.skipUnless(hasattr(os, 'chown') and (os.chown in os.supports_dir_fd), "test needs dir_fd support in os.chown()") + @unittest.skipUnless(os.chown in os.supports_dir_fd, "test needs dir_fd support in os.chown()") def test_chown_dir_fd(self): support.unlink(support.TESTFN) support.create_empty_file(support.TESTFN) @@ -1172,7 +1166,7 @@ def test_mkdir_dir_fd(self): posix.close(f) support.rmtree(support.TESTFN + 'dir') - @unittest.skipUnless(hasattr(os, 'mknod') and (os.mknod in os.supports_dir_fd) and hasattr(stat, 'S_IFIFO'), + @unittest.skipUnless((os.mknod in os.supports_dir_fd) and hasattr(stat, 'S_IFIFO'), "test requires both stat.S_IFIFO and dir_fd support for os.mknod()") def test_mknod_dir_fd(self): # Test using mknodat() to create a FIFO (the only use specified @@ -1205,7 +1199,7 @@ def test_open_dir_fd(self): posix.close(a) posix.close(b) - @unittest.skipUnless(hasattr(os, 'readlink') and (os.readlink in os.supports_dir_fd), "test needs dir_fd support in os.readlink()") + @unittest.skipUnless(os.readlink in os.supports_dir_fd, "test needs dir_fd support in os.readlink()") def test_readlink_dir_fd(self): os.symlink(support.TESTFN, support.TESTFN + 'link') f = posix.open(posix.getcwd(), posix.O_RDONLY) diff --git a/Modules/posixmodule.c b/Modules/posixmodule.c index cd3455b1f3288d..2ddf30de89a680 100644 --- a/Modules/posixmodule.c +++ b/Modules/posixmodule.c @@ -12540,8 +12540,6 @@ os_cpu_count_impl(PyObject *module) ncpu = mpctl(MPC_GETNUMSPUS, NULL, NULL); #elif defined(HAVE_SYSCONF) && defined(_SC_NPROCESSORS_ONLN) ncpu = sysconf(_SC_NPROCESSORS_ONLN); -#elif defined(__VXWORKS__) - ncpu = __builtin_popcount(vxCpuEnabledGet()); #elif defined(__DragonFly__) || \ defined(__OpenBSD__) || \ defined(__FreeBSD__) || \