From: "Rubén Justo" <rjusto@gmail.com>
To: Git List <git@vger.kernel.org>
Subject: [PATCH 4/5] test-terminal: introduce --no-stdin-pty
Date: Sun, 19 May 2024 09:14:31 +0200 [thread overview]
Message-ID: <d42a55b1-1ba9-4cfb-9c3d-98ea4d86da33@gmail.com> (raw)
In-Reply-To: <1d0cb55c-5f32-419a-b593-d5f0969a51fd@gmail.com>
In 18d8c26930 (test_terminal: redirect child process' stdin to a pty,
2015-08-04), t/test-terminal.perl learned to connect the child process'
stdin to a pty. It works well for what was intended: satisfying an
`isatty(STDIN_FILENO)` check.
However, the fork introduced, that copies the stdin to the child
process, does not always manage to send all the information.
To illustrate this behavior, we can use a function like this:
f ()
{
dd if=/dev/zero bs=1 count=10000 status=none |
t/test-terminal.perl cat - 2>/dev/null |
wc -c;
}
We do not obtain the expected results when executing this function
100 times:
$ for i in $(seq 100); do f; done | sort | uniq -c
36 0
4 1
53 4095
7 4159
If we do the same with a version that does not redirect stdin, a version
prior to 18d8c26930, the expected result is obtained:
$ git checkout 18d8c26930~1
$ for i in $(seq 100); do f; done | sort | uniq -c
100 10000
In a subsequent commit, a new test is going to rely on test-terminate,
and it does not require stdin to be connected to a terminal, but all
piped data needs to be successfully transmitted to the child process.
To make this possible, add a new parameter "--no-stdin-pty" to allow
disabling the stdin redirection though a pty.
Signed-off-by: Rubén Justo <rjusto@gmail.com>
---
t/test-terminal.perl | 32 ++++++++++++++++++--------------
1 file changed, 18 insertions(+), 14 deletions(-)
diff --git a/t/test-terminal.perl b/t/test-terminal.perl
index 3810e9bb43..85edc9e8b9 100755
--- a/t/test-terminal.perl
+++ b/t/test-terminal.perl
@@ -12,10 +12,10 @@ sub start_child {
if (not defined $pid) {
die "fork failed: $!"
} elsif ($pid == 0) {
- open STDIN, "<&", $in;
+ open STDIN, "<&", $in if $in;
open STDOUT, ">&", $out;
open STDERR, ">&", $err;
- close $in;
+ close $in if $in;
close $out;
exec(@$argv) or die "cannot exec '$argv->[0]': $!"
}
@@ -78,28 +78,32 @@ sub copy_stdio {
}
if ($#ARGV < 1) {
- die "usage: test-terminal program args";
+ die "usage: test-terminal [--no-stdin-pty] program args";
}
+my $no_stdin_pty = $ARGV[0] eq '--no-stdin-pty';
+shift @ARGV if $no_stdin_pty;
$ENV{TERM} = 'vt100';
-my $parent_in = new IO::Pty;
+my $parent_in = $no_stdin_pty ? undef : IO::Pty->new;
my $parent_out = new IO::Pty;
my $parent_err = new IO::Pty;
-$parent_in->set_raw();
+$parent_in->set_raw() if $parent_in;
$parent_out->set_raw();
$parent_err->set_raw();
-$parent_in->slave->set_raw();
+$parent_in->slave->set_raw() if $parent_in;
$parent_out->slave->set_raw();
$parent_err->slave->set_raw();
-my $pid = start_child(\@ARGV, $parent_in->slave, $parent_out->slave, $parent_err->slave);
-close $parent_in->slave;
+my $pid = start_child(\@ARGV,$parent_in ? $parent_in->slave : undef, $parent_out->slave, $parent_err->slave);
+close $parent_in->slave if $parent_in;
close $parent_out->slave;
close $parent_err->slave;
-my $in_pid = copy_stdin($parent_in);
+my $in_pid = $no_stdin_pty ? 0 : copy_stdin($parent_in);
copy_stdio($parent_out, $parent_err);
my $ret = finish_child($pid);
-# If the child process terminates before our copy_stdin() process is able to
-# write all of its data to $parent_in, the copy_stdin() process could stall.
-# Send SIGTERM to it to ensure it terminates.
-kill 'TERM', $in_pid;
-finish_child($in_pid);
+if ($in_pid) {
+ # If the child process terminates before our copy_stdin() process is able to
+ # write all of its data to $parent_in, the copy_stdin() process could stall.
+ # Send SIGTERM to it to ensure it terminates.
+ kill 'TERM', $in_pid;
+ finish_child($in_pid);
+}
exit($ret);
--
2.45.1.209.gd5886bf9cd
next prev parent reply other threads:[~2024-05-19 7:14 UTC|newest]
Thread overview: 113+ messages / expand[flat|nested] mbox.gz Atom feed top
2024-05-19 7:06 [PATCH 0/5] use the pager in 'add -p' Rubén Justo
2024-05-19 7:10 ` [PATCH 1/5] add-patch: test for 'p' command Rubén Justo
2024-05-19 7:12 ` [PATCH 2/5] pager: do not close fd 2 unnecessarily Rubén Justo
2024-05-20 19:14 ` Junio C Hamano
2024-05-20 22:33 ` Rubén Justo
2024-05-21 20:57 ` Junio C Hamano
2024-05-21 21:35 ` Rubén Justo
2024-05-21 22:00 ` Junio C Hamano
2024-05-22 17:19 ` Rubén Justo
2024-05-22 17:40 ` Junio C Hamano
2024-05-26 6:48 ` Rubén Justo
2024-05-26 21:26 ` Junio C Hamano
2024-05-19 7:13 ` [PATCH 3/5] pager: introduce wait_for_pager Rubén Justo
2024-05-19 7:14 ` Rubén Justo [this message]
2024-05-19 7:14 ` [PATCH 5/5] add-patch: render hunks through the pager Rubén Justo
2024-05-20 19:30 ` Junio C Hamano
2024-05-20 19:45 ` Dragan Simic
2024-05-20 22:35 ` Rubén Justo
2024-05-20 23:54 ` Dragan Simic
2024-05-21 19:56 ` Rubén Justo
2024-05-21 7:07 ` Jeff King
2024-05-21 19:59 ` Rubén Justo
2024-05-23 9:06 ` Jeff King
2024-05-23 14:00 ` Junio C Hamano
2024-05-23 14:18 ` Dragan Simic
2024-05-23 23:04 ` Junio C Hamano
2024-05-23 23:28 ` Dragan Simic
2024-05-23 23:43 ` Dragan Simic
2024-05-23 23:54 ` Junio C Hamano
2024-05-23 23:57 ` Dragan Simic
2024-05-25 4:54 ` Jeff King
2024-05-23 22:25 ` Rubén Justo
2024-05-23 23:03 ` Dragan Simic
2024-05-20 22:47 ` Rubén Justo
2024-05-20 23:18 ` Junio C Hamano
2024-05-20 23:27 ` Rubén Justo
2024-05-21 20:49 ` [PATCH v2 0/5] use the pager in 'add -p' Rubén Justo
2024-05-21 20:51 ` [PATCH v2 1/5] add-patch: test for 'p' command Rubén Justo
2024-05-21 20:52 ` [PATCH v2 2/5] pager: do not close fd 2 unnecessarily Rubén Justo
2024-05-21 20:52 ` [PATCH v2 3/5] pager: introduce wait_for_pager Rubén Justo
2024-05-21 20:52 ` [PATCH v2 4/5] test-terminal: introduce --no-stdin-pty Rubén Justo
2024-05-21 20:52 ` [PATCH v2 5/5] add-patch: render hunks through the pager Rubén Justo
2024-05-22 8:09 ` Dragan Simic
2024-05-22 18:47 ` Junio C Hamano
2024-05-22 21:23 ` Rubén Justo
2024-05-22 21:27 ` Dragan Simic
2024-06-02 15:38 ` [PATCH v3 0/6] use the pager in 'add -p' Rubén Justo
2024-06-02 15:42 ` [PATCH v3 1/6] add-patch: test for 'p' command Rubén Justo
2024-06-02 15:42 ` [PATCH v3 2/6] pager: do not close fd 2 unnecessarily Rubén Justo
2024-06-02 15:43 ` [PATCH v3 3/6] pager: introduce wait_for_pager Rubén Justo
2024-06-02 15:43 ` [PATCH v3 4/6] pager: introduce setup_custom_pager Rubén Justo
2024-06-02 15:43 ` [PATCH v3 5/6] test-terminal: introduce --no-stdin-pty Rubén Justo
2024-06-02 15:44 ` [PATCH v3 6/6] add-patch: introduce the command '|' Rubén Justo
2024-06-02 16:36 ` [PATCH v3 0/6] use the pager in 'add -p' Junio C Hamano
2024-06-02 17:11 ` Junio C Hamano
2024-06-02 17:33 ` Rubén Justo
2024-06-02 17:13 ` Rubén Justo
2024-06-02 17:46 ` Dragan Simic
2024-06-03 9:03 ` Junio C Hamano
2024-06-03 10:21 ` Dragan Simic
2024-06-03 15:28 ` Junio C Hamano
2024-06-04 17:34 ` Dragan Simic
2024-06-02 17:36 ` Dragan Simic
2024-06-03 16:01 ` Junio C Hamano
2024-06-04 17:41 ` Dragan Simic
2024-06-04 17:42 ` Dragan Simic
2024-06-03 20:19 ` Rubén Justo
2024-06-04 18:13 ` Dragan Simic
2024-06-03 20:35 ` [PATCH v4 " Rubén Justo
2024-06-03 20:38 ` [PATCH v4 1/6] add-patch: test for 'p' command Rubén Justo
2024-06-03 20:38 ` [PATCH v4 2/6] pager: do not close fd 2 unnecessarily Rubén Justo
2024-06-04 15:50 ` Junio C Hamano
2024-06-03 20:38 ` [PATCH v4 3/6] pager: introduce wait_for_pager Rubén Justo
2024-06-04 10:00 ` Phillip Wood
2024-06-04 16:29 ` Junio C Hamano
2024-06-05 22:03 ` Rubén Justo
2024-06-04 16:25 ` Junio C Hamano
2024-06-03 20:38 ` [PATCH v4 4/6] pager: introduce setup_custom_pager Rubén Justo
2024-06-04 16:43 ` Junio C Hamano
2024-06-03 20:38 ` [PATCH v4 5/6] test-terminal: introduce --no-stdin-pty Rubén Justo
2024-06-04 10:05 ` Phillip Wood
2024-06-04 10:33 ` Jeff King
2024-06-05 15:39 ` Junio C Hamano
2024-06-06 8:24 ` Jeff King
2024-06-05 22:50 ` Rubén Justo
2024-06-06 8:27 ` Jeff King
2024-06-09 7:26 ` Rubén Justo
2024-06-03 20:38 ` [PATCH v4 6/6] add-patch: introduce the command '|' Rubén Justo
2024-06-04 17:12 ` Junio C Hamano
2024-06-04 20:05 ` Dragan Simic
2024-06-05 5:16 ` Junio C Hamano
2024-06-04 10:17 ` [PATCH v3 0/6] use the pager in 'add -p' Jeff King
2024-06-04 15:32 ` Junio C Hamano
2024-06-05 9:09 ` Jeff King
2024-06-05 13:21 ` Phillip Wood
2024-06-08 5:54 ` Dragan Simic
2024-06-09 7:44 ` Rubén Justo
2024-06-09 7:57 ` Dragan Simic
2024-06-10 19:09 ` Rubén Justo
2024-06-10 21:02 ` Dragan Simic
2024-06-10 14:09 ` Phillip Wood
2024-06-10 16:13 ` Junio C Hamano
2024-06-10 19:14 ` Rubén Justo
2024-06-10 19:56 ` Junio C Hamano
2024-06-10 21:08 ` Dragan Simic
2024-06-10 19:28 ` Dragan Simic
2024-06-10 20:08 ` Junio C Hamano
2024-06-10 21:16 ` Dragan Simic
2024-06-09 14:29 ` phillip.wood123
2024-06-09 17:20 ` Dragan Simic
2024-06-10 8:27 ` Phillip Wood
2024-06-10 9:09 ` Dragan Simic
2024-06-05 17:24 ` Junio C Hamano
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=d42a55b1-1ba9-4cfb-9c3d-98ea4d86da33@gmail.com \
--to=rjusto@gmail.com \
--cc=git@vger.kernel.org \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).