win/test: tty-test: print screen size explicitly with CTRL-Q

tty-test.exe causes abnormal termination with low repeatability, try
changing it so as not to use SIGWINCH.
This commit is contained in:
erw7 2017-03-31 05:40:37 +09:00 committed by Justin M. Keyes
parent 3b992f1688
commit 1614e805b3
3 changed files with 44 additions and 34 deletions

View File

@ -15,11 +15,11 @@ uv_tty_t tty;
#include <windows.h> #include <windows.h>
bool owns_tty(void) bool owns_tty(void)
{ {
/* XXX: We need to make proper detect owns tty */ // XXX: We need to make proper detect owns tty
/* HWND consoleWnd = GetConsoleWindow(); */ // HWND consoleWnd = GetConsoleWindow();
/* DWORD dwProcessId; */ // DWORD dwProcessId;
/* GetWindowThreadProcessId(consoleWnd, &dwProcessId); */ // GetWindowThreadProcessId(consoleWnd, &dwProcessId);
/* return GetCurrentProcessId() == dwProcessId; */ // return GetCurrentProcessId() == dwProcessId;
return true; return true;
} }
#else #else
@ -57,15 +57,15 @@ static void sig_handler(int signum)
} }
} }
#else #else
static void sigwinch_cb(uv_signal_t *handle, int signum) // static void sigwinch_cb(uv_signal_t *handle, int signum)
{ // {
int width, height; // int width, height;
uv_tty_t out; // uv_tty_t out;
uv_tty_init(uv_default_loop(), &out, fileno(stdout), 0); // uv_tty_init(uv_default_loop(), &out, fileno(stdout), 0);
uv_tty_get_winsize(&out, &width, &height); // uv_tty_get_winsize(&out, &width, &height);
fprintf(stderr, "rows: %d, cols: %d\n", height, width); // fprintf(stderr, "rows: %d, cols: %d\n", height, width);
uv_close((uv_handle_t *)&out, NULL); // uv_close((uv_handle_t *)&out, NULL);
} // }
#endif #endif
static void alloc_cb(uv_handle_t *handle, size_t suggested, uv_buf_t *buf) static void alloc_cb(uv_handle_t *handle, size_t suggested, uv_buf_t *buf)
@ -82,10 +82,14 @@ static void read_cb(uv_stream_t *stream, ssize_t cnt, const uv_buf_t *buf)
} }
int *interrupted = stream->data; int *interrupted = stream->data;
bool prsz = false;
int width, height;
for (int i = 0; i < cnt; i++) { for (int i = 0; i < cnt; i++) {
if (buf->base[i] == 3) { if (buf->base[i] == 3) {
(*interrupted)++; (*interrupted)++;
} else if (buf->base[i] == 17) {
prsz = true;
} }
} }
@ -93,10 +97,17 @@ static void read_cb(uv_stream_t *stream, ssize_t cnt, const uv_buf_t *buf)
uv_loop_init(&write_loop); uv_loop_init(&write_loop);
uv_tty_t out; uv_tty_t out;
uv_tty_init(&write_loop, &out, fileno(stdout), 0); uv_tty_init(&write_loop, &out, fileno(stdout), 0);
uv_write_t req;
uv_buf_t b = {.base = buf->base, .len = (size_t)cnt}; if (prsz) {
uv_write(&req, STRUCT_CAST(uv_stream_t, &out), &b, 1, NULL); uv_tty_get_winsize(&out, &width, &height);
uv_run(&write_loop, UV_RUN_DEFAULT); fprintf(stderr, "rows: %d, cols: %d\n", height, width);
} else {
uv_write_t req;
uv_buf_t b = {.base = buf->base, .len = (size_t)cnt};
uv_write(&req, STRUCT_CAST(uv_stream_t, &out), &b, 1, NULL);
uv_run(&write_loop, UV_RUN_DEFAULT);
}
uv_close(STRUCT_CAST(uv_handle_t, &out), NULL); uv_close(STRUCT_CAST(uv_handle_t, &out), NULL);
uv_run(&write_loop, UV_RUN_DEFAULT); uv_run(&write_loop, UV_RUN_DEFAULT);
if (uv_loop_close(&write_loop)) { if (uv_loop_close(&write_loop)) {
@ -169,9 +180,9 @@ int main(int argc, char **argv)
sigaction(SIGHUP, &sa, NULL); sigaction(SIGHUP, &sa, NULL);
sigaction(SIGWINCH, &sa, NULL); sigaction(SIGWINCH, &sa, NULL);
#else #else
uv_signal_t sigwinch_watcher; // uv_signal_t sigwinch_watcher;
uv_signal_init(uv_default_loop(), &sigwinch_watcher); // uv_signal_init(uv_default_loop(), &sigwinch_watcher);
uv_signal_start(&sigwinch_watcher, sigwinch_cb, SIGWINCH); // uv_signal_start(&sigwinch_watcher, sigwinch_cb, SIGWINCH);
#endif #endif
uv_run(uv_default_loop(), UV_RUN_DEFAULT); uv_run(uv_default_loop(), UV_RUN_DEFAULT);

View File

@ -30,10 +30,9 @@ local function clear_attrs() feed_termcode('[0;10m') end
-- mouse -- mouse
local function enable_mouse() feed_termcode('[?1002h') end local function enable_mouse() feed_termcode('[?1002h') end
local function disable_mouse() feed_termcode('[?1002l') end local function disable_mouse() feed_termcode('[?1002l') end
local function wait_sigwinch() local function print_screen_size()
helpers.sleep(1000) helpers.sleep(1000)
hide_cursor() nvim('command', 'call jobsend(b:terminal_job_id, "\\<C-q>")')
show_cursor()
end end
local default_command = '["'..nvim_dir..'/tty-test'..'"]' local default_command = '["'..nvim_dir..'/tty-test'..'"]'
@ -116,6 +115,6 @@ return {
clear_attrs = clear_attrs, clear_attrs = clear_attrs,
enable_mouse = enable_mouse, enable_mouse = enable_mouse,
disable_mouse = disable_mouse, disable_mouse = disable_mouse,
wait_sigwinch = wait_sigwinch, print_screen_size = print_screen_size,
screen_setup = screen_setup screen_setup = screen_setup
} }

View File

@ -3,7 +3,7 @@ local helpers = require('test.functional.helpers')(after_each)
local thelpers = require('test.functional.terminal.helpers') local thelpers = require('test.functional.terminal.helpers')
local clear, eq, curbuf = helpers.clear, helpers.eq, helpers.curbuf local clear, eq, curbuf = helpers.clear, helpers.eq, helpers.curbuf
local feed, nvim_dir, feed_command = helpers.feed, helpers.nvim_dir, helpers.feed_command local feed, nvim_dir, feed_command = helpers.feed, helpers.nvim_dir, helpers.feed_command
local iswin, wait_sigwinch = helpers.iswin, thelpers.wait_sigwinch local iswin, print_screen_size = helpers.iswin, thelpers.print_screen_size
local eval = helpers.eval local eval = helpers.eval
local command = helpers.command local command = helpers.command
local wait = helpers.wait local wait = helpers.wait
@ -142,7 +142,7 @@ describe('terminal scrollback', function()
local function will_hide_top_line() local function will_hide_top_line()
screen:try_resize(screen._width, screen._height - 1) screen:try_resize(screen._width, screen._height - 1)
if iswin() then if iswin() then
wait_sigwinch() print_screen_size()
end end
screen:expect([[ screen:expect([[
line2 | line2 |
@ -161,7 +161,7 @@ describe('terminal scrollback', function()
will_hide_top_line() will_hide_top_line()
screen:try_resize(screen._width, screen._height - 2) screen:try_resize(screen._width, screen._height - 2)
if iswin() then if iswin() then
wait_sigwinch() print_screen_size()
end end
end) end)
@ -190,7 +190,7 @@ describe('terminal scrollback', function()
before_each(function() before_each(function()
screen:try_resize(screen._width, screen._height - 2) screen:try_resize(screen._width, screen._height - 2)
if iswin() then if iswin() then
wait_sigwinch() print_screen_size()
end end
end) end)
@ -214,7 +214,7 @@ describe('terminal scrollback', function()
will_delete_last_two_lines() will_delete_last_two_lines()
screen:try_resize(screen._width, screen._height - 1) screen:try_resize(screen._width, screen._height - 1)
if iswin() then if iswin() then
wait_sigwinch() print_screen_size()
end end
end) end)
@ -259,7 +259,7 @@ describe('terminal scrollback', function()
]]) ]])
screen:try_resize(screen._width, screen._height - 3) screen:try_resize(screen._width, screen._height - 3)
if iswin() then if iswin() then
wait_sigwinch() print_screen_size()
end end
screen:expect([[ screen:expect([[
line4 | line4 |
@ -274,7 +274,7 @@ describe('terminal scrollback', function()
local function pop_then_push() local function pop_then_push()
screen:try_resize(screen._width, screen._height + 1) screen:try_resize(screen._width, screen._height + 1)
if iswin() then if iswin() then
wait_sigwinch() print_screen_size()
end end
screen:expect([[ screen:expect([[
line4 | line4 |
@ -293,7 +293,7 @@ describe('terminal scrollback', function()
eq(8, curbuf('line_count')) eq(8, curbuf('line_count'))
screen:try_resize(screen._width, screen._height + 3) screen:try_resize(screen._width, screen._height + 3)
if iswin() then if iswin() then
wait_sigwinch() print_screen_size()
end end
end) end)
@ -331,7 +331,7 @@ describe('terminal scrollback', function()
feed('Gi') feed('Gi')
screen:try_resize(screen._width, screen._height + 4) screen:try_resize(screen._width, screen._height + 4)
if iswin() then if iswin() then
wait_sigwinch() print_screen_size()
end end
end) end)