Skip to content

Commit

Permalink
win: fix duplicate tty vt100 fn key
Browse files Browse the repository at this point in the history
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)
  • Loading branch information
erw7 authored and musm committed Jul 9, 2020
1 parent 6888be4 commit f14b0cb
Show file tree
Hide file tree
Showing 5 changed files with 200 additions and 75 deletions.
150 changes: 150 additions & 0 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,156 @@ set(uv_sources
src/uv-data-getter-setters.c
src/version.c)

set(uv_test_sources
test/blackhole-server.c
test/echo-server.c
test/run-tests.c
test/runner.c
test/test-active.c
test/test-async-null-cb.c
test/test-async.c
test/test-barrier.c
test/test-callback-order.c
test/test-callback-stack.c
test/test-close-fd.c
test/test-close-order.c
test/test-condvar.c
test/test-connect-unspecified.c
test/test-connection-fail.c
test/test-cwd-and-chdir.c
test/test-default-loop-close.c
test/test-delayed-accept.c
test/test-dlerror.c
test/test-eintr-handling.c
test/test-embed.c
test/test-emfile.c
test/test-env-vars.c
test/test-error.c
test/test-fail-always.c
test/test-fork.c
test/test-fs-copyfile.c
test/test-fs-event.c
test/test-fs-poll.c
test/test-fs.c
test/test-get-currentexe.c
test/test-get-loadavg.c
test/test-get-memory.c
test/test-get-passwd.c
test/test-getaddrinfo.c
test/test-gethostname.c
test/test-getnameinfo.c
test/test-getsockname.c
test/test-getters-setters.c
test/test-handle-fileno.c
test/test-homedir.c
test/test-hrtime.c
test/test-idle.c
test/test-idna.c
test/test-ip4-addr.c
test/test-ip6-addr.c
test/test-ip6-addr.c
test/test-ipc-heavy-traffic-deadlock-bug.c
test/test-ipc-send-recv.c
test/test-ipc.c
test/test-loop-alive.c
test/test-loop-close.c
test/test-loop-configure.c
test/test-loop-handles.c
test/test-loop-stop.c
test/test-loop-time.c
test/test-multiple-listen.c
test/test-mutexes.c
test/test-osx-select.c
test/test-pass-always.c
test/test-ping-pong.c
test/test-pipe-bind-error.c
test/test-pipe-close-stdout-read-stdin.c
test/test-pipe-connect-error.c
test/test-pipe-connect-multiple.c
test/test-pipe-connect-prepare.c
test/test-pipe-getsockname.c
test/test-pipe-pending-instances.c
test/test-pipe-sendmsg.c
test/test-pipe-server-close.c
test/test-pipe-set-fchmod.c
test/test-pipe-set-non-blocking.c
test/test-platform-output.c
test/test-poll-close-doesnt-corrupt-stack.c
test/test-poll-close.c
test/test-poll-closesocket.c
test/test-poll-oob.c
test/test-poll.c
test/test-process-priority.c
test/test-process-title-threadsafe.c
test/test-process-title.c
test/test-queue-foreach-delete.c
test/test-ref.c
test/test-run-nowait.c
test/test-run-once.c
test/test-semaphore.c
test/test-shutdown-close.c
test/test-shutdown-eof.c
test/test-shutdown-twice.c
test/test-signal-multiple-loops.c
test/test-signal.c
test/test-socket-buffer-size.c
test/test-spawn.c
test/test-stdio-over-pipes.c
test/test-strscpy.c
test/test-tcp-alloc-cb-fail.c
test/test-tcp-bind-error.c
test/test-tcp-bind6-error.c
test/test-tcp-close-accept.c
test/test-tcp-close-while-connecting.c
test/test-tcp-close.c
test/test-tcp-connect-error-after-write.c
test/test-tcp-connect-error.c
test/test-tcp-connect-timeout.c
test/test-tcp-connect6-error.c
test/test-tcp-create-socket-early.c
test/test-tcp-flags.c
test/test-tcp-oob.c
test/test-tcp-open.c
test/test-tcp-read-stop.c
test/test-tcp-shutdown-after-write.c
test/test-tcp-try-write.c
test/test-tcp-unexpected-read.c
test/test-tcp-write-after-connect.c
test/test-tcp-write-fail.c
test/test-tcp-write-queue-order.c
test/test-tcp-write-to-half-open-connection.c
test/test-tcp-writealot.c
test/test-thread-equal.c
test/test-thread.c
test/test-threadpool-cancel.c
test/test-threadpool.c
test/test-timer-again.c
test/test-timer-from-check.c
test/test-timer.c
test/test-tmpdir.c
test/test-tty-duplicate-key.c
test/test-tty.c
test/test-udp-alloc-cb-fail.c
test/test-udp-bind.c
test/test-udp-create-socket-early.c
test/test-udp-dgram-too-big.c
test/test-udp-ipv6.c
test/test-udp-multicast-interface.c
test/test-udp-multicast-interface6.c
test/test-udp-multicast-join.c
test/test-udp-multicast-join6.c
test/test-udp-multicast-ttl.c
test/test-udp-open.c
test/test-udp-options.c
test/test-udp-send-and-recv.c
test/test-udp-send-hang-loop.c
test/test-udp-send-immediate.c
test/test-udp-send-unreachable.c
test/test-udp-try-send.c
test/test-uname.c
test/test-walk-handles.c
test/test-watcher-cross-stop.c)

if(WIN32)
list(APPEND uv_defines WIN32_LEAN_AND_MEAN _WIN32_WINNT=0x0600)
list(APPEND uv_libraries
Expand Down
1 change: 0 additions & 1 deletion Makefile.am
Original file line number Diff line number Diff line change
Expand Up @@ -281,7 +281,6 @@ test_run_tests_SOURCES = test/blackhole-server.c \
test/test-timer.c \
test/test-tmpdir.c \
test/test-tty-duplicate-key.c \
test/test-tty-escape-sequence-processing.c \
test/test-tty.c \
test/test-udp-alloc-cb-fail.c \
test/test-udp-bind.c \
Expand Down
32 changes: 0 additions & 32 deletions test/test-list.h
Original file line number Diff line number Diff line change
Expand Up @@ -57,22 +57,6 @@ TEST_DECLARE (tty_raw_cancel)
TEST_DECLARE (tty_duplicate_vt100_fn_key)
TEST_DECLARE (tty_duplicate_alt_modifier_key)
TEST_DECLARE (tty_composing_character)
TEST_DECLARE (tty_cursor_up)
TEST_DECLARE (tty_cursor_down)
TEST_DECLARE (tty_cursor_forward)
TEST_DECLARE (tty_cursor_back)
TEST_DECLARE (tty_cursor_next_line)
TEST_DECLARE (tty_cursor_previous_line)
TEST_DECLARE (tty_cursor_horizontal_move_absolute)
TEST_DECLARE (tty_cursor_move_absolute)
TEST_DECLARE (tty_hide_show_cursor)
TEST_DECLARE (tty_set_cursor_shape)
TEST_DECLARE (tty_erase)
TEST_DECLARE (tty_erase_line)
TEST_DECLARE (tty_set_style)
TEST_DECLARE (tty_save_restore_cursor_position)
TEST_DECLARE (tty_full_reset)
TEST_DECLARE (tty_escape_sequence_processing)
#endif
TEST_DECLARE (tty_file)
TEST_DECLARE (tty_pty)
Expand Down Expand Up @@ -541,22 +525,6 @@ TASK_LIST_START
TEST_ENTRY (tty_duplicate_vt100_fn_key)
TEST_ENTRY (tty_duplicate_alt_modifier_key)
TEST_ENTRY (tty_composing_character)
TEST_ENTRY (tty_cursor_up)
TEST_ENTRY (tty_cursor_down)
TEST_ENTRY (tty_cursor_forward)
TEST_ENTRY (tty_cursor_back)
TEST_ENTRY (tty_cursor_next_line)
TEST_ENTRY (tty_cursor_previous_line)
TEST_ENTRY (tty_cursor_horizontal_move_absolute)
TEST_ENTRY (tty_cursor_move_absolute)
TEST_ENTRY (tty_hide_show_cursor)
TEST_ENTRY (tty_set_cursor_shape)
TEST_ENTRY (tty_erase)
TEST_ENTRY (tty_erase_line)
TEST_ENTRY (tty_set_style)
TEST_ENTRY (tty_save_restore_cursor_position)
TEST_ENTRY (tty_full_reset)
TEST_ENTRY (tty_escape_sequence_processing)
#endif
TEST_ENTRY (tty_file)
TEST_ENTRY (tty_pty)
Expand Down
91 changes: 50 additions & 41 deletions test/test-tty-duplicate-key.c
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,7 @@ static void print_err_msg(const char* expect, ssize_t expect_len,
fprintf(stderr, "\n");
}

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

TEST_IMPL(tty_duplicate_vt100_fn_key) {
int r;
uv_os_fd_t ttyin_fd;
int ttyin_fd;
uv_tty_t tty_in;
uv_loop_t* loop;
HANDLE handle;
INPUT_RECORD records[2];
DWORD written;

loop = uv_default_loop();

/* Make sure we have an FD that refers to a tty */
ttyin_fd = CreateFileA("conin$",
GENERIC_READ | GENERIC_WRITE,
FILE_SHARE_READ | FILE_SHARE_WRITE,
NULL,
OPEN_EXISTING,
FILE_ATTRIBUTE_NORMAL,
NULL);
ASSERT(ttyin_fd != INVALID_HANDLE_VALUE);
handle = CreateFileA("conin$",
GENERIC_READ | GENERIC_WRITE,
FILE_SHARE_READ | FILE_SHARE_WRITE,
NULL,
OPEN_EXISTING,
FILE_ATTRIBUTE_NORMAL,
NULL);
ASSERT(handle != INVALID_HANDLE_VALUE);
ttyin_fd = _open_osfhandle((intptr_t) handle, 0);
ASSERT(ttyin_fd >= 0);
ASSERT(UV_TTY == uv_guess_handle(ttyin_fd));

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

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

TEST_IMPL(tty_duplicate_alt_modifier_key) {
int r;
uv_os_fd_t ttyin_fd;
int ttyin_fd;
uv_tty_t tty_in;
uv_loop_t* loop;
HANDLE handle;
INPUT_RECORD records[2];
INPUT_RECORD alt_records[2];
DWORD written;

loop = uv_default_loop();

/* Make sure we have an FD that refers to a tty */
ttyin_fd = CreateFileA("conin$",
GENERIC_READ | GENERIC_WRITE,
FILE_SHARE_READ | FILE_SHARE_WRITE,
NULL,
OPEN_EXISTING,
FILE_ATTRIBUTE_NORMAL,
NULL);
ASSERT(ttyin_fd != INVALID_HANDLE_VALUE);
handle = CreateFileA("conin$",
GENERIC_READ | GENERIC_WRITE,
FILE_SHARE_READ | FILE_SHARE_WRITE,
NULL,
OPEN_EXISTING,
FILE_ATTRIBUTE_NORMAL,
NULL);
ASSERT(handle != INVALID_HANDLE_VALUE);
ttyin_fd = _open_osfhandle((intptr_t) handle, 0);
ASSERT(ttyin_fd >= 0);
ASSERT(UV_TTY == uv_guess_handle(ttyin_fd));

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

/* Emulate transmission of M-a at normal console */
make_key_event_records(VK_MENU, 0, TRUE, alt_records);
WriteConsoleInputW(ttyin_fd, &alt_records[0], 1, &written);
WriteConsoleInputW(handle, &alt_records[0], 1, &written);
ASSERT(written == 1);
make_key_event_records(L'A', LEFT_ALT_PRESSED, FALSE, records);
WriteConsoleInputW(ttyin_fd, records, ARRAY_SIZE(records), &written);
WriteConsoleInputW(handle, records, ARRAY_SIZE(records), &written);
ASSERT(written == 2);
WriteConsoleInputW(ttyin_fd, &alt_records[1], 1, &written);
WriteConsoleInputW(handle, &alt_records[1], 1, &written);
ASSERT(written == 1);

/* Emulate transmission of M-a at WSL(#2111) */
make_key_event_records(VK_MENU, 0, TRUE, alt_records);
WriteConsoleInputW(ttyin_fd, &alt_records[0], 1, &written);
WriteConsoleInputW(handle, &alt_records[0], 1, &written);
ASSERT(written == 1);
make_key_event_records(L'A', LEFT_ALT_PRESSED, TRUE, records);
WriteConsoleInputW(ttyin_fd, records, ARRAY_SIZE(records), &written);
WriteConsoleInputW(handle, records, ARRAY_SIZE(records), &written);
ASSERT(written == 2);
WriteConsoleInputW(ttyin_fd, &alt_records[1], 1, &written);
WriteConsoleInputW(handle, &alt_records[1], 1, &written);
ASSERT(written == 1);

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

TEST_IMPL(tty_composing_character) {
int r;
uv_os_fd_t ttyin_fd;
int ttyin_fd;
uv_tty_t tty_in;
uv_loop_t* loop;
HANDLE handle;
INPUT_RECORD records[2];
INPUT_RECORD alt_records[2];
DWORD written;

loop = uv_default_loop();

/* Make sure we have an FD that refers to a tty */
ttyin_fd = CreateFileA("conin$",
GENERIC_READ | GENERIC_WRITE,
FILE_SHARE_READ | FILE_SHARE_WRITE,
NULL,
OPEN_EXISTING,
FILE_ATTRIBUTE_NORMAL,
NULL);
ASSERT(ttyin_fd != INVALID_HANDLE_VALUE);
handle = CreateFileA("conin$",
GENERIC_READ | GENERIC_WRITE,
FILE_SHARE_READ | FILE_SHARE_WRITE,
NULL,
OPEN_EXISTING,
FILE_ATTRIBUTE_NORMAL,
NULL);
ASSERT(handle != INVALID_HANDLE_VALUE);
ttyin_fd = _open_osfhandle((intptr_t) handle, 0);
ASSERT(ttyin_fd >= 0);
ASSERT(UV_TTY == uv_guess_handle(ttyin_fd));

r = uv_tty_init(uv_default_loop(), &tty_in, ttyin_fd, 1); /* Readable. */
Expand All @@ -284,20 +293,20 @@ TEST_IMPL(tty_composing_character) {
/* Emulate EUR inputs by LEFT ALT+NUMPAD ASCII KeyComos */
make_key_event_records(VK_MENU, 0, FALSE, alt_records);
alt_records[1].Event.KeyEvent.uChar.UnicodeChar = EUR_UNICODE;
WriteConsoleInputW(ttyin_fd, &alt_records[0], 1, &written);
WriteConsoleInputW(handle, &alt_records[0], 1, &written);
make_key_event_records(VK_NUMPAD0, LEFT_ALT_PRESSED, FALSE, records);
WriteConsoleInputW(ttyin_fd, records, ARRAY_SIZE(records), &written);
WriteConsoleInputW(handle, records, ARRAY_SIZE(records), &written);
ASSERT(written == ARRAY_SIZE(records));
make_key_event_records(VK_NUMPAD1, LEFT_ALT_PRESSED, FALSE, records);
WriteConsoleInputW(ttyin_fd, records, ARRAY_SIZE(records), &written);
WriteConsoleInputW(handle, records, ARRAY_SIZE(records), &written);
ASSERT(written == ARRAY_SIZE(records));
make_key_event_records(VK_NUMPAD2, LEFT_ALT_PRESSED, FALSE, records);
WriteConsoleInputW(ttyin_fd, records, ARRAY_SIZE(records), &written);
WriteConsoleInputW(handle, records, ARRAY_SIZE(records), &written);
ASSERT(written == ARRAY_SIZE(records));
make_key_event_records(VK_NUMPAD8, LEFT_ALT_PRESSED, FALSE, records);
WriteConsoleInputW(ttyin_fd, records, ARRAY_SIZE(records), &written);
WriteConsoleInputW(handle, records, ARRAY_SIZE(records), &written);
ASSERT(written == ARRAY_SIZE(records));
WriteConsoleInputW(ttyin_fd, &alt_records[1], 1, &written);
WriteConsoleInputW(handle, &alt_records[1], 1, &written);

uv_run(loop, UV_RUN_DEFAULT);

Expand Down
Loading

0 comments on commit f14b0cb

Please sign in to comment.