Skip to content
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.

Commit 3c2cd98

Browse files
erw7musm
authored andcommittedJul 9, 2020
win: fix duplicate tty vt100 fn key
Refs: libuv#2114 Refs: nodejs/node#25875 Refs: nodejs/node#26013 Fixes: libuv#2168 PR-URL: libuv#2160 Reviewed-By: Bartosz Sosnowski <bartosz@janeasystems.com> Reviewed-By: Colin Ihrig <cjihrig@gmail.com> (cherry picked from commit 7ed1ece)
1 parent 2f829f0 commit 3c2cd98

File tree

5 files changed

+200
-75
lines changed

5 files changed

+200
-75
lines changed
 

‎CMakeLists.txt

+150
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,156 @@ set(uv_sources
2323
src/uv-data-getter-setters.c
2424
src/version.c)
2525

26+
set(uv_test_sources
27+
test/blackhole-server.c
28+
test/echo-server.c
29+
test/run-tests.c
30+
test/runner.c
31+
test/test-active.c
32+
test/test-async-null-cb.c
33+
test/test-async.c
34+
test/test-barrier.c
35+
test/test-callback-order.c
36+
test/test-callback-stack.c
37+
test/test-close-fd.c
38+
test/test-close-order.c
39+
test/test-condvar.c
40+
test/test-connect-unspecified.c
41+
test/test-connection-fail.c
42+
test/test-cwd-and-chdir.c
43+
test/test-default-loop-close.c
44+
test/test-delayed-accept.c
45+
test/test-dlerror.c
46+
test/test-eintr-handling.c
47+
test/test-embed.c
48+
test/test-emfile.c
49+
test/test-env-vars.c
50+
test/test-error.c
51+
test/test-fail-always.c
52+
test/test-fork.c
53+
test/test-fs-copyfile.c
54+
test/test-fs-event.c
55+
test/test-fs-poll.c
56+
test/test-fs.c
57+
test/test-get-currentexe.c
58+
test/test-get-loadavg.c
59+
test/test-get-memory.c
60+
test/test-get-passwd.c
61+
test/test-getaddrinfo.c
62+
test/test-gethostname.c
63+
test/test-getnameinfo.c
64+
test/test-getsockname.c
65+
test/test-getters-setters.c
66+
test/test-handle-fileno.c
67+
test/test-homedir.c
68+
test/test-hrtime.c
69+
test/test-idle.c
70+
test/test-idna.c
71+
test/test-ip4-addr.c
72+
test/test-ip6-addr.c
73+
test/test-ip6-addr.c
74+
test/test-ipc-heavy-traffic-deadlock-bug.c
75+
test/test-ipc-send-recv.c
76+
test/test-ipc.c
77+
test/test-loop-alive.c
78+
test/test-loop-close.c
79+
test/test-loop-configure.c
80+
test/test-loop-handles.c
81+
test/test-loop-stop.c
82+
test/test-loop-time.c
83+
test/test-multiple-listen.c
84+
test/test-mutexes.c
85+
test/test-osx-select.c
86+
test/test-pass-always.c
87+
test/test-ping-pong.c
88+
test/test-pipe-bind-error.c
89+
test/test-pipe-close-stdout-read-stdin.c
90+
test/test-pipe-connect-error.c
91+
test/test-pipe-connect-multiple.c
92+
test/test-pipe-connect-prepare.c
93+
test/test-pipe-getsockname.c
94+
test/test-pipe-pending-instances.c
95+
test/test-pipe-sendmsg.c
96+
test/test-pipe-server-close.c
97+
test/test-pipe-set-fchmod.c
98+
test/test-pipe-set-non-blocking.c
99+
test/test-platform-output.c
100+
test/test-poll-close-doesnt-corrupt-stack.c
101+
test/test-poll-close.c
102+
test/test-poll-closesocket.c
103+
test/test-poll-oob.c
104+
test/test-poll.c
105+
test/test-process-priority.c
106+
test/test-process-title-threadsafe.c
107+
test/test-process-title.c
108+
test/test-queue-foreach-delete.c
109+
test/test-ref.c
110+
test/test-run-nowait.c
111+
test/test-run-once.c
112+
test/test-semaphore.c
113+
test/test-shutdown-close.c
114+
test/test-shutdown-eof.c
115+
test/test-shutdown-twice.c
116+
test/test-signal-multiple-loops.c
117+
test/test-signal.c
118+
test/test-socket-buffer-size.c
119+
test/test-spawn.c
120+
test/test-stdio-over-pipes.c
121+
test/test-strscpy.c
122+
test/test-tcp-alloc-cb-fail.c
123+
test/test-tcp-bind-error.c
124+
test/test-tcp-bind6-error.c
125+
test/test-tcp-close-accept.c
126+
test/test-tcp-close-while-connecting.c
127+
test/test-tcp-close.c
128+
test/test-tcp-connect-error-after-write.c
129+
test/test-tcp-connect-error.c
130+
test/test-tcp-connect-timeout.c
131+
test/test-tcp-connect6-error.c
132+
test/test-tcp-create-socket-early.c
133+
test/test-tcp-flags.c
134+
test/test-tcp-oob.c
135+
test/test-tcp-open.c
136+
test/test-tcp-read-stop.c
137+
test/test-tcp-shutdown-after-write.c
138+
test/test-tcp-try-write.c
139+
test/test-tcp-unexpected-read.c
140+
test/test-tcp-write-after-connect.c
141+
test/test-tcp-write-fail.c
142+
test/test-tcp-write-queue-order.c
143+
test/test-tcp-write-to-half-open-connection.c
144+
test/test-tcp-writealot.c
145+
test/test-thread-equal.c
146+
test/test-thread.c
147+
test/test-threadpool-cancel.c
148+
test/test-threadpool.c
149+
test/test-timer-again.c
150+
test/test-timer-from-check.c
151+
test/test-timer.c
152+
test/test-tmpdir.c
153+
test/test-tty-duplicate-key.c
154+
test/test-tty.c
155+
test/test-udp-alloc-cb-fail.c
156+
test/test-udp-bind.c
157+
test/test-udp-create-socket-early.c
158+
test/test-udp-dgram-too-big.c
159+
test/test-udp-ipv6.c
160+
test/test-udp-multicast-interface.c
161+
test/test-udp-multicast-interface6.c
162+
test/test-udp-multicast-join.c
163+
test/test-udp-multicast-join6.c
164+
test/test-udp-multicast-ttl.c
165+
test/test-udp-open.c
166+
test/test-udp-options.c
167+
test/test-udp-send-and-recv.c
168+
test/test-udp-send-hang-loop.c
169+
test/test-udp-send-immediate.c
170+
test/test-udp-send-unreachable.c
171+
test/test-udp-try-send.c
172+
test/test-uname.c
173+
test/test-walk-handles.c
174+
test/test-watcher-cross-stop.c)
175+
26176
if(WIN32)
27177
list(APPEND uv_defines WIN32_LEAN_AND_MEAN _WIN32_WINNT=0x0600)
28178
list(APPEND uv_libraries

‎Makefile.am

-1
Original file line numberDiff line numberDiff line change
@@ -281,7 +281,6 @@ test_run_tests_SOURCES = test/blackhole-server.c \
281281
test/test-timer.c \
282282
test/test-tmpdir.c \
283283
test/test-tty-duplicate-key.c \
284-
test/test-tty-escape-sequence-processing.c \
285284
test/test-tty.c \
286285
test/test-udp-alloc-cb-fail.c \
287286
test/test-udp-bind.c \

‎test/test-list.h

-32
Original file line numberDiff line numberDiff line change
@@ -57,22 +57,6 @@ TEST_DECLARE (tty_raw_cancel)
5757
TEST_DECLARE (tty_duplicate_vt100_fn_key)
5858
TEST_DECLARE (tty_duplicate_alt_modifier_key)
5959
TEST_DECLARE (tty_composing_character)
60-
TEST_DECLARE (tty_cursor_up)
61-
TEST_DECLARE (tty_cursor_down)
62-
TEST_DECLARE (tty_cursor_forward)
63-
TEST_DECLARE (tty_cursor_back)
64-
TEST_DECLARE (tty_cursor_next_line)
65-
TEST_DECLARE (tty_cursor_previous_line)
66-
TEST_DECLARE (tty_cursor_horizontal_move_absolute)
67-
TEST_DECLARE (tty_cursor_move_absolute)
68-
TEST_DECLARE (tty_hide_show_cursor)
69-
TEST_DECLARE (tty_set_cursor_shape)
70-
TEST_DECLARE (tty_erase)
71-
TEST_DECLARE (tty_erase_line)
72-
TEST_DECLARE (tty_set_style)
73-
TEST_DECLARE (tty_save_restore_cursor_position)
74-
TEST_DECLARE (tty_full_reset)
75-
TEST_DECLARE (tty_escape_sequence_processing)
7660
#endif
7761
TEST_DECLARE (tty_file)
7862
TEST_DECLARE (tty_pty)
@@ -541,22 +525,6 @@ TASK_LIST_START
541525
TEST_ENTRY (tty_duplicate_vt100_fn_key)
542526
TEST_ENTRY (tty_duplicate_alt_modifier_key)
543527
TEST_ENTRY (tty_composing_character)
544-
TEST_ENTRY (tty_cursor_up)
545-
TEST_ENTRY (tty_cursor_down)
546-
TEST_ENTRY (tty_cursor_forward)
547-
TEST_ENTRY (tty_cursor_back)
548-
TEST_ENTRY (tty_cursor_next_line)
549-
TEST_ENTRY (tty_cursor_previous_line)
550-
TEST_ENTRY (tty_cursor_horizontal_move_absolute)
551-
TEST_ENTRY (tty_cursor_move_absolute)
552-
TEST_ENTRY (tty_hide_show_cursor)
553-
TEST_ENTRY (tty_set_cursor_shape)
554-
TEST_ENTRY (tty_erase)
555-
TEST_ENTRY (tty_erase_line)
556-
TEST_ENTRY (tty_set_style)
557-
TEST_ENTRY (tty_save_restore_cursor_position)
558-
TEST_ENTRY (tty_full_reset)
559-
TEST_ENTRY (tty_escape_sequence_processing)
560528
#endif
561529
TEST_ENTRY (tty_file)
562530
TEST_ENTRY (tty_pty)

‎test/test-tty-duplicate-key.c

+50-41
Original file line numberDiff line numberDiff line change
@@ -53,7 +53,7 @@ static void print_err_msg(const char* expect, ssize_t expect_len,
5353
fprintf(stderr, "\n");
5454
}
5555

56-
static void tty_alloc(uv_handle_t* ttyin_fd, size_t size, uv_buf_t* buf) {
56+
static void tty_alloc(uv_handle_t* handle, size_t size, uv_buf_t* buf) {
5757
buf->base = malloc(size);
5858
ASSERT(buf->base != NULL);
5959
buf->len = size;
@@ -133,23 +133,26 @@ static void make_key_event_records(WORD virt_key, DWORD ctr_key_state,
133133

134134
TEST_IMPL(tty_duplicate_vt100_fn_key) {
135135
int r;
136-
uv_os_fd_t ttyin_fd;
136+
int ttyin_fd;
137137
uv_tty_t tty_in;
138138
uv_loop_t* loop;
139+
HANDLE handle;
139140
INPUT_RECORD records[2];
140141
DWORD written;
141142

142143
loop = uv_default_loop();
143144

144145
/* Make sure we have an FD that refers to a tty */
145-
ttyin_fd = CreateFileA("conin$",
146-
GENERIC_READ | GENERIC_WRITE,
147-
FILE_SHARE_READ | FILE_SHARE_WRITE,
148-
NULL,
149-
OPEN_EXISTING,
150-
FILE_ATTRIBUTE_NORMAL,
151-
NULL);
152-
ASSERT(ttyin_fd != INVALID_HANDLE_VALUE);
146+
handle = CreateFileA("conin$",
147+
GENERIC_READ | GENERIC_WRITE,
148+
FILE_SHARE_READ | FILE_SHARE_WRITE,
149+
NULL,
150+
OPEN_EXISTING,
151+
FILE_ATTRIBUTE_NORMAL,
152+
NULL);
153+
ASSERT(handle != INVALID_HANDLE_VALUE);
154+
ttyin_fd = _open_osfhandle((intptr_t) handle, 0);
155+
ASSERT(ttyin_fd >= 0);
153156
ASSERT(UV_TTY == uv_guess_handle(ttyin_fd));
154157

155158
r = uv_tty_init(uv_default_loop(), &tty_in, ttyin_fd, 1); /* Readable. */
@@ -172,7 +175,7 @@ TEST_IMPL(tty_duplicate_vt100_fn_key) {
172175
* duplicate.
173176
*/
174177
make_key_event_records(VK_F1, 0, TRUE, records);
175-
WriteConsoleInputW(ttyin_fd, records, ARRAY_SIZE(records), &written);
178+
WriteConsoleInputW(handle, records, ARRAY_SIZE(records), &written);
176179
ASSERT(written == ARRAY_SIZE(records));
177180

178181
uv_run(loop, UV_RUN_DEFAULT);
@@ -183,24 +186,27 @@ TEST_IMPL(tty_duplicate_vt100_fn_key) {
183186

184187
TEST_IMPL(tty_duplicate_alt_modifier_key) {
185188
int r;
186-
uv_os_fd_t ttyin_fd;
189+
int ttyin_fd;
187190
uv_tty_t tty_in;
188191
uv_loop_t* loop;
192+
HANDLE handle;
189193
INPUT_RECORD records[2];
190194
INPUT_RECORD alt_records[2];
191195
DWORD written;
192196

193197
loop = uv_default_loop();
194198

195199
/* Make sure we have an FD that refers to a tty */
196-
ttyin_fd = CreateFileA("conin$",
197-
GENERIC_READ | GENERIC_WRITE,
198-
FILE_SHARE_READ | FILE_SHARE_WRITE,
199-
NULL,
200-
OPEN_EXISTING,
201-
FILE_ATTRIBUTE_NORMAL,
202-
NULL);
203-
ASSERT(ttyin_fd != INVALID_HANDLE_VALUE);
200+
handle = CreateFileA("conin$",
201+
GENERIC_READ | GENERIC_WRITE,
202+
FILE_SHARE_READ | FILE_SHARE_WRITE,
203+
NULL,
204+
OPEN_EXISTING,
205+
FILE_ATTRIBUTE_NORMAL,
206+
NULL);
207+
ASSERT(handle != INVALID_HANDLE_VALUE);
208+
ttyin_fd = _open_osfhandle((intptr_t) handle, 0);
209+
ASSERT(ttyin_fd >= 0);
204210
ASSERT(UV_TTY == uv_guess_handle(ttyin_fd));
205211

206212
r = uv_tty_init(uv_default_loop(), &tty_in, ttyin_fd, 1); /* Readable. */
@@ -220,22 +226,22 @@ TEST_IMPL(tty_duplicate_alt_modifier_key) {
220226

221227
/* Emulate transmission of M-a at normal console */
222228
make_key_event_records(VK_MENU, 0, TRUE, alt_records);
223-
WriteConsoleInputW(ttyin_fd, &alt_records[0], 1, &written);
229+
WriteConsoleInputW(handle, &alt_records[0], 1, &written);
224230
ASSERT(written == 1);
225231
make_key_event_records(L'A', LEFT_ALT_PRESSED, FALSE, records);
226-
WriteConsoleInputW(ttyin_fd, records, ARRAY_SIZE(records), &written);
232+
WriteConsoleInputW(handle, records, ARRAY_SIZE(records), &written);
227233
ASSERT(written == 2);
228-
WriteConsoleInputW(ttyin_fd, &alt_records[1], 1, &written);
234+
WriteConsoleInputW(handle, &alt_records[1], 1, &written);
229235
ASSERT(written == 1);
230236

231237
/* Emulate transmission of M-a at WSL(#2111) */
232238
make_key_event_records(VK_MENU, 0, TRUE, alt_records);
233-
WriteConsoleInputW(ttyin_fd, &alt_records[0], 1, &written);
239+
WriteConsoleInputW(handle, &alt_records[0], 1, &written);
234240
ASSERT(written == 1);
235241
make_key_event_records(L'A', LEFT_ALT_PRESSED, TRUE, records);
236-
WriteConsoleInputW(ttyin_fd, records, ARRAY_SIZE(records), &written);
242+
WriteConsoleInputW(handle, records, ARRAY_SIZE(records), &written);
237243
ASSERT(written == 2);
238-
WriteConsoleInputW(ttyin_fd, &alt_records[1], 1, &written);
244+
WriteConsoleInputW(handle, &alt_records[1], 1, &written);
239245
ASSERT(written == 1);
240246

241247
uv_run(loop, UV_RUN_DEFAULT);
@@ -246,24 +252,27 @@ TEST_IMPL(tty_duplicate_alt_modifier_key) {
246252

247253
TEST_IMPL(tty_composing_character) {
248254
int r;
249-
uv_os_fd_t ttyin_fd;
255+
int ttyin_fd;
250256
uv_tty_t tty_in;
251257
uv_loop_t* loop;
258+
HANDLE handle;
252259
INPUT_RECORD records[2];
253260
INPUT_RECORD alt_records[2];
254261
DWORD written;
255262

256263
loop = uv_default_loop();
257264

258265
/* Make sure we have an FD that refers to a tty */
259-
ttyin_fd = CreateFileA("conin$",
260-
GENERIC_READ | GENERIC_WRITE,
261-
FILE_SHARE_READ | FILE_SHARE_WRITE,
262-
NULL,
263-
OPEN_EXISTING,
264-
FILE_ATTRIBUTE_NORMAL,
265-
NULL);
266-
ASSERT(ttyin_fd != INVALID_HANDLE_VALUE);
266+
handle = CreateFileA("conin$",
267+
GENERIC_READ | GENERIC_WRITE,
268+
FILE_SHARE_READ | FILE_SHARE_WRITE,
269+
NULL,
270+
OPEN_EXISTING,
271+
FILE_ATTRIBUTE_NORMAL,
272+
NULL);
273+
ASSERT(handle != INVALID_HANDLE_VALUE);
274+
ttyin_fd = _open_osfhandle((intptr_t) handle, 0);
275+
ASSERT(ttyin_fd >= 0);
267276
ASSERT(UV_TTY == uv_guess_handle(ttyin_fd));
268277

269278
r = uv_tty_init(uv_default_loop(), &tty_in, ttyin_fd, 1); /* Readable. */
@@ -284,20 +293,20 @@ TEST_IMPL(tty_composing_character) {
284293
/* Emulate EUR inputs by LEFT ALT+NUMPAD ASCII KeyComos */
285294
make_key_event_records(VK_MENU, 0, FALSE, alt_records);
286295
alt_records[1].Event.KeyEvent.uChar.UnicodeChar = EUR_UNICODE;
287-
WriteConsoleInputW(ttyin_fd, &alt_records[0], 1, &written);
296+
WriteConsoleInputW(handle, &alt_records[0], 1, &written);
288297
make_key_event_records(VK_NUMPAD0, LEFT_ALT_PRESSED, FALSE, records);
289-
WriteConsoleInputW(ttyin_fd, records, ARRAY_SIZE(records), &written);
298+
WriteConsoleInputW(handle, records, ARRAY_SIZE(records), &written);
290299
ASSERT(written == ARRAY_SIZE(records));
291300
make_key_event_records(VK_NUMPAD1, LEFT_ALT_PRESSED, FALSE, records);
292-
WriteConsoleInputW(ttyin_fd, records, ARRAY_SIZE(records), &written);
301+
WriteConsoleInputW(handle, records, ARRAY_SIZE(records), &written);
293302
ASSERT(written == ARRAY_SIZE(records));
294303
make_key_event_records(VK_NUMPAD2, LEFT_ALT_PRESSED, FALSE, records);
295-
WriteConsoleInputW(ttyin_fd, records, ARRAY_SIZE(records), &written);
304+
WriteConsoleInputW(handle, records, ARRAY_SIZE(records), &written);
296305
ASSERT(written == ARRAY_SIZE(records));
297306
make_key_event_records(VK_NUMPAD8, LEFT_ALT_PRESSED, FALSE, records);
298-
WriteConsoleInputW(ttyin_fd, records, ARRAY_SIZE(records), &written);
307+
WriteConsoleInputW(handle, records, ARRAY_SIZE(records), &written);
299308
ASSERT(written == ARRAY_SIZE(records));
300-
WriteConsoleInputW(ttyin_fd, &alt_records[1], 1, &written);
309+
WriteConsoleInputW(handle, &alt_records[1], 1, &written);
301310

302311
uv_run(loop, UV_RUN_DEFAULT);
303312

0 commit comments

Comments
 (0)
Please sign in to comment.