mirror of
https://github.com/kovidgoyal/kitty.git
synced 2024-09-21 11:39:57 +03:00
Get the SIGINT test working on macOS
This commit is contained in:
parent
6ccfebd9e3
commit
9379853d47
@ -62,9 +62,11 @@ class Child:
|
|||||||
child_process_pid: int
|
child_process_pid: int
|
||||||
|
|
||||||
|
|
||||||
def wait_for_child_death(child_pid: int, timeout: float = 1) -> Optional[int]:
|
def wait_for_child_death(child_pid: int, timeout: float = 1, kill_signal: Optional[signal.Signals] = None) -> Optional[int]:
|
||||||
st = time.monotonic()
|
st = time.monotonic()
|
||||||
while time.monotonic() - st < timeout:
|
while not timeout or time.monotonic() - st < timeout:
|
||||||
|
if kill_signal is not None:
|
||||||
|
os.kill(child_pid, kill_signal)
|
||||||
try:
|
try:
|
||||||
pid, status = os.waitpid(child_pid, os.WNOHANG)
|
pid, status = os.waitpid(child_pid, os.WNOHANG)
|
||||||
except ChildProcessError:
|
except ChildProcessError:
|
||||||
@ -72,6 +74,8 @@ def wait_for_child_death(child_pid: int, timeout: float = 1) -> Optional[int]:
|
|||||||
else:
|
else:
|
||||||
if pid == child_pid:
|
if pid == child_pid:
|
||||||
return status
|
return status
|
||||||
|
if not timeout:
|
||||||
|
break
|
||||||
time.sleep(0.01)
|
time.sleep(0.01)
|
||||||
return None
|
return None
|
||||||
|
|
||||||
|
@ -64,23 +64,30 @@ def report_screen_size_change(*a):
|
|||||||
env.update({'TEST_ENV_PASS': 'xyz', 'KITTY_PREWARM_SOCKET': p.socket_env_var(), 'TERM': 'xterm-kitty', 'TERMINFO': terminfo_dir})
|
env.update({'TEST_ENV_PASS': 'xyz', 'KITTY_PREWARM_SOCKET': p.socket_env_var(), 'TERM': 'xterm-kitty', 'TERMINFO': terminfo_dir})
|
||||||
cols = 117
|
cols = 117
|
||||||
|
|
||||||
def wait_for_death(exit_code):
|
def wait_for_death(exit_code, signal=None):
|
||||||
status = wait_for_child_death(pty.child_pid, timeout=5)
|
status = wait_for_child_death(pty.child_pid, timeout=5, kill_signal=signal)
|
||||||
if status is None:
|
if status is None:
|
||||||
os.kill(pty.child_pid, signal.SIGKILL)
|
os.kill(pty.child_pid, signal.SIGKILL)
|
||||||
self.assertIsNotNone(status, f'prewarm wrapper process did not exit. Screen contents: {pty.screen_contents()}')
|
self.assertIsNotNone(status, f'prewarm wrapper process did not exit. Screen contents: {pty.screen_contents()}')
|
||||||
with suppress(AttributeError):
|
with suppress(AttributeError):
|
||||||
self.assertEqual(os.waitstatus_to_exitcode(status), exit_code, pty.screen_contents())
|
self.assertEqual(os.waitstatus_to_exitcode(status), exit_code, pty.screen_contents())
|
||||||
|
|
||||||
|
# test SIGINT both via signal to wrapper and by sending ctrl-c over the tty
|
||||||
pty = self.create_pty(
|
pty = self.create_pty(
|
||||||
argv=[kitty_exe(), '+runpy', src + 'socket_child_main(initial_print="child ready:")'], cols=cols, env=env, cwd=cwd)
|
argv=[kitty_exe(), '+runpy', src + 'socket_child_main(initial_print="child ready:")'], cols=cols, env=env, cwd=cwd)
|
||||||
pty.wait_till(lambda: 'child ready:' in pty.screen_contents())
|
pty.wait_till(lambda: 'child ready:' in pty.screen_contents())
|
||||||
pty.set_window_size(columns=cols + 3)
|
pty.set_window_size(columns=cols + 3)
|
||||||
pty.wait_till(lambda: f'Screen size changed: {cols + 3}' in pty.screen_contents())
|
pty.wait_till(lambda: f'Screen size changed: {cols + 3}' in pty.screen_contents())
|
||||||
os.kill(pty.child_pid, signal.SIGINT)
|
wait_for_death(128 + signal.SIGINT, signal=signal.SIGINT)
|
||||||
wait_for_death(128 + signal.SIGINT)
|
|
||||||
pty.wait_till(lambda: 'KeyboardInterrupt' in pty.screen_contents())
|
pty.wait_till(lambda: 'KeyboardInterrupt' in pty.screen_contents())
|
||||||
|
pty = self.create_pty(
|
||||||
|
argv=[kitty_exe(), '+runpy', src + 'socket_child_main(initial_print="child ready:")'], cols=cols, env=env, cwd=cwd)
|
||||||
|
pty.wait_till(lambda: 'child ready:' in pty.screen_contents())
|
||||||
|
pty.write_to_child('\x03')
|
||||||
|
pty.wait_till(lambda: 'KeyboardInterrupt' in pty.screen_contents())
|
||||||
|
wait_for_death(128 + signal.SIGINT)
|
||||||
|
|
||||||
|
# test passing of data via cwd, env vars and stdin/stdout redirection
|
||||||
stdin_r, stdin_w = os.pipe()
|
stdin_r, stdin_w = os.pipe()
|
||||||
os.set_inheritable(stdin_w, False)
|
os.set_inheritable(stdin_w, False)
|
||||||
stdout_r, stdout_w = os.pipe()
|
stdout_r, stdout_w = os.pipe()
|
||||||
|
@ -491,8 +491,8 @@ read_signals(void) {
|
|||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
memmove(buf, buf + sizeof(siginfo_t), sizeof(siginfo_t));
|
|
||||||
buf_pos -= sizeof(siginfo_t);
|
buf_pos -= sizeof(siginfo_t);
|
||||||
|
memmove(buf, buf + sizeof(siginfo_t), buf_pos);
|
||||||
}
|
}
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user