mirror of
https://git.libssh.org/projects/libssh.git
synced 2026-02-09 18:04:25 +09:00
tests: Assemble the output into single buffer
... before checking the content.
This test was failing randomly when the read returned only partial buffer.
Signed-off-by: Jakub Jelen <jjelen@redhat.com>
Reviewed-by: Andreas Schneider <asn@cryptomilk.org>
(cherry picked from commit 2743b510ac)
This commit is contained in:
@@ -84,18 +84,24 @@ static int session_teardown(void **state)
|
|||||||
static int check_channel_output(ssh_channel c, const char *expected)
|
static int check_channel_output(ssh_channel c, const char *expected)
|
||||||
{
|
{
|
||||||
char buffer[4096] = {0};
|
char buffer[4096] = {0};
|
||||||
int nbytes;
|
int nbytes, offset = 0;
|
||||||
|
|
||||||
nbytes = ssh_channel_read(c, buffer, sizeof(buffer) - 1, 0);
|
nbytes = ssh_channel_read(c, buffer, sizeof(buffer) - 1, 0);
|
||||||
while (nbytes > 0) {
|
while (nbytes > 0) {
|
||||||
buffer[nbytes]='\0';
|
buffer[offset + nbytes] = '\0';
|
||||||
ssh_log_hexdump("Read bytes:", (unsigned char *)buffer, nbytes);
|
ssh_log_hexdump("Read bytes:",
|
||||||
|
(unsigned char *)buffer,
|
||||||
|
offset + nbytes);
|
||||||
if (strstr(buffer, expected) != NULL)
|
if (strstr(buffer, expected) != NULL)
|
||||||
{
|
{
|
||||||
return 1;
|
return 1;
|
||||||
}
|
}
|
||||||
|
/* read on */
|
||||||
nbytes = ssh_channel_read(c, buffer, sizeof(buffer), 0);
|
offset = nbytes;
|
||||||
|
nbytes = ssh_channel_read(c,
|
||||||
|
buffer + offset,
|
||||||
|
sizeof(buffer) - offset - 1,
|
||||||
|
0);
|
||||||
}
|
}
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user