2009-01-17 18:50:13 +03:00
|
|
|
#!/bin/sh
|
|
|
|
|
|
|
|
test_description='check that the most basic functions work
|
|
|
|
|
|
|
|
|
|
|
|
Verify wrappers and compatibility functions.
|
|
|
|
'
|
|
|
|
|
2022-11-08 21:17:39 +03:00
|
|
|
TEST_PASSES_SANITIZE_LEAK=true
|
2009-01-17 18:50:13 +03:00
|
|
|
. ./test-lib.sh
|
|
|
|
|
2010-12-19 00:28:00 +03:00
|
|
|
test_expect_success 'mktemp to nonexistent directory prints filename' '
|
2018-03-24 10:44:47 +03:00
|
|
|
test_must_fail test-tool mktemp doesnotexist/testXXXXXX 2>err &&
|
2010-12-19 00:28:00 +03:00
|
|
|
grep "doesnotexist/test" err
|
|
|
|
'
|
|
|
|
|
2013-06-08 16:17:49 +04:00
|
|
|
test_expect_success POSIXPERM,SANITY 'mktemp to unwritable directory prints filename' '
|
2010-12-19 00:28:00 +03:00
|
|
|
mkdir cannotwrite &&
|
|
|
|
test_when_finished "chmod +w cannotwrite" &&
|
2018-06-15 21:13:39 +03:00
|
|
|
chmod -w cannotwrite &&
|
2018-03-24 10:44:47 +03:00
|
|
|
test_must_fail test-tool mktemp cannotwrite/testXXXXXX 2>err &&
|
2010-12-19 00:28:00 +03:00
|
|
|
grep "cannotwrite/test" err
|
|
|
|
'
|
|
|
|
|
2013-08-03 04:27:23 +04:00
|
|
|
test_expect_success 'git_mkstemps_mode does not fail if fd 0 is not open' '
|
|
|
|
git commit --allow-empty -m message <&-
|
|
|
|
'
|
|
|
|
|
2012-09-01 21:46:54 +04:00
|
|
|
test_expect_success 'check for a bug in the regex routines' '
|
|
|
|
# if this test fails, re-build git with NO_REGEX=1
|
2018-03-24 10:44:53 +03:00
|
|
|
test-tool regex --bug
|
2012-09-01 21:46:54 +04:00
|
|
|
'
|
|
|
|
|
sideband: avoid reporting incomplete sideband messages
In 2b695ecd74d (t5500: count objects through stderr, not trace,
2020-05-06) we tried to ensure that the "Total 3" message could be
grepped in Git's output, even if it sometimes got chopped up into
multiple lines in the trace machinery.
However, the first instance where this mattered now goes through the
sideband machinery, where it is _still_ possible for messages to get
chopped up: it *is* possible for the standard error stream to be sent
byte-for-byte and hence it can be easily interrupted. Meaning: it is
possible for the single line that we're looking for to be chopped up
into multiple sideband packets, with a primary packet being delivered
between them.
This seems to happen occasionally in the `vs-test` part of our CI
builds, i.e. with binaries built using Visual C, but not when building
with GCC or clang; The symptom is that t5500.43 fails to find a line
matching `remote: Total 3` in the `log` file, which ends in something
along these lines:
remote: Tota
remote: l 3 (delta 0), reused 0 (delta 0), pack-reused 0
This should not happen, though: we have code in `demultiplex_sideband()`
_specifically_ to stitch back together lines that were delivered in
separate sideband packets.
However, this stitching was broken in a subtle way in fbd76cd450
(sideband: reverse its dependency on pkt-line, 2019-01-16): before that
change, incomplete sideband lines would not be flushed upon receiving a
primary packet, but after that patch, they would be.
The subtleness of this bug comes from the fact that it is easy to get
confused by the ambiguous meaning of the `break` keyword: after writing
the primary packet contents, the `break;` in the original version of
`recv_sideband()` does _not_ break out of the `while` loop, but instead
only ends the `switch` case:
while (!retval) {
[...]
switch (band) {
[...]
case 1:
/* Write the contents of the primary packet */
write_or_die(out, buf + 1, len);
/* Here, we do *not* break out of the loop, `retval` is unchanged */
break;
[...]
}
if (outbuf.len) {
/* Write any remaining sideband messages lacking a trailing LF */
strbuf_addch(&outbuf, '\n');
xwrite(2, outbuf.buf, outbuf.len);
}
In contrast, after fbd76cd450 (sideband: reverse its dependency on
pkt-line, 2019-01-16), the body of the `while` loop was extracted into
`demultiplex_sideband()`, crucially _including_ the logic to write
incomplete sideband messages:
switch (band) {
[...]
case 1:
*sideband_type = SIDEBAND_PRIMARY;
/* This does not break out of the loop: the loop is in the caller */
break;
[...]
}
cleanup:
[...]
/* This logic is now no longer _outside_ the loop but _inside_ */
if (scratch->len) {
strbuf_addch(scratch, '\n');
xwrite(2, scratch->buf, scratch->len);
}
The correct way to fix this is to return from `demultiplex_sideband()`
early. The caller will then write out the contents of the primary packet
and continue looping. The `scratch` buffer for incomplete sideband
messages is owned by that caller, and will continue to accumulate the
remainder(s) of those messages. The loop will only end once
`demultiplex_sideband()` returned non-zero _and_ did not indicate a
primary packet, which is the case only when we hit the `cleanup:` path,
in which we take care of flushing any unfinished sideband messages and
release the `scratch` buffer.
To ensure that this does not get broken again, we introduce a pair of
subcommands of the `pkt-line` test helper that specifically chop up the
sideband message and squeeze a primary packet into the middle.
Final note: The other test case touched by 2b695ecd74d (t5500: count
objects through stderr, not trace, 2020-05-06) is not affected by this
issue because the sideband machinery is not involved there.
Signed-off-by: Johannes Schindelin <johannes.schindelin@gmx.de>
Signed-off-by: Junio C Hamano <gitster@pobox.com>
2020-10-19 22:35:40 +03:00
|
|
|
test_expect_success 'incomplete sideband messages are reassembled' '
|
|
|
|
test-tool pkt-line send-split-sideband >split-sideband &&
|
|
|
|
test-tool pkt-line receive-sideband <split-sideband 2>err &&
|
|
|
|
grep "Hello, world" err
|
|
|
|
'
|
|
|
|
|
sideband: diagnose more sideband anomalies
In demultiplex_sideband(), there are two oddities when we check an
incoming packet:
- if it has zero length, then we assume it's a flush packet. This
means we fail to notice the difference between a real flush and a
true zero-length packet that's missing its sideband designator. It's
not a huge problem in practice because we'd never send a zero-length
data packet (even our keepalives are otherwise-empty sideband-1
packets).
But it would be nice to detect and report the error, since it's
likely to cause other confusion (we think the other side flushed,
but they do not).
- we try to detect packets missing their designator by checking for
"if (len < 1)". But this will never trigger for "len == 0"; we've
already detected that and left the function before then.
It _could_ detect a negative "len" parameter. But in that case, the
error message is wrong. The issue is not "no sideband" but rather
"eof while reading the packet". However, this can't actually be
triggered in practice, because neither of the two callers uses
pkt_read's GENTLE_ON_EOF flag. Which means they'd die with "the
remote end hung up unexpectedly" before we even get here.
So this truly is dead code.
We can improve these cases by passing in a pkt-line status to the
demultiplexer, and by having recv_sideband() use GENTLE_ON_EOF. This
gives us two improvements:
- we can now reliably detect flush packets, and will report a normal
packet missing its sideband designator as an error
- we'll report an eof with a more detailed "protocol error: eof while
reading sideband packet", rather than the generic "the remote end
hung up unexpectedly"
- when we see an eof, we'll flush the sideband scratch buffer, which
may provide some hints from the remote about why they hung up
(though note we already flush on newlines, so it's likely that most
such messages already made it through)
In some sense this patch goes against fbd76cd450 (sideband: reverse its
dependency on pkt-line, 2019-01-16), which caused the sideband code not
to depend on the pkt-line code. But that commit was really just trying
to deal with the circular header dependency. The two modules are
conceptually interlinked, and it was just trying to keep things
compiling. And indeed, there's a sticking point in this patch: because
pkt-line.h includes sideband.h, we can't add the reverse include we need
for the sideband code to have an "enum packet_read_status" parameter.
Nor can we forward declare it, because you can't forward declare an enum
in C. However, C does guarantee that enums fit in an int, so we can just
use that type.
One alternative would be for the callers to check themselves that they
got something sane from the pkt-line code. But besides duplicating
logic, this gets quite tricky. Any error condition requires flushing the
sideband #2 scratch buffer, which only demultiplex_sideband() knows how
to do.
Signed-off-by: Jeff King <peff@peff.net>
Signed-off-by: Junio C Hamano <gitster@pobox.com>
2020-10-28 12:33:24 +03:00
|
|
|
test_expect_success 'eof on sideband message is reported' '
|
|
|
|
printf 1234 >input &&
|
|
|
|
test-tool pkt-line receive-sideband <input 2>err &&
|
2023-10-31 08:23:30 +03:00
|
|
|
test_grep "unexpected disconnect" err
|
sideband: diagnose more sideband anomalies
In demultiplex_sideband(), there are two oddities when we check an
incoming packet:
- if it has zero length, then we assume it's a flush packet. This
means we fail to notice the difference between a real flush and a
true zero-length packet that's missing its sideband designator. It's
not a huge problem in practice because we'd never send a zero-length
data packet (even our keepalives are otherwise-empty sideband-1
packets).
But it would be nice to detect and report the error, since it's
likely to cause other confusion (we think the other side flushed,
but they do not).
- we try to detect packets missing their designator by checking for
"if (len < 1)". But this will never trigger for "len == 0"; we've
already detected that and left the function before then.
It _could_ detect a negative "len" parameter. But in that case, the
error message is wrong. The issue is not "no sideband" but rather
"eof while reading the packet". However, this can't actually be
triggered in practice, because neither of the two callers uses
pkt_read's GENTLE_ON_EOF flag. Which means they'd die with "the
remote end hung up unexpectedly" before we even get here.
So this truly is dead code.
We can improve these cases by passing in a pkt-line status to the
demultiplexer, and by having recv_sideband() use GENTLE_ON_EOF. This
gives us two improvements:
- we can now reliably detect flush packets, and will report a normal
packet missing its sideband designator as an error
- we'll report an eof with a more detailed "protocol error: eof while
reading sideband packet", rather than the generic "the remote end
hung up unexpectedly"
- when we see an eof, we'll flush the sideband scratch buffer, which
may provide some hints from the remote about why they hung up
(though note we already flush on newlines, so it's likely that most
such messages already made it through)
In some sense this patch goes against fbd76cd450 (sideband: reverse its
dependency on pkt-line, 2019-01-16), which caused the sideband code not
to depend on the pkt-line code. But that commit was really just trying
to deal with the circular header dependency. The two modules are
conceptually interlinked, and it was just trying to keep things
compiling. And indeed, there's a sticking point in this patch: because
pkt-line.h includes sideband.h, we can't add the reverse include we need
for the sideband code to have an "enum packet_read_status" parameter.
Nor can we forward declare it, because you can't forward declare an enum
in C. However, C does guarantee that enums fit in an int, so we can just
use that type.
One alternative would be for the callers to check themselves that they
got something sane from the pkt-line code. But besides duplicating
logic, this gets quite tricky. Any error condition requires flushing the
sideband #2 scratch buffer, which only demultiplex_sideband() knows how
to do.
Signed-off-by: Jeff King <peff@peff.net>
Signed-off-by: Junio C Hamano <gitster@pobox.com>
2020-10-28 12:33:24 +03:00
|
|
|
'
|
|
|
|
|
|
|
|
test_expect_success 'missing sideband designator is reported' '
|
|
|
|
printf 0004 >input &&
|
|
|
|
test-tool pkt-line receive-sideband <input 2>err &&
|
2023-10-31 08:23:30 +03:00
|
|
|
test_grep "missing sideband" err
|
sideband: diagnose more sideband anomalies
In demultiplex_sideband(), there are two oddities when we check an
incoming packet:
- if it has zero length, then we assume it's a flush packet. This
means we fail to notice the difference between a real flush and a
true zero-length packet that's missing its sideband designator. It's
not a huge problem in practice because we'd never send a zero-length
data packet (even our keepalives are otherwise-empty sideband-1
packets).
But it would be nice to detect and report the error, since it's
likely to cause other confusion (we think the other side flushed,
but they do not).
- we try to detect packets missing their designator by checking for
"if (len < 1)". But this will never trigger for "len == 0"; we've
already detected that and left the function before then.
It _could_ detect a negative "len" parameter. But in that case, the
error message is wrong. The issue is not "no sideband" but rather
"eof while reading the packet". However, this can't actually be
triggered in practice, because neither of the two callers uses
pkt_read's GENTLE_ON_EOF flag. Which means they'd die with "the
remote end hung up unexpectedly" before we even get here.
So this truly is dead code.
We can improve these cases by passing in a pkt-line status to the
demultiplexer, and by having recv_sideband() use GENTLE_ON_EOF. This
gives us two improvements:
- we can now reliably detect flush packets, and will report a normal
packet missing its sideband designator as an error
- we'll report an eof with a more detailed "protocol error: eof while
reading sideband packet", rather than the generic "the remote end
hung up unexpectedly"
- when we see an eof, we'll flush the sideband scratch buffer, which
may provide some hints from the remote about why they hung up
(though note we already flush on newlines, so it's likely that most
such messages already made it through)
In some sense this patch goes against fbd76cd450 (sideband: reverse its
dependency on pkt-line, 2019-01-16), which caused the sideband code not
to depend on the pkt-line code. But that commit was really just trying
to deal with the circular header dependency. The two modules are
conceptually interlinked, and it was just trying to keep things
compiling. And indeed, there's a sticking point in this patch: because
pkt-line.h includes sideband.h, we can't add the reverse include we need
for the sideband code to have an "enum packet_read_status" parameter.
Nor can we forward declare it, because you can't forward declare an enum
in C. However, C does guarantee that enums fit in an int, so we can just
use that type.
One alternative would be for the callers to check themselves that they
got something sane from the pkt-line code. But besides duplicating
logic, this gets quite tricky. Any error condition requires flushing the
sideband #2 scratch buffer, which only demultiplex_sideband() knows how
to do.
Signed-off-by: Jeff King <peff@peff.net>
Signed-off-by: Junio C Hamano <gitster@pobox.com>
2020-10-28 12:33:24 +03:00
|
|
|
'
|
|
|
|
|
2023-12-17 17:41:36 +03:00
|
|
|
test_expect_success 'unpack-sideband: --no-chomp-newline' '
|
|
|
|
test_when_finished "rm -f expect-out expect-err" &&
|
|
|
|
test-tool pkt-line send-split-sideband >split-sideband &&
|
|
|
|
test-tool pkt-line unpack-sideband \
|
|
|
|
--no-chomp-newline <split-sideband >out 2>err &&
|
|
|
|
cat >expect-out <<-EOF &&
|
|
|
|
primary: regular output
|
|
|
|
EOF
|
|
|
|
cat >expect-err <<-EOF &&
|
|
|
|
Foo.
|
|
|
|
Bar.
|
|
|
|
Hello, world!
|
|
|
|
EOF
|
|
|
|
test_cmp expect-out out &&
|
|
|
|
test_cmp expect-err err
|
|
|
|
'
|
|
|
|
|
|
|
|
test_expect_success 'unpack-sideband: --chomp-newline (default)' '
|
|
|
|
test_when_finished "rm -f expect-out expect-err" &&
|
|
|
|
test-tool pkt-line send-split-sideband >split-sideband &&
|
|
|
|
test-tool pkt-line unpack-sideband \
|
|
|
|
--chomp-newline <split-sideband >out 2>err &&
|
|
|
|
printf "primary: regular output" >expect-out &&
|
|
|
|
printf "Foo.Bar.Hello, world!" >expect-err &&
|
|
|
|
test_cmp expect-out out &&
|
|
|
|
test_cmp expect-err err
|
|
|
|
'
|
|
|
|
|
2023-12-17 17:41:37 +03:00
|
|
|
test_expect_success 'unpack-sideband: packet_reader_read() consumes sideband, no chomp payload' '
|
2023-12-17 17:41:36 +03:00
|
|
|
test_when_finished "rm -f expect-out expect-err" &&
|
|
|
|
test-tool pkt-line send-split-sideband >split-sideband &&
|
|
|
|
test-tool pkt-line unpack-sideband \
|
|
|
|
--reader-use-sideband \
|
|
|
|
--no-chomp-newline <split-sideband >out 2>err &&
|
|
|
|
cat >expect-out <<-EOF &&
|
|
|
|
primary: regular output
|
|
|
|
EOF
|
|
|
|
printf "remote: Foo. \n" >expect-err &&
|
|
|
|
printf "remote: Bar. \n" >>expect-err &&
|
|
|
|
printf "remote: Hello, world! \n" >>expect-err &&
|
|
|
|
test_cmp expect-out out &&
|
|
|
|
test_cmp expect-err err
|
|
|
|
'
|
|
|
|
|
2023-12-17 17:41:38 +03:00
|
|
|
test_expect_success 'unpack-sideband: packet_reader_read() consumes sideband, chomp payload' '
|
2023-12-17 17:41:36 +03:00
|
|
|
test_when_finished "rm -f expect-out expect-err" &&
|
|
|
|
test-tool pkt-line send-split-sideband >split-sideband &&
|
|
|
|
test-tool pkt-line unpack-sideband \
|
|
|
|
--reader-use-sideband \
|
|
|
|
--chomp-newline <split-sideband >out 2>err &&
|
|
|
|
printf "primary: regular output" >expect-out &&
|
|
|
|
printf "remote: Foo. \n" >expect-err &&
|
|
|
|
printf "remote: Bar. \n" >>expect-err &&
|
|
|
|
printf "remote: Hello, world! \n" >>expect-err &&
|
|
|
|
test_cmp expect-out out &&
|
|
|
|
test_cmp expect-err err
|
|
|
|
'
|
|
|
|
|
2009-01-17 18:50:13 +03:00
|
|
|
test_done
|