annotate src/testdir/thread_util.py @ 28919:99c1356f4210 v8.2.4982

patch 8.2.4982: colors in terminal window are not 100% correct Commit: https://github.com/vim/vim/commit/b2b3acbf2b3ae29ecf517f03b46fbeadf0c1a905 Author: LemonBoy <thatlemon@gmail.com> Date: Fri May 20 10:10:34 2022 +0100 patch 8.2.4982: colors in terminal window are not 100% correct Problem: Colors in terminal window are not 100% correct. Solution: Use g:terminal_ansi_colors as documented. (closes https://github.com/vim/vim/issues/10429, closes #7227 closes #10347)
author Bram Moolenaar <Bram@vim.org>
date Fri, 20 May 2022 11:15:04 +0200
parents 06e3c6bac36d
children
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
27443
06e3c6bac36d patch 8.2.4250: channel out callback test is flaky on Mac
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1 import platform
06e3c6bac36d patch 8.2.4250: channel out callback test is flaky on Mac
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2
06e3c6bac36d patch 8.2.4250: channel out callback test is flaky on Mac
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
3 if platform.system() == 'Darwin':
06e3c6bac36d patch 8.2.4250: channel out callback test is flaky on Mac
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
4 from ctypes import (
06e3c6bac36d patch 8.2.4250: channel out callback test is flaky on Mac
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
5 CDLL,
06e3c6bac36d patch 8.2.4250: channel out callback test is flaky on Mac
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
6 POINTER,
06e3c6bac36d patch 8.2.4250: channel out callback test is flaky on Mac
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
7 Structure,
06e3c6bac36d patch 8.2.4250: channel out callback test is flaky on Mac
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
8 byref,
06e3c6bac36d patch 8.2.4250: channel out callback test is flaky on Mac
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
9 c_int,
06e3c6bac36d patch 8.2.4250: channel out callback test is flaky on Mac
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
10 c_uint,
06e3c6bac36d patch 8.2.4250: channel out callback test is flaky on Mac
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
11 c_uint32,
06e3c6bac36d patch 8.2.4250: channel out callback test is flaky on Mac
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
12 c_void_p,
06e3c6bac36d patch 8.2.4250: channel out callback test is flaky on Mac
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
13 sizeof
06e3c6bac36d patch 8.2.4250: channel out callback test is flaky on Mac
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
14 )
06e3c6bac36d patch 8.2.4250: channel out callback test is flaky on Mac
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
15 from ctypes.util import find_library
06e3c6bac36d patch 8.2.4250: channel out callback test is flaky on Mac
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
16
06e3c6bac36d patch 8.2.4250: channel out callback test is flaky on Mac
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
17 class ThreadTimeConstraintPolicy(Structure):
06e3c6bac36d patch 8.2.4250: channel out callback test is flaky on Mac
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
18 _fields_ = [
06e3c6bac36d patch 8.2.4250: channel out callback test is flaky on Mac
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
19 ("period", c_uint32),
06e3c6bac36d patch 8.2.4250: channel out callback test is flaky on Mac
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
20 ("computation", c_uint32),
06e3c6bac36d patch 8.2.4250: channel out callback test is flaky on Mac
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
21 ("constraint", c_uint32),
06e3c6bac36d patch 8.2.4250: channel out callback test is flaky on Mac
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
22 ("preemptible", c_uint)
06e3c6bac36d patch 8.2.4250: channel out callback test is flaky on Mac
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
23 ]
06e3c6bac36d patch 8.2.4250: channel out callback test is flaky on Mac
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
24
06e3c6bac36d patch 8.2.4250: channel out callback test is flaky on Mac
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
25 _libc = CDLL(find_library('c'))
06e3c6bac36d patch 8.2.4250: channel out callback test is flaky on Mac
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
26
06e3c6bac36d patch 8.2.4250: channel out callback test is flaky on Mac
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
27 THREAD_TIME_CONSTRAINT_POLICY = c_uint(2)
06e3c6bac36d patch 8.2.4250: channel out callback test is flaky on Mac
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
28
06e3c6bac36d patch 8.2.4250: channel out callback test is flaky on Mac
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
29 THREAD_TIME_CONSTRAINT_POLICY_COUNT = c_uint(
06e3c6bac36d patch 8.2.4250: channel out callback test is flaky on Mac
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
30 int(sizeof(ThreadTimeConstraintPolicy) / sizeof(c_int)))
06e3c6bac36d patch 8.2.4250: channel out callback test is flaky on Mac
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
31
06e3c6bac36d patch 8.2.4250: channel out callback test is flaky on Mac
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
32 _libc.pthread_self.restype = c_void_p
06e3c6bac36d patch 8.2.4250: channel out callback test is flaky on Mac
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
33
06e3c6bac36d patch 8.2.4250: channel out callback test is flaky on Mac
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
34 _libc.pthread_mach_thread_np.restype = c_uint
06e3c6bac36d patch 8.2.4250: channel out callback test is flaky on Mac
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
35 _libc.pthread_mach_thread_np.argtypes = [c_void_p]
06e3c6bac36d patch 8.2.4250: channel out callback test is flaky on Mac
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
36
06e3c6bac36d patch 8.2.4250: channel out callback test is flaky on Mac
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
37 _libc.thread_policy_get.restype = c_int
06e3c6bac36d patch 8.2.4250: channel out callback test is flaky on Mac
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
38 _libc.thread_policy_get.argtypes = [
06e3c6bac36d patch 8.2.4250: channel out callback test is flaky on Mac
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
39 c_uint,
06e3c6bac36d patch 8.2.4250: channel out callback test is flaky on Mac
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
40 c_uint,
06e3c6bac36d patch 8.2.4250: channel out callback test is flaky on Mac
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
41 c_void_p,
06e3c6bac36d patch 8.2.4250: channel out callback test is flaky on Mac
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
42 POINTER(c_uint),
06e3c6bac36d patch 8.2.4250: channel out callback test is flaky on Mac
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
43 POINTER(c_uint)
06e3c6bac36d patch 8.2.4250: channel out callback test is flaky on Mac
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
44 ]
06e3c6bac36d patch 8.2.4250: channel out callback test is flaky on Mac
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
45
06e3c6bac36d patch 8.2.4250: channel out callback test is flaky on Mac
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
46 _libc.thread_policy_set.restype = c_int
06e3c6bac36d patch 8.2.4250: channel out callback test is flaky on Mac
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
47 _libc.thread_policy_set.argtypes = [
06e3c6bac36d patch 8.2.4250: channel out callback test is flaky on Mac
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
48 c_uint,
06e3c6bac36d patch 8.2.4250: channel out callback test is flaky on Mac
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
49 c_uint,
06e3c6bac36d patch 8.2.4250: channel out callback test is flaky on Mac
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
50 c_void_p,
06e3c6bac36d patch 8.2.4250: channel out callback test is flaky on Mac
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
51 c_uint
06e3c6bac36d patch 8.2.4250: channel out callback test is flaky on Mac
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
52 ]
06e3c6bac36d patch 8.2.4250: channel out callback test is flaky on Mac
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
53
06e3c6bac36d patch 8.2.4250: channel out callback test is flaky on Mac
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
54 def _mach_thread_self():
06e3c6bac36d patch 8.2.4250: channel out callback test is flaky on Mac
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
55 return _libc.pthread_mach_thread_np(_libc.pthread_self())
06e3c6bac36d patch 8.2.4250: channel out callback test is flaky on Mac
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
56
06e3c6bac36d patch 8.2.4250: channel out callback test is flaky on Mac
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
57 def _get_time_constraint_policy(default=False):
06e3c6bac36d patch 8.2.4250: channel out callback test is flaky on Mac
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
58 thread = _mach_thread_self()
06e3c6bac36d patch 8.2.4250: channel out callback test is flaky on Mac
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
59 policy_info = ThreadTimeConstraintPolicy()
06e3c6bac36d patch 8.2.4250: channel out callback test is flaky on Mac
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
60 policy_infoCnt = THREAD_TIME_CONSTRAINT_POLICY_COUNT
06e3c6bac36d patch 8.2.4250: channel out callback test is flaky on Mac
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
61 get_default = c_uint(default)
06e3c6bac36d patch 8.2.4250: channel out callback test is flaky on Mac
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
62
06e3c6bac36d patch 8.2.4250: channel out callback test is flaky on Mac
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
63 kret = _libc.thread_policy_get(
06e3c6bac36d patch 8.2.4250: channel out callback test is flaky on Mac
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
64 thread,
06e3c6bac36d patch 8.2.4250: channel out callback test is flaky on Mac
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
65 THREAD_TIME_CONSTRAINT_POLICY,
06e3c6bac36d patch 8.2.4250: channel out callback test is flaky on Mac
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
66 byref(policy_info),
06e3c6bac36d patch 8.2.4250: channel out callback test is flaky on Mac
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
67 byref(policy_infoCnt),
06e3c6bac36d patch 8.2.4250: channel out callback test is flaky on Mac
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
68 byref(get_default))
06e3c6bac36d patch 8.2.4250: channel out callback test is flaky on Mac
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
69 if kret != 0:
06e3c6bac36d patch 8.2.4250: channel out callback test is flaky on Mac
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
70 return None
06e3c6bac36d patch 8.2.4250: channel out callback test is flaky on Mac
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
71 return policy_info
06e3c6bac36d patch 8.2.4250: channel out callback test is flaky on Mac
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
72
06e3c6bac36d patch 8.2.4250: channel out callback test is flaky on Mac
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
73 def _set_time_constraint_policy(policy_info):
06e3c6bac36d patch 8.2.4250: channel out callback test is flaky on Mac
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
74 thread = _mach_thread_self()
06e3c6bac36d patch 8.2.4250: channel out callback test is flaky on Mac
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
75 policy_infoCnt = THREAD_TIME_CONSTRAINT_POLICY_COUNT
06e3c6bac36d patch 8.2.4250: channel out callback test is flaky on Mac
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
76
06e3c6bac36d patch 8.2.4250: channel out callback test is flaky on Mac
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
77 kret = _libc.thread_policy_set(
06e3c6bac36d patch 8.2.4250: channel out callback test is flaky on Mac
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
78 thread,
06e3c6bac36d patch 8.2.4250: channel out callback test is flaky on Mac
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
79 THREAD_TIME_CONSTRAINT_POLICY,
06e3c6bac36d patch 8.2.4250: channel out callback test is flaky on Mac
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
80 byref(policy_info),
06e3c6bac36d patch 8.2.4250: channel out callback test is flaky on Mac
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
81 policy_infoCnt)
06e3c6bac36d patch 8.2.4250: channel out callback test is flaky on Mac
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
82 if kret != 0:
06e3c6bac36d patch 8.2.4250: channel out callback test is flaky on Mac
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
83 raise OSError(kret)
06e3c6bac36d patch 8.2.4250: channel out callback test is flaky on Mac
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
84
06e3c6bac36d patch 8.2.4250: channel out callback test is flaky on Mac
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
85 def set_high_priority():
06e3c6bac36d patch 8.2.4250: channel out callback test is flaky on Mac
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
86 policy_info = _get_time_constraint_policy(default=True)
06e3c6bac36d patch 8.2.4250: channel out callback test is flaky on Mac
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
87 if not policy_info:
06e3c6bac36d patch 8.2.4250: channel out callback test is flaky on Mac
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
88 return
06e3c6bac36d patch 8.2.4250: channel out callback test is flaky on Mac
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
89 policy_info.preemptible = c_uint(False)
06e3c6bac36d patch 8.2.4250: channel out callback test is flaky on Mac
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
90 _set_time_constraint_policy(policy_info)